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

131 lines
5.2 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.BuyCoin,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))
local levelConfig = ConfigManager.GetConfigDataByKey(ConfigName.PlayerLevelConfig,"PlayerLv",PlayerManager.level)
local levelNums = {0,0,0}
if levelConfig then
levelNums = {levelConfig.GoldExtraNum1,levelConfig.GoldExtraNum2,levelConfig.GoldExtraNum3}
end
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] + levelNums[i]) * (vipFactor*100)/100)
btnIcon.sprite=this.mainPanel.spLoader:LoadSprite(GetResourcePath(itemConfig[item].ResourceID))
btnText.text=string.format(Language[11655],num)
btnIcon.gameObject:SetActive(num~=0)
if num==0 then
btnText.text=Language[11656]
else
btnIcon.sprite=this.mainPanel.spLoader:LoadSprite(GetResourcePath(itemConfig[item].ResourceID))
btnText.text=string.format(Language[11655],num)
end
timeTip.text= Language[10580]..buyTime
Util.AddOnceClick(btn,function()
if buyTime<=0 then
PopupTipPanel.ShowTip(Language[11657])
return
end
if BagManager.GetItemCountById(item)<=0 and i~=1 and num~=0 then --i~=1 排除第一组免费领取 num~=0 排除后两组点金,第一次免费领取
PopupTipPanel.ShowTip(string.format(Language[10298],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 = Language[10023]..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 = Language[10023]..TimeToHMS(timeDown)
end, 1, -1, true)
this.timer:Start()
end
return QuickCommonPurchasePart