Пример #1
0
        /// <summary>
        ///     Create a new <see cref="CivPanel"/>.
        /// </summary>
        ///
        /// <param name="parent">
        ///     The parent within which the panel will be displayed.
        /// </param>
        /// <param name="civs">
        ///     The civs in the simulation.
        /// </param>
        public CivPanel(IPositionedElement parent, IEnumerable <Civilization> civs) : base(parent)
        {
            if (UIContentManager.TryGetInstance(out UIContentManager manager))
            {
                _civTexturePairs = new Dictionary <Civilization, Entry>();
                _scrollOffset    = 0;
                Visible          = true;
                Focused          = true;
                _textFont        = manager.GetFont("DebugFont");
                _civText         = new RelativeText(this, _textFont);

                _scrollbar = new Scrollbar(this)
                {
                    AnchorPosition   = AnchorPosition.TopRight,
                    Size             = new Point(15, Size.Y),
                    RelativePosition = new Point(-15, 0)
                };


                foreach (Civilization civ in civs)
                {
                    _civTexturePairs.Add(civ, new Entry()
                    {
                        EntryHeight = 0,
                        Texture     = new RelativeTexture(this, new SpriteDefinition(manager.GetColorTexture(civ.Color), new Rectangle(0, 0, 1, 1)))
                    });
                }
            }
            else
            {
                throw new InvalidOperationException("UI Content manager does not exist.");
            }
        }
Пример #2
0
        /// <summary>
        ///     Create a new <see cref="InputNumberField"/>.
        ///     Creates sub elements and sets default values.
        /// </summary>
        /// <param name="parent"></param>
        public InputNumberField(IPositionedElement parent) : base(parent)
        {
            if (UIContentManager.TryGetInstance(out UIContentManager contentManager))
            {
                _background = new RelativeTexture(this,
                                                  new SpriteDefinition(contentManager.GetColorTexture(Color.White), new Rectangle(Point.Zero, new Point(1, 1))))
                {
                    AnchorPosition   = AnchorPosition.TopLeft,
                    RelativePosition = Point.Zero,
                };

                _renderText = new RelativeText(this, contentManager.GetFont("DebugFont"))
                {
                    AnchorPosition   = AnchorPosition.TopLeft,
                    RelativePosition = new Point(1, 1)
                };

                _textSb = new StringBuilder();

                Visible = true;
            }
            else
            {
                throw new InvalidOperationException("UI content manager does not exist.");
            }
        }
Пример #3
0
 /// <summary>
 ///     Create a new <see cref="RelativeTexture"/>.
 /// </summary>
 ///
 /// <exception cref="ArgumentNullException" />
 public RelativeTexture(IPositionedElement parent, SpriteDefinition spriteDef) : base(parent)
 {
     SpriteDefinition = spriteDef;
     LayerDepth       = 0F;
     Size             = Point.Zero;
     SpriteEffects    = SpriteEffects.None;
     Visible          = true;
 }
Пример #4
0
        /// <summary>
        ///     Create a new <see cref="Scrollbar"/>.
        /// </summary>
        ///
        /// <exception cref="Exception" />
        public Scrollbar(IPositionedElement parent) : base(parent)
        {
            // Before the scrollbar items can be created, the required resources need to be created.
            Texture2D scrollbarSheet;

            if (UIContentManager.TryGetInstance(out UIContentManager manager))
            {
                scrollbarSheet = manager.GetTexture("UI\\Scrollbar");
            }
            else
            {
                throw new Exception("Could not retrieve scrollbar spritesheet.");
            }

            // Sprite definitions are created for the different sprites used by scrollbar items.
            Rectangle        upButtonRect = new Rectangle(0, 0, 15, 15);
            SpriteDefinition upButtonDef  = new SpriteDefinition(scrollbarSheet, upButtonRect);

            Rectangle        downButtonRect = new Rectangle(15, 0, 15, 15);
            SpriteDefinition downButtonDef  = new SpriteDefinition(scrollbarSheet, downButtonRect);

            Rectangle        handleRect = new Rectangle(0, 15, 15, 20);
            SpriteDefinition handleDef  = new SpriteDefinition(scrollbarSheet, handleRect);

            Rectangle        backgroundRect = new Rectangle(15, 15, 15, 35);
            SpriteDefinition backgroundDef  = new SpriteDefinition(scrollbarSheet, backgroundRect);

            // Finally, the items themselves can be created.
            _upButton = new Button(this, upButtonDef)
            {
                RelativePosition = Point.Zero,
                Size             = new Point(15, 15),
                Focused          = true,
                Visible          = true
            };
            _downButton = new Button(this, downButtonDef)
            {
                AnchorPosition   = AnchorPosition.BottomLeft,
                RelativePosition = new Point(0, -15),
                Size             = new Point(15, 15),
                Focused          = true,
                Visible          = true
            };
            _handle = new RelativeTexture(this, handleDef)
            {
                Size = new Point(15, 20)
            };
            _background = new RelativeTexture(this, backgroundDef)
            {
                RelativePosition = new Point(0, 15)
            };


            _downButton.Hold += _downButton_Hold;
            _upButton.Hold   += _upButton_Hold;

            ScrollPosition = 0F;
        }
Пример #5
0
 /// <summary>
 ///     Create a new <see cref="RelativeText"/>.
 /// </summary>
 ///
 /// <param name="font">
 ///     The font to use for drawing the text.
 /// </param>
 public RelativeText(IPositionedElement parent, SpriteFont font) : base(parent)
 {
     Font          = font;
     Text          = "";
     TextColor     = Color.Black;
     LayerDepth    = 0F;
     SpriteEffects = SpriteEffects.None;
     Visible       = true;
 }
Пример #6
0
 /// <summary>
 ///     Create a new <see cref="RelativeElement"/>.
 /// </summary>
 ///
 /// <param name="parent">
 ///     The element's parent.
 /// </param>
 public RelativeElement(IPositionedElement parent)
 {
     ParentElement    = parent;
     RelativePosition = Point.Zero;
 }