KLActivityPreviewItem.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. ---@class KLActivityPreviewItem:UIKmlLuaPanelBase
  2. ---@field view KLActivityPreviewItemView
  3. ---@field data {leftTime:number,id:number,open:boolean,cfg:cfg_activity_rule_column,isPreview:boolean}
  4. local KLActivityPreviewItem = class(UIKmlLuaPanelBase)
  5. local this = KLActivityPreviewItem
  6. ---创建时调用一次
  7. function this:Init()
  8. end
  9. function this:InitData(index, data)
  10. self.index = index
  11. self.data = data
  12. end
  13. ---创建或者刷新界面数据时调用
  14. function this:Refresh()
  15. end
  16. function this:RefreshItem()
  17. if self.data and self.data.cfg then
  18. GUI:Text_setString(self.view.activityName, self.data.cfg.name)
  19. GUI:Image_loadTexture(self.view.activityIcon, self.data.cfg.Icon, "Atlas/UIActivityPreview.spriteatlas")
  20. if self.data.open then
  21. GUI:Image_loadTexture(self.view.activityIsOpenImg, "act_open", "Atlas/UIActivityPreview.spriteatlas")
  22. else
  23. GUI:Image_loadTexture(self.view.activityIsOpenImg, "act_wait", "Atlas/UIActivityPreview.spriteatlas")
  24. end
  25. self:RefreshTimeText()
  26. if not self.timer then
  27. --self.timer = Timer.StartLoopForever(1, self.RefreshTimeText, self)
  28. self.timer = SL:Schedule(self.timer,0,1,-1,self.RefreshTimeText,self)
  29. end
  30. end
  31. end
  32. function this:RefreshTimeText()
  33. if not self.data then
  34. return
  35. end
  36. if self.data.open then
  37. local text = "剩余时间:"
  38. GUI:Text_setString(self.view.text, text)
  39. GUI:Text_setTextColor(self.view.textTime, EColor[EGradColor.green])
  40. else
  41. local text = "开启时间:"
  42. GUI:Text_setString(self.view.text, text)
  43. GUI:Text_setTextColor(self.view.textTime, EColor[EGradColor.red])
  44. end
  45. local showTime = self.data.leftTime - Time.GetServerTime()
  46. if showTime < 0 then
  47. if not self.isShowTimeOver then
  48. self.isShowTimeOver = true
  49. if self.timer then
  50. --Timer.Stop(self.timer)
  51. SL:UnSchedule(self.timer)
  52. self.timer = nil
  53. end
  54. SL:onLUAEvent(LUA_EVENT_ACTIVITYPREVIEW_CHANGE)
  55. self.isShowTimeOver = false
  56. end
  57. return
  58. end
  59. GUI:Text_setString(self.view.textTime, Time.FormatTimeHMS(math.ceil(showTime)))
  60. end
  61. function this:SetActiveUI(val)
  62. GUI:SetActive(self.view.root, val)
  63. end
  64. ----@return boolean
  65. function this:GetActiveUI(val)
  66. return GUI:getVisible(self.view.root)
  67. end
  68. ---注册UI事件和服务器消息
  69. function this:RegistEvents()
  70. GUI:AddOnClickEvent(self.view.btnGoNpc, self, self.OnClickGoNpc)
  71. end
  72. function this:OnClickGoNpc()
  73. if self.data and self.data.cfg then
  74. --狼魂要塞
  75. if self.data.cfg.id == EActivityType.WolfSoulFortress then
  76. if SL:MeData_GetUnionId() == 0 then
  77. SL:TipMessage( SL:GetConfig('cfg_string', 433).text, 1, NoticeType.NoticeMid )
  78. return
  79. end
  80. ---@type cfg_rep_column
  81. local tempTbl = InfoManager.wolfSoulFortressInfo:GetCfgByOpenServerDay()
  82. if tempTbl then
  83. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_ENTER_DUPLICATE, tempTbl.id)
  84. end
  85. else
  86. local cond, message = InfoManager.godsDescendInfo.CheckActivityCondition(self.data.cfg.id)
  87. if cond then
  88. ---@type cfg_activity_rule_column
  89. local tbl = SL:GetConfig("cfg_activity_rule", self.data.cfg.id)
  90. if tbl.mapid and table.count(tbl.mapid) >0 then
  91. if tbl.mapid[1] == 21000 then
  92. local cond, message = InfoManager.godsDescendInfo.CheckActivityConditionMapId(self.data.cfg.id)
  93. if cond then
  94. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_GOTO_CROSS_MAP,{})
  95. else
  96. SL:TipMessage(message, 1, NoticeType.NoticeMid)
  97. end
  98. return
  99. end
  100. end
  101. SL:ShortcutDO(tbl.panel)
  102. else
  103. SL:TipMessage( message, 1, NoticeType.NoticeMid )
  104. end
  105. --SL:ShortcutDO(self.data.cfg.panel)
  106. end
  107. end
  108. end
  109. function this:Close()
  110. if self.timer then
  111. --Timer.Stop(self.timer)
  112. SL:UnSchedule(self.timer)
  113. self.timer = nil
  114. end
  115. end
  116. return this