示例#1
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));
        }