internal static void CreateOnOffActionSet <T>(IMyTerminalControlCheckbox 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);
        }
Beispiel #2
0
        private void CreateTerminalControls()
        {
            if (_ControlsInited)
            {
                return;
            }

            _ControlsInited = true;
            bool enabledCheck(IMyTerminalBlock b)
            {
                return(b.BlockDefinition.SubtypeId == "DrillPlatform");
            }

            m_enableStone = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlCheckbox, IMyAssembler>("EnableStone");
            // Separator
            var sep = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSeparator, IMyAssembler>(string.Empty);

            if (sep != null)
            {
                sep.Visible = enabledCheck;
                sep.Enabled = enabledCheck;
                MyAPIGateway.TerminalControls.AddControl <IMyAssembler>(sep);
            }
            // EnableStone checkbox
            if (m_enableStone != null)
            {
                m_enableStone.Title   = MyStringId.GetOrCompute("开采石头");
                m_enableStone.Tooltip = MyStringId.GetOrCompute("启用此选项将会在设备中产生石头。");
                m_enableStone.Getter  = (b) => enabledCheck(b) && b.GameLogic.GetAs <Rig>().StoneEnabled;
                m_enableStone.Setter  = (b, v) => { if (enabledCheck(b))
                                                    {
                                                        MessageUtils.SendMessageToAll(new MessageToggleStoneEnable()
                        {
                            EntityId = b.EntityId, EnableStone = v
                        });
                                                    }
                };
                m_enableStone.Visible = enabledCheck;
                m_enableStone.Enabled = enabledCheck;
                m_enableStone.OnText  = MyStringId.GetOrCompute("On");
                m_enableStone.OffText = MyStringId.GetOrCompute("Off");
                MyAPIGateway.TerminalControls.AddControl <IMyAssembler>(m_enableStone);

                var action = MyAPIGateway.TerminalControls.CreateAction <IMyAssembler>("EnableStone");
                if (action != null)
                {
                    StringBuilder actionname = new StringBuilder();
                    actionname.Append(m_enableStone.Title).Append(" ").Append(m_enableStone.OnText).Append("/").Append(m_enableStone.OffText);

                    action.Name           = actionname;
                    action.Icon           = @"Textures\GUI\Icons\Actions\Toggle.dds";
                    action.ValidForGroups = true;
                    action.Action         = (b) => m_enableStone.Setter(b, !m_enableStone.Getter(b));
                    action.Writer         = (b, t) => t.Append(b.GameLogic.GetAs <Rig>().StoneEnabled ? m_enableStone.OnText : m_enableStone.OffText);

                    MyAPIGateway.TerminalControls.AddAction <IMyAssembler>(action);
                }
            }
        }
Beispiel #3
0
        public static IMyTerminalAction CreateToggleAction <TBlock>(this IMyTerminalControlCheckbox checkbox, string iconPath) where TBlock : IMyTerminalBlock
        {
            var onText  = MyTexts.Get(checkbox.OnText);
            var offText = MyTexts.Get(checkbox.OffText);
            var name    = GetTitle(checkbox.Title).Append(" ").Append(onText).Append("/").Append(offText);

            var action = MyAPIGateway.TerminalControls.CreateAction <TBlock>(((IMyTerminalControl)checkbox).Id);

            action.Name = name;

            action.Action  = block => checkbox.Setter(block, !checkbox.Getter(block));
            action.Writer  = (block, sb) => sb.Append(checkbox.Getter(block) ? onText : offText);
            action.Icon    = iconPath;
            action.Enabled = checkbox.Enabled;

            return(action);
        }
        private void CreateAction <T>(IMyTerminalControlCheckbox c,
                                      bool addToggle    = true,
                                      bool addOnOff     = false,
                                      string iconPack   = null,
                                      string iconToggle = null,
                                      string iconOn     = null,
                                      string iconOff    = null)
        {
            try
            {
                var id   = ((IMyTerminalControl)c).Id;
                var name = c.Title.String;
                Action <IMyTerminalBlock, StringBuilder> writer = (b, s) => s.Append(c.Getter(b) ? c.OnText : c.OffText);

                if (iconToggle == null && iconOn == null && iconOff == null)
                {
                    var pack     = iconPack ?? string.Empty;
                    var gamePath = MyAPIGateway.Utilities.GamePaths.ContentPath;
                    iconToggle = gamePath + @"\Textures\GUI\Icons\Actions\" + pack + "Toggle.dds";
                    iconOn     = gamePath + @"\Textures\GUI\Icons\Actions\" + pack + "SwitchOn.dds";
                    iconOff    = gamePath + @"\Textures\GUI\Icons\Actions\" + pack + "SwitchOff.dds";
                }

                if (addToggle)
                {
                    var a = MyAPIGateway.TerminalControls.CreateAction <T>(id + "_Toggle");
                    a.Name           = new StringBuilder(name).Append(" On/Off");
                    a.Icon           = iconToggle;
                    a.ValidForGroups = true;
                    a.Action         = (b) => c.Setter(b, !c.Getter(b));
                    if (writer != null)
                    {
                        a.Writer = writer;
                    }

                    MyAPIGateway.TerminalControls.AddAction <T>(a);
                }

                if (addOnOff)
                {
                    {
                        var a = MyAPIGateway.TerminalControls.CreateAction <T>(id + "_On");
                        a.Name           = new StringBuilder(name).Append(" On");
                        a.Icon           = iconOn;
                        a.ValidForGroups = true;
                        a.Action         = (b) => c.Setter(b, true);
                        if (writer != null)
                        {
                            a.Writer = writer;
                        }

                        MyAPIGateway.TerminalControls.AddAction <T>(a);
                    }
                    {
                        var a = MyAPIGateway.TerminalControls.CreateAction <T>(id + "_Off");
                        a.Name           = new StringBuilder(name).Append(" Off");
                        a.Icon           = iconOff;
                        a.ValidForGroups = true;
                        a.Action         = (b) => c.Setter(b, false);
                        if (writer != null)
                        {
                            a.Writer = writer;
                        }

                        MyAPIGateway.TerminalControls.AddAction <T>(a);
                    }
                }
            }
            catch (Exception ex) { Log.Line($"Exception in CreateAction<T>(IMyTerminalControlCheckbox: {ex}"); }
        }