internal static void CreateOnOffActionSet(Session session, IMyTerminalControlOnOffSwitch tc, string name, int id, Func <IMyTerminalBlock, bool> enabler, bool group = false)
        {
            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        = enabler;
            action0.ValidForGroups = group;

            MyAPIGateway.TerminalControls.AddAction <T>(action0);
            session.CustomActions.Add(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        = enabler;
            action1.ValidForGroups = group;

            MyAPIGateway.TerminalControls.AddAction <T>(action1);
            session.CustomActions.Add(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        = enabler;
            action2.ValidForGroups = group;

            MyAPIGateway.TerminalControls.AddAction <T>(action2);
            session.CustomActions.Add(action2);
        }
Example #2
0
        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);
        }
Example #3
0
        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>();
        }