暂存2
This commit is contained in:
Binary file not shown.
@@ -7,7 +7,7 @@
|
||||
"RelativeMoniker": "D:0:0:{F5AE8C3B-0221-4C16-A128-9A62D521A8FF}|WulaFallenEmpire.csproj|solutionrelative:debugactions.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
||||
},
|
||||
{
|
||||
"AbsoluteMoniker": "D:0:0:{F5AE8C3B-0221-4C16-A128-9A62D521A8FF}|WulaFallenEmpire.csproj|c:\\steam\\steamapps\\common\\rimworld\\mods\\3516260226\\source\\wulafallenempire\\mentalstate_brokenpersonality.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
||||
"AbsoluteMoniker": "D:0:0:{F5AE8C3B-0221-4C16-A128-9A62D521A8FF}|WulaFallenEmpire.csproj|C:\\Steam\\steamapps\\common\\RimWorld\\Mods\\3516260226\\Source\\WulaFallenEmpire\\mentalstate_brokenpersonality.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
||||
"RelativeMoniker": "D:0:0:{F5AE8C3B-0221-4C16-A128-9A62D521A8FF}|WulaFallenEmpire.csproj|solutionrelative:mentalstate_brokenpersonality.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
||||
},
|
||||
{
|
||||
@@ -91,8 +91,7 @@
|
||||
"RelativeToolTip": "MentalState_BrokenPersonality.cs",
|
||||
"ViewState": "AQIAABMAAAAAAAAAAAAAwEsAAAAjAAAA",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
||||
"WhenOpened": "2025-07-25T13:51:03.13Z",
|
||||
"EditorCaption": ""
|
||||
"WhenOpened": "2025-07-25T13:51:03.13Z"
|
||||
},
|
||||
{
|
||||
"$type": "Document",
|
||||
|
||||
64
Source/WulaFallenEmpire/Condition.cs
Normal file
64
Source/WulaFallenEmpire/Condition.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using Verse;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public abstract class Condition
|
||||
{
|
||||
public abstract bool IsMet(out string reason);
|
||||
}
|
||||
|
||||
public class Condition_VariableEquals : Condition
|
||||
{
|
||||
public string name;
|
||||
public string value;
|
||||
|
||||
public override bool IsMet(out string reason)
|
||||
{
|
||||
object variable = EventContext.GetVariable<object>(name);
|
||||
if (variable == null)
|
||||
{
|
||||
reason = $"Variable '{name}' not set.";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Simple string comparison for now. Can be expanded.
|
||||
bool met = variable.ToString() == value;
|
||||
if (!met)
|
||||
{
|
||||
reason = $"Requires {name} = {value} (Current: {variable})";
|
||||
}
|
||||
else
|
||||
{
|
||||
reason = "";
|
||||
}
|
||||
return met;
|
||||
}
|
||||
}
|
||||
|
||||
public class Condition_VariableGreaterThan : Condition
|
||||
{
|
||||
public string name;
|
||||
public float value;
|
||||
|
||||
public override bool IsMet(out string reason)
|
||||
{
|
||||
float variable = EventContext.GetVariable<float>(name, float.MinValue);
|
||||
if (variable == float.MinValue)
|
||||
{
|
||||
reason = $"Variable '{name}' not set.";
|
||||
return false;
|
||||
}
|
||||
|
||||
bool met = variable > value;
|
||||
if (!met)
|
||||
{
|
||||
reason = $"Requires {name} > {value} (Current: {variable})";
|
||||
}
|
||||
else
|
||||
{
|
||||
reason = "";
|
||||
}
|
||||
return met;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,5 +15,7 @@ namespace WulaFallenEmpire
|
||||
{
|
||||
public string label;
|
||||
public List<Effect> effects;
|
||||
public List<Condition> conditions;
|
||||
public string disabledReason; // Custom text to show if conditions aren't met
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,27 +31,42 @@ namespace WulaFallenEmpire
|
||||
|
||||
public override void DoWindowContents(Rect inRect)
|
||||
{
|
||||
// Top-left defName
|
||||
// Top-left defName and Label
|
||||
Text.Font = GameFont.Tiny;
|
||||
GUI.color = Color.gray;
|
||||
Widgets.Label(new Rect(0, 0, inRect.width, 30f), def.defName);
|
||||
Widgets.Label(new Rect(5, 5, inRect.width - 10, 20f), def.defName);
|
||||
GUI.color = Color.white;
|
||||
|
||||
Text.Font = GameFont.Small;
|
||||
Widgets.Label(new Rect(5, 20f, inRect.width - 10, 30f), def.label);
|
||||
|
||||
// Scaling factor to fit the new window size while maintaining layout proportions.
|
||||
float scale = 0.65f;
|
||||
|
||||
// The original CSS was based on a large canvas. We create a virtual canvas inside our window.
|
||||
// Center the main content block.
|
||||
float contentWidth = 1200f * scale;
|
||||
float contentHeight = 1100f * scale;
|
||||
Rect contentRect = new Rect((inRect.width - contentWidth) / 2, (inRect.height - contentHeight) / 2, contentWidth, contentHeight);
|
||||
// Define virtual total size from the CSS layout
|
||||
float virtualWidth = 500f + 650f; // lihui + text
|
||||
float virtualHeight = 800f; // lihui height
|
||||
|
||||
// All original positions are now relative to this contentRect and scaled.
|
||||
Rect mainBodySRect = new Rect(contentRect.x + 200f * scale, contentRect.y + 400f * scale, 1050f * scale, 1000f * scale);
|
||||
// Calculate scale to fit the window, maintaining aspect ratio
|
||||
float scaleX = inRect.width / virtualWidth;
|
||||
float scaleY = inRect.height / virtualHeight;
|
||||
float scale = Mathf.Min(scaleX, scaleY) * 0.95f; // Use 95% of space to leave some margin
|
||||
|
||||
// Calculate scaled dimensions
|
||||
float scaledLihuiWidth = 500f * scale;
|
||||
float scaledLihuiHeight = 800f * scale;
|
||||
float scaledNameWidth = 260f * scale;
|
||||
float scaledNameHeight = 130f * scale;
|
||||
float scaledTextWidth = 650f * scale;
|
||||
float scaledTextHeight = 250f * scale;
|
||||
float scaledOptionsWidth = 610f * scale;
|
||||
|
||||
// Center the whole content block
|
||||
float totalContentWidth = scaledLihuiWidth + scaledTextWidth;
|
||||
float totalContentHeight = scaledLihuiHeight;
|
||||
float startX = (inRect.width - totalContentWidth) / 2;
|
||||
float startY = (inRect.height - totalContentHeight) / 2;
|
||||
|
||||
// lihui (Portrait)
|
||||
Rect lihuiRect = new Rect(mainBodySRect.x - 150f * scale, mainBodySRect.y - 200f * scale, 500f * scale, 800f * scale);
|
||||
Rect lihuiRect = new Rect(startX, startY, scaledLihuiWidth, scaledLihuiHeight);
|
||||
if (portrait != null)
|
||||
{
|
||||
GUI.DrawTexture(lihuiRect, portrait, ScaleMode.ScaleToFit);
|
||||
@@ -62,7 +77,7 @@ namespace WulaFallenEmpire
|
||||
|
||||
|
||||
// name
|
||||
Rect nameRect = new Rect(lihuiRect.xMax, mainBodySRect.y - 30f * scale, 260f * scale, 130f * scale);
|
||||
Rect nameRect = new Rect(lihuiRect.xMax, lihuiRect.y, scaledNameWidth, scaledNameHeight);
|
||||
GUI.color = Color.white;
|
||||
Widgets.DrawBox(nameRect);
|
||||
GUI.color = Color.white; // Reset color
|
||||
@@ -73,7 +88,7 @@ namespace WulaFallenEmpire
|
||||
Text.Anchor = TextAnchor.UpperLeft;
|
||||
|
||||
// text (Description)
|
||||
Rect textRect = new Rect(nameRect.x, nameRect.yMax + 50f * scale, 650f * scale, 250f * scale);
|
||||
Rect textRect = new Rect(nameRect.x, nameRect.yMax + 20f * scale, scaledTextWidth, scaledTextHeight);
|
||||
GUI.color = Color.white;
|
||||
Widgets.DrawBox(textRect);
|
||||
GUI.color = Color.white; // Reset color
|
||||
@@ -81,7 +96,7 @@ namespace WulaFallenEmpire
|
||||
Widgets.Label(textInnerRect, def.description);
|
||||
|
||||
// option (Buttons)
|
||||
Rect optionRect = new Rect(nameRect.x, textRect.yMax, 610f * scale, 300f * scale);
|
||||
Rect optionRect = new Rect(nameRect.x, textRect.yMax + 20f * scale, scaledOptionsWidth, lihuiRect.height - nameRect.height - textRect.height - 40f * scale);
|
||||
// No need to draw a box for the options area, the buttons will be listed inside.
|
||||
|
||||
Listing_Standard listing = new Listing_Standard();
|
||||
@@ -90,9 +105,22 @@ namespace WulaFallenEmpire
|
||||
{
|
||||
foreach (var option in def.options)
|
||||
{
|
||||
if (listing.ButtonText(option.label))
|
||||
string reason;
|
||||
bool conditionsMet = AreConditionsMet(option.conditions, out reason);
|
||||
|
||||
if (conditionsMet)
|
||||
{
|
||||
HandleAction(option.effects);
|
||||
if (listing.ButtonText(option.label))
|
||||
{
|
||||
HandleAction(option.effects);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Draw a disabled button and add a tooltip
|
||||
Rect rect = listing.GetRect(30f);
|
||||
Widgets.ButtonText(rect, option.label, false, true, false);
|
||||
TooltipHandler.TipRegion(rect, GetDisabledReason(option, reason));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,5 +139,33 @@ namespace WulaFallenEmpire
|
||||
effect.Execute(this);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private string GetDisabledReason(CustomUIOption option, string reason)
|
||||
{
|
||||
if (!option.disabledReason.NullOrEmpty())
|
||||
{
|
||||
return option.disabledReason;
|
||||
}
|
||||
return reason;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Verse;
|
||||
using RimWorld;
|
||||
|
||||
@@ -87,4 +89,101 @@ namespace WulaFallenEmpire
|
||||
return;
|
||||
}
|
||||
|
||||
Faction.OfPlayer.TryAffectGoodwillWith(faction, goodwillChange, canSendMessage: true, canSendHostilityLetter: true, reason: HistoryEventDefOf.QuestGoodwill, lookTarget: null);
|
||||
Faction targetFaction = Find.FactionManager.FirstFactionOfDef(faction);
|
||||
if (targetFaction == null)
|
||||
{
|
||||
Log.Warning($"[WulaFallenEmpire] Could not find an active faction for FactionDef '{faction.defName}'.");
|
||||
return;
|
||||
}
|
||||
|
||||
Faction.OfPlayer.TryAffectGoodwillWith(targetFaction, goodwillChange, canSendMessage: true, canSendHostilityLetter: true, reason: null, lookTarget: null);
|
||||
}
|
||||
}
|
||||
|
||||
public class Effect_SetVariable : Effect
|
||||
{
|
||||
public string name;
|
||||
public string value;
|
||||
|
||||
public override void Execute(Dialog_CustomDisplay dialog)
|
||||
{
|
||||
// Try to parse as int, then float, otherwise keep as string
|
||||
if (int.TryParse(value, out int intValue))
|
||||
{
|
||||
EventContext.SetVariable(name, intValue);
|
||||
}
|
||||
else if (float.TryParse(value, out float floatValue))
|
||||
{
|
||||
EventContext.SetVariable(name, floatValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
EventContext.SetVariable(name, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Effect_ChangeFactionRelation_FromVariable : Effect
|
||||
{
|
||||
public FactionDef faction;
|
||||
public string goodwillVariableName;
|
||||
|
||||
public override void Execute(Dialog_CustomDisplay dialog)
|
||||
{
|
||||
if (faction == null)
|
||||
{
|
||||
Log.Error("[WulaFallenEmpire] Effect_ChangeFactionRelation_FromVariable has a null faction Def.");
|
||||
return;
|
||||
}
|
||||
|
||||
Faction targetFaction = Find.FactionManager.FirstFactionOfDef(faction);
|
||||
if (targetFaction == null)
|
||||
{
|
||||
Log.Warning($"[WulaFallenEmpire] Could not find an active faction for FactionDef '{faction.defName}'.");
|
||||
return;
|
||||
}
|
||||
|
||||
int goodwillChange = EventContext.GetVariable<int>(goodwillVariableName);
|
||||
Faction.OfPlayer.TryAffectGoodwillWith(targetFaction, goodwillChange, canSendMessage: true, canSendHostilityLetter: true, reason: null, lookTarget: null);
|
||||
}
|
||||
}
|
||||
|
||||
public class Effect_SpawnPawnAndStore : Effect
|
||||
{
|
||||
public PawnKindDef kindDef;
|
||||
public int count = 1;
|
||||
public string storeAs;
|
||||
|
||||
public override void Execute(Dialog_CustomDisplay dialog)
|
||||
{
|
||||
if (kindDef == null)
|
||||
{
|
||||
Log.Error("[WulaFallenEmpire] Effect_SpawnPawnAndStore has a null kindDef.");
|
||||
return;
|
||||
}
|
||||
if (storeAs.NullOrEmpty())
|
||||
{
|
||||
Log.Error("[WulaFallenEmpire] Effect_SpawnPawnAndStore needs a 'storeAs' variable name.");
|
||||
return;
|
||||
}
|
||||
|
||||
List<Pawn> spawnedPawns = new List<Pawn>();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
Pawn newPawn = PawnGenerator.GeneratePawn(kindDef, Faction.OfPlayer);
|
||||
IntVec3 loc = CellFinder.RandomSpawnCellForPawnNear(Find.CurrentMap.mapPawns.FreeColonists.First().Position, Find.CurrentMap, 10);
|
||||
GenSpawn.Spawn(newPawn, loc, Find.CurrentMap);
|
||||
spawnedPawns.Add(newPawn);
|
||||
}
|
||||
|
||||
if (count == 1)
|
||||
{
|
||||
EventContext.SetVariable(storeAs, spawnedPawns.First());
|
||||
}
|
||||
else
|
||||
{
|
||||
EventContext.SetVariable(storeAs, spawnedPawns);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
52
Source/WulaFallenEmpire/EventContext.cs
Normal file
52
Source/WulaFallenEmpire/EventContext.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System.Collections.Generic;
|
||||
using Verse;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public static class EventContext
|
||||
{
|
||||
private static Dictionary<string, object> variables = new Dictionary<string, object>();
|
||||
|
||||
public static void SetVariable(string name, object value)
|
||||
{
|
||||
if (variables.ContainsKey(name))
|
||||
{
|
||||
variables[name] = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
variables.Add(name, value);
|
||||
}
|
||||
Log.Message($"[EventContext] Set variable '{name}' to '{value}'.");
|
||||
}
|
||||
|
||||
public static T GetVariable<T>(string name, T defaultValue = default)
|
||||
{
|
||||
if (variables.TryGetValue(name, out object value))
|
||||
{
|
||||
if (value is T typedValue)
|
||||
{
|
||||
return typedValue;
|
||||
}
|
||||
// Try to convert, e.g., from int to float
|
||||
try
|
||||
{
|
||||
return (T)System.Convert.ChangeType(value, typeof(T));
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
Log.Warning($"[EventContext] Variable '{name}' is of type {value.GetType()} but could not be converted to {typeof(T)}.");
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
Log.Warning($"[EventContext] Variable '{name}' not found. Returning default value.");
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public static void Clear()
|
||||
{
|
||||
variables.Clear();
|
||||
Log.Message("[EventContext] All variables cleared.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,6 +106,8 @@
|
||||
<Compile Include="CustomUIDef.cs" />
|
||||
<Compile Include="Effect.cs" />
|
||||
<Compile Include="DebugActions.cs" />
|
||||
<Compile Include="EventContext.cs" />
|
||||
<Compile Include="Condition.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
||||
|
||||
Reference in New Issue
Block a user