UI
This commit is contained in:
@@ -8,33 +8,72 @@ using UnityEngine.UIElements;
|
||||
namespace ProjectM.Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Client-only screen HUD, rebuilt on UI Toolkit so it reads in the same Aether-cyan visual language as the
|
||||
/// menu / pause / settings screens (<see cref="MenuUi"/> / <see cref="HudUi"/>). A managed presentation
|
||||
/// SystemBase (<see cref="PresentationSystemGroup"/>) that OBSERVES the local player ghost + the global
|
||||
/// cycle / ledger / goal each frame and pushes values into a runtime UIDocument (shared PanelSettings,
|
||||
/// sortingOrder 50 so it sits BEHIND the pause overlay's 100). The root is <c>pickingMode = Ignore</c> so the
|
||||
/// HUD never eats clicks meant for the game world — only the build-palette buttons pick. Presentation only
|
||||
/// (client world, no simulation). The palette buttons set <see cref="BuildPaletteState"/> (client-local UI
|
||||
/// state), which BuildSendSystem turns into a ground ghost + click-to-place. The visual tree is built on the
|
||||
/// first OnUpdate where the UIDocument's root exists (giving the panel a frame to initialise its PanelSettings).
|
||||
/// Client-only screen HUD on UI Toolkit, skinned with the curated Synty sci-fi-soldier kit
|
||||
/// (<see cref="HudTheme"/>) over <see cref="MenuUi"/>'s Aether palette so it reads in one visual language with
|
||||
/// the menu / pause / settings. A managed presentation <see cref="SystemBase"/> (<see cref="PresentationSystemGroup"/>)
|
||||
/// that OBSERVES the local player ghost + the global cycle / ledger / goal each frame and pushes values into a
|
||||
/// runtime UIDocument (shared PanelSettings, sortingOrder 50 so it sits behind the pause overlay's 100). The
|
||||
/// root is <c>pickingMode = Ignore</c> so the HUD never eats world clicks — only the build-palette slots pick.
|
||||
/// Layout (good-HUD spatial convention): persistent self-state hugs the corners (health bottom-left, resources
|
||||
/// top-left, threat top-right, build deck bottom-center); transient mission state (phase / countdown / wave /
|
||||
/// goal) lives center-top; a low-health vignette + hurt-flash + a scheme-aware build-mode control-hint bar give
|
||||
/// just-in-time feedback. EVERY skinned element is null-safe: with no <see cref="HudTheme"/> it falls back to
|
||||
/// the flat-colour HUD. Presentation only (client world, no simulation, no rollback double-fire).
|
||||
/// </summary>
|
||||
[WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation)]
|
||||
[UpdateInGroup(typeof(PresentationSystemGroup))]
|
||||
public partial class HudSystem : SystemBase
|
||||
{
|
||||
// ---- palette (Aether language; Synty white skins are tinted into these) ----
|
||||
static readonly Color AetherCyan = new(0.30f, 0.85f, 1f);
|
||||
static readonly Color OreAmber = new(1f, 0.72f, 0.35f);
|
||||
static readonly Color BioGreen = new(0.55f, 0.85f, 0.45f);
|
||||
static readonly Color PanelDark = new(0.08f, 0.11f, 0.15f, 0.90f);
|
||||
static readonly Color PanelWarm = new(0.16f, 0.09f, 0.09f, 0.88f);
|
||||
static readonly Color PipDim = new(0.25f, 0.30f, 0.36f, 0.9f);
|
||||
static readonly Color BlightRed = new(0.85f, 0.10f, 0.08f);
|
||||
static readonly Color ThreatWarm = new(1f, 0.62f, 0.4f);
|
||||
static readonly Color SlotIdleBg = new(0.09f, 0.11f, 0.15f, 0.92f);
|
||||
static readonly Color SlotSelBg = new(0.16f, 0.26f, 0.32f, 0.95f);
|
||||
static readonly Color SlotIdleBorder = new(1f, 1f, 1f, 0.08f);
|
||||
const int MaxPips = 12;
|
||||
const float ExpeditionRegionXMin = 500f; // camera x past this = the +1000 expedition region (DR-013)
|
||||
|
||||
GameObject _hudGo;
|
||||
UIDocument _doc;
|
||||
bool _built;
|
||||
bool _themed; // HudTheme + PanelBox present (drives sprite-tint vs flat-colour retint)
|
||||
|
||||
VisualElement _healthFill, _cooldownFill, _goalFill, _downed, _paletteRow;
|
||||
Label _healthText, _threatText, _phaseText, _resourceText, _locationText, _goalText;
|
||||
// vitals
|
||||
VisualElement _healthFill, _cooldownFill, _shieldRow, _cdRow;
|
||||
Label _healthText;
|
||||
|
||||
bool _paletteBuilt;
|
||||
// threat
|
||||
VisualElement _threatPanel, _threatIcon;
|
||||
Label _threatNum;
|
||||
|
||||
// macro: banner + location + goal
|
||||
VisualElement _banner, _goalContainer, _goalPipsRow, _goalBar, _goalFill;
|
||||
Label _phaseText, _cycleText, _locationText, _goalText;
|
||||
readonly List<VisualElement> _pips = new();
|
||||
|
||||
// resources
|
||||
Label _aetherNum, _oreNum, _bioNum;
|
||||
|
||||
// build palette + hints
|
||||
VisualElement _paletteRow, _hintBar, _facingArrow;
|
||||
bool _paletteBuilt, _hintBuilt, _hintConveyor;
|
||||
byte _hintScheme = 255;
|
||||
readonly Dictionary<byte, PaletteItem> _palette = new();
|
||||
|
||||
// overlays
|
||||
VisualElement _vignette, _downed;
|
||||
float _prevHp, _flash;
|
||||
bool _haveHp;
|
||||
|
||||
EntityQuery _huskQuery;
|
||||
|
||||
struct PaletteItem { public VisualElement Root; public Label Cost; public int CostAmount; }
|
||||
struct PaletteItem { public VisualElement Root; public Label Cost; public int CostAmount; public byte CostRes; public VisualElement Glow; public VisualElement Icon; }
|
||||
|
||||
protected override void OnCreate()
|
||||
{
|
||||
@@ -67,46 +106,84 @@ namespace ProjectM.Client
|
||||
_built = true;
|
||||
}
|
||||
|
||||
// Job-safety insurance (matches the sibling presentation systems + CLAUDE.md): finish any jobs writing
|
||||
// the components we read on the main thread before reading them. No job writes these today, but this
|
||||
// stays correct the day a Health/stats writer is parallelised.
|
||||
EntityManager.CompleteDependencyBeforeRO<Health>();
|
||||
EntityManager.CompleteDependencyBeforeRO<EffectiveCharacterStats>();
|
||||
EntityManager.CompleteDependencyBeforeRO<EffectiveAbilityStats>();
|
||||
EntityManager.CompleteDependencyBeforeRO<AbilityCooldown>();
|
||||
EntityManager.CompleteDependencyBeforeRO<RespawnInvuln>();
|
||||
|
||||
float dt = SystemAPI.Time.DeltaTime; // wall-frame delta — correct in a presentation system
|
||||
bool haveTick = SystemAPI.TryGetSingleton<NetworkTime>(out var nt);
|
||||
int huskCount = _huskQuery.CalculateEntityCount();
|
||||
|
||||
// ---- Macro loop: phase + cycle + countdown ----
|
||||
// ---- Macro: phase + cycle + countdown (center-top banner) ----
|
||||
bool haveCycle = SystemAPI.TryGetSingleton<CycleState>(out var cyc);
|
||||
bool siege = haveCycle && cyc.Phase == CyclePhase.Siege;
|
||||
if (haveCycle)
|
||||
{
|
||||
var endTick = new NetworkTick(cyc.PhaseEndTick);
|
||||
string detail;
|
||||
if (cyc.Phase == CyclePhase.Siege)
|
||||
if (siege)
|
||||
detail = "WAVE " + cyc.WaveNumber + " - " + huskCount + " HUSKS";
|
||||
else if (haveTick && cyc.PhaseEndTick != 0 && endTick.IsValid && endTick.IsNewerThan(nt.ServerTick))
|
||||
detail = "INCURSION IN " + (endTick.TicksSince(nt.ServerTick) / 60 + 1) + "s";
|
||||
else
|
||||
detail = "";
|
||||
var col = PhaseColor(cyc.Phase);
|
||||
_phaseText.text = PhaseLabel(cyc.Phase) + (detail.Length > 0 ? " - " + detail : "");
|
||||
_phaseText.style.color = PhaseColor(cyc.Phase);
|
||||
_phaseText.style.color = col;
|
||||
_cycleText.text = "CYCLE " + cyc.CycleNumber;
|
||||
_banner.style.borderBottomColor = col;
|
||||
RetintPanel(_banner, siege ? PanelWarm : PanelDark);
|
||||
}
|
||||
else
|
||||
{
|
||||
_phaseText.text = "";
|
||||
_cycleText.text = "";
|
||||
}
|
||||
|
||||
// ---- Location + gate hint ----
|
||||
// ---- Location + gate hint (banner sub-line) ----
|
||||
var cam = Camera.main;
|
||||
bool onExpedition = cam != null && cam.transform.position.x > 500f;
|
||||
bool onExpedition = cam != null && cam.transform.position.x > ExpeditionRegionXMin;
|
||||
_locationText.text = onExpedition
|
||||
? "ON EXPEDITION - return through the gate"
|
||||
: "AT BASE - deploy through the gate when you're ready";
|
||||
_locationText.style.color = onExpedition ? new Color(1f, 0.8f, 0.4f) : new Color(0.6f, 0.85f, 1f);
|
||||
|
||||
// ---- Goal ----
|
||||
// ---- Goal (hex-pip meter, or a continuous bar for large targets) ----
|
||||
if (SystemAPI.TryGetSingleton<GoalProgress>(out var goal))
|
||||
{
|
||||
_goalContainer.style.display = DisplayStyle.Flex;
|
||||
float gfrac = goal.Target > 0 ? Mathf.Clamp01(goal.Charge / (float)goal.Target) : 0f;
|
||||
HudUi.SetFill(_goalFill, gfrac);
|
||||
_goalText.text = "GOAL " + goal.Charge + " / " + goal.Target;
|
||||
if (goal.Target >= 1 && goal.Target <= MaxPips)
|
||||
{
|
||||
_goalPipsRow.style.display = DisplayStyle.Flex;
|
||||
_goalBar.style.display = DisplayStyle.None;
|
||||
int active = Mathf.Min(goal.Charge, goal.Target); // Charge is the integer pip count; never over-fill
|
||||
for (int i = 0; i < _pips.Count; i++)
|
||||
{
|
||||
bool show = i < goal.Target;
|
||||
_pips[i].style.display = show ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
if (show) SetPip(_pips[i], i < active);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_goalPipsRow.style.display = DisplayStyle.None;
|
||||
_goalBar.style.display = DisplayStyle.Flex;
|
||||
HudUi.SetFill(_goalFill, gfrac);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_goalContainer.style.display = DisplayStyle.None;
|
||||
}
|
||||
|
||||
// ---- Resources (Ore feeds the palette affordability) ----
|
||||
// ---- Resources (feed palette affordability) ----
|
||||
int aether = 0, ore = 0, bio = 0;
|
||||
if (SystemAPI.TryGetSingletonEntity<ResourceLedger>(out var ledgerE))
|
||||
{
|
||||
@@ -119,10 +196,39 @@ namespace ProjectM.Client
|
||||
else if (en.ItemId == ResourceId.Biomass) bio = en.Count;
|
||||
}
|
||||
}
|
||||
_resourceText.text = "AETHER " + aether + " ORE " + ore + " BIO " + bio;
|
||||
_aetherNum.text = aether.ToString();
|
||||
_oreNum.text = ore.ToString();
|
||||
_bioNum.text = bio.ToString();
|
||||
|
||||
// ---- Build palette (lazy-built once the catalog has streamed; hidden off-base) ----
|
||||
UpdatePalette(ore, onExpedition);
|
||||
// ---- Threat readout (top-right) — hidden entirely at base with zero husks; its reappearance is the cue ----
|
||||
bool showThreat = siege || huskCount > 0;
|
||||
_threatPanel.style.display = showThreat ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
if (showThreat)
|
||||
{
|
||||
float intensity = Mathf.Clamp01(huskCount / 30f);
|
||||
Color tc = siege ? Color.Lerp(ThreatWarm, BlightRed, intensity) : ThreatWarm;
|
||||
_threatNum.text = huskCount.ToString();
|
||||
_threatNum.style.color = tc;
|
||||
_threatIcon.style.unityBackgroundImageTintColor = tc;
|
||||
RetintPanel(_threatPanel, siege ? PanelWarm : PanelDark);
|
||||
}
|
||||
|
||||
// ---- Build palette + control hints (bottom-center) ----
|
||||
UpdatePalette(aether, ore, bio, onExpedition);
|
||||
bool buildActive = BuildPaletteState.Active && !onExpedition && _paletteBuilt;
|
||||
if (buildActive)
|
||||
{
|
||||
byte scheme = AimPresentation.Scheme;
|
||||
bool conv = BuildPaletteState.Selected == StructureType.Conveyor;
|
||||
if (!_hintBuilt || _hintScheme != scheme || _hintConveyor != conv) RebuildHints(scheme, conv);
|
||||
if (conv && _facingArrow != null)
|
||||
_facingArrow.style.rotate = new StyleRotate(new Rotate(new Angle(FacingDegrees(BuildPaletteState.Direction))));
|
||||
_hintBar.style.display = DisplayStyle.Flex;
|
||||
}
|
||||
else
|
||||
{
|
||||
_hintBar.style.display = DisplayStyle.None;
|
||||
}
|
||||
|
||||
// ---- Per-player vitals ----
|
||||
bool found = false;
|
||||
@@ -153,27 +259,71 @@ namespace ProjectM.Client
|
||||
}
|
||||
|
||||
_doc.rootVisualElement.style.display = (found || haveCycle) ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
if (!found) { _downed.style.display = DisplayStyle.None; return; }
|
||||
|
||||
float frac = maxHp > 0f ? Mathf.Clamp01(hp / maxHp) : 0f;
|
||||
HudUi.SetFill(_healthFill, frac);
|
||||
_healthFill.style.backgroundColor = shielded
|
||||
? new Color(0.45f, 0.85f, 1f)
|
||||
: Color.Lerp(new Color(0.92f, 0.16f, 0.16f), new Color(0.25f, 0.9f, 0.5f), frac);
|
||||
_healthText.text = Mathf.CeilToInt(Mathf.Max(0f, hp)) + " / " + Mathf.CeilToInt(maxHp) + (shielded ? " SHIELDED" : "");
|
||||
// ---- Low-health vignette + hurt flash (full-screen) ----
|
||||
_flash = HudVisualMath.DecayFlash(_flash, dt);
|
||||
if (found)
|
||||
{
|
||||
float frac = maxHp > 0f ? Mathf.Clamp01(hp / maxHp) : 0f;
|
||||
if (_haveHp && hp < _prevHp - 1f) _flash = HudVisualMath.HurtFlashKick;
|
||||
_prevHp = hp; _haveHp = true;
|
||||
|
||||
HudUi.SetFill(_cooldownFill, cdFrac);
|
||||
_threatText.text = "HUSKS " + huskCount;
|
||||
_downed.style.display = dead ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
float vigOp = dead ? 0f : HudVisualMath.CombinedOpacity(frac, _flash);
|
||||
_vignette.style.opacity = vigOp;
|
||||
_vignette.style.display = vigOp > 0.001f ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
|
||||
HudUi.SetFill(_healthFill, frac);
|
||||
_healthFill.style.backgroundColor = shielded
|
||||
? new Color(0.45f, 0.85f, 1f)
|
||||
: Color.Lerp(new Color(0.92f, 0.16f, 0.16f), new Color(0.25f, 0.9f, 0.5f), frac);
|
||||
_healthText.text = Mathf.CeilToInt(Mathf.Max(0f, hp)) + " / " + Mathf.CeilToInt(maxHp);
|
||||
_shieldRow.style.display = shielded ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
|
||||
HudUi.SetFill(_cooldownFill, cdFrac);
|
||||
// A READY weapon (full bar) recedes; a CHARGING one is bright — so the inverted-vs-health polarity reads.
|
||||
if (_cdRow != null) _cdRow.style.opacity = cdFrac >= 1f ? 0.4f : 1f;
|
||||
_downed.style.display = dead ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
}
|
||||
else
|
||||
{
|
||||
_haveHp = false; _flash = 0f;
|
||||
_vignette.style.display = DisplayStyle.None;
|
||||
_downed.style.display = DisplayStyle.None;
|
||||
}
|
||||
}
|
||||
|
||||
void UpdatePalette(int ore, bool onExpedition)
|
||||
// ---- per-frame helpers ----
|
||||
|
||||
void RetintPanel(VisualElement p, Color c)
|
||||
{
|
||||
if (_themed) p.style.unityBackgroundImageTintColor = c;
|
||||
else p.style.backgroundColor = c;
|
||||
}
|
||||
|
||||
void SetPip(VisualElement pip, bool active)
|
||||
{
|
||||
var theme = HudTheme.Get();
|
||||
var spr = active ? theme?.PipActive : theme?.PipInactive;
|
||||
if (spr != null)
|
||||
{
|
||||
pip.style.backgroundImage = new StyleBackground(Background.FromSprite(spr));
|
||||
pip.style.unityBackgroundImageTintColor = active ? AetherCyan : PipDim;
|
||||
pip.style.backgroundSize = new StyleBackgroundSize(new BackgroundSize(BackgroundSizeType.Contain));
|
||||
}
|
||||
else
|
||||
{
|
||||
pip.style.backgroundColor = active ? AetherCyan : PipDim;
|
||||
MenuUi.Round(pip, 3);
|
||||
}
|
||||
}
|
||||
|
||||
void UpdatePalette(int aether, int ore, int bio, bool onExpedition)
|
||||
{
|
||||
if (!_paletteBuilt && SystemAPI.TryGetSingletonEntity<StructureCatalog>(out var catE))
|
||||
{
|
||||
var cat = SystemAPI.GetBuffer<StructureCatalogEntry>(catE);
|
||||
for (int i = 0; i < cat.Length; i++)
|
||||
AddPaletteItem(cat[i].Type, cat[i].CostAmount);
|
||||
AddPaletteItem(cat[i].Type, cat[i].CostAmount, cat[i].CostResourceId);
|
||||
_paletteBuilt = true;
|
||||
}
|
||||
if (!_paletteBuilt) { _paletteRow.style.display = DisplayStyle.None; return; }
|
||||
@@ -182,116 +332,419 @@ namespace ProjectM.Client
|
||||
foreach (var kv in _palette)
|
||||
{
|
||||
var item = kv.Value;
|
||||
bool affordable = ore >= item.CostAmount;
|
||||
int have = item.CostRes == ResourceId.Aether ? aether : item.CostRes == ResourceId.Biomass ? bio : ore;
|
||||
bool affordable = have >= item.CostAmount;
|
||||
bool selected = BuildPaletteState.Selected == kv.Key;
|
||||
item.Root.style.opacity = affordable ? 1f : 0.45f;
|
||||
item.Root.style.opacity = affordable ? 1f : 0.5f;
|
||||
item.Cost.style.color = affordable ? new Color(0.7f, 0.95f, 0.8f) : new Color(1f, 0.5f, 0.4f);
|
||||
MenuUi.Border(item.Root, selected ? MenuUi.Accent : new Color(1f, 1f, 1f, 0.08f), selected ? 2 : 1);
|
||||
item.Root.style.backgroundColor = selected
|
||||
? new Color(0.16f, 0.26f, 0.32f, 0.95f)
|
||||
: new Color(0.09f, 0.11f, 0.15f, 0.92f);
|
||||
if (item.Icon != null)
|
||||
item.Icon.style.unityBackgroundImageTintColor = affordable ? AetherCyan : new Color(0.5f, 0.55f, 0.6f);
|
||||
MenuUi.Border(item.Root, selected ? MenuUi.Accent : SlotIdleBorder, selected ? 2 : 1);
|
||||
item.Root.style.backgroundColor = selected ? SlotSelBg : SlotIdleBg;
|
||||
if (item.Glow != null) item.Glow.style.opacity = selected ? 0.6f : 0f;
|
||||
}
|
||||
}
|
||||
|
||||
void AddPaletteItem(byte type, int cost)
|
||||
void AddPaletteItem(byte type, int cost, byte costRes)
|
||||
{
|
||||
if (type == 0 || _palette.ContainsKey(type)) return;
|
||||
var theme = HudTheme.Get();
|
||||
|
||||
var root = new VisualElement();
|
||||
root.style.width = 92;
|
||||
root.style.width = 86;
|
||||
root.style.marginLeft = 4; root.style.marginRight = 4;
|
||||
root.style.paddingTop = 6; root.style.paddingBottom = 6;
|
||||
root.style.paddingTop = 8; root.style.paddingBottom = 6;
|
||||
root.style.alignItems = Align.Center;
|
||||
root.style.backgroundColor = new Color(0.09f, 0.11f, 0.15f, 0.92f);
|
||||
root.style.backgroundColor = SlotIdleBg;
|
||||
root.pickingMode = PickingMode.Position;
|
||||
MenuUi.Round(root, 6);
|
||||
MenuUi.Border(root, new Color(1f, 1f, 1f, 0.08f), 1);
|
||||
MenuUi.Border(root, SlotIdleBorder, 1);
|
||||
|
||||
var nameLabel = HudUi.Text(StructureName(type), 13, MenuUi.TextCol, TextAnchor.MiddleCenter);
|
||||
var costLabel = HudUi.Text(cost + " ORE", 12, new Color(0.7f, 0.95f, 0.8f), TextAnchor.MiddleCenter);
|
||||
costLabel.style.marginTop = 2;
|
||||
// selection glow: a soft Synty glow filling the slot behind everything, opacity toggled on select.
|
||||
var glow = new VisualElement();
|
||||
glow.style.position = Position.Absolute;
|
||||
glow.style.left = 3; glow.style.right = 3; glow.style.top = 4; glow.style.bottom = 4;
|
||||
glow.pickingMode = PickingMode.Ignore;
|
||||
glow.style.opacity = 0f;
|
||||
if (theme != null && theme.Glow != null)
|
||||
{
|
||||
glow.style.backgroundImage = new StyleBackground(Background.FromSprite(theme.Glow));
|
||||
glow.style.unityBackgroundImageTintColor = AetherCyan;
|
||||
glow.style.backgroundSize = new StyleBackgroundSize(new BackgroundSize(BackgroundSizeType.Cover));
|
||||
}
|
||||
root.Add(glow);
|
||||
|
||||
var iconEl = HudUi.Icon(theme != null ? theme.StructureIcon(type) : null, 44, AetherCyan);
|
||||
root.Add(iconEl);
|
||||
|
||||
var nameLabel = HudUi.Text(StructureName(type), 12, MenuUi.TextCol, TextAnchor.MiddleCenter);
|
||||
nameLabel.style.marginTop = 2;
|
||||
root.Add(nameLabel);
|
||||
root.Add(costLabel);
|
||||
|
||||
var costRow = new VisualElement();
|
||||
costRow.style.flexDirection = FlexDirection.Row;
|
||||
costRow.style.alignItems = Align.Center;
|
||||
costRow.style.marginTop = 2;
|
||||
costRow.pickingMode = PickingMode.Ignore;
|
||||
var costIcon = HudUi.Icon(ResourceSprite(theme, costRes), 14, ResourceTint(costRes));
|
||||
costIcon.style.marginRight = 3;
|
||||
costRow.Add(costIcon);
|
||||
var costLabel = HudUi.Display(cost.ToString(), 13, new Color(0.7f, 0.95f, 0.8f), TextAnchor.MiddleCenter);
|
||||
costRow.Add(costLabel);
|
||||
root.Add(costRow);
|
||||
|
||||
byte t = type;
|
||||
root.RegisterCallback<ClickEvent>(_ =>
|
||||
BuildPaletteState.Select(BuildPaletteState.Selected == t ? (byte)0 : t));
|
||||
|
||||
_paletteRow.Add(root);
|
||||
_palette[type] = new PaletteItem { Root = root, Cost = costLabel, CostAmount = cost };
|
||||
_palette[type] = new PaletteItem { Root = root, Cost = costLabel, CostAmount = cost, CostRes = costRes, Glow = glow, Icon = iconEl };
|
||||
}
|
||||
|
||||
void RebuildHints(byte scheme, bool conveyor)
|
||||
{
|
||||
_hintBar.Clear();
|
||||
_facingArrow = null;
|
||||
var theme = HudTheme.Get();
|
||||
bool pad = scheme == InputSchemeId.Gamepad;
|
||||
AddHint(pad ? theme?.PadPlace : theme?.KbmPlace, pad ? "A" : "LMB", "PLACE");
|
||||
AddHint(pad ? theme?.PadCancel : theme?.KbmCancel, pad ? "B" : "RMB", "CANCEL");
|
||||
if (conveyor)
|
||||
{
|
||||
// Rotate hint + a LIVE facing arrow (resolves the DR-021 conveyor-facing indicator). Only conveyors
|
||||
// rotate, so this chip is gated to them — the other buildables don't show a meaningless ROTATE.
|
||||
var chip = MakeChip();
|
||||
chip.Add(HudUi.Glyph(pad ? theme?.PadRotate : null, pad ? "LB" : "R", 26));
|
||||
var lbl = HudUi.Text("FACING", 12, MenuUi.SubCol, TextAnchor.MiddleLeft);
|
||||
lbl.style.marginLeft = 5; lbl.style.marginRight = 6;
|
||||
chip.Add(lbl);
|
||||
_facingArrow = HudUi.Icon(theme != null ? theme.ConveyorIcon : null, 24, AetherCyan);
|
||||
chip.Add(_facingArrow);
|
||||
_hintBar.Add(chip);
|
||||
}
|
||||
AddHint(pad ? theme?.PadExit : null, pad ? "MENU" : "ESC", "EXIT");
|
||||
_hintScheme = scheme;
|
||||
_hintConveyor = conveyor;
|
||||
_hintBuilt = true;
|
||||
}
|
||||
|
||||
VisualElement MakeChip()
|
||||
{
|
||||
var chip = new VisualElement();
|
||||
chip.style.flexDirection = FlexDirection.Row;
|
||||
chip.style.alignItems = Align.Center;
|
||||
chip.style.marginLeft = 8; chip.style.marginRight = 8;
|
||||
chip.pickingMode = PickingMode.Ignore;
|
||||
return chip;
|
||||
}
|
||||
|
||||
void AddHint(Sprite glyph, string fallback, string action)
|
||||
{
|
||||
var chip = MakeChip();
|
||||
chip.Add(HudUi.Glyph(glyph, fallback, 26));
|
||||
var lbl = HudUi.Text(action, 12, MenuUi.SubCol, TextAnchor.MiddleLeft);
|
||||
lbl.style.marginLeft = 5;
|
||||
chip.Add(lbl);
|
||||
_hintBar.Add(chip);
|
||||
}
|
||||
|
||||
// ---- UITK construction ----
|
||||
|
||||
void BuildTree(VisualElement root)
|
||||
{
|
||||
var theme = HudTheme.Get();
|
||||
_themed = theme != null && theme.PanelBox != null;
|
||||
|
||||
root.style.position = Position.Absolute;
|
||||
root.style.left = 0; root.style.right = 0; root.style.top = 0; root.style.bottom = 0;
|
||||
root.pickingMode = PickingMode.Ignore; // never eat game-world clicks
|
||||
|
||||
// Health + cooldown (bottom-left).
|
||||
var vitals = HudUi.Group();
|
||||
vitals.style.position = Position.Absolute;
|
||||
vitals.style.left = 40; vitals.style.bottom = 40;
|
||||
var cdBar = HudUi.Bar(440, 12, new Color(0.4f, 0.8f, 1f), out _cooldownFill);
|
||||
cdBar.style.marginBottom = 6;
|
||||
var hpBar = HudUi.Bar(440, 40, new Color(0.25f, 0.9f, 0.5f), out _healthFill);
|
||||
_healthText = HudUi.Text("100 / 100", 22, Color.white, TextAnchor.MiddleCenter);
|
||||
BuildVignette(root);
|
||||
BuildVitals(root);
|
||||
BuildThreat(root);
|
||||
BuildMacro(root);
|
||||
BuildResources(root);
|
||||
BuildPaletteRow(root);
|
||||
BuildHintBar(root);
|
||||
BuildDowned(root);
|
||||
}
|
||||
|
||||
void BuildVignette(VisualElement root)
|
||||
{
|
||||
_vignette = new VisualElement();
|
||||
_vignette.style.position = Position.Absolute;
|
||||
_vignette.style.left = 0; _vignette.style.right = 0; _vignette.style.top = 0; _vignette.style.bottom = 0;
|
||||
_vignette.pickingMode = PickingMode.Ignore;
|
||||
var theme = HudTheme.Get();
|
||||
if (theme != null && theme.Vignette != null)
|
||||
{
|
||||
_vignette.style.backgroundImage = new StyleBackground(Background.FromSprite(theme.Vignette));
|
||||
_vignette.style.unityBackgroundImageTintColor = BlightRed;
|
||||
_vignette.style.backgroundSize = new StyleBackgroundSize(new BackgroundSize(BackgroundSizeType.Cover));
|
||||
}
|
||||
else
|
||||
{
|
||||
_vignette.style.backgroundColor = new Color(BlightRed.r, BlightRed.g, BlightRed.b, 1f);
|
||||
}
|
||||
_vignette.style.display = DisplayStyle.None;
|
||||
root.Add(_vignette);
|
||||
}
|
||||
|
||||
void BuildVitals(VisualElement root)
|
||||
{
|
||||
var panel = HudUi.Panel(PanelDark);
|
||||
panel.style.position = Position.Absolute;
|
||||
panel.style.left = 40; panel.style.bottom = 40;
|
||||
panel.style.paddingLeft = 14; panel.style.paddingRight = 14;
|
||||
panel.style.paddingTop = 12; panel.style.paddingBottom = 12;
|
||||
panel.style.alignItems = Align.FlexStart;
|
||||
var theme = HudTheme.Get();
|
||||
|
||||
// shield chip (shown only while the respawn shield is active)
|
||||
_shieldRow = new VisualElement();
|
||||
_shieldRow.style.flexDirection = FlexDirection.Row;
|
||||
_shieldRow.style.alignItems = Align.Center;
|
||||
_shieldRow.style.marginBottom = 6;
|
||||
_shieldRow.pickingMode = PickingMode.Ignore;
|
||||
var shieldIcon = HudUi.Icon(theme != null ? theme.ShieldIcon : null, 22, AetherCyan);
|
||||
shieldIcon.style.marginRight = 6;
|
||||
_shieldRow.Add(shieldIcon);
|
||||
_shieldRow.Add(HudUi.Text("SHIELDED", 13, new Color(0.45f, 0.85f, 1f), TextAnchor.MiddleLeft));
|
||||
_shieldRow.style.display = DisplayStyle.None;
|
||||
panel.Add(_shieldRow);
|
||||
|
||||
// cooldown row: weapon icon + thin bar
|
||||
_cdRow = new VisualElement();
|
||||
_cdRow.style.flexDirection = FlexDirection.Row;
|
||||
_cdRow.style.alignItems = Align.Center;
|
||||
_cdRow.style.marginBottom = 6;
|
||||
_cdRow.pickingMode = PickingMode.Ignore;
|
||||
var cdIcon = HudUi.Icon(theme != null ? theme.CooldownIcon : null, 22, AetherCyan);
|
||||
cdIcon.style.marginRight = 8;
|
||||
_cdRow.Add(cdIcon);
|
||||
var cdBar = HudUi.Bar(420, 12, new Color(0.4f, 0.8f, 1f), out _cooldownFill);
|
||||
_cdRow.Add(cdBar);
|
||||
panel.Add(_cdRow);
|
||||
|
||||
// health row: health icon + big bar with numeric overlay
|
||||
var hpRow = new VisualElement();
|
||||
hpRow.style.flexDirection = FlexDirection.Row;
|
||||
hpRow.style.alignItems = Align.Center;
|
||||
hpRow.pickingMode = PickingMode.Ignore;
|
||||
var hpIcon = HudUi.Icon(theme != null ? theme.HealthIcon : null, 34, new Color(0.95f, 0.4f, 0.4f));
|
||||
hpIcon.style.marginRight = 8;
|
||||
hpRow.Add(hpIcon);
|
||||
var hpBar = HudUi.Bar(420, 40, new Color(0.25f, 0.9f, 0.5f), out _healthFill);
|
||||
_healthText = HudUi.Display("100 / 100", 24, Color.white, TextAnchor.MiddleCenter);
|
||||
_healthText.style.position = Position.Absolute;
|
||||
_healthText.style.left = 0; _healthText.style.right = 0; _healthText.style.top = 0; _healthText.style.bottom = 0;
|
||||
hpBar.Add(_healthText);
|
||||
vitals.Add(cdBar);
|
||||
vitals.Add(hpBar);
|
||||
root.Add(vitals);
|
||||
hpRow.Add(hpBar);
|
||||
panel.Add(hpRow);
|
||||
|
||||
// Threat (top-right).
|
||||
_threatText = HudUi.Text("HUSKS 0", 30, new Color(1f, 0.62f, 0.4f), TextAnchor.UpperRight);
|
||||
_threatText.style.position = Position.Absolute;
|
||||
_threatText.style.right = 40; _threatText.style.top = 28; _threatText.style.width = 380;
|
||||
root.Add(_threatText);
|
||||
root.Add(panel);
|
||||
}
|
||||
|
||||
// Macro stack (top-center).
|
||||
void BuildThreat(VisualElement root)
|
||||
{
|
||||
_threatPanel = HudUi.Panel(PanelDark);
|
||||
_threatPanel.style.position = Position.Absolute;
|
||||
_threatPanel.style.right = 40; _threatPanel.style.top = 28;
|
||||
_threatPanel.style.paddingLeft = 16; _threatPanel.style.paddingRight = 16;
|
||||
_threatPanel.style.paddingTop = 8; _threatPanel.style.paddingBottom = 8;
|
||||
_threatPanel.style.alignItems = Align.FlexEnd;
|
||||
var theme = HudTheme.Get();
|
||||
|
||||
var row = new VisualElement();
|
||||
row.style.flexDirection = FlexDirection.Row;
|
||||
row.style.alignItems = Align.Center;
|
||||
row.pickingMode = PickingMode.Ignore;
|
||||
_threatIcon = HudUi.Icon(theme != null ? theme.ThreatIcon : null, 36, ThreatWarm);
|
||||
_threatIcon.style.marginRight = 8;
|
||||
row.Add(_threatIcon);
|
||||
_threatNum = HudUi.Display("0", 34, ThreatWarm, TextAnchor.MiddleRight);
|
||||
row.Add(_threatNum);
|
||||
_threatPanel.Add(row);
|
||||
|
||||
var caption = HudUi.Text("HUSKS", 13, MenuUi.SubCol, TextAnchor.MiddleRight);
|
||||
caption.style.letterSpacing = 4;
|
||||
_threatPanel.Add(caption);
|
||||
|
||||
_threatPanel.style.display = DisplayStyle.None;
|
||||
root.Add(_threatPanel);
|
||||
}
|
||||
|
||||
void BuildMacro(VisualElement root)
|
||||
{
|
||||
var macro = HudUi.Group(Align.Center);
|
||||
macro.style.position = Position.Absolute;
|
||||
macro.style.top = 22; macro.style.left = 0; macro.style.right = 0;
|
||||
_phaseText = HudUi.Text("", 30, new Color(0.55f, 0.9f, 1f), TextAnchor.MiddleCenter);
|
||||
_resourceText = HudUi.Text("", 22, new Color(0.7f, 0.95f, 0.8f), TextAnchor.MiddleCenter);
|
||||
_resourceText.style.marginTop = 4;
|
||||
_locationText = HudUi.Text("", 18, new Color(0.6f, 0.85f, 1f), TextAnchor.MiddleCenter);
|
||||
_locationText.style.marginTop = 4;
|
||||
var goalBar = HudUi.Bar(360, 16, new Color(0.8f, 0.6f, 1f), out _goalFill);
|
||||
goalBar.style.marginTop = 8;
|
||||
_goalText = HudUi.Text("GOAL 0 / 10", 13, Color.white, TextAnchor.MiddleCenter);
|
||||
_goalText.style.position = Position.Absolute;
|
||||
_goalText.style.left = 0; _goalText.style.right = 0; _goalText.style.top = 0; _goalText.style.bottom = 0;
|
||||
goalBar.Add(_goalText);
|
||||
macro.Add(_phaseText);
|
||||
macro.Add(_resourceText);
|
||||
macro.Add(_locationText);
|
||||
macro.Add(goalBar);
|
||||
root.Add(macro);
|
||||
macro.style.top = 16; macro.style.left = 0; macro.style.right = 0;
|
||||
var theme = HudTheme.Get();
|
||||
|
||||
// Build palette row (bottom-center). The row passes clicks through; its buttons pick.
|
||||
// banner: objective icon + phase line + cycle, phase-coloured underline
|
||||
_banner = HudUi.Panel(PanelDark);
|
||||
_banner.style.flexDirection = FlexDirection.Row;
|
||||
_banner.style.alignItems = Align.Center;
|
||||
_banner.style.paddingLeft = 22; _banner.style.paddingRight = 22;
|
||||
_banner.style.paddingTop = 8; _banner.style.paddingBottom = 8;
|
||||
_banner.style.borderBottomWidth = 2;
|
||||
_banner.style.borderBottomColor = AetherCyan;
|
||||
var bIcon = HudUi.Icon(theme != null ? theme.GoalIcon : null, 26, AetherCyan);
|
||||
bIcon.style.marginRight = 10;
|
||||
_banner.Add(bIcon);
|
||||
_phaseText = HudUi.Display("", 30, AetherCyan, TextAnchor.MiddleCenter);
|
||||
_banner.Add(_phaseText);
|
||||
_cycleText = HudUi.Text("", 14, MenuUi.SubCol, TextAnchor.MiddleCenter);
|
||||
_cycleText.style.marginLeft = 14;
|
||||
_banner.Add(_cycleText);
|
||||
macro.Add(_banner);
|
||||
|
||||
_locationText = HudUi.Text("", 15, new Color(0.6f, 0.85f, 1f), TextAnchor.MiddleCenter);
|
||||
_locationText.style.marginTop = 5;
|
||||
macro.Add(_locationText);
|
||||
|
||||
// goal: hex-pip meter (or fallback bar) + numeral
|
||||
_goalContainer = HudUi.Group(Align.Center);
|
||||
_goalContainer.style.marginTop = 8;
|
||||
|
||||
var goalLine = new VisualElement();
|
||||
goalLine.style.flexDirection = FlexDirection.Row;
|
||||
goalLine.style.alignItems = Align.Center;
|
||||
goalLine.pickingMode = PickingMode.Ignore;
|
||||
|
||||
_goalPipsRow = new VisualElement();
|
||||
_goalPipsRow.style.flexDirection = FlexDirection.Row;
|
||||
_goalPipsRow.style.alignItems = Align.Center;
|
||||
_goalPipsRow.pickingMode = PickingMode.Ignore;
|
||||
for (int i = 0; i < MaxPips; i++)
|
||||
{
|
||||
var pip = new VisualElement();
|
||||
pip.style.width = 22; pip.style.height = 22;
|
||||
pip.style.marginLeft = 2; pip.style.marginRight = 2;
|
||||
pip.style.flexShrink = 0;
|
||||
pip.pickingMode = PickingMode.Ignore;
|
||||
pip.style.display = DisplayStyle.None;
|
||||
_pips.Add(pip);
|
||||
_goalPipsRow.Add(pip);
|
||||
}
|
||||
goalLine.Add(_goalPipsRow);
|
||||
|
||||
_goalText = HudUi.Display("GOAL 0 / 10", 16, AetherCyan, TextAnchor.MiddleCenter);
|
||||
_goalText.style.marginLeft = 10;
|
||||
goalLine.Add(_goalText);
|
||||
_goalContainer.Add(goalLine);
|
||||
|
||||
// fallback continuous bar (large targets)
|
||||
_goalBar = HudUi.Bar(360, 16, new Color(0.8f, 0.6f, 1f), out _goalFill);
|
||||
_goalBar.style.marginTop = 4;
|
||||
_goalBar.style.display = DisplayStyle.None;
|
||||
_goalContainer.Add(_goalBar);
|
||||
|
||||
macro.Add(_goalContainer);
|
||||
root.Add(macro);
|
||||
}
|
||||
|
||||
void BuildResources(VisualElement root)
|
||||
{
|
||||
var strip = HudUi.Panel(PanelDark);
|
||||
strip.style.position = Position.Absolute;
|
||||
strip.style.left = 40; strip.style.top = 28;
|
||||
strip.style.flexDirection = FlexDirection.Row;
|
||||
strip.style.alignItems = Align.Center;
|
||||
strip.style.paddingLeft = 14; strip.style.paddingRight = 14;
|
||||
strip.style.paddingTop = 8; strip.style.paddingBottom = 8;
|
||||
var theme = HudTheme.Get();
|
||||
|
||||
strip.Add(ResourceChip(theme != null ? theme.AetherIcon : null, AetherCyan, "0", out _aetherNum, 26, 20));
|
||||
strip.Add(ResourceChip(theme != null ? theme.OreIcon : null, OreAmber, "0", out _oreNum, 30, 22));
|
||||
strip.Add(ResourceChip(theme != null ? theme.BioIcon : null, BioGreen, "0", out _bioNum, 26, 20));
|
||||
|
||||
root.Add(strip);
|
||||
}
|
||||
|
||||
VisualElement ResourceChip(Sprite icon, Color tint, string initial, out Label num, float iconSize, int fontSize)
|
||||
{
|
||||
var chip = new VisualElement();
|
||||
chip.style.flexDirection = FlexDirection.Row;
|
||||
chip.style.alignItems = Align.Center;
|
||||
chip.style.marginLeft = 9; chip.style.marginRight = 9;
|
||||
chip.pickingMode = PickingMode.Ignore;
|
||||
var ic = HudUi.Icon(icon, iconSize, tint);
|
||||
ic.style.marginRight = 6;
|
||||
chip.Add(ic);
|
||||
num = HudUi.Display(initial, fontSize, tint, TextAnchor.MiddleLeft);
|
||||
chip.Add(num);
|
||||
return chip;
|
||||
}
|
||||
|
||||
void BuildPaletteRow(VisualElement root)
|
||||
{
|
||||
_paletteRow = new VisualElement();
|
||||
_paletteRow.style.position = Position.Absolute;
|
||||
_paletteRow.style.bottom = 24; _paletteRow.style.left = 0; _paletteRow.style.right = 0;
|
||||
_paletteRow.style.flexDirection = FlexDirection.Row;
|
||||
_paletteRow.style.justifyContent = Justify.Center;
|
||||
_paletteRow.pickingMode = PickingMode.Ignore;
|
||||
_paletteRow.pickingMode = PickingMode.Ignore; // the row passes clicks through; its slots pick
|
||||
root.Add(_paletteRow);
|
||||
}
|
||||
|
||||
// Downed overlay.
|
||||
void BuildHintBar(VisualElement root)
|
||||
{
|
||||
_hintBar = new VisualElement();
|
||||
_hintBar.style.position = Position.Absolute;
|
||||
_hintBar.style.bottom = 138; _hintBar.style.left = 0; _hintBar.style.right = 0;
|
||||
_hintBar.style.flexDirection = FlexDirection.Row;
|
||||
_hintBar.style.justifyContent = Justify.Center;
|
||||
_hintBar.pickingMode = PickingMode.Ignore;
|
||||
_hintBar.style.display = DisplayStyle.None;
|
||||
root.Add(_hintBar);
|
||||
}
|
||||
|
||||
void BuildDowned(VisualElement root)
|
||||
{
|
||||
_downed = new VisualElement();
|
||||
_downed.style.position = Position.Absolute;
|
||||
_downed.style.left = 0; _downed.style.right = 0; _downed.style.top = 0; _downed.style.bottom = 0;
|
||||
_downed.style.backgroundColor = new Color(0.35f, 0f, 0f, 0.35f);
|
||||
_downed.style.alignItems = Align.Center;
|
||||
_downed.style.justifyContent = Justify.Center;
|
||||
_downed.pickingMode = PickingMode.Ignore;
|
||||
_downed.Add(HudUi.Text("DOWNED - RESPAWNING", 52, new Color(1f, 0.45f, 0.4f), TextAnchor.MiddleCenter));
|
||||
var theme = HudTheme.Get();
|
||||
if (theme != null && theme.Vignette != null)
|
||||
{
|
||||
_downed.style.backgroundImage = new StyleBackground(Background.FromSprite(theme.Vignette));
|
||||
_downed.style.unityBackgroundImageTintColor = new Color(0.45f, 0f, 0f, 0.6f);
|
||||
_downed.style.backgroundSize = new StyleBackgroundSize(new BackgroundSize(BackgroundSizeType.Cover));
|
||||
}
|
||||
else
|
||||
{
|
||||
_downed.style.backgroundColor = new Color(0.35f, 0f, 0f, 0.35f);
|
||||
}
|
||||
_downed.Add(HudUi.Display("DOWNED - RESPAWNING", 52, new Color(1f, 0.45f, 0.4f), TextAnchor.MiddleCenter));
|
||||
_downed.style.display = DisplayStyle.None;
|
||||
root.Add(_downed);
|
||||
}
|
||||
|
||||
static Color ResourceTint(byte resId)
|
||||
=> resId == ResourceId.Aether ? AetherCyan : resId == ResourceId.Biomass ? BioGreen : OreAmber;
|
||||
|
||||
static Sprite ResourceSprite(HudTheme t, byte resId)
|
||||
{
|
||||
if (t == null) return null;
|
||||
return resId == ResourceId.Aether ? t.AetherIcon : resId == ResourceId.Biomass ? t.BioIcon : t.OreIcon;
|
||||
}
|
||||
|
||||
// Conveyor facing (BuildPaletteState.Direction 0=+X,1=-X,2=+Z,3=-Z) → arrow rotation; the arrow art points up (+Z).
|
||||
static float FacingDegrees(byte dir)
|
||||
{
|
||||
switch (dir)
|
||||
{
|
||||
case 0: return 90f; // +X
|
||||
case 1: return 270f; // -X
|
||||
case 3: return 180f; // -Z
|
||||
default: return 0f; // +Z
|
||||
}
|
||||
}
|
||||
|
||||
static Color PhaseColor(byte phase)
|
||||
{
|
||||
switch (phase)
|
||||
|
||||
Reference in New Issue
Block a user