private void RecreateControls()
        {
            Debug.Assert(m_infoPage != null, "Terminal page is null");
            if (m_infoPage == null)
                return;
            if (MyFakes.ENABLE_CENTER_OF_MASS)
            {
                var centerBtn = (MyGuiControlCheckbox)m_infoPage.Controls.GetControlByName("CenterBtn");
                centerBtn.IsChecked = MyCubeGrid.ShowCenterOfMass;
                centerBtn.IsCheckedChanged = centerBtn_IsCheckedChanged;

                var pivotBtn = (MyGuiControlCheckbox)m_infoPage.Controls.GetControlByName("PivotBtn");
                pivotBtn.IsChecked = MyCubeGrid.ShowGridPivot;
                pivotBtn.IsCheckedChanged = pivotBtn_IsCheckedChanged;
            }

            var showGravityGizmoBtn = (MyGuiControlCheckbox)m_infoPage.Controls.GetControlByName("ShowGravityGizmo");
            showGravityGizmoBtn.IsChecked = MyCubeGrid.ShowGravityGizmos;
            showGravityGizmoBtn.IsCheckedChanged = showGravityGizmos_IsCheckedChanged;

            var showSenzorGizmoBtn = (MyGuiControlCheckbox)m_infoPage.Controls.GetControlByName("ShowSenzorGizmo");
            showSenzorGizmoBtn.IsChecked = MyCubeGrid.ShowSenzorGizmos;
            showSenzorGizmoBtn.IsCheckedChanged = showSenzorGizmos_IsCheckedChanged;

            var showAntenaGizmoBtn = (MyGuiControlCheckbox)m_infoPage.Controls.GetControlByName("ShowAntenaGizmo");
            showAntenaGizmoBtn.IsChecked = MyCubeGrid.ShowAntennaGizmos;
            showAntenaGizmoBtn.IsCheckedChanged = showAntenaGizmos_IsCheckedChanged;

            var friendAntennaRange = (MyGuiControlSlider)m_infoPage.Controls.GetControlByName("FriendAntennaRange");
            friendAntennaRange.Value = MyHudMarkerRender.FriendAntennaRange;
            friendAntennaRange.ValueChanged += (MyGuiControlSlider s) => { MyHudMarkerRender.FriendAntennaRange = s.Value; };


            var enemyAntennaRange = (MyGuiControlSlider)m_infoPage.Controls.GetControlByName("EnemyAntennaRange");
            enemyAntennaRange.Value = MyHudMarkerRender.EnemyAntennaRange;
            enemyAntennaRange.ValueChanged += (MyGuiControlSlider s) => { MyHudMarkerRender.EnemyAntennaRange = s.Value; };

            var ownedAntennaRange = (MyGuiControlSlider)m_infoPage.Controls.GetControlByName("OwnedAntennaRange");
            ownedAntennaRange.Value = MyHudMarkerRender.OwnerAntennaRange;
            ownedAntennaRange.ValueChanged += (MyGuiControlSlider s) => { MyHudMarkerRender.OwnerAntennaRange = s.Value; };

            if (MyFakes.ENABLE_TERMINAL_PROPERTIES)
            {
                var renameShipLabel = (MyGuiControlLabel)m_infoPage.Controls.GetControlByName("RenameShipLabel");

                var renameShipBtn = (MyGuiControlButton)m_infoPage.Controls.GetControlByName("RenameShipButton");

                var renameShipText = (MyGuiControlTextbox)m_infoPage.Controls.GetControlByName("RenameShipText");
                if(renameShipText != null && m_grid != null)
                    renameShipText.Text = m_grid.DisplayName;

                var showRenameShip = IsPlayerOwner(m_grid);
                renameShipLabel.Visible = showRenameShip;
                renameShipBtn.Visible = showRenameShip;
                renameShipText.Visible = showRenameShip;
            }

            var convertBtn = (MyGuiControlButton)m_infoPage.Controls.GetControlByName("ConvertBtn");
            MyGuiControlList list = (MyGuiControlList)m_infoPage.Controls.GetControlByName("InfoList");
            list.Controls.Clear();

            if (m_grid == null || m_grid.Physics == null)
            {
                convertBtn.Enabled = false;
                MyGuiControlLabel noShip = new MyGuiControlLabel(text: MyTexts.GetString(MySpaceTexts.ScreenTerminalError_ShipNotConnected), font: Common.MyFontEnum.Red);
                list.Controls.Add(noShip);
                return;
            }

            if (!m_grid.IsStatic || m_grid.MarkedForClose)
                convertBtn.Enabled = false;

            var setDestructibleBlocks = (MyGuiControlCheckbox)m_infoPage.Controls.GetControlByName("SetDestructibleBlocks");
            setDestructibleBlocks.IsChecked = m_grid.DestructibleBlocks;
            setDestructibleBlocks.Visible = MySession.Static.Settings.ScenarioEditMode || MySession.Static.IsScenario;
            setDestructibleBlocks.Enabled = MySession.Static.Settings.ScenarioEditMode;
            setDestructibleBlocks.IsCheckedChanged = setDestructibleBlocksBtn_IsCheckedChanged;

            int gravityCounter = 0;
            if (m_grid.BlocksCounters.ContainsKey(typeof(MyObjectBuilder_GravityGenerator)))
                gravityCounter = m_grid.BlocksCounters[typeof(MyObjectBuilder_GravityGenerator)];
            int massCounter = 0;
            if (m_grid.BlocksCounters.ContainsKey(typeof(MyObjectBuilder_VirtualMass)))
                massCounter = m_grid.BlocksCounters[typeof(MyObjectBuilder_VirtualMass)];
            int lightCounter = 0;
            if (m_grid.BlocksCounters.ContainsKey(typeof(MyObjectBuilder_InteriorLight)))
                lightCounter = m_grid.BlocksCounters[typeof(MyObjectBuilder_InteriorLight)];
            var conveyorCounter = 0;
            foreach (var key in m_grid.BlocksCounters.Keys)
            {
                Type blockType = MyCubeBlockFactory.GetProducedType(key);
                if (typeof(IMyConveyorSegmentBlock).IsAssignableFrom(blockType) || typeof(IMyConveyorEndpointBlock).IsAssignableFrom(blockType))
                    conveyorCounter += m_grid.BlocksCounters[key];
            }
            int polygonCounter = 0;
            foreach (var block in m_grid.GetBlocks())
            {
                if (block.FatBlock != null)
                {
                    polygonCounter += block.FatBlock.Model.GetTrianglesCount();
                }
            }
            foreach (var cell in m_grid.RenderData.Cells.Values)
            {
                foreach (var part in cell.CubeParts)
                {
                    polygonCounter += part.Model.GetTrianglesCount();
                }
            }

	        int thrustCount = 0;
	        var thrustComp = m_grid.Components.Get<MyEntityThrustComponent>();
	        if (thrustComp != null)
		        thrustCount = thrustComp.ThrustCount;
	        MyGuiControlLabel thrustCountLabel = new MyGuiControlLabel(text: new StringBuilder().AppendStringBuilder(MyTexts.Get(MySpaceTexts.TerminalTab_Info_Thrusters)).AppendInt32(thrustCount).ToString());

            MyGuiControlLabel polygonCount = new MyGuiControlLabel(text: new StringBuilder().AppendStringBuilder(MyTexts.Get(MySpaceTexts.TerminalTab_Info_Triangles)).AppendInt32(polygonCounter).ToString());
            polygonCount.SetToolTip(MySpaceTexts.TerminalTab_Info_TrianglesTooltip);
            MyGuiControlLabel cubeCount = new MyGuiControlLabel(text: new StringBuilder().AppendStringBuilder(MyTexts.Get(MySpaceTexts.TerminalTab_Info_Blocks)).AppendInt32(m_grid.GetBlocks().Count).ToString());
            cubeCount.SetToolTip(MySpaceTexts.TerminalTab_Info_BlocksTooltip);
            MyGuiControlLabel blockCount = new MyGuiControlLabel(text: new StringBuilder().AppendStringBuilder(MyTexts.Get(MySpaceTexts.TerminalTab_Info_NonArmor)).AppendInt32(m_grid.Hierarchy.Children.Count).ToString());
            MyGuiControlLabel lightCount = new MyGuiControlLabel(text: new StringBuilder().Clear().AppendStringBuilder(MyTexts.Get(MySpaceTexts.TerminalTab_Info_Lights)).AppendInt32(lightCounter).ToString());
            MyGuiControlLabel reflectorCount = new MyGuiControlLabel(text: new StringBuilder().AppendStringBuilder(MyTexts.Get(MySpaceTexts.TerminalTab_Info_Reflectors)).AppendInt32(m_grid.GridSystems.ReflectorLightSystem.ReflectorCount).ToString());
            //MyGuiControlLabel wheelCount = new MyGuiControlLabel(text: new StringBuilder().AppendStringBuilder(MyTexts.Get(MySpaceTexts.TerminalTab_Info_Rotors)).AppendInt32(m_grid.WheelSystem.WheelCount));
            MyGuiControlLabel gravityCount = new MyGuiControlLabel(text: new StringBuilder().AppendStringBuilder(MyTexts.Get(MySpaceTexts.TerminalTab_Info_GravGens)).AppendInt32(gravityCounter).ToString());
            MyGuiControlLabel massCount = new MyGuiControlLabel(text: new StringBuilder().AppendStringBuilder(MyTexts.Get(MySpaceTexts.TerminalTab_Info_VirtualMass)).AppendInt32(massCounter).ToString());
            MyGuiControlLabel conveyorCount = new MyGuiControlLabel(text: new StringBuilder().AppendStringBuilder(MyTexts.Get(MySpaceTexts.TerminalTab_Info_Conveyors)).AppendInt32(conveyorCounter).ToString());
			var mainCockpit = m_grid.MainCockpit as MyShipController;
			MyCharacter pilot = null;
			if (mainCockpit != null)
				pilot = mainCockpit.Pilot;
			MyGuiControlLabel gridMass = new MyGuiControlLabel(text: new StringBuilder().AppendStringBuilder(MyTexts.Get(MySpaceTexts.TerminalTab_Info_GridMass)).AppendInt32(m_grid.GetCurrentMass(pilot)).ToString());
			list.InitControls(new MyGuiControlBase[] { cubeCount, blockCount, conveyorCount, thrustCountLabel, lightCount, reflectorCount, gravityCount, massCount, polygonCount, gridMass });
        }
        private void CreateGpsPageControls(MyGuiControlTabPage gpsPage)
        {
            gpsPage.Name      = "PageIns";
            gpsPage.TextEnum = MySpaceTexts.TerminalTab_GPS;
            gpsPage.TextScale = 0.9f;
            var spacingH = 0.01f;
            var spacingV = 0.01f;
            var buttonSize = new Vector2(0.29f, 0.052f);
            var smallerBtn = new Vector2(0.13f, 0.04f);
            var left = -0.4625f;
            var top = -0.325f;

            var gpsBlockSearch = new MyGuiControlTextbox()
            {
                Position = new Vector2(left,top),
                Size = new Vector2(0.29f, 0.052f),
                Name = "SearchIns",
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP
            };

            var gpsBlockSearchClear = new MyGuiControlButton()
            {
                Position = new Vector2(left+gpsBlockSearch.Size.X, top+0.01f),
                Size = new Vector2(0.045f, 0.05666667f),
                Name = "SearchInsClear",
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP,
                VisualStyle = MyGuiControlButtonStyleEnum.Close,
                ActivateOnMouseRelease = true
            };
            top += gpsBlockSearch.Size.Y + spacingV;

            var gpsBlockTable = new MyGuiControlTable()
            {
                Position = new Vector2(left,top),
                Size = new Vector2(0.29f, 0.5f),
                Name = "TableINS",
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP,
                ColumnsCount = 1,
                VisibleRowsCount = 14,
                HeaderVisible=false
            };
            gpsBlockTable.SetCustomColumnWidths(new float[1]{1});
            top += gpsBlockTable.Size.Y + spacingV;

            //LEFT SIDE BUTTONS:
            var gpsButtonAdd = new MyGuiControlButton(
                position: new Vector2(left,top),
                visualStyle: MyGuiControlButtonStyleEnum.Rectangular,
                size: new Vector2(140f, 48f) / MyGuiConstants.GUI_OPTIMAL_SIZE,
                text: MyTexts.Get(MySpaceTexts.TerminalTab_GPS_Add),
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP)
            {
                Name = "buttonAdd"
            };
            var gpsButtonDelete = new MyGuiControlButton(
                position: new Vector2(left,top +gpsButtonAdd.Size.Y+spacingV),
                visualStyle: MyGuiControlButtonStyleEnum.Rectangular,
                size: new Vector2(140f, 48f) / MyGuiConstants.GUI_OPTIMAL_SIZE,
                text: MyTexts.Get(MySpaceTexts.TerminalTab_GPS_Delete),
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP)
            {
                Name = "buttonDelete"
            };
            var gpsButtonFromCurrent = new MyGuiControlButton(
                position: new Vector2(left+gpsButtonAdd.Size.X+spacingH,top),
                visualStyle: MyGuiControlButtonStyleEnum.Rectangular,
                size: new Vector2(310f, 48f) / MyGuiConstants.GUI_OPTIMAL_SIZE,
                text: MyTexts.Get(MySpaceTexts.TerminalTab_GPS_NewFromCurrent),
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP)
            {
                Name = "buttonFromCurrent"
            };
            var gpsButtonFromClipboard = new MyGuiControlButton(
                position: new Vector2(left + gpsButtonAdd.Size.X + spacingH, top + gpsButtonAdd.Size.Y + spacingV),
                visualStyle: MyGuiControlButtonStyleEnum.Rectangular,
                size: new Vector2(310f, 48f) / MyGuiConstants.GUI_OPTIMAL_SIZE,
                text: MyTexts.Get(MySpaceTexts.TerminalTab_GPS_NewFromClipboard),
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP)
            {
                Name = "buttonFromClipboard"
            };


            gpsPage.Controls.Add(gpsBlockSearch);
            gpsPage.Controls.Add(gpsBlockSearchClear);
            gpsPage.Controls.Add(gpsBlockTable);
            gpsPage.Controls.Add(gpsButtonAdd);
            gpsPage.Controls.Add(gpsButtonDelete);
            gpsPage.Controls.Add(gpsButtonFromCurrent);
            gpsPage.Controls.Add(gpsButtonFromClipboard);


            //RIGHT SIDE:
            left = -0.15f;
            top = -0.325f;
            var gpsComposite = new MyGuiControlCompositePanel()
            {
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP,
                Position = new Vector2(left, top),
                Size = new Vector2(0.6f, 0.39f),
                Name = "compositeIns"
            };
            left += spacingH;
            top += spacingV+0.05f;

            var gpsNameLabel = new MyGuiControlLabel(
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER,
                position: new Vector2(left, top),
                size: new Vector2(0.4f, 0.035f)
            ) { Name = "labelInsName",
                Text = MyTexts.Get(MySpaceTexts.TerminalTab_GPS_Name).ToString()
            };
            var gpsNamePanel = new MyGuiControlTextbox(maxLength:32)
            {
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER,
                Position = new Vector2(left + spacingH + gpsNameLabel.Size.X, top),
                Size = new Vector2(gpsComposite.Size.X - spacingH - gpsNameLabel.Size.X - spacingH -0.01f, 0.035f),
                Name = "panelInsName"
            };

            top += gpsNamePanel.Size.Y + (2f * spacingV);

            var size = gpsNamePanel.Size - new Vector2(0.14f, 0.01f);

            var gpsDescLabel = new MyGuiControlLabel(
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER,
                position: new Vector2(left, top),
                //size: insNamePanel.Size - new Vector2(0.01f, 0.01f)
                size : new Vector2(gpsComposite.Size.X - 0.012f, 0.035f)
            ){
                Name = "labelInsDesc",
                Text = MyTexts.Get(MySpaceTexts.TerminalTab_GPS_Description).ToString()
            };
            top += gpsDescLabel.Size.Y + spacingV;

            var gpsDescText = new MyGuiControlTextbox(
                position: new Vector2(left, top),
                maxLength:255
            )
            {
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER,
                Name = "textInsDesc",
                Size= new Vector2(gpsComposite.Size.X - 2*spacingH, 0.035f)
            };
            top += gpsDescText.Size.Y + 2f * spacingV;

            //X,Y,Z:
            var gpsLabelX = new MyGuiControlLabel(
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER,
                position: new Vector2(left, top),
                size : new Vector2(0.01f, 0.035f),
                text : MyTexts.Get(MySpaceTexts.TerminalTab_GPS_X).ToString()
            )
            {
                Name = "labelInsX",
            };
            left += gpsLabelX.Size.X+spacingH;
            var gpsXCoord = new MyGuiControlTextbox()
            {
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER,
                Position = new Vector2(left, top),
                Size = new Vector2((gpsComposite.Size.X - spacingH )/ 3 - 2 * spacingH - gpsLabelX.Size.X, 0.035f),
                Name = "textInsX"
            };
            left += gpsXCoord.Size.X + spacingH;

            var gpsLabelY = new MyGuiControlLabel(
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER,
                position: new Vector2(left, top),
                //size: new Vector2(0.01f, 0.035f),
                size : new Vector2(gpsComposite.Size.X - 0.012f, 0.035f),
                text: MyTexts.Get(MySpaceTexts.TerminalTab_GPS_Y).ToString()
                //size: new Vector2(0.4f, 0.035f)
            )
            {
                Name = "labelInsY"
            };
            left += gpsLabelX.Size.X + spacingH;
            var gpsYCoord = new MyGuiControlTextbox()
            {
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER,
                Position = new Vector2(left, top),
                Size = new Vector2((gpsComposite.Size.X - spacingH) / 3 - 2 * spacingH - gpsLabelX.Size.X, 0.035f),
                Name = "textInsY"
            };
            left += gpsYCoord.Size.X + spacingH;

            var gpsLabelZ = new MyGuiControlLabel(
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER,
                position: new Vector2(left, top),
                size: new Vector2(0.01f, 0.035f),
                text: MyTexts.Get(MySpaceTexts.TerminalTab_GPS_Z).ToString()
                //size: new Vector2(0.4f, 0.035f)
            )
            {
                Name = "labelInsZ",
            };
            left += gpsLabelX.Size.X + spacingH;
            var gpsZCoord = new MyGuiControlTextbox()
            {
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER,
                Position = new Vector2(left, top),
                Size = new Vector2((gpsComposite.Size.X - spacingH) / 3 - 2 * spacingH - gpsLabelX.Size.X, 0.035f),
                Name = "textInsZ"
            };
            top += gpsNamePanel.Size.Y + (2f * spacingV);

            //BUTTONS:
            left = spacingH-0.15f;

            //SHOW ON HUD & COPY TO CLIPBOARD:
            var checkGpsShowOnHud = new MyGuiControlCheckbox(
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER,
                position: new Vector2(left, top)
            ) { Name = "checkInsShowOnHud" };

            var labelGpsShowOnHud = new MyGuiControlLabel(
             originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER,
             position: new Vector2(left+ checkGpsShowOnHud.Size.X + spacingH, top),
             size: checkGpsShowOnHud.Size - new Vector2(0.01f, 0.01f)
            )
            {
                Name = "labelInsShowOnHud",
                Text = MyTexts.Get(MySpaceTexts.TerminalTab_GPS_ShowOnHud).ToString()
            };

            var toClipboardButton = new MyGuiControlButton(
                position: new Vector2(gpsComposite.Position.X+gpsComposite.Size.X-spacingH, top),
                visualStyle: MyGuiControlButtonStyleEnum.Rectangular,
                size: new Vector2(300f, 48f) / MyGuiConstants.GUI_OPTIMAL_SIZE,
                text: MyTexts.Get(MySpaceTexts.TerminalTab_GPS_CopyToClipboard),
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER)
            {
                Name = "buttonToClipboard"
            };

            top += toClipboardButton.Size.Y * 1.1f;
            var checkGpsAlwaysVisible = new MyGuiControlCheckbox(
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER,
                position: new Vector2(left, top)
            )
            {
                Name = "checkInsAlwaysVisible",
            };
            checkGpsAlwaysVisible.SetToolTip(MySpaceTexts.TerminalTab_GPS_AlwaysVisible_Tooltip);

            var labelGpsAlwaysVisible = new MyGuiControlLabel(
             originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER,
             position: new Vector2(left + checkGpsShowOnHud.Size.X + spacingH, top),
             size: checkGpsShowOnHud.Size - new Vector2(0.01f, 0.01f)
            )
            {
                Name = "labelInsAlwaysVisible",
                Text = MyTexts.Get(MySpaceTexts.TerminalTab_GPS_AlwaysVisible).ToString()
            };
            labelGpsAlwaysVisible.SetToolTip(MySpaceTexts.TerminalTab_GPS_AlwaysVisible_Tooltip);

            top += checkGpsShowOnHud.Size.Y;
            var labelIllegalDataWarning = new MyGuiControlLabel(
             originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER,
             position: new Vector2(left + spacingH, top),
             size: new Vector2(gpsComposite.Size.X - 0.012f, 0.035f)
            )
            {
                Name = "TerminalTab_GPS_SaveWarning",
                Text = MyTexts.Get(MySpaceTexts.TerminalTab_GPS_SaveWarning).ToString(),
                ColorMask = Color.Red.ToVector4()
            };

            gpsPage.Controls.Add(gpsComposite);
            gpsPage.Controls.Add(gpsNamePanel);
            gpsPage.Controls.Add(gpsNameLabel);
            gpsPage.Controls.Add(gpsDescLabel);
            gpsPage.Controls.Add(gpsDescText);

            gpsPage.Controls.Add(gpsLabelX);
            gpsPage.Controls.Add(gpsXCoord);
            gpsPage.Controls.Add(gpsLabelY);
            gpsPage.Controls.Add(gpsYCoord);
            gpsPage.Controls.Add(gpsLabelZ);
            gpsPage.Controls.Add(gpsZCoord);

            gpsPage.Controls.Add(toClipboardButton);

            gpsPage.Controls.Add(checkGpsShowOnHud);
            gpsPage.Controls.Add(labelGpsShowOnHud);

            gpsPage.Controls.Add(labelIllegalDataWarning);

            gpsPage.Controls.Add(checkGpsAlwaysVisible);
            gpsPage.Controls.Add(labelGpsAlwaysVisible);
        }
        public void Init(IMyGuiControlsParent controlsParent)
        {
            m_controlsParent = controlsParent;
            RefreshUserInfo();

            m_tableFactions = (MyGuiControlTable)controlsParent.Controls.GetControlByName("FactionsTable");
            m_tableFactions.SetColumnComparison(0, (a, b) => ((StringBuilder)a.UserData).CompareToIgnoreCase((StringBuilder)b.UserData));
            m_tableFactions.SetColumnComparison(1, (a, b) => ((StringBuilder)a.UserData).CompareToIgnoreCase((StringBuilder)b.UserData));
            m_tableFactions.ItemSelected += OnFactionsTableItemSelected;
            RefreshTableFactions();
            m_tableFactions.SortByColumn(1);

            m_buttonCreate      = (MyGuiControlButton)controlsParent.Controls.GetControlByName("buttonCreate");
            m_buttonJoin        = (MyGuiControlButton)controlsParent.Controls.GetControlByName("buttonJoin");
            m_buttonCancelJoin  = (MyGuiControlButton)controlsParent.Controls.GetControlByName("buttonCancelJoin");
            m_buttonLeave       = (MyGuiControlButton)controlsParent.Controls.GetControlByName("buttonLeave");
            m_buttonSendPeace   = (MyGuiControlButton)controlsParent.Controls.GetControlByName("buttonSendPeace");
            m_buttonCancelPeace = (MyGuiControlButton)controlsParent.Controls.GetControlByName("buttonCancelPeace");
            m_buttonAcceptPeace = (MyGuiControlButton)controlsParent.Controls.GetControlByName("buttonAcceptPeace");
            m_buttonMakeEnemy   = (MyGuiControlButton)controlsParent.Controls.GetControlByName("buttonEnemy");

            m_buttonCreate.ShowTooltipWhenDisabled = true;

            m_buttonCreate.TextEnum      = MySpaceTexts.TerminalTab_Factions_Create;
            m_buttonJoin.TextEnum        = MySpaceTexts.TerminalTab_Factions_Join;
            m_buttonCancelJoin.TextEnum  = MySpaceTexts.TerminalTab_Factions_CancelJoin;
            m_buttonLeave.TextEnum       = MySpaceTexts.TerminalTab_Factions_Leave;
            m_buttonSendPeace.TextEnum   = MySpaceTexts.TerminalTab_Factions_Friend;
            m_buttonCancelPeace.TextEnum = MySpaceTexts.TerminalTab_Factions_CancelPeaceRequest;
            m_buttonAcceptPeace.TextEnum = MySpaceTexts.TerminalTab_Factions_AcceptPeaceRequest;
            m_buttonMakeEnemy.TextEnum   = MySpaceTexts.TerminalTab_Factions_Enemy;


            m_buttonJoin.SetToolTip(MySpaceTexts.TerminalTab_Factions_JoinToolTip);
            m_buttonSendPeace.SetToolTip(MySpaceTexts.TerminalTab_Factions_FriendToolTip);

            m_buttonCreate.ButtonClicked      += OnCreateClicked;
            m_buttonJoin.ButtonClicked        += OnJoinClicked;
            m_buttonCancelJoin.ButtonClicked  += OnCancelJoinClicked;
            m_buttonLeave.ButtonClicked       += OnLeaveClicked;
            m_buttonSendPeace.ButtonClicked   += OnFriendClicked;
            m_buttonCancelPeace.ButtonClicked += OnCancelPeaceRequestClicked;
            m_buttonAcceptPeace.ButtonClicked += OnAcceptFriendClicked;
            m_buttonMakeEnemy.ButtonClicked   += OnEnemyClicked;

            // RIGHT SIDE
            m_labelFactionName      = (MyGuiControlLabel)controlsParent.Controls.GetControlByName("labelFactionName");
            m_labelFactionDesc      = (MyGuiControlLabel)controlsParent.Controls.GetControlByName("labelFactionDesc");
            m_labelFactionPriv      = (MyGuiControlLabel)controlsParent.Controls.GetControlByName("labelFactionPrivate");
            m_labelMembers          = (MyGuiControlLabel)controlsParent.Controls.GetControlByName("labelFactionMembers");
            m_labelAutoAcceptMember = (MyGuiControlLabel)controlsParent.Controls.GetControlByName("labelFactionMembersAcceptEveryone");
            m_labelAutoAcceptPeace  = (MyGuiControlLabel)controlsParent.Controls.GetControlByName("labelFactionMembersAcceptPeace");

            m_labelFactionDesc.Text      = MyTexts.Get(MySpaceTexts.TerminalTab_Factions_CreateFactionDescription).ToString();
            m_labelFactionPriv.Text      = MyTexts.Get(MySpaceTexts.TerminalTab_Factions_Private).ToString();
            m_labelMembers.Text          = MyTexts.Get(MySpaceTexts.TerminalTab_Factions_Members).ToString();
            m_labelAutoAcceptMember.Text = MyTexts.Get(MySpaceTexts.TerminalTab_Factions_AutoAccept).ToString();
            m_labelAutoAcceptPeace.Text  = MyTexts.Get(MySpaceTexts.TerminalTab_Factions_AutoAcceptRequest).ToString();

            m_labelAutoAcceptMember.SetToolTip(MySpaceTexts.TerminalTab_Factions_AutoAcceptToolTip);
            m_labelAutoAcceptPeace.SetToolTip(MySpaceTexts.TerminalTab_Factions_AutoAcceptRequestToolTip);

            m_textFactionDesc = (MyGuiControlMultilineText)controlsParent.Controls.GetControlByName("textFactionDesc");
            m_textFactionPriv = (MyGuiControlMultilineText)controlsParent.Controls.GetControlByName("textFactionPrivate");

            m_textFactionDesc.BackgroundTexture = MyGuiConstants.TEXTURE_HIGHLIGHT_DARK;
            m_textFactionPriv.BackgroundTexture = MyGuiConstants.TEXTURE_HIGHLIGHT_DARK;

            m_tableMembers = (MyGuiControlTable)controlsParent.Controls.GetControlByName("tableMembers");
            m_tableMembers.SetColumnComparison(1, (a, b) => ((int)((MyMemberComparerEnum)a.UserData)).CompareTo((int)((MyMemberComparerEnum)b.UserData)));
            m_tableMembers.ItemSelected += OnTableItemSelected;

            m_checkAutoAcceptMember = (MyGuiControlCheckbox)controlsParent.Controls.GetControlByName("checkFactionMembersAcceptEveryone");
            m_checkAutoAcceptPeace  = (MyGuiControlCheckbox)controlsParent.Controls.GetControlByName("checkFactionMembersAcceptPeace");

            m_checkAutoAcceptMember.SetToolTip(MySpaceTexts.TerminalTab_Factions_AutoAcceptToolTip);
            m_checkAutoAcceptPeace.SetToolTip(MySpaceTexts.TerminalTab_Factions_AutoAcceptRequestToolTip);

            m_checkAutoAcceptMember.IsCheckedChanged += OnAutoAcceptChanged;
            m_checkAutoAcceptPeace.IsCheckedChanged  += OnAutoAcceptChanged;

            m_buttonEdit       = (MyGuiControlButton)controlsParent.Controls.GetControlByName("buttonEdit");
            m_buttonPromote    = (MyGuiControlButton)controlsParent.Controls.GetControlByName("buttonPromote");
            m_buttonKick       = (MyGuiControlButton)controlsParent.Controls.GetControlByName("buttonKick");
            m_buttonAcceptJoin = (MyGuiControlButton)controlsParent.Controls.GetControlByName("buttonAcceptJoin");
            m_buttonDemote     = (MyGuiControlButton)controlsParent.Controls.GetControlByName("buttonDemote");
            m_buttonAddNpc = (MyGuiControlButton)controlsParent.Controls.GetControlByName("buttonAddNpc");

            m_buttonEdit.TextEnum       = MyCommonTexts.Edit;
            m_buttonPromote.TextEnum    = MyCommonTexts.Promote;
            m_buttonKick.TextEnum       = MyCommonTexts.Kick;
            m_buttonAcceptJoin.TextEnum = MyCommonTexts.Accept;
            m_buttonDemote.TextEnum     = MyCommonTexts.Demote;
            m_buttonAddNpc.TextEnum = MySpaceTexts.AddNpcToFaction;
            m_buttonAddNpc.SetToolTip(MySpaceTexts.AddNpcToFactionHelp);

            m_buttonEdit.ButtonClicked       += OnCreateClicked;
            m_buttonPromote.ButtonClicked    += OnPromotePlayerClicked;
            m_buttonKick.ButtonClicked       += OnKickPlayerClicked;
            m_buttonAcceptJoin.ButtonClicked += OnAcceptJoinClicked;
            m_buttonDemote.ButtonClicked     += OnDemoteClicked;
            m_buttonAddNpc.ButtonClicked += OnNewNpcClicked;

            MySession.Static.Factions.FactionCreated           += OnFactionCreated;
            MySession.Static.Factions.FactionEdited            += OnFactionEdited;
            MySession.Static.Factions.FactionStateChanged      += OnFactionsStateChanged;
            MySession.Static.Factions.FactionAutoAcceptChanged += OnAutoAcceptChanged;

            Refresh();
        }
        public override void RecreateControls(bool constructor)
        {
            base.RecreateControls(constructor);

            var left       = -0.23f;
            var top        = -0.23f;
            var spacingV   =  0.045f;
            var buttonSize = new Vector2(0.29f, 0.052f);

            var composite = new MyGuiControlCompositePanel()
            {
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP,
                Position = new Vector2(left, top),
                Size = new Vector2(0.46f, 0.46f)
            };
            left += 0.005f;
            top  += 0.007f;

            var panel = new MyGuiControlPanel()
            {
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP,
                Position = new Vector2(left, top),
                Size = new Vector2(0.451f, 0.038f),
                BackgroundTexture = MyGuiConstants.TEXTURE_HIGHLIGHT_DARK
            };
            left += 0.005f;
            top  += 0.003f;

            // LABELS
            var headerText = MyTexts.GetString((m_editFaction == null) ? MySpaceTexts.TerminalTab_Factions_CreateFaction : MySpaceTexts.TerminalTab_Factions_EditFaction);
            var headerLabel = new MyGuiControlLabel(originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP, size: buttonSize, position: new Vector2(left, top), text: headerText);
            top += 0.01f;
            var shortcutLabel = new MyGuiControlLabel(originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP, size: buttonSize, position: new Vector2(left, top + spacingV), text: MyTexts.GetString(MySpaceTexts.TerminalTab_Factions_CreateFactionTag));
            var nameLabel = new MyGuiControlLabel(originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP, size: buttonSize, position: new Vector2(left, top + 2f * spacingV), text: MyTexts.GetString(MySpaceTexts.TerminalTab_Factions_CreateFactionName));
            var descLabel = new MyGuiControlLabel(originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP, size: buttonSize, position: new Vector2(left, top + 3f * spacingV), text: MyTexts.GetString(MySpaceTexts.TerminalTab_Factions_CreateFactionDescription));
            var secretLabel = new MyGuiControlLabel(originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP, size: buttonSize, position: new Vector2(left, top + 4f * spacingV), text: MyTexts.GetString(MySpaceTexts.TerminalTab_Factions_CreateFactionPrivateInfo));

            shortcutLabel.SetToolTip(MySpaceTexts.TerminalTab_Factions_CreateFactionTagToolTip);
            secretLabel.SetToolTip(MySpaceTexts.TerminalTab_Factions_CreateFactionPrivateInfoToolTip);

            Controls.Add(composite);
            Controls.Add(panel);
            Controls.Add(headerLabel);
            Controls.Add(shortcutLabel);
            Controls.Add(nameLabel);
            Controls.Add(descLabel);
            Controls.Add(secretLabel);

            // INPUTS
            var iLeft =  0.06f;
            var iTop  = -0.15f;

            m_shortcut = new MyGuiControlTextbox(position: new Vector2(iLeft, iTop),                 maxLength: 3,   defaultText: (m_editFaction != null) ? m_editFaction.Tag : "");
            m_name     = new MyGuiControlTextbox(position: new Vector2(iLeft, iTop + spacingV),      maxLength: 64,  defaultText: (m_editFaction != null) ? m_editFaction.Name : "");
            m_desc     = new MyGuiControlTextbox(position: new Vector2(iLeft, iTop + 2f * spacingV), maxLength: 512, defaultText: (m_editFaction != null) ? m_editFaction.Description : "");
            m_privInfo = new MyGuiControlTextbox(position: new Vector2(iLeft, iTop + 3f * spacingV), maxLength: 512, defaultText: (m_editFaction != null) ? m_editFaction.PrivateInfo : "");

            m_shortcut.SetToolTip(MySpaceTexts.TerminalTab_Factions_CreateFactionTagToolTip);
            m_privInfo.SetToolTip(MySpaceTexts.TerminalTab_Factions_CreateFactionPrivateInfoToolTip);

            Controls.Add(m_shortcut);
            Controls.Add(m_name);
            Controls.Add(m_desc);
            Controls.Add(m_privInfo);

            // BUTTONS
            top  -= 0.003f;

            Controls.Add(new MyGuiControlButton(originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM, size: buttonSize, position: new Vector2(left, -top), text: MyTexts.Get(MySpaceTexts.Ok), onButtonClick: OnOkClick));
            Controls.Add(new MyGuiControlButton(originAlign: MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM, size: buttonSize, position: new Vector2(-left, -top), text: MyTexts.Get(MySpaceTexts.Cancel), onButtonClick: OnCancelClick));
        }