Exemplo n.º 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));
        }
Exemplo n.º 2
0
        public override GameObject Build()
        {
            var button = PUIElements.CreateUI(Name);
            // Background
            var kImage    = button.AddComponent <KImage>();
            var trueColor = Color ?? PUITuning.Colors.ButtonPinkStyle;

            kImage.colorStyleSetting = trueColor;
            kImage.color             = trueColor.inactiveColor;
            kImage.sprite            = PUITuning.Images.ButtonBorder;
            kImage.type = Image.Type.Sliced;
            // Set on click event
            var kButton = button.AddComponent <KButton>();
            var evt     = OnClick;

            if (evt != null)
            {
                kButton.onClick += () => {
                    evt?.Invoke(button);
                }
            }
            ;
            kButton.additionalKImages = new KImage[0];
            kButton.soundPlayer       = PUITuning.ButtonSounds;
            kButton.bgImage           = kImage;
            // Add foreground image since the background already has one
            if (Sprite != null)
            {
                kButton.fgImage = ImageChildHelper(button, Sprite, SpriteTransform, SpriteSize);
            }
            // Set colors
            kButton.colorStyleSetting = trueColor;
            // Add text
            if (!string.IsNullOrEmpty(Text))
            {
                PLabel.TextChildHelper(button, TextStyle ?? PUITuning.Fonts.UILightStyle, Text);
            }
            // Add tooltip
            if (!string.IsNullOrEmpty(ToolTip))
            {
                button.AddComponent <ToolTip>().toolTip = ToolTip;
            }
            button.SetActive(true);
            // Icon and text are side by side
            var lp = new BoxLayoutParams()
            {
                Spacing   = IconSpacing, Direction = PanelDirection.Horizontal, Margin = Margin,
                Alignment = TextAlignment
            };

            if (DynamicSize)
            {
                button.AddComponent <BoxLayoutGroup>().Params = lp;
            }
            else
            {
                BoxLayoutGroup.LayoutNow(button, lp);
            }
            button.SetFlexUISize(FlexSize);
            InvokeRealize(button);
            return(button);
        }