예제 #1
0
        public static void CreateControlOnOff(string id, string title, string tooltip, string OnText, string OffText, Func <IMyTerminalBlock, bool> visible, Func <IMyTerminalBlock, bool> enabled, Func <IMyTerminalBlock, bool> getter, Action <IMyTerminalBlock, bool> setter)
        {
            if (ControlIdExists(id) != null)
            {
                return;
            }

            IMyTerminalControlOnOffSwitch mode = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlOnOffSwitch, IMyUpgradeModule>(id);

            mode.Enabled = enabled;
            mode.Visible = visible;
            mode.SupportsMultipleBlocks = false;

            if (title != null)
            {
                mode.Title = MyStringId.GetOrCompute(title);
            }
            if (tooltip != null)
            {
                mode.Tooltip = MyStringId.GetOrCompute(tooltip);
            }

            mode.OnText  = MyStringId.GetOrCompute(OnText);
            mode.OffText = MyStringId.GetOrCompute(OffText);

            mode.Getter = getter;
            mode.Setter = setter;

            MyAPIGateway.TerminalControls.AddControl <IMyUpgradeModule>(mode);
        }
        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);
        }
예제 #3
0
        void CreateCustomTerminalControls()
        {
            if (_terminalControlsInit)
            {
                return;
            }

            _terminalControlsInit = true;

            IMyTerminalControlOnOffSwitch rechargeControl = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlOnOffSwitch, IMyLargeGatlingTurret>("RechargeRailgun");

            rechargeControl.Title   = MyStringId.GetOrCompute("Recharge Railgun");
            rechargeControl.Enabled = x => x.BlockDefinition.SubtypeId.Equals("LargeRailgunTurretLZM");
            rechargeControl.Visible = x => x.BlockDefinition.SubtypeId.Equals("LargeRailgunTurretLZM");
            rechargeControl.SupportsMultipleBlocks = true;
            rechargeControl.OnText  = MyStringId.GetOrCompute("On");
            rechargeControl.OffText = MyStringId.GetOrCompute("Off");
            rechargeControl.Setter  = (x, v) => SetRecharging(x, v);
            rechargeControl.Getter  = x => GetRecharging(x);
            MyAPIGateway.TerminalControls.AddControl <IMyLargeGatlingTurret>(rechargeControl);

            //Recharge toggle action
            IMyTerminalAction rechargeOnOff = MyAPIGateway.TerminalControls.CreateAction <IMyLargeGatlingTurret>("Recharge_OnOff");

            rechargeOnOff.Action = (x) =>
            {
                var recharge = GetRecharging(x);
                SetRecharging(x, !recharge);
            };
            rechargeOnOff.ValidForGroups = true;
            rechargeOnOff.Writer         = (x, s) => GetWriter(x, s);
            rechargeOnOff.Icon           = @"Textures\GUI\Icons\Actions\Toggle.dds";
            rechargeOnOff.Enabled        = x => x.BlockDefinition.SubtypeId.Equals("LargeRailgunTurretLZM");
            rechargeOnOff.Name           = new StringBuilder("Recharge On/Off");
            MyAPIGateway.TerminalControls.AddAction <IMyLargeGatlingTurret>(rechargeOnOff);

            //Recharge on action
            IMyTerminalAction rechargeOn = MyAPIGateway.TerminalControls.CreateAction <IMyLargeGatlingTurret>("Recharge_On");

            rechargeOn.Action         = (x) => SetRecharging(x, true);
            rechargeOn.ValidForGroups = true;
            rechargeOn.Writer         = (x, s) => GetWriter(x, s);
            rechargeOn.Icon           = @"Textures\GUI\Icons\Actions\SwitchOn.dds";
            rechargeOn.Enabled        = x => x.BlockDefinition.SubtypeId.Equals("LargeRailgunTurretLZM");
            rechargeOn.Name           = new StringBuilder("Recharge On");
            MyAPIGateway.TerminalControls.AddAction <IMyLargeGatlingTurret>(rechargeOn);

            //Recharge off action
            IMyTerminalAction rechargeOff = MyAPIGateway.TerminalControls.CreateAction <IMyLargeGatlingTurret>("Recharge_Off");

            rechargeOff.Action         = (x) => SetRecharging(x, false);
            rechargeOff.ValidForGroups = true;
            rechargeOff.Writer         = (x, s) => GetWriter(x, s);
            rechargeOff.Icon           = @"Textures\GUI\Icons\Actions\SwitchOff.dds";
            rechargeOff.Enabled        = x => x.BlockDefinition.SubtypeId.Equals("LargeRailgunTurretLZM");
            rechargeOff.Name           = new StringBuilder("Recharge Off");
            MyAPIGateway.TerminalControls.AddAction <IMyLargeGatlingTurret>(rechargeOff);
        }
예제 #4
0
        public static bool GetRefreshToggle()
        {
            List <IMyTerminalControl> items;

            MyAPIGateway.TerminalControls.GetControls <IMyTerminalBlock>(out items);

            foreach (var item in items)
            {
                if (item.Id == "ShowInToolbarConfig")
                {
                    RefreshToggle = (IMyTerminalControlOnOffSwitch)item;
                    break;
                }
            }
            return(RefreshToggle != null);
        }
예제 #5
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);
        }
예제 #6
0
            public BoolProperty(string name, ITerminalProperty <bool> prop, PropertyBlock block)
            {
                this.prop   = prop;
                this.pBlock = block;
                this.name   = name;

                if (prop is IMyTerminalControlOnOffSwitch)
                {
                    IMyTerminalControlOnOffSwitch onOffSwitch = (IMyTerminalControlOnOffSwitch)prop;

                    OnText  = onOffSwitch.OnText;
                    OffText = onOffSwitch.OffText;
                }
                else
                {
                    OnText  = MySpaceTexts.SwitchText_On;
                    OffText = MySpaceTexts.SwitchText_Off;
                }
            }
        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}"); }
        }
예제 #8
0
        private void create_switch <_block_>(string id, string title, string tooltip, string enabled_text, string disabled_text, string toolbar_enabled_text, string toolbar_disabled_text,
                                             Func <IMyTerminalBlock, bool> getter, Action <IMyTerminalBlock, bool> setter, Func <IMyTerminalBlock, bool> state) where _block_ : IMyTerminalBlock
        {
            IMyTerminalControlOnOffSwitch panel_switch = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlOnOffSwitch, _block_>(id);

            panel_switch.Getter = getter;
            panel_switch.Setter = setter;
            if (state != null)
            {
                panel_switch.Enabled = state;
            }
            panel_switch.Title = MyStringId.GetOrCompute(title);
            if (tooltip != null)
            {
                panel_switch.Tooltip = MyStringId.GetOrCompute(tooltip);
            }
            panel_switch.OnText  = MyStringId.GetOrCompute(enabled_text);
            panel_switch.OffText = MyStringId.GetOrCompute(disabled_text);
            panel_switch.SupportsMultipleBlocks = true;
            MyAPIGateway.TerminalControls.AddControl <_block_>(panel_switch);

            create_toggle <_block_>(id + "OnOff", title + " " + enabled_text + "/" + disabled_text, toolbar_enabled_text, toolbar_disabled_text,
                                    delegate(IMyTerminalBlock block)
            {
                setter(block, !getter(block));
            },
                                    getter, state, "MissileToggle");
            create_toggle <_block_>(id + "OnOff_On", title + " " + enabled_text, toolbar_enabled_text, toolbar_disabled_text,
                                    delegate(IMyTerminalBlock block)
            {
                setter(block, true);
            },
                                    getter, state, "MissileSwitchOn");
            create_toggle <_block_>(id + "OnOff_Off", title + " " + disabled_text, toolbar_enabled_text, toolbar_disabled_text,
                                    delegate(IMyTerminalBlock block)
            {
                setter(block, false);
            },
                                    getter, state, "MissileSwitchOff");
        }
예제 #9
0
        static void createUI()
        {
            if (m_controlsInit)
            {
                return;
            }

            m_controlsInit = true;

            MyAPIGateway.TerminalControls.CustomControlGetter -= customControlGetter;

            MyAPIGateway.TerminalControls.CustomControlGetter += customControlGetter;

            // sender/receiver switch
            m_controlSender         = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlOnOffSwitch, IMyRefinery>("Cython.RPT.SenderReceiver");
            m_controlSender.Enabled = (b) => true;
            m_controlSender.Visible = (b) => b.BlockDefinition.SubtypeId.Equals("LargeBlockSmallRadialPowerTransmitter") || b.BlockDefinition.SubtypeId.Equals("SmallBlockSmallRadialPowerTransmitter");
            m_controlSender.Title   = MyStringId.GetOrCompute("Mode");
            m_controlSender.Tooltip = MyStringId.GetOrCompute("Switches this transmitters mode to Sender or Receiver");
            m_controlSender.OnText  = MyStringId.GetOrCompute("Send");
            m_controlSender.OffText = MyStringId.GetOrCompute("Rec.");
            m_controlSender.Getter  = (b) => b.GameLogic.GetAs <RadialPowerTransmitter>().m_sender;
            m_controlSender.Setter  = (b, v) => {
                b.GameLogic.GetAs <RadialPowerTransmitter>().m_sender      = v;
                b.GameLogic.GetAs <RadialPowerTransmitter>().m_info.sender = v;

                m_controlSender.UpdateVisual();
                m_controlPower.UpdateVisual();

                byte[] message   = new byte[13];
                byte[] messageId = BitConverter.GetBytes(0);
                byte[] entityId  = BitConverter.GetBytes(b.EntityId);

                for (int i = 0; i < 4; i++)
                {
                    message[i] = messageId[i];
                }

                for (int i = 0; i < 8; i++)
                {
                    message[i + 4] = entityId[i];
                }

                message[12] = BitConverter.GetBytes(v)[0];


                MyAPIGateway.Multiplayer.SendMessageToOthers(5910, message, true);
            };
            MyAPIGateway.TerminalControls.AddControl <IMyRefinery>(m_controlSender);

            // channel field
            m_controlChannel         = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlTextbox, IMyRefinery>("Cython.RPT.Channel");
            m_controlChannel.Enabled = (b) => true;
            m_controlChannel.Visible = (b) => b.BlockDefinition.SubtypeId.Equals("LargeBlockSmallRadialPowerTransmitter") || b.BlockDefinition.SubtypeId.Equals("SmallBlockSmallRadialPowerTransmitter");
            m_controlChannel.Title   = MyStringId.GetOrCompute("Channel");
            m_controlChannel.Tooltip = MyStringId.GetOrCompute("Channel this transmitter is supposed to send or receive on.");
            m_controlChannel.Getter  = (b) => (new StringBuilder()).Append(b.GameLogic.GetAs <RadialPowerTransmitter>().m_channel);
            m_controlChannel.Setter  = (b, s) => {
                uint channel;

                if (uint.TryParse(s.ToString(), out channel))
                {
                    var RPT = b.GameLogic.GetAs <RadialPowerTransmitter>();

                    RPT.m_channel      = channel;
                    RPT.m_info.channel = channel;

                    byte[] message   = new byte[16];
                    byte[] messageId = BitConverter.GetBytes(1);
                    byte[] entityId  = BitConverter.GetBytes(b.EntityId);
                    byte[] value     = BitConverter.GetBytes(channel);

                    for (int i = 0; i < 4; i++)
                    {
                        message[i] = messageId[i];
                    }

                    for (int i = 0; i < 8; i++)
                    {
                        message[i + 4] = entityId[i];
                    }

                    for (int i = 0; i < 4; i++)
                    {
                        message[i + 12] = value[i];
                    }

                    MyAPIGateway.Multiplayer.SendMessageToOthers(5910, message, true);
                }
            };

            MyAPIGateway.TerminalControls.AddControl <IMyRefinery>(m_controlChannel);

            // power field
            m_controlPower         = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlTextbox, IMyRefinery>("Cython.RPT.Power");
            m_controlPower.Enabled = (b) => b.GameLogic.GetAs <RadialPowerTransmitter>().m_sender;
            m_controlPower.Visible = (b) => b.BlockDefinition.SubtypeId.Equals("LargeBlockSmallRadialPowerTransmitter") || b.BlockDefinition.SubtypeId.Equals("SmallBlockSmallRadialPowerTransmitter");
            m_controlPower.Title   = MyStringId.GetOrCompute("Power");
            m_controlPower.Tooltip = MyStringId.GetOrCompute("Maximum power this transmitter is supposed to send.");
            m_controlPower.Getter  = (b) => (new StringBuilder()).Append(b.GameLogic.GetAs <RadialPowerTransmitter>().m_transmittedPower);
            m_controlPower.Setter  = (b, s) => {
                float power;

                if (float.TryParse(s.ToString(), out power))
                {
                    var RPT = b.GameLogic.GetAs <RadialPowerTransmitter>();

                    RPT.m_transmittedPower = power;

                    if (RPT.m_transmittedPower > RPT.m_currentMaxPower)
                    {
                        RPT.m_transmittedPower = RPT.m_currentMaxPower;
                    }

                    byte[] message   = new byte[16];
                    byte[] messageId = BitConverter.GetBytes(2);
                    byte[] entityId  = BitConverter.GetBytes(b.EntityId);
                    byte[] value     = BitConverter.GetBytes(RPT.m_transmittedPower);

                    for (int i = 0; i < 4; i++)
                    {
                        message[i] = messageId[i];
                    }

                    for (int i = 0; i < 8; i++)
                    {
                        message[i + 4] = entityId[i];
                    }

                    for (int i = 0; i < 4; i++)
                    {
                        message[i + 12] = value[i];
                    }

                    MyAPIGateway.Multiplayer.SendMessageToOthers(5910, message, true);
                }
            };

            MyAPIGateway.TerminalControls.AddControl <IMyRefinery>(m_controlPower);
        }
예제 #10
0
 public static IMyTerminalAction CreateOnAction <TBlock>(this IMyTerminalControlOnOffSwitch @switch) where TBlock : IMyTerminalBlock
 {
     return(@switch.CreateOnAction <TBlock>(TerminalActionIcons.ON));
 }
예제 #11
0
 public static IMyTerminalControlProperty <bool> CreateProperty <TBlock>(this IMyTerminalControlOnOffSwitch @switch) where TBlock : IMyTerminalBlock
 {
     return(@switch.CreateProperty <TBlock, bool>());
 }
예제 #12
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>();
        }
        static void createUI()
        {
            if (m_controlsInit)
            {
                return;
            }

            m_controlsInit = true;

            MyAPIGateway.TerminalControls.CustomControlGetter -= customControlGetter;

            MyAPIGateway.TerminalControls.CustomControlGetter += customControlGetter;

            // sender/receiver switch
            m_controlSender         = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlOnOffSwitch, IMyRefinery>("Cython.OPT.SenderReceiver");
            m_controlSender.Enabled = (b) => true;
            m_controlSender.Visible = (b) => b.BlockDefinition.SubtypeId.Equals("LargeBlockSmallOpticalPowerTransmitter") || b.BlockDefinition.SubtypeId.Equals("SmallBlockSmallOpticalPowerTransmitter");
            m_controlSender.Title   = MyStringId.GetOrCompute("Mode");
            m_controlSender.Tooltip = MyStringId.GetOrCompute("Switches this transmitters mode to Sender or Receiver");
            m_controlSender.OnText  = MyStringId.GetOrCompute("Send");
            m_controlSender.OffText = MyStringId.GetOrCompute("Rec.");
            m_controlSender.Getter  = (b) => b.GameLogic.GetAs <OpticalPowerTransmitter>().m_sender;
            m_controlSender.Setter  = (b, v) => {
                b.GameLogic.GetAs <OpticalPowerTransmitter>().m_sender      = v;
                b.GameLogic.GetAs <OpticalPowerTransmitter>().m_info.sender = v;

                m_controlSender.UpdateVisual();
                m_controlPower.UpdateVisual();

                byte[] message   = new byte[13];
                byte[] messageId = BitConverter.GetBytes(3);
                byte[] entityId  = BitConverter.GetBytes(b.EntityId);

                for (int i = 0; i < 4; i++)
                {
                    message[i] = messageId[i];
                }

                for (int i = 0; i < 8; i++)
                {
                    message[i + 4] = entityId[i];
                }

                message[12] = BitConverter.GetBytes(v)[0];


                MyAPIGateway.Multiplayer.SendMessageToOthers(5910, message, true);
            };
            MyAPIGateway.TerminalControls.AddControl <IMyRefinery>(m_controlSender);

            // channel field
            m_controlId         = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlTextbox, IMyRefinery>("Cython.OPT.ID");
            m_controlId.Enabled = (b) => true;
            m_controlId.Visible = (b) => b.BlockDefinition.SubtypeId.Equals("LargeBlockSmallOpticalPowerTransmitter") || b.BlockDefinition.SubtypeId.Equals("SmallBlockSmallOpticalPowerTransmitter");
            m_controlId.Title   = MyStringId.GetOrCompute("ID");
            m_controlId.Tooltip = MyStringId.GetOrCompute("ID this transmitter is being identified as when being receiver or it is supposed to send to.");
            m_controlId.Getter  = (b) => {
                if (b.GameLogic.GetAs <OpticalPowerTransmitter>().m_sender)
                {
                    return((new StringBuilder()).Append(b.GameLogic.GetAs <OpticalPowerTransmitter>().m_targetId));
                }
                else
                {
                    return((new StringBuilder()).Append(b.GameLogic.GetAs <OpticalPowerTransmitter>().m_id));
                }
            };

            m_controlId.Setter = (b, s) => {
                uint id;

                if (uint.TryParse(s.ToString(), out id))
                {
                    var OPT = b.GameLogic.GetAs <OpticalPowerTransmitter>();
                    if (OPT.m_sender)
                    {
                        OPT.m_targetId = id;
                    }
                    else
                    {
                        OPT.m_id      = id;
                        OPT.m_info.id = id;
                    }

                    byte[] message   = new byte[16];
                    byte[] messageId = BitConverter.GetBytes(4);
                    byte[] entityId  = BitConverter.GetBytes(b.EntityId);
                    byte[] value     = BitConverter.GetBytes(id);

                    for (int i = 0; i < 4; i++)
                    {
                        message[i] = messageId[i];
                    }

                    for (int i = 0; i < 8; i++)
                    {
                        message[i + 4] = entityId[i];
                    }

                    for (int i = 0; i < 4; i++)
                    {
                        message[i + 12] = value[i];
                    }

                    MyAPIGateway.Multiplayer.SendMessageToOthers(5910, message, true);
                }
            };

            MyAPIGateway.TerminalControls.AddControl <Sandbox.ModAPI.Ingame.IMyRefinery>(m_controlId);


            // power field
            m_controlPower         = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlTextbox, Sandbox.ModAPI.Ingame.IMyRefinery>("Cython.OPT.Power");
            m_controlPower.Enabled = (b) => b.GameLogic.GetAs <OpticalPowerTransmitter>().m_sender;
            m_controlPower.Visible = (b) => b.BlockDefinition.SubtypeId.Equals("LargeBlockSmallOpticalPowerTransmitter") || b.BlockDefinition.SubtypeId.Equals("SmallBlockSmallOpticalPowerTransmitter");
            m_controlPower.Title   = MyStringId.GetOrCompute("Power");
            m_controlPower.Tooltip = MyStringId.GetOrCompute("Maximum power this transmitter is supposed to send.");
            m_controlPower.Getter  = (b) => (new StringBuilder()).Append(b.GameLogic.GetAs <OpticalPowerTransmitter>().m_transmittedPower);
            m_controlPower.Setter  = (b, s) => {
                float power;

                if (float.TryParse(s.ToString(), out power))
                {
                    var OPT = b.GameLogic.GetAs <OpticalPowerTransmitter>();

                    OPT.m_transmittedPower = power;

                    if (OPT.m_transmittedPower > OPT.m_currentMaxPower)
                    {
                        OPT.m_transmittedPower = OPT.m_currentMaxPower;
                    }

                    byte[] message   = new byte[16];
                    byte[] messageId = BitConverter.GetBytes(5);
                    byte[] entityId  = BitConverter.GetBytes(b.EntityId);
                    byte[] value     = BitConverter.GetBytes(OPT.m_transmittedPower);

                    for (int i = 0; i < 4; i++)
                    {
                        message[i] = messageId[i];
                    }

                    for (int i = 0; i < 8; i++)
                    {
                        message[i + 4] = entityId[i];
                    }

                    for (int i = 0; i < 4; i++)
                    {
                        message[i + 12] = value[i];
                    }

                    MyAPIGateway.Multiplayer.SendMessageToOthers(5910, message, true);
                }
            };

            MyAPIGateway.TerminalControls.AddControl <IMyRefinery>(m_controlPower);
        }
예제 #14
0
        public override void UpdateOnceBeforeFrame()
        {
            if (_init)
            {
                return;
            }

            _init  = true;
            _block = Entity as IMyCollector;

            if (_block == null)
            {
                return;
            }

            //create terminal controls
            IMyTerminalControlSeparator sep = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSeparator, IMyCollector>(string.Empty);

            sep.Visible = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner");
            MyAPIGateway.TerminalControls.AddControl <IMyCollector>(sep);

            IMyTerminalControlOnOffSwitch guideSwitch = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlOnOffSwitch, IMyCollector>("Shipyard_GuideSwitch");

            guideSwitch.Title   = MyStringId.GetOrCompute("Guide Boxes");
            guideSwitch.Tooltip = MyStringId.GetOrCompute("Toggles the guide boxes drawn around grids in the shipyard.");
            guideSwitch.OnText  = MyStringId.GetOrCompute("On");
            guideSwitch.OffText = MyStringId.GetOrCompute("Off");
            guideSwitch.Visible = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner");
            guideSwitch.Enabled = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner") && GetYard(b) != null;
            guideSwitch.SupportsMultipleBlocks = true;
            guideSwitch.Getter = GetGuideEnabled;
            guideSwitch.Setter = SetGuideEnabled;
            MyAPIGateway.TerminalControls.AddControl <IMyCollector>(guideSwitch);
            Controls.Add(guideSwitch);

            var lockSwitch = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlOnOffSwitch, IMyCollector>("Shipyard_LockSwitch");

            lockSwitch.Title   = MyStringId.GetOrCompute("Advanced Locking");
            lockSwitch.Tooltip = MyStringId.GetOrCompute("Toggles locking grids in the shipyard when grinding or welding while moving.");
            lockSwitch.OnText  = MyStringId.GetOrCompute("On");
            lockSwitch.OffText = MyStringId.GetOrCompute("Off");
            lockSwitch.Visible = b => b.BlockDefinition.SubtypeId.Equals("ShipyardCorner_Small");
            lockSwitch.Enabled = b => b.BlockDefinition.SubtypeId.Equals("ShipyardCorner_Small") && GetYard(b) != null;
            lockSwitch.SupportsMultipleBlocks = true;
            lockSwitch.Getter = GetLockEnabled;
            lockSwitch.Setter = SetLockEnabled;
            MyAPIGateway.TerminalControls.AddControl <IMyCollector>(lockSwitch);
            Controls.Add(lockSwitch);

            IMyTerminalControlButton grindButton = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyCollector>("Shipyard_GrindButton");
            IMyTerminalControlButton weldButton  = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyCollector>("Shipyard_WeldButton");
            IMyTerminalControlButton stopButton  = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyCollector>("Shipyard_StopButton");

            grindButton.Title   = MyStringId.GetOrCompute("Grind");
            grindButton.Tooltip = MyStringId.GetOrCompute("Begins grinding ships in the yard.");
            grindButton.Enabled = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner") && GetYard(b)?.YardType == ShipyardType.Disabled;
            grindButton.Visible = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner");
            grindButton.SupportsMultipleBlocks = true;
            grindButton.Action = b => Communication.SendYardCommand(b.CubeGrid.EntityId, ShipyardType.Grind);
            MyAPIGateway.TerminalControls.AddControl <IMyCollector>(grindButton);
            Controls.Add(grindButton);

            weldButton.Title   = MyStringId.GetOrCompute("Weld");
            weldButton.Tooltip = MyStringId.GetOrCompute("Begins welding ships in the yard.");
            weldButton.Enabled = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner") && GetYard(b)?.YardType == ShipyardType.Disabled;
            weldButton.Visible = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner");
            weldButton.SupportsMultipleBlocks = true;
            weldButton.Action = b => Communication.SendYardCommand(b.CubeGrid.EntityId, ShipyardType.Weld);
            MyAPIGateway.TerminalControls.AddControl <IMyCollector>(weldButton);
            Controls.Add(weldButton);

            stopButton.Title   = MyStringId.GetOrCompute("Stop");
            stopButton.Tooltip = MyStringId.GetOrCompute("Stops the shipyard.");
            stopButton.Enabled = b =>
            {
                if (!b.BlockDefinition.SubtypeId.Contains("ShipyardCorner"))
                {
                    return(false);
                }

                ShipyardItem yard = GetYard(b);

                return(yard?.YardType == ShipyardType.Weld || yard?.YardType == ShipyardType.Grind);
            };
            stopButton.Visible = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner");
            stopButton.SupportsMultipleBlocks = true;
            stopButton.Action = b => Communication.SendYardCommand(b.CubeGrid.EntityId, ShipyardType.Disabled);
            MyAPIGateway.TerminalControls.AddControl <IMyCollector>(stopButton);
            Controls.Add(stopButton);

            IMyTerminalControlCombobox buildPattern = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlCombobox, IMyCollector>("Shipyard_BuildPattern");

            buildPattern.Title           = MyStringId.GetOrCompute("Build Pattern");
            buildPattern.Tooltip         = MyStringId.GetOrCompute("Pattern used to build projections.");
            buildPattern.ComboBoxContent = FillPatternCombo;
            buildPattern.Visible         = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner");
            buildPattern.Enabled         = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner") && GetYard(b)?.YardType == ShipyardType.Disabled;
            buildPattern.Getter          = GetBuildPattern;
            buildPattern.Setter          = SetBuildPattern;
            MyAPIGateway.TerminalControls.AddControl <IMyCollector>(buildPattern);
            Controls.Add(buildPattern);

            IMyTerminalControlSlider beamCountSlider = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyCollector>("Shipyard_BeamCount");

            beamCountSlider.Title = MyStringId.GetOrCompute("Beam Count");

            beamCountSlider.Tooltip = MyStringId.GetOrCompute("Number of beams this shipyard can use per corner.");
            beamCountSlider.SetLimits(1, 3);
            beamCountSlider.Writer  = (b, result) => result.Append(GetBeamCount(b));
            beamCountSlider.Visible = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner");
            beamCountSlider.Enabled = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner") && GetYard(b) != null;
            beamCountSlider.Getter  = b => GetBeamCount(b);
            beamCountSlider.Setter  = (b, v) =>
            {
                SetBeamCount(b, (int)Math.Round(v, 0, MidpointRounding.ToEven));
                beamCountSlider.UpdateVisual();
            };
            beamCountSlider.SupportsMultipleBlocks = true;
            MyAPIGateway.TerminalControls.AddControl <IMyCollector>(beamCountSlider);
            Controls.Add(beamCountSlider);

            IMyTerminalControlSlider grindSpeedSlider = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyCollector>("Shipyard_GrindSpeed");

            grindSpeedSlider.Title = MyStringId.GetOrCompute("Grind Speed");

            grindSpeedSlider.Tooltip = MyStringId.GetOrCompute("How fast this shipyard grinds grids.");
            grindSpeedSlider.SetLimits(0.01f, 2);
            grindSpeedSlider.Writer  = (b, result) => result.Append(GetGrindSpeed(b));
            grindSpeedSlider.Visible = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner");
            grindSpeedSlider.Enabled = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner") && GetYard(b) != null;
            grindSpeedSlider.Getter  = GetGrindSpeed;
            grindSpeedSlider.Setter  = (b, v) =>
            {
                SetGrindSpeed(b, (float)Math.Round(v, 2, MidpointRounding.ToEven));
                grindSpeedSlider.UpdateVisual();
            };
            grindSpeedSlider.SupportsMultipleBlocks = true;
            MyAPIGateway.TerminalControls.AddControl <IMyCollector>(grindSpeedSlider);
            Controls.Add(grindSpeedSlider);

            IMyTerminalControlSlider weldSpeedSlider = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyCollector>("Shipyard_WeldSpeed");

            weldSpeedSlider.Title = MyStringId.GetOrCompute("Weld Speed");

            weldSpeedSlider.Tooltip = MyStringId.GetOrCompute("How fast this shipyard welds grids.");
            weldSpeedSlider.SetLimits(0.01f, 2);
            weldSpeedSlider.Writer  = (b, result) => result.Append(GetWeldSpeed(b));
            weldSpeedSlider.Visible = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner");
            weldSpeedSlider.Enabled = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner") && GetYard(b) != null;
            weldSpeedSlider.Getter  = GetWeldSpeed;
            weldSpeedSlider.Setter  = (b, v) =>
            {
                SetWeldSpeed(b, (float)Math.Round(v, 2, MidpointRounding.ToEven));
                weldSpeedSlider.UpdateVisual();
            };
            weldSpeedSlider.SupportsMultipleBlocks = true;
            MyAPIGateway.TerminalControls.AddControl <IMyCollector>(weldSpeedSlider);
            Controls.Add(weldSpeedSlider);

            IMyTerminalAction grindAction = MyAPIGateway.TerminalControls.CreateAction <IMyCollector>("Shipyard_GrindAction");

            grindAction.Enabled = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner");
            grindAction.Name    = new StringBuilder("Grind");
            grindAction.Icon    = @"Textures\GUI\Icons\Actions\Start.dds";
            grindAction.Action  = b => Communication.SendYardCommand(b.CubeGrid.EntityId, ShipyardType.Grind);
            MyAPIGateway.TerminalControls.AddAction <IMyCollector>(grindAction);

            IMyTerminalAction weldAction = MyAPIGateway.TerminalControls.CreateAction <IMyCollector>("Shipyard_WeldAction");

            weldAction.Enabled = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner");
            weldAction.Name    = new StringBuilder("Weld");
            weldAction.Icon    = @"Textures\GUI\Icons\Actions\Start.dds";
            weldAction.Action  = b => Communication.SendYardCommand(b.CubeGrid.EntityId, ShipyardType.Weld);
            MyAPIGateway.TerminalControls.AddAction <IMyCollector>(weldAction);

            IMyTerminalAction stopAction = MyAPIGateway.TerminalControls.CreateAction <IMyCollector>("Shipyard_StopAction");

            stopAction.Enabled = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner");
            stopAction.Name    = new StringBuilder("Stop");
            stopAction.Icon    = @"Textures\GUI\Icons\Actions\Reset.dds";
            stopAction.Action  = b => Communication.SendYardCommand(b.CubeGrid.EntityId, ShipyardType.Disabled);
            MyAPIGateway.TerminalControls.AddAction <IMyCollector>(stopAction);
        }
예제 #15
0
        public static void InitLate()
        {
            initialized = true;

            powerSwitch         = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlOnOffSwitch, IMyTerminalBlock>("HoverRail_OnOff");
            powerSwitch.Title   = MyStringId.GetOrCompute("Maglev Engine");
            powerSwitch.Tooltip = MyStringId.GetOrCompute("Enable to apply force to stick to the track.");
            powerSwitch.Getter  = b => (bool)SettingsStore.Get(b, "power_on", true);
            powerSwitch.Setter  = (b, v) => SettingsStore.Set(b, "power_on", v);
            powerSwitch.SupportsMultipleBlocks = true;
            powerSwitch.OnText  = MyStringId.GetOrCompute("On");
            powerSwitch.OffText = MyStringId.GetOrCompute("Off");
            powerSwitch.Visible = BlockIsEngine;
            MyAPIGateway.TerminalControls.AddControl <IMyTerminalBlock>(powerSwitch);

            forceSlider         = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyTerminalBlock>("HoverRail_ForceLimit");
            forceSlider.Title   = MyStringId.GetOrCompute("Force Limit");
            forceSlider.Tooltip = MyStringId.GetOrCompute("The amount of force applied to align this motor with the track.");
            forceSlider.SetLogLimits(10000.0f, 50000000.0f);
            forceSlider.SupportsMultipleBlocks = true;
            forceSlider.Getter  = b => (float)SettingsStore.Get(b, "force_slider", 100000.0f);
            forceSlider.Setter  = (b, v) => SettingsStore.Set(b, "force_slider", (float)LogRound(v));
            forceSlider.Writer  = (b, result) => result.Append(String.Format("{0}N", SIFormat((float)SettingsStore.Get(b, "force_slider", 100000.0f))));
            forceSlider.Visible = BlockIsEngine;
            MyAPIGateway.TerminalControls.AddControl <IMyTerminalBlock>(forceSlider);

            heightSlider         = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyTerminalBlock>("HoverRail_HeightOffset");
            heightSlider.Title   = MyStringId.GetOrCompute("Height Offset");
            heightSlider.Tooltip = MyStringId.GetOrCompute("The height we float above the track.");
            heightSlider.SetLimits(0.1f, 2.5f);
            heightSlider.SupportsMultipleBlocks = true;
            heightSlider.Getter  = b => (float)SettingsStore.Get(b, "height_offset", 1.25f);
            heightSlider.Setter  = (b, v) => SettingsStore.Set(b, "height_offset", (float)Math.Round(v, 1));
            heightSlider.Writer  = (b, result) => result.Append(String.Format("{0}m", (float)SettingsStore.Get(b, "height_offset", 1.25f)));
            heightSlider.Visible = BlockIsEngine;
            MyAPIGateway.TerminalControls.AddControl <IMyTerminalBlock>(heightSlider);

            lowerHeightAction        = MyAPIGateway.TerminalControls.CreateAction <IMyTerminalBlock>("HoverRailEngine_LowerHeight0.1");
            lowerHeightAction.Name   = new StringBuilder("Lower Height");
            lowerHeightAction.Action = LowerHeightAction;
            lowerHeightAction.Writer = (block, builder) => {
                builder.Clear();
                builder.Append(String.Format("{0} -", (float)SettingsStore.Get(block, "height_offset", 1.25f)));
            };
            MyAPIGateway.TerminalControls.AddAction <IMyTerminalBlock>(lowerHeightAction);

            raiseHeightAction        = MyAPIGateway.TerminalControls.CreateAction <IMyTerminalBlock>("HoverRailEngine_RaiseHeight0.1");
            raiseHeightAction.Name   = new StringBuilder("Raise Height");
            raiseHeightAction.Action = RaiseHeightAction;
            raiseHeightAction.Writer = (block, builder) => {
                builder.Clear();
                builder.Append(String.Format("{0} +", (float)SettingsStore.Get(block, "height_offset", 1.25f)));
            };
            MyAPIGateway.TerminalControls.AddAction <IMyTerminalBlock>(raiseHeightAction);

            turnOnAction        = MyAPIGateway.TerminalControls.CreateAction <IMyTerminalBlock>("HoverRailEngine_On");
            turnOnAction.Name   = new StringBuilder("Power On");
            turnOnAction.Action = TurnOnAction;
            turnOnAction.Writer = OnOffWriter;
            MyAPIGateway.TerminalControls.AddAction <IMyTerminalBlock>(turnOnAction);

            turnOffAction        = MyAPIGateway.TerminalControls.CreateAction <IMyTerminalBlock>("HoverRailEngine_Off");
            turnOffAction.Name   = new StringBuilder("Power Off");
            turnOffAction.Action = TurnOffAction;
            turnOffAction.Writer = OnOffWriter;
            MyAPIGateway.TerminalControls.AddAction <IMyTerminalBlock>(turnOffAction);

            turnOnOffAction        = MyAPIGateway.TerminalControls.CreateAction <IMyTerminalBlock>("HoverRailEngine_OnOff");
            turnOnOffAction.Name   = new StringBuilder("Power On/Off");
            turnOnOffAction.Action = TurnOnOffAction;
            turnOnOffAction.Writer = OnOffWriter;
            MyAPIGateway.TerminalControls.AddAction <IMyTerminalBlock>(turnOnOffAction);

            MyAPIGateway.TerminalControls.CustomActionGetter += GetEngineActions;
        }
예제 #16
0
        public static void InitLate()
        {
            initialized = true;

            turnLeftSwitch         = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlOnOffSwitch, IMyTerminalBlock>("LeftJunction_TurnOnOff");
            turnLeftSwitch.Title   = MyStringId.GetOrCompute("Junction Direction");
            turnLeftSwitch.Tooltip = MyStringId.GetOrCompute("Which way should a train go?");
            turnLeftSwitch.Getter  = b => (bool)SettingsStore.Get(b, "junction_turn", false);
            turnLeftSwitch.Setter  = (b, v) => SettingsStore.Set(b, "junction_turn", v);
            turnLeftSwitch.OnText  = MyStringId.GetOrCompute("Left");
            turnLeftSwitch.OffText = MyStringId.GetOrCompute("Fwd");
            turnLeftSwitch.Visible = BlockIsLeftJunction;
            MyAPIGateway.TerminalControls.AddControl <IMyTerminalBlock>(turnLeftSwitch);

            turnRightSwitch         = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlOnOffSwitch, IMyTerminalBlock>("RightJunction_TurnOnOff");
            turnRightSwitch.Title   = MyStringId.GetOrCompute("Junction Direction");
            turnRightSwitch.Tooltip = MyStringId.GetOrCompute("Which way should a train go?");
            // meaning flipped relative to switch, so that we can
            // swap the labels and have [Fwd] [Right], which is more pleasing
            turnRightSwitch.Getter  = b => !(bool)SettingsStore.Get(b, "junction_turn", false);
            turnRightSwitch.Setter  = (b, v) => SettingsStore.Set(b, "junction_turn", !v);
            turnRightSwitch.OnText  = MyStringId.GetOrCompute("Fwd");
            turnRightSwitch.OffText = MyStringId.GetOrCompute("Right");
            turnRightSwitch.Visible = BlockIsRightJunction;
            MyAPIGateway.TerminalControls.AddControl <IMyTerminalBlock>(turnRightSwitch);

            leftSwitchAction        = MyAPIGateway.TerminalControls.CreateAction <IMyTerminalBlock>("HoverRailLeftJunction_Switch");
            leftSwitchAction.Name   = new StringBuilder("Switch Direction");
            leftSwitchAction.Writer = LeftJunctionText;
            leftSwitchAction.Action = JunctionSwitchAction;
            // TODO figure out why doesn't work
            leftSwitchAction.Icon = @"Textures\Icons\HoverRail\HoverRail_Junction_Left_10x-12x_OnOff.dds";
            MyAPIGateway.TerminalControls.AddAction <IMyTerminalBlock>(leftSwitchAction);

            leftSwitchLeftAction        = MyAPIGateway.TerminalControls.CreateAction <IMyTerminalBlock>("HoverRailLeftJunction_Left");
            leftSwitchLeftAction.Name   = new StringBuilder("Go Left");
            leftSwitchLeftAction.Writer = LeftJunctionText;
            leftSwitchLeftAction.Action = JunctionSwitchSideAction;
            leftSwitchLeftAction.Icon   = @"Textures\Icons\HoverRail\HoverRail_Junction_Left_10x-12x_On.dds";
            MyAPIGateway.TerminalControls.AddAction <IMyTerminalBlock>(leftSwitchLeftAction);

            leftSwitchStraightAction        = MyAPIGateway.TerminalControls.CreateAction <IMyTerminalBlock>("HoverRailLeftJunction_Straight");
            leftSwitchStraightAction.Name   = new StringBuilder("Go Fwd");
            leftSwitchStraightAction.Writer = LeftJunctionText;
            leftSwitchStraightAction.Action = JunctionSwitchStraightAction;
            leftSwitchStraightAction.Icon   = @"Textures\Icons\HoverRail\HoverRail_Junction_Left_10x-12x_Off.dds";
            MyAPIGateway.TerminalControls.AddAction <IMyTerminalBlock>(leftSwitchStraightAction);

            rightSwitchAction        = MyAPIGateway.TerminalControls.CreateAction <IMyTerminalBlock>("HoverRailRightJunction_Switch");
            rightSwitchAction.Name   = new StringBuilder("Switch Direction");
            rightSwitchAction.Writer = RightJunctionText;
            rightSwitchAction.Action = JunctionSwitchAction;
            // rightSwitchAction.Icon = @"Textures\Icons\HoverRail\HoverRail_Junction_Right_10x-12x_OnOff.dds";
            MyAPIGateway.TerminalControls.AddAction <IMyTerminalBlock>(rightSwitchAction);

            rightSwitchStraightAction        = MyAPIGateway.TerminalControls.CreateAction <IMyTerminalBlock>("HoverRailRightJunction_Straight");
            rightSwitchStraightAction.Name   = new StringBuilder("Go Fwd");
            rightSwitchStraightAction.Writer = RightJunctionText;
            rightSwitchStraightAction.Action = JunctionSwitchStraightAction;
            // rightSwitchStraightAction.Icon = @"Textures\Icons\HoverRail\HoverRail_Junction_Right_10x-12x_Off.dds";
            MyAPIGateway.TerminalControls.AddAction <IMyTerminalBlock>(rightSwitchStraightAction);

            rightSwitchRightAction        = MyAPIGateway.TerminalControls.CreateAction <IMyTerminalBlock>("HoverRailRightJunction_Right");
            rightSwitchRightAction.Name   = new StringBuilder("Go Right");
            rightSwitchRightAction.Writer = RightJunctionText;
            rightSwitchRightAction.Action = JunctionSwitchSideAction;
            // rightSwitchRightAction.Icon = @"Textures\Icons\HoverRail\HoverRail_Junction_Right_10x-12x_On.dds";
            MyAPIGateway.TerminalControls.AddAction <IMyTerminalBlock>(rightSwitchRightAction);

            MyAPIGateway.TerminalControls.CustomActionGetter += GetSwitchActions;
        }