miduo_client/Assets/ManagedResources/~Lua/Modules/QuickPurchase/QuickCoinPurchasePart.lua

125 lines
4.9 KiB
Lua
Raw Normal View History

2020-08-25 15:46:38 +08:00
 --[[
2020-05-09 13:31:21 +08:00
* @ClassName QuickCommonPurchasePart
* @Description
* @Date 2020/4/27 18:05
* @Author MagicianJoker, fengliudianshao@outlook.com
* @Copyright Copyright (c) 2019, MagicianJoker
--]]
local QuickCommonPurchasePart = quick_class("QuickCommonPurchasePart")
local this=QuickCommonPurchasePart
local itemConfig=ConfigManager.GetConfig(ConfigName.ItemConfig)
local specialConfig=ConfigManager.GetConfig(ConfigName.SpecialConfig)
local panels={}--小面板容器
local pType={[1]=12,[2]=51,[3]=52}--特权类型
function QuickCommonPurchasePart:ctor(mainPanel, transform)
this.mainPanel = mainPanel
this.transform = transform
this.time=this.transform:Find("Time"):GetComponent("Text")
this.helpBtn=this.transform:Find("HelpBtn")
this.helpPosition=this.helpBtn:GetComponent("RectTransform").localPosition
this.panel=this.transform:Find("Panel")
for i = 1, 3 do
panels[i]=Util.GetGameObject(this.panel,"Get"..i)
end
Util.AddClick(this.helpBtn.gameObject,function()
UIManager.OpenPanel(UIName.HelpPopup,HELP_TYPE.DailyCarbon,this.helpPosition.x,this.helpPosition.y)
end)
end
function QuickCommonPurchasePart:OnShow(context)
this.transform.gameObject:SetActive(true)
this.context = context
2020-06-03 19:09:01 +08:00
Game.GlobalEvent:AddEvent(GameEvent.Shop.OnShopInfoChange, this.RefreshPanel)
2020-05-09 13:31:21 +08:00
this.RefreshPanel()
end
function QuickCommonPurchasePart:OnHide()
this.transform.gameObject:SetActive(false)
if this.timer then
this.timer:Stop()
this.timer = nil
end
2020-06-03 19:09:01 +08:00
Game.GlobalEvent:RemoveEvent(GameEvent.Shop.OnShopInfoChange,this.RefreshPanel)
2020-05-09 13:31:21 +08:00
end
--刷新面板
function this.RefreshPanel()
this.SetPanel()
end
function this.SetPanel()
2020-06-03 19:09:01 +08:00
this.TimeCountDown(ShopManager.CountShopRefreshLeftTime(SHOP_TYPE.BUYCOIN_SHOP))
2020-05-09 13:31:21 +08:00
for i = 1, #panels do
local o=panels[i]
local coinNum=Util.GetGameObject(o,"Coin/Num"):GetComponent("Text")
local btn=Util.GetGameObject(o,"Btn")
local btnIcon=Util.GetGameObject(o,"Btn/Icon"):GetComponent("Image")
local btnText=Util.GetGameObject(o,"Btn/Text"):GetComponent("Text")
local timeTip=Util.GetGameObject(o,"TimeTip"):GetComponent("Text")
2020-06-03 19:09:01 +08:00
local storeData=ConfigManager.GetConfigDataByDoubleKey(ConfigName.StoreConfig,"StoreId",SHOP_TYPE.BUYCOIN_SHOP,"Limit",pType[i])--商店表数据
2020-06-18 20:39:29 +08:00
--LogBlue("storeData.Id"..storeData.Id) --PrivilegeManager.GetPrivilegeRemainValue(storeData.Limit)
--LogBlue("storeData.Limit"..storeData.Limit) --PrivilegeManager.GetPrivilegeRemainValue(storeData.Limit)
--LogBlue("maxTimes = "..PrivilegeManager.GetPrivilegeNumber(storeData.Limit))
--LogBlue("bugTimes = "..ShopManager.GetShopItemHadBuyTimes(SHOP_TYPE.BUYCOIN_SHOP,storeData.Id))
2020-06-03 19:09:01 +08:00
local buyTime= PrivilegeManager.GetPrivilegeNumber(storeData.Limit)-ShopManager.GetShopItemHadBuyTimes(SHOP_TYPE.BUYCOIN_SHOP,storeData.Id) -- 购买次数
local item,num,oldNum = ShopManager.CalculateCostCountByShopId(SHOP_TYPE.BUYCOIN_SHOP, storeData.Id, 1) --商品ID 价格数 旧价格
2020-05-09 13:31:21 +08:00
2020-06-18 20:39:29 +08:00
local vipFactor = PrivilegeManager.GetPrivilegeNumber(PRIVILEGE_TYPE.BuyGoldAdd)
coinNum.text= math.floor(storeData.Goods[1][2] * vipFactor)
2020-05-09 13:31:21 +08:00
btnIcon.sprite=Util.LoadSprite(GetResourcePath(itemConfig[item].ResourceID))
2021-02-20 18:01:57 +08:00
btnText.text=string.format(Language[11655],num)
2020-05-09 13:31:21 +08:00
btnIcon.gameObject:SetActive(num~=0)
if num==0 then
2021-02-20 18:01:57 +08:00
btnText.text=Language[11656]
2020-05-09 13:31:21 +08:00
else
btnIcon.sprite=Util.LoadSprite(GetResourcePath(itemConfig[item].ResourceID))
2021-02-20 18:01:57 +08:00
btnText.text=string.format(Language[11655],num)
2020-05-09 13:31:21 +08:00
end
2021-02-20 18:01:57 +08:00
timeTip.text= Language[10580]..buyTime
2020-05-09 13:31:21 +08:00
Util.AddOnceClick(btn,function()
if buyTime<=0 then
2021-02-20 18:01:57 +08:00
PopupTipPanel.ShowTip(Language[11657])
2020-05-09 13:31:21 +08:00
return
end
if BagManager.GetItemCountById(item)<=0 and i~=1 and num~=0 then --i~=1 排除第一组免费领取 num~=0 排除后两组点金,第一次免费领取
2021-02-20 18:01:57 +08:00
PopupTipPanel.ShowTip(string.format(Language[10298],GetLanguageStrById(itemConfig[item].Name)))
2020-05-09 13:31:21 +08:00
return
end
2020-06-03 19:09:01 +08:00
ShopManager.RequestBuyShopItem(SHOP_TYPE.BUYCOIN_SHOP, storeData.Id,1 , function()
2020-05-25 19:55:27 +08:00
PrivilegeManager.RefreshPrivilegeUsedTimes(storeData.Limit, 1)
2020-05-09 13:31:21 +08:00
this.RefreshPanel()
end)
end)
end
end
function this.TimeCountDown(timeDown)
if this.timer then
this.timer:Stop()
this.timer = nil
end
2021-02-20 18:01:57 +08:00
this.time.text = Language[10023]..TimeToHMS(timeDown)
2020-05-09 13:31:21 +08:00
this.timer = Timer.New(function()
if timeDown < 1 then
this.timer:Stop()
this.timer = nil
this.RefreshPanel()
return
end
timeDown = timeDown - 1
2021-02-20 18:01:57 +08:00
this.time.text = Language[10023]..TimeToHMS(timeDown)
2020-05-09 13:31:21 +08:00
end, 1, -1, true)
this.timer:Start()
end
2020-06-23 18:36:24 +08:00
return QuickCommonPurchasePart