UIDiffTaskView.lua 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. local UIDiffTaskView = require("UITask/UIDiffTaskView_Generate")
  2. function UIDiffTaskView:OnAwake(data)
  3. self.controller = require("UITask/UIDiffTaskCtr"):new()
  4. self.controller:Init(self)
  5. self.controller:SetData(data)
  6. self.CurGroup = nil
  7. end
  8. function UIDiffTaskView:AddEventListener()
  9. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  10. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.UI_TASK_CHANGE, self, self.RefreshTask)
  11. self.uiBase:AddButtonEventListener(self.BtnClose.button,self,self.OnCloseClick)
  12. self.uiBase:AddButtonEventListener(self.getBtn.button,self,self.OnClickGetGroupReward)
  13. self.uiBase:AddButtonEventListener(self.btnGoto.button,self,self.OnClickJump)
  14. end
  15. function UIDiffTaskView:FillContent(data, uiBase)
  16. self.uiBase = uiBase
  17. local gameObject = self.uiBase:GetRoot()
  18. if gameObject ~= nil then
  19. self.gameObject = gameObject
  20. self.transform = gameObject.transform
  21. end
  22. self:InitGenerate(self.transform, data)
  23. self:Init()
  24. end
  25. function UIDiffTaskView:Init()
  26. self:SetItems()
  27. --self:SetGroupReward({{100,100},{110,50},{47,1000000},{529,5}})
  28. end
  29. function UIDiffTaskView:RemoveEventListener()
  30. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  31. end
  32. function UIDiffTaskView:AddUIEventListener()
  33. end
  34. function UIDiffTaskView:OnHide()
  35. end
  36. function UIDiffTaskView:OnShow(data)
  37. self.controller:SetData(data)
  38. end
  39. function UIDiffTaskView:OnClose()
  40. end
  41. function UIDiffTaskView:OnDispose()
  42. self.controller:OnDispose()
  43. self.scrollView.loopHorizontalScrollRect:ClearCells()
  44. self.scrollView.loopHorizontalScrollRect:ClearAnchoredPostion()
  45. self.goodsItems.loopHorizontalScrollRect:ClearCells()
  46. self.goodsItems.loopHorizontalScrollRect:ClearAnchoredPostion()
  47. end
  48. function UIDiffTaskView:OnCloseClick()
  49. self:UIClose()
  50. end
  51. function UIDiffTaskView:SetItems()
  52. local curgroup = self.controller:GetShowTaskData()
  53. LogError("--------curgroup---"..Inspect(curgroup))
  54. self.CurGroup = curgroup
  55. local datalist = {}--{1,2,3,}
  56. if curgroup ~= nil and curgroup.groupTask ~= nil then
  57. --LogError("--------curgroup 有值---")
  58. self:SetGroupReward(curgroup.rewardCfg.GroupReward)
  59. local got = curgroup.groupTask._got
  60. self.btnGoto:SetActive(got == 0)
  61. self.getBtn:SetActive(got == 1)
  62. self.sealBtn:SetActive(got == 2)
  63. --self.getBtn.button.interactable = curgroup.groupTask._got == 1
  64. else
  65. self.getBtn:SetActive(false)
  66. self.sealBtn:SetActive(false)
  67. self.btnGoto:SetActive(false)
  68. end
  69. if curgroup ~= nil and curgroup.taskList then
  70. datalist = self:GetTaskList(curgroup.taskList)
  71. end
  72. --datalist = self:GetTaskList(curgroup.taskList)
  73. LogError("--------datalist---"..Inspect(datalist))
  74. self.scrollView.loopHorizontalScrollRect:ClearCells()
  75. --self.scrollView.loopHorizontalScrollRect:ClearAnchoredPostion()
  76. CommonUtil.LoopGridViewEleCreateNew(self,
  77. self.scrollView.loopHorizontalScrollRect,
  78. self.content.horizontalLayoutGroup,
  79. datalist,
  80. 0,
  81. self,
  82. self.UpdateTaskItem,
  83. nil,nil,0);
  84. self.scrollView.loopHorizontalScrollRect:MoveTo(0)
  85. self:SetGroupTxt(curgroup)
  86. end
  87. function UIDiffTaskView:UpdateTaskItem(_itemLua, _idx,_data)
  88. if not _itemLua or not _data then return end
  89. --_itemLua.gameObject:SetParent(wnd.content.transform)
  90. CommonUtil.UpdateItemPrefab(self, _itemLua, _data, Enum.ItemIEnterType.Bag,self,self.OnClickGetReward)
  91. end
  92. function UIDiffTaskView:UpdateRewardItem(_itemLua, _idx,_data)
  93. if not _itemLua or not _data then return end
  94. --_itemLua.gameObject:SetParent(wnd.content.transform)
  95. CommonUtil.UpdateItemPrefab(self, _itemLua, _data, Enum.ItemIEnterType.Bag)
  96. end
  97. function UIDiffTaskView:SetGroupReward(rewards)
  98. local rewardlist = ManagerContainer.DataMgr.HardMissionDataMgr:GetReward(rewards)
  99. self.goodsItems.loopHorizontalScrollRect:ClearCells()
  100. --self.goodsItems.loopHorizontalScrollRect:ClearAnchoredPostion()
  101. CommonUtil.LoopGridViewEleCreateNew(self,
  102. self.goodsItems.loopHorizontalScrollRect,
  103. self.goodsItemsContent.horizontalLayoutGroup,
  104. rewardlist,
  105. 0,
  106. self,
  107. self.UpdateRewardItem,
  108. nil,nil,0);
  109. --self.goodsItems.loopHorizontalScrollRect:SetItemStartIdx(0)
  110. end
  111. function UIDiffTaskView:RefreshTask()
  112. self:SetItems()
  113. end
  114. function UIDiffTaskView:OnClickGetReward(btn,data)
  115. --LogError("-----btn-----------"..Inspect(btn))
  116. --LogError("-----data-----------"..Inspect(data))
  117. ManagerContainer.DataMgr.TaskDataNew:CSGetTaskScoreRewardReq(data[0]._taskType,data[0]._id)
  118. end
  119. function UIDiffTaskView:OnClickGetGroupReward()
  120. ManagerContainer.DataMgr.TaskDataNew:CSGetTaskScoreRewardReq(self.CurGroup.groupTask._taskType,self.CurGroup.groupTask._id)
  121. end
  122. function UIDiffTaskView:OnClickJump()
  123. self:OnCloseClick()
  124. if(ManagerContainer.LuaBattleMgr:GetBattleMode() ~= 1) then
  125. ManagerContainer.LuaBattleMgr:SendChangeMapLevelTypeReq(1)
  126. end
  127. end
  128. function UIDiffTaskView:SetGroupTxt(grouptask)
  129. local txt = ""
  130. if grouptask ~= nil then
  131. txt = I18N.SetLanguageValue("DiffGroupTaskConditionTxt",grouptask.value,grouptask.total)
  132. end
  133. self.taskTxt.text.text = txt
  134. end
  135. function UIDiffTaskView:GetTaskList(data)
  136. --LogError("----GetTaskList-data-----------"..Inspect(data))
  137. local tasklist = {}
  138. for _, v in pairs(data) do
  139. tasklist[#tasklist +1] = v
  140. end
  141. table.sort(tasklist,function (a,b)
  142. return a._id < b._id
  143. end)
  144. return tasklist
  145. end
  146. return UIDiffTaskView