KLKingOfRoadPanel.lua 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. ---@class KLKingOfRoadPanel:UIKmlLuaPanelBase
  2. ---@field view KLKingOfRoadPanelView
  3. local KLKingOfRoadPanel = class(UIKmlLuaPanelBase)
  4. local this =KLKingOfRoadPanel
  5. ---创建时调用一次
  6. function this:Init()
  7. self:InitData()
  8. GUI:DataListInitData(self.view.taskDataList, function()
  9. return table.count(self.chapterTaskInfo[tostring(self.clickIndex)].task_info_list)
  10. end,function()
  11. end,function()
  12. end,function(realIndex)
  13. local taskInfo = self.chapterTaskInfo[tostring(self.clickIndex)].task_info_list[realIndex+1]
  14. local info = SL:GetConfig('cfg_king_road_task', taskInfo.task_id)
  15. local name = info['text']
  16. local rewardItem = info['rewardItem']
  17. local taskTargetId = info['taskTargetId']
  18. local TaskName = GUI:GetChildControl(self.view.taskDataList,realIndex,'TaskName')
  19. local item6 = GUI:GetChildControl(self.view.taskDataList,realIndex,'item6')
  20. local TaskCount = GUI:GetChildControl(self.view.taskDataList,realIndex,'TaskCount')
  21. local BtnGet = GUI:GetChildControl(self.view.taskDataList,realIndex,'BtnGet')
  22. local highLight = GUI:GetChildControl(self.view.taskDataList,realIndex,'highLight')
  23. local Img_Received = GUI:GetChildControl(self.view.taskDataList,realIndex,'Img_Received')
  24. GUI:Text_setString(TaskName, name)
  25. GUI:Item_UpdataData(item6, {
  26. ["itemid"] = rewardItem[1],
  27. ["itemcount"] = rewardItem[2],
  28. })
  29. GUI:AddOnClickEvent(item6, self, function()
  30. SL:OpenTips(nil, rewardItem[1])
  31. end)
  32. if taskInfo == nil then
  33. return
  34. end
  35. if taskInfo.goal_count < taskInfo.max_count then
  36. GUI:Text_setString(TaskCount, string.format('<color="#9b1818">%d</color>/%d', taskInfo.goal_count, taskInfo.max_count))
  37. else
  38. GUI:Text_setString(TaskCount, string.format('<color="#2a8430">%d</color>/%d', taskInfo.goal_count, taskInfo.max_count))
  39. end
  40. if taskInfo.state == 1 then
  41. GUI:setVisible(BtnGet, true)
  42. GUI:setVisible(Img_Received, false)
  43. GUI:Text_setString(BtnGet, "前往")
  44. GUI:setVisible(highLight, false)
  45. local inst = SL:GetConfig('cfg_task_target', taskTargetId).instruction
  46. GUI:AddOnClickEvent(BtnGet, self, function()
  47. self:ClosePanel()
  48. SL:ShortcutDO(inst[1])
  49. end )
  50. elseif taskInfo.state == 2 then
  51. GUI:setVisible(BtnGet, true)
  52. GUI:setVisible(Img_Received, false)
  53. GUI:Text_setString(BtnGet, "领取")
  54. GUI:setVisible(highLight, true)
  55. GUI:AddOnClickEvent(BtnGet, self, function()
  56. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_SUBMIT_KING_ROAD_TASK,info.id)
  57. end )
  58. else
  59. GUI:setVisible(BtnGet, false)
  60. GUI:setVisible(Img_Received, true)
  61. end
  62. end)
  63. GUI:DataListInitData(self.view.groupDataList, function()
  64. local tbl = SL:GetConfigTable('cfg_king_road')
  65. return table.count(tbl)
  66. end,function()
  67. end,function()
  68. end,function(realIndex)
  69. local tbl = SL:GetConfig('cfg_king_road', realIndex+1 )
  70. local icon = tbl.icon
  71. local rewardItem = tbl['rewardItem']
  72. local chapteraName = GUI:GetChildControl(self.view.groupDataList,realIndex,'chapteraName')
  73. local AwardObj = GUI:GetChildControl(self.view.groupDataList,realIndex,'AwardObj')
  74. local Lock = GUI:GetChildControl(self.view.groupDataList,realIndex,'Lock')
  75. local selectBg = GUI:GetChildControl(self.view.groupDataList,realIndex,'selectBg')
  76. local selectToggle = GUI:GetChildControl(self.view.groupDataList,realIndex,'selectToggle')
  77. GUI:Image_loadTexture(chapteraName, icon,"Atlas/KLKingOfRoad.spriteatlas")
  78. GUI:Item_setItemId(AwardObj, rewardItem[1])
  79. if self:GetIsLock(realIndex+1) then
  80. GUI:setVisible(Lock, true)
  81. else
  82. GUI:setVisible(Lock, false)
  83. end
  84. if realIndex + 1 == self.clickIndex then
  85. GUI:setVisible(selectBg, true)
  86. else
  87. GUI:setVisible(selectBg, false)
  88. end
  89. GUI:AddOnClickEvent(selectToggle, self, self.selectToggle, {clickIndex=realIndex+1})
  90. end)
  91. end
  92. function this:selectToggle(control, eventData)
  93. local clickIndex = eventData.clickIndex
  94. if self:GetIsLock(clickIndex) then
  95. return
  96. end
  97. self.clickIndex = clickIndex
  98. GUI:DataListUpdateData(self.view.taskDataList)
  99. GUI:DataListUpdateData(self.view.groupDataList)
  100. self:SetRewardData()
  101. end
  102. function this:InitData()
  103. self.curChapterToTask = {}
  104. local tbl = SL:GetConfigTable('cfg_king_road_task')
  105. for _, info in pairs(tbl) do
  106. local chapter = info.group
  107. if self.curChapterToTask[chapter] == nil then
  108. self.curChapterToTask[chapter] = {}
  109. end
  110. table.insert(self.curChapterToTask[chapter], info)
  111. end
  112. end
  113. ---注册UI事件和服务器消息
  114. function this:RegistEvents()
  115. GUI:AddOnClickEvent(self.view.Btn_Close, self, self.ClosePanel)
  116. GUI:AddOnClickEvent(self.view.BtnGet1, self, self.BtnGet1)
  117. GUI:AddOnClickEvent(self.view.ObjPos, self, self.ObjPosOnclick)
  118. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_KING_ROAD_TASK_INFO, self.ResKingRoadTaskInfo, self)
  119. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_KING_ROAD_TASK_CHANGE, self.RES_KING_ROAD_TASK_CHANGE, self)
  120. end
  121. function this:BtnGet1()
  122. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_RECEIVE_KING_ROAD_CHAPTER_AWARD,self.clickIndex)
  123. end
  124. function this:ObjPosOnclick()
  125. if not self.item_cfgid then
  126. return
  127. end
  128. SL:OpenTips(nil, self.item_cfgid)
  129. end
  130. function this:RES_KING_ROAD_TASK_CHANGE(_, message)
  131. local curChapter = message.now_chapter
  132. local state = message.chapter_state
  133. local changeTask = message.change_task
  134. self.curChapter = curChapter
  135. self.chapterTaskInfo[tostring(self.curChapter)].state = state
  136. for taskId, taskInfo in pairs(changeTask) do
  137. if self.chapterTaskInfo[tostring(self.curChapter)].task_info[taskId] ~= nil then
  138. self.chapterTaskInfo[tostring(self.curChapter)].task_info[taskId] = taskInfo
  139. end
  140. for index, listInfo in pairs(self.chapterTaskInfo[tostring(self.curChapter)].task_info_list) do
  141. if listInfo.task_id == tonumber(taskId) then
  142. self.chapterTaskInfo[tostring(self.curChapter)].task_info_list[index] = taskInfo
  143. end
  144. end
  145. end
  146. table.sort(self.chapterTaskInfo[tostring(self.curChapter)].task_info_list, function(a, b)
  147. -- 如果 a 和 b 的 state 都不等于 2,则直接比较它们的 state
  148. if a.state ~= 2 and b.state ~= 2 then
  149. return a.state < b.state
  150. -- 如果 a 的 state 是 2,则 a 应该排在 b 前面
  151. elseif a.state == 2 then
  152. if b.state == 2 then
  153. return false
  154. end
  155. return true
  156. -- 如果 b 的 state 是 2,则 a 不应该排在 b 前面(即 b 应该排在 a 前面)
  157. else
  158. return false
  159. end
  160. end)
  161. GUI:DataListUpdateData(self.view.taskDataList)
  162. GUI:DataListUpdateData(self.view.groupDataList)
  163. self:SetRewardData()
  164. end
  165. ---创建或者刷新界面数据时调用
  166. function this:Refresh()
  167. self.clickIndex = 1
  168. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_KING_ROAD_TASK_INFO)
  169. end
  170. function this:Close()
  171. SL.ShowMainPanel()
  172. end
  173. function this:ClosePanel()
  174. GUI:UIPanel_Close("dev/outui/Task/Panel/KLKingOfRoad/KLKingOfRoadPanel")
  175. end
  176. function this:ResKingRoadTaskInfo(eventId, eventData)
  177. if eventData.now_chapter == -1 then
  178. self.curChapter = self.clickIndex
  179. else
  180. self.curChapter = eventData.now_chapter
  181. end
  182. self.chapterTaskInfo = eventData.chapter_task_info
  183. self.clickIndex = self.curChapter
  184. for index, chapterInfo in pairs(self.chapterTaskInfo) do
  185. chapterInfo.task_info_list = {}
  186. for taskId, taskInfo in pairs(chapterInfo.task_info) do
  187. table.insert(chapterInfo.task_info_list, taskInfo)
  188. end
  189. table.sort(chapterInfo.task_info_list, function(a, b)
  190. -- 如果 a 和 b 的 state 都不等于 2,则直接比较它们的 state
  191. if a.state ~= 2 and b.state ~= 2 then
  192. return a.state < b.state
  193. -- 如果 a 的 state 是 2,则 a 应该排在 b 前面
  194. elseif a.state == 2 then
  195. if b.state == 2 then
  196. return false
  197. end
  198. return true
  199. -- 如果 b 的 state 是 2,则 a 不应该排在 b 前面(即 b 应该排在 a 前面)
  200. else
  201. return false
  202. end
  203. end)
  204. end
  205. GUI:DataListUpdateData(self.view.taskDataList)
  206. GUI:DataListUpdateData(self.view.groupDataList)
  207. self:SetRewardData()
  208. end
  209. --function this:GetSelectTaskInfo(targetTaskId)
  210. -- if self.chapterTaskInfo[tostring(self.clickIndex)] == nil then
  211. -- return
  212. -- end
  213. --
  214. -- for _, taskInfo in pairs(self.chapterTaskInfo[tostring(self.clickIndex)].task_info) do
  215. -- if taskInfo.target_id == targetTaskId then
  216. -- return taskInfo
  217. -- end
  218. --
  219. -- end
  220. --end
  221. function this:GetIsLock(selectIndex)
  222. if self.curChapter < selectIndex then
  223. return true
  224. end
  225. return false
  226. end
  227. function this:SetRewardData()
  228. local tbl = SL:GetConfig('cfg_king_road', self.clickIndex)
  229. local rewardItem = tbl['rewardItem']
  230. self.item_cfgid = rewardItem[1]
  231. GUI:Item_setItemId(self.view.ObjPos, rewardItem[1])
  232. GUI:Item_Scale(self.view.ObjPos, 150)
  233. local info = self.chapterTaskInfo[tostring(self.clickIndex)]
  234. if info == nil then
  235. GUI:setVisible(self.view.BtnGet1, false)
  236. GUI:setVisible(self.view.Img_Received_1, false)
  237. return
  238. end
  239. if info.state == 1 then
  240. GUI:setVisible(self.view.BtnGet1, false)
  241. GUI:setVisible(self.view.Img_Received_1, false)
  242. elseif info.state == 2 then
  243. GUI:setVisible(self.view.BtnGet1, true)
  244. GUI:setVisible(self.view.Img_Received_1, false)
  245. else
  246. GUI:setVisible(self.view.BtnGet1, false)
  247. GUI:setVisible(self.view.Img_Received_1, true)
  248. end
  249. end
  250. return this