Exemplo n.º 1
0
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 /// <summary>
 /// Copy constructor
 /// </summary>
 ///
 /// <param name="copy">Instance to copy</param>
 ///
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 public Label(Label copy)
     : base(copy)
 {
     m_LoadedConfigFile = copy.m_LoadedConfigFile;
     m_Background       = new RectangleShape(copy.m_Background);
     m_Text             = new Text(copy.m_Text);
     m_AutoSize         = copy.m_AutoSize;
 }
Exemplo n.º 2
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Copy constructor
        /// </summary>
        ///
        /// <param name="copy">Instance to copy</param>
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public MessageBox(MessageBox copy)
            : base(copy)
        {
            ButtonClickedCallback      = copy.ButtonClickedCallback;

            m_LoadedConfigFile         = copy.m_LoadedConfigFile;
            m_ButtonConfigFileFilename = copy.m_ButtonConfigFileFilename;
            m_TextSize                 = copy.m_TextSize;

            m_Label = Copy<Label>(copy.m_Label, "MessageBoxText");

            foreach (Button button in copy.m_Buttons)
            {
                Button newButton = Copy(button);
                newButton.LeftMouseClickedCallback -= copy.ButtonClickedCallbackFunction;
                newButton.SpaceKeyPressedCallback -= copy.ButtonClickedCallbackFunction;
                newButton.ReturnKeyPressedCallback -= copy.ButtonClickedCallbackFunction;
                newButton.LeftMouseClickedCallback += ButtonClickedCallbackFunction;
                newButton.SpaceKeyPressedCallback += ButtonClickedCallbackFunction;
                newButton.ReturnKeyPressedCallback += ButtonClickedCallbackFunction;

                m_Buttons.Add(button);
            }
        }
Exemplo n.º 3
0
        private void LoadNews(Label labelNews)
        {
            string[] news = File.ReadAllLines(Constants.FILEPATH_DATA + "news.txt");

            foreach (var line in news)
            {
                labelNews.Text += line + "\n";
            }
        }
Exemplo n.º 4
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Add a new line of text to the chat box
        /// </summary>
        ///
        /// <param name="text">Text that will be added to the chat box</param>
        /// <param name="color">Color of the text</param>
        /// <param name="textSize">Size of the text</param>
        /// <param name="font">Font of the text (null to use default font)</param>
        ///
        /// <remarks>The whole text passed to this function will be considered as one line for the GetLine and RemoveLine functions,
        /// even if it is too long and gets split over multiple lines.</remarks>
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public void AddLine(string text, Color color, uint textSize, Font font = null)
        {
            var widgets = m_Panel.GetWidgets ();

            // Remove the top line if you exceed the maximum
            if ((m_MaxLines > 0) && (m_MaxLines < widgets.Count + 1))
                RemoveLine (0);

            Label label = m_Panel.Add (new Label ());
            label.TextColor = color;
            label.TextSize = textSize;

            if (font != null)
                label.TextFont = font;

            Label tempLine = new Label();
            tempLine.TextSize = textSize;
            tempLine.TextFont = label.TextFont;

            float width = m_Panel.Size.X;
            if (m_Scroll != null)
                width -= m_Scroll.Size.X;

            if (width < 0)
                width = 0;

            // Split the label over multiple lines if necessary
            int pos = 0;
            int size = 0;
            while (pos + size < text.Length)
            {
                tempLine.Text = text.Substring(pos, ++size);

                if (tempLine.Size.X + 4.0f > width)
                {
                    label.Text = label.Text + text.Substring(pos, size - 1) + "\n";

                    pos = pos + size - 1;
                    size = 0;
                }
            }
            label.Text = label.Text + tempLine.Text;

            m_FullTextHeight += GetLineSpacing((uint)widgets.Count - 1);

            if (m_Scroll != null)
            {
                m_Scroll.Maximum = (int)m_FullTextHeight;

                if (m_Scroll.Maximum > m_Scroll.LowValue)
                    m_Scroll.Value = m_Scroll.Maximum - m_Scroll.LowValue;
            }

            // Reposition the labels
            UpdateDisplayedText();
        }