UIDiffTaskView.lua 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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 有值---"..Inspect(curgroup))
  70. local grd = {}
  71. if curgroup.rewardCfg then
  72. grd = curgroup.rewardCfg.GroupReward
  73. else
  74. grd = curgroup.groupTask._cfgData.rewardCfg.GroupReward
  75. end
  76. self:SetGroupReward(grd)
  77. local got = curgroup.groupTask._got
  78. self.btnGoto:SetActive(got == 0)
  79. self.getBtn:SetActive(got == 1)
  80. self.sealBtn:SetActive(got == 2)
  81. --self.getBtn.button.interactable = curgroup.groupTask._got == 1
  82. else
  83. self.goodsItems.loopHorizontalScrollRect:ClearCells()
  84. self.getBtn:SetActive(false)
  85. self.sealBtn:SetActive(false)
  86. self.btnGoto:SetActive(false)
  87. end
  88. if curgroup ~= nil and curgroup.taskList then
  89. datalist = self:GetTaskList(curgroup.taskList)
  90. end
  91. --datalist = self:GetTaskList(curgroup.taskList)
  92. --LogError("--------datalist---"..Inspect(datalist))
  93. self.scrollView.loopHorizontalScrollRect:ClearCells()
  94. --self.scrollView.loopHorizontalScrollRect:ClearAnchoredPostion()
  95. CommonUtil.LoopGridViewEleCreateNew(self,
  96. self.scrollView.loopHorizontalScrollRect,
  97. self.content.horizontalLayoutGroup,
  98. datalist,
  99. 0,
  100. self,
  101. self.UpdateTaskItem,
  102. nil,nil,0);
  103. self.scrollView.loopHorizontalScrollRect:MoveTo(0)
  104. self:SetGroupTxt(curgroup)
  105. end
  106. function UIDiffTaskView:UpdateTaskItem(_itemLua, _idx,_data)
  107. if not _itemLua or not _data then return end
  108. --_itemLua.gameObject:SetParent(wnd.content.transform)
  109. CommonUtil.UpdateItemPrefab(self, _itemLua, _data, Enum.ItemIEnterType.Bag,self,self.OnClickGetReward)
  110. end
  111. function UIDiffTaskView:UpdateRewardItem(_itemLua, _idx,_data)
  112. if not _itemLua or not _data then return end
  113. --_itemLua.gameObject:SetParent(wnd.content.transform)
  114. CommonUtil.UpdateItemPrefab(self, _itemLua, _data, Enum.ItemIEnterType.Bag)
  115. end
  116. function UIDiffTaskView:SetGroupReward(rewards)
  117. local rewardlist = ManagerContainer.DataMgr.HardMissionDataMgr:GetReward(rewards)
  118. self.goodsItems.loopHorizontalScrollRect:ClearCells()
  119. --self.goodsItems.loopHorizontalScrollRect:ClearAnchoredPostion()
  120. CommonUtil.LoopGridViewEleCreateNew(self,
  121. self.goodsItems.loopHorizontalScrollRect,
  122. self.goodsItemsContent.horizontalLayoutGroup,
  123. rewardlist,
  124. 0,
  125. self,
  126. self.UpdateRewardItem,
  127. nil,nil,0);
  128. --self.goodsItems.loopHorizontalScrollRect:SetItemStartIdx(0)
  129. end
  130. function UIDiffTaskView:RefreshTask()
  131. self:SetItems()
  132. end
  133. function UIDiffTaskView:OnClickGetReward(btn,data)
  134. --LogError("-----btn-----------"..Inspect(btn))
  135. --LogError("-----data-----------"..Inspect(data))
  136. ManagerContainer.DataMgr.TaskDataNew:CSGetTaskScoreRewardReq(data[0]._taskType,data[0]._id)
  137. end
  138. function UIDiffTaskView:OnClickGetGroupReward()
  139. ManagerContainer.DataMgr.TaskDataNew:CSGetTaskScoreRewardReq(self.CurGroup.groupTask._taskType,self.CurGroup.groupTask._id)
  140. end
  141. function UIDiffTaskView:OnClickJump()
  142. self:OnCloseClick()
  143. local curType = self.controller.TaskType
  144. if(ManagerContainer.LuaBattleMgr:GetBattleMode() ~= curType) then
  145. ManagerContainer.LuaBattleMgr:SendChangeMapLevelTypeReq(curType)
  146. end
  147. end
  148. function UIDiffTaskView:SetGroupTxt(grouptask)
  149. local txt = ""
  150. if grouptask ~= nil then
  151. txt = I18N.SetLanguageValue("DiffGroupTaskConditionTxt",grouptask.value,grouptask.total)
  152. end
  153. self.taskTxt.text.text = txt
  154. end
  155. function UIDiffTaskView:GetTaskList(data)
  156. --LogError("----GetTaskList-data-----------"..Inspect(data))
  157. local tasklist = {}
  158. for _, v in pairs(data) do
  159. tasklist[#tasklist +1] = v
  160. end
  161. table.sort(tasklist,function (a,b)
  162. return a._id < b._id
  163. end)
  164. return tasklist
  165. end
  166. function UIDiffTaskView:GetCurTaskTextKey()
  167. if self.controller.TaskType == 1 then
  168. return "DiffTaskConditionTxt"
  169. else
  170. return "Diff_S_TaskConditionTxt"
  171. end
  172. end
  173. function UIDiffTaskView:GetTitleText()
  174. local txt = I18N.T("TaskUI_"..self.controller.TaskType)
  175. return txt
  176. end
  177. function UIDiffTaskView:GetConditionTxt(task)
  178. local condition = task._cfgData.MissionCondition[1]
  179. if( condition == nil ) then
  180. return ""
  181. end
  182. local lvCfg = ManagerContainer.CfgMgr:GetLevelDataById(condition[2])
  183. local mapcfg = ManagerContainer.CfgMgr:GetMapData(lvCfg.MapId)
  184. local lvname = I18N.T(mapcfg.Name) .. " "..lvCfg.LevelId
  185. local state = task._got >= 1 and 1 or 0
  186. local txt = I18N.SetLanguageValue(self:GetCurTaskTextKey(),lvname,state)
  187. return txt
  188. end
  189. function UIDiffTaskView:OnClickRight()
  190. self.controller:SetTypeData(2)
  191. self:SetItems()
  192. self:ShowChangeModeBtn()
  193. end
  194. function UIDiffTaskView:OnClickLeft()
  195. self.controller:SetTypeData(1)
  196. self:SetItems()
  197. self:ShowChangeModeBtn()
  198. end
  199. function UIDiffTaskView:ShowChangeModeBtn()
  200. local isShowLeft = self.controller.TaskType == 2
  201. self.btnArrowR:SetActive(not isShowLeft)
  202. self.btnArrowL:SetActive(isShowLeft)
  203. end
  204. function UIDiffTaskView:ShowModeBtn()
  205. self.btnArrowR:SetActive(false)
  206. self.btnArrowL:SetActive(false)
  207. end
  208. return UIDiffTaskView