Ejemplo n.º 1
0
 public ButtonAnimation(IAnimation animation, IBorderStyle border, ITextConfig textConfig, Color?tint)
 {
     Border     = border;
     TextConfig = textConfig;
     Tint       = tint;
     Animation  = animation;
 }
Ejemplo n.º 2
0
        public void Render(IObject obj, IViewport viewport)
        {
            ISprite sprite = obj.Animation?.Sprite;

            if (sprite == null || sprite.Image == null)
            {
                return;
            }
            var boundingBoxes = obj.GetBoundingBoxes(viewport);

            if (boundingBoxes == null || !boundingBoxes.RenderBox.IsValid)
            {
                return;
            }

            ITexture texture = _textures.GetOrAdd(sprite.Image.ID, _createTextureFunc);

            _colorAdjusters[0] = sprite;
            _colorAdjusters[1] = obj;
            IGLColor color = _colorBuilder.Build(_colorAdjusters);

            IBorderStyle   border    = obj.Border;
            AGSBoundingBox borderBox = _emptySquare;

            if (!obj.Visible)
            {
                return;
            }
            if (border != null)
            {
                if (boundingBoxes.RenderBox.BottomLeft.X > boundingBoxes.RenderBox.BottomRight.X)
                {
                    borderBox = boundingBoxes.RenderBox.FlipHorizontal();
                }
                else
                {
                    borderBox = boundingBoxes.RenderBox;
                }

                border.RenderBorderBack(borderBox);
            }
            _renderer.Render(texture.ID, boundingBoxes, color);

            border?.RenderBorderFront(borderBox);
            if (obj.DebugDrawPivot)
            {
                IObject parent = obj.TreeNode.Parent;
                float   x      = obj.X;
                float   y      = obj.Y;
                while (parent != null)
                {
                    x     += (parent.X - parent.Width * parent.Pivot.X);
                    y     += (parent.Y - parent.Height * parent.Pivot.Y);
                    parent = parent.TreeNode.Parent;
                }
                _glUtils.DrawCross(x - viewport.X, y - viewport.Y, 10, 10, 1f, 1f, 1f, 1f);
            }
        }
Ejemplo n.º 3
0
        public void Apply(GridDefinition grid)
        {
            var styles = new IBorderStyle[]
            {
                new LeftBorderStyle(),
                new RightBorderStyle(),
                new TopBorderStyle(),
                new BottomBorderStyle()
            };

            foreach (var style in styles)
            {
                style.Apply(grid);
            }
        }
Ejemplo n.º 4
0
        public static void DrawRoundRectangle(Graphics g, IBorderStyle arg)
        {
            if (g == null || arg.BorderWidth == 0)
            {
                return;
            }

            using (var path = CreateRoundPath(arg.Rectangle, arg.CornerRadiu))
            {
                g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                g.SmoothingMode = SmoothingMode.HighQuality;
                using (var pen = new Pen(new SolidBrush(arg.BorderColor), arg.BorderWidth))
                    g.DrawPath(pen, path);
            }
        }
Ejemplo n.º 5
0
        public static void DrawRoundRectangle(Graphics g, IBorderStyle arg)
        {
            if (g == null || arg.BorderWidth == 0)
            {
                return;
            }

            using (var path = CreateRoundPath(arg.Rectangle, arg.CornerRadiu))
            {
                g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                g.SmoothingMode     = SmoothingMode.HighQuality;
                using (var pen = new Pen(new SolidBrush(arg.BorderColor), arg.BorderWidth))
                    g.DrawPath(pen, path);
            }
        }
Ejemplo n.º 6
0
        private void selectObject(ITreeStringNode node)
        {
            var obj = node.Properties.Entities.GetValue(Fields.Entity);

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

            if (image != null && borderComponent != null)
            {
                _lastSelectedBorder = borderComponent;
                IBorderStyle border = null;
                border            = borderComponent.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)
                {
                    borderComponent.Border = hoverBorder;
                }
                else
                {
                    borderComponent.Border = AGSBorders.Multiple(border, hoverBorder);
                }

                if (image.Opacity == 0)
                {
                    _lastOpacity           = image.Opacity;
                    _lastSelectedMaskImage = image;
                    image.Opacity          = 100;
                }
            }
            if (visibleComponent != null)
            {
                _lastMaskVisible         = visibleComponent.Visible;
                _lastSelectedMaskVisible = visibleComponent;
                visibleComponent.Visible = true;
            }
        }
Ejemplo n.º 7
0
        private void unselect()
        {
            var lastSelectedBorder      = _lastSelectedBorder;
            var lastSelectedMaskVisible = _lastSelectedMaskVisible;
            var lastSelectedMaskImage   = _lastSelectedMaskImage;

            if (lastSelectedBorder != null)
            {
                lastSelectedBorder.Border = _lastObjectBorder;
            }
            if (lastSelectedMaskVisible != null)
            {
                lastSelectedMaskVisible.Visible = _lastMaskVisible;
            }
            if (lastSelectedMaskImage != null)
            {
                lastSelectedMaskImage.Opacity = _lastOpacity;
            }
            _lastSelectedBorder = null;
            _lastObjectBorder   = null;
            _lastMaskVisible    = false;
            _lastOpacity        = 0;
        }
Ejemplo n.º 8
0
        public async Task<string> Run()
        {
            IGameFactory factory = _game.Factory;
            float panelWidth = _game.Settings.VirtualResolution.Width * 3 / 4f;
            float panelHeight = _game.Settings.VirtualResolution.Height * 3 / 4f;
            const float labelHeight = 20f;
            const float textBoxHeight = 20f;
            const float buttonHeight = 20f;
            const float itemHeight = 20f;
            const float itemPaddingX = 5f;
            const float itemPaddingY = 5f;
            const float scrollButtonWidth = 20f;
            const float scrollButtonHeight = 20f;
            const float scrollButtonOffsetX = 5f;
            const float scrollButtonOffsetY = 5f;
            const float okButtonWidth = 50f;
            const float okButtonHeight = 20f;
            const float okButtonPaddingX = 20f;
            const float okButtonPaddingY = 20f;
            float okCancelWidth = okButtonWidth * 2 + okButtonPaddingX;
            float okButtonX = panelWidth / 2f - okCancelWidth / 2f;
            float cancelButtonX = okButtonX + okButtonWidth + okButtonPaddingX;
            float panelX = _game.Settings.VirtualResolution.Width / 2f - panelWidth / 2f;
            float panelY = _game.Settings.VirtualResolution.Height / 2f - panelHeight / 2f;
            ITextConfig textBoxConfig = new AGSTextConfig(alignment: Alignment.BottomLeft,
                autoFit: AutoFit.TextShouldCrop, font: Hooks.FontLoader.LoadFont(null, 10f));

            IPanel panel = factory.UI.GetPanel("SelectFilePanel", panelWidth, panelHeight, panelX, panelY);
            panel.SkinTags.Add(AGSSkin.DialogBoxTag);
            panel.Skin.Apply(panel);
            ILabel titleLabel = factory.UI.GetLabel("SelectFileTitle", _title, panelWidth, labelHeight, 0f, panelHeight - labelHeight, _buttonsTextConfig);
            _fileTextBox = factory.UI.GetTextBox("SelectFileTextBox", 0f, panelHeight - labelHeight - textBoxHeight, _startPath, textBoxConfig, width: panelWidth, height: textBoxHeight);

            _inventory = new AGSInventory();
            IInventoryWindow invWindow = factory.Inventory.GetInventoryWindow("SelectFileInventory", panelWidth - scrollButtonWidth - scrollButtonOffsetX * 2,
                                                                              panelHeight - labelHeight - buttonHeight - textBoxHeight - okButtonPaddingY, ITEM_WIDTH + itemPaddingX, itemHeight + itemPaddingY, 0f, okButtonPaddingY + okButtonHeight, _inventory);
            invWindow.Z = 1;
            IButton okButton = factory.UI.GetButton("SelectFileOkButton", (string)null, null, null, okButtonX, okButtonPaddingY, "OK", _buttonsTextConfig, width: okButtonWidth, height: okButtonHeight);
            IButton cancelButton = factory.UI.GetButton("SelectFileCancelButton", (string)null, null, null, cancelButtonX, okButtonPaddingY, "Cancel", _buttonsTextConfig, width: okButtonWidth, height: okButtonHeight);
            IButton scrollDownButton = factory.UI.GetButton("SelectFileScrollDown", (string)null, null, null, panelWidth - scrollButtonWidth - scrollButtonOffsetX, okButton.Y + okButtonHeight + scrollButtonOffsetY, "", _buttonsTextConfig, width: scrollButtonWidth, height: scrollButtonHeight);
            IButton scrollUpButton = factory.UI.GetButton("SelectFileScrollUp", (string)null, null, null, panelWidth - scrollButtonWidth - scrollButtonOffsetX, panelHeight - labelHeight - textBoxHeight - scrollButtonHeight - scrollButtonOffsetY, "", _buttonsTextConfig, width: scrollButtonWidth, height: scrollButtonHeight);
            titleLabel.TreeNode.SetParent(panel.TreeNode);
            _fileTextBox.TreeNode.SetParent(panel.TreeNode);
            invWindow.TreeNode.SetParent(panel.TreeNode);
            okButton.TreeNode.SetParent(panel.TreeNode);
            cancelButton.TreeNode.SetParent(panel.TreeNode);
            scrollDownButton.TreeNode.SetParent(panel.TreeNode);
            scrollUpButton.TreeNode.SetParent(panel.TreeNode);

            cancelButton.MouseClicked.Subscribe(onCancelClicked);
            okButton.MouseClicked.Subscribe(onOkClicked);

            scrollDownButton.MouseClicked.Subscribe((sender, args) => invWindow.ScrollDown());
            scrollUpButton.MouseClicked.Subscribe((sender, args) => invWindow.ScrollUp());

            _fileIcon = new FileIcon(_glUtils);
            _fileIconSelected = new FileIcon(_glUtils) { IsSelected = true };
            _folderIcon = new FolderIcon(_glUtils);
            _folderIconSelected = new FolderIcon(_glUtils) { IsSelected = true };

            var arrowDownIcon = getIcon("ArrowDown", factory, scrollButtonWidth, scrollButtonHeight, 
                                        new ArrowIcon(_glUtils) { Direction = ArrowIcon.ArrowDirection.Down });
            arrowDownIcon.Anchor = new PointF();
            arrowDownIcon.Enabled = false;
            arrowDownIcon.TreeNode.SetParent(scrollDownButton.TreeNode);
            _game.State.UI.Add(arrowDownIcon);

            var arrowUpIcon = getIcon("ArrowUp", factory, scrollButtonWidth, scrollButtonHeight,
                                      new ArrowIcon(_glUtils) { Direction = ArrowIcon.ArrowDirection.Up });
            arrowUpIcon.Anchor = new PointF();
            arrowUpIcon.Enabled = false;
            arrowUpIcon.TreeNode.SetParent(scrollUpButton.TreeNode);
            _game.State.UI.Add(arrowUpIcon);

            _fileGraphics = getIcon("FileGraphics", factory, ITEM_WIDTH, itemHeight, _fileIcon);
            _folderGraphics = getIcon("FolderGraphics", factory, ITEM_WIDTH, itemHeight, _folderIcon);

            fillAllFiles(_startPath);

            _fileTextBox.OnPressingKey.Subscribe(onTextBoxKeyPressed);

            bool okGiven = await _tcs.Task;
            removeAllUI(panel);
            if (!okGiven) return null;
            return _fileTextBox.Text;
        }
Ejemplo n.º 9
0
 private IObject getIcon(string id, IGameFactory factory, float width, float height, IBorderStyle icon)
 {
     var obj = factory.Object.GetObject(id);
     obj.Tint = Colors.Transparent;
     obj.Image = new EmptyImage(width, height);
     obj.RenderLayer = AGSLayers.UI;
     obj.Anchor = new PointF(0.5f, 0.5f);
     obj.IgnoreScalingArea = true;
     obj.IgnoreViewport = true;
     obj.Border = icon;
     return obj;
 }
Ejemplo n.º 10
0
 public static string CreateTop(string horizontalLine, IBorderStyle borderStyle)
 {
     return($"{borderStyle.LeftTop}{horizontalLine}{borderStyle.RightTop}");
 }
Ejemplo n.º 11
0
        public static GridRender AddStyle(this GridRender gridRender, IBorderStyle borderStyle)
        {
            gridRender.Styles.Add(borderStyle);

            return(gridRender);
        }
Ejemplo n.º 12
0
        public void Render(IObject obj, IViewport viewport)
        {
            if (obj.Animation == null)
            {
                return;
            }
            ISprite sprite = obj.Animation.Sprite;

            if (sprite == null || sprite.Image == null)
            {
                return;
            }

            var  layerViewport     = _layerViewports.GetViewport(obj.RenderLayer.Z);
            var  gameResolution    = AGSGame.Game.Settings.VirtualResolution;
            var  resolution        = obj.RenderLayer.IndependentResolution ?? gameResolution;
            bool resolutionMatches = resolution.Equals(gameResolution);

            var viewportMatrix = obj.IgnoreViewport ? Matrix4.Identity : layerViewport.GetMatrix(viewport, obj.RenderLayer.ParallaxSpeed);

            var modelMatrices = obj.GetModelMatrices();

            _matrices.ModelMatrix    = modelMatrices.InVirtualResolutionMatrix;
            _matrices.ViewportMatrix = viewportMatrix;

            _boundingBoxBuilder.Build(BoundingBoxes, sprite.Image.Width,
                                      sprite.Image.Height, _matrices, resolutionMatches, true);
            IGLBoundingBox hitTestBox = BoundingBoxes.HitTestBox;

            if (!resolutionMatches)
            {
                _matrices.ModelMatrix = modelMatrices.InObjResolutionMatrix;
                _boundingBoxBuilder.Build(BoundingBoxes, sprite.Image.Width,
                                          sprite.Image.Height, _matrices, true, false);
            }
            IGLBoundingBox renderBox = BoundingBoxes.RenderBox;

            ITexture texture = _textures.GetOrAdd(sprite.Image.ID, () => createNewTexture(sprite.Image.ID));

            IGLColor color = _colorBuilder.Build(sprite, obj);

            IBorderStyle border       = obj.Border;
            ISquare      renderSquare = null;

            if (border != null)
            {
                renderSquare = renderBox.ToSquare();
                border.RenderBorderBack(renderSquare);
            }
            _renderer.Render(texture.ID, renderBox, color);

            Vector3 bottomLeft  = hitTestBox.BottomLeft;
            Vector3 topLeft     = hitTestBox.TopLeft;
            Vector3 bottomRight = hitTestBox.BottomRight;
            Vector3 topRight    = hitTestBox.TopRight;

            AGSSquare square = new AGSSquare(new PointF(bottomLeft.X, bottomLeft.Y),
                                             new PointF(bottomRight.X, bottomRight.Y), new PointF(topLeft.X, topLeft.Y),
                                             new PointF(topRight.X, topRight.Y));

            obj.BoundingBox = square;

            if (border != null)
            {
                border.RenderBorderFront(renderSquare);
            }
            if (obj.DebugDrawAnchor)
            {
                IObject parent = obj.TreeNode.Parent;
                float   x      = obj.X;
                float   y      = obj.Y;
                while (parent != null)
                {
                    x     += (parent.X - parent.Width * parent.Anchor.X);
                    y     += (parent.Y - parent.Height * parent.Anchor.Y);
                    parent = parent.TreeNode.Parent;
                }
                _glUtils.DrawCross(x - viewport.X, y - viewport.Y, 10, 10, 1f, 1f, 1f, 1f);
            }
        }
Ejemplo n.º 13
0
        public async Task <string> Run()
        {
            IGameFactory factory       = _game.Factory;
            float        panelWidth    = _game.Settings.VirtualResolution.Width * 3 / 4f;
            float        panelHeight   = _game.Settings.VirtualResolution.Height * 3 / 4f;
            const float  labelHeight   = 20f;
            const float  textBoxHeight = 20f;
            const float  buttonHeight  = 20f;
            float        itemHeight    = panelHeight / 8f;

            ITEM_WIDTH = panelWidth / 10f;
            float       itemPaddingX        = panelWidth / 10f;
            float       itemPaddingY        = panelHeight / 12f;
            const float scrollButtonWidth   = 20f;
            const float scrollButtonHeight  = 20f;
            const float scrollButtonOffsetX = 5f;
            const float scrollButtonOffsetY = 5f;
            const float okButtonWidth       = 50f;
            const float okButtonHeight      = 20f;
            const float okButtonPaddingX    = 20f;
            const float okButtonPaddingY    = 20f;
            float       okCancelWidth       = okButtonWidth * 2 + okButtonPaddingX;
            float       okButtonX           = panelWidth / 2f - okCancelWidth / 2f;
            float       cancelButtonX       = okButtonX + okButtonWidth + okButtonPaddingX;
            float       panelX        = _game.Settings.VirtualResolution.Width / 2f - panelWidth / 2f;
            float       panelY        = _game.Settings.VirtualResolution.Height / 2f - panelHeight / 2f;
            ITextConfig textBoxConfig = factory.Fonts.GetTextConfig(alignment: Alignment.BottomLeft,
                                                                    autoFit: AutoFit.TextShouldCrop, font: _game.Factory.Fonts.LoadFont(_game.Settings.Defaults.TextFont.FontFamily, 10f));

            IPanel panel = factory.UI.GetPanel("SelectFilePanel", panelWidth, panelHeight, panelX, panelY);

            panel.RenderLayer = new AGSRenderLayer(AGSLayers.UI.Z - 1);
            panel.SkinTags.Add(AGSSkin.DialogBoxTag);
            panel.Skin?.Apply(panel);
            panel.AddComponent <IModalWindowComponent>().GrabFocus();
            factory.UI.GetLabel("SelectFileTitle", _title, panelWidth, labelHeight, 0f, panelHeight - labelHeight, panel, _buttonsTextConfig);
            _fileTextBox = factory.UI.GetTextBox("SelectFileTextBox", 0f, panelHeight - labelHeight - textBoxHeight, panel, _startPath, textBoxConfig, width: panelWidth, height: textBoxHeight);

            _inventory = new AGSInventory();
            IInventoryWindow invWindow = factory.Inventory.GetInventoryWindow("SelectFileInventory", panelWidth - scrollButtonWidth - scrollButtonOffsetX * 2,
                                                                              panelHeight - labelHeight - buttonHeight - textBoxHeight - okButtonPaddingY, ITEM_WIDTH + itemPaddingX, itemHeight + itemPaddingY, 0f, okButtonPaddingY + okButtonHeight, _inventory);

            invWindow.Z = 1;
            IButton okButton         = factory.UI.GetButton("SelectFileOkButton", (string)null, null, null, okButtonX, okButtonPaddingY, panel, "OK", _buttonsTextConfig, width: okButtonWidth, height: okButtonHeight);
            IButton cancelButton     = factory.UI.GetButton("SelectFileCancelButton", (string)null, null, null, cancelButtonX, okButtonPaddingY, panel, "Cancel", _buttonsTextConfig, width: okButtonWidth, height: okButtonHeight);
            IButton scrollDownButton = factory.UI.GetButton("SelectFileScrollDown", (string)null, null, null, panelWidth - scrollButtonWidth - scrollButtonOffsetX, okButton.Y + okButtonHeight + scrollButtonOffsetY, panel, "", _buttonsTextConfig, width: scrollButtonWidth, height: scrollButtonHeight);
            IButton scrollUpButton   = factory.UI.GetButton("SelectFileScrollUp", (string)null, null, null, panelWidth - scrollButtonWidth - scrollButtonOffsetX, panelHeight - labelHeight - textBoxHeight - scrollButtonHeight - scrollButtonOffsetY, panel, "", _buttonsTextConfig, width: scrollButtonWidth, height: scrollButtonHeight);

            invWindow.TreeNode.SetParent(panel.TreeNode);

            cancelButton.MouseClicked.Subscribe(onCancelClicked);
            okButton.MouseClicked.SubscribeToAsync(onOkClicked);

            scrollDownButton.MouseClicked.Subscribe(_ => invWindow.ScrollDown());
            scrollUpButton.MouseClicked.Subscribe(_ => invWindow.ScrollUp());

            var iconFactory = factory.Graphics.Icons;

            _fileIcon           = iconFactory.GetFileIcon();
            _fileIconSelected   = iconFactory.GetFileIcon(true);
            _folderIcon         = iconFactory.GetFolderIcon();
            _folderIconSelected = iconFactory.GetFolderIcon(true);

            var arrowDownIcon = getIcon("ArrowDown", factory, scrollButtonWidth, scrollButtonHeight,
                                        iconFactory.GetArrowIcon(ArrowDirection.Down), scrollDownButton.RenderLayer);

            arrowDownIcon.Pivot   = new PointF();
            arrowDownIcon.Enabled = false;
            arrowDownIcon.TreeNode.SetParent(scrollDownButton.TreeNode);
            _game.State.UI.Add(arrowDownIcon);

            var arrowUpIcon = getIcon("ArrowUp", factory, scrollButtonWidth, scrollButtonHeight,
                                      iconFactory.GetArrowIcon(ArrowDirection.Up), scrollUpButton.RenderLayer);

            arrowUpIcon.Pivot   = new PointF();
            arrowUpIcon.Enabled = false;
            arrowUpIcon.TreeNode.SetParent(scrollUpButton.TreeNode);
            _game.State.UI.Add(arrowUpIcon);

            _fileGraphics   = getIcon("FileGraphics", factory, ITEM_WIDTH, itemHeight, _fileIcon, scrollUpButton.RenderLayer);
            _folderGraphics = getIcon("FolderGraphics", factory, ITEM_WIDTH, itemHeight, _folderIcon, scrollUpButton.RenderLayer);

            fillAllFiles(_startPath);

            _fileTextBox.OnPressingKey.Subscribe(onTextBoxKeyPressed);

            bool okGiven = await _tcs.Task;

            clearInventory();
            panel.GetComponent <IModalWindowComponent>().LoseFocus();
            destroy(panel);
            destroy(_fileGraphics);
            destroy(_folderGraphics);
            destroy(_fileTextBox);
            var result = _fileTextBox.Text;

            if (!okGiven)
            {
                return(null);
            }
            return(result);
        }
Ejemplo n.º 14
0
        private IObject getIcon(string id, IGameFactory factory, float width, float height, IBorderStyle icon, IRenderLayer renderLayer)
        {
            var obj = factory.Object.GetObject(id);

            obj.Tint              = Colors.Transparent;
            obj.Image             = new EmptyImage(width, height);
            obj.RenderLayer       = renderLayer;
            obj.Pivot             = new PointF(0.5f, 0.5f);
            obj.IgnoreScalingArea = true;
            obj.IgnoreViewport    = true;
            obj.Border            = icon;
            return(obj);
        }
Ejemplo n.º 15
0
 public static string CreateBottom(string horizontalLine, IBorderStyle borderStyle)
 {
     return($"{borderStyle.LeftBottom}{horizontalLine}{borderStyle.RightBottom}");
 }
Ejemplo n.º 16
0
 public void Setup(IBorderStyle border, AGSBoundingBox box)
 {
     _border = border;
     _box    = box;
 }
Ejemplo n.º 17
0
 private static void ApplyStyle(this GridDefinition grid, IBorderStyle borderStyle)
 {
     borderStyle?.Apply(grid);
 }