Пример #1
0
        public ChatBox(GUIComponent parent, bool isSinglePlayer)
        {
            this.IsSinglePlayer = isSinglePlayer;
            if (radioIcon == null)
            {
                radioIcon        = new Sprite("Content/UI/inventoryAtlas.png", new Rectangle(527, 952, 38, 52), null);
                radioIcon.Origin = radioIcon.size / 2;
            }

            screenResolution = new Point(GameMain.GraphicsWidth, GameMain.GraphicsHeight);

            int toggleButtonWidth = (int)(30 * GUI.Scale);

            GUIFrame = new GUIFrame(HUDLayoutSettings.ToRectTransform(HUDLayoutSettings.ChatBoxArea, parent.RectTransform), style: null);
            var chatBoxHolder = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.875f), GUIFrame.RectTransform), style: "ChatBox");

            chatBox = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.95f), chatBoxHolder.RectTransform, Anchor.CenterRight), style: null);

            ToggleButton = new GUIButton(new RectTransform(new Point(toggleButtonWidth, HUDLayoutSettings.ChatBoxArea.Height), parent.RectTransform),
                                         style: "UIToggleButton");

            ToggleButton.OnClicked += (GUIButton btn, object userdata) =>
            {
                ToggleOpen = !ToggleOpen;
                return(true);
            };

            InputBox = new GUITextBox(new RectTransform(new Vector2(0.925f, 0.125f), GUIFrame.RectTransform, Anchor.BottomLeft),
                                      style: "ChatTextBox")
            {
                Font          = GUI.SmallFont,
                MaxTextLength = ChatMessage.MaxLength
            };
            InputBox.OnDeselected += (gui, Keys) =>
            {
                //gui.Text = "";
            };

            var chatSendButton = new GUIButton(new RectTransform(new Vector2(0.075f, 0.125f), GUIFrame.RectTransform, Anchor.BottomRight)
            {
                RelativeOffset = new Vector2(0.0f, -0.01f)
            }, ">");

            chatSendButton.OnClicked += (GUIButton btn, object userdata) =>
            {
                InputBox.OnEnterPressed(InputBox, InputBox.Text);
                return(true);
            };

            showNewMessagesButton = new GUIButton(new RectTransform(new Vector2(1f, 0.125f), GUIFrame.RectTransform, Anchor.BottomCenter)
            {
                RelativeOffset = new Vector2(0.0f, -0.125f)
            }, TextManager.Get("chat.shownewmessages"));
            showNewMessagesButton.OnClicked += (GUIButton btn, object userdata) =>
            {
                chatBox.ScrollBar.BarScrollValue = 1f;
                showNewMessagesButton.Visible    = false;
                return(true);
            };

            showNewMessagesButton.Visible = false;
            ToggleOpen = GameMain.Config.ChatOpen;
        }