84 lines
3.3 KiB
C#
84 lines
3.3 KiB
C#
using RimWorld;
|
|
using UnityEngine;
|
|
using Verse;
|
|
using Verse.Sound;
|
|
|
|
namespace ArachnaeSwarm
|
|
{
|
|
public class GestaltBandwidthGizmo : Gizmo
|
|
{
|
|
private Pawn_GestaltTracker tracker;
|
|
|
|
public GestaltBandwidthGizmo(Pawn_GestaltTracker tracker)
|
|
{
|
|
this.tracker = tracker;
|
|
this.Order = -90f; // 放在最前面
|
|
}
|
|
|
|
public override bool Visible => tracker != null && tracker.Pawn != null && tracker.Pawn.IsGestaltNode(GestaltNodeType.OverlordNode);
|
|
|
|
public override float GetWidth(float maxWidth)
|
|
{
|
|
return 140f;
|
|
}
|
|
|
|
public override GizmoResult GizmoOnGUI(Vector2 topLeft, float maxWidth, GizmoRenderParms parms)
|
|
{
|
|
Rect rect = new Rect(topLeft.x, topLeft.y, GetWidth(maxWidth), 75f);
|
|
Rect rect2 = rect.ContractedBy(6f);
|
|
|
|
// 背景
|
|
GUI.color = parms.lowLight ? Command.LowLightBgColor : Color.white;
|
|
GenUI.DrawTextureWithMaterial(rect, Command.BGTex, null);
|
|
GUI.color = Color.white;
|
|
|
|
// 标题
|
|
Text.Font = GameFont.Tiny;
|
|
Text.Anchor = TextAnchor.UpperCenter;
|
|
Widgets.Label(new Rect(rect2.x, rect2.y, rect2.width, 18f), "ARA_GestaltBandwidth".Translate());
|
|
|
|
// 带宽条
|
|
Rect barRect = new Rect(rect2.x, rect2.y + 20f, rect2.width, 20f);
|
|
float fillPercent = (float)tracker.UsedBandwidth / tracker.TotalBandwidth;
|
|
Widgets.FillableBar(barRect, fillPercent, SolidColorMaterials.NewSolidColorTexture(new Color(0.2f, 0.6f, 0.8f)));
|
|
|
|
// 带宽文本
|
|
Text.Font = GameFont.Small;
|
|
Text.Anchor = TextAnchor.MiddleCenter;
|
|
string bandwidthText = $"{tracker.UsedBandwidth}/{tracker.TotalBandwidth}";
|
|
Widgets.Label(barRect, bandwidthText);
|
|
|
|
// 控制组数量
|
|
Rect groupRect = new Rect(rect2.x, rect2.y + 45f, rect2.width, 20f);
|
|
Text.Font = GameFont.Tiny;
|
|
Text.Anchor = TextAnchor.MiddleLeft;
|
|
string groupText = "ARA_GestaltGroup".Translate() + $": {tracker.ControlGroups.Count}/{tracker.TotalAvailableControlGroups}";
|
|
Widgets.Label(groupRect, groupText);
|
|
|
|
Text.Anchor = TextAnchor.UpperLeft;
|
|
Text.Font = GameFont.Small;
|
|
|
|
// 鼠标悬停提示
|
|
if (Mouse.IsOver(rect))
|
|
{
|
|
TooltipHandler.TipRegion(rect, () =>
|
|
{
|
|
string tip = "ARA_GestaltBandwidthTip".Translate(tracker.UsedBandwidth, tracker.TotalBandwidth);
|
|
tip += $"\n\n{"ARA_GestaltGroup".Translate()}: {tracker.ControlGroups.Count}/{tracker.TotalAvailableControlGroups}";
|
|
|
|
if (tracker.UsedBandwidth > tracker.TotalBandwidth)
|
|
{
|
|
tip += $"\n\n{"ARA_GestaltBandwidthExceeded".Translate()}".Colorize(Color.red);
|
|
}
|
|
|
|
return tip;
|
|
}, 7234342);
|
|
|
|
Widgets.DrawHighlight(rect);
|
|
}
|
|
|
|
return new GizmoResult(GizmoState.Clear);
|
|
}
|
|
}
|
|
}
|