55 lines
2.0 KiB
C#
55 lines
2.0 KiB
C#
using UnityEngine;
|
|
using Verse;
|
|
|
|
namespace ArachnaeSwarm
|
|
{
|
|
[StaticConstructorOnStartup]
|
|
public class Gizmo_StructurePanel : Gizmo
|
|
{
|
|
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;
|
|
|
|
public Gizmo_StructurePanel(IStructurePoints armor)
|
|
{
|
|
this.armor = armor;
|
|
this.Order = -100f; // Correctly use the 'Order' property
|
|
}
|
|
|
|
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(984988, 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, armor.Label);
|
|
|
|
// Draw bar
|
|
Rect barRect = rect;
|
|
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
|
|
Text.Font = GameFont.Small;
|
|
Text.Anchor = TextAnchor.MiddleCenter;
|
|
Widgets.Label(barRect, $"{armor.StructurePoints:F0} / {armor.StructurePointsMax:F0}");
|
|
Text.Anchor = TextAnchor.UpperLeft;
|
|
});
|
|
return new GizmoResult(GizmoState.Clear);
|
|
}
|
|
}
|
|
} |