示例#1
0
        private static void AddMessage(ColoredText msg)
        {
            //listbox not created yet, don't attempt to add
            if (listBox == null)
            {
                return;
            }

            if (listBox.children.Count > MaxMessages)
            {
                listBox.children.RemoveRange(0, listBox.children.Count - MaxMessages);
            }

            Messages.Add(msg);
            if (Messages.Count > MaxMessages)
            {
                Messages.RemoveRange(0, Messages.Count - MaxMessages);
            }

            try
            {
                var textBlock = new GUITextBlock(new Rectangle(0, 0, listBox.Rect.Width, 0), msg.Text, "", Alignment.TopLeft, Alignment.Left, null, true, GUI.SmallFont);
                textBlock.CanBeFocused = false;
                textBlock.TextColor    = msg.Color;

                listBox.AddChild(textBlock);
                listBox.BarScroll = 1.0f;
            }
            catch (Exception e)
            {
                ThrowError("Failed to add a message to the debug console.", e);
            }

            selectedIndex = Messages.Count;
        }
示例#2
0
        public GUIMessage(string text, Color color, Vector2 worldPosition, Vector2 velocity, float lifeTime, Alignment textAlignment = Alignment.Center, ScalableFont font = null)
        {
            coloredText   = new ColoredText(text, color, false);
            WorldSpace    = true;
            pos           = worldPosition;
            Timer         = lifeTime;
            Velocity      = velocity;
            this.lifeTime = lifeTime;

            Font = font;

            size = font.MeasureString(text);

            Origin = new Vector2((int)(0.5f * size.X), (int)(0.5f * size.Y));
            if (textAlignment.HasFlag(Alignment.Left))
            {
                Origin.X -= size.X * 0.5f;
            }

            if (textAlignment.HasFlag(Alignment.Right))
            {
                Origin.X += size.X * 0.5f;
            }

            if (textAlignment.HasFlag(Alignment.Top))
            {
                Origin.Y -= size.Y * 0.5f;
            }

            if (textAlignment.HasFlag(Alignment.Bottom))
            {
                Origin.Y += size.Y * 0.5f;
            }
        }
示例#3
0
        public GUIMessage(string text, Color color, Vector2 position, float lifeTime, Alignment textAlignment, bool autoCenter)
        {
            coloredText     = new ColoredText(text, color, false);
            pos             = position;
            this.lifeTime   = lifeTime;
            this.Alignment  = textAlignment;
            this.AutoCenter = autoCenter;

            size = GUI.Font.MeasureString(text);

            if (textAlignment.HasFlag(Alignment.Left))
            {
                Origin.X += size.X * 0.5f;
            }

            if (textAlignment.HasFlag(Alignment.Right))
            {
                Origin.X -= size.X * 0.5f;
            }

            if (textAlignment.HasFlag(Alignment.Top))
            {
                Origin.Y += size.Y * 0.5f;
            }

            if (textAlignment.HasFlag(Alignment.Bottom))
            {
                Origin.Y -= size.Y * 0.5f;
            }

            if (autoCenter)
            {
                Origin = new Vector2((int)(0.5f * size.X), (int)(0.5f * size.Y));
            }
        }
示例#4
0
        public GUIMessage(string text, Color color, Vector2 position, float lifeTime)
        {
            coloredText   = new ColoredText(text, color);
            pos           = position;
            this.lifeTime = lifeTime;

            size = GUI.Font.MeasureString(text);
        }
        public GUIMessage(string text, Color color, float lifeTime, ScalableFont font = null)
        {
            coloredText   = new ColoredText(text, color, false, false);
            this.lifeTime = lifeTime;
            Timer         = lifeTime;

            size   = font.MeasureString(text);
            Origin = new Vector2(0, size.Y * 0.5f);

            Font = font;
        }
示例#6
0
        private static void AddMessage(ColoredText msg)
        {
            //listbox not created yet, don't attempt to add
            if (listBox == null)
            {
                return;
            }

            if (listBox.Content.CountChildren > MaxMessages)
            {
                listBox.RemoveChild(listBox.Content.Children.First());
            }

            Messages.Add(msg);
            if (Messages.Count > MaxMessages)
            {
                Messages.RemoveRange(0, Messages.Count - MaxMessages);
            }

            try
            {
                var textBlock = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), listBox.Content.RectTransform),
                                                 msg.Text, font: GUI.SmallFont, wrap: true)
                {
                    CanBeFocused = false,
                    TextColor    = msg.Color
                };
                listBox.UpdateScrollBarSize();
                listBox.BarScroll = 1.0f;
            }
            catch (Exception e)
            {
                ThrowError("Failed to add a message to the debug console.", e);
            }

            selectedIndex = Messages.Count;
        }