Пример #1
0
        public ISkin CreateSkin()
        {
            AGSSkin skin = new AGSSkin();

            skin.AddRule(entity => entity.GetComponent <IButtonComponent>() != null, entity =>
            {
                var border             = entity.GetComponent <IBorderComponent>();
                var button             = entity.GetComponent <IButtonComponent>();
                button.IdleAnimation   = getAnimation(border, ButtonIdleAnimation);
                button.HoverAnimation  = getAnimation(border, ButtonHoverAnimation);
                button.PushedAnimation = getAnimation(border, ButtonPushedAnimation);
            });

            skin.AddRule(entity => entity.GetComponent <ICheckboxComponent>() != null, entity =>
            {
                var border = entity.GetComponent <IBorderComponent>();
                var button = entity.GetComponent <ICheckboxComponent>();
                button.NotCheckedAnimation      = getAnimation(border, CheckboxNotCheckedAnimation);
                button.CheckedAnimation         = getAnimation(border, CheckboxCheckedAnimation);
                button.HoverCheckedAnimation    = getAnimation(border, CheckboxHoverCheckedAnimation);
                button.HoverNotCheckedAnimation = getAnimation(border, CheckboxHoverNotCheckedAnimation);
            });

            skin.AddRule(entity =>
            {
                var skinComponent = entity.GetComponent <ISkinComponent>();
                return(skinComponent != null && skinComponent.SkinTags.Contains(AGSSkin.DropDownButtonTag));
            }, entity =>
            {
                var textComponent  = entity.GetComponent <ITextComponent>();
                textComponent.Text = "\u25BE"; //Unicode for down arrow. Another option is "\u25BC";
            });

            skin.AddRule(entity =>
            {
                var skinComponent = entity.GetComponent <ISkinComponent>();
                return(skinComponent != null && skinComponent.SkinTags.Contains(AGSSkin.DialogBoxTag));
            }, entity =>
            {
                var imageComponent  = entity.GetComponent <IImageComponent>();
                var borderComponent = entity.GetComponent <IBorderComponent>();
                if (imageComponent != null)
                {
                    imageComponent.Tint = DialogBoxColor;
                }
                if (borderComponent != null)
                {
                    borderComponent.Border = DialogBoxBorder;
                }
            });

            skin.AddRule(entity =>
            {
                var skinComponent = entity.GetComponent <ISkinComponent>();
                return(skinComponent != null && skinComponent.SkinTags.Contains(AGSSkin.CheckBoxTag));
            }, entity =>
            {
                var checkBoxComponent = entity.GetComponent <ICheckboxComponent>();
                if (checkBoxComponent == null)
                {
                    return;
                }
                var textComponent          = entity.GetComponent <ITextComponent>();
                const string checkedStr    = "\u2611";
                const string notCheckedStr = "\u2610";
                if (!textComponent.Text.StartsWith(checkedStr) && !textComponent.Text.StartsWith(notCheckedStr))
                {
                    textComponent.Text = (checkBoxComponent.Checked ? checkedStr : notCheckedStr) + textComponent.Text;
                }
                checkBoxComponent.OnCheckChanged.Subscribe(_ =>
                {
                    textComponent.Text = (checkBoxComponent.Checked ? checkedStr : notCheckedStr) + textComponent.Text.Substring(1);
                });
            });

            skin.AddRule <ITextComponent>(text =>
            {
                var textConfig = TextConfig;
                if (textConfig == null)
                {
                    return;
                }
                text.TextConfig = textConfig;
            });

            skin.AddRule <ITextBoxComponent>(entity =>
            {
                var image  = entity.GetComponent <IImageComponent>();
                var border = entity.GetComponent <IBorderComponent>();
                if (image != null)
                {
                    image.Tint = TextBoxBackColor;
                }
                if (border != null)
                {
                    border.Border = TextBoxBorderStyle;
                }
            });

            return(skin);
        }
Пример #2
0
        public ISkin CreateSkin()
        {
            AGSSkin skin = new AGSSkin();

            skin.AddRule <IButtonComponent>(button =>
            {
                button.IdleAnimation             = new AGSSingleFrameAnimation(new EmptyImage(DefaultItemSize), _factory);
                button.IdleAnimation.Sprite.Tint = ButtonIdleBackColor;

                button.HoverAnimation             = new AGSSingleFrameAnimation(new EmptyImage(DefaultItemSize), _factory);
                button.HoverAnimation.Sprite.Tint = ButtonHoverBackColor;

                button.PushedAnimation             = new AGSSingleFrameAnimation(new EmptyImage(DefaultItemSize), _factory);
                button.PushedAnimation.Sprite.Tint = ButtonPushedBackColor;
            });

            skin.AddRule <IButtonComponent>(entity =>
            {
                var animationContainer = entity.GetComponent <IAnimationContainer>();
                if (animationContainer == null)
                {
                    return;
                }
                animationContainer.Border = ButtonBorderStyle;
            });

            skin.AddRule <ICheckboxComponent>(checkBox =>
            {
                checkBox.NotCheckedAnimation             = new AGSSingleFrameAnimation(new EmptyImage(DefaultItemSize), _factory);
                checkBox.NotCheckedAnimation.Sprite.Tint = CheckboxNotCheckedColor;

                checkBox.CheckedAnimation             = new AGSSingleFrameAnimation(new EmptyImage(DefaultItemSize), _factory);
                checkBox.CheckedAnimation.Sprite.Tint = CheckboxCheckedColor;

                checkBox.HoverNotCheckedAnimation             = new AGSSingleFrameAnimation(new EmptyImage(DefaultItemSize), _factory);
                checkBox.HoverNotCheckedAnimation.Sprite.Tint = CheckboxHoverNotCheckedColor;

                checkBox.HoverCheckedAnimation             = new AGSSingleFrameAnimation(new EmptyImage(DefaultItemSize), _factory);
                checkBox.HoverCheckedAnimation.Sprite.Tint = CheckboxHoverCheckedColor;
            });

            skin.AddRule <ICheckboxComponent>(entity =>
            {
                var animationContainer = entity.GetComponent <IAnimationContainer>();
                if (animationContainer == null)
                {
                    return;
                }
                animationContainer.Border = CheckboxBorderStyle;
            });

            skin.AddRule(entity =>
            {
                var skinComponent = entity.GetComponent <ISkinComponent>();
                return(skinComponent != null && skinComponent.SkinTags.Contains(AGSSkin.DropDownButtonTag));
            }, entity =>
            {
                var textComponent  = entity.GetComponent <ITextComponent>();
                textComponent.Text = "\u25BE";//Unicode for down arrow. Another option is "\u25BC";
            });

            skin.AddRule(entity =>
            {
                var skinComponent = entity.GetComponent <ISkinComponent>();
                return(skinComponent != null && skinComponent.SkinTags.Contains(AGSSkin.DialogBoxTag));
            }, entity =>
            {
                var imageComponent = entity.GetComponent <IImageComponent>();
                if (imageComponent != null)
                {
                    imageComponent.Tint = DialogBoxColor;
                }
                var animationContainer = entity.GetComponent <IAnimationContainer>();
                if (animationContainer != null)
                {
                    animationContainer.Border = DialogBoxBorder;
                }
            });

            skin.AddRule(entity =>
            {
                var skinComponent = entity.GetComponent <ISkinComponent>();
                return(skinComponent != null && skinComponent.SkinTags.Contains(AGSSkin.CheckBoxTag));
            }, entity =>
            {
                var checkBoxComponent = entity.GetComponent <ICheckboxComponent>();
                if (checkBoxComponent == null)
                {
                    return;
                }
                var textComponent          = entity.GetComponent <ITextComponent>();
                const string checkedStr    = "\u2611";
                const string notCheckedStr = "\u2610";
                if (!textComponent.Text.StartsWith(checkedStr) && !textComponent.Text.StartsWith(notCheckedStr))
                {
                    textComponent.Text = (checkBoxComponent.Checked ? checkedStr : notCheckedStr) + textComponent.Text;
                }
                checkBoxComponent.OnCheckChanged.Subscribe((sender, args) =>
                {
                    textComponent.Text = (checkBoxComponent.Checked ? checkedStr : notCheckedStr) + textComponent.Text.Substring(1);
                });
            });

            skin.AddRule <ITextComponent>(text =>
            {
                var textConfig = TextConfig;
                if (textConfig == null)
                {
                    return;
                }
                text.TextConfig = textConfig;
            });

            skin.AddRule <ITextBoxComponent>(entity =>
            {
                var animationContainer = entity.GetComponent <IAnimationContainer>();
                var image = entity.GetComponent <IImageComponent>();
                if (animationContainer == null)
                {
                    return;
                }
                image.Tint = TextBoxBackColor;
                animationContainer.Border = TextBoxBorderStyle;
            });

            return(skin);
        }