UIExpeditionArrangeView.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. local UIExpeditionArrangeView = require("UIExpedition/UIExpeditionArrangeView_Generate")
  2. local RoleListItemCtr = require("Common/RoleListItemCtr")
  3. function UIExpeditionArrangeView:OnAwake(data)
  4. self.controller = require("UIExpedition/UIExpeditionArrangeCtr"):new()
  5. self.controller:Init(self)
  6. self.controller:SetData(data)
  7. end
  8. function UIExpeditionArrangeView:AddEventListener()
  9. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name,UIEventNames.EID_Expedition_RefreshData,self,self.RefreshData)
  10. end
  11. function UIExpeditionArrangeView: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 UIExpeditionArrangeView:RemoveEventListener()
  22. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  23. end
  24. function UIExpeditionArrangeView:AddUIEventListener()
  25. self.uiBase:AddButtonEventListener(self.backBtn.button,self, self.OnClickBackBtn)
  26. self.uiBase:AddButtonEventListener(self.helpBtn.button,self, self.OnClickHelpBtn)
  27. self.uiBase:AddButtonEventListener(self.helpLogBtn.button,self, self.OnClickHelpLogBtn)
  28. end
  29. function UIExpeditionArrangeView:OnHide()
  30. end
  31. function UIExpeditionArrangeView:OnShow(data)
  32. self.controller:SetData(data)
  33. end
  34. function UIExpeditionArrangeView:OnClose()
  35. self:DestroyGOes()
  36. for i=1, 6 do
  37. local go = self:GetTeamMemberGo(i)
  38. if go~= nil then
  39. local pos = go.rectTransform.anchoredPosition3D
  40. pos.y = 0
  41. go.rectTransform.anchoredPosition3D = pos
  42. end
  43. end
  44. AvatarRTMgr.Instance:Hide()
  45. end
  46. function UIExpeditionArrangeView:OnDispose()
  47. self.controller:OnDispose()
  48. end
  49. function UIExpeditionArrangeView:Init()
  50. self.instGoes = nil
  51. self.curSelectedUid = 0
  52. self.lastSelectedIdx = 0
  53. self:HideAllSelectedActorGO()
  54. self:LoadOtherUI()
  55. end
  56. function UIExpeditionArrangeView:LoadOtherUI()
  57. self.isLoading = true
  58. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.EID_Expedition_UIPart_Loaded,self,self.OnUIPartLoaded);
  59. local partResPaths = {"UIExpedition/SelectedHeroExp","UIExpedition/PortraitExp"}
  60. local seqId = ManagerContainer.ResMgr:LoadAssetGameObjects(Constants.UIPath, ELoadType.OTHER, function(objs)
  61. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Expedition_UIPart_Loaded,objs)
  62. end, unpack(partResPaths))
  63. end
  64. function UIExpeditionArrangeView:OnUIPartLoaded(objs)
  65. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.EID_Expedition_UIPart_Loaded,self,self.OnUIPartLoaded);
  66. self.instGoes = {}
  67. self.isLoading = false
  68. local selectedPrefab = objs[0]
  69. local rolePrefab = objs[1]
  70. for i=1, 6 do
  71. local memberNode = self:GetTeamMemberGo(i)
  72. local go = UnityEngine.GameObject.Instantiate(rolePrefab)
  73. go:SetActive(true)
  74. local rectTransform = go:GetComponent(Enum.TypeInfo.RectTransform)
  75. rectTransform:SetParent(memberNode.transform, false);
  76. rectTransform.localRotation = Quaternion.identity;
  77. rectTransform.localScale = Vector3(1,1,1);
  78. rectTransform.anchorMin = Vector2 (0, 0);
  79. rectTransform.anchorMax = Vector2(1.0, 1.0);
  80. rectTransform.pivot = Vector2 (0.5, 0.5);
  81. rectTransform.anchoredPosition3D = Vector3(0,0,0);
  82. rectTransform.sizeDelta = Vector2(0,0);
  83. self.instGoes[#self.instGoes+1] = go
  84. memberNode.roleLua = CommonUtil.BindGridViewItem2Lua(self, "PortraitExp", go)
  85. end
  86. for i=1,4 do
  87. local charGo = self:GetBattleActorGo(i)
  88. local go = UnityEngine.GameObject.Instantiate(selectedPrefab)
  89. go:SetActive(true)
  90. local rectTransform = go:GetComponent(Enum.TypeInfo.RectTransform)
  91. rectTransform:SetParent(charGo.transform, false);
  92. rectTransform.localRotation = Quaternion.identity;
  93. rectTransform.localScale = Vector3(1,1,1);
  94. rectTransform.anchorMin = Vector2 (0, 0);
  95. rectTransform.anchorMax = Vector2(1.0, 1.0);
  96. rectTransform.pivot = Vector2 (0.5, 0.5);
  97. rectTransform.anchoredPosition3D = Vector3(0,0,0);
  98. rectTransform.sizeDelta = Vector2(0,0);
  99. self.instGoes[#self.instGoes+1] = go
  100. charGo.heroLua = CommonUtil.BindGridViewItem2Lua(self, "SelectedHeroExp", go)
  101. end
  102. self:SetTeamData()
  103. end
  104. function UIExpeditionArrangeView:HideAllSelectedActorGO()
  105. for i = 1, 4 do
  106. local actorGo = self:GetBattleActorGo(i)
  107. actorGo:SetActive(false)
  108. end
  109. end
  110. function UIExpeditionArrangeView:RefreshData()
  111. local teamDatas = self.controller:GetTeams()
  112. for i = 1, #teamDatas do
  113. local go = self:GetTeamMemberGo(i)
  114. self:SetTeamMemberData(i,go,teamDatas[i])
  115. end
  116. self:ShowBattleHeros()
  117. end
  118. function UIExpeditionArrangeView:ShowBattleHeros()
  119. local battleActorIds = ManagerContainer.DataMgr.ExpeditionDataMgr:GetCurrBattleTeamMembers()
  120. if battleActorIds~= nil then
  121. for i = 1, #battleActorIds do
  122. local actorGo = self:GetBattleActorGo(i)
  123. self:SetBattleHeroData(battleActorIds[i],actorGo)
  124. end
  125. end
  126. self.fighterPowerText.text.text = tostring(ManagerContainer.DataMgr.ExpeditionDataMgr:GetTeamTotalFightPower())
  127. end
  128. function UIExpeditionArrangeView:GetBattleActorGo(idx)
  129. if idx == 1 then
  130. return self.selectedHero1
  131. elseif idx == 2 then
  132. return self.selectedHero2
  133. elseif idx == 3 then
  134. return self.selectedHero3
  135. else
  136. return self.selectedHero4
  137. end
  138. end
  139. function UIExpeditionArrangeView:SetBattleHeroData(uid,node)
  140. local heroData = self.controller:GetHeroData(uid)
  141. if heroData == nil or node == nil then
  142. return
  143. end
  144. local hpPercent,spPercent = ManagerContainer.DataMgr.ExpeditionDataMgr:GetHeroHPAndSP(uid)
  145. node.heroLua.helpNode:SetActive(hpPercent == 0)
  146. if hpPercent == 0 then
  147. AvatarRTMgr.Instance:PlayAnim(uid,"f_Injured")
  148. else
  149. AvatarRTMgr.Instance:PlayAnim(uid,"f_idle")
  150. end
  151. CommonUtil.NeedUIGray(node.heroLua.heroImg.rawImage,hpPercent == 0)
  152. if heroData.mainRole then
  153. node.heroLua.heroName.text.text = ManagerContainer.DataMgr.UserData:GetUserNickname()
  154. else
  155. node.heroLua.heroName.text.text = I18N.T(heroData.cfgData.Name)
  156. end
  157. node.heroLua.heroLv.text.text = tostring(heroData.logicData.baseLevel)
  158. CommonUtil.LoadIcon(self, heroData.cfgData.JobIcon2, function (sprite)
  159. node.heroLua.jobIcon.image.sprite = sprite
  160. end)
  161. node.heroLua.heroImg.rawImage.texture = AvatarRTMgr.Instance:GetActorRT(uid)
  162. node.heroLua.replaceBtn:SetActive(false)
  163. self.uiBase:AddButtonUniqueEventListener(node.heroLua.replaceBtn.button, self, self.OnClickReplaceBtn, uid)
  164. node.heroLua.heroImg:SetActive(true)
  165. node:SetActive(true)
  166. end
  167. function UIExpeditionArrangeView:OnClickReplaceBtn(btn,param)
  168. local uid = param[0]
  169. if self.curSelectedUid ~= uid then
  170. local hpPercent,spPercent = ManagerContainer.DataMgr.ExpeditionDataMgr:GetHeroHPAndSP(self.curSelectedUid)
  171. if hpPercent == 0 then
  172. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("ExpeditionDead")
  173. return
  174. end
  175. ManagerContainer.DataMgr.ExpeditionDataMgr:ReplaceBattleActorId(uid,self.curSelectedUid)
  176. self:ShowBattleHeros()
  177. self:RestorePos(self.curSelectedUid)
  178. self:SetBattleState(self.curSelectedUid)
  179. self:SetBattleState(uid)
  180. self.curSelectedUid = 0
  181. end
  182. end
  183. function UIExpeditionArrangeView:RestorePos(uid)
  184. local idx = self.controller:GetHeroIdx(uid)
  185. local curGo = self:GetTeamMemberGo(idx)
  186. if curGo ~= nil then
  187. local pos = curGo.rectTransform.anchoredPosition3D
  188. pos.y = 0
  189. LuaBattleBridge.BeginTweenRecTransformPos(curGo,0.1,pos)
  190. end
  191. end
  192. function UIExpeditionArrangeView:SetTeamData()
  193. local teamDatas = self.controller:GetTeams()
  194. for i = 1, #teamDatas do
  195. local go = self:GetTeamMemberGo(i)
  196. self:SetTeamMemberData(i,go,teamDatas[i])
  197. end
  198. local ourMembers = {}
  199. for i = 1, #teamDatas do
  200. if teamDatas[i].owned then
  201. local actor = ManagerContainer.LuaActorDataMgr:GetActorsById(teamDatas[i].uid,teamDatas[i].cfgId)
  202. if actor ~= nil then
  203. ourMembers[#ourMembers+1] = actor
  204. end
  205. end
  206. end
  207. AvatarRTMgr.Instance:LoadPreviewActors(ourMembers,self)
  208. end
  209. function UIExpeditionArrangeView:OnLoadCompleted()
  210. self:ShowBattleHeros()
  211. end
  212. function UIExpeditionArrangeView:GetTeamMemberGo(idx)
  213. if idx == 1 then
  214. return self.hero1
  215. elseif idx == 2 then
  216. return self.hero2
  217. elseif idx == 3 then
  218. return self.hero3
  219. elseif idx == 4 then
  220. return self.hero4
  221. elseif idx == 5 then
  222. return self.hero5
  223. elseif idx == 6 then
  224. return self.hero6
  225. end
  226. return nil
  227. end
  228. function UIExpeditionArrangeView:SetTeamMemberData(idx,node,data)
  229. if node == nil or data == nil then
  230. return
  231. end
  232. RoleListItemCtr:SetData(self, node.roleLua.role, {idx, data.logicData, data.cfgData},self,self.OnClickHero)
  233. local _isBattle = ManagerContainer.DataMgr.ExpeditionDataMgr:IsInBattleTeam(data.uid);
  234. node.roleLua.statusNode:SetActive(data.owned)
  235. node.roleLua.selectedNode:SetActive(_isBattle)
  236. node.roleLua.role.labelUp:SetActive(_isBattle)
  237. node.roleLua.role.labelLead:SetActive(false)
  238. local hpPercent,spPercent = ManagerContainer.DataMgr.ExpeditionDataMgr:GetHeroHPAndSP(data.uid)
  239. node.roleLua.hp.image.fillAmount = hpPercent * 0.01
  240. node.roleLua.sp.image.fillAmount = spPercent * 0.01
  241. end
  242. function UIExpeditionArrangeView:OnClickHero(btn,params)
  243. local idx = params[0]
  244. local uid = params[1]
  245. local heroData = self.controller:GetHeroData(uid)
  246. if heroData == nil then
  247. return
  248. end
  249. if heroData.owned == false then
  250. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("ArenaChangePartnerTips2")
  251. return
  252. end
  253. if ManagerContainer.DataMgr.ExpeditionDataMgr:IsInBattleTeam(uid) then
  254. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("ArenaChangePartnerTips1")
  255. return
  256. end
  257. if ManagerContainer.DataMgr.ExpeditionDataMgr:CurMemberCnt() >= 4 then
  258. self:SelectedHero(idx,uid)
  259. else
  260. ManagerContainer.DataMgr.ExpeditionDataMgr:OnBattle(uid)
  261. self:SetBattleState(uid)
  262. self:ShowBattleHeros()
  263. end
  264. end
  265. function UIExpeditionArrangeView:SelectedHero(idx,uid)
  266. if self.lastSelectedIdx ~= idx then
  267. if self.lastSelectedIdx ~= nil then
  268. local go = self:GetTeamMemberGo(self.lastSelectedIdx)
  269. if go ~= nil then
  270. local pos = go.rectTransform.anchoredPosition3D
  271. pos.y = 0
  272. LuaBattleBridge.BeginTweenRecTransformPos(go,0.1,pos)
  273. end
  274. end
  275. local curGo = self:GetTeamMemberGo(idx)
  276. if curGo ~= nil then
  277. local pos = curGo.rectTransform.anchoredPosition3D
  278. pos.y = 30
  279. LuaBattleBridge.BeginTweenRecTransformPos(curGo,0.1,pos)
  280. end
  281. self.curSelectedUid = uid
  282. self.lastSelectedIdx = idx
  283. self:ShowReplaceBtn(true)
  284. else
  285. local curGo = self:GetTeamMemberGo(self.lastSelectedIdx)
  286. if curGo ~= nil then
  287. local pos = curGo.rectTransform.anchoredPosition3D
  288. pos.y = 0
  289. LuaBattleBridge.BeginTweenRecTransformPos(curGo,0.1,pos)
  290. end
  291. self:ShowReplaceBtn(false)
  292. self.lastSelectedIdx = 0
  293. end
  294. end
  295. function UIExpeditionArrangeView:ShowReplaceBtn(vis)
  296. local battleActorIds = ManagerContainer.DataMgr.ExpeditionDataMgr:GetCurrBattleTeamMembers()
  297. if battleActorIds~= nil then
  298. for i = 1, #battleActorIds do
  299. local actorGo = self:GetBattleActorGo(i)
  300. actorGo.heroLua.replaceBtn:SetActive(vis)
  301. end
  302. end
  303. end
  304. function UIExpeditionArrangeView:SetBattleState(uid)
  305. local idx = self.controller:GetHeroIdx(uid)
  306. local go = self:GetTeamMemberGo(idx)
  307. if go == nil then
  308. return
  309. end
  310. local _isBattle = ManagerContainer.DataMgr.ExpeditionDataMgr:IsInBattleTeam(uid);
  311. go.roleLua.role.labelUp:SetActive(_isBattle)
  312. go.roleLua.selectedNode:SetActive(_isBattle)
  313. end
  314. function UIExpeditionArrangeView:OnClickBackBtn()
  315. if AvatarRTMgr.Instance.IsLoading or self.isLoading then
  316. return
  317. end
  318. AvatarRTMgr.Instance:Hide()
  319. self:UIClose()
  320. end
  321. function UIExpeditionArrangeView:OnClickHelpBtn()
  322. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIExpeditionHelp)
  323. end
  324. function UIExpeditionArrangeView:OnClickHelpLogBtn()
  325. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIExpiditionHelpLog)
  326. end
  327. function UIExpeditionArrangeView:DestroyGOes()
  328. if self.instGoes == nil then
  329. return
  330. end
  331. CommonUtil.ClearGridViewItem(self, "PortraitArrange")
  332. CommonUtil.ClearGridViewItem(self, "SelectedHeroArrange")
  333. for i = 1, #self.instGoes do
  334. CommonUtil.DestroyGO(self.instGoes[i])
  335. end
  336. self.instGoes = nil
  337. end
  338. return UIExpeditionArrangeView