Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,17 @@
<SoftParticleDistanceScale>0.1</SoftParticleDistanceScale>
<Texture>Textures\fusionBarBackground.dds</Texture>
</TransparentMaterial>
<TransparentMaterial>
<Id>
<TypeId>TransparentMaterialDefinition</TypeId>
<SubtypeId>HudBackground</SubtypeId>
</Id>
<AlphaMistingEnable>false</AlphaMistingEnable>
<AlphaSaturation>1</AlphaSaturation>
<CanBeAffectedByOtherLights>false</CanBeAffectedByOtherLights>
<IgnoreDepth>false</IgnoreDepth>
<SoftParticleDistanceScale>0.1</SoftParticleDistanceScale>
<Texture>Textures\HudBackground.dds</Texture>
</TransparentMaterial>
</TransparentMaterials>
</Definitions>
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using RichHudFramework.UI.Rendering;
using VRageMath;

namespace Epstein_Fusion_DS.HudHelpers
{
/// <summary>
/// HUD constants class for Fusion Systems
/// </summary>
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(
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
{
Expand Down
Binary file not shown.
Binary file not shown.