KLRedFortPanel.lua 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. ---@class KLRedFortPanel:UIKmlLuaPanelBase
  2. ---@field view KLRedFortPanelView
  3. ---@field cfg cfg_rep_column
  4. local KLRedFortPanel = class(UIKmlLuaPanelBase)
  5. local this = KLRedFortPanel
  6. ---创建时调用一次
  7. function this:Init()
  8. self.itemList = {}
  9. end
  10. ---注册UI事件和服务器消息
  11. function this:RegistEvents()
  12. GUI:AddOnClickEvent(self.view.btnClose, self, self.BtnCloseOnClick)
  13. GUI:AddOnClickEvent(self.view.btnEnter, self, self.BtnEnterOnClick)
  14. end
  15. function this:BtnCloseOnClick()
  16. GUI:UIPanel_Close("dev/outui/Activity/Panel/KLRedFort/KLRedFortPanel")
  17. end
  18. function this:BtnEnterOnClick()
  19. self.cfg = InfoManager.redFortInfo:GetCfgByLevel()
  20. ---@type cfg_activity_rule_column
  21. self.activityInfo = InfoManager.activityPreviewInfo:GetActivityInfo(InfoManager.redFortInfo.activityCfg.id)
  22. local isInTeam = SL:GetMetaValue(EMetaVarGetKey.TEAM_IS_IN)
  23. if isInTeam then
  24. SL:TipMessage( SL:GetConfig('cfg_string',248).text, 1, NoticeType.NoticeMid )--"请先退出队伍!",
  25. return
  26. end
  27. local level = SL:GetMetaValue(EMetaVarGetKey.LEVEL)
  28. if level < InfoManager.redFortInfo.activityCfg.level then
  29. SL:TipMessage( SL:GetConfig('cfg_string',249).text,1, NoticeType.NoticeMid )--"等级不足!",
  30. return
  31. end
  32. if not self.cfg or not self.activityInfo then
  33. SL:TipMessage(SL:GetConfig('cfg_string',250).text,1, NoticeType.NoticeMid )-- "活动未开启",
  34. return
  35. end
  36. if not self.activityInfo.open then
  37. SL:TipMessage(SL:GetConfig('cfg_string',251).text,1, NoticeType.NoticeMid )-- "本次活动报名已截止",
  38. return
  39. end
  40. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_ENTER_DUPLICATE, self.cfg.id)
  41. end
  42. ---创建或者刷新界面数据时调用
  43. function this:Refresh()
  44. SL:HideMainPanel()
  45. self:RefreshUI()
  46. end
  47. function this:RefreshUI()
  48. self.cfg = InfoManager.redFortInfo:GetCfgByMinLevel()
  49. local level = SL:GetMetaValue(EMetaVarGetKey.LEVEL)
  50. GUI:Text_setString(self.view.textLevel, tostring(InfoManager.redFortInfo.activityCfg.level))
  51. if level < InfoManager.redFortInfo.activityCfg.level then
  52. GUI:Text_setTextColor(self.view.textLevel,EColor[EGradColor.red])
  53. else
  54. GUI:Text_setTextColor(self.view.textLevel,EColor[EGradColor.green])
  55. end
  56. local times = string.split(InfoManager.redFortInfo.activityCfg.timeText, "|")
  57. GUI:Text_setString(self.view.textOpenTime, times[1])
  58. GUI:Text_setString(self.view.textActivityTime, times[2])
  59. self:InitRewards()
  60. self:RefreshTimeText()
  61. if not self.timer then
  62. ---self.timer = Timer.StartLoopForever(1, self.RefreshTimeText, self)
  63. self.timer = SL:StartLoopForever(1, self.RefreshTimeText, self)
  64. end
  65. end
  66. function this:InitRewards()
  67. local itemRewards = self.cfg.UIreward
  68. if not itemRewards or #itemRewards == 0 then
  69. itemRewards = InfoManager.redFortInfo:GetCfgByMinLevel()
  70. end
  71. if #self.itemList >= #itemRewards then
  72. for i = 1, #self.itemList do
  73. if i <= #itemRewards then
  74. GUI:setVisible(self.itemList[i], true)
  75. else
  76. GUI:setVisible(self.itemList[i], false)
  77. end
  78. end
  79. else
  80. for i = #self.itemList + 1, #itemRewards do
  81. local itemId = itemRewards[i][1]
  82. local item = GUI:Item_Create(self.view.itemRoot, {
  83. width = "70",
  84. height = "70",
  85. itemid = itemId,
  86. mfixsize = "80,80",
  87. tips = "1",
  88. itemcustomcount = itemRewards[i][2]
  89. })
  90. GUI:AddOnClickEvent(item, self, function()
  91. SL:OpenTips(nil, itemId)
  92. end)
  93. table.insert(self.itemList, item)
  94. end
  95. for i = 1, #self.itemList do
  96. if i <= #itemRewards then
  97. GUI:setVisible(self.itemList[i], true)
  98. else
  99. GUI:setVisible(self.itemList[i], false)
  100. end
  101. end
  102. end
  103. end
  104. function this:RefreshTimeText()
  105. self.activityInfo = InfoManager.activityPreviewInfo:GetActivityInfo(InfoManager.redFortInfo.activityCfg.id)
  106. if self.activityInfo then
  107. if self.activityInfo.open then
  108. GUI:Text_setTextColor(self.view.textOpenTime,EColor[EGradColor.green])
  109. GUI:Text_setTextColor(self.view.textActivityTime,EColor[EGradColor.green])
  110. else
  111. GUI:Text_setTextColor(self.view.textOpenTime,EColor[EGradColor.red])
  112. GUI:Text_setTextColor(self.view.textActivityTime,EColor[EGradColor.red])
  113. end
  114. end
  115. end
  116. function this:Close()
  117. SL:ShowMainPanel()
  118. if self.timer then
  119. ---Timer.Stop(self.timer)
  120. SL:UnSchedule(self.timer)
  121. self.timer = nil
  122. end
  123. end
  124. return this