This commit is contained in:
2025-10-14 18:47:56 +08:00
parent 4d4c0a1da7
commit 226ef22fb7
10 changed files with 38 additions and 225 deletions

View File

@@ -271,7 +271,6 @@
<Compile Include="PowerArmor\CompPowerArmorStation.cs" />
<Compile Include="PowerArmor\Gizmo_StructurePanel.cs" />
<Compile Include="PowerArmor\JobDriver_EnterPowerArmor.cs" />
<Compile Include="PowerArmor\Gizmo_FuelPanel.cs" />
<Compile Include="PowerArmor\Harmony_ThingWithComps_GetFloatMenuOptions.cs" />
</ItemGroup>
<ItemGroup>

View File

@@ -56,28 +56,23 @@ namespace ArachnaeSwarm
#region Ticker
protected override void Tick()
{
base.Tick(); // Call Apparel's Tick
if (this.Wearer == null) return; // Only tick if worn
base.Tick();
if (this.Wearer == null) return;
var fuelComp = this.GetComp<CompRefuelableNutrition>();
if (fuelComp != null)
{
// Explicitly call the component's Tick method to ensure fuel consumption logic is executed.
// This is needed because Apparel's base Tick does not automatically call component Ticks.
// First, update consumption rate and hediffs
if (this.Wearer.IsHashIntervalTick(60)) // Check every second
// Set the consumption rate on every tick. This value is then used by CompRefuelableNutrition's CompTick.
// We use the value from our PowerArmorExtension, ensuring it's always active.
fuelComp.currentConsumptionRate = Ext?.fuelConsumptionRate ?? 0f;
// We must explicitly call the component's Tick, as Apparel's base Tick does not.
// This will trigger the consumption logic inside CompRefuelableNutrition.
fuelComp.CompTick();
// Handle hediff for empty fuel, checked frequently for responsiveness.
if (this.Wearer.IsHashIntervalTick(60))
{
if (this.Wearer.pather != null && this.Wearer.pather.MovingNow)
{
fuelComp.currentConsumptionRate = Ext?.fuelConsumptionRate ?? 0.5f;
}
else
{
fuelComp.currentConsumptionRate = 0f;
}
// Handle hediff for empty fuel
var hediffDef = Ext?.hediffOnEmptyFuel;
if (hediffDef != null)
{
@@ -98,10 +93,8 @@ namespace ArachnaeSwarm
}
}
}
// Then, explicitly call the component's Tick method to ensure fuel consumption logic is executed with the UPDATED rate.
fuelComp.CompTick();
}
} // Correctly close the Tick method
}
#endregion
#region Data
@@ -125,11 +118,15 @@ namespace ArachnaeSwarm
// Yield our custom structure points gizmo.
yield return new Gizmo_StructurePanel(this);
// Yield our custom fuel panel gizmo.
// Yield the default gizmos from the CompRefuelable component.
// This will provide the standard RimWorld fuel gizmo.
var fuelComp = this.GetComp<CompRefuelableNutrition>();
if (fuelComp != null)
{
yield return new Gizmo_FuelPanel(fuelComp);
foreach (var gizmo in fuelComp.CompGetGizmosExtra())
{
yield return gizmo;
}
}
}
#endregion
@@ -183,9 +180,12 @@ namespace ArachnaeSwarm
GenPlace.TryPlaceThing(building, pawn.Position, pawn.Map, ThingPlaceMode.Near);
Log.Message($"[PA_Debug] Notify_Unequipped: After spawning building (ID: {building.thingIDNumber}) - HitPoints: {building.HitPoints}, StackCount: {building.stackCount}");
// Destroy the apparel to prevent duplication
this.Destroy(DestroyMode.Vanish);
Log.Message($"[PA_Debug] Notify_Unequipped: Apparel {this.Label} (ID: {this.thingIDNumber}) destroyed.");
// To prevent the game from spawning a duplicate item, we must destroy the apparel.
// However, using DestroyMode.Vanish or Kill can cause "Spawning destroyed thing" errors
// if called directly within Notify_Unequipped.
// DestroyMode.QuestLogic is the correct way: it marks the thing as destroyed
// but defers the actual cleanup until the end of the current tick, avoiding race conditions.
this.Destroy(DestroyMode.QuestLogic);
}
#endregion

View File

@@ -1,55 +0,0 @@
using UnityEngine;
using Verse;
using RimWorld; // For SolidColorMaterials
namespace ArachnaeSwarm
{
[StaticConstructorOnStartup]
public class Gizmo_FuelPanel : Gizmo
{
private static readonly Texture2D FullBarTex = SolidColorMaterials.NewSolidColorTexture(new Color(0.9f, 0.7f, 0.2f)); // Orange for fuel
private static readonly Texture2D EmptyBarTex = SolidColorMaterials.NewSolidColorTexture(new Color(0.1f, 0.1f, 0.1f));
private CompRefuelableNutrition fuelComp;
public Gizmo_FuelPanel(CompRefuelableNutrition fuelComp)
{
this.fuelComp = fuelComp;
this.Order = -90f; // Slightly higher order than structure panel
}
public override float GetWidth(float maxWidth)
{
return 140f;
}
public override GizmoResult GizmoOnGUI(Vector2 topLeft, float maxWidth, GizmoRenderParms parms)
{
Rect overRect = new Rect(topLeft.x, topLeft.y, GetWidth(maxWidth), 75f);
Find.WindowStack.ImmediateWindow(984989, overRect, WindowLayer.GameUI, delegate
{
Rect rect = overRect.AtZero().ContractedBy(6f);
// Draw label
Rect labelRect = rect;
labelRect.height = overRect.height / 2f;
Text.Font = GameFont.Tiny;
Widgets.Label(labelRect, "Fuel".Translate()); // Use "Fuel" or custom text
// Draw bar
Rect barRect = rect;
barRect.yMin = overRect.height / 2f;
float fillPercent = fuelComp.FuelPercentOfMax;
Widgets.FillableBar(barRect, fillPercent, FullBarTex, EmptyBarTex, false);
// Draw text on bar
Text.Font = GameFont.Small;
Text.Anchor = TextAnchor.MiddleCenter;
Widgets.Label(barRect, $"{fuelComp.Fuel:F0} / {fuelComp.Props.fuelCapacity:F0}");
Text.Anchor = TextAnchor.UpperLeft;
});
return new GizmoResult(GizmoState.Clear);
}
}
}

View File

@@ -6,9 +6,8 @@ namespace ArachnaeSwarm
[StaticConstructorOnStartup]
public class Gizmo_StructurePanel : Gizmo
{
private static readonly Texture2D FullBarTex = SolidColorMaterials.NewSolidColorTexture(new Color(0.2f, 0.8f, 0.2f));
private static readonly Texture2D EmptyBarTex = SolidColorMaterials.NewSolidColorTexture(new Color(0.1f, 0.1f, 0.1f));
private static readonly Texture2D UnderflowBarTex = SolidColorMaterials.NewSolidColorTexture(new Color(0.9f, 0.1f, 0.1f));
private static readonly Texture2D FullBarTex = SolidColorMaterials.NewSolidColorTexture(new Color(0.2f, 0.2f, 0.24f));
private static readonly Texture2D EmptyBarTex = SolidColorMaterials.NewSolidColorTexture(Color.clear);
private IStructurePoints armor;
@@ -41,6 +40,7 @@ namespace ArachnaeSwarm
barRect.yMin = overRect.height / 2f;
float fillPercent = armor.StructurePointsPercent;
// Use the colors from the Exosuit example
Widgets.FillableBar(barRect, fillPercent, FullBarTex, EmptyBarTex, false);
// Draw text on bar

View File

@@ -50,8 +50,8 @@ namespace ArachnaeSwarm
apparelFuelComp.ReceiveFuel(buildingFuelComp.Fuel);
}
// Wear the apparel
actor.apparel.Wear(apparel, true, true);
// Wear the apparel, ensuring it's not locked.
actor.apparel.Wear(apparel, false, true);
// Despawn the building
building.DeSpawn();