UIDiffTaskView.lua 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. self.uiBase:AddButtonEventListener(self.btnArrowL.button,self,self.OnClickLeft)
  15. self.uiBase:AddButtonEventListener(self.btnArrowR.button,self,self.OnClickRight)
  16. end
  17. function UIDiffTaskView:FillContent(data, uiBase)
  18. self.uiBase = uiBase
  19. local gameObject = self.uiBase:GetRoot()
  20. if gameObject ~= nil then
  21. self.gameObject = gameObject
  22. self.transform = gameObject.transform
  23. end
  24. self:InitGenerate(self.transform, data)
  25. self:Init()
  26. end
  27. function UIDiffTaskView:Init()
  28. self.lBtntxt.text.text = I18N.T("TaskUI_1")
  29. self.rBtntxt.text.text = I18N.T("TaskUI_2")
  30. self:ShowChangeModeBtn()
  31. self:SetItems()
  32. --self:SetGroupReward({{100,100},{110,50},{47,1000000},{529,5}})
  33. end
  34. function UIDiffTaskView:RemoveEventListener()
  35. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  36. end
  37. function UIDiffTaskView:AddUIEventListener()
  38. end
  39. function UIDiffTaskView:OnHide()
  40. end
  41. function UIDiffTaskView:OnShow(data)
  42. self.controller:SetData(data)
  43. end
  44. function UIDiffTaskView:OnClose()
  45. end
  46. function UIDiffTaskView:OnDispose()
  47. self.controller:OnDispose()
  48. self.scrollView.loopHorizontalScrollRect:ClearCells()
  49. self.scrollView.loopHorizontalScrollRect:ClearAnchoredPostion()
  50. self.goodsItems.loopHorizontalScrollRect:ClearCells()
  51. self.goodsItems.loopHorizontalScrollRect:ClearAnchoredPostion()
  52. end
  53. function UIDiffTaskView:OnCloseClick()
  54. self:UIClose()
  55. end
  56. function UIDiffTaskView:SetItems()
  57. local curgroup = self.controller:GetShowTaskData()
  58. self.title.text.text = self:GetTitleText()
  59. --LogError("--------curgroup---"..Inspect(curgroup))
  60. self.CurGroup = curgroup
  61. local datalist = {}--{1,2,3,}
  62. if curgroup ~= nil and curgroup.groupTask ~= nil then
  63. --LogError("--------curgroup 有值---")
  64. self:SetGroupReward(curgroup.rewardCfg.GroupReward)
  65. local got = curgroup.groupTask._got
  66. self.btnGoto:SetActive(got == 0)
  67. self.getBtn:SetActive(got == 1)
  68. self.sealBtn:SetActive(got == 2)
  69. --self.getBtn.button.interactable = curgroup.groupTask._got == 1
  70. else
  71. self.goodsItems.loopHorizontalScrollRect:ClearCells()
  72. self.getBtn:SetActive(false)
  73. self.sealBtn:SetActive(false)
  74. self.btnGoto:SetActive(false)
  75. end
  76. if curgroup ~= nil and curgroup.taskList then
  77. datalist = self:GetTaskList(curgroup.taskList)
  78. end
  79. --datalist = self:GetTaskList(curgroup.taskList)
  80. LogError("--------datalist---"..Inspect(datalist))
  81. self.scrollView.loopHorizontalScrollRect:ClearCells()
  82. --self.scrollView.loopHorizontalScrollRect:ClearAnchoredPostion()
  83. CommonUtil.LoopGridViewEleCreateNew(self,
  84. self.scrollView.loopHorizontalScrollRect,
  85. self.content.horizontalLayoutGroup,
  86. datalist,
  87. 0,
  88. self,
  89. self.UpdateTaskItem,
  90. nil,nil,0);
  91. self.scrollView.loopHorizontalScrollRect:MoveTo(0)
  92. self:SetGroupTxt(curgroup)
  93. end
  94. function UIDiffTaskView:UpdateTaskItem(_itemLua, _idx,_data)
  95. if not _itemLua or not _data then return end
  96. --_itemLua.gameObject:SetParent(wnd.content.transform)
  97. CommonUtil.UpdateItemPrefab(self, _itemLua, _data, Enum.ItemIEnterType.Bag,self,self.OnClickGetReward)
  98. end
  99. function UIDiffTaskView:UpdateRewardItem(_itemLua, _idx,_data)
  100. if not _itemLua or not _data then return end
  101. --_itemLua.gameObject:SetParent(wnd.content.transform)
  102. CommonUtil.UpdateItemPrefab(self, _itemLua, _data, Enum.ItemIEnterType.Bag)
  103. end
  104. function UIDiffTaskView:SetGroupReward(rewards)
  105. local rewardlist = ManagerContainer.DataMgr.HardMissionDataMgr:GetReward(rewards)
  106. self.goodsItems.loopHorizontalScrollRect:ClearCells()
  107. --self.goodsItems.loopHorizontalScrollRect:ClearAnchoredPostion()
  108. CommonUtil.LoopGridViewEleCreateNew(self,
  109. self.goodsItems.loopHorizontalScrollRect,
  110. self.goodsItemsContent.horizontalLayoutGroup,
  111. rewardlist,
  112. 0,
  113. self,
  114. self.UpdateRewardItem,
  115. nil,nil,0);
  116. --self.goodsItems.loopHorizontalScrollRect:SetItemStartIdx(0)
  117. end
  118. function UIDiffTaskView:RefreshTask()
  119. self:SetItems()
  120. end
  121. function UIDiffTaskView:OnClickGetReward(btn,data)
  122. --LogError("-----btn-----------"..Inspect(btn))
  123. --LogError("-----data-----------"..Inspect(data))
  124. ManagerContainer.DataMgr.TaskDataNew:CSGetTaskScoreRewardReq(data[0]._taskType,data[0]._id)
  125. end
  126. function UIDiffTaskView:OnClickGetGroupReward()
  127. ManagerContainer.DataMgr.TaskDataNew:CSGetTaskScoreRewardReq(self.CurGroup.groupTask._taskType,self.CurGroup.groupTask._id)
  128. end
  129. function UIDiffTaskView:OnClickJump()
  130. self:OnCloseClick()
  131. local curType = self.controller.TaskType
  132. if(ManagerContainer.LuaBattleMgr:GetBattleMode() ~= curType) then
  133. ManagerContainer.LuaBattleMgr:SendChangeMapLevelTypeReq(curType)
  134. end
  135. end
  136. function UIDiffTaskView:SetGroupTxt(grouptask)
  137. local txt = ""
  138. if grouptask ~= nil then
  139. txt = I18N.SetLanguageValue("DiffGroupTaskConditionTxt",grouptask.value,grouptask.total)
  140. end
  141. self.taskTxt.text.text = txt
  142. end
  143. function UIDiffTaskView:GetTaskList(data)
  144. --LogError("----GetTaskList-data-----------"..Inspect(data))
  145. local tasklist = {}
  146. for _, v in pairs(data) do
  147. tasklist[#tasklist +1] = v
  148. end
  149. table.sort(tasklist,function (a,b)
  150. return a._id < b._id
  151. end)
  152. return tasklist
  153. end
  154. function UIDiffTaskView:GetCurTaskTextKey()
  155. if self.controller.TaskType == 1 then
  156. return "DiffTaskConditionTxt"
  157. else
  158. return "Diff_S_TaskConditionTxt"
  159. end
  160. end
  161. function UIDiffTaskView:GetTitleText()
  162. local txt = I18N.T("TaskUI_"..self.controller.TaskType)
  163. return txt
  164. end
  165. function UIDiffTaskView:GetConditionTxt(task)
  166. local condition = task._cfgData.MissionCondition[1]
  167. if( condition == nil ) then
  168. return ""
  169. end
  170. local lvCfg = ManagerContainer.CfgMgr:GetLevelDataById(condition[2])
  171. local state = task._got >= 1 and 1 or 0
  172. local txt = I18N.SetLanguageValue(self:GetCurTaskTextKey(),lvCfg.Name,state)
  173. return txt
  174. end
  175. function UIDiffTaskView:OnClickRight()
  176. self.controller:SetTypeData(2)
  177. self:SetItems()
  178. self:ShowChangeModeBtn()
  179. end
  180. function UIDiffTaskView:OnClickLeft()
  181. self.controller:SetTypeData(1)
  182. self:SetItems()
  183. self:ShowChangeModeBtn()
  184. end
  185. function UIDiffTaskView:ShowChangeModeBtn()
  186. local isShowLeft = self.controller.TaskType == 2
  187. self.btnArrowR:SetActive(not isShowLeft)
  188. self.btnArrowL:SetActive(isShowLeft)
  189. end
  190. return UIDiffTaskView