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

213 lines
8.0 KiB
Lua
Raw Normal View History

2021-05-22 15:10:06 +08:00
local FuXingGaoZhaoPanel = {}
2021-03-29 09:52:53 +08:00
local sortingOrder = 0
2021-05-22 15:10:06 +08:00
function FuXingGaoZhaoPanel:New(gameObject)
local b = {}
b.gameObject = gameObject
b.transform = gameObject.transform
setmetatable(b, { __index = FuXingGaoZhaoPanel })
return b
end
2021-03-30 16:24:28 +08:00
local timeData = string.split(ConfigManager.GetConfigDataByKey(ConfigName.SpecialConfig,"Id",109).Value,"#")
2021-05-22 15:10:06 +08:00
2021-03-29 09:52:53 +08:00
--初始化组件(用于子类重写)
2021-05-22 15:10:06 +08:00
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")
2021-05-18 20:22:26 +08:00
self.price = Util.GetGameObject(self.gameObject,"Content/bg/zi/price"):GetComponent("Image")
2021-05-22 15:10:06 +08:00
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")
2021-05-22 15:10:06 +08:00
if #self.rewardList == 0 then
2021-03-30 10:27:18 +08:00
for i = 1, self.mid.transform.childCount do
2021-05-22 15:10:06 +08:00
table.insert(self.rewardList,self.mid.transform:GetChild(i-1))
2021-03-30 10:27:18 +08:00
end
end
2021-05-22 15:10:06 +08:00
self.text = Util.GetGameObject(self.getBtn,"Text"):GetComponent("Text")
self.redPoint = Util.GetGameObject(self.getBtn,"redPoint")
2021-03-29 09:52:53 +08:00
end
--绑定事件(用于子类重写)
2021-05-22 15:10:06 +08:00
function FuXingGaoZhaoPanel:BindEvent()
2021-03-29 09:52:53 +08:00
Util.AddClick(self.backBtn,function ()
self:ClosePanel()
end)
2021-03-30 10:27:18 +08:00
Util.AddClick(self.getBtn,function ()
2021-05-22 15:10:06 +08:00
if self.data.ActState == 0 then
2021-03-30 18:50:15 +08:00
local configData = ConfigManager.GetConfigDataByKey(ConfigName.SpecialConfig,"Id",110).Value
2021-03-30 20:20:12 +08:00
local strings = string.split(configData,"#")
local costId, costNum = tonumber(strings[1]),tonumber(strings[2])
2021-03-30 10:27:18 +08:00
if costNum > BagManager.GetTotalItemNum(costId) then
JumpManager.GoJump(36003)
else
local itemName = ConfigManager.GetConfigData(ConfigName.ItemConfig,costId).Name
2021-04-09 12:26:35 +08:00
MsgPanel.ShowTwo(string.format(Language[12243],costNum,GetLanguageStrById(itemName)), nil, function()
2021-05-22 15:10:06 +08:00
NetManager.FuXingStoreBuyRequest(self.data.activityId,function ()
2021-04-09 12:26:35 +08:00
PopupTipPanel.ShowTip(Language[12244])
2021-05-28 16:20:14 +08:00
if self.timer then
self.timer:Stop()
self.timer = nil
end
2021-05-22 15:10:06 +08:00
self:Refresh()
2021-03-30 18:50:15 +08:00
end)
2021-03-30 10:27:18 +08:00
end)
end
2021-05-22 15:10:06 +08:00
elseif self.data.ActState == 1 then
NetManager.GetActivityRewardRequest(-1,self.data.activityId,function (drop)
2021-03-30 10:27:18 +08:00
UIManager.OpenPanel(UIName.RewardItemPopup, drop, 1,function()
2021-05-22 15:10:06 +08:00
self:Refresh()
2021-03-30 10:27:18 +08:00
end)
end)
end
end)
2021-03-29 09:52:53 +08:00
end
--添加事件监听(用于子类重写)
2021-05-22 15:10:06 +08:00
function FuXingGaoZhaoPanel:AddListener()
2021-05-27 14:09:39 +08:00
Game.GlobalEvent:AddEvent(GameEvent.FiveAMRefresh.ServerNotifyRefresh, self.Refresh,self)
2021-03-29 09:52:53 +08:00
end
--移除事件监听(用于子类重写)
2021-05-22 15:10:06 +08:00
function FuXingGaoZhaoPanel:RemoveListener()
2021-05-27 14:09:39 +08:00
Game.GlobalEvent:RemoveEvent(GameEvent.FiveAMRefresh.ServerNotifyRefresh, self.Refresh,self)
2021-03-29 09:52:53 +08:00
end
2021-06-02 15:47:26 +08:00
function FuXingGaoZhaoPanel:OnSortingOrderChange(_sortingOrder)
Util.SetParticleSortLayer(self.effect,_sortingOrder + 1)
self.sortingOrder = _sortingOrder
2021-03-29 09:52:53 +08:00
end
--界面打开时调用(用于子类重写)
2021-05-24 11:08:16 +08:00
function FuXingGaoZhaoPanel:OnOpen(_activityConfig,_index,parent)
2021-05-22 15:10:06 +08:00
self.actConfig = _activityConfig
self.pageIndex = _index
self.parent = parent
2021-03-29 09:52:53 +08:00
end
-- 打开,重新打开时回调
2021-05-24 11:08:16 +08:00
function FuXingGaoZhaoPanel:OnShow(_sortingOrder)
2021-05-22 15:10:06 +08:00
self.gameObject:SetActive(true)
2021-05-24 11:08:16 +08:00
Util.AddParticleSortLayer(self.effect, _sortingOrder - sortingOrder)
sortingOrder = _sortingOrder
2021-05-22 15:10:06 +08:00
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()
2021-03-30 10:27:18 +08:00
end
2021-05-22 15:10:06 +08:00
function FuXingGaoZhaoPanel:Refresh()
self.data = FuXingGaoZhaoManager.GetData()
2021-05-27 14:09:39 +08:00
LogYellow("self.data.ActState:"..tostring(self.data.ActState))
2021-05-22 15:10:06 +08:00
self:SetBtn()
if self.data.ActState == 0 then
self:SetTime()
2021-03-30 16:24:28 +08:00
self.time.gameObject:SetActive(true)
else
self.time.gameObject:SetActive(false)
end
2021-05-22 15:10:06 +08:00
for i = 1, #self.rewardList do
self:SetSingleReward(self.rewardList[i],self.data.rewards[i],i)
2021-03-30 10:27:18 +08:00
end
CheckRedPointStatus(RedPointType.FuXingGaoZhao)
2021-03-30 10:27:18 +08:00
end
2021-05-22 15:10:06 +08:00
function FuXingGaoZhaoPanel:SetBtn()
if self.data.ActState == 0 then
self.text.text = Language[12245]
2021-03-30 10:27:18 +08:00
self.getBtn:SetActive(true)
2021-05-22 15:10:06 +08:00
self.redPoint:SetActive(false)
elseif self.data.ActState == 1 then
self.text.text = Language[11948]
2021-03-30 10:27:18 +08:00
local bool = FuXingGaoZhaoManager.CheckRedPoint()
self.getBtn:SetActive(bool)
2021-05-22 15:10:06 +08:00
self.redPoint:SetActive(bool)
elseif self.data.ActState == 2 then
2021-03-30 16:24:28 +08:00
self.getBtn:SetActive(false)
2021-03-30 10:27:18 +08:00
end
end
2021-03-29 09:52:53 +08:00
2021-05-22 15:10:06 +08:00
function FuXingGaoZhaoPanel:SetTime()
2021-03-30 16:24:28 +08:00
if self.timer then
self.timer:Stop()
self.timer = nil
end
2021-05-22 15:10:06 +08:00
local time = self.data.startTime + tonumber(timeData[1])*86400 - GetTimeStamp()
2021-05-27 14:09:39 +08:00
local curDay = math.ceil(time/86400)
PlayerPrefs.SetInt(PlayerManager.uid.."FuXingGaoZhao"..curDay,1)
CheckRedPointStatus(RedPointType.FuXingGaoZhao)
2021-04-09 12:26:35 +08:00
self.time.text = string.format(Language[12246],TimeToFelaxible(time))
2021-03-30 16:24:28 +08:00
self.timer = Timer.New(function()
time = time - 1
if time < 1 then
self.timer:Stop()
self.timer = nil
2021-05-27 17:40:54 +08:00
self.parent:ClosePanel()
2021-03-30 16:24:28 +08:00
end
2021-04-09 12:26:35 +08:00
self.time.text = string.format(Language[12246],TimeToFelaxible(time))
2021-03-30 16:24:28 +08:00
end, 1, -1, true)
self.timer:Start()
end
2021-05-22 15:10:06 +08:00
function FuXingGaoZhaoPanel:SetSingleReward(go,sdata,index)
2021-03-30 10:27:18 +08:00
local reward = Util.GetGameObject(go,"GameObject")
2021-03-30 16:24:28 +08:00
local mask = Util.GetGameObject(go,"mask")
-- LogBlue("index:"..index.." go:"..tostring(go.name).." 天数:"..tostring(NumToSimplenessFont[index]))
2021-04-09 12:26:35 +08:00
Util.GetGameObject(go,"Text"):GetComponent("Text").text = string.format(Language[10528],NumToSimplenessFont[index])
2021-05-22 15:10:06 +08:00
if not self.itemPreList[index] then
self.itemPreList[index] = SubUIManager.Open(SubUIConfig.ItemView,reward.transform)
2021-03-30 10:27:18 +08:00
end
2021-05-22 15:10:06 +08:00
self.itemPreList[index]:OnOpen(false, sdata.Reward, 0.85,false, false, false, sortingOrder)
2021-03-30 17:53:01 +08:00
mask:SetActive(sdata.State == 1)
2021-05-22 15:10:06 +08:00
local effect = Util.GetGameObject(self.itemPreList[index].gameObject,"effects/UI_Effect_jinkuang_Fang")
2021-05-24 11:08:16 +08:00
self.itemPreList[index]:SetEffectLayer(sortingOrder)
2021-05-22 15:10:06 +08:00
effect:SetActive((self.data.ActState == 1) and (sdata.State == 0) and (sdata.Progress <= GetTimeStamp()))
2021-03-29 09:52:53 +08:00
end
--界面关闭时调用(用于子类重写)
2021-05-22 15:10:06 +08:00
function FuXingGaoZhaoPanel:OnClose()
self.gameObject:SetActive(false)
2021-03-30 16:24:28 +08:00
if self.timer then
self.timer:Stop()
self.timer = nil
2021-03-30 20:20:12 +08:00
end
2021-05-22 15:10:06 +08:00
if self.func then
self.func()
self.func = nil
2021-03-30 20:20:12 +08:00
end
2021-03-29 09:52:53 +08:00
end
--界面销毁时调用(用于子类重写)
2021-05-22 15:10:06 +08:00
function FuXingGaoZhaoPanel:OnDestroy()
self.spLoader:Destroy()
2021-03-30 16:24:28 +08:00
if self.timer then
self.timer:Stop()
self.timer = nil
end
2021-05-24 11:08:16 +08:00
for k,v in pairs(self.itemPreList) do
SubUIManager.Close(v)
end
2021-05-22 15:10:06 +08:00
self.itemPreList={}
self.rewardList={}
2021-03-29 09:52:53 +08:00
end
2021-05-22 15:10:06 +08:00
return FuXingGaoZhaoPanel