Example #1
0
        /// <summary>
        /// Create the panel tabs.
        /// </summary>
        /// <param name="buttonsBackground">Optional buttons background panel.</param>
        public PanelTabs(PanelSkin buttonsBackground = PanelSkin.None) : base(new Vector2(0, 0), Anchor.TopCenter, Vector2.Zero)
        {
            // update style
            UpdateStyle(DefaultStyle);

            // remove self padding
            Padding = Vector2.Zero;

            if (!UserInterface.Active._isDeserializing)
            {
                // create the internal panel that contains everything - buttons + panels
                _internalRoot             = new Panel(Vector2.Zero, PanelSkin.None, Anchor.TopCenter);
                _internalRoot.SpaceBefore = _internalRoot.SpaceAfter = _internalRoot.Padding = Vector2.Zero;
                _internalRoot.Identifier  = "_internalRoot";
                AddChild(_internalRoot);

                // create the panel to hold the tab buttons
                _buttonsPanel             = new Panel(Vector2.Zero, buttonsBackground, Anchor.TopCenter);
                _buttonsPanel.SpaceBefore = _buttonsPanel.SpaceAfter = _buttonsPanel.Padding = Vector2.Zero;
                _buttonsPanel.Identifier  = "_buttonsPanel";
                _internalRoot.AddChild(_buttonsPanel);

                // create the panel to hold the tab panels
                _panelsPanel             = new Panel(Vector2.Zero, PanelSkin.None, Anchor.TopCenter, new Vector2(0, 0));
                _panelsPanel.SpaceBefore = _panelsPanel.SpaceAfter = _panelsPanel.Padding = Vector2.Zero;
                _panelsPanel.Identifier  = "_panelsPanel";
                _internalRoot.AddChild(_panelsPanel);

                // make internal stuff hidden
                _panelsPanel._hiddenInternalEntity  = true;
                _buttonsPanel._hiddenInternalEntity = true;
                _internalRoot._hiddenInternalEntity = true;
            }
        }
Example #2
0
        /// <summary>
        /// Add a new tab to the panel tabs.
        /// </summary>
        /// <param name="name">Tab name (also what will appear on the panel button).</param>
        /// <param name="panelSkin">Panel skin to use for this panel.</param>
        /// <returns>The new tab we created - contains the panel and the button to switch it.</returns>
        public TabData AddTab(string name, PanelSkin panelSkin = PanelSkin.None)
        {
            Panel  newPanel  = new Panel(Vector2.Zero, panelSkin, Anchor.TopCenter);
            Button newButton = new Button(name, ButtonSkin.Default, Anchor.AutoInlineNoBreak, new Vector2(-1, -1));

            newPanel.Identifier = name;
            return(AddTab(newPanel, newButton));
        }
Example #3
0
        public DefenceMenu(PlayerStats stats, Vector2 size, PanelSkin skin = PanelSkin.Simple, Anchor anchor = Anchor.CenterLeft, Vector2?offset = null)
            : base(size, skin, anchor, offset)
        {
            this.stats = stats;

            Padding = new Vector2(10);
            PanelOverflowBehavior = PanelOverflowBehavior.VerticalScroll;
        }
Example #4
0
 /// <summary>
 /// Create the panel.
 /// </summary>
 /// <param name="size">Panel size.</param>
 /// <param name="skin">Panel skin (texture to use). Use PanelSkin.None for invisible panels.</param>
 /// <param name="anchor">Position anchor.</param>
 /// <param name="offset">Offset from anchor position.</param>
 public Panel(Vector2 size, PanelSkin skin = PanelSkin.Default, Anchor anchor = Anchor.Center, Vector2?offset = null) :
     base(size, skin, anchor, offset)
 {
     UpdateStyle(DefaultStyle);
     if (size.Y == -1)
     {
         AdjustHeightAutomatically = true;
     }
 }
Example #5
0
        /// <summary>
        /// Create the panel.
        /// </summary>
        /// <param name="size">Panel size.</param>
        /// <param name="skin">Panel skin (texture to use). Use PanelSkin.None for invisible panels.</param>
        /// <param name="anchor">Position anchor.</param>
        /// <param name="offset">Offset from anchor position.</param>
        public Panel(UserInterface ui, Vector2 size, PanelSkin skin, Anchor anchor = Anchor.Center, Vector2?offset = null, Vector2?innermargin = null) :
            base(ui, size, skin, anchor, offset)
        {
            UpdateStyle(DefaultStyle);
            if (size.Y == -1)
            {
                AdjustHeightAutomatically = true;
            }

            Vector2?mg = null;

            if ((int)skin > 0)
            {
                TextureData data = Resources.PanelData[(int)skin];  //TODO in base?
                mg = data.InnerMargin;
            }

            InnerMargin = innermargin ?? mg ?? new Vector2(0);
        }
Example #6
0
        public StatsView(PlayerStats stats, Vector2 size, PanelSkin skin = PanelSkin.None, Anchor anchor = Anchor.TopRight)
            : base(size, skin, anchor, null)
        {
            this.stats = stats;
            Padding    = new Vector2(5f);

            elapsedTimeView = new Paragraph(ElapsedTimeString, Anchor.Auto);
            pointsView      = new Paragraph(PointsString, Anchor.Auto);

            AddPointsButton = new Button("Add Points", size: new Vector2(size.X - Padding.X * 2, 60))
            {
                Padding = new Vector2(5f)
            };

            AddPointsButton.ButtonParagraph.Scale = 0.8f;

            AddChild(elapsedTimeView);
            AddChild(pointsView);
            AddChild(AddPointsButton);
        }
Example #7
0
        /// <summary>
        /// Generate and return a set of panels aligned next to each other.
        /// This is useful for cases like when you want to divide your panel into 3 colums.
        /// </summary>
        /// <param name="panelSizes">Array with panel sizes to generate (also determine how many panels to return).</param>
        /// <param name="parent">Optional parent entity to add panels to.</param>
        /// <param name="skin">Panels skin to use (default to None, making them invisible.</param>
        /// <returns>Array with generated panels.</returns>
        public static Panel[] GenerateColums(Vector2[] panelSizes, Entity parent, PanelSkin skin = PanelSkin.None)
        {
            // list of panels to return
            List <Panel> retList = new List <Panel>();

            // create panels
            foreach (var currSize in panelSizes)
            {
                Panel currPanel = new Panel(parent._userinterface, currSize, skin, Anchor.AutoInlineNoBreak);
                currPanel.Padding = Vector2.Zero;
                retList.Add(currPanel);
                if (parent != null)
                {
                    parent.AddChild(currPanel);
                }
            }

            // return result panels
            return(retList.ToArray());
        }
Example #8
0
        public DefenceMenuItem(Vector2 size, string name, Texture2D image, int cost, PanelSkin skin = PanelSkin.Default, Anchor anchor = Anchor.Auto)
            : base(size, skin, anchor, null)
        {
            Name    = name;
            Cost    = cost;
            Padding = new Vector2(10);

            AddChild(new Image(image, Size - Padding * 2, ImageDrawMode.Stretch, Anchor.TopCenter)
            {
                ClickThrough = true
            });

            AddChild(new Paragraph(name, Anchor.TopLeft)
            {
                ClickThrough = true
            });

            AddChild(new Label(cost.ToString() + " Points", Anchor.BottomRight)
            {
                ClickThrough = true
            });

            OnClick = (e) => Click?.Invoke(this);
        }
Example #9
0
 /// <summary>
 /// Create the panel.
 /// </summary>
 /// <param name="size">Panel size.</param>
 /// <param name="skin">Panel skin (texture to use). Use PanelSkin.None for invisible panels.</param>
 /// <param name="anchor">Position anchor.</param>
 /// <param name="offset">Offset from anchor position.</param>
 public Panel(Vector2 size, PanelSkin skin = PanelSkin.Default, Anchor anchor = Anchor.Center, Vector2?offset = null) :
     base(size, skin, anchor, offset)
 {
     UpdateStyle(DefaultStyle);
 }
Example #10
0
        /// <summary>
        /// Create the text input.
        /// </summary>
        /// <param name="multiline">If true, text input will accept multiple lines.</param>
        /// <param name="size">Input box size.</param>
        /// <param name="anchor">Position anchor.</param>
        /// <param name="offset">Offset from anchor position.</param>
        /// <param name="skin">TextInput skin, eg which texture to use.</param>
        public TextInput(bool multiline, Vector2 size, Anchor anchor = Anchor.Auto, Vector2?offset = null, PanelSkin skin = PanelSkin.ListBackground) :
            base(size, skin, anchor, offset)
        {
            // set multiline mode
            _multiLine = multiline;

            // special case - if multiline and asked for default height, make it heigher
            if (multiline && size.Y == -1)
            {
                _size.Y *= 4;
            }

            // update default style
            UpdateStyle(DefaultStyle);

            // set limit by size - default true in single-line, default false in multi-line
            LimitBySize = !_multiLine;

            // create paragraph to show current value
            TextParagraph = UserInterface.DefaultParagraph(string.Empty, _multiLine ? Anchor.TopLeft : Anchor.CenterLeft);
            TextParagraph.UpdateStyle(DefaultParagraphStyle);
            AddChild(TextParagraph, true);

            // create the placeholder paragraph
            PlaceholderParagraph = UserInterface.DefaultParagraph(string.Empty, _multiLine ? Anchor.TopLeft : Anchor.CenterLeft);
            PlaceholderParagraph.UpdateStyle(DefaultPlaceholderStyle);
            AddChild(PlaceholderParagraph, true);

            // create the scrollbar
            if (_multiLine)
            {
                _scrollbar         = new VerticalScrollbar(0, 0, Anchor.CenterRight, offset: new Vector2(-8, 0));
                _scrollbar.Value   = 0;
                _scrollbar.Visible = false;
                AddChild(_scrollbar, false);
            }

            // set word-wrap mode based on weather or not this text input is multiline
            TextParagraph.WrapWords        = _multiLine;
            PlaceholderParagraph.WrapWords = _multiLine;

            // if the default paragraph type is multicolor, disable it for input
            MulticolorParagraph colorTextParagraph = TextParagraph as MulticolorParagraph;

            if (colorTextParagraph != null)
            {
                colorTextParagraph.EnableColorInstructions = false;
            }
        }
Example #11
0
        /// <summary>
        /// Create the text input.
        /// </summary>
        /// <param name="multiline">If true, text input will accept multiple lines.</param>
        /// <param name="size">Input box size.</param>
        /// <param name="anchor">Position anchor.</param>
        /// <param name="offset">Offset from anchor position.</param>
        /// <param name="skin">TextInput skin, eg which texture to use.</param>
        public TextInput(bool multiline, Vector2 size, Anchor anchor = Anchor.Auto, Vector2?offset = null, PanelSkin skin = PanelSkin.ListBackground) :
            base(size, skin, anchor, offset)
        {
            // set multiline mode
            _multiLine = multiline;

            // special case - if multiline and asked for default height, make it heigher
            if (multiline && size.Y == -1)
            {
                _size.Y *= 4;
            }

            // update default style
            UpdateStyle(DefaultStyle);

            // set limit by size - default true in single-line, default false in multi-line
            LimitBySize = !_multiLine;

            if (!UserInterface.Active._isDeserializing)
            {
                // create paragraph to show current value
                TextParagraph = UserInterface.DefaultParagraph(string.Empty, Anchor.TopLeft);
                TextParagraph.UpdateStyle(DefaultParagraphStyle);
                TextParagraph._hiddenInternalEntity = true;
                TextParagraph.Identifier            = "_TextParagraph";
                AddChild(TextParagraph, true);

                // create the placeholder paragraph
                PlaceholderParagraph = UserInterface.DefaultParagraph(string.Empty, Anchor.TopLeft);
                PlaceholderParagraph.UpdateStyle(DefaultPlaceholderStyle);
                PlaceholderParagraph._hiddenInternalEntity = true;
                PlaceholderParagraph.Identifier            = "_PlaceholderParagraph";
                AddChild(PlaceholderParagraph, true);

                // update multiline related stuff
                UpdateMultilineState();

                // if the default paragraph type is multicolor, disable it for input
                MulticolorParagraph colorTextParagraph = TextParagraph as MulticolorParagraph;
                if (colorTextParagraph != null)
                {
                    colorTextParagraph.EnableColorInstructions = false;
                }
            }
        }
Example #12
0
        /// <summary>
        /// Create the DropDown list.
        /// </summary>
        /// <param name="size">List size (refers to the whole size of the list + the header when dropdown list is opened).</param>
        /// <param name="anchor">Position anchor.</param>
        /// <param name="offset">Offset from anchor position.</param>
        /// <param name="skin">Panel skin to use for this DropDown list and header.</param>
        /// <param name="listSkin">An optional skin to use for the dropdown list only (if you want a different skin for the list).</param>
        /// <param name="showArrow">If true, will show an up/down arrow next to the dropdown text.</param>
        public DropDown(Vector2 size, Anchor anchor = Anchor.Auto, Vector2?offset = null, PanelSkin skin = PanelSkin.ListBackground, PanelSkin?listSkin = null, bool showArrow = true) :
            base(size, anchor, offset)
        {
            // default padding of self is 0
            Padding = Vector2.Zero;

            // to get collision right when list is opened
            UseActualSizeForCollision = true;

            if (!UserInterface.Active._isDeserializing)
            {
                // create the panel and paragraph used to show currently selected value (what's shown when drop-down is closed)
                _selectedTextPanel     = new Panel(new Vector2(0, SelectedPanelHeight), skin, Anchor.TopLeft);
                _selectedTextParagraph = UserInterface.DefaultParagraph(string.Empty, Anchor.CenterLeft);
                _selectedTextParagraph.UseActualSizeForCollision = false;
                _selectedTextParagraph.UpdateStyle(SelectList.DefaultParagraphStyle);
                _selectedTextParagraph.UpdateStyle(DefaultParagraphStyle);
                _selectedTextParagraph.UpdateStyle(DefaultSelectedParagraphStyle);
                _selectedTextParagraph.Identifier = "_selectedTextParagraph";
                _selectedTextPanel.AddChild(_selectedTextParagraph, true);
                _selectedTextPanel._hiddenInternalEntity = true;
                _selectedTextPanel.Identifier            = "_selectedTextPanel";

                // create the arrow down icon
                _arrowDownImage = new Image(Resources.ArrowDown, new Vector2(ArrowSize, ArrowSize), ImageDrawMode.Stretch, Anchor.CenterRight, new Vector2(-10, 0));
                _selectedTextPanel.AddChild(_arrowDownImage, true);
                _arrowDownImage._hiddenInternalEntity = true;
                _arrowDownImage.Identifier            = "_arrowDownImage";
                _arrowDownImage.Visible = showArrow;

                // create the list component
                _selectList = new SelectList(new Vector2(0f, size.Y), Anchor.TopCenter, Vector2.Zero, listSkin ?? skin);

                // update list offset and space before
                _selectList.Offset                = new Vector2(0, SelectedPanelHeight);
                _selectList.SpaceBefore           = Vector2.Zero;
                _selectList._hiddenInternalEntity = true;
                _selectList.Identifier            = "_selectList";

                // add the header and select list as children
                AddChild(_selectedTextPanel);
                AddChild(_selectList);

                InitEvents();
            }
            // if during serialization create just a temp placeholder
            else
            {
                _selectList = new SelectList(new Vector2(0f, size.Y), Anchor.TopCenter, Vector2.Zero, listSkin ?? skin);
            }
        }
        /// <summary>
        /// Create the select list.
        /// </summary>
        /// <param name="size">List size.</param>
        /// <param name="anchor">Position anchor.</param>
        /// <param name="offset">Offset from anchor position.</param>
        /// <param name="skin">SelectList skin, eg which texture to use.</param>
        public SelectList(Vector2 size, Anchor anchor = Anchor.Auto, Vector2?offset = null, PanelSkin skin = PanelSkin.ListBackground) :
            base(size, skin, anchor, offset)
        {
            // update style and set default padding
            UpdateStyle(DefaultStyle);

            // create the scrollbar
            _scrollbar         = new VerticalScrollbar(0, 10, Anchor.CenterRight, offset: new Vector2(-8, 0));
            _scrollbar.Value   = 0;
            _scrollbar.Visible = false;
            AddChild(_scrollbar, false);
        }
Example #14
0
 /// <summary>
 /// Create the panel.
 /// </summary>
 /// <param name="size">Panel size.</param>
 /// <param name="skin">Panel skin (texture to use). Use PanelSkin.None for invisible panels.</param>
 /// <param name="anchor">Position anchor.</param>
 /// <param name="offset">Offset from anchor position.</param>
 public PanelBase(Vector2 size, PanelSkin skin = PanelSkin.Default, Anchor anchor = Anchor.Center, Vector2?offset = null) :
     base(size, anchor, offset)
 {
     _skin = skin;
     UpdateStyle(Panel.DefaultStyle);
 }
Example #15
0
        /// <summary>
        /// Create the DropDown list.
        /// </summary>
        /// <param name="size">List size (refers to the whole size of the list + the header when dropdown list is opened).</param>
        /// <param name="anchor">Position anchor.</param>
        /// <param name="offset">Offset from anchor position.</param>
        /// <param name="skin">Panel skin to use for this DropDown list and header.</param>
        /// <param name="listSkin">An optional skin to use for the dropdown list only (if you want a different skin for the list).</param>
        /// <param name="showArrow">If true, will show an up/down arrow next to the dropdown text.</param>
        public DropDown(Vector2 size, Anchor anchor = Anchor.Auto, Vector2?offset = null, PanelSkin skin = PanelSkin.ListBackground, PanelSkin?listSkin = null, bool showArrow = true) :
            base(size, anchor, offset)
        {
            // default padding of self is 0
            Padding = Vector2.Zero;

            // to get collision right when list is opened
            UseActualSizeForCollision = true;

            // create the panel and paragraph used to show currently selected value (what's shown when drop-down is closed)
            _selectedTextPanel     = new Panel(new Vector2(0, SelectedPanelHeight), skin, Anchor.TopLeft);
            _selectedTextParagraph = UserInterface.DefaultParagraph(string.Empty, Anchor.CenterLeft);
            _selectedTextParagraph.UseActualSizeForCollision = false;
            _selectedTextParagraph.UpdateStyle(SelectList.DefaultParagraphStyle);
            _selectedTextParagraph.UpdateStyle(DefaultParagraphStyle);
            _selectedTextParagraph.UpdateStyle(DefaultSelectedParagraphStyle);
            _selectedTextPanel.AddChild(_selectedTextParagraph, true);
            _selectedTextPanel._hiddenInternalEntity = true;

            // create the arrow down icon
            _arrowDownImage = new Image(Resources.ArrowDown, new Vector2(ArrowSize, ArrowSize), ImageDrawMode.Stretch, Anchor.CenterRight, new Vector2(-10, 0));
            _selectedTextPanel.AddChild(_arrowDownImage, true);
            _arrowDownImage._hiddenInternalEntity = true;
            _arrowDownImage.Visible = showArrow;

            // create the list component
            _selectList = new SelectList(new Vector2(0f, size.Y), Anchor.TopCenter, Vector2.Zero, listSkin ?? skin);

            // update list offset and space before
            _selectList.SetOffset(new Vector2(0, SelectedPanelHeight));
            _selectList.SpaceBefore           = Vector2.Zero;
            _selectList._hiddenInternalEntity = true;

            // add the header and select list as children
            AddChild(_selectedTextPanel);
            AddChild(_selectList);

            // add callback on list value change
            _selectList.OnValueChange = (Entity entity) =>
            {
                // hide list
                ListVisible = false;

                // set selected text
                _selectedTextParagraph.Text = (SelectedValue ?? DefaultText);
            };

            // on click, always hide the selectlist
            _selectList.OnClick = (Entity entity) =>
            {
                ListVisible = false;
            };

            // hide the list by default
            _selectList.Visible = false;

            // setup the callback to show / hide the list when clicking the dropbox
            _selectedTextPanel.OnClick = (Entity self) =>
            {
                // change visibility
                ListVisible = !ListVisible;
            };

            // set starting text
            _selectedTextParagraph.Text = (SelectedValue ?? DefaultText);

            // update styles
            _selectList.UpdateStyle(DefaultStyle);

            // make the list events trigger the dropdown events
            _selectList.PropagateEventsTo(this);

            // make the selected value panel trigger the dropdown events
            _selectedTextPanel.PropagateEventsTo(this);
        }
Example #16
0
        /// <summary>
        /// Create the DropDown list.
        /// </summary>
        /// <param name="size">List size (refers to the whole size of the list + the header when dropdown list is opened).</param>
        /// <param name="anchor">Position anchor.</param>
        /// <param name="offset">Offset from anchor position.</param>
        /// <param name="skin">Panel skin to use for this DropDown list and header.</param>
        public DropDown(Vector2 size, Anchor anchor = Anchor.Auto, Vector2?offset = null, PanelSkin skin = PanelSkin.ListBackground) :
            base(size, anchor, offset)
        {
            // default padding of self is 0
            Padding = Vector2.Zero;

            // to get collision right when list is opened
            UseActualSizeForCollision = true;

            // create the panel and paragraph used to show currently selected value (what's shown when drop-down is closed)
            _selectedTextPanel     = new Panel(new Vector2(0, SelectedPanelHeight), skin, Anchor.TopLeft);
            _selectedTextParagraph = UserInterface.DefaultParagraph(string.Empty, Anchor.CenterLeft);
            _selectedTextParagraph.UseActualSizeForCollision = false;
            _selectedTextParagraph.UpdateStyle(SelectList.DefaultParagraphStyle);
            _selectedTextParagraph.UpdateStyle(DefaultParagraphStyle);
            _selectedTextParagraph.UpdateStyle(DefaultSelectedParagraphStyle);
            _selectedTextPanel.AddChild(_selectedTextParagraph, true);

            // create the arrow down icon
            _arrowDownImage = new Image(Resources.ArrowDown, new Vector2(ArrowSize, ArrowSize), ImageDrawMode.Stretch, Anchor.CenterRight, new Vector2(-10, 0));
            _selectedTextPanel.AddChild(_arrowDownImage, true);

            // create the list component
            _selectList = new SelectList(size, Anchor.TopCenter, Vector2.Zero, skin);

            // update list offset and space before
            _selectList.SetOffset(new Vector2(0, SelectedPanelHeight));
            _selectList.SpaceBefore = Vector2.Zero;

            // add the header and select list as children
            AddChild(_selectedTextPanel);
            AddChild(_selectList);

            // add callback on list value change
            _selectList.OnValueChange = (Entity entity) =>
            {
                // hide list
                ListVisible = false;

                // set selected text
                _selectedTextParagraph.Text = (SelectedValue ?? DefaultText);
            };

            // hide the list by default
            _selectList.Visible = false;

            // setup the callback to show / hide the list when clicking the dropbox
            _selectedTextPanel.OnClick = (Entity self) =>
            {
                // change visibility
                ListVisible = !ListVisible;
            };

            // set starting text
            _selectedTextParagraph.Text = (SelectedValue ?? DefaultText);

            // update styles
            _selectList.UpdateStyle(DefaultStyle);

            // make the list events trigger the dropdown events
            _selectList.OnListChange       += (Entity entity) => { OnListChange?.Invoke(this); };
            _selectList.OnMouseDown        += (Entity entity) => { OnMouseDown?.Invoke(this); };
            _selectList.OnMouseReleased    += (Entity entity) => { OnMouseReleased?.Invoke(this); };
            _selectList.WhileMouseDown     += (Entity entity) => { WhileMouseDown?.Invoke(this); };
            _selectList.WhileMouseHover    += (Entity entity) => { WhileMouseHover?.Invoke(this); };
            _selectList.OnClick            += (Entity entity) => { OnClick?.Invoke(this); };
            _selectList.OnValueChange      += (Entity entity) => { OnValueChange?.Invoke(this); };
            _selectList.OnMouseEnter       += (Entity entity) => { OnMouseEnter?.Invoke(this); };
            _selectList.OnMouseLeave       += (Entity entity) => { OnMouseLeave?.Invoke(this); };
            _selectList.OnMouseWheelScroll += (Entity entity) => { OnMouseWheelScroll?.Invoke(this); };
            _selectList.OnStartDrag        += (Entity entity) => { OnStartDrag?.Invoke(this); };
            _selectList.OnStopDrag         += (Entity entity) => { OnStopDrag?.Invoke(this); };
            _selectList.WhileDragging      += (Entity entity) => { WhileDragging?.Invoke(this); };
            _selectList.BeforeDraw         += (Entity entity) => { BeforeDraw?.Invoke(this); };
            _selectList.AfterDraw          += (Entity entity) => { AfterDraw?.Invoke(this); };
            _selectList.BeforeUpdate       += (Entity entity) => { BeforeUpdate?.Invoke(this); };
            _selectList.AfterUpdate        += (Entity entity) => { AfterUpdate?.Invoke(this); };

            // make the selected value panel trigger the dropdown events
            _selectedTextPanel.OnMouseDown        += (Entity entity) => { OnMouseDown?.Invoke(this); };
            _selectedTextPanel.OnMouseReleased    += (Entity entity) => { OnMouseReleased?.Invoke(this); };
            _selectedTextPanel.WhileMouseDown     += (Entity entity) => { WhileMouseDown?.Invoke(this); };
            _selectedTextPanel.WhileMouseHover    += (Entity entity) => { WhileMouseHover?.Invoke(this); };
            _selectedTextPanel.OnClick            += (Entity entity) => { OnClick?.Invoke(this); };
            _selectedTextPanel.OnValueChange      += (Entity entity) => { OnValueChange?.Invoke(this); };
            _selectedTextPanel.OnMouseEnter       += (Entity entity) => { OnMouseEnter?.Invoke(this); };
            _selectedTextPanel.OnMouseLeave       += (Entity entity) => { OnMouseLeave?.Invoke(this); };
            _selectedTextPanel.OnMouseWheelScroll += (Entity entity) => { OnMouseWheelScroll?.Invoke(this); };
            _selectedTextPanel.OnStartDrag        += (Entity entity) => { OnStartDrag?.Invoke(this); };
            _selectedTextPanel.OnStopDrag         += (Entity entity) => { OnStopDrag?.Invoke(this); };
            _selectedTextPanel.WhileDragging      += (Entity entity) => { WhileDragging?.Invoke(this); };
            _selectedTextPanel.BeforeDraw         += (Entity entity) => { BeforeDraw?.Invoke(this); };
            _selectedTextPanel.AfterDraw          += (Entity entity) => { AfterDraw?.Invoke(this); };
            _selectedTextPanel.BeforeUpdate       += (Entity entity) => { BeforeUpdate?.Invoke(this); };
            _selectedTextPanel.AfterUpdate        += (Entity entity) => { AfterUpdate?.Invoke(this); };
        }
Example #17
0
        /// <summary>
        /// Create the DropDown list.
        /// </summary>
        /// <param name="size">List size (refers to the whole size of the list + the header when dropdown list is opened).</param>
        /// <param name="anchor">Position anchor.</param>
        /// <param name="offset">Offset from anchor position.</param>
        /// <param name="skin">Panel skin to use for this DropDown list and header.</param>
        public DropDown(Vector2 size, Anchor anchor = Anchor.Auto, Vector2?offset = null, PanelSkin skin = PanelSkin.ListBackground) :
            base(size, anchor, offset, skin)
        {
            // create the panel and paragraph used to show selected value
            _selectedTextPanel     = new Panel(new Vector2(0, SelectedPanelHeight), skin, Anchor.TopLeft);
            _selectedTextParagraph = new Paragraph("", Anchor.CenterLeft, new Vector2(0, SelectedPanelHeight + 8));
            _selectedTextParagraph.UseActualSizeForCollision = false;
            _selectedTextParagraph.UpdateStyle(SelectList.DefaultParagraphStyle);
            _selectedTextParagraph.UpdateStyle(DefaultParagraphStyle);
            _selectedTextParagraph.UpdateStyle(DefaultSelectedParagraphStyle);
            _selectedTextPanel.AddChild(_selectedTextParagraph, true);

            // create the arrow down icon
            Image arrow = new Image(Resources.ArrowDown, new Vector2(30, 30), ImageDrawMode.Stretch, Anchor.CenterRight, new Vector2(-10, 0));

            _selectedTextPanel.AddChild(arrow, true);

            // setup the callback to show / hide the list when clicking the dropbox
            _selectedTextPanel.OnClick = (Entity self) =>
            {
                _isListVisible = !_isListVisible;
                OnResize();
            };

            // update styles
            UpdateStyle(DefaultStyle);

            // make sure default state is without children, eg list is hidden
            ClearChildren();
        }
Example #18
0
        /// <summary>
        /// Generate and return a set of panels aligned next to each other with a constant size.
        /// This is useful for cases like when you want to divide your panel into 3 colums.
        /// </summary>
        /// <param name="amount">How many panels to create.</param>
        /// <param name="parent">Optional parent entity to add panels to.</param>
        /// <param name="columnSize">Size of every column. If not set will be 1f / amount with auto-set height.</param>
        /// <param name="skin">Panels skin to use (default to None, making them invisible.</param>
        /// <returns>Array with generated panels.</returns>
        public static Panel[] GenerateColums(int amount, Entity parent, Vector2?columnSize = null, PanelSkin skin = PanelSkin.None)
        {
            // list of panels to return
            List <Panel> retList = new List <Panel>();

            // default column size
            columnSize = columnSize ?? new Vector2(1f / amount, -1);

            // create panels
            for (int i = 0; i < amount; ++i)
            {
                Panel currPanel = new Panel(parent._userinterface, columnSize.Value, skin, Anchor.AutoInlineNoBreak);
                currPanel.Padding = Vector2.Zero;
                retList.Add(currPanel);
                if (parent != null)
                {
                    parent.AddChild(currPanel);
                }
            }

            // return result panels
            return(retList.ToArray());
        }
Example #19
0
 /// <summary>
 /// Create the panel with default params.
 /// </summary>
 public Panel(UserInterface ui, PanelSkin skin) :
     this(ui, new Vector2(500, 500), skin)
 {
 }
Example #20
0
        /// <summary>
        /// Add a new tab to the panel tabs.
        /// </summary>
        /// <param name="name">Tab name (also what will appear on the panel button).</param>
        /// <param name="panelSkin">Panel skin to use for this panel.</param>
        /// <returns>The new tab we created - contains the panel and the button to switch it.</returns>
        public TabData AddTab(string name, PanelSkin panelSkin = PanelSkin.None)
        {
            // create new panel and button
            Panel  newPanel  = new Panel(Vector2.Zero, panelSkin, Anchor.TopCenter);
            Button newButton = new Button(name, ButtonSkin.Default, Anchor.AutoInline, new Vector2(-1, -1));

            // create the new tab data
            TabData newTab = new TabData(name, newPanel, newButton);

            // link tab data to panel
            newTab.panel.AttachedData = newTab;

            // set button styles
            newTab.button.UpdateStyle(DefaultButtonStyle);
            newTab.button.ButtonParagraph.UpdateStyle(DefaultButtonParagraphStyle);

            // add new tab to tabs list
            _tabs.Add(newTab);

            // update all button sizes
            float width = 1f / (float)_tabs.Count;

            if (width == 1)
            {
                width = 0;
            }
            foreach (TabData data in _tabs)
            {
                data.button.Size = new Vector2(width, data.button.Size.Y);
            }

            // set button to togglemode and unchecked
            newTab.button.ToggleMode = true;
            newTab.button.Checked    = false;

            // set identifiers for panel and button
            newTab.button.Identifier = "tab-button-" + name;
            newTab.panel.Identifier  = "tab-panel-" + name;

            // by default all panels are hidden
            newTab.panel.Visible = false;

            // attach callback to newly created button
            newTab.button.OnValueChange = (Entity entity) =>
            {
                // get self as a button
                Button self = (Button)(entity);

                // clear the currently active panel
                Panel prevActive = _activeTab != null ? _activeTab.panel : null;
                _activeTab = null;

                // if we were checked, uncheck all the other buttons
                if (self.Checked)
                {
                    // un-toggle all the other buttons
                    foreach (TabData data in _tabs)
                    {
                        Button iterButton = data.button;
                        if (iterButton != self && iterButton.Checked)
                        {
                            iterButton.Checked = false;
                        }
                    }
                }

                // get the panel associated with this tab button.
                Panel selfPanel = _panelsPanel.Find <Panel>("tab-panel-" + name);

                // show / hide the panel
                selfPanel.Visible = self.Checked;

                // if our new value is checked, set as the currently active tab
                if (self.Checked)
                {
                    _activeTab = (TabData)selfPanel.AttachedData;
                }

                // if at this phase there's no active panel, revert by checking self again
                // it could happen if user click the same tab button twice or via code.
                if (_activeTab == null && prevActive == selfPanel)
                {
                    self.Checked = true;
                }

                // invoke change event
                if (self.Checked)
                {
                    DoOnValueChange();
                }
            };

            // add button and panel to their corresponding containers
            _panelsPanel.AddChild(newTab.panel);
            _buttonsPanel.AddChild(newTab.button);

            // if its first button, set it as checked
            if (_tabs.Count == 1)
            {
                newTab.button.Checked = true;
            }

            // set as dirty to recalculate destination rect
            MarkAsDirty();

            // return the newly created tab data (panel + button)
            return(newTab);
        }
Example #21
0
        /// <summary>
        /// Create the text input.
        /// </summary>
        /// <param name="multiline">If true, text input will accept multiple lines.</param>
        /// <param name="size">Input box size.</param>
        /// <param name="anchor">Position anchor.</param>
        /// <param name="offset">Offset from anchor position.</param>
        /// <param name="skin">TextInput skin, eg which texture to use.</param>
        public TextInput(UserInterface ui, bool multiline, Vector2 size, Anchor anchor = Anchor.Auto, Vector2?offset = null, PanelSkin skin = PanelSkin.ListBackground) :
            base(ui, size, skin, anchor, offset)
        {
            // set multiline mode
            _multiLine = multiline;

            // update default style
            UpdateStyle(DefaultStyle);

            // default size of multiline text input is 4 times bigger
            if (multiline)
            {
                SetStyleProperty(StylePropertyIds.DefaultSize, new DataTypes.StyleProperty(EntityDefaultSize * new Vector2(1, 4)));
            }

            // set limit by size - default true in single-line, default false in multi-line
            LimitBySize = !_multiLine;

            if (!_userinterface.Active._isDeserializing)
            {
                // create paragraph to show current value
                TextParagraph = _userinterface.DefaultParagraph(string.Empty, Anchor.TopLeft);
                TextParagraph.UpdateStyle(DefaultParagraphStyle);
                TextParagraph._hiddenInternalEntity = true;
                TextParagraph.Identifier            = "_TextParagraph";
                AddChild(TextParagraph, true);

                // create the placeholder paragraph
                PlaceholderParagraph = _userinterface.DefaultParagraph(string.Empty, Anchor.TopLeft);
                PlaceholderParagraph.UpdateStyle(DefaultPlaceholderStyle);
                PlaceholderParagraph._hiddenInternalEntity = true;
                PlaceholderParagraph.Identifier            = "_PlaceholderParagraph";
                AddChild(PlaceholderParagraph, true);

                // update multiline related stuff
                UpdateMultilineState();

                // if the default paragraph type is multicolor, disable it for input
                RichParagraph colorTextParagraph = TextParagraph as RichParagraph;
                if (colorTextParagraph != null)
                {
                    colorTextParagraph.EnableStyleInstructions = false;
                }
            }
        }
Example #22
0
 /// <summary>
 /// Create the panel.
 /// </summary>
 /// <param name="size">Panel size.</param>
 /// <param name="skin">Panel skin (texture to use). Use PanelSkin.None for invisible panels.</param>
 /// <param name="anchor">Position anchor.</param>
 /// <param name="offset">Offset from anchor position.</param>
 public PanelBase(UserInterface ui, Vector2 size, PanelSkin skin, Anchor anchor = Anchor.Center, Vector2?offset = null) :
     base(ui, size, anchor, offset)
 {
     _skin = skin;
     UpdateStyle(Panel.DefaultStyle);
 }