示例#1
0
        internal static void CreateSliderActionSet(Session session, IMyTerminalControlSlider tc, string name, int id, int min, int max, float incAmt, Func <IMyTerminalBlock, bool> enabler, bool group)
        {
            var action0 = MyAPIGateway.TerminalControls.CreateAction <T>($"WC_{id}_Increase");

            action0.Icon           = @"Textures\GUI\Icons\Actions\Increase.dds";
            action0.Name           = new StringBuilder($"Increase {name}");
            action0.Action         = (b) => tc.Setter(b, tc.Getter(b) + incAmt <= max ? tc.Getter(b) + incAmt : max);
            action0.Writer         = TerminalHelpers.EmptyStringBuilder;
            action0.Enabled        = enabler;
            action0.ValidForGroups = group;

            MyAPIGateway.TerminalControls.AddAction <T>(action0);
            session.CustomActions.Add(action0);

            var action1 = MyAPIGateway.TerminalControls.CreateAction <T>($"WC_{id}_Decrease");

            action1.Icon           = @"Textures\GUI\Icons\Actions\Decrease.dds";
            action1.Name           = new StringBuilder($"Decrease {name}");
            action1.Action         = (b) => tc.Setter(b, tc.Getter(b) - incAmt >= min ? tc.Getter(b) - incAmt : min);
            action1.Writer         = TerminalHelpers.EmptyStringBuilder;
            action1.Enabled        = enabler;
            action1.ValidForGroups = group;

            MyAPIGateway.TerminalControls.AddAction <T>(action1);
            session.CustomActions.Add(action1);
        }
        private void CreateActionDamageModRate <T>(IMyTerminalControlSlider c,
                                                   float defaultValue        = 100f, // HACK terminal controls don't have a default value built in...
                                                   float modifier            = 10f,
                                                   string iconReset          = null,
                                                   string iconIncrease       = null,
                                                   string iconDecrease       = null,
                                                   bool gridSizeDefaultValue = false) // hacky quick way to get a dynamic default value depending on grid size)
        {
            try
            {
                var id   = ((IMyTerminalControl)c).Id;
                var name = c.Title.String;

                if (iconReset == null && iconIncrease == null && iconDecrease == null)
                {
                    var gamePath = MyAPIGateway.Utilities.GamePaths.ContentPath;
                    iconReset    = gamePath + @"\Textures\GUI\Icons\Actions\Reset.dds";
                    iconIncrease = gamePath + @"\Textures\GUI\Icons\Actions\Increase.dds";
                    iconDecrease = gamePath + @"\Textures\GUI\Icons\Actions\Decrease.dds";
                }

                {
                    var a = MyAPIGateway.TerminalControls.CreateAction <T>(id + "_Reset");
                    a.Name = new StringBuilder($"{Localization.GetText("ActionDefault")} ").Append(name);
                    if (!gridSizeDefaultValue)
                    {
                        a.Name.Append(" (").Append(defaultValue.ToString("0.###")).Append(")");
                    }
                    a.Icon           = iconReset;
                    a.ValidForGroups = true;
                    a.Action         = (b) => c.Setter(b, gridSizeDefaultValue ? b.CubeGrid.GridSize : defaultValue);
                    a.Writer         = (b, s) => s.Append(c.Getter(b));

                    MyAPIGateway.TerminalControls.AddAction <T>(a);
                }
                {
                    var a = MyAPIGateway.TerminalControls.CreateAction <T>(id + "_Increase");
                    a.Name           = new StringBuilder($"{Localization.GetText("ActionIncrease")} ").Append(name).Append(" (+").Append(modifier.ToString("0.###")).Append(")");
                    a.Icon           = iconIncrease;
                    a.ValidForGroups = true;
                    a.Action         = ActionAddDamageMod;
                    a.Writer         = (b, s) => s.Append(c.Getter(b));

                    MyAPIGateway.TerminalControls.AddAction <T>(a);
                }
                {
                    var a = MyAPIGateway.TerminalControls.CreateAction <T>(id + "_Decrease");
                    a.Name           = new StringBuilder($"{Localization.GetText("ActionDecrease")} ").Append(name).Append(" (-").Append(modifier.ToString("0.###")).Append(")");
                    a.Icon           = iconDecrease;
                    a.ValidForGroups = true;
                    a.Action         = ActionSubtractDamageMod;
                    a.Writer         = (b, s) => s.Append(c.Getter(b).ToString("0.###"));

                    MyAPIGateway.TerminalControls.AddAction <T>(a);
                }
            }
            catch (Exception ex) { Log.Line($"Exception in CreateActionDamageModRate: {ex}"); }
        }
示例#3
0
        public static IMyTerminalAction CreateIncreaseAction <TBlock>(this IMyTerminalControlSlider slider, float step, Func <IMyTerminalBlock, float> min, Func <IMyTerminalBlock, float> max, string iconPath) where TBlock : IMyTerminalBlock
        {
            var action = MyAPIGateway.TerminalControls.CreateAction <TBlock>("Increase" + ((IMyTerminalControl)slider).Id);

            action.Name    = Combine(MySpaceTexts.ToolbarAction_Increase, slider.Title);
            action.Action  = block => slider.Setter(block, MathHelper.Clamp(slider.Getter(block) + max(block) * step, min(block), max(block)));
            action.Writer  = slider.Writer;
            action.Icon    = iconPath;
            action.Enabled = slider.Enabled;

            return(action);
        }
        internal static void CreateSliderActionSet <T>(IMyTerminalControlSlider tc, string name, int id, int min, int max, float incAmt, Func <IMyTerminalBlock, int, bool> enabler) where T : IMyTerminalBlock
        {
            var action0 = MyAPIGateway.TerminalControls.CreateAction <T>($"WC_{id}_Increase");

            action0.Icon           = @"Textures\GUI\Icons\Actions\Increase.dds";
            action0.Name           = new StringBuilder($"Increase {name}");
            action0.Action         = (b) => tc.Setter(b, tc.Getter(b) + incAmt <= max ? tc.Getter(b) + incAmt : max);
            action0.Writer         = (b, t) => t.Append("");
            action0.Enabled        = (b) => enabler(b, id);
            action0.ValidForGroups = false;

            MyAPIGateway.TerminalControls.AddAction <T>(action0);

            var action1 = MyAPIGateway.TerminalControls.CreateAction <T>($"WC_{id}_Decrease");

            action1.Icon           = @"Textures\GUI\Icons\Actions\Decrease.dds";
            action1.Name           = new StringBuilder($"Decrease {name}");
            action1.Action         = (b) => tc.Setter(b, tc.Getter(b) - incAmt >= min ? tc.Getter(b) - incAmt : min);
            action1.Writer         = (b, t) => t.Append("");
            action1.Enabled        = (b) => enabler(b, id);
            action1.ValidForGroups = false;

            MyAPIGateway.TerminalControls.AddAction <T>(action1);
        }
示例#5
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>();
        }