Esempio n. 1
0
 private ButtonAnimation getAnimation(IAnimationComponent container, ButtonAnimation animation)
 {
     if (animation.Border == null || container == null || container.Border == null) return animation;
     ButtonAnimation newAnimation = new ButtonAnimation(AGSBorders.Multiple(container.Border, animation.Border),
                                                        animation.TextConfig, animation.Tint);
     newAnimation.Animation = animation.Animation;
     return newAnimation;
 }
Esempio n. 2
0
        private (ButtonAnimation idle, ButtonAnimation hovered, ButtonAnimation pushed) getArrowButtonAnimations(ArrowDirection direction, float lineWidth)
        {
            var whiteArrow = AGSBorders.Multiple(AGSBorders.SolidColor(Colors.WhiteSmoke, lineWidth),
                                                 _graphics.Icons.GetArrowIcon(direction, Colors.WhiteSmoke));
            var yellowArrow = AGSBorders.Multiple(AGSBorders.SolidColor(Colors.Yellow, lineWidth),
                                                  _graphics.Icons.GetArrowIcon(direction, Colors.Yellow));

            return(new ButtonAnimation(whiteArrow, null, Colors.Transparent),
                   new ButtonAnimation(yellowArrow, null, Colors.Transparent),
                   new ButtonAnimation(yellowArrow, null, Colors.White.WithAlpha(100)));
        }
        public void RefreshUI()
        {
            var color = (Color)_property.Prop.GetValue(_property.Object);

            if (_namedColorsReversed.ContainsKey(color.Value))
            {
                _text.Text = _namedColorsReversed[color.Value];
            }
            else
            {
                _text.Text = $"{color.R},{color.G},{color.B},{color.A}";
            }
            _colorLabel.Tint = color;
            _text.Border     = AGSBorders.SolidColor(color, 2f);
            var buttonBorder = AGSBorders.Multiple(AGSBorders.SolidColor(color, 1f),
                                                   _factory.Graphics.Icons.GetArrowIcon(ArrowDirection.Down, color));

            _dropDownButton.IdleAnimation = new ButtonAnimation(buttonBorder, null, Colors.Transparent);
            _dropDownButton.Border        = buttonBorder;
        }
Esempio n. 4
0
        private void selectObject(ITreeStringNode node)
        {
            var obj = node.Properties.Entities.GetValue(Fields.Entity);

            _inspector.Inspector.Show(obj);
            var animation        = obj.GetComponent <IAnimationComponent>();
            var visibleComponent = obj.GetComponent <IVisibleComponent>();
            var image            = obj.GetComponent <IImageComponent>();

            if (animation != null)
            {
                _lastSelectedObject = animation;
                IBorderStyle border = null;
                border            = animation.Border;
                _lastObjectBorder = border;
                IBorderStyle hoverBorder = AGSBorders.Gradient(new FourCorners <Color>(Colors.Yellow, Colors.Yellow.WithAlpha(150),
                                                                                       Colors.Yellow.WithAlpha(150), Colors.Yellow), 1, true);
                if (border == null)
                {
                    animation.Border = hoverBorder;
                }
                else
                {
                    animation.Border = AGSBorders.Multiple(border, hoverBorder);
                }
            }
            if (visibleComponent != null)
            {
                _lastMaskVisible         = visibleComponent.Visible;
                _lastSelectedMaskVisible = visibleComponent;
                visibleComponent.Visible = true;
            }
            if (image != null && image.Opacity == 0)
            {
                _lastOpacity           = image.Opacity;
                _lastSelectedMaskImage = image;
                image.Opacity          = 100;
            }
        }
Esempio n. 5
0
        public ICheckBox GetCheckBox(string id, ButtonAnimation notChecked, ButtonAnimation notCheckedHovered, ButtonAnimation @checked, ButtonAnimation checkedHovered,
                                     float x, float y, IObject parent = null, string text = "", ITextConfig config = null, bool addToUi = true, float width = -1F, float height = -1F, bool isCheckButton = false)
        {
            bool pixelArtButton = notChecked?.Animation != null && notChecked.Animation.Frames.Count > 0;

            if (width == -1f && pixelArtButton)
            {
                width = notChecked.Animation.Frames[0].Sprite.Width;
            }
            if (height == -1f && pixelArtButton)
            {
                height = notChecked.Animation.Frames[0].Sprite.Height;
            }

            var                    idleColor         = Colors.White;
            var                    hoverColor        = Colors.Yellow;
            const float            lineWidth         = 1f;
            const float            padding           = 300f;
            Func <ButtonAnimation> notCheckedDefault = () => new ButtonAnimation(AGSBorders.SolidColor(idleColor, lineWidth), null, Colors.Black);
            Func <ButtonAnimation> checkedDefault    = () =>
            {
                var checkIcon = _graphics.Icons.GetXIcon(color: idleColor, padding: padding);
                return(new ButtonAnimation(AGSBorders.Multiple(AGSBorders.SolidColor(idleColor, lineWidth), checkIcon), null, Colors.Black));
            };
            Func <ButtonAnimation> hoverNotCheckedDefault = () => new ButtonAnimation(AGSBorders.SolidColor(hoverColor, lineWidth), null, Colors.Black);
            Func <ButtonAnimation> hoverCheckedDefault    = () =>
            {
                var checkHoverIcon = _graphics.Icons.GetXIcon(color: hoverColor, padding: padding);
                return(new ButtonAnimation(AGSBorders.Multiple(AGSBorders.SolidColor(hoverColor, lineWidth), checkHoverIcon), null, Colors.Black));
            };

            notChecked        = validateAnimation(id, notChecked, notCheckedDefault, width, height);
            notCheckedHovered = validateAnimation(id, notCheckedHovered, hoverNotCheckedDefault, width, height);
            @checked          = validateAnimation(id, @checked, checkedDefault, width, height);
            checkedHovered    = validateAnimation(id, checkedHovered, hoverCheckedDefault, width, height);
            TypedParameter idParam  = new TypedParameter(typeof(string), id);
            ICheckBox      checkbox = _resolver.Container.Resolve <ICheckBox>(idParam);

            if (!string.IsNullOrEmpty(text))
            {
                checkbox.TextLabel = GetLabel($"{id}_Label", text, 100f, 20f, x + width + 5f, y, parent, config, addToUi);
            }
            if (!isCheckButton)
            {
                checkbox.SkinTags.Add(AGSSkin.CheckBoxTag);
            }
            if (notChecked != null)
            {
                checkbox.NotCheckedAnimation = notChecked;
            }
            if (notCheckedHovered != null)
            {
                checkbox.HoverNotCheckedAnimation = notCheckedHovered;
            }
            if (@checked != null)
            {
                checkbox.CheckedAnimation = @checked;
            }
            if (checkedHovered != null)
            {
                checkbox.HoverCheckedAnimation = checkedHovered;
            }

            checkbox.Tint = pixelArtButton ? Colors.White : Colors.Transparent;
            checkbox.X    = x;
            checkbox.Y    = y;
            setParent(checkbox, parent);

            checkbox.Skin?.Apply(checkbox);
            checkbox.NotCheckedAnimation.StartAnimation(checkbox, checkbox.TextLabel, checkbox, checkbox);

            if (addToUi)
            {
                _gameState.UI.Add(checkbox);
            }

            return(checkbox);
        }
Esempio n. 6
0
        public IComboBox GetComboBox(string id, IButton dropDownButton        = null, ITextBox textBox = null,
                                     Func <string, IButton> itemButtonFactory = null, IObject parent   = null, bool addToUi = true, float defaultWidth = 500f, float defaultHeight = 40f)
        {
            TypedParameter idParam  = new TypedParameter(typeof(string), id);
            IComboBox      comboBox = _resolver.Container.Resolve <IComboBox>(idParam);

            if (parent != null)
            {
                comboBox.RenderLayer = parent.RenderLayer;
            }
            defaultHeight = dropDownButton?.Height ?? textBox?.Height ?? defaultHeight;
            float itemWidth = textBox?.Width ?? defaultWidth;

            if (textBox == null)
            {
                textBox = GetTextBox(id + "_TextBox", 0f, 0f, comboBox, "", new AGSTextConfig(alignment: Alignment.MiddleCenter, autoFit: AutoFit.TextShouldFitLabel),
                                     false, itemWidth, defaultHeight);
                textBox.Border = AGSBorders.SolidColor(Colors.WhiteSmoke, 3f);
                textBox.Tint   = Colors.Transparent;
            }
            else
            {
                setParent(textBox, comboBox);
            }
            textBox.RenderLayer = comboBox.RenderLayer;
            textBox.Enabled     = false;

            if (dropDownButton == null)
            {
                var whiteArrow = AGSBorders.Multiple(AGSBorders.SolidColor(Colors.WhiteSmoke, 3f),
                                                     _graphics.Icons.GetArrowIcon(ArrowDirection.Down, Colors.WhiteSmoke));
                var yellowArrow = AGSBorders.Multiple(AGSBorders.SolidColor(Colors.Yellow, 3f),
                                                      _graphics.Icons.GetArrowIcon(ArrowDirection.Down, Colors.Yellow));
                dropDownButton = GetButton(id + "_DropDownButton",
                                           new ButtonAnimation(whiteArrow, null, Colors.Transparent),
                                           new ButtonAnimation(yellowArrow, null, Colors.Transparent),
                                           new ButtonAnimation(yellowArrow, null, Colors.White.WithAlpha(100)),
                                           0f, 0f, comboBox, "", null,
                                           false, 30f, defaultHeight);

                dropDownButton.Border = whiteArrow;
            }
            else
            {
                setParent(dropDownButton, comboBox);
            }
            dropDownButton.RenderLayer = comboBox.RenderLayer;
            dropDownButton.Z           = textBox.Z - 1;
            dropDownButton.SkinTags.Add(AGSSkin.DropDownButtonTag);
            dropDownButton.Skin?.Apply(dropDownButton);

            var dropDownPanelLayer = new AGSRenderLayer(comboBox.RenderLayer.Z - 1, comboBox.RenderLayer.ParallaxSpeed, comboBox.RenderLayer.IndependentResolution); //Making sure that the drop-down layer is rendered before the combobox layer, so that it will appear in front of other ui elements that may be below.

            if (itemButtonFactory == null)
            {
                var yellowBrush = _graphics.Brushes.LoadSolidBrush(Colors.Yellow);
                var whiteBrush  = _graphics.Brushes.LoadSolidBrush(Colors.White);
                itemButtonFactory = text =>
                {
                    var button = GetButton(id + "_" + text,
                                           new ButtonAnimation(null, new AGSTextConfig(whiteBrush, autoFit: AutoFit.LabelShouldFitText), null),
                                           new ButtonAnimation(null, new AGSTextConfig(yellowBrush, autoFit: AutoFit.LabelShouldFitText), null),
                                           new ButtonAnimation(null, new AGSTextConfig(yellowBrush, outlineBrush: whiteBrush, outlineWidth: 0.5f, autoFit: AutoFit.LabelShouldFitText), null),
                                           0f, 0f, width: itemWidth, height: defaultHeight);
                    button.Pivot       = new PointF(0f, 1f);
                    button.RenderLayer = dropDownPanelLayer;
                    return(button);
                };
            }

            var dropDownPanel = GetPanel(id + "_DropDownPanel", new EmptyImage(1f, 1f), 0f, 0f, comboBox);

            dropDownPanel.AddComponent <IBoundingBoxWithChildrenComponent>();
            dropDownPanel.AddComponent <IStackLayoutComponent>();
            dropDownPanel.Border      = AGSBorders.SolidColor(Colors.White, 3f);
            dropDownPanel.Tint        = Colors.Black;
            dropDownPanel.RenderLayer = dropDownPanelLayer;
            var listBox = dropDownPanel.AddComponent <IListboxComponent>();

            listBox.ItemButtonFactory = itemButtonFactory;
            listBox.MaxHeight         = 300f;
            CreateScrollingPanel(dropDownPanel);

            comboBox.DropDownButton = dropDownButton;
            comboBox.TextBox        = textBox;
            comboBox.DropDownPanel  = dropDownPanel;

            setParent(comboBox, parent);

            if (addToUi)
            {
                _gameState.UI.Add(textBox);
                _gameState.UI.Add(dropDownButton);
                _gameState.UI.Add(comboBox);
            }

            return(comboBox);
        }