Exemple #1
0
        private Type GetProducedType <TBlock>()
        {
            Type producedType;

            // Originally I checked MyObjectBuilder_XX and mapped them to the class, but now I'm going to do ModAPI interfaces as well.  I left
            // the old method here, but it can be removed
            if (typeof(TBlock).IsInterface)
            {
                producedType = FindTerminalTypeFromInterface <TBlock>();
            }
            else
            {
                producedType = MyCubeBlockFactory.GetProducedType(typeof(TBlock));
            }

            return(producedType);
        }
        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");
            var convertToStationBtn = (MyGuiControlButton)m_infoPage.Controls.GetControlByName("ConvertToStationBtn");
            MyGuiControlList list   = (MyGuiControlList)m_infoPage.Controls.GetControlByName("InfoList");

            list.Controls.Clear();
            var setDestructibleBlocks = (MyGuiControlCheckbox)m_infoPage.Controls.GetControlByName("SetDestructibleBlocks");

            setDestructibleBlocks.Visible = MySession.Static.Settings.ScenarioEditMode || MySession.Static.IsScenario;
            setDestructibleBlocks.Enabled = MySession.Static.Settings.ScenarioEditMode;

            if (m_grid == null || m_grid.Physics == null)
            {
                convertBtn.Enabled          = false;
                convertToStationBtn.Enabled = false;

                RecreateServerLimitInfo(list);
                return;
            }

            if (!m_grid.IsStatic)
            {
                convertBtn.Enabled          = false;
                convertToStationBtn.Enabled = true;
            }
            else
            {
                convertBtn.Enabled          = true;
                convertToStationBtn.Enabled = false;
            }

            if (m_grid.GridSizeEnum == MyCubeSize.Small)
            {
                convertToStationBtn.Enabled = false;
            }

            if (!m_grid.BigOwners.Contains(MySession.Static.LocalPlayerId))
            {
                convertBtn.Enabled          = false;
                convertToStationBtn.Enabled = false;
            }

            setDestructibleBlocks.IsChecked        = m_grid.DestructibleBlocks;
            setDestructibleBlocks.IsCheckedChanged = setDestructibleBlocks_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 });
        }