private void CreateActionCombobox <T>(IMyTerminalControlCombobox c,
                                              string[] itemIds   = null,
                                              string[] itemNames = null,
                                              string icon        = null)
        {
            var items = new List <MyTerminalControlComboBoxItem>();

            c.ComboBoxContent.Invoke(items);

            foreach (var item in items)
            {
                var id = itemIds == null ? item.Value.String : itemIds[item.Key];

                if (id == null)
                {
                    continue; // item id is null intentionally in the array, this means "don't add action".
                }
                var a = MyAPIGateway.TerminalControls.CreateAction <T>(id);
                a.Name = new StringBuilder(itemNames == null ? item.Value.String : itemNames[item.Key]);
                if (icon != null)
                {
                    a.Icon = icon;
                }
                a.ValidForGroups = true;
                a.Action         = (b) => c.Setter(b, item.Key);
                //if(writer != null)
                //    a.Writer = writer;

                MyAPIGateway.TerminalControls.AddAction <T>(a);
            }
        }
Exemplo n.º 2
0
            public StaticVariables()
            {
                Separator = new MyTerminalControlSeparator <MyCockpit>();

                AeroShow        = new MyTerminalControlCheckbox <MyCockpit>("Arms_AeroShow", MyStringId.GetOrCompute("Draw Air Resistance"), MyStringId.GetOrCompute("Draw ARMS calculations of air resistance."));
                AeroShow.Getter = Get_AeroTerminal;
                AeroShow.Setter = Set_AeroTerminal;

                DirectionSelector = MyTerminalControls.Static.CreateControl <IMyTerminalControlCombobox, IMyCockpit>("Arms_AeroDirection");
                DirectionSelector.ComboBoxContent = ListDirections;
                DirectionSelector.Getter          = DirectionGetter;
                DirectionSelector.Setter          = DirectionSetter;
                DirectionSelector.Title           = MyStringId.GetOrCompute("Direction of Movement");

                EnableHelper        = new MyTerminalControlCheckbox <MyCockpit>("Arms_FlightHelper", MyStringId.GetOrCompute("Flight Control Assist"), MyStringId.GetOrCompute("Enable ARMS Flight Control Assistance for atmospheric flight"));
                EnableHelper.Getter = Get_Helper;
                EnableHelper.Setter = Set_Helper;

                AileronButton         = GetRotorButton("Aileron");
                AileronButton.Action  = RotorButtonAileron;
                ElevatorButton        = GetRotorButton("Elevator");
                ElevatorButton.Action = RotorButtonElevator;
                RudderButton          = GetRotorButton("Rudder");
                RudderButton.Action   = RotorButtonRudder;
            }
Exemplo n.º 3
0
        public static void CreateTerminalControls()
        {
            if (controls_created)
            {
                return;
            }
            controls_created = true;
            if (ComboListBox == null)
            {
                ComboListBox                        = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlCombobox, IMyTextPanel>("Script List");
                ComboListBox.Enabled                = ControlEnabled;
                ComboListBox.Title                  = MyStringId.GetOrCompute("Channel List");
                ComboListBox.Visible                = ControlVisible;
                ComboListBox.ComboBoxContent        = (x) => GetContent(x);
                ComboListBox.SupportsMultipleBlocks = SupportsMultipleBlocks;
                ComboListBox.Setter                 = Setter;
                ComboListBox.Getter                 = (x) => Getter(x);
                MyAPIGateway.TerminalControls.AddControl <IMyTextPanel>(ComboListBox);

                var LineItem = new MyTerminalControlComboBoxItem();
                LineItem.Key   = 0;
                LineItem.Value = None;
                Obj.Add(LineItem);
                SteamIdGetter.Add(LineItem.Key, 0);
                LineGetter.Add(0, LineItem.Key);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns true if it can retrieve the current value without throwing an exception.
        /// </summary>
        public static bool CanAccessValue(this IMyTerminalControlCombobox comboBox, IMyTerminalBlock tBlock, List <MyTerminalControlComboBoxItem> contentBuffer)
        {
            if (CanAccessValue(comboBox, tBlock) && comboBox.ComboBoxContent != null)
            {
                try
                {
                    contentBuffer.Clear();
                    comboBox.ComboBoxContent(contentBuffer);
                    return(true);
                }
                catch { }
            }

            return(false);
        }
        private void AddPBScriptSelector()
        {
            ScriptsDropdown =
                MyAPIGateway.TerminalControls.CreateControl <
                    IMyTerminalControlCombobox,
                    IMyProgrammableBlock>("ScriptWhitelist");
            ScriptsDropdown.Title = MyStringId.GetOrCompute("Active Script");
            MyAPIGateway.TerminalControls.AddControl <IMyProgrammableBlock>(ScriptsDropdown);

            ScriptsDropdown.ComboBoxContent = (List <MyTerminalControlComboBoxItem> items) => {
                foreach (var script in WhitelistData.Scripts)
                {
                    items.Add(new MyTerminalControlComboBoxItem()
                    {
                        Key   = script.Key,
                        Value = MyStringId.GetOrCompute(script.Value)
                    });
                }
            };
            ScriptsDropdown.Getter = GetActiveScript;
            ScriptsDropdown.Setter = SetActiveScript;
        }
Exemplo n.º 6
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);
        }