Esempio n. 1
0
        public ActionsUI(ClientActionsComponent actionsComponent)
        {
            SetValue(LayoutContainer.DebugProperty, true);
            _actionsComponent = actionsComponent;
            _actionManager    = IoCManager.Resolve <ActionManager>();
            _entityManager    = IoCManager.Resolve <IEntityManager>();
            _gameTiming       = IoCManager.Resolve <IGameTiming>();
            _gameHud          = IoCManager.Resolve <IGameHud>();
            _menu             = new ActionMenu(_actionsComponent, this);

            LayoutContainer.SetGrowHorizontal(this, LayoutContainer.GrowDirection.End);
            LayoutContainer.SetGrowVertical(this, LayoutContainer.GrowDirection.Constrain);
            LayoutContainer.SetAnchorTop(this, 0f);
            LayoutContainer.SetAnchorBottom(this, 0.8f);
            LayoutContainer.SetMarginLeft(this, 13);
            LayoutContainer.SetMarginTop(this, 110);

            HorizontalAlignment = HAlignment.Left;
            VerticalExpand      = true;

            var resourceCache = IoCManager.Resolve <IResourceCache>();

            // everything needs to go within an inner panel container so the panel resizes to fit the elements.
            // Because ActionsUI is being anchored by layoutcontainer, the hotbar backing would appear too tall
            // if ActionsUI was the panel container

            var panelContainer = new PanelContainer()
            {
                StyleClasses        = { StyleNano.StyleClassHotbarPanel },
                HorizontalAlignment = HAlignment.Left,
                VerticalAlignment   = VAlignment.Top
            };

            AddChild(panelContainer);

            var hotbarContainer = new BoxContainer
            {
                Orientation         = LayoutOrientation.Vertical,
                SeparationOverride  = 3,
                HorizontalAlignment = HAlignment.Left
            };

            panelContainer.AddChild(hotbarContainer);

            var settingsContainer = new BoxContainer
            {
                Orientation      = LayoutOrientation.Horizontal,
                HorizontalExpand = true
            };

            hotbarContainer.AddChild(settingsContainer);

            settingsContainer.AddChild(new Control {
                HorizontalExpand = true, SizeFlagsStretchRatio = 1
            });
            _lockTexture   = resourceCache.GetTexture("/Textures/Interface/Nano/lock.svg.192dpi.png");
            _unlockTexture = resourceCache.GetTexture("/Textures/Interface/Nano/lock_open.svg.192dpi.png");
            _lockButton    = new TextureButton
            {
                TextureNormal         = _unlockTexture,
                HorizontalAlignment   = HAlignment.Center,
                VerticalAlignment     = VAlignment.Center,
                SizeFlagsStretchRatio = 1,
                Scale        = (0.5f, 0.5f),
                ToolTip      = Loc.GetString("ui-actionsui-function-lock-action-slots"),
                TooltipDelay = CustomTooltipDelay
            };
            settingsContainer.AddChild(_lockButton);
            settingsContainer.AddChild(new Control {
                HorizontalExpand = true, SizeFlagsStretchRatio = 2
            });
            _settingsButton = new TextureButton
            {
                TextureNormal         = resourceCache.GetTexture("/Textures/Interface/Nano/gear.svg.192dpi.png"),
                HorizontalAlignment   = HAlignment.Center,
                VerticalAlignment     = VAlignment.Center,
                SizeFlagsStretchRatio = 1,
                Scale        = (0.5f, 0.5f),
                ToolTip      = Loc.GetString("ui-actionsui-function-open-abilities-menu"),
                TooltipDelay = CustomTooltipDelay
            };
            settingsContainer.AddChild(_settingsButton);
            settingsContainer.AddChild(new Control {
                HorizontalExpand = true, SizeFlagsStretchRatio = 1
            });

            // this allows a 2 column layout if window gets too small
            _slotContainer = new GridContainer
            {
                MaxGridHeight = CalcMaxHeight()
            };
            hotbarContainer.AddChild(_slotContainer);

            _loadoutContainer = new BoxContainer
            {
                Orientation      = LayoutOrientation.Horizontal,
                HorizontalExpand = true,
                MouseFilter      = MouseFilterMode.Stop
            };
            hotbarContainer.AddChild(_loadoutContainer);

            _loadoutContainer.AddChild(new Control {
                HorizontalExpand = true, SizeFlagsStretchRatio = 1
            });
            var previousHotbarIcon = new TextureRect()
            {
                Texture               = resourceCache.GetTexture("/Textures/Interface/Nano/left_arrow.svg.192dpi.png"),
                HorizontalAlignment   = HAlignment.Center,
                VerticalAlignment     = VAlignment.Center,
                SizeFlagsStretchRatio = 1,
                TextureScale          = (0.5f, 0.5f)
            };

            _loadoutContainer.AddChild(previousHotbarIcon);
            _loadoutContainer.AddChild(new Control {
                HorizontalExpand = true, SizeFlagsStretchRatio = 2
            });
            _loadoutNumber = new Label
            {
                Text = "1",
                SizeFlagsStretchRatio = 1
            };
            _loadoutContainer.AddChild(_loadoutNumber);
            _loadoutContainer.AddChild(new Control {
                HorizontalExpand = true, SizeFlagsStretchRatio = 2
            });
            var nextHotbarIcon = new TextureRect
            {
                Texture               = resourceCache.GetTexture("/Textures/Interface/Nano/right_arrow.svg.192dpi.png"),
                HorizontalAlignment   = HAlignment.Center,
                VerticalAlignment     = VAlignment.Center,
                SizeFlagsStretchRatio = 1,
                TextureScale          = (0.5f, 0.5f)
            };

            _loadoutContainer.AddChild(nextHotbarIcon);
            _loadoutContainer.AddChild(new Control {
                HorizontalExpand = true, SizeFlagsStretchRatio = 1
            });

            _slots = new ActionSlot[ClientActionsComponent.Slots];

            _dragShadow = new TextureRect
            {
                MinSize = (64, 64),
                Stretch = TextureRect.StretchMode.Scale,
                Visible = false,
                SetSize = (64, 64)
            };
            UserInterfaceManager.PopupRoot.AddChild(_dragShadow);

            for (byte i = 0; i < ClientActionsComponent.Slots; i++)
            {
                var slot = new ActionSlot(this, _menu, actionsComponent, i);
                _slotContainer.AddChild(slot);
                _slots[i] = slot;
            }

            DragDropHelper = new DragDropHelper <ActionSlot>(OnBeginActionDrag, OnContinueActionDrag, OnEndActionDrag);

            MinSize = (10, 400);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates an action slot for the specified number
        /// </summary>
        /// <param name="slotIndex">slot index this corresponds to, 0-9 (0 labeled as 1, 8, labeled "9", 9 labeled as "0".</param>
        public ActionSlot(ActionsUI actionsUI, ActionMenu actionMenu, byte slotIndex)
        {
            _actionsUI  = actionsUI;
            _actionMenu = actionMenu;
            _gameTiming = IoCManager.Resolve <IGameTiming>();
            SlotIndex   = slotIndex;
            MouseFilter = MouseFilterMode.Stop;

            MinSize           = (64, 64);
            VerticalAlignment = VAlignment.Top;
            TooltipDelay      = CustomTooltipDelay;
            TooltipSupplier   = SupplyTooltip;

            _number = new RichTextLabel
            {
                StyleClasses = { StyleNano.StyleClassHotbarSlotNumber }
            };
            _number.SetMessage(SlotNumberLabel());

            _bigActionIcon = new TextureRect
            {
                HorizontalExpand = true,
                VerticalExpand   = true,
                Stretch          = TextureRect.StretchMode.Scale,
                Visible          = false
            };
            _bigItemSpriteView = new SpriteView
            {
                HorizontalExpand  = true,
                VerticalExpand    = true,
                Scale             = (2, 2),
                Visible           = false,
                OverrideDirection = Direction.South,
            };
            _smallActionIcon = new TextureRect
            {
                HorizontalAlignment = HAlignment.Right,
                VerticalAlignment   = VAlignment.Bottom,
                Stretch             = TextureRect.StretchMode.Scale,
                Visible             = false
            };
            _smallItemSpriteView = new SpriteView
            {
                HorizontalAlignment = HAlignment.Right,
                VerticalAlignment   = VAlignment.Bottom,
                Visible             = false,
                OverrideDirection   = Direction.South,
            };

            _cooldownGraphic = new CooldownGraphic {
                Progress = 0, Visible = false
            };

            // padding to the left of the number to shift it right
            var paddingBox = new BoxContainer
            {
                Orientation      = LayoutOrientation.Horizontal,
                HorizontalExpand = true,
                VerticalExpand   = true,
                MinSize          = (64, 64)
            };

            paddingBox.AddChild(new Control()
            {
                MinSize = (4, 4),
            });