Exemplo n.º 1
0
    private void UpdateTooltipDescription(Entity item, ItemAuth itemAuth)
    {
        _descriptionData.Clear();
        if (item != Entity.Null)
        {
            // General Description
            _descriptionData.Add(new DescriptionData(itemAuth.EffectDescription, Color.white, true));

            // AP Cost
            _descriptionData.Add(new DescriptionData("Coût AP : " + itemAuth.ApCost, Color.white, true));

            // Item Specific Settings
            if (itemAuth.CooldownType == ItemAuth.CooldownMode.Seconds)
            {
                _descriptionData.Add(new DescriptionData($"Cooldown (time) : {itemAuth.CooldownDuration}", Color.white, true));
            }
        }

        PresentationHelpers.UpdateGameObjectList(_descriptionElements, _descriptionData, _itemDescriptionPrefab, _itemDescriptionContainer,
                                                 onUpdate: (element, data) => element.UpdateDescription(data.Desc, data.Color, data.AddBG));
    }
Exemplo n.º 2
0
    public void UpdateCurrentInventorySlot(
        ItemAuth gameActionAuth,
        int itemIndex,
        PlayerActionBarSlotInfo slotInfo,
        System.Action <int> onItemPrimaryActionUsed,
        System.Action <int> onItemSecondaryActionUsed,
        int stacks = -1)
    {
        _actionBarSlotUnavailable = false;

        _currentItemIndex          = itemIndex;
        _info                      = slotInfo;
        _onItemPrimaryActionUsed   = onItemPrimaryActionUsed;
        _onItemSecondaryActionUsed = onItemSecondaryActionUsed;

        UnavailableTimerText.gameObject.SetActive(false);
        UnavailableSpriteObject.SetActive(false);

        ShortcutDisplay.text = GetPrettyName(_info.InputShortcut);

        UpdateCurrentItemSlot(gameActionAuth, null, null, GamePresentationCache.Instance.LocalPawn, stacks);
    }
Exemplo n.º 3
0
    public virtual void UpdateCurrentItemSlot(ItemAuth itemAuth, System.Action onItemLeftClicked, System.Action onItemRightClicked, Entity owner, int stacks = -1)
    {
        InitIfNeeded();

        _currentItemGameActionAuth = itemAuth;
        _onItemLeftClicked         = onItemLeftClicked;
        _onItemRightClicked        = onItemRightClicked;
        _itemsOwner = owner;

        if (stacks <= 0)
        {
            _stackText.gameObject.SetActive(false);
        }
        else
        {
            _stackText.text = "x" + stacks;
            _stackText.gameObject.SetActive(true);
        }

        if (_currentItemGameActionAuth != null)
        {
            ItemIcon.color  = _currentItemGameActionAuth.IconTint;
            ItemIcon.sprite = _currentItemGameActionAuth.Icon;
        }
        else
        {
            ItemIcon.color = ItemIcon.color.ChangedAlpha(0);
        }

        if (_mouseInside)
        {
            // force refresh tooltip content
            SetTooltip(true, force: true);
        }

        UpdateBackgroundColor();
    }
Exemplo n.º 4
0
    public void ActivateTooltipDisplay(ItemAuth itemGameActionAuth, Entity itemOwner)
    {
        if (!Input.GetKey(KeyCode.LeftAlt))
        {
            if (_currentDelayedTooltipActivationCoroutine == null)
            {
                _currentDelayedTooltipActivationCoroutine = this.DelayedCall(_displayDelay, () =>
                {
                    ActivateTooltipDisplay(itemGameActionAuth, itemOwner);
                });

                return;
            }
            else
            {
                StopCoroutine(_currentDelayedTooltipActivationCoroutine);
                _currentDelayedTooltipActivationCoroutine = null;
            }
        }

        if (itemGameActionAuth != null)
        {
            SimAsset simAsset = itemGameActionAuth.GetComponent <SimAsset>();
            if (simAsset != null)
            {
                Entity itemEntity = FindItemFromAssetId(simAsset.GetSimAssetId(), itemOwner);
                if (itemEntity != Entity.Null)
                {
                    _itemName.text = itemGameActionAuth.Name; // update title Text
                    UpdateTooltipDescription(itemEntity, itemGameActionAuth);
                    UpdateTooltipColors(Color.white);
                    _shouldBeDisplayed = true;
                }
            }
        }
    }
    protected override void OnGamePresentationUpdate()
    {
        if (SimWorld.TryGetBufferReadOnly(SimEntity, out DynamicBuffer <InventoryItemReference> items))
        {
            if ((items.Length == 1))
            {
                if (!_appearanceChanged)
                {
                    _appearanceChanged = true;

                    _spriteContainer.localScale = new Vector3(_scaleChange, _scaleChange, 1);

                    InventoryItemReference item = items[0];
                    if (SimWorld.TryGetComponent(item.ItemEntity, out SimAssetId itemIDComponent))
                    {
                        ItemAuth itemAuth = PresentationHelpers.FindItemAuth(itemIDComponent);
                        _chestRenderer.sprite = itemAuth.Icon;
                    }

                    _bgRenderer.gameObject.SetActive(true);

                    _currentAnimation = _spriteContainer.DOMoveY(transform.position.y + _yDisplacement, _animationDuration).SetLoops(-1, LoopType.Yoyo).SetEase(Ease.InOutSine);
                }
            }
            else
            {
                _appearanceChanged = false;

                _bgRenderer.gameObject.SetActive(false);

                _spriteContainer.localScale = new Vector3(1, 1, 1);

                _currentAnimation?.Kill();
            }
        }
    }
    private void UpdateInventorySlots()
    {
        if (SimWorld.TryGetBufferReadOnly(Cache.LocalPawn, out DynamicBuffer <InventoryItemReference> inventory))
        {
            List <DisplayedItemData> displayedInventory = ListPool <DisplayedItemData> .Take();

            // gather all items to display
            for (int i = 0; i < inventory.Length; i++)
            {
                Entity item = inventory[i].ItemEntity;

                if (SimWorld.TryGetComponent(item, out SimAssetId itemAssetId))
                {
                    ItemAuth itemGameActionAuth = PresentationHelpers.FindItemAuth(itemAssetId);
                    if (itemGameActionAuth != null && !itemGameActionAuth.HideInInventory)
                    {
                        displayedInventory.Add(new DisplayedItemData()
                        {
                            ItemAuth = itemGameActionAuth,
                            ItemRef  = inventory[i],
                            Index    = i
                        });
                    }
                }
            }

            // Ajust Slot amount accordiwdng to inventory max size
            InventoryCapacity inventoryCapacity = SimWorld.GetComponent <InventoryCapacity>(Cache.LocalPawn);

            _gridLayoutGroup.constraintCount = min(_maxCollumns, inventoryCapacity);

            PresentationHelpers.ResizeGameObjectList(_slotVisuals, max(min(_maxCollumns, inventoryCapacity), displayedInventory.Count), _inventorySlotPrefab, _slotsContainer);

            for (int i = 0; i < _slotVisuals.Count; i++)
            {
                if (i < displayedInventory.Count)
                {
                    Entity item   = displayedInventory[i].ItemRef.ItemEntity;
                    int    stacks = displayedInventory[i].ItemRef.Stacks;

                    if (stacks == 1 && !SimWorld.GetComponent <StackableFlag>(item))
                    {
                        stacks = -1; // used in display to hide stacks
                    }
                    _slotVisuals[i].UpdateCurrentInventorySlot(displayedInventory[i].ItemAuth,
                                                               displayedInventory[i].Index,
                                                               GetSlotShotcut(i),
                                                               OnIntentionToUsePrimaryActionOnItem,
                                                               OnIntentionToUseSecondaryActionOnItem,
                                                               stacks);

                    if (!CommonReads.CanUseItem(SimWorld, Cache.LocalPawn, item))
                    {
                        _slotVisuals[i].UpdateDisplayAsUnavailable(item);
                    }
                }
                else
                {
                    _slotVisuals[i].UpdateCurrentInventorySlot(null, i, GetSlotShotcut(i), null, null);
                }
            }

            ListPool <DisplayedItemData> .Release(displayedInventory);
        }
    }