UIExpeditionDungeonInfoView.lua 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. local UIExpeditionDungeonInfoView = require("UIExpedition/UIExpeditionDungeonInfoView_Generate")
  2. function UIExpeditionDungeonInfoView:OnAwake(data)
  3. self.controller = require("UIExpedition/UIExpeditionDungeonInfoCtr"):new()
  4. self.controller:Init(self)
  5. self.controller:SetData(data)
  6. end
  7. function UIExpeditionDungeonInfoView:AddEventListener()
  8. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Expedition_RefreshData,self,self.RefreshData)
  9. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Expedition_ResetData,self,self.OnExpeditionResetData)
  10. end
  11. function UIExpeditionDungeonInfoView:FillContent(data, uiBase)
  12. self.uiBase = uiBase
  13. local gameObject = self.uiBase:GetRoot()
  14. if gameObject ~= nil then
  15. self.gameObject = gameObject
  16. self.transform = gameObject.transform
  17. end
  18. self:InitGenerate(self.transform, data)
  19. self:Init()
  20. end
  21. function UIExpeditionDungeonInfoView:Init()
  22. self:InitListView()
  23. self:ShowLevelBg()
  24. self:SetLevelData()
  25. self:ShowLevelRewards()
  26. self:RefreshTeamHPStatus()
  27. end
  28. function UIExpeditionDungeonInfoView:InitListView()
  29. self.boxScrollList.loopGridView:InitGridView(0, function(gridView, itemIndex, row, column)
  30. return self:GetItemByRowColumn(gridView, itemIndex, row, column)
  31. end, nil)
  32. end
  33. function UIExpeditionDungeonInfoView:RemoveEventListener()
  34. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  35. end
  36. function UIExpeditionDungeonInfoView:AddUIEventListener()
  37. self.uiBase:AddButtonEventListener(self.AnyBtn.button,self, self.OnClickCloseBtn)
  38. self.uiBase:AddButtonEventListener(self.closeBtn.button,self, self.OnClickCloseBtn)
  39. self.uiBase:AddButtonEventListener(self.nextLevelBtn.button,self, self.OnClickNextLevel)
  40. self.uiBase:AddButtonEventListener(self.lastLevelBtn.button,self, self.OnClickLastLevel)
  41. self.uiBase:AddButtonEventListener(self.getAllRewardBtn.button,self, self.OnClickGetAllReward)
  42. self.uiBase:AddButtonEventListener(self.arrangeBtn.button,self, self.OnClickArrangeBtn)
  43. self.uiBase:AddButtonEventListener(self.skillBtn.button,self, self.OnClickSkillBtn)
  44. self.uiBase:AddButtonEventListener(self.petBtn.button,self, self.OnClickPetBtn)
  45. self.uiBase:AddButtonEventListener(self.blessBtn.button,self, self.OnClickBlessBtn)
  46. end
  47. function UIExpeditionDungeonInfoView:OnHide()
  48. --self.boxScrollList.loopGridView:Dispose()
  49. end
  50. function UIExpeditionDungeonInfoView:OnShow(data)
  51. self.controller:SetData(data)
  52. end
  53. function UIExpeditionDungeonInfoView:OnClose()
  54. self.boxScrollList.loopGridView:Dispose()
  55. self.levelDatas = nil
  56. end
  57. function UIExpeditionDungeonInfoView:OnDispose()
  58. self.controller:OnDispose()
  59. end
  60. function UIExpeditionDungeonInfoView:RefreshData(isSingleReward)
  61. self:SetLevelData()
  62. self:ShowLevelRewards(isSingleReward)
  63. self:RefreshTeamHPStatus()
  64. end
  65. function UIExpeditionDungeonInfoView:ShowLevelBg()
  66. local mapData = self.controller:GetMapData()
  67. if mapData.levelBg ~= nil and mapData.levelBg ~= "" then
  68. CommonUtil.LoadIcon(self, mapData.levelBg, function (sprite)
  69. self.levelBg.image.sprite = sprite
  70. end)
  71. end
  72. end
  73. function UIExpeditionDungeonInfoView:OnExpeditionResetData()
  74. ManagerContainer.LuaUIMgr:ClosePage(Enum.UIPageName.UIExpeditionArrange)
  75. ManagerContainer.LuaUIMgr:ClosePage(Enum.UIPageName.UISkillSettings)
  76. ManagerContainer.LuaUIMgr:ClosePage(Enum.UIPageName.UIPetBattle)
  77. ManagerContainer.LuaUIMgr:ClosePage(Enum.UIPageName.UIExpeditionBless)
  78. self:UIClose()
  79. end
  80. function UIExpeditionDungeonInfoView:RefreshTeamHPStatus()
  81. local totalHPPercent = 0
  82. local hasDead = false
  83. local heroIds = ManagerContainer.DataMgr.ExpeditionDataMgr:GetCurrBattleTeamMembers()
  84. if #heroIds > 0 then
  85. for i = 1, #heroIds do
  86. local hpPercent,spPercent = ManagerContainer.DataMgr.ExpeditionDataMgr:GetHeroHPAndSP(heroIds[i])
  87. if hpPercent == 0 then
  88. hasDead = true
  89. end
  90. totalHPPercent = totalHPPercent + hpPercent
  91. end
  92. totalHPPercent = totalHPPercent / #heroIds
  93. end
  94. self.arrangeBtn.hpTipsNode.tips.text.text = string.format('%.1f', totalHPPercent) .. "%"
  95. if hasDead then
  96. self.arrangeBtn.hpTipsNode.healthFlag:SetActive(false)
  97. self.arrangeBtn.hpTipsNode.warningFlag:SetActive(false)
  98. self.arrangeBtn.hpTipsNode.deadFlag:SetActive(true)
  99. self.arrangeBtn.hpTipsNode.tips:SetActive(false)
  100. else
  101. if totalHPPercent >= 90 then
  102. self.arrangeBtn.hpTipsNode.healthFlag:SetActive(true)
  103. self.arrangeBtn.hpTipsNode.warningFlag:SetActive(false)
  104. self.arrangeBtn.hpTipsNode.deadFlag:SetActive(false)
  105. self.arrangeBtn.hpTipsNode.tips:SetActive(true)
  106. self.arrangeBtn.hpTipsNode.tips.text.color = Color.New(0, 177/255, 101/255, 1)
  107. else
  108. self.arrangeBtn.hpTipsNode.healthFlag:SetActive(false)
  109. self.arrangeBtn.hpTipsNode.warningFlag:SetActive(true)
  110. self.arrangeBtn.hpTipsNode.deadFlag:SetActive(false)
  111. self.arrangeBtn.hpTipsNode.tips:SetActive(true)
  112. self.arrangeBtn.hpTipsNode.tips.text.color = Color.New(1, 150/255, 0, 1)
  113. end
  114. end
  115. end
  116. function UIExpeditionDungeonInfoView:SetLevelData()
  117. local mapData = self.controller:GetMapData()
  118. local curLevelId = ManagerContainer.DataMgr.ExpeditionDataMgr:GetCurLevelId()
  119. if mapData.isPassed then
  120. curLevelId = mapData.maxLevelNum
  121. end
  122. local bossList = ManagerContainer.DataMgr.ExpeditionDataMgr:GetBossList()
  123. local challengeBossSlot = ManagerContainer.DataMgr.ExpeditionDataMgr:ChanllengeSlotIdx()
  124. local levelData = mapData:FindLevelByLevelId(curLevelId)
  125. local deltaLevel = mapData:GetNextGoodRewardLevel(curLevelId)
  126. if deltaLevel > 0 then
  127. self.tipsTxt.text.text = string.formatbykey("ExpeditionBox",deltaLevel)
  128. else
  129. self.tipsTxt.text.text = string.formatbykey("ExpeditionBigBox")
  130. end
  131. self.title.text.text = I18N.T( mapData.name)
  132. self.curLevelTxt.text.text = tostring(curLevelId) .. "/" .. mapData.maxLevelNum
  133. local CurScore = ManagerContainer.DataMgr.ExpeditionDataMgr:GetCurScore()
  134. local MaxScore = ManagerContainer.DataMgr.ExpeditionDataMgr:GetMaxScore()
  135. local CurLevelScore = levelData:GetScore()
  136. self.score1.number.text.text = tostring(CurLevelScore)
  137. self.score2.number.text.text = tostring(MaxScore)
  138. self.score3.number.text.text = tostring(CurScore)
  139. for i = 1, 3 do
  140. local bossItem = self:GetBossItem(i)
  141. bossItem:SetActive(false)
  142. end
  143. if mapData.isPassed then
  144. self.passedNode:SetActive(true)
  145. else
  146. self.passedNode:SetActive(false)
  147. if challengeBossSlot>= 1 and challengeBossSlot<=3 then
  148. local bossMaxHP,bossMaxSp = levelData:GetBossMaxHPAndSp(bossList[challengeBossSlot].id)
  149. local bossCfg = ManagerContainer.CfgMgr:GetNpcCfgById(bossList[challengeBossSlot].id)
  150. if bossCfg ~= nil then
  151. local hpPercent = bossList[challengeBossSlot].hp / bossMaxHP
  152. self:SetBossData(self:GetBossItem(challengeBossSlot),bossCfg,hpPercent,challengeBossSlot,bossList[challengeBossSlot].id)
  153. end
  154. else
  155. for i = 1, #bossList do
  156. local bossInfo = bossList[i]
  157. local bossCfg = ManagerContainer.CfgMgr:GetNpcCfgById(bossInfo.id)
  158. if bossCfg ~= nil then
  159. self:SetBossData(self:GetBossItem(i),bossCfg,1,i,bossInfo.id)
  160. end
  161. end
  162. end
  163. end
  164. end
  165. function UIExpeditionDungeonInfoView:SetBossData(bossItemLua,bossCfg,hpPercent,bossSlotIdx,BossId)
  166. bossItemLua.bossName.text.text = I18N.T(bossCfg.Name)
  167. bossItemLua.hpProgress.slider.value = hpPercent
  168. --boss 积分
  169. local CurBossScore = ManagerContainer.DataMgr.ExpeditionDataMgr:GetCurBossScore(BossId)
  170. bossItemLua.scoreTxt.text.text = "+"..tostring(CurBossScore)
  171. if bossCfg.Icon~= nil then
  172. CommonUtil.LoadIcon(self, bossCfg.Icon, function (sprite)
  173. bossItemLua.bossImg.image.sprite = sprite
  174. bossItemLua.bossImg.image:SetNativeSize()
  175. if bossCfg.IconOffset~= nil then
  176. local offset = Vector2(bossCfg.IconOffset[1],bossCfg.IconOffset[2])
  177. bossItemLua.bossImg.rectTransform.anchoredPosition = offset
  178. end
  179. end)
  180. end
  181. local natureCfg = ManagerContainer.CfgMgr:GetNatureDataById(bossCfg.NatureId)
  182. if natureCfg ~= nil and natureCfg.Icon~=nil then
  183. CommonUtil.LoadIcon(self, natureCfg.Icon, function (sprite)
  184. bossItemLua.natureImg.image.sprite = sprite
  185. end)
  186. end
  187. self.uiBase:AddButtonUniqueEventListener(bossItemLua.challengeBtn.button,self, self.OnClickChallengeBoss,bossSlotIdx)
  188. self.uiBase:AddButtonUniqueEventListener(bossItemLua.bossImg.button,self, self.OnClickViewBossDetail,bossSlotIdx)
  189. bossItemLua:SetActive(true)
  190. end
  191. function UIExpeditionDungeonInfoView:OnClickViewBossDetail(btn,params)
  192. local bossList = ManagerContainer.DataMgr.ExpeditionDataMgr:GetBossList()
  193. local bossSlotIdx = params[0]
  194. local bossData = bossList[bossSlotIdx]
  195. local bossActor = ActorData.CreateNpcPlayerActor(0,bossData.id,bossData.level)
  196. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIBattleBossTips,bossActor)
  197. end
  198. function UIExpeditionDungeonInfoView:GetBossItem(idx)
  199. if idx == 1 then
  200. return self.bossItem1
  201. elseif idx == 2 then
  202. return self.bossItem2
  203. else
  204. return self.bossItem3
  205. end
  206. end
  207. function UIExpeditionDungeonInfoView:RefreshRewards(isSingleReward)
  208. self.controller:RefreshMapData()
  209. local mapData = self.controller:GetMapData()
  210. if self.levelDatas == nil then
  211. self.levelDatas = {}
  212. end
  213. if mapData.allLevels ~= nil then
  214. for _,v in pairs(mapData.allLevels) do
  215. self.levelDatas[v.levelId] = v
  216. end
  217. end
  218. local loopGridView = self.boxScrollList.loopGridView
  219. local length = #self.levelDatas
  220. if not isSingleReward then
  221. loopGridView:SetListItemCount(length, true)
  222. else
  223. loopGridView:RefreshListByIndex(length)
  224. end
  225. loopGridView:RefreshAllShownItem()
  226. self.onekeyRP:SetActive(mapData:HasRedPoint())
  227. end
  228. function UIExpeditionDungeonInfoView:ShowLevelRewards(isSingleReward)
  229. local curLevelId = self.controller:GetCurLevelId()
  230. local mapData = self.controller:GetMapData()
  231. --local startLevelId = curLevelId
  232. --if (curLevelId+5) > mapData.maxLevelNum then
  233. -- startLevelId = mapData.maxLevelNum - 5
  234. --else
  235. -- if math.fmod(curLevelId, 5) > 0 then
  236. -- startLevelId = curLevelId - math.fmod(curLevelId, 5) + 1
  237. -- else
  238. -- if curLevelId == 5 then
  239. -- startLevelId = 0
  240. -- else
  241. -- startLevelId = curLevelId - 4
  242. -- end
  243. -- end
  244. --end
  245. self:RefreshRewards(isSingleReward)
  246. if not isSingleReward then
  247. local curIdx = curLevelId < #mapData.allLevels - 4 and curLevelId - 1 or #mapData.allLevels - 5
  248. self.boxScrollList.loopGridView:MovePanelToItemByIndex(curIdx)
  249. end
  250. end
  251. function UIExpeditionDungeonInfoView:GetItemByRowColumn(gridView, itemIndex, row, column)
  252. local levelData = self.levelDatas[itemIndex + 1]
  253. local item
  254. if levelData then
  255. item = gridView:NewListViewItem('DungeonRewardBox')
  256. local rewardLua = CommonUtil.BindGridViewItem2Lua(self, 'DungeonRewardBox', item.gameObject)
  257. local levelData = self.levelDatas[itemIndex + 1]
  258. local idx = itemIndex
  259. CommonUtil.LoadIcon(self, levelData.closeRewardBoxImg, function (sprite)
  260. rewardLua.closeNode.image.sprite = sprite
  261. end,rewardLua,"CloseRewardBoxIdx")
  262. CommonUtil.LoadIcon(self, levelData.openRewardBoxImg, function (sprite)
  263. rewardLua.openNode.image.sprite = sprite
  264. end,rewardLua,"OpenRewardBoxIdx")
  265. rewardLua.currentNode:SetActive(not levelData.isPassed and (idx+1) == self.controller:GetCurLevelId())
  266. rewardLua.levelNum.text.text =I18N.SetLanguageValue('DiNGuan',idx+1)
  267. if levelData.isGotReward then
  268. rewardLua.openNode:SetActive(true)
  269. rewardLua.closeNode:SetActive(false)
  270. rewardLua.activeNode:SetActive(false)
  271. self.uiBase:AddButtonUniqueEventListener(rewardLua.button,self, self.OnClickViewRewardBox,levelData.levelId)
  272. elseif levelData.isPassed then
  273. rewardLua.openNode:SetActive(false)
  274. rewardLua.closeNode:SetActive(true)
  275. rewardLua.activeNode:SetActive(true)
  276. self.uiBase:AddButtonUniqueEventListener(rewardLua.button,self, self.OnClickGetRewardBox,levelData.levelId)
  277. else
  278. rewardLua.openNode:SetActive(false)
  279. rewardLua.closeNode:SetActive(true)
  280. rewardLua.activeNode:SetActive(false)
  281. self.uiBase:AddButtonUniqueEventListener(rewardLua.button,self, self.OnClickViewRewardBox,levelData.levelId)
  282. end
  283. end
  284. return item
  285. end
  286. function UIExpeditionDungeonInfoView:OnClickViewRewardBox(btn,params)
  287. local mapData = self.controller:GetMapData()
  288. local levelId = params[0]
  289. local levelData = mapData:FindLevelByLevelId(levelId)
  290. if levelData ~= nil and levelData.rewards ~= nil and #levelData.rewards > 0 then
  291. ManagerContainer.LuaUIMgr:ShowMinRewardTips(levelData.rewards)
  292. end
  293. end
  294. function UIExpeditionDungeonInfoView:OnClickGetRewardBox(btn,params)
  295. local levelId = params[0]
  296. local mapData = self.controller:GetMapData()
  297. ManagerContainer.DataMgr.ExpeditionDataMgr:SendGotRewardReq(mapData.mapId,levelId)
  298. end
  299. function UIExpeditionDungeonInfoView:OnClickCloseBtn()
  300. self:UIClose()
  301. end
  302. function UIExpeditionDungeonInfoView:OnClickNextLevel()
  303. local idx = self.boxScrollList.loopGridView:FindNearestItemIndex()
  304. local startPos = idx + 5
  305. self.boxScrollList.loopGridView:MovePanelToItemByIndex(startPos)
  306. end
  307. function UIExpeditionDungeonInfoView:OnClickLastLevel()
  308. local idx = self.boxScrollList.loopGridView:FindNearestItemIndex()
  309. local startPos = idx - 5
  310. if startPos < 0 then
  311. self.boxScrollList.loopGridView:MovePanelToItemByIndex(0)
  312. return
  313. end
  314. self.boxScrollList.loopGridView:MovePanelToItemByIndex(startPos)
  315. end
  316. function UIExpeditionDungeonInfoView:OnClickGetAllReward()
  317. local mapData = self.controller:GetMapData()
  318. ManagerContainer.DataMgr.ExpeditionDataMgr:SendGotRewardReq(mapData.mapId,0)
  319. end
  320. function UIExpeditionDungeonInfoView:OnClickArrangeBtn()
  321. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIExpeditionArrange)
  322. end
  323. function UIExpeditionDungeonInfoView:OnClickSkillBtn()
  324. ManagerContainer.LuaUIMgr:Hide(self.uiData.id)
  325. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UISkillSettings,{1},self.uiData.id)
  326. end
  327. function UIExpeditionDungeonInfoView:OnClickPetBtn()
  328. ManagerContainer.LuaUIMgr:Hide(self.uiData.id)
  329. local data = {list = ManagerContainer.DataMgr.ExpeditionDataMgr:GetCurrBattleTeamMembers()}
  330. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPetBattle,data,self.uiData.id)
  331. end
  332. function UIExpeditionDungeonInfoView:OnClickBlessBtn()
  333. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIExpeditionBless)
  334. end
  335. function UIExpeditionDungeonInfoView:OnClickChallengeBoss(btn,params)
  336. local bossSlotIdx = params[0]
  337. ManagerContainer.DataMgr.ExpeditionDataMgr:SendChallengeBossStart(bossSlotIdx)
  338. end
  339. return UIExpeditionDungeonInfoView