Skip to content

Commit

Permalink
Merge branch 'main' into projectile-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ari-steas authored Jan 5, 2024
2 parents 2f2c274 + 0e07511 commit fc6bb0e
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ namespace YourName.ModName.Data.Scripts.HeartModule.Weapons
public class Heart_Settings
{
[ProtoMember(1)]
public float CringeSetting;
public bool ShootState;

[ProtoMember(2)]
public float BasedSetting;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
using Sandbox.ModAPI;
using System;
using VRage.Game.Components;
using VRage.Game.ModAPI.Network;
using VRage.ModAPI;
using VRage.ObjectBuilders;
using VRage.Sync;
using VRageMath;
using YourName.ModName.Data.Scripts.HeartModule.Utility;

namespace YourName.ModName.Data.Scripts.HeartModule.Weapons.Setup.Adding
{
// For more info about the gamelogic comp see https://github.com/THDigi/SE-ModScript-Examples/blob/master/Data/Scripts/Examples/BasicExample_GameLogicAndSession/GameLogic.cs
[MyEntityComponentDescriptor(typeof(MyObjectBuilder_ConveyorSorter), false, "TestWeapon")]
public class SorterWeaponLogic : MyGameLogicComponent
{
Expand All @@ -18,6 +20,7 @@ public class SorterWeaponLogic : MyGameLogicComponent
public const int HeartSettingsUpdateCount = 60 * 1 / 10;
int SyncCountdown;

public MySync<bool, SyncDirection.BothWays> ShootState; //temporary (lmao) magic bullshit in place of an actual

public readonly Heart_Settings Settings = new Heart_Settings();

Expand All @@ -27,8 +30,18 @@ public class SorterWeaponLogic : MyGameLogicComponent
public override void Init(MyObjectBuilder_EntityBase objectBuilder)
{
NeedsUpdate = MyEntityUpdateEnum.BEFORE_NEXT_FRAME;

ShootState.ValueChanged += OnShootStateChanged; // Attach the handler
}

private void OnShootStateChanged(MySync<bool, SyncDirection.BothWays> obj)
{
// Accessing the boolean value using .Value property
bool newValue = obj.Value;
MyAPIGateway.Utilities.ShowNotification($"Shoot State changed to: {newValue}", 2000, "White");
}


public override void UpdateOnceBeforeFrame()
{
SorterWeaponTerminalControls.DoOnce(ModContext);
Expand All @@ -37,31 +50,38 @@ public override void UpdateOnceBeforeFrame()
if (SorterWep.CubeGrid?.Physics == null)
return; // ignore ghost/projected grids

// stuff and things
// LoadSettings(); // artifact from chets meme
}

// these are going to be set or retrieved by the terminal controls (as seen in the terminal control's Getter and Setter).

// as mentioned in the other .cs file, the terminal stuff are only GUI.
// if you want the values to persist over world reloads and be sent to clients you'll need to implement that yourself.
// see: https://github.com/THDigi/SE-ModScript-Examples/wiki/Save-&-Sync-ways
public float Terminal_ExampleFloat { get; set; }

public bool Terminal_Heart_Shoot
{
get
{
MyAPIGateway.Utilities.ShowNotification("Terminal_Heart_Shoot Getter called");
return shoot;

return Settings.ShootState;
}

set
{
shoot = value;
MyAPIGateway.Utilities.ShowNotification("Terminal_Heart_Shoot Getter called");
MyAPIGateway.Utilities.ShowNotification("Terminal_Heart_Shoot" + value);
Settings.ShootState = true;

if ((NeedsUpdate & MyEntityUpdateEnum.EACH_10TH_FRAME) == 0)
NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME;

}
}


public float Terminal_ExampleFloat { get; set; }

public override void Close()
{
base.Close();
// Unsubscribe from the event when the component is closed
if (ShootState != null)
ShootState.ValueChanged -= OnShootStateChanged;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
using Sandbox.Game.Localization;
using Sandbox.ModAPI;
Expand Down Expand Up @@ -71,88 +72,77 @@ static void CreateControls()
MyAPIGateway.TerminalControls.AddControl<IMyConveyorSorter>(c);
}
{
var c = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlLabel, IMyConveyorSorter>(IdPrefix + "SampleLabel");
c.Label = MyStringId.GetOrCompute("Sample Label");
var c = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlLabel, IMyConveyorSorter>(IdPrefix + "HeartWeaponOptions");
c.Label = MyStringId.GetOrCompute("HeartWeaponOptions");
c.SupportsMultipleBlocks = true;
c.Visible = CustomVisibleCondition;

MyAPIGateway.TerminalControls.AddControl<IMyConveyorSorter>(c);
}
{
var c = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlOnOffSwitch, IMyConveyorSorter>(IdPrefix + "SampleOnOff");
c.Title = MyStringId.GetOrCompute("Shoot");
c.Tooltip = MyStringId.GetOrCompute("This does some stuff!");
c.SupportsMultipleBlocks = true; // wether this control should be visible when multiple blocks are selected (as long as they all have this control).
var ShootToggle = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlOnOffSwitch, IMyConveyorSorter>(IdPrefix + "Shoot");
ShootToggle.Title = MyStringId.GetOrCompute("Toogle Shoot");
ShootToggle.Tooltip = MyStringId.GetOrCompute("This does some stuff!");
ShootToggle.SupportsMultipleBlocks = true; // wether this control should be visible when multiple blocks are selected (as long as they all have this control).

// callbacks to determine if the control should be visible or not-grayed-out(Enabled) depending on whatever custom condition you want, given a block instance.
// optional, they both default to true.
c.Visible = CustomVisibleCondition;
ShootToggle.Visible = CustomVisibleCondition;
//c.Enabled = CustomVisibleCondition;

c.OnText = MySpaceTexts.SwitchText_On;
c.OffText = MySpaceTexts.SwitchText_Off;
ShootToggle.OnText = MySpaceTexts.SwitchText_On;
ShootToggle.OffText = MySpaceTexts.SwitchText_Off;
//c.OffText = MyStringId.GetOrCompute("Off");

// setters and getters should both be assigned on all controls that have them, to avoid errors in mods or PB scripts getting exceptions from them.
c.Getter = (b) => b?.GameLogic?.GetAs<SorterWeaponLogic>()?.Terminal_Heart_Shoot ?? false; //?? when statement on left is null, this is false
c.Setter = (b, v) =>
{
var logic = b?.GameLogic?.GetAs<SorterWeaponLogic>();
if (logic != null)
logic.Terminal_Heart_Shoot = v;
};
ShootToggle.Getter = (b) => b.GameLogic.GetAs<SorterWeaponLogic>().ShootState.Value; // Getting the value
ShootToggle.Setter = (b, v) => b.GameLogic.GetAs<SorterWeaponLogic>().ShootState.Value = v; // Setting the value

MyAPIGateway.TerminalControls.AddControl<IMyConveyorSorter>(c);

MyAPIGateway.TerminalControls.AddControl<IMyConveyorSorter>(ShootToggle);
}
}

static void CreateActions(IMyModContext context)
{
// yes, there's only one type of action
{
var a = MyAPIGateway.TerminalControls.CreateAction<IMyConveyorSorter>(IdPrefix + "SampleAction");

a.Name = new StringBuilder("Sample Action");
var ShootToggleAction = MyAPIGateway.TerminalControls.CreateAction<IMyConveyorSorter>(IdPrefix + "ToggleShoot");

// If the action is visible for grouped blocks (as long as they all have this action).
a.ValidForGroups = true;
ShootToggleAction.Name = new StringBuilder("Toggle Shoot");

// The icon shown in the list and top-right of the block icon in toolbar.
a.Icon = @"Textures\GUI\Icons\Actions\CharacterToggle.dds";
// For paths inside the mod folder you need to supply an absolute path which can be retrieved from a session or gamelogic comp's ModContext.
//a.Icon = Path.Combine(context.ModPath, @"Textures\YourIcon.dds");
// If the action is visible for grouped blocks (as long as they all have this action).
ShootToggleAction.ValidForGroups = true;

// Called when the toolbar slot is triggered
// Should not be unassigned.
a.Action = (b) => { };
// The icon shown in the list and top-right of the block icon in toolbar.
ShootToggleAction.Icon = @"Textures\GUI\Icons\Actions\Toggle.dds";

// The status of the action, shown in toolbar icon text and can also be read by mods or PBs.
a.Writer = (b, sb) =>
// Called when the toolbar slot is triggered
ShootToggleAction.Action = (b) =>
{
var logic = b?.GameLogic?.GetAs<SorterWeaponLogic>();
if (logic != null && logic.ShootState != null)
{
sb.Append("Hi\nthere");
};
// Toggle the shoot state and ensure sync
logic.ShootState.Value = !logic.ShootState.Value; // Toggling the value
MyAPIGateway.Utilities.ShowNotification($"Shoot Action toggled to: {(logic.ShootState.Value ? "ON" : "OFF")}", 2000, "White");
}
};

// Define what the action's tooltip/status text should say
ShootToggleAction.Writer = (b, sb) =>
{
var logic = b?.GameLogic?.GetAs<SorterWeaponLogic>();
if (logic != null && logic.ShootState != null)
{
sb.Append(logic.ShootState.Value ? "Shooting" : "Not Shooting");
}
};

// What toolbar types to NOT allow this action for.
// Can be left unassigned to allow all toolbar types.
// The below are the options used by jumpdrive's Jump action as an example.
//a.InvalidToolbarTypes = new List<MyToolbarType>()
//{
// MyToolbarType.ButtonPanel,
// MyToolbarType.Character,
// MyToolbarType.Seat
//};
// PB checks if it's valid for ButtonPanel before allowing the action to be invoked.

// Wether the action is to be visible for the given block instance.
// Can be left unassigned as it defaults to true.
// Warning: gets called per tick while in toolbar for each block there, including each block in groups.
// It also can be called by mods or PBs.
a.Enabled = CustomVisibleCondition;

MyAPIGateway.TerminalControls.AddAction<IMyConveyorSorter>(a);
}
ShootToggleAction.Enabled = CustomVisibleCondition;

MyAPIGateway.TerminalControls.AddAction<IMyConveyorSorter>(ShootToggleAction);
}


static void CreateProperties()
{
// Terminal controls automatically generate properties like these, but you can also add new ones manually without the GUI counterpart.
Expand Down

0 comments on commit fc6bb0e

Please sign in to comment.