KLUnionElectionAndReplacePanel.lua 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. ---@class KLUnionElectionAndReplacePanel:UIKmlLuaPanelBase
  2. ---@field view KLUnionElectionAndReplacePanelView
  3. local KLUnionElectionAndReplacePanel = class(UIKmlLuaPanelBase)
  4. local this = KLUnionElectionAndReplacePanel
  5. ---创建时调用一次
  6. function this:Init()
  7. self.type = self.args.type
  8. GUI:Image_loadTexture(self.view.TitleImage, self.type == EUnionLeaderOperateType.Election and "title_election" or "title_replace",
  9. "Atlas/TS_UnionElection.spriteatlas")
  10. self.level = nil
  11. self.unionData = nil
  12. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_GET_UNION_INFO)
  13. if self.type == EUnionLeaderOperateType.Election then
  14. GUI:setVisible(self.view.levelList, true)
  15. GUI:setVisible(self.view.ticketList, true)
  16. GUI:setVisible(self.view.replaceLevel, false)
  17. elseif self.type == EUnionLeaderOperateType.Replace then
  18. GUI:setVisible(self.view.levelList, false)
  19. GUI:setVisible(self.view.ticketList, false)
  20. GUI:setVisible(self.view.replaceLevel, true)
  21. end
  22. --[[ GUI:DataListInitData(self.view.datalist,
  23. function()
  24. local data = InfoManager.unionElectionInfo:GetElectionDataList()
  25. return table.count(data)
  26. end,
  27. function(realIndex)
  28. return self:ItemGetFunc(realIndex)
  29. end,
  30. function(realIndex, kmlCtrl)
  31. return self:ItemInitFunc(realIndex, kmlCtrl)
  32. end,
  33. function(realIndex, kmlCtrl)
  34. return self:ItemUpdateFunc(realIndex, kmlCtrl)
  35. end)]]
  36. end
  37. ---创建或者刷新界面数据时调用
  38. function this:Refresh()
  39. end
  40. ---注册UI事件和服务器消息
  41. function this:RegistEvents()
  42. GUI:AddOnClickEvent(self.view.btnJoin, self, self.JoinOnCLick)
  43. GUI:AddOnClickEvent(self.view.btnAdd, self, self.AddOnCLick)
  44. GUI:AddOnClickEvent(self.view.btnClose, self, self.CloseSelf)
  45. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_GET_UNION_INFO, self.RES_GET_UNION_INFO, self)
  46. SL:RegisterLUAEvent(LUA_EVENT_ELECTION_DATA_CHANGE, self.On_DataChange, self)
  47. end
  48. function this:On_DataChange(_, isReplace)
  49. if isReplace and self.type == EUnionLeaderOperateType.Replace then
  50. self:ItemUpdateFunc()
  51. elseif not isReplace and self.type == EUnionLeaderOperateType.Election then
  52. self:ItemUpdateFunc()
  53. end
  54. end
  55. --刷新竞选数据
  56. function this:ItemUpdateFunc()
  57. if not self.unionData then
  58. return
  59. end
  60. local myId = SL:GetMetaValue("MAIN_ACTOR_ID")
  61. local hasMe = false
  62. self:UnSchedule()
  63. local endTime
  64. if self.type == EUnionLeaderOperateType.Election then
  65. --竞选
  66. local data = InfoManager.unionElectionInfo:GetElectionDataList()
  67. local filePath = "dev/outui/Union/Item/KLUnionElectionReplace/KLUnionElectionReplaceItem"
  68. GUI:UIPanel_Close(filePath)
  69. if data then
  70. for k, v in pairs(data) do
  71. if self.unionData.memberinfos[k] then
  72. GUI:UIPanel_Open(filePath, self.view.layout4, self, {
  73. id = k, data = v, memberInfo = self.unionData.memberinfos[k], level = self.level
  74. }, true)
  75. if k == myId then
  76. hasMe = true
  77. end
  78. end
  79. end
  80. end
  81. --竞选倒计时
  82. endTime = InfoManager.unionElectionInfo:GetElectionEndTime()
  83. --[[ if endTime then
  84. --local delta = endTime - SL:server
  85. local nowTime = SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME)
  86. local deltaTime = endTime - nowTime
  87. if deltaTime > 0 then
  88. self.schedule = SL:Schedule(0, 1, deltaTime // 1000 + 1, function()
  89. local nowTime_ = SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME)
  90. local deltaTime_ = endTime - nowTime_
  91. if deltaTime_ <= 0 then
  92. deltaTime_ = 0
  93. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_UNION_RUN_FOR_LEADER_DATA)
  94. SL:onLUAEvent(LUA_EVENT_CHANGE_UNION_FUNCTION, "infoToggle")
  95. GUI:UIPanel_Close(self.filePath)
  96. return
  97. end
  98. GUI:Text_setString(self.view.txtCountDown, "竞选结束倒计时"..self:FormatTimeStr(deltaTime_))
  99. end)
  100. end
  101. end]]
  102. elseif self.type == EUnionLeaderOperateType.Replace then
  103. local data = InfoManager.unionElectionInfo:GetReplaceDataList()
  104. local filePath = "dev/outui/Union/Item/KLUnionReplace/KLUnionReplaceItem"
  105. GUI:UIPanel_Close(filePath)
  106. if data then
  107. for k, v in pairs(data) do
  108. GUI:UIPanel_Open(filePath, self.view.layout4, self, {
  109. memberInfo = self.unionData.memberinfos[k]
  110. }, true)
  111. if k == myId then
  112. hasMe = true
  113. end
  114. end
  115. end
  116. endTime = InfoManager.unionElectionInfo:GetReplaceEndTime()
  117. end
  118. if endTime then
  119. endTime = tonumber(endTime)
  120. --local delta = endTime - SL:server
  121. local nowTime = SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME)
  122. local deltaTime = endTime - tonumber(nowTime)
  123. local preStr = self.type == EUnionLeaderOperateType.Election and "竞选结束倒计时" or "取代结束倒计时"
  124. if deltaTime > 0 then
  125. local takeABreak = false
  126. self.schedule = SL:Schedule(self.schedule, 0, 1, deltaTime // 1000 + 2, function()
  127. local nowTime_ = SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME)
  128. local deltaTime_ = endTime - tonumber(nowTime_)
  129. if deltaTime_ <= 0 then
  130. deltaTime_ = 0
  131. if takeABreak == false then
  132. takeABreak = true
  133. else
  134. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_UNION_RUN_FOR_LEADER_DATA)
  135. SL:onLUAEvent(LUA_EVENT_CHANGE_UNION_FUNCTION, "infoToggle")
  136. GUI:UIPanel_Close(self.filePath)
  137. return
  138. end
  139. end
  140. GUI:Text_setString(self.view.txtCountDown, preStr .. InfoManager.unionElectionInfo.FormatTimeStr(deltaTime_))
  141. end)
  142. else
  143. deltaTime = 0
  144. GUI:Text_setString(self.view.txtCountDown, preStr .. InfoManager.unionElectionInfo.FormatTimeStr(deltaTime))
  145. end
  146. end
  147. GUI:Text_setString(self.view.btnJoin, hasMe and "已参与" or "参与")
  148. GUI:Image_loadTexture(self.view.btnJoin, hasMe and "button_interface_window37_gery" or "button_interface_window37",
  149. hasMe and "Atlas/TS_Common.spriteatlas" or "Atlas/Common.spriteatlas")
  150. GUI:setTouchEnabled(self.view.btnJoin, not hasMe)
  151. end
  152. function this:RES_GET_UNION_INFO(id, message)
  153. self.unionData = message
  154. self.level = tonumber(message.unionlevel)
  155. local costTbl = self:GetCostTbl()
  156. if costTbl then
  157. GUI:setVisible(self.view.CostBg, true)
  158. local own = SL:GetBagItemCount(costTbl[1])
  159. GUI:Text_setString(self.view.txtCost, string.format("<color=%s>%s</color>",
  160. own >= costTbl[2] and "#1BE419" or "#9b1818", costTbl[2]))
  161. GUI:Item_UpdataData(self.view.item, {
  162. ["itemid"] = costTbl[1],
  163. })
  164. else
  165. GUI:setVisible(self.view.CostBg, false)
  166. end
  167. self:ItemUpdateFunc()
  168. end
  169. function this:GetCostTbl()
  170. ---@type cfg_unionLevel_column
  171. local cfg = SL:GetConfig("cfg_unionLevel", self.level, "unionLevel")
  172. local costTbl
  173. local condTbl
  174. if cfg then
  175. if self.type == EUnionLeaderOperateType.Election then
  176. costTbl = cfg.cast
  177. condTbl = cfg.electionConditions
  178. elseif self.type == EUnionLeaderOperateType.Campaign then
  179. costTbl = cfg.campaignCast
  180. condTbl = cfg.campaignCondition
  181. elseif self.type == EUnionLeaderOperateType.Replace then
  182. costTbl = cfg.replaceCast
  183. condTbl = cfg.replaceConditions
  184. end
  185. end
  186. return costTbl, condTbl
  187. end
  188. function this:CloseSelf()
  189. GUI:UIPanel_Close("dev/ui/Union/Panel/KLUnionToggleList/KLUnionToggleListPanel")
  190. GUI:UIPanel_Close(self.filePath)
  191. SL.ShowMainPanel()
  192. end
  193. function this:JoinOnCLick()
  194. if not self.level then return end
  195. GUI:UIPanel_Open("dev/outui/Union/Panel/KLUnionLeaderOperate/KLUnionLeaderOperatePanel",
  196. _, _, { type = self.type, unionLevel = self.level })
  197. end
  198. function this:AddOnCLick()
  199. local costTbl = self:GetCostTbl()
  200. if costTbl then
  201. SL:CommonItemGetPath(nil, costTbl[1])
  202. end
  203. end
  204. function this:Close()
  205. self:UnSchedule()
  206. GUI:UIPanel_Close("dev/outui/Union/Panel/KLUnionElectionVote/KLUnionElectionVotePanel")
  207. if self.type == EUnionLeaderOperateType.Election then
  208. local filePath = "dev/outui/Union/Item/KLUnionElectionReplace/KLUnionElectionReplaceItem"
  209. GUI:UIPanel_Close(filePath)
  210. elseif self.type == EUnionLeaderOperateType.Replace then
  211. local filePath = "dev/outui/Union/Item/KLUnionReplace/KLUnionReplaceItem"
  212. GUI:UIPanel_Close(filePath)
  213. end
  214. end
  215. function this:UnSchedule()
  216. if self.schedule then
  217. SL:UnSchedule(self.schedule)
  218. end
  219. self.schedule = nil
  220. end
  221. return this