// This code will run on all clients and the server, so we need to isolate it to the server only.
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            _objectBuilder    = objectBuilder;
            this.NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;

            if (!_staticIsInitialized)
            {
                _staticIsInitialized          = true;
                _initialRemoteControlMaxSpeed = (float)ConfigurableSpeedComponentLogic.Instance.EnvironmentComponent.RemoteControlMaxSpeed;
            }

            if (!_isInitilized)
            {
                // Use this space to initialize and hook up events. NOT TO PROCESS ANYTHING.
                _isInitilized = true;

                if (_initialRemoteControlMaxSpeed > 0)
                {
                    _remoteControlEntity = (IMyRemoteControl)Entity;

                    List <IMyTerminalControl> controls;
                    MyAPIGateway.TerminalControls.GetControls <IMyRemoteControl>(out controls);

                    //VRage.Utils.MyLog.Default.WriteLine($"#### SpeedLimit {_remoteControlEntity.SpeedLimit} {_initialRemoteControlMaxSpeed}");

                    IMyTerminalControl       control       = controls.FirstOrDefault(c => c.Id == "SpeedLimit");
                    IMyTerminalControlSlider sliderControl = control as IMyTerminalControlSlider;
                    // control limits are set universally and cannot be applied individually.
                    sliderControl?.SetLimits(0, _initialRemoteControlMaxSpeed);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Synchronize and save a value associated with a terminal control. The value will be synchronized everytime it changes.
        /// </summary>
        /// <param name="control">GUI control for getting/setting the value.</param>
        /// <param name="fieldName">The name of a field in the script to get/set the value from/to. If the field has a default value, the DefaultValueAttribute should be used.</param>
        /// <param name="save">Iff true, save the value to disk.</param>
        public ValueSync(IMyTerminalValueControl <TValue> control, string fieldName, bool save = true)
            : base(control.Id, fieldName, save)
        {
            control.Getter = GetValue;
            control.Setter = SetValue;

            _control = (IMyTerminalControl)control;
        }
예제 #3
0
        /// <summary>
        /// Synchronize and save a value associated with a terminal control. The value will be synchronized everytime it changes.
        /// </summary>
        /// <param name="control">GUI control for getting/setting the value.</param>
        /// <param name="getter">Function to get the value from a script.</param>
        /// <param name="setter">Function to set a value in a script.</param>
        /// <param name="save">Iff true, save the value to disk.</param>
        /// <param name="defaultValue">The default value to use. The value in the script will be set to defaultValue by ValueSync.</param>
        public ValueSync(IMyTerminalValueControl <TValue> control, GetterDelegate getter, SetterDelegate setter, bool save = true, TValue defaultValue = default(TValue))
            : base(control.Id, getter, setter, save, defaultValue)
        {
            control.Getter = GetValue;
            control.Setter = SetValue;

            _control = (IMyTerminalControl)control;
        }
예제 #4
0
        public TypedValueSync(IMyTerminalControlTextbox control, GetterDelegate getter, SetterDelegate setter, bool save = true, TValue defaultValue = default(TValue))
            : base(((IMyTerminalControl)control).Id, getter, setter, save, defaultValue)
        {
            // MyTerminalControlTextbox has different Getter/Setter
            control.Getter = GetStringBuilder;
            control.Setter = SetStringBuilder;

            _control = control;
        }
예제 #5
0
        /// <summary>
        /// Synchronize and save a StringBuilder associated with a MyTerminalControlTextbox. The StringBuilder is synchronized from time to time.
        /// </summary>
        /// <param name="control">GUI control for getting/setting the value.</param>
        /// <param name="getter">Function to get the StringBuilder from a script.</param>
        /// <param name="setter">Function to set a StringBuilder in a script.</param>
        /// <param name="save">Iff true, save the value to disk.</param>
        public StringBuilderSync(IMyTerminalControlTextbox control, GetterDelegate getter, SetterDelegate setter, bool save = true)
            : base(((IMyTerminalControl)control).Id, getter, setter, save)
        {
            // MyTerminalControlTextbox has different Getter/Setter
            control.Getter = GetValue;
            control.Setter = SetValue;

            _control = control;
        }
예제 #6
0
        /// <summary>
        /// Synchronize and save a StringBuilder associated with a MyTerminalControlTextbox. The StringBuilder is synchronized from time to time.
        /// </summary>
        /// <param name="control">GUI control for getting/setting the value.</param>
        /// <param name="fieldName">The name of a field in the script to get/set the value from/to.</param>
        /// <param name="save">Iff true, save the value to disk.</param>
        public StringBuilderSync(IMyTerminalControlTextbox control, string fieldName, bool save = true)
            : base(((IMyTerminalControl)control).Id, fieldName, save)
        {
            // MyTerminalControlTextbox has different Getter/Setter
            control.Getter = GetValue;
            control.Setter = SetValue;

            _control = control;
        }
예제 #7
0
        private static void TerminalControls_CustomControlGetter(IMyTerminalBlock block, List <IMyTerminalControl> controls)
        {
            if (!(block is IMyPistonBase))
            {
                return;
            }

            IMyTerminalControl detach   = null;
            IMyTerminalControl attach   = null;
            IMyTerminalControl smallTop = null;
            int move = 0;

            for (int i = controls.Count - 1; i >= 0; i--)
            {
                IMyTerminalControl c = controls[i];
                if (move >= 2 && c.Id == "Reverse")
                {
                    if (smallTop != null)
                    {
                        controls[i] = smallTop;
                        i++;
                        controls[i] = c;
                    }
                    if (attach != null && detach != null)
                    {
                        controls[i + 1] = detach;
                        controls[i + 2] = attach;
                    }
                    break;
                }

                if (move > 0)
                {
                    controls[i + move] = c;
                }

                if (move < 3)
                {
                    if (c.Id == "Attach")
                    {
                        attach = c;
                        move++;
                    }
                    else if (c.Id == "Detach")
                    {
                        detach = c;
                        move++;
                    }
                    else if (c.Id == "AddSmallTop")
                    {
                        smallTop = c;
                        move++;
                    }
                }
            }
        }
예제 #8
0
        private static IMyTerminalControl ControlIdExists(string id)
        {
            List <IMyTerminalControl> controls = new List <IMyTerminalControl>();

            MyAPIGateway.TerminalControls.GetControls <IMyUpgradeModule>(out controls);

            IMyTerminalControl control = controls.Find(x => x.Id == id);

            return(control);
        }
예제 #9
0
        public static bool isOptionApplicable(IMyTerminalBlock block, IMyTerminalControl control, LogicCore caller)
        {
            var    lgc  = block.GameLogic.GetAs <LogicCore>();
            string type = lgc != null?lgc.GetType().ToString() : null;

            string seek = getBlockTypeFilter(control);

            //if (seek != null)
            // MyAPIGateway.Utilities.ShowNotification(block.CustomName+" check "+control.Id+" > looking for '"+seek+"', have '"+type);
            return(seek == null || type == seek);
        }
예제 #10
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            NeedsUpdate |= VRage.ModAPI.MyEntityUpdateEnum.BEFORE_NEXT_FRAME;

            List <IMyTerminalControl> controls;

            MyAPIGateway.TerminalControls.GetControls <IMyRemoteControl>(out controls);

            IMyTerminalControl control = controls.FirstOrDefault(c => c.Id == "SpeedLimit");

            SliderControl = control as IMyTerminalControlSlider;
            RelativeTopSpeed.SettingsChanged += OnSettingsChanged;
            OnSettingsChanged(Settings.Instance);
        }
예제 #11
0
        private void CustomControlHandler(IMyTerminalBlock block, List <IMyTerminalControl> controls)
        {
            var    cube = (MyCubeBlock)block;
            GridAi gridAi;

            if (GridTargetingAIs.TryGetValue(cube.CubeGrid, out gridAi))
            {
                gridAi.LastTerminal = block;
                WeaponComponent comp;
                if (gridAi.WeaponBase.TryGetValue(cube, out comp) && comp.Platform.State == MyWeaponPlatform.PlatformState.Ready)
                {
                    gridAi.LastWeaponTerminal   = block;
                    gridAi.WeaponTerminalAccess = true;

                    int rangeControl = -1;
                    IMyTerminalControl wcRangeControl = null;
                    for (int i = controls.Count - 1; i >= 0; i--)
                    {
                        if (controls[i].Id.Equals("Range"))
                        {
                            rangeControl = i;
                            controls.RemoveAt(i);
                        }
                        else if (controls[i].Id.Equals("WC_Range"))
                        {
                            wcRangeControl = controls[i];
                            controls.RemoveAt(i);
                        }
                    }

                    if (rangeControl != -1)
                    {
                        controls.RemoveAt(rangeControl);
                    }

                    if (wcRangeControl != null)
                    {
                        if (rangeControl != -1)
                        {
                            controls.Insert(rangeControl, wcRangeControl);
                        }

                        else
                        {
                            controls.Add(wcRangeControl);
                        }
                    }
                }
            }
        }
예제 #12
0
        /// <summary>
        /// Checks whether or not the Enabled and Visible delegates are defined and whether
        /// invoking those delegates will throw an exception.
        /// </summary>
        public static bool CanUseControl(this IMyTerminalControl control, IMyTerminalBlock tBlock)
        {
            try
            {
                if (control.Enabled != null && control.Visible != null)
                {
                    control.Enabled(tBlock);
                    control.Visible(tBlock);

                    return(true);
                }
            }
            catch { }

            return(false);
        }
예제 #13
0
        public void RemoveControl <TBlock>(IMyTerminalControl item)
        {
            if (!IsTypeValid <TBlock>())
            {
                return;
            }

            Type producedType = GetProducedType <TBlock>();

            if (producedType == null)
            {
                return;
            }

            MyTerminalControlFactory.RemoveControl(producedType, item);
        }
예제 #14
0
        public void AddControl <TBlock>(IMyTerminalControl item)
        {
            if (!IsTypeValid <TBlock>())
            {
                return;
            }

            Type producedType = GetProducedType <TBlock>();

            if (producedType == null)
            {
                return;
            }

            MyTerminalControlFactory.AddControl(producedType, (ITerminalControl)item);
            MyTerminalControlFactory.AddActions(producedType, (ITerminalControl)item);
        }
예제 #15
0
        private void CustomControlHandler(IMyTerminalBlock block, List <IMyTerminalControl> controls)
        {
            LastTerminal = block;

            var    cube = (MyCubeBlock)block;
            GridAi gridAi;

            if (GridTargetingAIs.TryGetValue(cube.CubeGrid, out gridAi))
            {
                gridAi.LastTerminal = block;
                CoreComponent comp;
                if (gridAi.WeaponBase.TryGetValue(cube, out comp) && comp.Platform.State == CorePlatform.PlatformState.Ready)
                {
                    TerminalMon.HandleInputUpdate(comp);
                    IMyTerminalControl wcRangeControl = null;
                    for (int i = controls.Count - 1; i >= 0; i--)
                    {
                        var control = controls[i];
                        if (control.Id.Equals("Range"))
                        {
                            controls.RemoveAt(i);
                        }
                        else if (control.Id.Equals("UseConveyor"))
                        {
                            controls.RemoveAt(i);
                        }
                        else if (control.Id.Equals("WC_Range"))
                        {
                            wcRangeControl = control;
                            controls.RemoveAt(i);
                        }
                    }

                    if (wcRangeControl != null)
                    {
                        controls.Add(wcRangeControl);
                    }
                }
            }
        }
        public static void RemoveControl(Type blockType, IMyTerminalControl controlItem)
        {
            var controlList = GetList(blockType).Controls;

            foreach (var item in controlList)
            {
                if (item == (ITerminalControl)controlItem)
                {
                    controlList.Remove(item);
                    break;
                }
            }

            var block = (ITerminalControl)controlItem;

            if (block.Actions != null)
            {
                foreach (var a in block.Actions)
                {
                    GetList(blockType).Actions.Remove((ITerminalAction)a);
                }
            }
        }
예제 #17
0
        // move this mods' terminal controls right after the control specified in AFTER_CONTROL_ID
        public void CustomControlGetter(IMyTerminalBlock block, List <IMyTerminalControl> controls)
        {
            if (block is IMyProgrammableBlock)
            {
                var index = controls.FindIndex((m) => m.Id == SLIDER_ID);

                if (index == -1)
                {
                    return;
                }

                if (separator == null)
                {
                    separator = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSeparator, IMyProgrammableBlock>(string.Empty);
                }

                var runIndex = controls.FindIndex((m) => m.Id == AFTER_CONTROL_ID);
                var c        = controls[index];
                controls.RemoveAt(index);
                controls.AddOrInsert(separator, runIndex + 1);
                controls.AddOrInsert(c, runIndex + 2);
            }
        }
 /// <summary>
 /// Remove a control from a terminal block.  These will return on session load.
 /// </summary>
 /// <typeparam name="TBlock"></typeparam>
 /// <param name="id"></param>
 public static void RemoveControl <TBlock>(IMyTerminalControl item)
 {
     RemoveControl(typeof(TBlock), item);
 }
예제 #19
0
        internal static IMyTerminalControl[] AddVectorEditor <T>(T block, string name, string title, string tooltip, Func <IMyTerminalBlock, Vector3> getter, Action <IMyTerminalBlock, Vector3> setter, float min = -10, float max = 10, Func <IMyTerminalBlock, bool> enabledGetter = null, Func <IMyTerminalBlock, bool> visibleGetter = null, string writerFormat = "0.##") where T : IMyTerminalBlock
        {
            var controls = new IMyTerminalControl[4];

            var d = GetDefaultEnabled();

            var lb = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlLabel, T>(name + "_Label");

            lb.Label   = MyStringId.GetOrCompute(title);
            lb.Enabled = enabledGetter ?? d;
            lb.Visible = visibleGetter ?? d;
            MyAPIGateway.TerminalControls.AddControl <T>(lb);
            controls[0] = lb;

            var x = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, T>(name + "_X");

            x.Title   = MyStringId.GetOrCompute("X");
            x.Tooltip = MyStringId.GetOrCompute(tooltip);
            x.Writer  = (b, s) => s.Append(getter(b).X.ToString(writerFormat));
            x.Getter  = b => getter(b).X;
            x.Setter  = (b, v) =>
            {
                var vc = getter(b);
                vc.X = v;
                setter(b, vc);
            };
            x.Enabled = enabledGetter ?? d;
            x.Visible = visibleGetter ?? d;
            x.SetLimits(min, max);
            MyAPIGateway.TerminalControls.AddControl <T>(x);
            controls[1] = x;

            var y = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, T>(name + "_Y");

            y.Title   = MyStringId.GetOrCompute("Y");
            y.Tooltip = MyStringId.GetOrCompute(tooltip);
            y.Writer  = (b, s) => s.Append(getter(b).Y.ToString(writerFormat));
            y.Getter  = b => getter(b).Y;
            y.Setter  = (b, v) =>
            {
                var vc = getter(b);
                vc.Y = v;
                setter(b, vc);
            };
            y.Enabled = enabledGetter ?? d;
            y.Visible = visibleGetter ?? d;
            y.SetLimits(min, max);
            MyAPIGateway.TerminalControls.AddControl <T>(y);
            controls[2] = y;

            var z = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, T>(name + "_Z");

            z.Title   = MyStringId.GetOrCompute("Z");
            z.Tooltip = MyStringId.GetOrCompute(tooltip);
            z.Writer  = (b, s) => s.Append(getter(b).Z.ToString(writerFormat));
            z.Getter  = b => getter(b).Z;
            z.Setter  = (b, v) =>
            {
                var vc = getter(b);
                vc.Z = v;
                setter(b, vc);
            };
            z.Enabled = enabledGetter ?? d;
            z.Visible = visibleGetter ?? d;
            z.SetLimits(min, max);
            MyAPIGateway.TerminalControls.AddControl <T>(z);
            controls[3] = z;

            return(controls);
        }
예제 #20
0
 private static string getBlockTypeFilter(IMyTerminalControl control)
 {
     return(control.Id.Contains("[BLOCKFILTER=") ? control.Id.Replace("BLOCKFILTER=", "").Split('[', ']')[1] : null);
 }
예제 #21
0
 public static void SetEnabledAndVisible(this IMyTerminalControl control, Func <IMyTerminalBlock, bool> function)
 {
     control.Enabled = function;
     control.Visible = function;
 }