From 437390475371ebd0fd36fab62644030710e23e6b Mon Sep 17 00:00:00 2001
From: Aristeas <94058548+ari-steas@users.noreply.github.com>
Date: Mon, 24 Feb 2025 17:38:44 -0600
Subject: [PATCH] Mostly functional upgraded fusion hud
---
...f_score_background.sbc => HudTextures.sbc} | 12 +
.../HudHelpers/FusionWindow.cs | 220 ++++++++++++++++++
.../HudHelpers/HudConstants.cs | 20 ++
.../ModularAssemblies/S_FusionPlayerHud.cs | 12 +-
.../Textures/HudBackground.dds | Bin 0 -> 54548 bytes
.../Textures/HudBackground.pdn | Bin 0 -> 5317 bytes
6 files changed, 259 insertions(+), 5 deletions(-)
rename Utility Mods/MoA Fusion Systems/Data/{ctf_score_background.sbc => HudTextures.sbc} (71%)
create mode 100644 Utility Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/HudHelpers/FusionWindow.cs
create mode 100644 Utility Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/HudHelpers/HudConstants.cs
create mode 100644 Utility Mods/MoA Fusion Systems/Textures/HudBackground.dds
create mode 100644 Utility Mods/MoA Fusion Systems/Textures/HudBackground.pdn
diff --git a/Utility Mods/MoA Fusion Systems/Data/ctf_score_background.sbc b/Utility Mods/MoA Fusion Systems/Data/HudTextures.sbc
similarity index 71%
rename from Utility Mods/MoA Fusion Systems/Data/ctf_score_background.sbc
rename to Utility Mods/MoA Fusion Systems/Data/HudTextures.sbc
index 0e6538197..dadd3556e 100644
--- a/Utility Mods/MoA Fusion Systems/Data/ctf_score_background.sbc
+++ b/Utility Mods/MoA Fusion Systems/Data/HudTextures.sbc
@@ -25,5 +25,17 @@
0.1
Textures\fusionBarBackground.dds
+
+
+ TransparentMaterialDefinition
+ HudBackground
+
+ false
+ 1
+ false
+ false
+ 0.1
+ Textures\HudBackground.dds
+
diff --git a/Utility Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/HudHelpers/FusionWindow.cs b/Utility Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/HudHelpers/FusionWindow.cs
new file mode 100644
index 000000000..8a8f76261
--- /dev/null
+++ b/Utility Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/HudHelpers/FusionWindow.cs
@@ -0,0 +1,220 @@
+using Epstein_Fusion_DS.Communication;
+using Epstein_Fusion_DS.FusionParts;
+using Epstein_Fusion_DS.HeatParts;
+using RichHudFramework.UI;
+using RichHudFramework.UI.Rendering;
+using RichHudFramework.UI.Rendering.Client;
+using Sandbox.Game.Entities;
+using Sandbox.ModAPI;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using VRage.Game.Entity;
+using VRage.Game.ModAPI;
+using VRageMath;
+
+namespace Epstein_Fusion_DS.HudHelpers
+{
+ internal class FusionWindow : CamSpaceNode
+ {
+ private readonly TexturedBox _backgroundBox, _foregroundBox, _heatBox, _storBox;
+ private readonly Label _heatLabel, _storageLabel, _infoLabelLeft;
+
+ private readonly GlyphFormat _stdTextFormat = new GlyphFormat(color: HudConstants.HudTextColor, alignment: TextAlignment.Center, font: FontManager.GetFont("BI_Monospace"));
+ private readonly GlyphFormat _stdTextFormatInfo = new GlyphFormat(color: HudConstants.HudTextColor, textSize: 0.85f, alignment: TextAlignment.Left, font: FontManager.GetFont("BI_Monospace"));
+
+ public FusionWindow(HudParentBase parent) : base(parent)
+ {
+ RotationAxis = new Vector3(0, 1, 0);
+ RotationAngle = 0.25f;
+ TransformOffset = new Vector3D(-0.0675, -0.04, -0.05);
+
+ _backgroundBox = new TexturedBox(this)
+ {
+ Material = new Material("WhiteSquare", HudConstants.HudSize),
+ Size = HudConstants.HudSize,
+ Color = HudConstants.HudBackgroundColor,
+ IsMasking = true,
+ ZOffset = sbyte.MinValue,
+ Padding = Vector2.Zero,
+ };
+ _foregroundBox = new TexturedBox(this)
+ {
+ Material = new Material("HudBackground", new Vector2(400, 136)),
+ Size = HudConstants.HudSize,
+ ZOffset = sbyte.MaxValue,
+ };
+
+ _heatLabel = new Label(this)
+ {
+ Text = "00% HEAT",
+ Offset = new Vector2(0, 0),
+ Format = _stdTextFormat,
+ ZOffset = sbyte.MaxValue,
+ };
+ _storageLabel = new Label(this)
+ {
+ Text = "00% STOR",
+ Offset = new Vector2(0, -_backgroundBox.Size.Y/3),
+ Format = _stdTextFormat,
+ ZOffset = sbyte.MaxValue,
+ };
+
+ _infoLabelLeft = new Label(this)
+ {
+ Text = "100% INTEGRITY - ALL SYSTEMS NOMINAL",
+ Offset = new Vector2(0, _backgroundBox.Size.Y/3),
+ Format = _stdTextFormat,
+ ZOffset = sbyte.MaxValue,
+ };
+
+ _heatBox = new TexturedBox(_backgroundBox)
+ {
+ Material = new Material("WhiteSquare", new Vector2(384, 38) * HudConstants.HudSizeRatio),
+ Size = new Vector2(384, 38) * HudConstants.HudSizeRatio,
+ ParentAlignment = ParentAlignments.Left | ParentAlignments.Top | ParentAlignments.Inner,
+ Offset = new Vector2(8, -49) * HudConstants.HudSizeRatio,
+ ZOffset = 0,
+ Color = Color.Red,
+ };
+
+ _storBox = new TexturedBox(_backgroundBox)
+ {
+ Material = new Material("WhiteSquare", new Vector2(384, 38) * HudConstants.HudSizeRatio),
+ Size = new Vector2(384, 38) * HudConstants.HudSizeRatio,
+ ParentAlignment = ParentAlignments.Left | ParentAlignments.Top | ParentAlignments.Inner,
+ Offset = new Vector2(8, -95) * HudConstants.HudSizeRatio,
+ ZOffset = 0,
+ Color = Color.Orange,
+ };
+ }
+
+
+ private static ModularDefinitionApi ModularApi => Epstein_Fusion_DS.ModularDefinition.ModularApi;
+ private int _ticks = 0;
+ private bool _shouldHide;
+ private MyEntity3DSoundEmitter _soundEmitter = null;
+ private readonly MySoundPair _alertSound = new MySoundPair("ArcSoundBlockAlert2");
+
+ public void Update()
+ {
+ _ticks++;
+ var playerCockpit = MyAPIGateway.Session?.Player?.Controller?.ControlledEntity?.Entity as IMyShipController;
+
+ // Pulling the current HudState is SLOOOOWWWW, so we only pull it when tab is just pressed.
+ //if (MyAPIGateway.Input.IsNewKeyPressed(MyKeys.Tab))
+ // _shouldHide = MyAPIGateway.Session?.Config?.HudState != 1;
+
+ // Hide HUD element if the player isn't in a cockpit
+ if (playerCockpit == null || _shouldHide)
+ {
+ if (Visible) Visible = false;
+
+ if (_soundEmitter != null)
+ {
+ _soundEmitter.StopSound(true);
+ _soundEmitter = null;
+ }
+ return;
+ }
+
+ var playerGrid = playerCockpit.CubeGrid;
+
+ float totalFusionCapacity = 0;
+ float totalFusionGeneration = 0;
+ float totalFusionStored = 0;
+ float reactorIntegrity = 0;
+ int reactorCount = 0;
+
+ foreach (var system in SFusionManager.I.FusionSystems)
+ {
+ if (playerGrid != ModularApi.GetAssemblyGrid(system.Key))
+ continue;
+
+ totalFusionCapacity += system.Value.MaxPowerStored;
+ totalFusionGeneration += system.Value.PowerGeneration;
+ totalFusionStored += system.Value.PowerStored;
+ foreach (var reactor in system.Value.Reactors)
+ {
+ reactorIntegrity += reactor.Block.SlimBlock.Integrity/reactor.Block.SlimBlock.MaxIntegrity;
+ reactorCount++;
+ }
+ foreach (var thruster in system.Value.Thrusters)
+ {
+ reactorIntegrity += thruster.Block.SlimBlock.Integrity/thruster.Block.SlimBlock.MaxIntegrity;
+ reactorCount++;
+ }
+ }
+ reactorIntegrity /= reactorCount;
+
+ // Hide HUD element if the grid has no fusion systems (capacity is always >0 for a fusion system)
+ if (totalFusionCapacity == 0)
+ {
+ if (Visible) Visible = false;
+ return;
+ }
+
+ // Show otherwise
+ if (!Visible) Visible = true;
+
+ var heatPct = HeatManager.I.GetGridHeatLevel(playerGrid);
+
+ _heatBox.Width = 384 * HudConstants.HudSizeRatio.X * heatPct;
+ _heatBox.Color = new Color(heatPct, 1-heatPct, 0, 0.75f);
+
+ _storBox.Width = 384 * HudConstants.HudSizeRatio.X * (totalFusionStored / totalFusionCapacity);
+
+ _infoLabelLeft.Text = new RichText
+ {
+ {(reactorIntegrity*100).ToString("N0") + "%", _stdTextFormatInfo.WithColor(reactorIntegrity > 0.6 ? Color.White : Color.Red)},
+ {" INTEGRITY - ", _stdTextFormatInfo},
+ {GetNoticeText(heatPct, reactorIntegrity), GetNoticeFormat(heatPct, reactorIntegrity)},
+ };
+
+ _heatLabel.Text = $"{heatPct*100:N0}% HEAT";
+ _storageLabel.Text = $"{(totalFusionStored / totalFusionCapacity) * 100:N0}% STOR";
+
+ if (heatPct > 0.8f)
+ {
+ if (_soundEmitter == null)
+ {
+ _soundEmitter = new MyEntity3DSoundEmitter((MyEntity) playerCockpit.Entity)
+ {
+ CanPlayLoopSounds = true
+ };
+ _soundEmitter.PlaySound(_alertSound);
+ }
+ }
+ else
+ {
+ if (_soundEmitter != null)
+ {
+ _soundEmitter.StopSound(true);
+ _soundEmitter = null;
+ }
+ }
+ }
+
+ private string GetNoticeText(float heatPct, float integrityPct)
+ {
+ if (integrityPct < 0.1)
+ return "I DON'T WANT TO DIE.";
+ if (integrityPct < 0.5)
+ return "-!- REACTOR FAILURE -!-";
+ if (integrityPct < 0.6)
+ return "-!- SHUTDOWN IMMINENT -!-";
+ if (heatPct > 0.8)
+ return "! THERMAL DAMAGE !";
+ return "ALL SYSTEMS NOMINAL";
+ }
+
+ private GlyphFormat GetNoticeFormat(float heatPct, float integrityPct)
+ {
+ if (integrityPct < 0.6 || heatPct > 0.8)
+ return _stdTextFormatInfo.WithColor(Color.Red);
+ return _stdTextFormatInfo;
+ }
+ }
+}
diff --git a/Utility Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/HudHelpers/HudConstants.cs b/Utility Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/HudHelpers/HudConstants.cs
new file mode 100644
index 000000000..cab42a67e
--- /dev/null
+++ b/Utility Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/HudHelpers/HudConstants.cs
@@ -0,0 +1,20 @@
+using RichHudFramework.UI.Rendering;
+using VRageMath;
+
+namespace Epstein_Fusion_DS.HudHelpers
+{
+ ///
+ /// HUD constants class for Fusion Systems
+ ///
+ public static class HudConstants
+ {
+ public static readonly Color HudBackgroundColor = new Color(255, 255, 255, 40);
+ public static readonly Color HudTextColor = Color.White;
+ public static Vector2 HudSize = new Vector2(300, 102);
+ public static Vector2 HudSizeRatio = HudSize / new Vector2(400, 136);
+
+ //public static Material BackgroundMaterial = new Material("HudBackground", new Vector2(435, 102));
+
+ //public static Vector2 HudAngle = new Vector2(
+ }
+}
diff --git a/Utility Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/S_FusionPlayerHud.cs b/Utility Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/S_FusionPlayerHud.cs
index e21fca76b..76f6d0a24 100644
--- a/Utility Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/S_FusionPlayerHud.cs
+++ b/Utility Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/S_FusionPlayerHud.cs
@@ -21,7 +21,7 @@ public class SFusionPlayerHud : MySessionComponentBase
public static SFusionPlayerHud I;
private int _ticks;
- private ConsumptionBar _consumptionBar;
+ private FusionWindow _fusionHud;
private static ModularDefinitionApi ModularApi => Epstein_Fusion_DS.ModularDefinition.ModularApi;
private static SFusionManager FusionManager => SFusionManager.I;
private static HeatManager HeatManager => HeatManager.I;
@@ -53,15 +53,17 @@ public override void UpdateAfterSimulation()
_ticks++;
try
{
- if (_consumptionBar == null && RichHudClient.Registered)
- _consumptionBar = new ConsumptionBar(HudMain.HighDpiRoot)
+ if (_fusionHud == null && RichHudClient.Registered)
+ {
+ _fusionHud = new FusionWindow(HudMain.HighDpiRoot)
{
Visible = true
- };
+ };
+ }
HeatManager.UpdateTick();
FusionManager.UpdateTick();
- _consumptionBar?.Update();
+ _fusionHud?.Update();
if (ModularApi.IsDebug())
{
diff --git a/Utility Mods/MoA Fusion Systems/Textures/HudBackground.dds b/Utility Mods/MoA Fusion Systems/Textures/HudBackground.dds
new file mode 100644
index 0000000000000000000000000000000000000000..1e517cff8cdc7acb5740cec450102dc7a292fbf0
GIT binary patch
literal 54548
zcmeI)L246G0LJkbA}ER^C#VH4pu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