PGRData/Resources/Scripts/XUi/XUiFubenChallengeMap/XUiPanelJieduan.lua

94 lines
3.2 KiB
Lua
Raw Normal View History

2022-12-26 08:36:01 +00:00
local XUiPanelJieduan = XClass(nil, "XUiPanelJieduan")
XUiPanelJieduan.StatusType = {
OFF = 1,
ON = 2,
REWARD = 3
}
function XUiPanelJieduan:Ctor(ui, isLast, sectionId, status)
self.GameObject = ui.gameObject
self.Transform = ui.transform
self.SectionId = sectionId
self.IsLast = isLast
self:InitAutoScript()
self:SetStatus(status)
end
-- auto
-- Automatic generation of code, forbid to edit
function XUiPanelJieduan:InitAutoScript()
self:AutoInitUi()
self.SpecialSoundMap = {}
self:AutoAddListener()
end
function XUiPanelJieduan:AutoInitUi()
self.ImgJieduanOn = self.Transform:Find("ImgJieduanOn"):GetComponent("Image")
self.ImgJieduanOff = self.Transform:Find("ImgJieduanOff"):GetComponent("Image")
self.BtnJieduanGift = self.Transform:Find("BtnJieduanGift"):GetComponent("Button")
end
function XUiPanelJieduan:GetAutoKey(uiNode,eventName)
if not uiNode then return end
return eventName .. uiNode:GetHashCode()
end
function XUiPanelJieduan:RegisterListener(uiNode, eventName, func)
local key = self:GetAutoKey(uiNode, eventName)
if not key then return end
local listener = self.AutoCreateListeners[key]
if listener ~= nil then
uiNode[eventName]:RemoveListener(listener)
end
if func ~= nil then
if type(func) ~= "function" then
XLog.Error("XUiPanelJieduan:RegisterListener函数错误, 参数func需要是function类型, func的类型是" .. type(func))
end
listener = function(...)
XSoundManager.PlayBtnMusic(self.SpecialSoundMap[key],eventName)
func(self, ...)
end
uiNode[eventName]:AddListener(listener)
self.AutoCreateListeners[key] = listener
end
end
function XUiPanelJieduan:AutoAddListener()
self.AutoCreateListeners = {}
XUiHelper.RegisterClickEvent(self, self.BtnJieduanGift, self.OnBtnJieduanGiftClick)
end
-- auto
function XUiPanelJieduan:OnBtnJieduanGiftClick()
if self.Status == XUiPanelJieduan.StatusType.REWARD then
XDataCenter.FubenDailyManager.ReceiveDailyReward(function(reward)
self.Status = XUiPanelJieduan.StatusType.ON
self:RefreshUI()
XUiManager.OpenUiObtain(reward, CS.XTextManager.GetText("Award"))
end, self.SectionId)
elseif self.Status == XUiPanelJieduan.StatusType.OFF then
local cfg = XDataCenter.FubenDailyManager.GetDailySection(self.SectionId)
local data = XRewardManager.GetRewardList(cfg.RewardId)
XUiManager.OpenUiObtain(data)
else
XUiManager.TipMsg(CS.XTextManager.GetText("ChallengeRewardIsGetted"))
end
end
function XUiPanelJieduan:RefreshUI()
self.BtnJieduanGift.gameObject:SetActive(self.IsLast)
self.BtnJieduanGift.interactable = self.Status == XUiPanelJieduan.StatusType.REWARD or self.Status == XUiPanelJieduan.StatusType.OFF
self.ImgJieduanOn.gameObject:SetActive(not self.IsLast and self.Status == XUiPanelJieduan.StatusType.ON)
self.ImgJieduanOff.gameObject:SetActive(not self.IsLast and self.Status == XUiPanelJieduan.StatusType.OFF)
end
function XUiPanelJieduan:SetStatus(status)
self.Status = status
self:RefreshUI()
end
return XUiPanelJieduan