public void ResourcesSpent(EResourceType type, int amount)
 {
     if (_itemsCollected[(int)type] >= amount)
     {
         _itemsCollected[(int)type] -= amount;
     }
     Debug.Log("Not enough resources of type " + type.ToString());
 }
Example #2
0
 private void RegisterResourceLoader(EResourceType type, IResourceLoader loader)
 {
     if (resourceLoaderTable == null)
     {
         resourceLoaderTable = new Dictionary <EResourceType, IResourceLoader>();
     }
     if (resourceLoaderTable.ContainsKey(type))
     {
         Debug.LogError(string.Format("重复注册资源加载器[{0}]", type.ToString()));
         return;
     }
     resourceLoaderTable[type] = loader;
 }
Example #3
0
        /// <summary>
        /// Creates a ResourceIWindowItem, which consists of the resources color, it's name and it's amount
        /// </summary>
        /// <param name="resourceType">resource type</param>
        /// <param name="amount">resource amount</param>
        /// <param name="size">size of the item to create (width important)</param>
        /// <param name="spriteFont">text's spritefont</param>
        public ResourceIWindowItem(EResourceType resourceType, int amount, Vector2 size, SpriteFont spriteFont)
        {
            mSpriteFont = spriteFont;

            mTypeColor    = ResourceHelper.GetColor(resourceType);
            mResourceText = resourceType.ToString();

            Amount = amount;

            // set to Vector.Zero, since the window will manage this item's position
            Position = Vector2.Zero;

            var minItemWidth = mSpriteFont.MeasureString("Y").Y / 2 + mSpriteFont.MeasureString(Amount.ToString()).X +
                               mSpriteFont.MeasureString(mResourceText).X + 30;

            // set size to automatically fit the text height + width
            Size = size.X < minItemWidth ? new Vector2(minItemWidth, mSpriteFont.MeasureString(mResourceText).Y) : new Vector2(size.X, mSpriteFont.MeasureString(mResourceText).Y);

            ActiveInWindow = true;
        }