コード例 #1
0
    void OnConfirmClick()
    {
        if (curSelectItem == null)
        {
            return;
        }
        int count = curSelectItem.GetBuyCount();

        if (count <= 0)
        {
            return;
        }
        Jyx2ShopItem item    = curShopData.ShopItems[curSelectItem.GetIndex()];
        Jyx2Item     itemCfg = ConfigTable.Get <Jyx2Item>(item.Id);

        if (itemCfg == null)
        {
            return;
        }
        int moneyCost = count * item.Price;

        if (GameRuntimeData.Instance.GetMoney() < moneyCost)
        {
            GameUtil.DisplayPopinfo("银两不够");
            return;
        }
        GameRuntimeData.Instance.AddItem(item.Id, count);
        AddBuyCount(item.Id, count);
        GameUtil.DisplayPopinfo($"获得物品{itemCfg.Name},数量{count}");
        GameRuntimeData.Instance.AddItem(Jyx2Consts.MONEY_ID, -moneyCost);

        RefreshChild();
        RefreshMoney();
    }
コード例 #2
0
    public void Refresh(Jyx2ShopItem shopItem, int index, int hasBuyNum)
    {
        this.index    = index;
        this.shopItem = shopItem;
        Jyx2Item item = ConfigTable.Get <Jyx2Item>(shopItem.Id);

        if (item == null)
        {
            GameUtil.LogError("查询不到物品配置,id =" + shopItem.Id);
            return;
        }
        Jyx2ResourceHelper.GetItemSprite(int.Parse(item.Id), iconImg);
        desText.text = $"{item.Name}\n价格:{shopItem.Price}";
        leftNum      = shopItem.Count - hasBuyNum;
        leftNum      = Tools.Limit(leftNum, 0, shopItem.Count);
        itemNum.text = leftNum.ToString();
    }
コード例 #3
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;
            }
        }
    }