private void UpdateActionSlot(EntityUid item, ItemActionType itemActionType, ActionSlot actionSlot, ActionAssignment? assignedActionType) { if (!_entityManager.TryGetEntity(item, out var itemEntity)) return; if (_actionManager.TryGet(itemActionType, out var action)) { actionSlot.Assign(action, itemEntity, true); } else { Logger.ErrorS("action", "unrecognized actionType {0}", assignedActionType); actionSlot.Clear(); return; } if (!_actionsComponent.TryGetItemActionState(itemActionType, item, out var actionState)) { // action is no longer tied to an item, this should never happen as we // check this at the start of this method. But just to be safe // we will restore our assignment here to the correct state Logger.ErrorS("action", "coding error, expected actionType {0} to have" + " a state but it didn't", assignedActionType); _actionsComponent.Assignments.AssignSlot(SelectedHotbar, actionSlot.SlotIndex, ActionAssignment.For(itemActionType)); actionSlot.Assign(action); return; } if (!actionState.Enabled) { // just disabled an action we were trying to target with, stop targeting if (SelectingTargetFor?.Action != null && SelectingTargetFor.Action == action) { StopTargeting(); } actionSlot.DisableAction(); } else { // action is currently granted actionSlot.EnableAction(); // if we are targeting with an action now on cooldown, stop targeting if we should if (SelectingTargetFor?.Action != null && SelectingTargetFor.Action == action && SelectingTargetFor.Item == itemEntity && actionState.IsOnCooldown(_gameTiming) && action.DeselectOnCooldown) { StopTargeting(); } } actionSlot.Cooldown = actionState.Cooldown; // check if we need to toggle it if (action.BehaviorType == BehaviorType.Toggle) { actionSlot.ToggledOn = actionState.ToggledOn; } }
/// <summary> /// If currently targeting with this slot, stops targeting. /// If currently targeting with no slot or a different slot, switches to /// targeting with the specified slot. /// </summary> /// <param name="slot"></param> public void ToggleTargeting(ActionSlot slot) { if (SelectingTargetFor == slot) { StopTargeting(); return; } StartTargeting(slot); }
/// <summary> /// Puts us in targeting mode, where we need to pick either a target point or entity /// </summary> private void StartTargeting(ActionSlot actionSlot) { // If we were targeting something else we should stop StopTargeting(); SelectingTargetFor = actionSlot; // show it as toggled on to indicate we are currently selecting a target for it if (!actionSlot.ToggledOn) { actionSlot.ToggledOn = true; } }
private void UpdateActionSlot(ItemActionType itemlessActionType, ActionSlot actionSlot, ActionAssignment?assignedActionType) { if (_actionManager.TryGet(itemlessActionType, out var action)) { actionSlot.Assign(action); } else { Logger.ErrorS("action", "unrecognized actionType {0}", assignedActionType); actionSlot.Clear(); } actionSlot.Cooldown = null; }
/// <summary> /// Puts us in targeting mode, where we need to pick either a target point or entity /// </summary> private void StartTargeting(ActionSlot actionSlot) { if (actionSlot.Action == null) return; // If we were targeting something else we should stop StopTargeting(); SelectingTargetFor = actionSlot; if (actionSlot.Action is TargetedAction targetAction) System.StartTargeting(targetAction); UpdateUI(); }
private void UpdateActionSlot(ActionType actionType, ActionSlot actionSlot, ActionAssignment?assignedActionType) { if (_actionManager.TryGet(actionType, out var action)) { actionSlot.Assign(action, true); } else { Logger.ErrorS("action", "unrecognized actionType {0}", assignedActionType); actionSlot.Clear(); return; } if (!_actionsComponent.TryGetActionState(actionType, out var actionState) || !actionState.Enabled) { // action is currently disabled // just revoked an action we were trying to target with, stop targeting if (SelectingTargetFor?.Action != null && SelectingTargetFor.Action == action) { StopTargeting(); } actionSlot.DisableAction(); actionSlot.Cooldown = null; } else { // action is currently granted actionSlot.EnableAction(); actionSlot.Cooldown = actionState.Cooldown; // if we are targeting for this action and it's now on cooldown, stop targeting if we're supposed to if (SelectingTargetFor?.Action != null && SelectingTargetFor.Action == action && actionState.IsOnCooldown(_gameTiming) && action.DeselectOnCooldown) { StopTargeting(); } } // check if we need to toggle it if (action.BehaviorType == BehaviorType.Toggle) { actionSlot.ToggledOn = actionState.ToggledOn; } }
private void UpdateActionSlot(ActionType action, ActionSlot actionSlot) { actionSlot.Assign(action); if (!action.Enabled) { // just revoked an action we were trying to target with, stop targeting if (SelectingTargetFor?.Action != null && SelectingTargetFor.Action == action) { StopTargeting(); } actionSlot.Disable(); } else { actionSlot.Enable(); } actionSlot.UpdateIcons(); actionSlot.DrawModeChanged(); }
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); }