UIDiffTaskView.lua 6.8 KB

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