随便吧乌拉乌拉
This commit is contained in:
Binary file not shown.
@@ -36,6 +36,7 @@
|
|||||||
<li Class="WulaFallenEmpire.Effect_CloseDialog" />
|
<li Class="WulaFallenEmpire.Effect_CloseDialog" />
|
||||||
<li Class="WulaFallenEmpire.Effect_OpenCustomUI">
|
<li Class="WulaFallenEmpire.Effect_OpenCustomUI">
|
||||||
<defName>Wula_Test_VariableEvent</defName>
|
<defName>Wula_Test_VariableEvent</defName>
|
||||||
|
<delayTicks>180</delayTicks> <!-- 3 seconds -->
|
||||||
</li>
|
</li>
|
||||||
</effects>
|
</effects>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
61
Source/WulaFallenEmpire/EventSystem/DelayedActionManager.cs
Normal file
61
Source/WulaFallenEmpire/EventSystem/DelayedActionManager.cs
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using RimWorld.Planet;
|
||||||
|
using Verse;
|
||||||
|
|
||||||
|
namespace WulaFallenEmpire
|
||||||
|
{
|
||||||
|
public class DelayedActionManager : WorldComponent
|
||||||
|
{
|
||||||
|
private class DelayedAction
|
||||||
|
{
|
||||||
|
public int TicksRemaining;
|
||||||
|
public Action Action;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<DelayedAction> actions = new List<DelayedAction>();
|
||||||
|
|
||||||
|
public DelayedActionManager(World world) : base(world)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddAction(Action action, int delayTicks)
|
||||||
|
{
|
||||||
|
if (action == null || delayTicks <= 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
actions.Add(new DelayedAction { TicksRemaining = delayTicks, Action = action });
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void WorldComponentTick()
|
||||||
|
{
|
||||||
|
base.WorldComponentTick();
|
||||||
|
for (int i = actions.Count - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
DelayedAction delayedAction = actions[i];
|
||||||
|
delayedAction.TicksRemaining--;
|
||||||
|
if (delayedAction.TicksRemaining <= 0)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
delayedAction.Action();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error($"[WulaFallenEmpire] Error executing delayed action: {ex}");
|
||||||
|
}
|
||||||
|
actions.RemoveAt(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ExposeData()
|
||||||
|
{
|
||||||
|
// This simple manager does not save scheduled actions across game loads.
|
||||||
|
// If you need actions to persist, you would need a more complex system
|
||||||
|
// to serialize the action's target and parameters.
|
||||||
|
base.ExposeData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,8 +15,29 @@ namespace WulaFallenEmpire
|
|||||||
public class Effect_OpenCustomUI : Effect
|
public class Effect_OpenCustomUI : Effect
|
||||||
{
|
{
|
||||||
public string defName;
|
public string defName;
|
||||||
|
public int delayTicks = 0;
|
||||||
|
|
||||||
public override void Execute(Dialog_CustomDisplay dialog = null)
|
public override void Execute(Dialog_CustomDisplay dialog = null)
|
||||||
|
{
|
||||||
|
if (delayTicks > 0)
|
||||||
|
{
|
||||||
|
var actionManager = Find.World.GetComponent<DelayedActionManager>();
|
||||||
|
if (actionManager != null)
|
||||||
|
{
|
||||||
|
actionManager.AddAction(() => OpenUI(), delayTicks);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.Error("[WulaFallenEmpire] DelayedActionManager not found. Cannot schedule delayed UI opening.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
OpenUI();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OpenUI()
|
||||||
{
|
{
|
||||||
EventDef nextDef = DefDatabase<EventDef>.GetNamed(defName);
|
EventDef nextDef = DefDatabase<EventDef>.GetNamed(defName);
|
||||||
if (nextDef != null)
|
if (nextDef != null)
|
||||||
|
|||||||
@@ -80,6 +80,7 @@
|
|||||||
<Compile Include="EventSystem\CompOpenCustomUI.cs" />
|
<Compile Include="EventSystem\CompOpenCustomUI.cs" />
|
||||||
<Compile Include="EventSystem\Condition.cs" />
|
<Compile Include="EventSystem\Condition.cs" />
|
||||||
<Compile Include="EventSystem\DebugActions.cs" />
|
<Compile Include="EventSystem\DebugActions.cs" />
|
||||||
|
<Compile Include="EventSystem\DelayedActionManager.cs" />
|
||||||
<Compile Include="EventSystem\Dialog_CustomDisplay.cs" />
|
<Compile Include="EventSystem\Dialog_CustomDisplay.cs" />
|
||||||
<Compile Include="EventSystem\Effect.cs" />
|
<Compile Include="EventSystem\Effect.cs" />
|
||||||
<Compile Include="EventSystem\EventContext.cs" />
|
<Compile Include="EventSystem\EventContext.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user