예제 #1
0
        public static void CreateControlListbox(string id, string title, string tooltip, int rowCount, Func <IMyTerminalBlock, bool> visible, Func <IMyTerminalBlock, bool> enabled, Action <IMyTerminalBlock, List <MyTerminalControlListBoxItem>, List <MyTerminalControlListBoxItem> > populate, Action <IMyTerminalBlock, List <MyTerminalControlListBoxItem> > selectItem)
        {
            if (ControlIdExists(id) != null)
            {
                return;
            }

            IMyTerminalControlListbox listbox = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlListbox, IMyUpgradeModule>(id);

            listbox.Enabled                = enabled;
            listbox.Visible                = visible;
            listbox.Multiselect            = false;
            listbox.SupportsMultipleBlocks = false;

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

            listbox.VisibleRowsCount = rowCount;
            listbox.ListContent      = populate;
            listbox.ItemSelected     = selectItem;

            MyAPIGateway.TerminalControls.AddControl <IMyUpgradeModule>(listbox);
        }
예제 #2
0
        private void Cleanup()
        {
            m_commandList.Clear();

            m_infoMessage     = null;
            m_termCommandList = null;
            m_currentCommand  = null;
        }
예제 #3
0
        public override void AddControls(List <Sandbox.ModAPI.Interfaces.Terminal.IMyTerminalControl> controls)
        {
            if (m_oreListbox == null)
            {
                m_oreListbox              = new MyTerminalControlListbox <MyShipController>("Ores", MyStringId.GetOrCompute("Ores"), MyStringId.NullOrEmpty);
                m_oreListbox.ListContent  = ListContent;
                m_oreListbox.ItemSelected = ItemSelected;
            }
            controls.Add(m_oreListbox);

            if (!m_addingOres)
            {
                controls.Add(new MyTerminalControlButton <MyShipController>("AddOre", MyStringId.GetOrCompute("Add Ore"), MyStringId.NullOrEmpty, AddOre));
                controls.Add(new MyTerminalControlButton <MyShipController>("RemoveOre", MyStringId.GetOrCompute("Remove Ore"), MyStringId.NullOrEmpty, RemoveOre));
                controls.Add(new MyTerminalControlButton <MyShipController>("MoveOreUp", MyStringId.GetOrCompute("Move Ore Up"), MyStringId.NullOrEmpty, MoveOreUp));
                controls.Add(new MyTerminalControlButton <MyShipController>("MoveOreDown", MyStringId.GetOrCompute("Move Ore Down"), MyStringId.NullOrEmpty, MoveOreDown));
            }
        }
예제 #4
0
        public override void AddControls(List <Sandbox.ModAPI.Interfaces.Terminal.IMyTerminalControl> controls)
        {
            if (!m_addingResponse)
            {
                MyTerminalControlSlider <MyShipController> range = new MyTerminalControlSlider <MyShipController>("RangeSlider", MyStringId.GetOrCompute("Range"),
                                                                                                                  MyStringId.GetOrCompute("How close enemy needs to be for autopilot to respond to it. Zero indicates infinite range."));
                range.Normalizer   = Normalizer;
                range.Denormalizer = Denormalizer;
                range.Writer       = (block, sb) => {
                    sb.Append(PrettySI.makePretty(m_range));
                    sb.Append('m');
                };
                IMyTerminalValueControl <float> valueControler = range;
                valueControler.Getter = block => m_range;
                valueControler.Setter = (block, value) => m_range = value;
                controls.Add(range);

                MyTerminalControlTextbox <MyShipController> enemyId = new MyTerminalControlTextbox <MyShipController>("EnemyId", MyStringId.GetOrCompute("Enemy Entity ID"), MyStringId.GetOrCompute("If set, only target an enemy with this entity ID"));
                enemyId.Getter = block => new StringBuilder(m_enemyId.ToString());
                enemyId.Setter = (block, value) => {
                    if (!long.TryParse(value.ToString(), out m_enemyId))
                    {
                        m_enemyId = -1L;
                    }
                };
                controls.Add(enemyId);
            }

            if (m_responseListbox == null)
            {
                m_responseListbox              = new MyTerminalControlListbox <MyShipController>("Responses", MyStringId.GetOrCompute("Responses"), MyStringId.NullOrEmpty);
                m_responseListbox.ListContent  = ListContent;
                m_responseListbox.ItemSelected = ItemSelected;
            }
            controls.Add(m_responseListbox);

            if (!m_addingResponse)
            {
                controls.Add(new MyTerminalControlButton <MyShipController>("AddResponse", MyStringId.GetOrCompute("Add Response"), MyStringId.NullOrEmpty, AddResponse));
                controls.Add(new MyTerminalControlButton <MyShipController>("RemoveResponse", MyStringId.GetOrCompute("Remove Response"), MyStringId.NullOrEmpty, RemoveResponse));
                controls.Add(new MyTerminalControlButton <MyShipController>("MoveResponseUp", MyStringId.GetOrCompute("Move Response Up"), MyStringId.NullOrEmpty, MoveResponseUp));
                controls.Add(new MyTerminalControlButton <MyShipController>("MoveResponseDown", MyStringId.GetOrCompute("Move Response Down"), MyStringId.NullOrEmpty, MoveResponseDown));
            }
        }
예제 #5
0
        /// <summary>
        /// Creates all of the custom controls for the blocks
        /// </summary>
        private void MakeControls()
        {
            IMyTerminalControlSeparator sep1
                = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSeparator, IMyUpgradeModule>("Sep1");

            _radarControls.Add(sep1);

            IMyTerminalControlSlider rangeSlider
                = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyUpgradeModule>("RangeSlider");

            rangeSlider.Title   = MyStringId.GetOrCompute("Range");
            rangeSlider.Tooltip = MyStringId.GetOrCompute("Maximum range of this radar system");
            rangeSlider.SetLimits(100, 15000);
            rangeSlider.Getter = (block) => {
                RadarController controller = block.GameLogic.GetAs <RadarController>();
                return(controller.GetRange());
            };
            rangeSlider.Setter = (block, value) => {
                RadarController controller = block.GameLogic.GetAs <RadarController>();
                controller.SetRange((int)value);
                SendRadarSettings(new BlockAddress(block.CubeGrid.EntityId, block.EntityId));
            };
            rangeSlider.Writer = (block, str) => {
                RadarController controller = block.GameLogic.GetAs <RadarController>();
                str.Append(controller.GetRange() + "m");
            };
            _radarRangeSlider = rangeSlider;
            _radarControls.Add(rangeSlider);

            IMyTerminalControlSlider freqSlider
                = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyUpgradeModule>("FreqSlider");

            freqSlider.Title   = MyStringId.GetOrCompute("Frequency");
            freqSlider.Tooltip = MyStringId.GetOrCompute("Operating frequency of this system");
            freqSlider.SetLimits(8.0f, 12.0f);
            freqSlider.Getter = (block) => {
                RadarController controller = block.GameLogic.GetAs <RadarController>();
                return(controller.GetFreq());
            };
            freqSlider.Setter = (block, value) => {
                RadarController controller = block.GameLogic.GetAs <RadarController>();
                controller.SetFreq(value);
                SendRadarSettings(new BlockAddress(block.CubeGrid.EntityId, block.EntityId));
            };
            freqSlider.Writer = (block, str) => {
                RadarController controller = block.GameLogic.GetAs <RadarController>();
                str.Append(controller.GetFreq() + "GHz");
            };
            _radarFreqSlider = freqSlider;
            _radarControls.Add(freqSlider);

            IMyTerminalControlSeparator sep2
                = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSeparator, IMyUpgradeModule>("Sep2");

            _radarControls.Add(sep2);

            IMyTerminalControlListbox unassignedList
                = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlListbox, IMyUpgradeModule>("UnassignedList");

            unassignedList.Title = MyStringId.GetOrCompute("Available");
            //unassignedList.Tooltip = MyStringId.GetOrCompute("Radar blocks which are able to be assigned to this system.");
            unassignedList.Multiselect      = true;
            unassignedList.VisibleRowsCount = 6;
            unassignedList.ListContent      = (block, items, selected) => {
                RadarController controller
                    = block.GameLogic.GetAs <RadarController>();
                List <RadarController.Radar> available
                    = controller.GetAvailableRadars();

                foreach (RadarController.Radar r in available)
                {
                    MyTerminalControlListBoxItem item
                        = new MyTerminalControlListBoxItem(
                              MyStringId.GetOrCompute(r.block.FatBlock.DisplayNameText),
                              MyStringId.GetOrCompute(r.type.ToString()),
                              r
                              );
                    items.Add(item);
                }
            };
            unassignedList.ItemSelected = (block, items) => {
                _selectedUnassigned.Clear();

                foreach (MyTerminalControlListBoxItem item in items)
                {
                    _selectedUnassigned.Add(item.UserData as RadarController.Radar);
                }
            };
            _radarControls.Add(unassignedList);

            IMyTerminalControlButton addButton
                = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyUpgradeModule>("AddButton");

            addButton.Title   = MyStringId.GetOrCompute("Assign");
            addButton.Tooltip = MyStringId.GetOrCompute("Assign the selected radar to this system.");
            _radarControls.Add(addButton);

            IMyTerminalControlListbox assignedList
                = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlListbox, IMyUpgradeModule>("AssignedList");

            assignedList.Title            = MyStringId.GetOrCompute("Assigned");
            assignedList.Tooltip          = MyStringId.GetOrCompute("Radar blocks which are currently assigned to this system.");
            assignedList.Multiselect      = true;
            assignedList.VisibleRowsCount = 6;
            assignedList.ListContent      = (block, items, selected) => {
                RadarController controller
                    = block.GameLogic.GetAs <RadarController>();
                List <RadarController.Radar> assigned
                    = controller.GetAssignedRadars();

                foreach (RadarController.Radar r in assigned)
                {
                    MyTerminalControlListBoxItem item
                        = new MyTerminalControlListBoxItem(
                              MyStringId.GetOrCompute(r.block.FatBlock.DisplayNameText),
                              MyStringId.GetOrCompute(r.type.ToString()),
                              r
                              );
                    items.Add(item);
                }
            };
            assignedList.ItemSelected = (block, items) => {
                _selectedAssigned.Clear();

                foreach (MyTerminalControlListBoxItem item in items)
                {
                    _selectedAssigned.Add(item.UserData as RadarController.Radar);
                }
            };
            _radarControls.Add(assignedList);

            // Add button action must be after assigned list because it
            // needs the pointer
            addButton.Action = (block) => {
                RadarController controller
                    = block.GameLogic.GetAs <RadarController>();

                foreach (RadarController.Radar radar in _selectedUnassigned)
                {
                    controller.AssignRadar(radar);
                }

                unassignedList.UpdateVisual();
                assignedList.UpdateVisual();

                SetRadarSliderLimits((int)controller.GetRadarType());
                rangeSlider.UpdateVisual();
                freqSlider.UpdateVisual();
            };

            IMyTerminalControlButton removeButton
                = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyUpgradeModule>("AddButton");

            removeButton.Title   = MyStringId.GetOrCompute("Remove");
            removeButton.Tooltip = MyStringId.GetOrCompute("Remove the selected radars from the system.");
            removeButton.Action  = (block) => {
                RadarController controller
                    = block.GameLogic.GetAs <RadarController>();

                foreach (RadarController.Radar radar in _selectedAssigned)
                {
                    controller.UnassignedRadar(radar);
                }

                unassignedList.UpdateVisual();
                assignedList.UpdateVisual();

                SetRadarSliderLimits((int)controller.GetRadarType());
                rangeSlider.UpdateVisual();
                freqSlider.UpdateVisual();
            };
            _radarControls.Add(removeButton);
        }
        // Context: All
        public override void UpdateOnceBeforeFrame()
        {
            if (me.CubeGrid?.Physics == null)
            {
                return;
            }

            _state = new SyncableProjectorState(me, State.Idle, 0);

            if (Constants.IsServer)
            {
                LoadStorage();
                _settings.OnValueReceived += SaveStorage;
                BuildState           = State.Idle;
                me.IsWorkingChanged += Me_IsWorkingChanged;
            }
            else
            {
                _settings = new SyncableProjectorSettings(me, 0, true);
                _state.RequestFromServer();
                _settings.RequestFromServer();
                _state.OnValueReceived += ReceivedNewState;
            }

            MyProjectorDefinition def = (MyProjectorDefinition)MyDefinitionManager.Static.GetCubeBlockDefinition(me.BlockDefinition);

            minPower = def.RequiredPowerInput;
            sink     = me.Components.Get <MyResourceSinkComponent>();
            MyDefinitionId powerDef = MyResourceDistributorComponent.ElectricityId;

            sink.SetRequiredInputFuncByType(powerDef, GetCurrentPower);
            sink.Update();
            _settings.OnValueReceived += RefreshUI;

            me.AppendingCustomInfo += CustomInfo;
            me.RefreshCustomInfo();

            Settings.MapSettings config = IPSession.Instance.MapSettings;
            config.OnSubgridsChanged += ClearCachedComps;
            config.OnComponentCostModifierChanged += ClearCachedComps;
            config.OnExtraComponentChanged        += ClearCachedComps;
            config.OnExtraCompCostChanged         += ClearCachedComps;

            if (!controls)
            {
                // Terminal controls

                IMyTerminalControlSeparator sep = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSeparator, IMyProjector>("BuildGridSep");
                sep.Enabled = IsValid;
                sep.Visible = IsValid;
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(sep);

                IMyTerminalControlButton btnBuild = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyProjector>("BuildGrid");
                btnBuild.Enabled = IsWorking;
                btnBuild.Visible = IsValid;
                btnBuild.SupportsMultipleBlocks = true;
                btnBuild.Title   = MyStringId.GetOrCompute("Build Grid");
                btnBuild.Action  = BuildClient;
                btnBuild.Tooltip = MyStringId.GetOrCompute("Builds the projection instantly.\nThere will be a cooldown after building.");
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(btnBuild);

                IMyTerminalControlButton btnCancel = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyProjector>("CancelBuildGrid");
                btnCancel.Enabled = IsWorking;
                btnCancel.Visible = IsValid;
                btnCancel.SupportsMultipleBlocks = true;
                btnCancel.Title   = MyStringId.GetOrCompute("Cancel");
                btnCancel.Action  = CancelClient;
                btnCancel.Tooltip = MyStringId.GetOrCompute("Cancels the build process.");
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(btnCancel);

                IMyTerminalControlCheckbox chkShift = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlCheckbox, IMyProjector>("MoveProjectionArea");
                chkShift.Enabled = IsWorking;
                chkShift.Visible = IsValid;
                chkShift.SupportsMultipleBlocks = true;
                chkShift.Title   = MyStringId.GetOrCompute("Loose Projection Area");
                chkShift.OnText  = MyStringId.GetOrCompute("On");
                chkShift.OffText = MyStringId.GetOrCompute("Off");
                chkShift.Tooltip = MyStringId.GetOrCompute("Allow the projection to spawn in a different area if the original area is occupied.");
                chkShift.Setter  = SetLooseArea;
                chkShift.Getter  = GetLooseArea;
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(chkShift);

                IMyTerminalControlSlider sliderSpeed = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyProjector>("BuildSpeed");
                sliderSpeed.Enabled = IsWorking;
                sliderSpeed.Visible = IsValid;
                sliderSpeed.SupportsMultipleBlocks = true;
                sliderSpeed.Title   = MyStringId.GetOrCompute("Speed");
                sliderSpeed.Tooltip = MyStringId.GetOrCompute("Increasing the speed will use more energy.");
                sliderSpeed.SetLogLimits(Constants.minSpeed, Constants.maxSpeed);
                sliderSpeed.Writer = GetSpeedText;
                sliderSpeed.Getter = GetSpeed;
                sliderSpeed.Setter = SetSpeed;
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(sliderSpeed);

                IMyTerminalControlTextbox txtTimeout = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlTextbox, IMyProjector>("GridTimer");
                txtTimeout.Enabled = (b) => false;
                txtTimeout.Visible = IsValid;
                txtTimeout.Getter  = GetTimer;
                txtTimeout.Setter  = (b, s) => { };
                txtTimeout.SupportsMultipleBlocks = false;
                txtTimeout.Title   = MyStringId.GetOrCompute("Build Timer");
                txtTimeout.Tooltip = MyStringId.GetOrCompute("The amount of time you must wait after building a grid to be able to build another.");
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(txtTimeout);

                // Terminal actions
                // Button panels are special and trigger on the server instead of the client, making everything more complicated.

                IMyTerminalAction aCancel = MyAPIGateway.TerminalControls.CreateAction <IMyProjector>("CancelBuildAction");
                aCancel.Enabled             = IsValid;
                aCancel.Action              = CancelClient; // For all except button panels
                aCancel.ValidForGroups      = true;
                aCancel.Name                = new StringBuilder("Cancel Spawn Grid");
                aCancel.Writer              = (b, s) => s.Append("Cancel");
                aCancel.InvalidToolbarTypes = new[] { MyToolbarType.ButtonPanel }.ToList();
                MyAPIGateway.TerminalControls.AddAction <IMyProjector>(aCancel);
                IMyTerminalAction aCancel2 = MyAPIGateway.TerminalControls.CreateAction <IMyProjector>("CancelBuildGrid");
                aCancel2.Enabled             = IsValid;
                aCancel2.Action              = CancelClientUnsafe; // For only button panels
                aCancel2.ValidForGroups      = true;
                aCancel2.Name                = new StringBuilder("Cancel Spawn Grid");
                aCancel2.Writer              = (b, s) => s.Append("Cancel");
                aCancel2.InvalidToolbarTypes = new List <MyToolbarType> {
                    MyToolbarType.BuildCockpit, MyToolbarType.Character, MyToolbarType.LargeCockpit,
                    MyToolbarType.None, MyToolbarType.Seat, MyToolbarType.Ship, MyToolbarType.SmallCockpit, MyToolbarType.Spectator
                };
                MyAPIGateway.TerminalControls.AddAction <IMyProjector>(aCancel2);

                IMyTerminalAction aBuild = MyAPIGateway.TerminalControls.CreateAction <IMyProjector>("BuildGridAction");
                aBuild.Enabled             = IsValid;
                aBuild.Action              = BuildClient; // For all except button panels
                aBuild.ValidForGroups      = true;
                aBuild.Name                = new StringBuilder("Spawn Grid");
                aBuild.Writer              = (b, s) => s.Append("Spawn");
                aBuild.InvalidToolbarTypes = new [] { MyToolbarType.ButtonPanel }.ToList();
                MyAPIGateway.TerminalControls.AddAction <IMyProjector>(aBuild);
                IMyTerminalAction aBuild2 = MyAPIGateway.TerminalControls.CreateAction <IMyProjector>("BuildGrid");
                aBuild2.Enabled             = IsValid;
                aBuild2.Action              = BuildClientUnsafe; // For only button panels
                aBuild2.ValidForGroups      = true;
                aBuild2.Name                = new StringBuilder("Spawn Grid");
                aBuild2.Writer              = (b, s) => s.Append("Spawn");
                aBuild2.InvalidToolbarTypes = new List <MyToolbarType> {
                    MyToolbarType.BuildCockpit, MyToolbarType.Character, MyToolbarType.LargeCockpit,
                    MyToolbarType.None, MyToolbarType.Seat, MyToolbarType.Ship, MyToolbarType.SmallCockpit, MyToolbarType.Spectator
                };
                MyAPIGateway.TerminalControls.AddAction <IMyProjector>(aBuild2);

                IMyTerminalControlListbox itemList = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlListbox, IMyProjector>("ComponentList");
                itemList.Enabled                = IsWorking;
                itemList.Visible                = IsValid;
                itemList.ListContent            = GetItemList;
                itemList.Multiselect            = false;
                itemList.SupportsMultipleBlocks = false;
                itemList.Title            = MyStringId.GetOrCompute("Components");
                itemList.VisibleRowsCount = 10;
                itemList.ItemSelected     = (b, l) => { };
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(itemList);


                // Programmable Block stuff

                IMyTerminalControlProperty <Dictionary <MyItemType, int> > itemListProp
                    = MyAPIGateway.TerminalControls.CreateProperty <Dictionary <MyItemType, int>, IMyProjector>("RequiredComponents");
                itemListProp.Enabled = IsWorking;
                itemListProp.Visible = IsValid;
                itemListProp.SupportsMultipleBlocks = false;
                itemListProp.Setter = (b, l) => { };
                itemListProp.Getter = GetItemListPB;
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(itemListProp);

                IMyTerminalControlProperty <int> gridTimeoutProp
                    = MyAPIGateway.TerminalControls.CreateProperty <int, IMyProjector>("GridTimerProjection");
                gridTimeoutProp.Enabled = IsWorking;
                gridTimeoutProp.Visible = IsValid;
                gridTimeoutProp.SupportsMultipleBlocks = false;
                gridTimeoutProp.Setter = (b, l) => { };
                gridTimeoutProp.Getter = GetMaxTimerPB;
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(gridTimeoutProp);

                IMyTerminalControlProperty <int> gridTimeoutActive
                    = MyAPIGateway.TerminalControls.CreateProperty <int, IMyProjector>("GridTimerCurrent");
                gridTimeoutActive.Enabled = IsWorking;
                gridTimeoutActive.Visible = IsValid;
                gridTimeoutActive.SupportsMultipleBlocks = false;
                gridTimeoutActive.Setter = (b, l) => { };
                gridTimeoutActive.Getter = GetCurrentTimerPB;
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(gridTimeoutActive);

                IMyTerminalControlProperty <int> buildState
                    = MyAPIGateway.TerminalControls.CreateProperty <int, IMyProjector>("BuildState");
                buildState.Enabled = IsWorking;
                buildState.Visible = IsValid;
                buildState.SupportsMultipleBlocks = false;
                buildState.Setter = (b, l) => { };
                buildState.Getter = GetStatePB;
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(gridTimeoutActive);

                MyLog.Default.WriteLineAndConsole("Initialized Instant Projector.");
                controls = true;
            }
        }
예제 #7
0
        private void CustomControlGetter(IMyTerminalBlock block, List <IMyTerminalControl> controls)
        {
            //Log.DebugLog("entered");

            if (block != m_block)
            {
                return;
            }

            controls.Clear();

            if (m_listCommands)
            {
                Log.DebugLog("showing command list");

                if (m_termCommandList == null)
                {
                    m_termCommandList              = new MyTerminalControlListbox <MyShipController>("CommandList", MyStringId.GetOrCompute("Commands"), MyStringId.NullOrEmpty, false, 10);
                    m_termCommandList.ListContent  = ListCommands;
                    m_termCommandList.ItemSelected = CommandSelected;
                }
                controls.Add(m_termCommandList);

                controls.Add(new MyTerminalControlButton <MyShipController>("AddCommand", MyStringId.GetOrCompute("Add Command"), MyStringId.NullOrEmpty, AddCommand));
                controls.Add(new MyTerminalControlButton <MyShipController>("InsertCommand", MyStringId.GetOrCompute("Insert Command"), MyStringId.NullOrEmpty, InsertCommand));
                controls.Add(new MyTerminalControlButton <MyShipController>("RemoveCommand", MyStringId.GetOrCompute("Remove Command"), MyStringId.NullOrEmpty, RemoveCommand));
                controls.Add(new MyTerminalControlButton <MyShipController>("EditCommand", MyStringId.GetOrCompute("Edit Command"), MyStringId.NullOrEmpty, EditCommand));
                controls.Add(new MyTerminalControlButton <MyShipController>("MoveCommandUp", MyStringId.GetOrCompute("Move Command Up"), MyStringId.NullOrEmpty, MoveCommandUp));
                controls.Add(new MyTerminalControlButton <MyShipController>("MoveCommandDown", MyStringId.GetOrCompute("Move Command Down"), MyStringId.NullOrEmpty, MoveCommandDown));
                controls.Add(new MyTerminalControlSeparator <MyShipController>());
                controls.Add(new MyTerminalControlButton <MyShipController>("Finished", MyStringId.GetOrCompute("Save & Exit"), MyStringId.GetOrCompute("Save all commands and exit"), b => Finished(true)));
                controls.Add(new MyTerminalControlButton <MyShipController>("DiscardAll", MyStringId.GetOrCompute("Discard & Exit"), MyStringId.GetOrCompute("Discard all commands and exit"), b => Finished(false)));

                return;
            }

            if (m_currentCommand == null)
            {
                // add/insert new command
                if (m_currentAddNode.Count == 0)
                {
                    m_currentAddNode.Push(Static.addCommandRoot);
                }

                foreach (AddCommandTreeNode child in m_currentAddNode.Peek().Children)
                {
                    controls.Add(new MyTerminalControlButton <MyShipController>(child.Name.RemoveWhitespace(), MyStringId.GetOrCompute(child.Name), MyStringId.GetOrCompute(child.Tooltip), shipController => {
                        AddCommandLeafNode leaf = child as AddCommandLeafNode;
                        if (leaf != null)
                        {
                            m_currentCommand = leaf.Command.Clone();
                            if (!m_currentCommand.HasControls)
                            {
                                CheckAndSave(block);
                            }
                            m_currentAddNode.Clear();
                        }
                        else
                        {
                            m_currentAddNode.Push((AddCommandInternalNode)child);
                        }
                        ClearMessage();
                    }));
                }

                controls.Add(new MyTerminalControlButton <MyShipController>("UpOneLevel", MyStringId.GetOrCompute("Up one level"), MyStringId.GetOrCompute("Return to previous list"), shipController => {
                    m_currentAddNode.Pop();
                    if (m_currentAddNode.Count == 0)
                    {
                        m_listCommands = true;
                    }
                    shipController.RebuildControls();
                }));

                return;
            }

            Log.DebugLog("showing single command: " + m_currentCommand.Identifier);

            m_currentCommand.AddControls(controls);
            controls.Add(new MyTerminalControlSeparator <MyShipController>());
            controls.Add(new MyTerminalControlButton <MyShipController>("SaveGooeyCommand", MyStringId.GetOrCompute("Check & Save"), MyStringId.GetOrCompute("Check the current command for syntax errors and save it"), CheckAndSave));
            controls.Add(new MyTerminalControlButton <MyShipController>("DiscardGooeyCommand", MyStringId.GetOrCompute("Discard"), MyStringId.GetOrCompute("Discard the current command"), Discard));
        }
        public static void Create()
        {
            if (controls)
            {
                return;
            }

            IMyTerminalControlSeparator sep = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSeparator, IMyProjector>("BuildGridSep");

            sep.Enabled = IsValid;
            sep.Visible = IsValid;
            sep.SupportsMultipleBlocks = true;
            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(sep);

            IMyTerminalControlLabel lbl = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlLabel, IMyProjector>("BuildGridLabel");

            lbl.Enabled = IsValid;
            lbl.Visible = IsValid;
            lbl.SupportsMultipleBlocks = true;
            lbl.Label = MyStringId.GetOrCompute("Instant Projector Controls");
            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(lbl);

            IMyTerminalControlButton btnBuild = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyProjector>("BuildGrid");

            btnBuild.Enabled = IsWorking;
            btnBuild.Visible = IsValid;
            btnBuild.SupportsMultipleBlocks = true;
            btnBuild.Title   = MyStringId.GetOrCompute("Build Grid");
            btnBuild.Action  = BuildClient;
            btnBuild.Tooltip = MyStringId.GetOrCompute("Builds the projection instantly.\nThere will be a cooldown after building.");
            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(btnBuild);

            IMyTerminalControlButton btnCancel = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyProjector>("CancelBuildGrid");

            btnCancel.Enabled = IsWorking;
            btnCancel.Visible = IsValid;
            btnCancel.SupportsMultipleBlocks = true;
            btnCancel.Title   = MyStringId.GetOrCompute("Cancel");
            btnCancel.Action  = CancelClient;
            btnCancel.Tooltip = MyStringId.GetOrCompute("Cancels the build process.");
            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(btnCancel);

            IMyTerminalControlCheckbox chkShift = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlCheckbox, IMyProjector>("MoveProjectionArea");

            chkShift.Enabled = IsWorking;
            chkShift.Visible = IsValid;
            chkShift.SupportsMultipleBlocks = true;
            chkShift.Title   = MyStringId.GetOrCompute("Loose Projection Area");
            chkShift.OnText  = MyStringId.GetOrCompute("On");
            chkShift.OffText = MyStringId.GetOrCompute("Off");
            chkShift.Tooltip = MyStringId.GetOrCompute("Allow the projection to spawn in a different area if the original area is occupied.");
            chkShift.Setter  = SetLooseArea;
            chkShift.Getter  = GetLooseArea;
            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(chkShift);

            IMyTerminalControlSlider sliderSpeed = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyProjector>("BuildSpeed");

            sliderSpeed.Enabled = IsWorking;
            sliderSpeed.Visible = IsValid;
            sliderSpeed.SupportsMultipleBlocks = true;
            sliderSpeed.Title   = MyStringId.GetOrCompute("Speed");
            sliderSpeed.Tooltip = MyStringId.GetOrCompute("Increasing the speed will use more energy.");
            sliderSpeed.SetLogLimits(Constants.minSpeed, Constants.maxSpeed);
            sliderSpeed.Writer = GetSpeedText;
            sliderSpeed.Getter = GetSpeed;
            sliderSpeed.Setter = SetSpeed;
            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(sliderSpeed);

            IMyTerminalControlTextbox txtTimeout = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlTextbox, IMyProjector>("GridTimer");

            txtTimeout.Enabled = (b) => false;
            txtTimeout.Visible = IsValid;
            txtTimeout.Getter  = GetTimer;
            txtTimeout.Setter  = (b, s) => { };
            txtTimeout.SupportsMultipleBlocks = false;
            txtTimeout.Title   = MyStringId.GetOrCompute("Build Timer");
            txtTimeout.Tooltip = MyStringId.GetOrCompute("The amount of time you must wait after building a grid to be able to build another.");
            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(txtTimeout);

            // Terminal actions
            // Button panels are special and trigger on the server instead of the client, making everything more complicated.

            IMyTerminalAction aCancel = MyAPIGateway.TerminalControls.CreateAction <IMyProjector>("CancelBuildAction");

            aCancel.Enabled             = IsValid;
            aCancel.Action              = CancelClient; // For all except button panels
            aCancel.ValidForGroups      = true;
            aCancel.Name                = new StringBuilder("Cancel Spawn Grid");
            aCancel.Writer              = (b, s) => s.Append("Cancel");
            aCancel.InvalidToolbarTypes = new[] { MyToolbarType.ButtonPanel }.ToList();
            MyAPIGateway.TerminalControls.AddAction <IMyProjector>(aCancel);
            IMyTerminalAction aCancel2 = MyAPIGateway.TerminalControls.CreateAction <IMyProjector>("CancelBuildGrid");

            aCancel2.Enabled             = IsValid;
            aCancel2.Action              = CancelClientUnsafe; // For only button panels
            aCancel2.ValidForGroups      = true;
            aCancel2.Name                = new StringBuilder("Cancel Spawn Grid");
            aCancel2.Writer              = (b, s) => s.Append("Cancel");
            aCancel2.InvalidToolbarTypes = new List <MyToolbarType> {
                MyToolbarType.BuildCockpit, MyToolbarType.Character, MyToolbarType.LargeCockpit,
                MyToolbarType.None, MyToolbarType.Seat, MyToolbarType.Ship, MyToolbarType.SmallCockpit, MyToolbarType.Spectator
            };
            MyAPIGateway.TerminalControls.AddAction <IMyProjector>(aCancel2);

            IMyTerminalAction aBuild = MyAPIGateway.TerminalControls.CreateAction <IMyProjector>("BuildGridAction");

            aBuild.Enabled             = IsValid;
            aBuild.Action              = BuildClient; // For all except button panels
            aBuild.ValidForGroups      = true;
            aBuild.Name                = new StringBuilder("Spawn Grid");
            aBuild.Writer              = (b, s) => s.Append("Spawn");
            aBuild.InvalidToolbarTypes = new[] { MyToolbarType.ButtonPanel }.ToList();
            MyAPIGateway.TerminalControls.AddAction <IMyProjector>(aBuild);
            IMyTerminalAction aBuild2 = MyAPIGateway.TerminalControls.CreateAction <IMyProjector>("BuildGrid");

            aBuild2.Enabled             = IsValid;
            aBuild2.Action              = BuildClientUnsafe; // For only button panels
            aBuild2.ValidForGroups      = true;
            aBuild2.Name                = new StringBuilder("Spawn Grid");
            aBuild2.Writer              = (b, s) => s.Append("Spawn");
            aBuild2.InvalidToolbarTypes = new List <MyToolbarType> {
                MyToolbarType.BuildCockpit, MyToolbarType.Character, MyToolbarType.LargeCockpit,
                MyToolbarType.None, MyToolbarType.Seat, MyToolbarType.Ship, MyToolbarType.SmallCockpit, MyToolbarType.Spectator
            };
            MyAPIGateway.TerminalControls.AddAction <IMyProjector>(aBuild2);

            IMyTerminalControlListbox itemList = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlListbox, IMyProjector>("ComponentList");

            itemList.Enabled                = IsWorking;
            itemList.Visible                = IsValid;
            itemList.ListContent            = GetItemList;
            itemList.Multiselect            = false;
            itemList.SupportsMultipleBlocks = false;
            itemList.Title            = MyStringId.GetOrCompute("Components");
            itemList.VisibleRowsCount = 10;
            itemList.ItemSelected     = (b, l) => { };
            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(itemList);

            IMyTerminalControlButton itemListInfo = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyProjector>("ComponentListInfo");

            itemListInfo.Enabled = IsWorking;
            itemListInfo.Visible = IsValid;
            itemListInfo.SupportsMultipleBlocks = false;
            itemListInfo.Title  = MyStringId.GetOrCompute("Check Inventory");
            itemListInfo.Action = OpenItemList;
            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(itemListInfo);


            // Programmable Block stuff

            IMyTerminalControlProperty <Dictionary <MyItemType, int> > itemListProp
                = MyAPIGateway.TerminalControls.CreateProperty <Dictionary <MyItemType, int>, IMyProjector>("RequiredComponents");

            itemListProp.Enabled = IsWorking;
            itemListProp.Visible = IsValid;
            itemListProp.SupportsMultipleBlocks = false;
            itemListProp.Setter = (b, l) => { };
            itemListProp.Getter = GetItemListPB;
            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(itemListProp);

            IMyTerminalControlProperty <int> gridTimeoutProp
                = MyAPIGateway.TerminalControls.CreateProperty <int, IMyProjector>("GridTimerProjection");

            gridTimeoutProp.Enabled = IsWorking;
            gridTimeoutProp.Visible = IsValid;
            gridTimeoutProp.SupportsMultipleBlocks = false;
            gridTimeoutProp.Setter = (b, l) => { };
            gridTimeoutProp.Getter = GetMaxTimerPB;
            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(gridTimeoutProp);

            IMyTerminalControlProperty <int> gridTimeoutActive
                = MyAPIGateway.TerminalControls.CreateProperty <int, IMyProjector>("GridTimerCurrent");

            gridTimeoutActive.Enabled = IsWorking;
            gridTimeoutActive.Visible = IsValid;
            gridTimeoutActive.SupportsMultipleBlocks = false;
            gridTimeoutActive.Setter = (b, l) => { };
            gridTimeoutActive.Getter = GetCurrentTimerPB;
            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(gridTimeoutActive);

            IMyTerminalControlProperty <int> buildState
                = MyAPIGateway.TerminalControls.CreateProperty <int, IMyProjector>("BuildState");

            buildState.Enabled = IsWorking;
            buildState.Visible = IsValid;
            buildState.SupportsMultipleBlocks = false;
            buildState.Setter = (b, l) => { };
            buildState.Getter = GetStatePB;
            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(gridTimeoutActive);

            MyLog.Default.WriteLineAndConsole("Initialized Instant Projector.");
            controls = true;
        }
        private void addTerminalControls()
        {
            if (controlsAdded == true)
            {
                return;
            }

            controlsAdded = true;

            IMyTerminalControlListbox lightSettingsList = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlListbox, IMyInteriorLight>("XOX_LightList");
            IMyTerminalControlButton  applyButton       = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyInteriorLight>("XOX_ApplyButton");

            lightSettingsList.ListContent = (terminalBlock, itemList, selectedItemList) =>
            {
                IMyInteriorLight terminalLight = terminalBlock as IMyInteriorLight;
                if (terminalLight == null)
                {
                    return;
                }

                itemList.Clear();
                itemList.Add(GetListBoxItem("Candle", 255, 147, 41));
                itemList.Add(GetListBoxItem("40W Tungsten", 255, 197, 143));
                itemList.Add(GetListBoxItem("100W Tungsten", 255, 214, 170));
                itemList.Add(GetListBoxItem("Halogen", 255, 241, 224));
                itemList.Add(GetListBoxItem("Carbon Arc", 255, 250, 244));
                itemList.Add(GetListBoxItem("High Noon Sun", 255, 255, 251));
                itemList.Add(GetListBoxItem("Direct Sunlight", 255, 255, 255));
                itemList.Add(GetListBoxItem("Overcast Sky", 201, 226, 255));
                itemList.Add(GetListBoxItem("Clear Blue Sky", 64, 156, 255));
                itemList.Add(GetListBoxItem("Warm Fluorescent", 255, 244, 229));
                itemList.Add(GetListBoxItem("Standard Fluorescent", 244, 255, 250));
                itemList.Add(GetListBoxItem("Cool White Fluorescent", 212, 235, 255));
                itemList.Add(GetListBoxItem("Full Spectrum Fluorescent", 255, 244, 242));
                itemList.Add(GetListBoxItem("Grow Light Fluorescent", 255, 239, 247));
                itemList.Add(GetListBoxItem("Black Light Fluorescent", 167, 0, 255));
                itemList.Add(GetListBoxItem("Mercury Vapor", 216, 247, 255));
                itemList.Add(GetListBoxItem("Sodium Vapor", 255, 209, 178));
                itemList.Add(GetListBoxItem("Metal Halide", 242, 252, 255));
                itemList.Add(GetListBoxItem("High Pressure Sodium", 255, 183, 76));
            };

            lightSettingsList.ItemSelected = (terminalBlock, selectedItemList) => {
                IMyInteriorLight terminalLight = terminalBlock as IMyInteriorLight;
                if (terminalLight == null)
                {
                    return;
                }



                RealisticLightSettings lightSettings = terminalLight?.GameLogic?.GetAs <RealisticLightSettings>();
                if (lightSettings == null)
                {
                    return;
                }

                var selectedItem = selectedItemList.FirstOrDefault();
                lightSettings.selectedLightPresetData = selectedItem?.UserData as LightPresetData;
                MyLog.Default.WriteLine($"Selected data is null? {lightSettings.selectedLightPresetData == null}");
            };

            lightSettingsList.Title = MyStringId.GetOrCompute("Presets");
            lightSettingsList.SupportsMultipleBlocks = true;
            lightSettingsList.Multiselect            = false;
            lightSettingsList.VisibleRowsCount       = 5;
            MyAPIGateway.TerminalControls.AddControl <IMyInteriorLight>(lightSettingsList);

            applyButton.Action = (terminalBlock) => {
                IMyInteriorLight terminalLight = terminalBlock as IMyInteriorLight;
                if (terminalLight == null)
                {
                    return;
                }

                RealisticLightSettings lightSettings = terminalLight?.GameLogic?.GetAs <RealisticLightSettings>();
                if (lightSettings == null)
                {
                    return;
                }

                if (lightSettings.selectedLightPresetData == null)
                {
                    return;
                }

                terminalLight.Falloff   = lightSettings.selectedLightPresetData.Falloff;
                terminalLight.Intensity = lightSettings.selectedLightPresetData.Intensity;
                terminalLight.Color     = lightSettings.selectedLightPresetData.LightColor;
            };
            applyButton.SupportsMultipleBlocks = true;
            applyButton.Title = MyStringId.GetOrCompute("Apply");
            MyAPIGateway.TerminalControls.AddControl <IMyInteriorLight>(applyButton);
        }