Skip to content

Commit

Permalink
Merge pull request StarCoreSE#145 from InvalidArgument3/morehudandter…
Browse files Browse the repository at this point in the history
…minal

terminal option for barrel indicator and attempt at richhud
  • Loading branch information
InvalidArgument3 authored Feb 13, 2024
2 parents 4e7f901 + 79d6f99 commit 4eb1807
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ public override void PerWeaponUpdate(SorterWeaponLogic weapon)
//Window?.UpdateWeaponText(weapon);
}
}

}
Original file line number Diff line number Diff line change
@@ -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;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,8 @@ public class Heart_Settings

[ProtoMember(15)]
public bool MouseShootState;

[ProtoMember(16)]
public bool HudBarrelIndicatorState;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,22 @@ static void CreateControls()
(b, v) => b.GameLogic.GetAs<SorterTurretLogic>().Terminal_Heart_TargetUnowned = v
);
}
{
var c = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlLabel, IMyConveyorSorter>(IdPrefix + "HeartWeaponHUDDivider");
c.Label = MyStringId.GetOrCompute("=== HUD ===");
c.SupportsMultipleBlocks = true;
c.Visible = CustomVisibleCondition;
MyAPIGateway.TerminalControls.AddControl<IMyConveyorSorter>(c);
}
{
ControlsHelper.CreateToggle<SorterTurretLogic>(
"HeartHUDBarrelIndicatorToggle",
"HUD Barrel Indicator",
"HUDBarrelIndicatorDesc",
(b) => b.GameLogic.GetAs<SorterTurretLogic>().Terminal_Heart_ToggleHUDBarrelIndicator,
(b, v) => b.GameLogic.GetAs<SorterTurretLogic>().Terminal_Heart_ToggleHUDBarrelIndicator = v
);
}
}

static void CreateActions(IMyModContext context)
Expand Down Expand Up @@ -631,6 +647,32 @@ static void CreateActions(IMyModContext context)
@"Textures\GUI\Icons\Actions\Toggle.dds"
);
}

{
ControlsHelper.CreateAction<SorterTurretLogic>(
"ToggleHUDBarrelIndicator",
"Toggle HUD Barrel Indicator",
(b) =>
{
var logic = b?.GameLogic?.GetAs<SorterTurretLogic>();
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<SorterTurretLogic>();
if (logic != null)
{
sb.Append(logic.Terminal_Heart_ToggleHUDBarrelIndicator ? "Ind. ON" : "Ind. OFF");
}
},
@"Textures\GUI\Icons\Actions\Toggle.dds"
);
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ 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;

}
}

Expand Down Expand Up @@ -532,6 +533,7 @@ public bool Terminal_Heart_TargetUnowned
NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME;
}
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public partial class SorterWeaponLogic : MyGameLogicComponent
//insert ammo loaded state here (how the hell are we gonna do that)
public MySync<long, SyncDirection.BothWays> 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<long, SyncDirection.BothWays> ControlTypeState;
public MySync<bool, SyncDirection.BothWays> HudBarrelIndicatorState;

public readonly Heart_Settings Settings = new Heart_Settings();

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -403,6 +420,8 @@ internal virtual void LoadDefaultSettings()

Terminal_Heart_Shoot = false;
Terminal_Heart_AmmoComboBox = 0;
Terminal_Heart_ToggleHUDBarrelIndicator = false;

}

internal virtual bool LoadSettings()
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 4eb1807

Please sign in to comment.