internal static void CreateOnOffActionSet <T>(IMyTerminalControlOnOffSwitch tc, string name, int id, Func <IMyTerminalBlock, int, bool> enabler, bool group = false) where T : IMyTerminalBlock { var action0 = MyAPIGateway.TerminalControls.CreateAction <T>($"WC_{id}_Toggle"); action0.Icon = @"Textures\GUI\Icons\Actions\Toggle.dds"; action0.Name = new StringBuilder($"{name} Toggle On/Off"); action0.Action = (b) => tc.Setter(b, !tc.Getter(b)); action0.Writer = (b, t) => t.Append(tc.Getter(b) ? tc.OnText : tc.OffText); action0.Enabled = (b) => enabler(b, id); action0.ValidForGroups = group; MyAPIGateway.TerminalControls.AddAction <T>(action0); var action1 = MyAPIGateway.TerminalControls.CreateAction <T>($"WC_{id}_Toggle_On"); action1.Icon = @"Textures\GUI\Icons\Actions\SwitchOn.dds"; action1.Name = new StringBuilder($"{name} On"); action1.Action = (b) => tc.Setter(b, true); action1.Writer = (b, t) => t.Append(tc.Getter(b) ? tc.OnText : tc.OffText); action1.Enabled = (b) => enabler(b, id); action1.ValidForGroups = group; MyAPIGateway.TerminalControls.AddAction <T>(action1); var action2 = MyAPIGateway.TerminalControls.CreateAction <T>($"WC_{id}_Toggle_Off"); action2.Icon = @"Textures\GUI\Icons\Actions\SwitchOff.dds"; action2.Name = new StringBuilder($"{name} Off"); action2.Action = (b) => tc.Setter(b, true); action2.Writer = (b, t) => t.Append(tc.Getter(b) ? tc.OnText : tc.OffText); action2.Enabled = (b) => enabler(b, id); action2.ValidForGroups = group; MyAPIGateway.TerminalControls.AddAction <T>(action2); }
//forces GUI refresh public static void RefreshTerminalControls(IMyTerminalBlock b) { if (RefreshToggle != null) { var originalSetting = RefreshToggle.Getter(b); RefreshToggle.Setter(b, !originalSetting); RefreshToggle.Setter(b, originalSetting); } }
public void CreateShuntAction <T>(IMyTerminalControlOnOffSwitch c) { try { var id = ((IMyTerminalControl)c).Id; var gamePath = MyAPIGateway.Utilities.GamePaths.ContentPath; Action <IMyTerminalBlock, StringBuilder> writer = (b, s) => s.Append(c.Getter(b) ? c.OnText : c.OffText); { var a = MyAPIGateway.TerminalControls.CreateAction <T>(id + "_ShuntToggle"); a.Name = new StringBuilder(c.Title.String).Append(" - ").Append($" {Localization.GetText("TerminalSwitchPush")}").Append(" /").Append($" {Localization.GetText("TerminalSwitchPull")}"); a.Icon = gamePath + @"\Textures\GUI\Icons\Actions\SmallShipToggle.dds"; a.ValidForGroups = true; a.Action = (b) => c.Setter(b, !c.Getter(b)); a.Writer = writer; MyAPIGateway.TerminalControls.AddAction <T>(a); } { var a = MyAPIGateway.TerminalControls.CreateAction <T>(id + "_ShuntOn"); a.Name = new StringBuilder(c.Title.String).Append(" - ").Append($" {Localization.GetText("TerminalSwitchPush")}"); a.Icon = gamePath + @"\Textures\GUI\Icons\Actions\SmallShipSwitchOn.dds"; a.ValidForGroups = true; a.Action = (b) => c.Setter(b, true); a.Writer = writer; MyAPIGateway.TerminalControls.AddAction <T>(a); } { var a = MyAPIGateway.TerminalControls.CreateAction <T>(id + "_ShuntOff"); a.Name = new StringBuilder(c.Title.String).Append(" - ").Append($" {Localization.GetText("TerminalSwitchPull")}"); a.Icon = gamePath + @"\Textures\GUI\Icons\Actions\LargeShipSwitchOn.dds"; a.ValidForGroups = true; a.Action = (b) => c.Setter(b, false); a.Writer = writer; MyAPIGateway.TerminalControls.AddAction <T>(a); } } catch (Exception ex) { Log.Line($"Exception in CreateAction: {ex}"); } }
public static IMyTerminalAction CreateOnAction <TBlock>(this IMyTerminalControlOnOffSwitch @switch, string iconPath) where TBlock : IMyTerminalBlock { var onText = MyTexts.Get(@switch.OnText); var offText = MyTexts.Get(@switch.OffText); var name = GetTitle(@switch.Title).Append(" ").Append(onText); var action = MyAPIGateway.TerminalControls.CreateAction <TBlock>(((IMyTerminalControl)@switch).Id + "_On"); action.Name = name; action.Action = block => @switch.Setter(block, true); action.Writer = (block, sb) => sb.Append(@switch.Getter(block) ? onText : offText); action.Icon = iconPath; action.Enabled = @switch.Enabled; return(action); }
private void InitControls() { ThrusterOverclock = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyThrust>("Overclock"); ThrusterOverclock.Title = MyStringId.GetOrCompute("Overclock"); ThrusterOverclock.Tooltip = MyStringId.GetOrCompute("Multiplies thruster power at the cost of heat and degradation."); ThrusterOverclock.SetLimits(1, maxThrusterOverclock); ThrusterOverclock.SupportsMultipleBlocks = true; ThrusterOverclock.Getter = (x) => { if (x == null || x.GameLogic == null) { return(1f); } var logic = x.GameLogic.GetAs <ThrustOverride>(); return(logic != null ? logic.Overclock : 1f); }; ThrusterOverclock.Setter = (x, y) => { var logic = x.GameLogic.GetAs <ThrustOverride>(); if (logic != null) { logic.Overclock = y; if (Sync.IsClient) { var message = new MessageThrusterVariables(); message.EntityId = logic.Entity.EntityId; message.UpdateCustomData = true; message.Overclock = logic.Overclock; message.SafetySwitch = logic.SafetySwitch; Messaging.SendMessageToServer(message); } } }; ThrusterOverclock.Writer = (x, y) => { if (x == null || x.GameLogic == null) { return; } var logic = x.GameLogic.GetAs <ThrustOverride>(); if (logic != null) { y.Append(logic.Overclock.ToString() + "x"); } }; SafetySwitch = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlOnOffSwitch, IMyThrust>("SafetySwitch"); SafetySwitch.Title = MyStringId.GetOrCompute("Safety Switch"); SafetySwitch.Tooltip = MyStringId.GetOrCompute("When enabled, reduces thrust when necessary to prevent damage from excessive heat.\nTurning this off can allow steady thrust over longer periods of time,\nwhich can be useful in emergencies."); SafetySwitch.OnText = MyStringId.GetOrCompute("On"); SafetySwitch.OffText = MyStringId.GetOrCompute("Off"); SafetySwitch.SupportsMultipleBlocks = true; SafetySwitch.Getter = x => { if (x == null || x.GameLogic == null) { return(true); } var logic = x.GameLogic.GetAs <ThrustOverride>(); return(logic != null ? logic.SafetySwitch : true); }; SafetySwitch.Setter = (x, y) => { Debug.Write("Attempting to set safety switch", 1); if (x == null || x.GameLogic == null) { return; } var logic = x.GameLogic.GetAs <ThrustOverride>(); logic.SafetySwitch = y; if (Sync.IsClient) { Debug.Write("Set safety switch on client", 1); } if (Sync.IsServer) { Debug.Write("Set safety switch on server", 1); } if (Sync.IsClient) { var message = new MessageThrusterVariables(); message.UpdateCustomData = true; message.EntityId = logic.Entity.EntityId; message.Overclock = logic.Overclock; message.SafetySwitch = logic.SafetySwitch; Messaging.SendMessageToServer(message); } }; safetySwitchAction = MyAPIGateway.TerminalControls.CreateAction <IMyThrust>("SafetySwitchAction"); safetySwitchAction.Enabled = (x) => true; safetySwitchAction.Name = new StringBuilder(string.Format("Safety Toggle On/Off")); safetySwitchAction.Icon = @"Textures\GUI\Icons\Actions\Toggle.dds"; safetySwitchAction.Action = (x) => { if (x == null || SafetySwitch == null) { return; } SafetySwitch.Setter(x, !SafetySwitch.Getter(x)); }; safetySwitchAction.ValidForGroups = true; safetySwitchAction.Writer = (x, y) => { if (x == null || SafetySwitch == null) { return; } y.Append(SafetySwitch.Getter(x) ? "On" : "Off"); }; safetySwitchAction.InvalidToolbarTypes = new List <MyToolbarType>(); overclockActionIncrease = MyAPIGateway.TerminalControls.CreateAction <IMyThrust>("OverclockActionIncrease"); overclockActionIncrease.Enabled = (x) => true; overclockActionIncrease.Name = new StringBuilder(string.Format("Increase Overclock")); overclockActionIncrease.Icon = @"Textures\GUI\Icons\Actions\Increase.dds"; overclockActionIncrease.ValidForGroups = true; overclockActionIncrease.Action = (x) => { if (x == null || ThrusterOverclock == null) { return; } ThrusterOverclock.Setter(x, Math.Min(ThrusterOverclock.Getter(x) + 1f, maxThrusterOverclock)); }; overclockActionIncrease.Writer = (x, y) => { if (x == null || ThrusterOverclock == null) { return; } y.Append(ThrusterOverclock.Getter(x).ToString() + "x"); }; overclockActionIncrease.InvalidToolbarTypes = new List <MyToolbarType>(); overclockActionDecrease = MyAPIGateway.TerminalControls.CreateAction <IMyThrust>("OverclockActionDecrease"); overclockActionDecrease.Enabled = (x) => true; overclockActionDecrease.Name = new StringBuilder(string.Format("Decrease Overclock")); overclockActionDecrease.Icon = @"Textures\GUI\Icons\Actions\Decrease.dds"; overclockActionDecrease.ValidForGroups = true; overclockActionDecrease.Action = (x) => { if (x == null || ThrusterOverclock == null) { return; } ThrusterOverclock.Setter(x, Math.Max(ThrusterOverclock.Getter(x) - 1f, 1f)); }; overclockActionDecrease.Writer = (x, y) => { if (x == null || ThrusterOverclock == null) { return; } y.Append(ThrusterOverclock.Getter(x).ToString() + "x"); }; overclockActionDecrease.InvalidToolbarTypes = new List <MyToolbarType>(); }