KLTaskFinishPanel.lua 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. ---@class KLTaskFinishPanel:UIKmlLuaPanelBase
  2. ---@field view KLTaskFinishPanelView
  3. local KLTaskFinishPanel = class(UIKmlLuaPanelBase)
  4. local this =KLTaskFinishPanel
  5. ---创建时调用一次
  6. function this:Init()
  7. self.finishTaskId = self.args.taskId
  8. self.retMap = {}
  9. self.retList = {}
  10. self:GetRewardMap()
  11. GUI:DataListInitData( self.view.award_list,function()
  12. return table.count(self.retList)
  13. end,function(realIndex)
  14. end,function(realIndex, kmlcontrol)
  15. return self:DataListItemInitFunc(realIndex, kmlcontrol)
  16. end, function(realIndex, kmlcontrol)
  17. end)
  18. end
  19. function this:DataListItemInitFunc(realIndex, kmlcontrol)
  20. local item = GUI:GetChildControl(self.view.award_list,realIndex,'award_item')
  21. local cfgId = self.retList[realIndex+1]
  22. local itemCount = self.retMap[cfgId].count
  23. GUI:Item_UpdataData(item, {
  24. itemid = cfgId,
  25. itemcount = tostring(itemCount)
  26. })
  27. GUI:AddOnClickEvent(item, self, function()
  28. SL:OpenTips(nil,cfgId)
  29. end)
  30. end
  31. function this:GetRewardMap()
  32. local allTasks = SL:TaskInfo_GetAllTasks()
  33. local boxItem = allTasks[self.finishTaskId].boxReward
  34. for _, boxInfo in pairs(boxItem) do
  35. self.retMap[boxInfo.cfgId] = boxInfo
  36. table.insert(self.retList, boxInfo.cfgId)
  37. end
  38. local rewardList = SL:GetConfig('cfg_task', self.finishTaskId).rewardItem
  39. for _, boxInfo in pairs(rewardList) do
  40. local cfgId = boxInfo[1]
  41. local count = boxInfo[2]
  42. if self.retMap[cfgId] then
  43. self.retMap[cfgId]["count"] = self.retMap[cfgId]["count"] + count
  44. else
  45. self.retMap[cfgId] = {
  46. cfgId = cfgId,
  47. count = SL:GetSimpleNumber(count, 0)
  48. }
  49. table.insert(self.retList, cfgId)
  50. end
  51. end
  52. end
  53. ---创建或者刷新界面数据时调用
  54. function this:Refresh()
  55. local task_title = SL:GetConfig('cfg_task', self.finishTaskId).title
  56. GUI:Text_setString(self.view.LabelTask, task_title)
  57. local diaLogDone = SL:GetConfig('cfg_task', self.finishTaskId).diaLogDone
  58. GUI:Text_setString(self.view.LabelDesc, diaLogDone)
  59. GUI:DataListUpdateData(self.view.award_list)
  60. end
  61. ---注册UI事件和服务器消息
  62. function this:RegistEvents()
  63. GUI:AddOnClickEvent(self.view.BtnClose,self,self.BtnClose)
  64. GUI:AddOnClickEvent(self.view.BtnGet,self,self.BtnGet)
  65. end
  66. function this:Close()
  67. SL.ShowMainPanel()
  68. end
  69. function this:BtnClose()
  70. GUI:UIPanel_Close("dev/ui/Task/Panel/KLTaskFinish/KLTaskFinishPanel")
  71. end
  72. function this:BtnGet()
  73. SL:ReqSubmitTaskMessage(self.finishTaskId, 1)
  74. GUI:UIPanel_Close("dev/ui/Task/Panel/KLTaskFinish/KLTaskFinishPanel")
  75. end
  76. return this