重写事件再暂存
This commit is contained in:
@@ -83,7 +83,7 @@ namespace WulaFallenEmpire
|
||||
background = ContentFinder<Texture2D>.Get(bgPath);
|
||||
}
|
||||
|
||||
HandleAction(def.onOpenEffects);
|
||||
HandleAction(def.immediateEffects);
|
||||
}
|
||||
|
||||
public override void DoWindowContents(Rect inRect)
|
||||
@@ -186,7 +186,7 @@ namespace WulaFallenEmpire
|
||||
{
|
||||
if (listing.ButtonText(option.label))
|
||||
{
|
||||
HandleAction(option.effects);
|
||||
HandleAction(option.optionEffects);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -200,16 +200,26 @@ namespace WulaFallenEmpire
|
||||
listing.End();
|
||||
}
|
||||
|
||||
private void HandleAction(List<Effect> effects)
|
||||
private void HandleAction(List<ConditionalEffects> conditionalEffects)
|
||||
{
|
||||
if (effects.NullOrEmpty())
|
||||
if (conditionalEffects.NullOrEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var effect in effects)
|
||||
foreach (var ce in conditionalEffects)
|
||||
{
|
||||
effect.Execute(this);
|
||||
string reason;
|
||||
if (AreConditionsMet(ce.conditions, out reason))
|
||||
{
|
||||
if (!ce.effects.NullOrEmpty())
|
||||
{
|
||||
foreach (var effect in ce.effects)
|
||||
{
|
||||
effect.Execute(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,13 +21,56 @@ namespace WulaFallenEmpire
|
||||
EventDef nextDef = DefDatabase<EventDef>.GetNamed(defName);
|
||||
if (nextDef != null)
|
||||
{
|
||||
Find.WindowStack.Add(new Dialog_CustomDisplay(nextDef));
|
||||
if (nextDef.hiddenWindow)
|
||||
{
|
||||
// Since effects are merged in PostLoad, we only need to execute dismissEffects here.
|
||||
if (!nextDef.dismissEffects.NullOrEmpty())
|
||||
{
|
||||
foreach (var conditionalEffect in nextDef.dismissEffects)
|
||||
{
|
||||
string reason;
|
||||
if (AreConditionsMet(conditionalEffect.conditions, out reason))
|
||||
{
|
||||
if (!conditionalEffect.effects.NullOrEmpty())
|
||||
{
|
||||
foreach (var effect in conditionalEffect.effects)
|
||||
{
|
||||
effect.Execute(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Find.WindowStack.Add(new Dialog_CustomDisplay(nextDef));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error($"[WulaFallenEmpire] Effect_OpenCustomUI could not find EventDef named '{defName}'");
|
||||
}
|
||||
}
|
||||
|
||||
private bool AreConditionsMet(List<Condition> conditions, out string reason)
|
||||
{
|
||||
reason = "";
|
||||
if (conditions.NullOrEmpty())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (var condition in conditions)
|
||||
{
|
||||
if (!condition.IsMet(out string singleReason))
|
||||
{
|
||||
reason = singleReason;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class Effect_CloseDialog : Effect
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace WulaFallenEmpire
|
||||
// New system: list of descriptions
|
||||
public List<string> descriptions;
|
||||
public DescriptionSelectionMode descriptionMode = DescriptionSelectionMode.Random;
|
||||
public bool hiddenWindow = false;
|
||||
|
||||
// Backwards compatibility: old single description field
|
||||
public new string description = null;
|
||||
@@ -26,9 +27,8 @@ namespace WulaFallenEmpire
|
||||
|
||||
public List<EventOption> options;
|
||||
public string backgroundImagePath;
|
||||
public List<Effect> onOpenEffects;
|
||||
public List<Effect> dismissEffects;
|
||||
|
||||
public List<ConditionalEffects> immediateEffects;
|
||||
public List<ConditionalEffects> dismissEffects;
|
||||
public override void PostLoad()
|
||||
{
|
||||
base.PostLoad();
|
||||
@@ -44,14 +44,30 @@ namespace WulaFallenEmpire
|
||||
description = null; // Clear the old field to prevent confusion
|
||||
}
|
||||
#pragma warning restore 0618
|
||||
// If hiddenWindow is true, merge immediateEffects into dismissEffects at load time.
|
||||
if (hiddenWindow && !immediateEffects.NullOrEmpty())
|
||||
{
|
||||
if (dismissEffects.NullOrEmpty())
|
||||
{
|
||||
dismissEffects = new List<ConditionalEffects>();
|
||||
}
|
||||
dismissEffects.AddRange(immediateEffects);
|
||||
immediateEffects = null; // Clear to prevent double execution
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class EventOption
|
||||
{
|
||||
public string label;
|
||||
public List<Effect> effects;
|
||||
public List<ConditionalEffects> optionEffects;
|
||||
public List<Condition> conditions;
|
||||
public string disabledReason;
|
||||
}
|
||||
|
||||
public class ConditionalEffects
|
||||
{
|
||||
public List<Condition> conditions;
|
||||
public List<Effect> effects;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,11 +29,21 @@ namespace WulaFallenEmpire
|
||||
var currentOption = optionDef;
|
||||
Action choiceAction = delegate
|
||||
{
|
||||
if (!currentOption.effects.NullOrEmpty())
|
||||
if (!currentOption.optionEffects.NullOrEmpty())
|
||||
{
|
||||
foreach (var effect in currentOption.effects)
|
||||
foreach (var conditionalEffect in currentOption.optionEffects)
|
||||
{
|
||||
effect.Execute(null);
|
||||
string reason;
|
||||
if (AreConditionsMet(conditionalEffect.conditions, out reason))
|
||||
{
|
||||
if (!conditionalEffect.effects.NullOrEmpty())
|
||||
{
|
||||
foreach (var effect in conditionalEffect.effects)
|
||||
{
|
||||
effect.Execute(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (quest != null && !quest.hidden && !quest.Historical)
|
||||
@@ -55,6 +65,25 @@ namespace WulaFallenEmpire
|
||||
|
||||
public override bool CanDismissWithRightClick => false;
|
||||
|
||||
private bool AreConditionsMet(List<Condition> conditions, out string reason)
|
||||
{
|
||||
reason = "";
|
||||
if (conditions.NullOrEmpty())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (var condition in conditions)
|
||||
{
|
||||
if (!condition.IsMet(out string singleReason))
|
||||
{
|
||||
reason = singleReason;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void ExposeData()
|
||||
{
|
||||
base.ExposeData();
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace WulaFallenEmpire
|
||||
public class Option
|
||||
{
|
||||
public string label;
|
||||
public List<Effect> effects;
|
||||
public List<ConditionalEffects> optionEffects;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user