From d2ebabb6a286903ff64de58de436fb535283fe8d Mon Sep 17 00:00:00 2001 From: InvalidArgument3 Date: Tue, 13 Feb 2024 02:17:41 -0600 Subject: [PATCH 1/6] Update SorterWeaponTerminalControls.cs --- .../Setup/SorterWeaponTerminalControls.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/Setup/SorterWeaponTerminalControls.cs b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/Setup/SorterWeaponTerminalControls.cs index 9cf48fab..bede9556 100644 --- a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/Setup/SorterWeaponTerminalControls.cs +++ b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/Setup/SorterWeaponTerminalControls.cs @@ -285,6 +285,22 @@ static void CreateControls() (b, v) => b.GameLogic.GetAs().Terminal_Heart_TargetUnowned = v ); } + { + var c = MyAPIGateway.TerminalControls.CreateControl(IdPrefix + "HeartWeaponHUDDivider"); + c.Label = MyStringId.GetOrCompute("=== HUD ==="); + c.SupportsMultipleBlocks = true; + c.Visible = CustomVisibleCondition; + MyAPIGateway.TerminalControls.AddControl(c); + } + { + ControlsHelper.CreateToggle( + "HeartHUDBarrelIndicatorToggle", + "Target Unowned", + "TargetUnownedDesc", + (b) => b.GameLogic.GetAs().Terminal_Heart_TargetUnowned, + (b, v) => b.GameLogic.GetAs().Terminal_Heart_TargetUnowned = v + ); + } } static void CreateActions(IMyModContext context) From a47ff82219fc86c0edc54220fdb0171acb8a449a Mon Sep 17 00:00:00 2001 From: InvalidArgument3 Date: Tue, 13 Feb 2024 02:57:47 -0600 Subject: [PATCH 2/6] create terminal, link to hook --- .../HeartModule/Weapons/Heart_Settings.cs | 3 +++ .../Setup/SorterWeaponTerminalControls.cs | 8 ++++---- .../HeartModule/Weapons/SorterTurretLogic.cs | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/Heart_Settings.cs b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/Heart_Settings.cs index 8ba79d72..2fc7f96d 100644 --- a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/Heart_Settings.cs +++ b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/Heart_Settings.cs @@ -49,5 +49,8 @@ public class Heart_Settings [ProtoMember(15)] public bool MouseShootState; + + [ProtoMember(16)] + public bool HudBarrelIndicatorState; } } diff --git a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/Setup/SorterWeaponTerminalControls.cs b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/Setup/SorterWeaponTerminalControls.cs index bede9556..b9131dfc 100644 --- a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/Setup/SorterWeaponTerminalControls.cs +++ b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/Setup/SorterWeaponTerminalControls.cs @@ -295,10 +295,10 @@ static void CreateControls() { ControlsHelper.CreateToggle( "HeartHUDBarrelIndicatorToggle", - "Target Unowned", - "TargetUnownedDesc", - (b) => b.GameLogic.GetAs().Terminal_Heart_TargetUnowned, - (b, v) => b.GameLogic.GetAs().Terminal_Heart_TargetUnowned = v + "HUD Barrel Indicator", + "HUDBarrelIndicatorDesc", + (b) => b.GameLogic.GetAs().Terminal_Heart_ToggleHUDBarrelIndicator, + (b, v) => b.GameLogic.GetAs().Terminal_Heart_ToggleHUDBarrelIndicator = v ); } } diff --git a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/SorterTurretLogic.cs b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/SorterTurretLogic.cs index c1540ec0..7b379a91 100644 --- a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/SorterTurretLogic.cs +++ b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/SorterTurretLogic.cs @@ -355,6 +355,7 @@ internal override bool LoadSettings() public MySync TargetNeutralsState; public MySync TargetEnemiesState; public MySync TargetUnownedState; + public MySync HudBarrelIndicatorState; public float Terminal_Heart_Range_Slider { @@ -532,6 +533,22 @@ public bool Terminal_Heart_TargetUnowned NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME; } } + + public bool Terminal_Heart_ToggleHUDBarrelIndicator + { + get + { + return Settings.HudBarrelIndicatorState; + } + + set + { + Settings.HudBarrelIndicatorState = value; + HudBarrelIndicatorState.Value = value; + if ((NeedsUpdate & MyEntityUpdateEnum.EACH_10TH_FRAME) == 0) + NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME; + } + } #endregion } } From 217b8bc6ecbe95f10e798fa0e0b8382552b6e912 Mon Sep 17 00:00:00 2001 From: InvalidArgument3 Date: Tue, 13 Feb 2024 03:05:22 -0600 Subject: [PATCH 3/6] Update SorterTurretLogic.cs --- .../Data/Scripts/HeartModule/Weapons/SorterTurretLogic.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/SorterTurretLogic.cs b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/SorterTurretLogic.cs index 7b379a91..0fbd662c 100644 --- a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/SorterTurretLogic.cs +++ b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/SorterTurretLogic.cs @@ -266,6 +266,8 @@ internal override void LoadDefaultSettings() Terminal_Heart_TargetNeutrals = (Definition.Targeting.DefaultIFF & IFF_Enum.TargetNeutrals) == IFF_Enum.TargetNeutrals; Terminal_Heart_TargetUnowned = false; Terminal_Heart_PreferUniqueTargets = (Definition.Targeting.DefaultIFF & IFF_Enum.TargetUnique) == IFF_Enum.TargetUnique; + Terminal_Heart_ToggleHUDBarrelIndicator = false; + } } @@ -326,6 +328,9 @@ internal override bool LoadSettings() Settings.TargetUnownedState = loadedSettings.TargetUnownedState; TargetUnownedState.Value = Settings.TargetUnownedState; + Settings.HudBarrelIndicatorState = loadedSettings.HudBarrelIndicatorState; + HudBarrelIndicatorState.Value = Settings.HudBarrelIndicatorState; + return baseRet; } } From 9381f02f93dfd1f5cff2043d874cb292238edc1a Mon Sep 17 00:00:00 2001 From: InvalidArgument3 Date: Tue, 13 Feb 2024 03:16:11 -0600 Subject: [PATCH 4/6] it works --- .../UserInterface/GridBasedIndicator_Base.cs | 23 ++++++++++++++----- .../HeartModule/Weapons/SorterTurretLogic.cs | 20 ---------------- .../HeartModule/Weapons/SorterWeaponLogic.cs | 22 ++++++++++++++++++ 3 files changed, 39 insertions(+), 26 deletions(-) diff --git a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/UserInterface/GridBasedIndicator_Base.cs b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/UserInterface/GridBasedIndicator_Base.cs index 81cf4759..8162d1c1 100644 --- a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/UserInterface/GridBasedIndicator_Base.cs +++ b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/UserInterface/GridBasedIndicator_Base.cs @@ -15,25 +15,36 @@ internal abstract class GridBasedIndicator_Base : MySessionComponentBase public override void UpdateAfterSimulation() { + base.UpdateAfterSimulation(); + if (MyAPIGateway.Utilities.IsDedicated || !HeartData.I.IsLoaded) + { Visible = false; - else - Visible = MyAPIGateway.Gui.GetCurrentScreen == MyTerminalPageEnum.None; + return; + } + + Visible = MyAPIGateway.Gui.GetCurrentScreen == MyTerminalPageEnum.None; if (!Visible) return; - IMyEntity controlledEntity = MyAPIGateway.Session.Player?.Controller?.ControlledEntity?.Entity?.GetTopMostParent(); // Get the currently controlled grid. + IMyEntity controlledEntity = MyAPIGateway.Session.Player?.Controller?.ControlledEntity?.Entity?.GetTopMostParent(); if (!(controlledEntity is IMyCubeGrid)) { controlledGrid = null; return; } - controlledGrid = (IMyCubeGrid)controlledEntity; // TODO: Make work on subparts + controlledGrid = (IMyCubeGrid)controlledEntity; - foreach (var gridWeapon in WeaponManager.I.GridWeapons[controlledGrid]) - PerWeaponUpdate(gridWeapon); + foreach (var weaponLogic in WeaponManager.I.GridWeapons[controlledGrid]) + { + // Check if the HUD Barrel Indicator is enabled for this weapon + if (weaponLogic.Terminal_Heart_ToggleHUDBarrelIndicator) + { + PerWeaponUpdate(weaponLogic); + } + } } public abstract void PerWeaponUpdate(SorterWeaponLogic weapon); diff --git a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/SorterTurretLogic.cs b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/SorterTurretLogic.cs index 0fbd662c..49ac46bb 100644 --- a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/SorterTurretLogic.cs +++ b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/SorterTurretLogic.cs @@ -266,7 +266,6 @@ internal override void LoadDefaultSettings() Terminal_Heart_TargetNeutrals = (Definition.Targeting.DefaultIFF & IFF_Enum.TargetNeutrals) == IFF_Enum.TargetNeutrals; Terminal_Heart_TargetUnowned = false; Terminal_Heart_PreferUniqueTargets = (Definition.Targeting.DefaultIFF & IFF_Enum.TargetUnique) == IFF_Enum.TargetUnique; - Terminal_Heart_ToggleHUDBarrelIndicator = false; } } @@ -328,9 +327,6 @@ internal override bool LoadSettings() Settings.TargetUnownedState = loadedSettings.TargetUnownedState; TargetUnownedState.Value = Settings.TargetUnownedState; - Settings.HudBarrelIndicatorState = loadedSettings.HudBarrelIndicatorState; - HudBarrelIndicatorState.Value = Settings.HudBarrelIndicatorState; - return baseRet; } } @@ -360,7 +356,6 @@ internal override bool LoadSettings() public MySync TargetNeutralsState; public MySync TargetEnemiesState; public MySync TargetUnownedState; - public MySync HudBarrelIndicatorState; public float Terminal_Heart_Range_Slider { @@ -539,21 +534,6 @@ public bool Terminal_Heart_TargetUnowned } } - public bool Terminal_Heart_ToggleHUDBarrelIndicator - { - get - { - return Settings.HudBarrelIndicatorState; - } - - set - { - Settings.HudBarrelIndicatorState = value; - HudBarrelIndicatorState.Value = value; - if ((NeedsUpdate & MyEntityUpdateEnum.EACH_10TH_FRAME) == 0) - NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME; - } - } #endregion } } diff --git a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/SorterWeaponLogic.cs b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/SorterWeaponLogic.cs index 3bab70ba..7122508d 100644 --- a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/SorterWeaponLogic.cs +++ b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/SorterWeaponLogic.cs @@ -35,6 +35,7 @@ public partial class SorterWeaponLogic : MyGameLogicComponent //insert ammo loaded state here (how the hell are we gonna do that) public MySync AmmoLoadedState; //dang this mysync thing is pretty cool it will surely not bite me in the ass when I need over 32 entries public MySync ControlTypeState; + public MySync HudBarrelIndicatorState; public readonly Heart_Settings Settings = new Heart_Settings(); @@ -372,6 +373,22 @@ public void CycleAmmoType(bool forward) Terminal_Heart_AmmoComboBox = Magazines.AmmoIndex; } + public bool Terminal_Heart_ToggleHUDBarrelIndicator + { + get + { + return Settings.HudBarrelIndicatorState; + } + + set + { + Settings.HudBarrelIndicatorState = value; + HudBarrelIndicatorState.Value = value; + if ((NeedsUpdate & MyEntityUpdateEnum.EACH_10TH_FRAME) == 0) + NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME; + } + } + #endregion #region Saving @@ -403,6 +420,8 @@ internal virtual void LoadDefaultSettings() Terminal_Heart_Shoot = false; Terminal_Heart_AmmoComboBox = 0; + Terminal_Heart_ToggleHUDBarrelIndicator = false; + } internal virtual bool LoadSettings() @@ -439,6 +458,9 @@ internal virtual bool LoadSettings() Settings.ControlTypeState = loadedSettings.ControlTypeState; ControlTypeState.Value = Settings.ControlTypeState; + Settings.HudBarrelIndicatorState = loadedSettings.HudBarrelIndicatorState; + HudBarrelIndicatorState.Value = Settings.HudBarrelIndicatorState; + return true; } } From d56a026cf5492e5c1e9ba8b77732af6cfa936c1a Mon Sep 17 00:00:00 2001 From: InvalidArgument3 Date: Tue, 13 Feb 2024 03:18:31 -0600 Subject: [PATCH 5/6] now, an action --- .../Setup/SorterWeaponTerminalControls.cs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/Setup/SorterWeaponTerminalControls.cs b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/Setup/SorterWeaponTerminalControls.cs index b9131dfc..63d51c34 100644 --- a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/Setup/SorterWeaponTerminalControls.cs +++ b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/Setup/SorterWeaponTerminalControls.cs @@ -647,6 +647,32 @@ static void CreateActions(IMyModContext context) @"Textures\GUI\Icons\Actions\Toggle.dds" ); } + + { + ControlsHelper.CreateAction( + "ToggleHUDBarrelIndicator", + "Toggle HUD Barrel Indicator", + (b) => + { + var logic = b?.GameLogic?.GetAs(); + if (logic != null) + { + // Toggle the "Target Unowned" option and ensure sync + logic.Terminal_Heart_ToggleHUDBarrelIndicator = !logic.Terminal_Heart_ToggleHUDBarrelIndicator; // Toggling the value + } + }, + (b, sb) => + { + var logic = b?.GameLogic?.GetAs(); + if (logic != null) + { + sb.Append(logic.Terminal_Heart_ToggleHUDBarrelIndicator ? "Ind. ON" : "Ind. OFF"); + } + }, + @"Textures\GUI\Icons\Actions\Toggle.dds" + ); + } + } From 79d6f99f0d2f86a6e8a2e4b3d2a835b9562acf79 Mon Sep 17 00:00:00 2001 From: InvalidArgument3 Date: Tue, 13 Feb 2024 04:47:02 -0600 Subject: [PATCH 6/6] resource window --- .../ResourceSystem/WeaponResourceSystem.cs | 7 ++ .../ReloadIndicators/ReloadIndicator.cs | 1 + .../UserInterface/ResourceStatusWindow.cs | 86 +++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/UserInterface/ResourceStatusWindow.cs diff --git a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/ResourceSystem/WeaponResourceSystem.cs b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/ResourceSystem/WeaponResourceSystem.cs index 2ba75214..b558865a 100644 --- a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/ResourceSystem/WeaponResourceSystem.cs +++ b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/ResourceSystem/WeaponResourceSystem.cs @@ -1,8 +1,15 @@ using System; using System.Collections.Generic; +using System.Runtime.Remoting.Messaging; using Heart_Module.Data.Scripts.HeartModule.Weapons.StandardClasses; +using RichHudFramework.Client; +using RichHudFramework.UI.Client; +using RichHudFramework.UI; using Sandbox.ModAPI; +using VRage.Game.Components; using YourName.ModName.Data.Scripts.HeartModule.Weapons.Setup.Adding; +using VRageMath; // For Vector2, Vector4, Color + namespace Heart_Module.Data.Scripts.HeartModule.ResourceSystem { diff --git a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/UserInterface/ReloadIndicators/ReloadIndicator.cs b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/UserInterface/ReloadIndicators/ReloadIndicator.cs index 08ab32d7..d36221f1 100644 --- a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/UserInterface/ReloadIndicators/ReloadIndicator.cs +++ b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/UserInterface/ReloadIndicators/ReloadIndicator.cs @@ -56,4 +56,5 @@ public override void PerWeaponUpdate(SorterWeaponLogic weapon) //Window?.UpdateWeaponText(weapon); } } + } diff --git a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/UserInterface/ResourceStatusWindow.cs b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/UserInterface/ResourceStatusWindow.cs new file mode 100644 index 00000000..80f143d4 --- /dev/null +++ b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/UserInterface/ResourceStatusWindow.cs @@ -0,0 +1,86 @@ +using RichHudFramework.Client; +using RichHudFramework.UI; +using RichHudFramework.UI.Client; +using VRage.Game.Components; +using VRageMath; + +namespace Heart_Module.Data.Scripts.HeartModule.UserInterface +{ + + [MySessionComponentDescriptor(MyUpdateOrder.AfterSimulation)] + internal class ResourceIndicator : MySessionComponentBase + { + private bool _hasInitedHud = false; + private ResourceStatusWindow _window; + + public override void UpdateAfterSimulation() + { + base.UpdateAfterSimulation(); + + if (!RichHudClient.Registered) + return; + + if (!_hasInitedHud) + InitHud(); + + try + { + // Here you would fetch the current resource count and update the window. + // For demonstration purposes, let's assume a method GetResourceCount() returns an int. + int resourceCount = GetResourceCount(); // You need to implement this method. + _window.UpdateResourceInfo($"Resources: {resourceCount}"); + } + catch { /* Handle any exceptions appropriately */ } + } + + private void InitHud() + { + _window = new ResourceStatusWindow(HudMain.HighDpiRoot) + { + Visible = true, + }; + + _hasInitedHud = true; + } + + private int GetResourceCount() + { + // Implement logic to retrieve the current resource count + return 0; // Placeholder return + } + } + + internal class ResourceStatusWindow : WindowBase + { + private Label _resourceInfo; + + public ResourceStatusWindow(HudParentBase parent) : base(parent) + { + _resourceInfo = new Label(body) + { + ParentAlignment = ParentAlignments.Top | ParentAlignments.InnerH | ParentAlignments.InnerV, + Text = "Resource Status: Initializing...", + AutoResize = false, + DimAlignment = DimAlignments.Both, + }; + + // Window styling + BodyColor = new Color(41, 54, 62, 150); + BorderColor = new Color(58, 68, 77); + + header.Format = new GlyphFormat(Vector4.One, TextAlignment.Center); + header.Height = 30f; + + HeaderText = "Resource Status"; + Size = new Vector2(250f, 150f); + // Adjust Offset here to align it with the ReloadWindow but a bit to the left + Offset = new Vector2(580, 464); + } + + public void UpdateResourceInfo(string infoText) + { + _resourceInfo.Text = infoText; + } + } + +}