KLFirstChargeADPanel.lua 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. ---@class KLFirstChargeADPanel:UIKmlLuaPanelBase
  2. ---@field view KLFirstChargeADPanelView
  3. local KLFirstChargeADPanel = class(UIKmlLuaPanelBase)
  4. local this = KLFirstChargeADPanel
  5. function this:AsyncLoadUI()
  6. end
  7. ---创建时调用一次
  8. function this:Init()
  9. end
  10. function this:SetPos()
  11. local PlayerPanel = GUI:GetUI("dev/ui/MainUI/Panel/KLUISystemTop/KLUISystemTopPanel")
  12. if PlayerPanel and PlayerPanel.systemTemplateList then
  13. for i, systemItem in pairs(PlayerPanel.systemTemplateList) do
  14. if systemItem.args.id == 203 then
  15. self.FirstBtn = systemItem
  16. local worldPositionX, worldPositionY = GUI:GetWorldPosition(self.FirstBtn.view.root)
  17. GUI:SetWorldPosition(self.view.root, worldPositionX-0.6, worldPositionY+0.5, 100)
  18. end
  19. end
  20. end
  21. end
  22. ---注册UI事件和服务器消息
  23. function this:RegistEvents()
  24. GUI:AddOnClickEvent(self.view.CloseBtn, self, self.CloseBtnOnClick)
  25. end
  26. function this:CloseBtnOnClick()
  27. self:SaveComplete()
  28. SL:HideMainPanel()
  29. GUI:UIPanel_Open("dev/outui/FirstCharge/Panel/KLFirstCharge/KLFirstChargePanel")
  30. GUI:UIPanel_Close("dev/outui/FirstCharge/Panel/KLFirstChargeAD/KLFirstChargeADPanel")
  31. end
  32. ---界面显示时调用一次
  33. function this:Show()
  34. GUI:SetActive(self.view.root,false)
  35. if self.args and self.args.count then
  36. local count = self.args.count + 1
  37. self.showTimer = self.args.count
  38. local RoleId = SL:GetMetaValue(EMetaVarGetKey.MAIN_ACTOR_ID)
  39. local careerID = SL:GetMetaValue(EMetaVarGetKey.ACTOR_JOB_ID)
  40. for _,v in pairs(self.args.popUpsPicture) do
  41. if v[1] and tonumber(v[1]) == careerID then
  42. PlayerPrefs.SetString("FirstChargeAdPopUpsPictureCareerID" ..RoleId, v[1])
  43. PlayerPrefs.SetString("FirstChargeAdPopUpsPictureIcon" ..RoleId, v[2])
  44. GUI:Image_loadTexture(self.view.model_icon, v[2], "Atlas/QJ5_UIRechargeMainPanel.spriteatlas")
  45. end
  46. end
  47. PlayerPrefs.SetString("FirstChargeAdComplete" ..RoleId, "false")
  48. PlayerPrefs.Save()
  49. --[[ local RoleId = SL:GetMetaValue(EMetaVarGetKey.MAIN_ACTOR_ID)
  50. self.SaveFirstChargeAd = "FirstChargeAdTime" .. RoleId
  51. local savePre = PlayerPrefs.GetInt(self.SaveFirstChargeAd)
  52. local complete = PlayerPrefs.GetString("FirstChargeAdComplete" ..RoleId,"false")
  53. if complete == "true" then
  54. GUI:UIPanel_Close("dev/outui/FirstCharge/Panel/KLFirstChargeAD/KLFirstChargeADPanel")
  55. return
  56. end
  57. if savePre > 0 then
  58. self.showTimer = savePre
  59. count = self.showTimer + 1
  60. else
  61. self.showTimer = 120
  62. count = self.showTimer + 1
  63. end]]
  64. self.timer = SL:Schedule(self.timer, 1, 1, count, function()
  65. self:SetPos()
  66. self.showTimer = self.showTimer - 1
  67. local minute = math.floor(self.showTimer / 60)
  68. local time = string.format("%02d分%02d秒", minute, (self.showTimer - minute * 60))
  69. GUI:Text_setString(self.view.DevilText, time)
  70. PlayerPrefs.SetString("FirstChargeAdTime" ..RoleId, self.showTimer)
  71. PlayerPrefs.Save()
  72. GUI:SetActive(self.view.root,true)
  73. if self.showTimer <= 0 then
  74. self:SaveComplete()
  75. GUI:UIPanel_Close("dev/outui/FirstCharge/Panel/KLFirstChargeAD/KLFirstChargeADPanel")
  76. end
  77. end)
  78. end
  79. end
  80. ---创建或者刷新界面数据时调用
  81. function this:Refresh()
  82. end
  83. function this:SaveComplete()
  84. local RoleId = SL:GetMetaValue(EMetaVarGetKey.MAIN_ACTOR_ID)
  85. PlayerPrefs.SetString("FirstChargeAdComplete" ..RoleId, "true")
  86. PlayerPrefs.Save()
  87. end
  88. function this:Close()
  89. if self.timer then
  90. SL:UnSchedule(self.timer)
  91. end
  92. self.timer = nil
  93. local RoleId = SL:GetMetaValue(EMetaVarGetKey.MAIN_ACTOR_ID)
  94. if RoleId then
  95. PlayerPrefs.SetString("FirstChargeAdTime" ..RoleId, self.showTimer)
  96. PlayerPrefs.Save()
  97. end
  98. end
  99. function this:OnHide()
  100. if self.timer then
  101. SL:UnSchedule(self.timer)
  102. end
  103. self.timer = nil
  104. end
  105. return this