UIClimbingTowerView.lua 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016
  1. local UIClimbingTowerView = require("UIClimbingTower/UIClimbingTowerView_Generate")
  2. local PreviewSystem = require "PreviewSystem"
  3. local RoleViewSystem = require "RoleViewSystem"
  4. local IconItemCtr = require "Common.IconItemCtr"
  5. local previewSystem
  6. local moveState = false
  7. local LastmoveState = false
  8. function UIClimbingTowerView:OnAwake(data)
  9. self.controller = require("UIClimbingTower/UIClimbingTowerCtr"):new()
  10. self.controller:Init(self)
  11. self.controller:SetData(data)
  12. end
  13. function UIClimbingTowerView:AddEventListener()
  14. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name,UIEventNames.EID_REFRESH_CLIMBINGTOWER_DATA,self,self.UpdateLevelsData)
  15. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name,UIEventNames.REFRESH_CLIMBINGTOWER_DAYREWARD,self,self.GetPopGot)
  16. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name,UIEventNames.EID_CHANGE_TOWER_SHOW_REFRESH,self,self.ShowChange)
  17. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name,UIEventNames.EID_REFRESH_PEAKTOWER_WIN_DATA,self,self.UpdatePeakTowerDataAfterWin)
  18. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name,UIEventNames.EID_Refresh_ClimbingTower_FriendInfo,self,self.RefreshClimbingTowerFriendInfo)
  19. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_TOWER_LEVEL_MIN_FIGHT_POWER_ACK, self.OnFightPowerAck,self)
  20. end
  21. function UIClimbingTowerView:GetPopGot(data)
  22. if not data then
  23. return
  24. end
  25. local rewards = {}
  26. for i = 1, #data do
  27. table.insert(rewards,{cfgId = data[i].key,num = data[i].value})
  28. end
  29. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPOPGot,{rewards = rewards})
  30. end
  31. function UIClimbingTowerView:FillContent(data, uiBase)
  32. self.uiBase = uiBase
  33. local gameObject = self.uiBase:GetRoot()
  34. if gameObject ~= nil then
  35. self.gameObject = gameObject
  36. self.transform = gameObject.transform
  37. end
  38. self:InitGenerate(self.transform, data)
  39. self:Init()
  40. end
  41. function UIClimbingTowerView:Init()
  42. self.initedOver = false
  43. self.otherType = nil
  44. self.uIGoto:SetActive(true)
  45. self.text2.uILocalizeScript:SetContent("GoToLvlUp")
  46. self.text1.uILocalizeScript:SetContentAndValues("LvlUpNum", {0})
  47. self:OnHeroLvChanged()
  48. --会跳往主角界面
  49. if ManagerContainer.LuaUIMgr:HasOpenPage(Enum.UIPageName.UIMain) == false then
  50. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIMain)
  51. end
  52. --打开限时礼包
  53. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.LIMIT_RECHARGE_OPEN_UI_NTF)
  54. -- --适配宽度
  55. -- if nil ~= self.scrollview and nil ~= self.scrollview.content and nil ~= self.scrollview.content.gridLayoutGroup then
  56. -- local rectTrans = self.scrollview.content:GetComponent(Enum.TypeInfo.RectTransform)
  57. -- if nil ~= rectTrans then
  58. -- self.scrollview.content.gridLayoutGroup.cellSize = Vector2(rectTrans.rect.width, self.scrollview.content.gridLayoutGroup.cellSize.y)
  59. -- end
  60. -- end
  61. -- self:InitGrid()
  62. self.cover:SetActive(true)
  63. self.cover.animator:Play("CoverKeep")
  64. --保护机制 5秒后关闭云
  65. if self.cloudTimer then
  66. self.cloudTimer:Stop()
  67. end
  68. if not self.cloudTimer then
  69. self.cloudTimer = Timer.New(slot(self.CloudOut, self), 1)
  70. end
  71. if not self.cloudTimer.running then
  72. self.cloudTimer:Start()
  73. end
  74. self:Refresh()
  75. if not self.queryTimer then
  76. self.queryTimer = FrameTimer.New(slot(self.QueryDatas, self), 1)
  77. end
  78. if not self.queryTimer.running then
  79. self.queryTimer:Start()
  80. end
  81. end
  82. function UIClimbingTowerView:QueryDatas()
  83. local type = self.controller:GetCurTowerType()
  84. self.controller:SendTowerInfoReq(type)
  85. end
  86. function UIClimbingTowerView:Refresh()
  87. local type = self.controller:GetCurTowerType()
  88. if type == Enum.UnlimitTowerType.PeakTower then
  89. self.rewardLoopGridMap = {}
  90. self.scrollItemGoes = {}
  91. self.roleSystemMap = {}
  92. self.previewSystemMap = {}
  93. self.scrollview.loopListView.mOnSnapItemFinished = function(loopListView, loopListViewItem)
  94. return self:OnSnapItemFinished(loopListView, loopListViewItem)
  95. end
  96. self.boardTitle.uILocalizeScript:SetContent("TopTowerTitle")
  97. elseif type == Enum.UnlimitTowerType.ClimbingTower then
  98. self.boardTitle.uILocalizeScript:SetContent("TitleClimbingTower")
  99. end
  100. local isShowTop_Lock = (self.controller:FindLevelIsPassed() == true and type == Enum.UnlimitTowerType.ClimbingTower)
  101. self.btnTowerTop:SetActive(type == Enum.UnlimitTowerType.ClimbingTower)
  102. self.btnTowerTop_lock:SetActive(not isShowTop_Lock)
  103. self.btnTower:SetActive(type == Enum.UnlimitTowerType.PeakTower)
  104. self.btnStatistics:SetActive(type == Enum.UnlimitTowerType.ClimbingTower)
  105. end
  106. function UIClimbingTowerView:InitGrid()
  107. self.scrollview.loopListView:InitListView(0, function(gridView, itemIndex)
  108. return self:GetItemByRowColumn(gridView, itemIndex)
  109. end, nil)
  110. end
  111. function UIClimbingTowerView:RemoveEventListener()
  112. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  113. end
  114. function UIClimbingTowerView:AddUIEventListener()
  115. self.uiBase:AddButtonEventListener(self.closeBtn.button,self,self.OnClickClose)
  116. self.uiBase:AddButtonEventListener(self.rankBtn.button,self,self.OnClickRank)
  117. self.uiBase:AddButtonEventListener(self.playRuleBtn.button, self, self.OnClickPlayRuleBtn)
  118. self.uiBase:AddButtonEventListener(self.btnStatistics.button,self,self.OnClickBtnStatistics)
  119. --角色升级动画弹出播放
  120. self.uiBase:AddButtonEventListener(self.btnInOut.button,self,self.OnPlayChangeShowState)
  121. -- 前往角色界面
  122. self.uiBase:AddButtonEventListener(self.btnGoto.button,self,self.OnShowRoleWnd)
  123. self.uiBase:AddButtonEventListener(self.btnTower.button, self, self.ShowTowerMode)
  124. self.uiBase:AddButtonEventListener(self.btnTowerTop.button, self, self.ShowTowerMode)
  125. self.uiBase:AddButtonEventListener(self.btnPresent.button, self, self.OnBtnPresentClick)
  126. self.uiBase:AddButtonEventListener(self.towerBgBtn.button,self,self.CloseModeNode)
  127. self.uiBase:AddButtonEventListener(self.wjchallengeBtn.button,self,self.OnClickWJBtn)
  128. end
  129. function UIClimbingTowerView:OnSnapItemFinished(loopListView, loopListViewItem)
  130. for _,v in pairs(self.scrollItemGoes) do
  131. local instanceId = v.gameObject:GetInstanceID()
  132. if v.gameObject.activeSelf then
  133. self.previewSystemMap[instanceId]:RemoveGo(v.gameObject)
  134. end
  135. end
  136. end
  137. function UIClimbingTowerView:ShowChange(needChange)
  138. self:Clear()
  139. self.cover:SetActive(true)
  140. self:InitGrid()
  141. LogError("Show change "..Inspect(needChange))
  142. --保护机制 5秒后关闭云
  143. if not self.cloudTimer then
  144. self.cloudTimer = Timer.New(slot(self.CloudOut, self), 1)
  145. end
  146. if not self.cloudTimer.running then
  147. self.cloudTimer:Start()
  148. end
  149. if needChange and self.otherType then
  150. self.controller:ChangeToOtherType()
  151. self.otherType = nil
  152. end
  153. self:Refresh()
  154. end
  155. function UIClimbingTowerView:CloudOut()
  156. self.cover.animator:Play("CoverOut")
  157. end
  158. function UIClimbingTowerView:OnBtnTowerClick()
  159. --ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('ClimbingTowerClickTips')
  160. LogError('OnBtnTowerClick')
  161. self.otherType = 1 - self.controller:GetCurTowerType()
  162. local needQuery = self.controller:SendTowerInfoReq(self.otherType)
  163. if not needQuery then
  164. self:ShowChange(true)
  165. self:UpdateLevelsData()
  166. end
  167. end
  168. function UIClimbingTowerView:OnBtnPresentClick()
  169. local server_time = ManagerContainer.LuaTimerMgr:CurLuaServerTime()
  170. local servertime = type(server_time) == "number" and server_time or #server_time
  171. local dayRewardTime = ManagerContainer.DataMgr.TowerDataMgr:GetDayRewardTime()
  172. if dayRewardTime < servertime then
  173. local curlevel = ManagerContainer.DataMgr.TowerDataMgr:GetCurChallengeLevel() - 1
  174. local curRewardData,nextRewardData,NoReward = self:GetRewardDataBylv(curlevel)
  175. local tipsKey = ""
  176. local data = nil
  177. if NoReward then
  178. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("PresentErrorTips2")
  179. return
  180. end
  181. if nextRewardData then
  182. tipsKey = "ClimbingTowerDayRewardTips1"
  183. data = {curRewardData[2],nextRewardData[1] - curlevel,nextRewardData[2]}
  184. else
  185. tipsKey = "ClimbingTowerDayRewardTips2"
  186. data = {curRewardData[2]}
  187. end
  188. ManagerContainer.LuaUIMgr:ShowMessageBox(tipsKey,data,nil,self,self.OnSureGetDayReward)
  189. else
  190. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("PresentErrorTips1")
  191. end
  192. end
  193. function UIClimbingTowerView:OnSureGetDayReward()
  194. ManagerContainer.DataMgr.TowerDataMgr:OnClimbingTowerDayRewardREQ()
  195. end
  196. function UIClimbingTowerView:GetRewardDataBylv(lv)
  197. local str = GlobalConfig.Instance:GetConfigStrValue(357)
  198. local tab = CommonUtil.DeserializeGlobalStrToNumberTable(str)
  199. if tab then
  200. for i = 1, #tab do
  201. local curData = tab[i]
  202. local nextData = tab[i + 1]
  203. if nextData then
  204. if lv < curData[1] then
  205. return {0,0},curData,true
  206. elseif curData[1] <= lv and lv < nextData[1] then
  207. return curData,nextData
  208. end
  209. else
  210. return curData,nil
  211. end
  212. end
  213. end
  214. end
  215. --角色升级后 升级动画弹出播放
  216. function UIClimbingTowerView:OnHeroLvChanged()
  217. local nCount,nId = self:GetLeveUpNum()
  218. if nCount > 0 then
  219. moveState = true
  220. if nil ~= self.light then
  221. self.light:SetActive(true)
  222. end
  223. else
  224. if nil ~= self.light then
  225. self.light:SetActive(false)
  226. end
  227. end
  228. self:OnPlayChangeShow(nCount)
  229. end
  230. --获取上阵角色可升级数量
  231. function UIClimbingTowerView:GetLeveUpNum()
  232. local nBattlePatnerNum = 0
  233. local nPartnerId = -1
  234. --可上阵伙伴
  235. local tbBattlePartner = self:GetSortPartner()
  236. for i = 1, #tbBattlePartner do
  237. --是否可升级
  238. local lvUpState = ManagerContainer.RedPointMgr.HeroRPCtr:GetPartnerLvUpRPStatusById(tbBattlePartner[i].id)
  239. if lvUpState then
  240. if nPartnerId == -1 then
  241. nPartnerId = tbBattlePartner[i].id
  242. end
  243. nBattlePatnerNum = nBattlePatnerNum + 1
  244. end
  245. end
  246. return nBattlePatnerNum , nPartnerId
  247. end
  248. function UIClimbingTowerView:GetSortPartner()
  249. local partnerDatas = ManagerContainer.DataMgr.PartnerData:GetPartnersDataByInBattle()
  250. local sortedPartnerDatas = {}
  251. for _,v in pairs(partnerDatas) do
  252. sortedPartnerDatas[#sortedPartnerDatas + 1] = v
  253. end
  254. table.sort(sortedPartnerDatas, function (a, b)
  255. if a.owned and b.owned then
  256. return a.post < b.post
  257. else
  258. if a.owned and not b.owned then
  259. return true
  260. elseif not a.owned and b.owned then
  261. return false
  262. else
  263. return a.post < b.post
  264. end
  265. end
  266. end)
  267. return sortedPartnerDatas
  268. end
  269. --按钮点击 角色升级动画弹出播放
  270. function UIClimbingTowerView:OnPlayChangeShowState()
  271. moveState = not moveState
  272. self:OnPlayChangeShow()
  273. end
  274. --展示升级动画弹出播放
  275. function UIClimbingTowerView:OnPlayChangeShow(nCount)
  276. if nil == self.text1 or nil == self.bgGoto then
  277. return
  278. end
  279. if nil ~= nCount then
  280. self.text1.uILocalizeScript:SetContentAndValues("LvlUpNum", {nCount})
  281. end
  282. if LastmoveState ~= moveState then
  283. if moveState then
  284. self.bgGoto.animator:CrossFade("UIGotoIn", 0.1)
  285. else
  286. self.bgGoto.animator:CrossFade("UIGotoOut", 0.1)
  287. end
  288. LastmoveState = moveState
  289. end
  290. end
  291. -- 前往角色界面
  292. function UIClimbingTowerView:OnShowRoleWnd()
  293. local ncount,nId = self:GetLeveUpNum()
  294. if nId == -1 then
  295. nId = nil
  296. end
  297. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UIMAINVIEW_CHANGE_NOTICE, Enum.MainViewPageType.Role, nId)
  298. end
  299. function UIClimbingTowerView:OnHide()
  300. end
  301. function UIClimbingTowerView:OnShow(data)
  302. self.controller:SetData(data)
  303. self:UpdateLevelsData()
  304. end
  305. function UIClimbingTowerView:Clear()
  306. self.initedOver = false
  307. if self.queryTimer then
  308. self.queryTimer:Stop()
  309. self.queryTimer = nil
  310. end
  311. if self.cloudTimer then
  312. self.cloudTimer:Stop()
  313. self.cloudTimer = nil
  314. end
  315. if self.peakRefreshTimer then
  316. self.peakRefreshTimer:Stop()
  317. self.peakRefreshTimer = nil
  318. end
  319. local type = self.controller:GetCurTowerType()
  320. if type == Enum.UnlimitTowerType.PeakTower then
  321. if self.scrollItemGoes then
  322. self.scrollItemGoes = nil
  323. end
  324. if self.rewardLoopGridMap then
  325. for _, v in pairs(self.rewardLoopGridMap) do
  326. v:Dispose()
  327. end
  328. self.rewardLoopGridMap = nil
  329. end
  330. if self.previewSystemMap then
  331. for _, v in pairs(self.previewSystemMap) do
  332. v:Dispose()
  333. end
  334. self.previewSystemMap = nil
  335. end
  336. if self.roleSystemMap then
  337. for _, v in pairs(self.roleSystemMap) do
  338. v:Dispose()
  339. end
  340. self.rewardLoopGridMap = nil
  341. end
  342. end
  343. self.scrollview.loopListView:Dispose()
  344. end
  345. function UIClimbingTowerView:OnClose()
  346. self:Clear()
  347. self.cover:SetActive(false)
  348. end
  349. function UIClimbingTowerView:OnDispose()
  350. end
  351. function UIClimbingTowerView:RefreshClimbingTowerFriendInfo(levelIds)
  352. self.scrollview.loopListView:RefreshAllShownItem()
  353. end
  354. function UIClimbingTowerView:FindItemGo(levelId)
  355. if self.scrollview.content == nil then
  356. return nil
  357. end
  358. return self.scrollview.content.transform:Find(tostring(levelId))
  359. end
  360. function UIClimbingTowerView:UpdateLevelsData()
  361. self.controller:RefreshTowerDatas()
  362. local loopListView = self.scrollview.loopListView
  363. local length = self.controller:GetShowDataLength()
  364. local curTowerFloorIdx = self.controller:GetCurTowerFloorIdx()
  365. local type = self.controller:GetCurTowerType()
  366. if type == Enum.UnlimitTowerType.PeakTower then
  367. if curTowerFloorIdx < length then
  368. length = math.min(curTowerFloorIdx + 5, length)
  369. if curTowerFloorIdx <= 2 then
  370. curTowerFloorIdx = 1
  371. else
  372. curTowerFloorIdx = curTowerFloorIdx - 1
  373. end
  374. else
  375. curTowerFloorIdx = length - 2
  376. end
  377. self.peakStep = 0
  378. loopListView:SetListItemCount(length, false)
  379. self.scrollview.loopListView:MovePanelToItemIndex(curTowerFloorIdx - 1, 0)
  380. if not self.peakRefreshTimer then
  381. self.peakRefreshTimer = FrameTimer.New(slot(self.RefreshPeakTowerItems, self), 10, 3)
  382. end
  383. if not self.peakRefreshTimer.running then
  384. self.peakRefreshTimer:Start()
  385. end
  386. elseif type == Enum.UnlimitTowerType.ClimbingTower then
  387. if curTowerFloorIdx <= 2 then
  388. curTowerFloorIdx = 1
  389. else
  390. curTowerFloorIdx = curTowerFloorIdx - 1
  391. end
  392. loopListView:SetListItemCount(length, false)
  393. if curTowerFloorIdx > 1 then
  394. loopListView:MovePanelToItemIndex(curTowerFloorIdx - 1, 0)
  395. end
  396. end
  397. self.initedOver = true
  398. -- self.cover.animator:Play("CoverOut")
  399. end
  400. function UIClimbingTowerView:RefreshPeakTowerItems()
  401. self.peakStep = self.peakStep + 1
  402. local length = self.controller:GetShowDataLength()
  403. for i = 1, length do
  404. self:RefreshTopPeakItemByIdx(nil, i)
  405. end
  406. if self.peakStep >= 3 then
  407. self.peakStep = -1
  408. end
  409. end
  410. function UIClimbingTowerView:SetNpcInfo(levelNode,npcImg,natureImg,npc,Level)
  411. --怪物等級為爬塔層數 * 2
  412. levelNode.text.text = tostring(Level * 2)
  413. CommonUtil.LoadIcon(self, npc.npcImg, function (sprite)
  414. npcImg.image.sprite = sprite
  415. npcImg.image:SetNativeSize()
  416. if npc.offset~= nil then
  417. npcImg.rectTransform.anchoredPosition = npc.offset
  418. end
  419. end)
  420. CommonUtil.LoadIcon(self, npc.natureIcon, function (sprite)
  421. natureImg.image.sprite = sprite
  422. end)
  423. end
  424. function UIClimbingTowerView:GetItemByRowColumn(gridView, itemIndex, row, column)
  425. local length = self.controller:GetShowDataLength();
  426. if (itemIndex < 0 or itemIndex >=length) then
  427. return nil
  428. end
  429. local type = self.controller:GetCurTowerType()
  430. if type == Enum.UnlimitTowerType.ClimbingTower then
  431. return self:RefreshClimbingTowerItem(gridView, itemIndex)
  432. elseif type == Enum.UnlimitTowerType.PeakTower then
  433. return self:RefreshPeakTowerItem(gridView, itemIndex)
  434. end
  435. return nil
  436. end
  437. function UIClimbingTowerView:RefreshClimbingTowerItem(gridView, idx)
  438. local levelData = self.controller:GetShowDataByIdx(idx)
  439. local item = gridView:NewListViewItem("ClimbingTowerLevelItem")
  440. local levelLua = CommonUtil.BindGridViewItem2Lua(self, "ClimbingTowerLevelItem", item.gameObject)
  441. levelLua.gameObject.name = levelData.levelId
  442. levelLua.levelNum.text.text = "第"..levelData.levelId.."层"
  443. levelLua.passedNode:SetActive(levelData.hasPassed)
  444. levelLua.challengeBtn:SetActive(levelData.levelId == self.controller:GetCurTowerFloorIdx())
  445. levelLua.friendNode:SetActive(levelData:HasFriend())
  446. levelLua.newLevelNode:SetActive(levelData.levelId > self.controller:GetCurTowerFloorIdx())
  447. levelLua.bottomNode:SetActive(levelData.levelId <= self.controller:GetCurTowerFloorIdx())
  448. if nil ~= levelData.CardUnlock and "" ~= levelData.CardUnlock then
  449. levelLua.unLock.unlocktext.uILocalizeScript:SetContent(levelData.CardUnlock)
  450. levelLua.unLock:SetActive(true)
  451. else
  452. levelLua.unLock:SetActive(false)
  453. end
  454. if levelData.hasPassed then
  455. levelLua.npcList:SetActive(false)
  456. else
  457. levelLua.npcList:SetActive(true)
  458. for i=1, #levelData.npcs do
  459. local npc = levelData.npcs[i]
  460. if npc.npcImg ~= nil then
  461. if i == 1 then
  462. self:SetNpcInfo(levelLua.npcList.npcLevel1,levelLua.npcList.npc1,levelLua.npcList.natureIcon1,npc,levelData.levelId)
  463. elseif i == 2 then
  464. self:SetNpcInfo(levelLua.npcList.npcLevel2,levelLua.npcList.npc2,levelLua.npcList.natureIcon2,npc,levelData.levelId)
  465. elseif i == 3 then
  466. self:SetNpcInfo(levelLua.npcList.npcLevel3,levelLua.npcList.npc3,levelLua.npcList.natureIcon3,npc,levelData.levelId)
  467. elseif i == 4 then
  468. self:SetNpcInfo(levelLua.npcList.npcLevel4,levelLua.npcList.npc4,levelLua.npcList.natureIcon4,npc,levelData.levelId)
  469. end
  470. end
  471. end
  472. end
  473. self:HideAllItems(levelLua)
  474. if levelData.specialReward ~= nil then
  475. for i =1, #levelData.specialReward do
  476. self:SetSpecialData(self:GetItemGo(levelLua,i),levelData.specialReward[i][1],levelData.specialReward[i][2])
  477. end
  478. levelLua.bonusNode:SetActive(true)
  479. else
  480. levelLua.bonusNode:SetActive(false)
  481. end
  482. self.uiBase:AddButtonUniqueEventListener(levelLua.levelInfoBtn.button, self, self.OnClickViewLevelInfo, levelData.levelId)
  483. self.uiBase:AddButtonUniqueEventListener(levelLua.challengeBtn.button, self, self.OnClickChallengeBtn, levelData.levelId)
  484. self.uiBase:AddButtonUniqueEventListener(levelLua.friendNode.button, self, self.OnClickFriendBtn, levelData.levelId)
  485. return item
  486. end
  487. function UIClimbingTowerView:UpdatePeakTowerDataAfterWin(idx)
  488. self.controller:RefreshTowerDatas()
  489. local loopListView = self.scrollview.loopListView
  490. local length = self.controller:GetShowDataLength()
  491. local curTowerFloorIdx = self.controller:GetCurTowerFloorIdx()
  492. local type = self.controller:GetCurTowerType()
  493. if type == Enum.UnlimitTowerType.PeakTower then
  494. if curTowerFloorIdx < length then
  495. length = math.min(curTowerFloorIdx + 5, length)
  496. end
  497. end
  498. self.peakStep = -1
  499. loopListView:SetListItemCount(length, false)
  500. loopListView:RefreshAllShownItem()
  501. end
  502. function UIClimbingTowerView:RefreshPeakTowerItem(gridView, idx)
  503. local showData = self.controller:GetShowDataByIdx(idx)
  504. local item = gridView:NewListViewItem("ClimbingTowerTopItem")
  505. local itemlua = CommonUtil.BindGridViewItem2Lua(self, "ClimbingTowerTopItem", item.gameObject)
  506. local instanceId = item.gameObject:GetInstanceID()
  507. local curTowerFloorIdx = self.controller:GetCurTowerFloorIdx()
  508. local curState = curTowerFloorIdx > showData.floorIdx
  509. local selfUid = ManagerContainer.DataMgr.UserData:GetUserRoleId()
  510. local userData = showData:GetRoleInfo()
  511. local isRobot = userData.isRobot
  512. if not self.scrollItemGoes[instanceId] then
  513. self.scrollItemGoes[instanceId] = itemlua
  514. end
  515. item.gameObject.name = showData.floorIdx
  516. if not userData.inited then
  517. itemlua.playerNode:SetActive(false)
  518. itemlua.challengeBtn:SetActive(false)
  519. itemlua.btnBuy:SetActive(false)
  520. itemlua.rewards:SetActive(false)
  521. itemlua.passedNode:SetActive(false)
  522. itemlua.cover:SetActive(true)
  523. itemlua.btnBuy:SetActive(false)
  524. itemlua.challengeBtn:SetActive(false)
  525. itemlua.levelNum.text.text = I18N.SetLanguageValue("TopTowerLevel", showData.floorIdx)
  526. itemlua.btnMessage:SetActive(false)
  527. return item
  528. end
  529. itemlua.playerNode:SetActive(not curState)
  530. itemlua.challengeBtn:SetActive(not curState)
  531. itemlua.btnBuy:SetActive(not curState)
  532. itemlua.rewards:SetActive(not curState)
  533. itemlua.passedNode:SetActive(curState)
  534. itemlua.nametext.text.text = userData.nickName
  535. itemlua.cover:SetActive(curTowerFloorIdx < showData.floorIdx)
  536. itemlua.btnBuy:SetActive(curTowerFloorIdx == showData.floorIdx)
  537. itemlua.challengeBtn:SetActive(curTowerFloorIdx == showData.floorIdx)
  538. itemlua.levelNum.text.text = I18N.SetLanguageValue("TopTowerLevel", showData.floorIdx)
  539. itemlua.btnMessage:SetActive(not isRobot and selfUid ~= userData.uid)
  540. if self.peakStep == -1 then
  541. self:RefreshTopPeakItemByIdx(itemlua, showData.floorIdx)
  542. end
  543. return item
  544. end
  545. function UIClimbingTowerView:RefreshTopPeakItemByIdx(itemlua, idx)
  546. if not itemlua then
  547. itemlua = self:GetTopPeakItemByIdx(idx)
  548. end
  549. if not itemlua then return end
  550. local showData = self.controller:GetShowDataByIdx(idx - 1)
  551. local instanceId = itemlua.gameObject:GetInstanceID()
  552. if not showData then return end
  553. local heroData = showData:GetRoleHeroData()
  554. local curTowerFloorIdx = self.controller:GetCurTowerFloorIdx()
  555. local curState = curTowerFloorIdx > showData.floorIdx
  556. local userData = showData:GetRoleInfo()
  557. if not curState then
  558. if self.peakStep == -1 or self.peakStep == 2 then
  559. if not self.roleSystemMap[instanceId] then
  560. self.roleSystemMap[instanceId] = RoleViewSystem:new()
  561. end
  562. if not self.previewSystemMap[instanceId] then
  563. self.previewSystemMap[instanceId] = PreviewSystem:new("Preview", 256, 256)
  564. self.previewSystemMap[instanceId]:SetView(Vector3(-0.116, 1.649, 2.5), Quaternion.Euler(12.174, -182.628, 0.085))
  565. end
  566. itemlua.pos:SetActive(true)
  567. local selectZone = userData.selectZone
  568. if selectZone == 0 then
  569. local serverData = ManagerContainer.LuaGameMgr.serverData
  570. selectZone = serverData and serverData.id or 0
  571. end
  572. itemlua.servertext.text.text = I18N.SetLanguageValue("TopTowerServer", selectZone-1)--ManagerContainer.LuaGameMgr.serverData.name--
  573. itemlua.atknum.text.text = userData.fightPower
  574. self.roleSystemMap[instanceId]:CancelCreate()
  575. self.previewSystemMap[instanceId]:RemoveAllGo()
  576. self.roleSystemMap[instanceId]:SetHeroId(instanceId)
  577. self.roleSystemMap[instanceId]:RefreshView(Enum.RoleInEnvType.RoleMainView, userData.roleCfgId, userData.viewData, heroData and heroData.extGoesShowData or nil, self, self.LoadModelCB)
  578. itemlua.roleModel.rawImage.texture = self.previewSystemMap[instanceId]:GetRenderTexture()
  579. end
  580. if self.peakStep == -1 or self.peakStep == 3 then
  581. local loopGridView = itemlua.scrollView.loopGridView
  582. if not self.rewardLoopGridMap[instanceId] then
  583. self.rewardLoopGridMap[instanceId] = loopGridView
  584. end
  585. if not itemlua.initedLoop then
  586. loopGridView:InitGridView(0, function(gridView, itemIndex, row, column)
  587. return self:GetRewardItemByRowColumn(gridView, itemIndex, row, column)
  588. end, nil)
  589. itemlua.initedLoop = true
  590. end
  591. local cfgData = ManagerContainer.CfgMgr:GetTopTowerRewardCfgDataByLv(showData.floorIdx)
  592. self.curPeakTowerItemRewardData = cfgData and cfgData.RewardItems or nil
  593. local rewardLength = cfgData and #cfgData.RewardItems or 0
  594. loopGridView:RefreshListByIndex(rewardLength, 0)
  595. local cost = cfgData and cfgData.BuyRoadCost or nil
  596. itemlua.btnBuy.icon.image.enabled = false
  597. if cost and cost[1] then
  598. local key = cost[1][1]
  599. local val = cost[1][2]
  600. local ownNum = CommonUtil.GetOwnResCountByItemId(key)
  601. local costCfgData = ManagerContainer.CfgMgr:GetItemById(key)
  602. if costCfgData.Icon and costCfgData.Icon ~= '' then
  603. CommonUtil.LoadIcon(self, costCfgData.Icon, function (sprite)
  604. itemlua.btnBuy.icon.image.sprite = sprite
  605. itemlua.btnBuy.icon.image.enabled = true
  606. end, 'ItemIcon'..idx)
  607. end
  608. if ownNum < val then
  609. itemlua.btnBuy.num.text.text = string.format(Constant.PinkColorText, val)
  610. else
  611. itemlua.btnBuy.num.text.text = val
  612. end
  613. self.uiBase:AddButtonUniqueEventListener(itemlua.btnBuy.button, self, self.OnPeakTowerBuyClick, showData.floorIdx, val)
  614. end
  615. self.uiBase:AddButtonUniqueEventListener(itemlua.challengeBtn.button, self, self.OnPeakTowerChallengeClick, showData.floorIdx)
  616. self.uiBase:AddButtonUniqueEventListener(itemlua.btnMessage.button, self, self.OnCheckFightInfo, showData.floorIdx)
  617. end
  618. end
  619. end
  620. function UIClimbingTowerView:LoadModelCB(go, result, instanceId)
  621. if not go then return end
  622. if self.previewSystemMap[instanceId] and go ~= nil then
  623. go.name = instanceId
  624. self.scrollItemGoes[instanceId].pos:SetActive(false)
  625. self.scrollItemGoes[instanceId].roleModel:SetActive(true)
  626. self.previewSystemMap[instanceId]:UpdateGo(go)
  627. end
  628. go:SetActive(true)
  629. end
  630. function UIClimbingTowerView:GetTopPeakItemByIdx(idx)
  631. local item = self.scrollview.loopListView:GetShownItemByItemIndex(idx - 1)
  632. if item then
  633. local itemlua = CommonUtil.GetBindGridViewItem2Lua(self, "ClimbingTowerTopItem", item.gameObject)
  634. return itemlua
  635. end
  636. end
  637. function UIClimbingTowerView:OnPeakTowerBuyClick(button, params)
  638. self.curBuyIdx = params[0]
  639. local data = {"PeakTowerBuyTips", {params[1]}, nil, self, self.ConfirmBuy}
  640. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UINoticeTips, data)
  641. end
  642. function UIClimbingTowerView:ConfirmBuy()
  643. if not self.curBuyIdx then return end
  644. self.controller:SendPeakTowerBuyReq(self.curBuyIdx)
  645. end
  646. function UIClimbingTowerView:OnPeakTowerChallengeClick(button, params)
  647. local floorIdx = params[0]
  648. self.controller:SendChallengeReq(floorIdx)
  649. end
  650. function UIClimbingTowerView:OnCheckFightInfo(button, params)
  651. local idx = params[0]
  652. self.controller:QueryCrossFightInfo(idx)
  653. end
  654. function UIClimbingTowerView:GetRewardItemByRowColumn(gridView, itemIndex, row, column)
  655. if not self.curPeakTowerItemRewardData then
  656. return nil
  657. end
  658. local showData = self.curPeakTowerItemRewardData[itemIndex + 1]
  659. if not showData then
  660. return nil
  661. end
  662. local item = gridView:NewListViewItem("IconSmallItem")
  663. local itemlua = CommonUtil.BindGridViewItem2Lua(self, "IconItem", item.gameObject)
  664. local data = {cfgId = showData[1], num = showData[2]}
  665. IconItemCtr:SetData(self, itemlua, data, Enum.ItemIEnterType.Bag, self, self.OnItemClick)
  666. return item
  667. end
  668. function UIClimbingTowerView:OnItemClick(button,params)
  669. ManagerContainer.LuaUIMgr:OpenTips(params[0])
  670. end
  671. function UIClimbingTowerView:SetSpecialData(itemlua,itemId,itemCnt)
  672. CommonUtil.SetRewardItemData(self,itemId,itemlua,itemCnt, self.OnClickItem)
  673. itemlua:SetActive(true)
  674. end
  675. function UIClimbingTowerView:GetItemGo(levelLua,idx)
  676. if idx == 1 then
  677. return levelLua.bonusNode.items.item1
  678. elseif idx ==2 then
  679. return levelLua.bonusNode.items.item2
  680. else
  681. return levelLua.bonusNode.items.item3
  682. end
  683. end
  684. function UIClimbingTowerView:HideAllItems(levelLua)
  685. for i = 1, 3 do
  686. local go = self:GetItemGo(levelLua,i)
  687. go:SetActive(false)
  688. end
  689. end
  690. function UIClimbingTowerView:OnClickItem(btn,params)
  691. local logicData = params[0]
  692. ManagerContainer.LuaUIMgr:OpenTips(logicData)
  693. end
  694. function UIClimbingTowerView:OnClickClose()
  695. --ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UIMAINVIEW_CHANGE_NOTICE, Enum.MainViewPageType.Town)
  696. ManagerContainer.LuaUIMgr:OpenSourceUI(self)
  697. end
  698. function UIClimbingTowerView:OnDragScrollView()
  699. self.controller:SendFriendPassTowerInfo()
  700. end
  701. function UIClimbingTowerView:OnFightPowerAck(data)
  702. local bIsOpen = true
  703. if self.controller == nil then return end
  704. if nil ~= data.min_tower_info then
  705. --LogError(Inspect(data.min_tower_info))
  706. local info = data.min_tower_info
  707. local levelInfo = self.controller:GetLevelInfo(info.tower_level)
  708. bIsOpen = tonumber(self.lastClickViewInfo) == tonumber(info.tower_level)
  709. if levelInfo ~= nil then
  710. levelInfo:SetLowestPlayerInfo(info.brief,info.fight_power,info.record_time,info.battle_time)
  711. end
  712. end
  713. if bIsOpen then
  714. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIClimbingTowerLevelInfo,self.lastClickViewInfo)
  715. end
  716. end
  717. function UIClimbingTowerView:OnClickViewLevelInfo(btn,param)
  718. local levelId = param[0]
  719. self.lastClickViewInfo = levelId
  720. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_TOWER_LEVEL_MIN_FIGHT_POWER_REQ, {tower_level = levelId})
  721. end
  722. function UIClimbingTowerView:OnClickChallengeBtn(btn,param)
  723. local levelId = param[0]
  724. if levelId ~= self.controller:GetCurTowerFloorIdx() then
  725. return
  726. end
  727. self.controller:EnterBattle(levelId)
  728. end
  729. function UIClimbingTowerView:OnClickFriendBtn(btn,param)
  730. local levelId = param[0]
  731. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIClimbingTowerFriendInfo,levelId)
  732. end
  733. function UIClimbingTowerView:OnClickRank()
  734. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIClimbingTowerRank)
  735. end
  736. function UIClimbingTowerView:OnClickPlayRuleBtn()
  737. local type = self.controller:GetCurTowerType()
  738. if type == Enum.UnlimitTowerType.ClimbingTower then
  739. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPlayRule, {'PlayExplainTitle', 'PracticeTowerPlayExplain'})
  740. elseif type == Enum.UnlimitTowerType.PeakTower then
  741. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPlayRule, {'PlayExplainTitle', 'TopTowerRule'})
  742. end
  743. end
  744. function UIClimbingTowerView:OnClickBtnStatistics()
  745. if LuaBattleBridge.HasStatistics(BattleMode.Time,BattleSubMode.ClimbingTower) then
  746. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIBattleStatistics,{BattleMode.Time,BattleSubMode.ClimbingTower})
  747. else
  748. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("NullBattleInformation2")
  749. end
  750. end
  751. function UIClimbingTowerView:ShowTowerMode()
  752. -- local type = self.controller:GetCurTowerType()
  753. -- if type == Enum.UnlimitTowerType.ClimbingTower then
  754. -- elseif type == Enum.UnlimitTowerType.PeakTower then
  755. -- end
  756. local TDMgr = ManagerContainer.DataMgr.TowerDataMgr
  757. local tmode = TDMgr:GetTowerMode()
  758. self.towerModes:SetActive(true)
  759. self:RefTowerModeBtn(tmode)
  760. end
  761. function UIClimbingTowerView:RefTowerModeBtn(cmode)
  762. local curMode = cmode
  763. local AllMode = {0,1,2} ---0 c 1 P 2 W
  764. -- local emUnlockLevel = GlobalConfig.Instance:GetConfigIntValue(365)
  765. -- local curLevel = ManagerContainer.LuaBattleMgr:GetCurDiffLvID()
  766. -- if(curLevel >= emUnlockLevel)then
  767. -- table.insert(AllMode,2)
  768. -- end
  769. local needShowModeBtn = {}
  770. for _, v in ipairs(AllMode) do
  771. if v ~= curMode then
  772. table.insert(needShowModeBtn,v)
  773. end
  774. end
  775. self.modeNode.loopVerticalScrollRect:ClearCells()
  776. CommonUtil.LoopGridViewEleCreateNew(self,
  777. self.modeNode.loopVerticalScrollRect,
  778. self.content.verticalLayoutGroup,
  779. needShowModeBtn,
  780. 0,
  781. self,
  782. self.UpdateModeNode,
  783. nil, nil, 0);
  784. end
  785. function UIClimbingTowerView:UpdateModeNode(_itemLua, _idx,_data)
  786. if not _itemLua or not _data then return end
  787. CommonUtil.UpdateItemPrefab(self, _itemLua, _data, nil,self,self.OnClickTowerMode)
  788. end
  789. function UIClimbingTowerView:OnClickTowerMode(btn, data)
  790. -- LogError("点击 data = " ..Inspect(data))
  791. local mdata = data[0]
  792. local TDMgr = ManagerContainer.DataMgr.TowerDataMgr
  793. local tmode = TDMgr:GetTowerMode()
  794. if mdata < 2 then
  795. if tmode >= 2 then
  796. local type = self.controller:GetCurTowerType()
  797. if mdata ~= type then
  798. --self.controller:SetCurTowerType(1 - mdata)
  799. self:OnBtnTowerClick()
  800. else
  801. self.cover:SetActive(true)
  802. -- 保护机制 5秒后关闭云
  803. if not self.cloudTimer then
  804. self.cloudTimer = Timer.New(slot(self.CloudOut, self), 1)
  805. end
  806. if not self.cloudTimer.running then
  807. self.cloudTimer:Start()
  808. end
  809. end
  810. else
  811. self:OnBtnTowerClick()
  812. end
  813. else
  814. --self.boardTitle.uILocalizeScript:SetContent("TopTowerTitle")
  815. self.cover:SetActive(true)
  816. -- 保护机制 5秒后关闭云
  817. if not self.cloudTimer then
  818. self.cloudTimer = Timer.New(slot(self.CloudOut, self), 1)
  819. end
  820. if not self.cloudTimer.running then
  821. self.cloudTimer:Start()
  822. end
  823. end
  824. local isWj = mdata == 2
  825. self.scrollview:SetActive(not isWj)
  826. self.wJNode:SetActive(isWj)
  827. if isWj then
  828. local curwjInfo = TDMgr:GetCurWJTowerInfo()
  829. self:RefWJNpcView(curwjInfo.npcList,curwjInfo.lv)
  830. end
  831. self:SetTitle(mdata)
  832. TDMgr:SetTowerMode(mdata)
  833. self.towerModes:SetActive(false)
  834. end
  835. function UIClimbingTowerView:CloseModeNode()
  836. self.towerModes:SetActive(false)
  837. end
  838. function UIClimbingTowerView:RefWJNpcView(npclist,lv)
  839. for i=1, #npclist do
  840. local npc = npclist[i]
  841. if npc.npcImg ~= nil then
  842. if i == 1 then
  843. self:SetNpcInfo(self.wjnpcList.npcLevel1,self.wjnpcList.npc1,self.wjnpcList.natureIcon1,npc,lv)
  844. elseif i == 2 then
  845. self:SetNpcInfo(self.wjnpcList.npcLevel2,self.wjnpcList.npc2,self.wjnpcList.natureIcon2,npc,lv)
  846. elseif i == 3 then
  847. self:SetNpcInfo(self.wjnpcList.npcLevel3,self.wjnpcList.npc3,self.wjnpcList.natureIcon3,npc,lv)
  848. elseif i == 4 then
  849. self:SetNpcInfo(self.wjnpcList.npcLevel4,self.wjnpcList.npc4,self.wjnpcList.natureIcon4,npc,lv)
  850. end
  851. end
  852. end
  853. end
  854. function UIClimbingTowerView:SetTitle(mode)
  855. self.boardTitle.uILocalizeScript:SetContent(self:GetCurTowerTitle(mode))
  856. end
  857. function UIClimbingTowerView:GetCurTowerTitle(mode)
  858. local modeTxt ="TitleClimbingTower"
  859. if(mode == 1) then
  860. modeTxt ="TopTowerTitle"
  861. elseif mode == 2 then
  862. modeTxt ="wjTower"
  863. end
  864. return modeTxt
  865. end
  866. function UIClimbingTowerView:OnClickWJBtn()
  867. ManagerContainer.DataMgr.TowerDataMgr:EnterBattle_WJ(1,{})
  868. end
  869. return UIClimbingTowerView