miduo_client/Assets/ManagedResources/~Lua/Modules/FuXingGaoZhao/FuXingGaoZhaoPanel.lua

213 lines
8.0 KiB
Lua

local FuXingGaoZhaoPanel = {}
local sortingOrder = 0
function FuXingGaoZhaoPanel:New(gameObject)
local b = {}
b.gameObject = gameObject
b.transform = gameObject.transform
setmetatable(b, { __index = FuXingGaoZhaoPanel })
return b
end
local timeData = string.split(ConfigManager.GetConfigDataByKey(ConfigName.SpecialConfig,"Id",109).Value,"#")
--初始化组件(用于子类重写)
function FuXingGaoZhaoPanel:InitComponent()
self.rewardList = {}
self.itemPreList={} --item预设容器
self.data = {}
self.spLoader = SpriteLoader.New()
self.backBtn = Util.GetGameObject(self.gameObject,"Content/btnBack")
self.effect = Util.GetGameObject(self.gameObject,"Content/UI_effect_LuckyCatPanel_normal")
self.time = Util.GetGameObject(self.gameObject,"Content/Time"):GetComponent("Text")
self.price = Util.GetGameObject(self.gameObject,"Content/bg/zi/price"):GetComponent("Image")
self.price.sprite = self.spLoader:LoadSprite(ConfigManager.GetConfigData(ConfigName.SpecialConfig,114).Key)
self.getBtn = Util.GetGameObject(self.gameObject,"Content/getBtn")
self.mid = Util.GetGameObject(self.gameObject,"Content/mid")
if #self.rewardList == 0 then
for i = 1, self.mid.transform.childCount do
table.insert(self.rewardList,self.mid.transform:GetChild(i-1))
end
end
self.text = Util.GetGameObject(self.getBtn,"Text"):GetComponent("Text")
self.redPoint = Util.GetGameObject(self.getBtn,"redPoint")
end
--绑定事件(用于子类重写)
function FuXingGaoZhaoPanel:BindEvent()
Util.AddClick(self.backBtn,function ()
self:ClosePanel()
end)
Util.AddClick(self.getBtn,function ()
if self.data.ActState == 0 then
local configData = ConfigManager.GetConfigDataByKey(ConfigName.SpecialConfig,"Id",110).Value
local strings = string.split(configData,"#")
local costId, costNum = tonumber(strings[1]),tonumber(strings[2])
if costNum > BagManager.GetTotalItemNum(costId) then
JumpManager.GoJump(36003)
else
local itemName = ConfigManager.GetConfigData(ConfigName.ItemConfig,costId).Name
MsgPanel.ShowTwo(string.format(Language[12243],costNum,GetLanguageStrById(itemName)), nil, function()
NetManager.FuXingStoreBuyRequest(self.data.activityId,function ()
PopupTipPanel.ShowTip(Language[12244])
if self.timer then
self.timer:Stop()
self.timer = nil
end
self:Refresh()
end)
end)
end
elseif self.data.ActState == 1 then
NetManager.GetActivityRewardRequest(-1,self.data.activityId,function (drop)
UIManager.OpenPanel(UIName.RewardItemPopup, drop, 1,function()
self:Refresh()
end)
end)
end
end)
end
--添加事件监听(用于子类重写)
function FuXingGaoZhaoPanel:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.FiveAMRefresh.ServerNotifyRefresh, self.Refresh,self)
end
--移除事件监听(用于子类重写)
function FuXingGaoZhaoPanel:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.FiveAMRefresh.ServerNotifyRefresh, self.Refresh,self)
end
function FuXingGaoZhaoPanel:OnSortingOrderChange(_sortingOrder)
Util.SetParticleSortLayer(self.effect,_sortingOrder + 1)
self.sortingOrder = _sortingOrder
end
--界面打开时调用(用于子类重写)
function FuXingGaoZhaoPanel:OnOpen(_activityConfig,_index,parent)
self.actConfig = _activityConfig
self.pageIndex = _index
self.parent = parent
end
-- 打开,重新打开时回调
function FuXingGaoZhaoPanel:OnShow(_sortingOrder)
self.gameObject:SetActive(true)
Util.AddParticleSortLayer(self.effect, _sortingOrder - sortingOrder)
sortingOrder = _sortingOrder
self.actId = self.actConfig.ActId
self.actType = self.actConfig.ActiveType > 0 and self.actConfig.ActiveType or self.actConfig.FunType
if self.actConfig.IfBack == 1 then
if self.actConfig.ActiveType > 0 then
local id = ActivityGiftManager.IsActivityTypeOpen(self.actConfig.ActiveType)
if id and id > 0 then
self.actId = id
local config = ConfigManager.TryGetConfigDataByThreeKey(ConfigName.ActivityGroups,"PageType",self.actConfig.PageType,"ActiveType",self.actConfig.ActiveType,"ActId",id)
if config then
self.actConfig = config
end
end
end
end
FuXingGaoZhaoManager.InitRewardData()
self:Refresh()
end
function FuXingGaoZhaoPanel:Refresh()
self.data = FuXingGaoZhaoManager.GetData()
LogYellow("self.data.ActState:"..tostring(self.data.ActState))
self:SetBtn()
if self.data.ActState == 0 then
self:SetTime()
self.time.gameObject:SetActive(true)
else
self.time.gameObject:SetActive(false)
end
for i = 1, #self.rewardList do
self:SetSingleReward(self.rewardList[i],self.data.rewards[i],i)
end
CheckRedPointStatus(RedPointType.FuXingGaoZhao)
end
function FuXingGaoZhaoPanel:SetBtn()
if self.data.ActState == 0 then
self.text.text = Language[12245]
self.getBtn:SetActive(true)
self.redPoint:SetActive(false)
elseif self.data.ActState == 1 then
self.text.text = Language[11948]
local bool = FuXingGaoZhaoManager.CheckRedPoint()
self.getBtn:SetActive(bool)
self.redPoint:SetActive(bool)
elseif self.data.ActState == 2 then
self.getBtn:SetActive(false)
end
end
function FuXingGaoZhaoPanel:SetTime()
if self.timer then
self.timer:Stop()
self.timer = nil
end
local time = self.data.startTime + tonumber(timeData[1])*86400 - GetTimeStamp()
local curDay = math.ceil(time/86400)
PlayerPrefs.SetInt(PlayerManager.uid.."FuXingGaoZhao"..curDay,1)
CheckRedPointStatus(RedPointType.FuXingGaoZhao)
self.time.text = string.format(Language[12246],TimeToFelaxible(time))
self.timer = Timer.New(function()
time = time - 1
if time < 1 then
self.timer:Stop()
self.timer = nil
self.parent:ClosePanel()
end
self.time.text = string.format(Language[12246],TimeToFelaxible(time))
end, 1, -1, true)
self.timer:Start()
end
function FuXingGaoZhaoPanel:SetSingleReward(go,sdata,index)
local reward = Util.GetGameObject(go,"GameObject")
local mask = Util.GetGameObject(go,"mask")
-- LogBlue("index:"..index.." go:"..tostring(go.name).." 天数:"..tostring(NumToSimplenessFont[index]))
Util.GetGameObject(go,"Text"):GetComponent("Text").text = string.format(Language[10528],NumToSimplenessFont[index])
if not self.itemPreList[index] then
self.itemPreList[index] = SubUIManager.Open(SubUIConfig.ItemView,reward.transform)
end
self.itemPreList[index]:OnOpen(false, sdata.Reward, 0.85,false, false, false, sortingOrder)
mask:SetActive(sdata.State == 1)
local effect = Util.GetGameObject(self.itemPreList[index].gameObject,"effects/UI_Effect_jinkuang_Fang")
self.itemPreList[index]:SetEffectLayer(sortingOrder)
effect:SetActive((self.data.ActState == 1) and (sdata.State == 0) and (sdata.Progress <= GetTimeStamp()))
end
--界面关闭时调用(用于子类重写)
function FuXingGaoZhaoPanel:OnClose()
self.gameObject:SetActive(false)
if self.timer then
self.timer:Stop()
self.timer = nil
end
if self.func then
self.func()
self.func = nil
end
end
--界面销毁时调用(用于子类重写)
function FuXingGaoZhaoPanel:OnDestroy()
self.spLoader:Destroy()
if self.timer then
self.timer:Stop()
self.timer = nil
end
for k,v in pairs(self.itemPreList) do
SubUIManager.Close(v)
end
self.itemPreList={}
self.rewardList={}
end
return FuXingGaoZhaoPanel