UIDiffTaskView.lua 7.0 KB

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