Beispiel #1
0
        // PRAGMA MARK - Public Interface
        public void SetupWithIdQuantity <TEntity>(IdQuantity <TEntity> idQuantity) where TEntity : DTEntity
        {
            IViewIdQuantity viewIdQuantity = new ViewIdQuantity <TEntity>(idQuantity);

            DTEntity         entity           = viewIdQuantity.Entity;
            DisplayComponent displayComponent = entity.GetComponent <DisplayComponent>();

            if (displayComponent != null)
            {
                this._image.sprite = displayComponent.displaySprite;
            }

            if (viewIdQuantity.Quantity <= 0)
            {
                Debug.LogWarning("IdQuantityView - don't know how to show a quantity less than or equal to zero!");
            }

            if (viewIdQuantity.Quantity > 1)
            {
                this._textContainer.SetActive(true);
                this._text.SetText(string.Format("x{0}", viewIdQuantity.Quantity));
            }
            else
            {
                this._textContainer.SetActive(false);
            }
        }
        private IdQuantity <TEntity> GetIdQuantityForId(int id)
        {
            if (!this._initialized)
            {
                this.RefreshMap();
                this._initialized = true;
            }

            if (!this._idMap.ContainsKey(id))
            {
                DTEntity entity = IdList <TEntity> .Instance.LoadById(id);

                if (entity == null)
                {
                    Debug.LogWarning("GetIdQuantityForId - called with invalid " + typeof(TEntity).Name + " id: " + id + "!");
                    return(null);
                }

                IdQuantity <TEntity> idQuantity = new IdQuantity <TEntity>(id, quantity: 0);
                this._idList.Add(idQuantity);
                this._idMap[id] = idQuantity;
            }

            return(this._idMap[id]);
        }
        public void AddIdQuantity(IdQuantity <TEntity> addQuantity)
        {
            IdQuantity <TEntity> idQuantity = this.GetIdQuantityForId(addQuantity.id);

            idQuantity.quantity += addQuantity.quantity;

            this.OnInventoryUpdated.Invoke();
            this.OnAddedIdQuantity.Invoke(addQuantity);
        }
        // PRAGMA MARK - Public Interface
        public void SetupWithRequiredIdQuantity <TEntity>(IdQuantity <TEntity> requiredIdQuantity) where TEntity : DTEntity
        {
            IViewIdQuantity requiredViewIdQuantity = new ViewIdQuantity <TEntity>(requiredIdQuantity);

            this._requiredViewIdQuantity = requiredViewIdQuantity;
            this._requiredViewIdQuantity.OnUserInventoryUpdated += this.HandleInventoryUpdated;

            DTEntity         entity           = this._requiredViewIdQuantity.Entity;
            DisplayComponent displayComponent = entity.GetComponent <DisplayComponent>();

            if (displayComponent != null)
            {
                this._requiredImage.sprite = displayComponent.displaySprite;
            }

            this.UpdateUserCount();
        }
        public bool RemoveIdQuantity(IdQuantity <TEntity> removeQuantity, bool silenceInventoryUpdatedEvent = false)
        {
            IdQuantity <TEntity> idQuantity = this.GetIdQuantityForId(removeQuantity.id);

            if (idQuantity.quantity < removeQuantity.quantity)
            {
                Debug.LogWarning("RemoveIdQuantity: Can't remove " + removeQuantity.quantity + " of " + typeof(TEntity).Name + " id: " + removeQuantity.id + "!");
                return(false);
            }

            idQuantity.quantity -= removeQuantity.quantity;
            this.OnRemovedIdQuantity.Invoke(removeQuantity);
            if (!silenceInventoryUpdatedEvent)
            {
                this.OnInventoryUpdated.Invoke();
            }
            return(true);
        }
Beispiel #6
0
 public ViewIdQuantity(IdQuantity <TEntity> idQuantity)
 {
     this._idQuantity = idQuantity;
     UserIdInventory <TEntity> .Instance.OnInventoryUpdated += this.HandleUserInventoryUpdated;
 }
Beispiel #7
0
        // PRAGMA MARK - Static Interface
        public static EntityQuantity From <TEntity>(IdQuantity <TEntity> idQuantity) where TEntity : DTEntity
        {
            TEntity entity = idQuantity.GetEntity();

            return(new EntityQuantity(entity, idQuantity.quantity));
        }
        public bool CanRemoveIdQuantity(IdQuantity <TEntity> removeQuantity)
        {
            IdQuantity <TEntity> idQuantity = this.GetIdQuantityForId(removeQuantity.id);

            return(idQuantity.quantity >= removeQuantity.quantity);
        }
Beispiel #9
0
 public static TEntity GetEntity <TEntity>(this IdQuantity <TEntity> idQuantity) where TEntity : DTEntity
 {
     return(IdList <TEntity> .Instance.LoadById(idQuantity.id));
 }
Beispiel #10
0
 // PRAGMA MARK - Public Interface
 public IdQuantityLootReward(IdQuantity <TEntity> idQuantity)
 {
     this.idQuantity = idQuantity;
 }