PGRData/Resources/Scripts/XUi/XUiPlayer/XUiPanelSetBirthday.lua
2022-12-26 14:06:01 +05:30

94 lines
No EOL
2.7 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

XUiPanelSetBirthday = XClass(nil, "XUiPanelSetBirthday")
function XUiPanelSetBirthday:Ctor(ui,base)
self.GameObject = ui.gameObject
self.Transform = ui.transform
self.Base = base
XTool.InitUiObject(self)
self:InitAutoScript()
end
-- auto
-- Automatic generation of code, forbid to edit
function XUiPanelSetBirthday:InitAutoScript()
self:AutoInitUi()
self:AutoAddListener()
end
function XUiPanelSetBirthday:AutoInitUi()
self.BtnBirSure = self.Transform:Find("BtnBirSure"):GetComponent("Button")
self.BtnBirCancel = self.Transform:Find("BtnBirCancel"):GetComponent("Button")
self.TxtB = self.Transform:Find("Txt"):GetComponent("Text")
self.TxtMon = self.Transform:Find("InMon/TxtMon"):GetComponent("Text")
self.TxtDay = self.Transform:Find("InDay/TxtDay"):GetComponent("Text")
end
function XUiPanelSetBirthday:RegisterClickEvent(uiNode, func)
if func == nil then
XLog.Error("XUiPanelSetBirthday:RegisterClickEvent函数参数错误参数func不能为空")
return
end
if type(func) ~= "function" then
XLog.Error("XUiPanelSetBirthday:RegisterClickEvent函数错误, 参数func需要是function类型, func的类型是" .. type(func))
end
local listener = function(...)
func(self, ...)
end
CsXUiHelper.RegisterClickEvent(uiNode, listener)
end
function XUiPanelSetBirthday:AutoAddListener()
self:RegisterClickEvent(self.BtnBirSure, self.OnBtnBirSureClick)
self:RegisterClickEvent(self.BtnBirCancel, self.OnBtnBirCancelClick)
self.BtnClose.CallBack = function()
self:OnBtnBirCancelClick()
end
end
-- auto
function XUiPanelSetBirthday:OnBtnBirSureClick()
local dayNum = 31
local mon = tonumber(self.TxtMon.text)
local day = tonumber(self.TxtDay.text)
if not mon or not day then
XUiManager.TipText("WrongDate",XUiManager.UiTipType.Wrong)
return
end
if mon < 1 or mon > 12 then
XUiManager.TipText("WrongDate",XUiManager.UiTipType.Wrong)
return
end
if mon == 2 then
dayNum = 29
elseif mon == 4 or mon == 6 or mon == 9 or mon == 11 then
dayNum = 30
end
if day < 1 or day > dayNum then
XUiManager.TipText("WrongDate",XUiManager.UiTipType.Wrong)
return
end
local currBir = XPlayer.Birthday
if currBir then
if (currBir.Mon and mon == currBir.Mon) and (currBir.Day and day == currBir.Day) then
self.Base:HidePanelSetBirthday()
return
end
end
XPlayer.ChangeBirthday(mon, day, function()
self.Base:ChangeBirthdayCallback()
end)
end
function XUiPanelSetBirthday:OnBtnBirCancelClick()
self.Base:HidePanelSetBirthday()
end
return XUiPanelSetBirthday