예제 #1
0
 public void SellItem(ShopUIItem shopUIItem)
 {
     playerStats.gold += shopUIItem.item.price;
     RemoveItem(shopUIItem.item);
     characterItems.Remove(shopUIItem.item);
     shopUIItem.UpdateItem(null);
 }
예제 #2
0
    public void ItemAddOrUpdate(Item item, bool toCount, bool isEmpty)
    {
        foreach (var UIItem in activeItems)
        {
            if (UIItem.item.ObjectSlug == item.ObjectSlug)
            {
                emptyItem = UIItem;
                break;
            }
        }

        if (isEmpty)
        {
            Debug.Log("Destroying " + item.ItemName + " item container");
            Destroy(emptyItem.gameObject);
            activeItems.Remove(emptyItem);
        }
        else
        {
            if (toCount)
            {
                Debug.Log(emptyItem.item.ObjectSlug);
                emptyItem.UpdateValues();
            }
            else
            {
                Debug.Log("Adding Item: " + item.ItemName);
                emptyItem = Instantiate(itemContainer);
                activeItems.Add(emptyItem);
                emptyItem.SetItem(item);
                emptyItem.transform.SetParent(scrollViewContent, false);
            }
        }
    }
예제 #3
0
 public void BuyItem(ShopUIItem shopUIItem)
 {
     if (playerStats.gold > shopUIItem.item.price && characterItems.Count < sizeOfInventory)
     {
         playerStats.gold -= shopUIItem.item.price;
         characterItems.Add(shopUIItem.item);
         inventoryInShop.AddNewItem(shopUIItem.item);
         shopUIItem.UpdateItem(null);
     }
 }
예제 #4
0
    public void sell(Item item, ShopUIItem UIitem, int count)
    {
        Debug.Log("Selling " + count + item.ItemName);
        int counter = 0;

        while (counter < count)
        {
            inventory.RemoveItem(item.ObjectSlug);
            playersystem.ChangeMoney((int)item.MonetaryValue, true);
            counter++;
        }
        UIitem.UpdateValues();
    }
예제 #5
0
 /// <summary>
 /// 计算商品价格并购买
 /// </summary>
 /// <param name="item"></param>
 public void CalcItemPrice(ShopUIItem item)
 {
     if (shopData.goldCount >= item.itemPrice)   //当金币数大于商品价格时
     {
         Debug.Log("购买成功");
         item.buyState.SetActive(false);                                               //隐藏购买按钮
         shopData.goldCount -= item.itemPrice;                                         //金币数减去商品价格
         ShowUIData();                                                                 //更新UI数据
         shopData.ChangeXMLData(savePath, "GoldCount", shopData.goldCount.ToString()); //更新金币数
         shopData.ChangeXMLData(savePath, "ID" + item.itemID, "1");                    //更新商品的购买状态
     }
     else
     {
         Debug.Log("购买失败,金币不足");
     }
 }
예제 #6
0
    Dictionary <int, int> currentBuyCount = new Dictionary <int, int>();//当前已经购买的物品数量
    protected override void OnCreate()
    {
        InitTrans();
        childMgr = GameUtil.GetOrAddComponent <ChildGoComponent>(ItemRoot_RectTransform);
        childMgr.Init(ScrollItem_RectTransform, (trans) =>
        {
            ShopUIItem item = GameUtil.GetOrAddComponent <ShopUIItem>(trans);
            item.Init();
            BindListener(trans.GetComponent <Button>(), () =>
            {
                OnItemClick(item);
            });
        });

        BindListener(CloseBtn_Button, OnCloseClick);
        BindListener(ConfirmBtn_Button, OnConfirmClick);
    }
예제 #7
0
    void OnItemClick(ShopUIItem item)
    {
        int index = item.GetIndex();

        if (index == curSelectIndex)
        {
            return;
        }
        curSelectIndex = index;
        if (curSelectItem)
        {
            curSelectItem.SetSelect(false);
        }
        curSelectItem = item;
        curSelectItem.SetSelect(true);
        RefreshProperty();
    }
예제 #8
0
    void RefreshChild()
    {
        childMgr.RefreshChildCount(curShopData.ShopItems.Count);
        List <Transform> childList = childMgr.GetUsingTransList();

        for (int i = 0; i < childList.Count; i++)
        {
            Transform    trans      = childList[i];
            Jyx2ShopItem data       = curShopData.ShopItems[i];
            ShopUIItem   uiItem     = trans.GetComponent <ShopUIItem>();
            int          currentNum = GetHasBuyNum(data.Id);
            uiItem.Refresh(data, i, currentNum);
            uiItem.SetSelect(curSelectIndex == i);
            if (curSelectIndex == i)
            {
                curSelectItem = uiItem;
            }
        }
    }