예제 #1
0
    void OpenBuyForm(int resId)
    {
        if (!DataManager.ShopTable.ContainsKey(resId))
        {
            return;
        }

        if (!mAllItemsLists.ContainsKey(resId))
        {
            return;
        }

        ShopItemUI itemUi = mAllItemsLists[resId];

        if (itemUi == null || itemUi.IsScretItemBuyDone)
        {
            return;
        }

        ShopTableItem item = DataManager.ShopTable[resId] as ShopTableItem;

        ItemTableItem tableItem = ItemManager.GetItemRes(item.itemId);

        if (tableItem == null)
        {
#if UNITY_EDITOR
            GameDebug.LogError("物品表中缺少ID为" + item.itemId + "的物品");
#endif
            return;
        }

        //gNameLb.text = tableItem.name;
        gNameLb.text       = ItemManager.getItemNameWithColor(item.itemId);
        gItemDetailLb.text = tableItem.desc;
        gGetDetailLb.text  = tableItem.desc0;
        UIAtlasHelper.SetSpriteImage(gIconSp, tableItem.picname, true);
        gItemTypeLb.text = ItemManager.GetItemTypeStr(item.itemId);

        ProceedsType pt   = ProceedsType.Invalid;
        int          cost = 0;

        if (!itemUi.GetProcTypeAndCost(ref pt, ref cost))
        {
            return;
        }

        UIAtlasHelper.SetSpriteByMoneyType(gMoneySp, pt);
        gMoneySp.transform.localScale = new Vector3(0.5f, 0.5f, 1f);

        PlayerDataModule playerModule = ModuleManager.Instance.FindModule <PlayerDataModule>();
        if (playerModule == null)
        {
            GameDebug.LogError("player data is null!");
            return;
        }

        if (playerModule.GetProceeds(pt) < cost)
        {
            gMoneyLb.text = StringHelper.StringWithColor(FontColor.Red, cost.ToString());
        }
        else
        {
            gMoneyLb.text = cost.ToString();
        }

        gBuyObj.SetActive(true);
    }
예제 #2
0
    void BuyMallItem(int resId)
    {
        ShopTableItem item = DataManager.ShopTable[resId] as ShopTableItem;

        if (item == null)
        {
            return;
        }

        PlayerDataModule pdm = ModuleManager.Instance.FindModule <PlayerDataModule>();

        if (pdm == null || pdm.GetShopIsBuyDone(resId))
        {
            return;
        }

        if (!mAllItemsLists.ContainsKey(resId))
        {
            return;
        }

        ShopItemUI itemUi = mAllItemsLists[resId];

        if (itemUi == null)
        {
            return;
        }

        // 已经买了吗;
        if (itemUi.IsScretItemBuyDone)
        {
            //PromptUIManager.Instance.AddNewPrompt(StringHelper.GetString("buy_done"));
            PopTipManager.Instance.AddNewTip(StringHelper.StringWithColor(FontColor.Red, StringHelper.GetString("buy_done")));
            return;
        }

        /// 钱够了吗;
        ProceedsType pt   = ProceedsType.Invalid;
        int          cost = 0;

        if (!itemUi.GetProcTypeAndCost(ref pt, ref cost))
        {
            return;
        }

        if (pdm.GetProceeds(pt) < cost)
        {
            //PromptUIManager.Instance.AddNewPrompt(ShopModule.GetBuyMoneyNotEnougthStr(pt));
            PopTipManager.Instance.AddNewTip(StringHelper.StringWithColor(FontColor.Red, ShopModule.GetBuyMoneyNotEnougthStr(pt)));
            return;
        }

        // 成功逻辑;
        ShopBuyItemAction param = new ShopBuyItemAction();

        param.OpType = (int)ShopOpType.BuyItem;
        param.ResId  = resId;

        Net.Instance.DoAction((int)Message.MESSAGE_ID.ID_MSG_SHOP, param);

        //MallBuyItemAction param = new MallBuyItemAction();
        //param.ResId = resId;
        //param.SubIdx = subId;

        ////有钱没;
        //MallItemInfo info = item.mallItems[subId];
        //if (pdm.GetProceeds((ProceedsType)item.processType) < info.processNow)
        //{
        //    PromptUIManager.Instance.AddNewPrompt("钱不够");
        //    return;
        //}

        ////次数够了没;
        //switch (mModule.GetLimitTypeByID(resId))
        //{
        //    case MallLimitType.ERROR:
        //        GameDebug.LogError("数据错误");
        //        return;
        //    case MallLimitType.NONE:
        //        break;
        //    case MallLimitType.DAY:
        //    case MallLimitType.FOREVER:
        //        if (mModule.GetPlayerBuyTimes(resId) >= item.limitTimes)
        //        {
        //            PromptUIManager.Instance.AddNewPrompt("购买次数够了");
        //            return;
        //        }
        //        break;
        //}

        //Net.Instance.DoAction((int)Message.MESSAGE_ID.ID_MSG_MALL_BUY, param);
    }