Skip to content

Commit e911c3f

Browse files
authored
Mostly functional upgraded fusion hud (#1894)
1 parent ed414cf commit e911c3f

6 files changed

Lines changed: 259 additions & 5 deletions

File tree

Utility Mods/MoA Fusion Systems/Data/ctf_score_background.sbc renamed to Utility Mods/MoA Fusion Systems/Data/HudTextures.sbc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,17 @@
2525
<SoftParticleDistanceScale>0.1</SoftParticleDistanceScale>
2626
<Texture>Textures\fusionBarBackground.dds</Texture>
2727
</TransparentMaterial>
28+
<TransparentMaterial>
29+
<Id>
30+
<TypeId>TransparentMaterialDefinition</TypeId>
31+
<SubtypeId>HudBackground</SubtypeId>
32+
</Id>
33+
<AlphaMistingEnable>false</AlphaMistingEnable>
34+
<AlphaSaturation>1</AlphaSaturation>
35+
<CanBeAffectedByOtherLights>false</CanBeAffectedByOtherLights>
36+
<IgnoreDepth>false</IgnoreDepth>
37+
<SoftParticleDistanceScale>0.1</SoftParticleDistanceScale>
38+
<Texture>Textures\HudBackground.dds</Texture>
39+
</TransparentMaterial>
2840
</TransparentMaterials>
2941
</Definitions>
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
using Epstein_Fusion_DS.Communication;
2+
using Epstein_Fusion_DS.FusionParts;
3+
using Epstein_Fusion_DS.HeatParts;
4+
using RichHudFramework.UI;
5+
using RichHudFramework.UI.Rendering;
6+
using RichHudFramework.UI.Rendering.Client;
7+
using Sandbox.Game.Entities;
8+
using Sandbox.ModAPI;
9+
using System;
10+
using System.Collections.Generic;
11+
using System.Linq;
12+
using System.Text;
13+
using System.Threading.Tasks;
14+
using VRage.Game.Entity;
15+
using VRage.Game.ModAPI;
16+
using VRageMath;
17+
18+
namespace Epstein_Fusion_DS.HudHelpers
19+
{
20+
internal class FusionWindow : CamSpaceNode
21+
{
22+
private readonly TexturedBox _backgroundBox, _foregroundBox, _heatBox, _storBox;
23+
private readonly Label _heatLabel, _storageLabel, _infoLabelLeft;
24+
25+
private readonly GlyphFormat _stdTextFormat = new GlyphFormat(color: HudConstants.HudTextColor, alignment: TextAlignment.Center, font: FontManager.GetFont("BI_Monospace"));
26+
private readonly GlyphFormat _stdTextFormatInfo = new GlyphFormat(color: HudConstants.HudTextColor, textSize: 0.85f, alignment: TextAlignment.Left, font: FontManager.GetFont("BI_Monospace"));
27+
28+
public FusionWindow(HudParentBase parent) : base(parent)
29+
{
30+
RotationAxis = new Vector3(0, 1, 0);
31+
RotationAngle = 0.25f;
32+
TransformOffset = new Vector3D(-0.0675, -0.04, -0.05);
33+
34+
_backgroundBox = new TexturedBox(this)
35+
{
36+
Material = new Material("WhiteSquare", HudConstants.HudSize),
37+
Size = HudConstants.HudSize,
38+
Color = HudConstants.HudBackgroundColor,
39+
IsMasking = true,
40+
ZOffset = sbyte.MinValue,
41+
Padding = Vector2.Zero,
42+
};
43+
_foregroundBox = new TexturedBox(this)
44+
{
45+
Material = new Material("HudBackground", new Vector2(400, 136)),
46+
Size = HudConstants.HudSize,
47+
ZOffset = sbyte.MaxValue,
48+
};
49+
50+
_heatLabel = new Label(this)
51+
{
52+
Text = "00% HEAT",
53+
Offset = new Vector2(0, 0),
54+
Format = _stdTextFormat,
55+
ZOffset = sbyte.MaxValue,
56+
};
57+
_storageLabel = new Label(this)
58+
{
59+
Text = "00% STOR",
60+
Offset = new Vector2(0, -_backgroundBox.Size.Y/3),
61+
Format = _stdTextFormat,
62+
ZOffset = sbyte.MaxValue,
63+
};
64+
65+
_infoLabelLeft = new Label(this)
66+
{
67+
Text = "100% INTEGRITY - ALL SYSTEMS NOMINAL",
68+
Offset = new Vector2(0, _backgroundBox.Size.Y/3),
69+
Format = _stdTextFormat,
70+
ZOffset = sbyte.MaxValue,
71+
};
72+
73+
_heatBox = new TexturedBox(_backgroundBox)
74+
{
75+
Material = new Material("WhiteSquare", new Vector2(384, 38) * HudConstants.HudSizeRatio),
76+
Size = new Vector2(384, 38) * HudConstants.HudSizeRatio,
77+
ParentAlignment = ParentAlignments.Left | ParentAlignments.Top | ParentAlignments.Inner,
78+
Offset = new Vector2(8, -49) * HudConstants.HudSizeRatio,
79+
ZOffset = 0,
80+
Color = Color.Red,
81+
};
82+
83+
_storBox = new TexturedBox(_backgroundBox)
84+
{
85+
Material = new Material("WhiteSquare", new Vector2(384, 38) * HudConstants.HudSizeRatio),
86+
Size = new Vector2(384, 38) * HudConstants.HudSizeRatio,
87+
ParentAlignment = ParentAlignments.Left | ParentAlignments.Top | ParentAlignments.Inner,
88+
Offset = new Vector2(8, -95) * HudConstants.HudSizeRatio,
89+
ZOffset = 0,
90+
Color = Color.Orange,
91+
};
92+
}
93+
94+
95+
private static ModularDefinitionApi ModularApi => Epstein_Fusion_DS.ModularDefinition.ModularApi;
96+
private int _ticks = 0;
97+
private bool _shouldHide;
98+
private MyEntity3DSoundEmitter _soundEmitter = null;
99+
private readonly MySoundPair _alertSound = new MySoundPair("ArcSoundBlockAlert2");
100+
101+
public void Update()
102+
{
103+
_ticks++;
104+
var playerCockpit = MyAPIGateway.Session?.Player?.Controller?.ControlledEntity?.Entity as IMyShipController;
105+
106+
// Pulling the current HudState is SLOOOOWWWW, so we only pull it when tab is just pressed.
107+
//if (MyAPIGateway.Input.IsNewKeyPressed(MyKeys.Tab))
108+
// _shouldHide = MyAPIGateway.Session?.Config?.HudState != 1;
109+
110+
// Hide HUD element if the player isn't in a cockpit
111+
if (playerCockpit == null || _shouldHide)
112+
{
113+
if (Visible) Visible = false;
114+
115+
if (_soundEmitter != null)
116+
{
117+
_soundEmitter.StopSound(true);
118+
_soundEmitter = null;
119+
}
120+
return;
121+
}
122+
123+
var playerGrid = playerCockpit.CubeGrid;
124+
125+
float totalFusionCapacity = 0;
126+
float totalFusionGeneration = 0;
127+
float totalFusionStored = 0;
128+
float reactorIntegrity = 0;
129+
int reactorCount = 0;
130+
131+
foreach (var system in SFusionManager.I.FusionSystems)
132+
{
133+
if (playerGrid != ModularApi.GetAssemblyGrid(system.Key))
134+
continue;
135+
136+
totalFusionCapacity += system.Value.MaxPowerStored;
137+
totalFusionGeneration += system.Value.PowerGeneration;
138+
totalFusionStored += system.Value.PowerStored;
139+
foreach (var reactor in system.Value.Reactors)
140+
{
141+
reactorIntegrity += reactor.Block.SlimBlock.Integrity/reactor.Block.SlimBlock.MaxIntegrity;
142+
reactorCount++;
143+
}
144+
foreach (var thruster in system.Value.Thrusters)
145+
{
146+
reactorIntegrity += thruster.Block.SlimBlock.Integrity/thruster.Block.SlimBlock.MaxIntegrity;
147+
reactorCount++;
148+
}
149+
}
150+
reactorIntegrity /= reactorCount;
151+
152+
// Hide HUD element if the grid has no fusion systems (capacity is always >0 for a fusion system)
153+
if (totalFusionCapacity == 0)
154+
{
155+
if (Visible) Visible = false;
156+
return;
157+
}
158+
159+
// Show otherwise
160+
if (!Visible) Visible = true;
161+
162+
var heatPct = HeatManager.I.GetGridHeatLevel(playerGrid);
163+
164+
_heatBox.Width = 384 * HudConstants.HudSizeRatio.X * heatPct;
165+
_heatBox.Color = new Color(heatPct, 1-heatPct, 0, 0.75f);
166+
167+
_storBox.Width = 384 * HudConstants.HudSizeRatio.X * (totalFusionStored / totalFusionCapacity);
168+
169+
_infoLabelLeft.Text = new RichText
170+
{
171+
{(reactorIntegrity*100).ToString("N0") + "%", _stdTextFormatInfo.WithColor(reactorIntegrity > 0.6 ? Color.White : Color.Red)},
172+
{" INTEGRITY - ", _stdTextFormatInfo},
173+
{GetNoticeText(heatPct, reactorIntegrity), GetNoticeFormat(heatPct, reactorIntegrity)},
174+
};
175+
176+
_heatLabel.Text = $"{heatPct*100:N0}% HEAT";
177+
_storageLabel.Text = $"{(totalFusionStored / totalFusionCapacity) * 100:N0}% STOR";
178+
179+
if (heatPct > 0.8f)
180+
{
181+
if (_soundEmitter == null)
182+
{
183+
_soundEmitter = new MyEntity3DSoundEmitter((MyEntity) playerCockpit.Entity)
184+
{
185+
CanPlayLoopSounds = true
186+
};
187+
_soundEmitter.PlaySound(_alertSound);
188+
}
189+
}
190+
else
191+
{
192+
if (_soundEmitter != null)
193+
{
194+
_soundEmitter.StopSound(true);
195+
_soundEmitter = null;
196+
}
197+
}
198+
}
199+
200+
private string GetNoticeText(float heatPct, float integrityPct)
201+
{
202+
if (integrityPct < 0.1)
203+
return "I DON'T WANT TO DIE.";
204+
if (integrityPct < 0.5)
205+
return "-!- REACTOR FAILURE -!-";
206+
if (integrityPct < 0.6)
207+
return "-!- SHUTDOWN IMMINENT -!-";
208+
if (heatPct > 0.8)
209+
return "! THERMAL DAMAGE !";
210+
return "ALL SYSTEMS NOMINAL";
211+
}
212+
213+
private GlyphFormat GetNoticeFormat(float heatPct, float integrityPct)
214+
{
215+
if (integrityPct < 0.6 || heatPct > 0.8)
216+
return _stdTextFormatInfo.WithColor(Color.Red);
217+
return _stdTextFormatInfo;
218+
}
219+
}
220+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using RichHudFramework.UI.Rendering;
2+
using VRageMath;
3+
4+
namespace Epstein_Fusion_DS.HudHelpers
5+
{
6+
/// <summary>
7+
/// HUD constants class for Fusion Systems
8+
/// </summary>
9+
public static class HudConstants
10+
{
11+
public static readonly Color HudBackgroundColor = new Color(255, 255, 255, 40);
12+
public static readonly Color HudTextColor = Color.White;
13+
public static Vector2 HudSize = new Vector2(300, 102);
14+
public static Vector2 HudSizeRatio = HudSize / new Vector2(400, 136);
15+
16+
//public static Material BackgroundMaterial = new Material("HudBackground", new Vector2(435, 102));
17+
18+
//public static Vector2 HudAngle = new Vector2(
19+
}
20+
}

Utility Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/S_FusionPlayerHud.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class SFusionPlayerHud : MySessionComponentBase
2121
public static SFusionPlayerHud I;
2222
private int _ticks;
2323

24-
private ConsumptionBar _consumptionBar;
24+
private FusionWindow _fusionHud;
2525
private static ModularDefinitionApi ModularApi => Epstein_Fusion_DS.ModularDefinition.ModularApi;
2626
private static SFusionManager FusionManager => SFusionManager.I;
2727
private static HeatManager HeatManager => HeatManager.I;
@@ -53,15 +53,17 @@ public override void UpdateAfterSimulation()
5353
_ticks++;
5454
try
5555
{
56-
if (_consumptionBar == null && RichHudClient.Registered)
57-
_consumptionBar = new ConsumptionBar(HudMain.HighDpiRoot)
56+
if (_fusionHud == null && RichHudClient.Registered)
57+
{
58+
_fusionHud = new FusionWindow(HudMain.HighDpiRoot)
5859
{
5960
Visible = true
60-
};
61+
};
62+
}
6163

6264
HeatManager.UpdateTick();
6365
FusionManager.UpdateTick();
64-
_consumptionBar?.Update();
66+
_fusionHud?.Update();
6567

6668
if (ModularApi.IsDebug())
6769
{
53.3 KB
Binary file not shown.
5.19 KB
Binary file not shown.

0 commit comments

Comments
 (0)