Ejemplo n.º 1
0
        public MyGuiScreenTriggerBlockDestroyed(MyTrigger trig) : base(trig, new Vector2(0.5f, 0.8f))
        {
            trigger = (MyTriggerBlockDestroyed)trig;
            AddCaption(MySpaceTexts.GuiTriggerCaptionBlockDestroyed);

            var layout = new MyLayoutTable(this);

            layout.SetColumnWidthsNormalized(10, 30, 3, 30, 10);
            layout.SetRowHeightsNormalized(20, 35, 6, 4, 4, 5, 33);

            m_selectedBlocks = new MyGuiControlTable();
            m_selectedBlocks.VisibleRowsCount = 8;
            m_selectedBlocks.ColumnsCount     = 1;
            m_selectedBlocks.SetCustomColumnWidths(new float[] { 1 });
            m_selectedBlocks.SetColumnName(0, MyTexts.Get(MySpaceTexts.GuiTriggerBlockDestroyed_ColumnName));

            layout.AddWithSize(m_selectedBlocks, MyAlignH.Left, MyAlignV.Top, 1, 1, rowSpan: 1, colSpan: 3);

            m_buttonPaste = new MyGuiControlButton(
                text: MyTexts.Get(MySpaceTexts.GuiTriggerPasteBlocks),
                visualStyle: MyGuiControlButtonStyleEnum.Rectangular,
                onButtonClick: OnPasteButtonClick
                );
            m_buttonPaste.SetToolTip(MySpaceTexts.GuiTriggerPasteBlocksTooltip);
            layout.AddWithSize(m_buttonPaste, MyAlignH.Left, MyAlignV.Top, 2, 1, rowSpan: 1, colSpan: 1);

            m_buttonDelete = new MyGuiControlButton(
                text: MyTexts.Get(MySpaceTexts.GuiTriggerDeleteBlocks),
                visualStyle: MyGuiControlButtonStyleEnum.Rectangular,
                onButtonClick: OnDeleteButtonClick);
            layout.AddWithSize(m_buttonDelete, MyAlignH.Left, MyAlignV.Top, 2, 3, rowSpan: 1, colSpan: 1);

            m_labelSingleMessage = new MyGuiControlLabel(
                text: MyTexts.Get(MySpaceTexts.GuiTriggerBlockDestroyedSingleMessage).ToString()
                );
            layout.AddWithSize(m_labelSingleMessage, MyAlignH.Left, MyAlignV.Top, 3, 1, rowSpan: 1, colSpan: 1);
            m_textboxSingleMessage = new MyGuiControlTextbox(
                defaultText: trigger.SingleMessage,
                maxLength: 85);
            layout.AddWithSize(m_textboxSingleMessage, MyAlignH.Left, MyAlignV.Top, 4, 1, rowSpan: 1, colSpan: 3);

            foreach (var block in trigger.Blocks)
            {
                AddRow(block.Key);
            }
            m_tempSb.Clear().Append(trigger.SingleMessage);
            m_textboxSingleMessage.SetText(m_tempSb);
        }
        public override void RecreateControls(bool constructor)
        {
            base.RecreateControls(constructor);
            var layout = new MyLayoutTable(this);

            layout.SetColumnWidthsNormalized(50, 250, 150, 250, 50);
            layout.SetRowHeightsNormalized(50, 450, 30, 50);

            m_mainLabel = new MyGuiControlLabel(text: MyTexts.GetString(MySpaceTexts.GuiScenarioDescription), originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER);
            layout.AddWithSize(m_mainLabel, MyAlignH.Left, MyAlignV.Center, 0, 1, colSpan: 3);
            //BRIEFING:
            m_descriptionBox = new MyGuiControlMultilineText(
                position: new Vector2(0.0f, 0.0f),
                size: new Vector2(0.2f, 0.2f),
                textBoxAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP,
                selectable: false);
            layout.AddWithSize(m_descriptionBox, MyAlignH.Left, MyAlignV.Top, 1, 1, rowSpan: 1, colSpan: 3);

            m_okButton = new MyGuiControlButton(text: MyTexts.Get(MyCommonTexts.Ok), visualStyle: MyGuiControlButtonStyleEnum.Rectangular, highlightType: MyGuiControlHighlightType.WHEN_ACTIVE,
                                                size: new Vector2(200, 48f) / MyGuiConstants.GUI_OPTIMAL_SIZE, onButtonClick: OnOkClicked);
            layout.AddWithSize(m_okButton, MyAlignH.Left, MyAlignV.Top, 2, 2);
        }
        public override void RecreateControls(bool constructor)
        {
            base.RecreateControls(constructor);
            var layout = new MyLayoutTable(this);

            layout.SetColumnWidthsNormalized(50, 300, 300, 300, 300, 300, 50);
            layout.SetRowHeightsNormalized(50, 450, 70, 70, 70, 400, 70, 70, 50);

            //BRIEFING:
            MyGuiControlParent briefing = new MyGuiControlParent();
            var briefingScrollableArea  = new MyGuiControlScrollablePanel(
                scrolledControl: briefing)
            {
                Name = "BriefingScrollableArea",
                ScrollbarVEnabled   = true,
                OriginAlign         = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP,
                BackgroundTexture   = MyGuiConstants.TEXTURE_SCROLLABLE_LIST,
                ScrolledAreaPadding = new MyGuiBorderThickness(0.005f),
            };

            layout.AddWithSize(briefingScrollableArea, MyAlignH.Left, MyAlignV.Top, 1, 1, rowSpan: 4, colSpan: 3);
            //inside scrollable area:
            m_descriptionBox = new MyGuiControlMultilineText(
                position: new Vector2(-0.227f, 5f),
                size: new Vector2(briefingScrollableArea.Size.X - 0.02f, 11f),
                textBoxAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP,
                selectable: false);
            briefing.Controls.Add(m_descriptionBox);

            m_connectedPlayers                  = new MyGuiControlTable();
            m_connectedPlayers.Size             = new Vector2(490f, 150f) / MyGuiConstants.GUI_OPTIMAL_SIZE;
            m_connectedPlayers.VisibleRowsCount = 8;
            m_connectedPlayers.ColumnsCount     = 2;
            m_connectedPlayers.SetCustomColumnWidths(new float[] { 0.7f, 0.3f });
            m_connectedPlayers.SetColumnName(0, MyTexts.Get(MySpaceTexts.GuiScenarioPlayerName));
            m_connectedPlayers.SetColumnName(1, MyTexts.Get(MySpaceTexts.GuiScenarioPlayerStatus));

            m_kickPlayerButton = new MyGuiControlButton(text: MyTexts.Get(MyCommonTexts.Kick), visualStyle: MyGuiControlButtonStyleEnum.Rectangular, highlightType: MyGuiControlHighlightType.WHEN_ACTIVE,
                                                        size: new Vector2(190f, 48f) / MyGuiConstants.GUI_OPTIMAL_SIZE, onButtonClick: OnKick2Clicked);
            m_kickPlayerButton.Enabled = CanKick();

            m_timeoutLabel = new MyGuiControlLabel(text: MyTexts.GetString(MySpaceTexts.GuiScenarioTimeout), originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER);

            TimeoutCombo = new MyGuiControlCombobox();
            TimeoutCombo.ItemSelected += OnTimeoutSelected;
            TimeoutCombo.AddItem(3, MyTexts.Get(MySpaceTexts.GuiScenarioTimeout3min));
            TimeoutCombo.AddItem(5, MyTexts.Get(MySpaceTexts.GuiScenarioTimeout5min));
            TimeoutCombo.AddItem(10, MyTexts.Get(MySpaceTexts.GuiScenarioTimeout10min));
            TimeoutCombo.AddItem(-1, MyTexts.Get(MySpaceTexts.GuiScenarioTimeoutUnlimited));
            TimeoutCombo.SelectItemByIndex(0);
            TimeoutCombo.Enabled = Sync.IsServer;

            m_canJoinRunningLabel = new MyGuiControlLabel(text: MyTexts.GetString(MySpaceTexts.ScenarioSettings_CanJoinRunningShort), originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER);
            m_canJoinRunning      = new MyGuiControlCheckbox();

            m_canJoinRunningLabel.Enabled = false;
            m_canJoinRunning.Enabled      = false;

            m_startButton = new MyGuiControlButton(text: MyTexts.Get(MySpaceTexts.GuiScenarioStart), visualStyle: MyGuiControlButtonStyleEnum.Rectangular, highlightType: MyGuiControlHighlightType.WHEN_ACTIVE,
                                                   size: new Vector2(200, 48f) / MyGuiConstants.GUI_OPTIMAL_SIZE, onButtonClick: OnStartClicked);
            m_startButton.Enabled = Sync.IsServer;

            m_chatControl = new MyHudControlChat(
                MyHud.Chat,
                size: new Vector2(1400f, 300f) / MyGuiConstants.GUI_OPTIMAL_SIZE,
                font: MyFontEnum.DarkBlue,
                textScale: 0.7f,
                textAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM,
                backgroundColor: MyGuiConstants.THEMED_GUI_BACKGROUND_COLOR,
                contents: null,
                drawScrollbar: true,
                textBoxAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM);
            m_chatControl.BorderEnabled = true;
            m_chatControl.BorderColor   = Color.CornflowerBlue;

            m_chatTextbox               = new MyGuiControlTextbox(maxLength: ChatMessageBuffer.MAX_MESSAGE_SIZE);
            m_chatTextbox.Size          = new Vector2(1400f, 48f) / MyGuiConstants.GUI_OPTIMAL_SIZE;
            m_chatTextbox.TextScale     = 0.8f;
            m_chatTextbox.VisualStyle   = MyGuiControlTextboxStyleEnum.Default;
            m_chatTextbox.EnterPressed += ChatTextbox_EnterPressed;

            m_sendChatButton = new MyGuiControlButton(text: MyTexts.Get(MySpaceTexts.GuiScenarioSend), visualStyle: MyGuiControlButtonStyleEnum.Rectangular, highlightType: MyGuiControlHighlightType.WHEN_ACTIVE,
                                                      size: new Vector2(190f, 48f) / MyGuiConstants.GUI_OPTIMAL_SIZE, onButtonClick: OnSendChatClicked);


            layout.AddWithSize(m_connectedPlayers, MyAlignH.Left, MyAlignV.Top, 1, 4, rowSpan: 2, colSpan: 2);

            layout.AddWithSize(m_kickPlayerButton, MyAlignH.Left, MyAlignV.Center, 2, 5);
            layout.AddWithSize(m_timeoutLabel, MyAlignH.Left, MyAlignV.Center, 3, 4);
            layout.AddWithSize(TimeoutCombo, MyAlignH.Left, MyAlignV.Center, 3, 5);

            layout.AddWithSize(m_canJoinRunningLabel, MyAlignH.Left, MyAlignV.Center, 4, 4);
            layout.AddWithSize(m_canJoinRunning, MyAlignH.Right, MyAlignV.Center, 4, 5);

            layout.AddWithSize(m_chatControl, MyAlignH.Left, MyAlignV.Top, 5, 1, rowSpan: 1, colSpan: 5);

            layout.AddWithSize(m_chatTextbox, MyAlignH.Left, MyAlignV.Top, 6, 1, rowSpan: 1, colSpan: 4);
            layout.AddWithSize(m_sendChatButton, MyAlignH.Right, MyAlignV.Top, 6, 5);

            layout.AddWithSize(m_startButton, MyAlignH.Left, MyAlignV.Top, 7, 2);
        }
        private void InitRightSide()
        {
            var originL = -m_size.Value / 2 + new Vector2(MARGIN_LEFT, MARGIN_TOP);

            var screenSize         = m_size.Value;
            var layoutSize         = new Vector2(screenSize.X / 2 - originL.X, screenSize.Y - MARGIN_TOP - MARGIN_BOTTOM) - new Vector2(0.05f, 0.05f);
            var columnWidthLabel   = layoutSize.X * 0.4f;
            var columnWidthControl = layoutSize.X - columnWidthLabel;
            var rowHeight          = 0.052f;
            var leftHeight         = layoutSize.Y - 4 * rowHeight;
            var descriptionMargin  = 0.005f;

            m_tableLayout = new MyLayoutTable(this, originL, layoutSize);
            m_tableLayout.SetColumnWidthsNormalized(columnWidthLabel, columnWidthControl);
            m_tableLayout.SetRowHeightsNormalized(rowHeight, rowHeight, rowHeight, rowHeight, leftHeight);

            // Name
            m_nameLabel = new MyGuiControlLabel
            {
                Text        = MyTexts.GetString(MyCommonTexts.Name),
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER,
            };

            m_nameTextbox = new MyGuiControlTextbox
            {
                MaxLength   = MySession.MAX_NAME_LENGTH,
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER,
                Enabled     = false
            };

            // Difficulty
            m_difficultyLabel = new MyGuiControlLabel
            {
                Text        = MyTexts.GetString(MySpaceTexts.Difficulty),
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_TOP
            };

            m_difficultyCombo = new MyGuiControlCombobox
            {
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER,
                Enabled     = false
            };
            m_difficultyCombo.AddItem((int)0, MySpaceTexts.DifficultyEasy);
            m_difficultyCombo.AddItem((int)1, MySpaceTexts.DifficultyNormal);
            m_difficultyCombo.AddItem((int)2, MySpaceTexts.DifficultyHard);

            // Online
            m_onlineModeLabel = new MyGuiControlLabel
            {
                Text        = MyTexts.GetString(MyCommonTexts.WorldSettings_OnlineMode),
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_TOP
            };
            m_onlineMode = new MyGuiControlCheckbox
            {
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER,
                Enabled     = false
            };

            // Description
            m_descriptionMultilineText = new MyGuiControlMultilineText(
                selectable: false)
            {
                Name         = "BriefingMultilineText",
                Position     = new Vector2(-0.009f, -0.115f),
                Size         = new Vector2(0.419f, 0.412f),
                OriginAlign  = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP,
                TextAlign    = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP,
                TextBoxAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP
            };

            var panel = new MyGuiControlCompositePanel
            {
                BackgroundTexture = MyGuiConstants.TEXTURE_RECTANGLE_DARK,
            };


            m_tableLayout.Add(m_nameLabel, MyAlignH.Left, MyAlignV.Center, 0, 0);
            m_tableLayout.Add(m_difficultyLabel, MyAlignH.Left, MyAlignV.Center, 2, 0);
            m_tableLayout.Add(m_onlineModeLabel, MyAlignH.Left, MyAlignV.Center, 3, 0);

            m_tableLayout.AddWithSize(m_nameTextbox, MyAlignH.Left, MyAlignV.Center, 0, 1);
            m_tableLayout.AddWithSize(m_difficultyCombo, MyAlignH.Left, MyAlignV.Center, 2, 1);
            m_tableLayout.AddWithSize(m_onlineMode, MyAlignH.Left, MyAlignV.Center, 3, 1);

            m_tableLayout.AddWithSize(panel, MyAlignH.Left, MyAlignV.Top, 4, 0, 1, 2);
            m_tableLayout.AddWithSize(m_descriptionMultilineText, MyAlignH.Left, MyAlignV.Top, 4, 0, 1, 2);

            // Panel offset from text
            var bothSidesOffset = 0.003f;

            panel.Position = new Vector2(panel.PositionX - bothSidesOffset, panel.PositionY - bothSidesOffset);
            panel.Size     = new Vector2(panel.Size.X + bothSidesOffset, panel.Size.Y + bothSidesOffset * 2);

            // The bulgarian constant is offset from side to match the size of the layout
            var buttonsOrigin           = panel.Position + new Vector2(panel.Size.X, panel.Size.Y + 0.02f);
            var buttonSize              = MyGuiConstants.BACK_BUTTON_SIZE;
            var buttonHorizontalSpacing = 0.02f;

            // Ok/Cancel/Publish
            m_publishButton = new MyGuiControlButton(position: buttonsOrigin, size: buttonSize, text: MyTexts.Get(MyCommonTexts.LoadScreenButtonPublish), onButtonClick: OnPublishButtonOnClick, originAlign: MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP);
            var cancelButton = new MyGuiControlButton(position: buttonsOrigin + new Vector2(0, buttonSize.Y), size: buttonSize, text: MyTexts.Get(MyCommonTexts.Cancel), onButtonClick: OnCancelButtonClick, originAlign: MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP);
            var okButton     = new MyGuiControlButton(position: buttonsOrigin + new Vector2(-buttonSize.X - buttonHorizontalSpacing, buttonSize.Y), size: buttonSize, text: MyTexts.Get(MyCommonTexts.Ok), onButtonClick: OnOkButtonClicked, originAlign: MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP);

            Controls.Add(m_publishButton);
            Controls.Add(okButton);
            Controls.Add(cancelButton);

            CloseButtonEnabled = true;
        }