125 lines
4.9 KiB
Lua
125 lines
4.9 KiB
Lua
--[[
|
||
* @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
|
||
|
||
Game.GlobalEvent:AddEvent(GameEvent.Shop.OnShopInfoChange, this.RefreshPanel)
|
||
|
||
this.RefreshPanel()
|
||
end
|
||
|
||
function QuickCommonPurchasePart:OnHide()
|
||
this.transform.gameObject:SetActive(false)
|
||
if this.timer then
|
||
this.timer:Stop()
|
||
this.timer = nil
|
||
end
|
||
Game.GlobalEvent:RemoveEvent(GameEvent.Shop.OnShopInfoChange,this.RefreshPanel)
|
||
|
||
end
|
||
|
||
--刷新面板
|
||
function this.RefreshPanel()
|
||
this.SetPanel()
|
||
end
|
||
|
||
|
||
function this.SetPanel()
|
||
this.TimeCountDown(ShopManager.CountShopRefreshLeftTime(SHOP_TYPE.BUYCOIN_SHOP))
|
||
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")
|
||
|
||
local storeData=ConfigManager.GetConfigDataByDoubleKey(ConfigName.StoreConfig,"StoreId",SHOP_TYPE.BUYCOIN_SHOP,"Limit",pType[i])--商店表数据
|
||
--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))
|
||
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 价格数 旧价格
|
||
|
||
local vipFactor = PrivilegeManager.GetPrivilegeNumber(PRIVILEGE_TYPE.BuyGoldAdd)
|
||
coinNum.text= math.floor(storeData.Goods[1][2] * vipFactor)
|
||
btnIcon.sprite=Util.LoadSprite(GetResourcePath(itemConfig[item].ResourceID))
|
||
btnText.text=string.format("%s领取",num)
|
||
btnIcon.gameObject:SetActive(num~=0)
|
||
if num==0 then
|
||
btnText.text="免费领取"
|
||
else
|
||
btnIcon.sprite=Util.LoadSprite(GetResourcePath(itemConfig[item].ResourceID))
|
||
btnText.text=string.format("%s领取",num)
|
||
end
|
||
timeTip.text= "剩余:"..buyTime
|
||
Util.AddOnceClick(btn,function()
|
||
if buyTime<=0 then
|
||
PopupTipPanel.ShowTip("剩余点金次数不足!")
|
||
return
|
||
end
|
||
if BagManager.GetItemCountById(item)<=0 and i~=1 and num~=0 then --i~=1 排除第一组免费领取 num~=0 排除后两组点金,第一次免费领取
|
||
PopupTipPanel.ShowTip(string.format("%s不足!",GetLanguageStrById(itemConfig[item].Name)))
|
||
return
|
||
end
|
||
ShopManager.RequestBuyShopItem(SHOP_TYPE.BUYCOIN_SHOP, storeData.Id,1 , function()
|
||
PrivilegeManager.RefreshPrivilegeUsedTimes(storeData.Limit, 1)
|
||
this.RefreshPanel()
|
||
end)
|
||
end)
|
||
end
|
||
end
|
||
|
||
function this.TimeCountDown(timeDown)
|
||
if this.timer then
|
||
this.timer:Stop()
|
||
this.timer = nil
|
||
end
|
||
this.time.text = "剩余时间:"..TimeToHMS(timeDown)
|
||
this.timer = Timer.New(function()
|
||
if timeDown < 1 then
|
||
this.timer:Stop()
|
||
this.timer = nil
|
||
this.RefreshPanel()
|
||
return
|
||
end
|
||
timeDown = timeDown - 1
|
||
this.time.text = "剩余时间:"..TimeToHMS(timeDown)
|
||
end, 1, -1, true)
|
||
this.timer:Start()
|
||
end
|
||
|
||
return QuickCommonPurchasePart |