Example #1
0
        /// <summary>
        /// Lays out the dialog title bar and close button.
        /// </summary>
        /// <param name="layout">The layout manager for the dialog.</param>
        /// <param name="onClose">The action to invoke when close is pressed.</param>
        private void LayoutTitle(PGridLayoutGroup layout, PUIDelegates.OnButtonPressed
                                 onClose)
        {
            // Title text, expand to width
            var title = new PLabel("Title")
            {
                Margin = new RectOffset(3, 4, 0, 0), Text = Title, FlexSize = Vector2.one
            }.SetKleiPinkColor().Build();

            layout.AddComponent(title, new GridComponentSpec(0, 0)
            {
                Margin = new RectOffset(0, -2, 0, 0)
            });
            // Black border on the title bar overlaps the edge, but 0 margins so should be OK
            // Fixes the 2px bug handily!
            var titleBG = title.AddOrGet <Image>();

            titleBG.sprite = PUITuning.Images.BoxBorder;
            titleBG.type   = Image.Type.Sliced;
            // Close button
            layout.AddComponent(new PButton(DIALOG_KEY_CLOSE)
            {
                Sprite     = PUITuning.Images.Close, Margin = CLOSE_ICON_MARGIN, OnClick = onClose,
                SpriteSize = CLOSE_ICON_SIZE, ToolTip = STRINGS.UI.TOOLTIPS.CLOSETOOLTIP
            }.SetKleiBlueStyle().Build(), new GridComponentSpec(0, 1));
        }
Example #2
0
        /// <summary>
        /// Creates the user buttons.
        /// </summary>
        /// <param name="layout">The location to add the buttons.</param>
        /// <param name="onPressed">The handler to call when any button is pressed.</param>
        private void CreateUserButtons(PGridLayoutGroup layout,
                                       PUIDelegates.OnButtonPressed onPressed)
        {
            var buttonPanel = new PPanel("Buttons")
            {
                Alignment = TextAnchor.LowerCenter, Spacing = 7, Direction = PanelDirection.
                                                                             Horizontal, Margin = new RectOffset(5, 5, 0, 10)
            };
            int i = 0;

            // Add each user button
            foreach (var button in buttons)
            {
                string key     = button.key;
                var    bgColor = button.backColor;
                var    fgColor = button.textColor ?? PUITuning.Fonts.UILightStyle;
                var    db      = new PButton(key)
                {
                    Text    = button.text, ToolTip = button.tooltip, Margin = BUTTON_MARGIN,
                    OnClick = onPressed, Color = bgColor, TextStyle = fgColor
                };
                // Last button is special and gets a pink color
                if (bgColor == null)
                {
                    if (++i >= buttons.Count)
                    {
                        db.SetKleiPinkStyle();
                    }
                    else
                    {
                        db.SetKleiBlueStyle();
                    }
                }
                buttonPanel.AddChild(db);
            }
            layout.AddComponent(buttonPanel.Build(), new GridComponentSpec(2, 0)
            {
                ColumnSpan = 2
            });
        }