BattleHeadsBoxPart.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. local BattleHeadsBoxPart = class("BattleHeadsBoxPart")
  2. function BattleHeadsBoxPart:ctor()
  3. end
  4. function BattleHeadsBoxPart:InitGo(host,uiGo)
  5. self.host = host
  6. self.viewLua = CommonUtil.BindGridViewItem2Lua(self.host, "BattleHeadsBox", uiGo)
  7. self:InitPanel()
  8. end
  9. function BattleHeadsBoxPart:InitPanel()
  10. self.buffGoes = {}
  11. for i =1, 8 do
  12. local buffGo = UnityEngine.GameObject.Instantiate(self.viewLua.buffTemp)
  13. buffGo.transform:SetParent(self.viewLua.buffTemp.transform.parent)
  14. buffGo.transform.localScale = Vector3.one
  15. buffGo.transform.localPosition = Vector3.zero
  16. self.buffGoes[#self.buffGoes+1] = buffGo
  17. end
  18. end
  19. function BattleHeadsBoxPart:AddEventListener()
  20. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.EID_Refresh_Fighter_Life,self,self.RefreshFighterLife);
  21. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.EID_Refresh_Fighter_Sp,self,self.RefreshFighterSp);
  22. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.EID_Refresh_Player_Buff,self,self.OnRefreshPlayerBuff);
  23. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.EID_Remove_Player_Buff,self,self.OnRemovePlayerBuff);
  24. end
  25. function BattleHeadsBoxPart:RemoveEventListener()
  26. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.EID_Refresh_Fighter_Life,self,self.RefreshFighterLife);
  27. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.EID_Refresh_Fighter_Sp,self,self.RefreshFighterSp);
  28. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.EID_Refresh_Player_Buff,self,self.OnRefreshPlayerBuff);
  29. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.EID_Remove_Player_Buff,self,self.OnRemovePlayerBuff);
  30. end
  31. function BattleHeadsBoxPart:AddUIEventListener()
  32. end
  33. function BattleHeadsBoxPart:GetSlotSortActor(tbActor)
  34. --伙伴界面排序
  35. local sortedPartnerDatas = ManagerContainer.DataMgr.PartnerData:SortPartnerData()
  36. --根据伙伴界面排序 排序
  37. local sortedData = {}
  38. for j =1, tbActor.Count do--主角第一
  39. local actor = tbActor[j-1]
  40. local UserId = 1
  41. if tostring(UserId)==tostring(actor.ID) then
  42. table.insert(sortedData,actor)
  43. end
  44. end
  45. for i=1, #sortedPartnerDatas do --伙伴排序
  46. local PartnerData = sortedPartnerDatas[i]
  47. for j =1, tbActor.Count do
  48. local actor = tbActor[j-1]
  49. if tostring(PartnerData.id)==tostring(actor.ID) then
  50. table.insert(sortedData,actor)
  51. end
  52. end
  53. end
  54. return sortedData
  55. end
  56. function BattleHeadsBoxPart:Show()
  57. self:HidePlayerNodes()
  58. self:AddEventListener()
  59. self.ourMembers = self:GetSlotSortActor(LuaBattleBridge.GetBattleTeamPlayerActors())
  60. self.actorBuffs = {}
  61. self.actorHeadMapping = {}
  62. for i =1, #self.ourMembers do
  63. local actor = self.ourMembers[i]
  64. local go = self:GetHeadGo(i)
  65. self.actorHeadMapping[tostring(actor.ID)] = go
  66. self.actorBuffs[tostring(actor.ID)] = {}
  67. go.headPosItem:SetActive(false)
  68. self:SetPlayerData(actor.ID,go.headBoxItemNew,actor)
  69. if i == 1 then
  70. self:ShowCurrentSelectPlayerData(actor.ID)
  71. end
  72. end
  73. self.viewLua:SetActive(true)
  74. end
  75. function BattleHeadsBoxPart:ShowCurrentSelectPlayerData(uid)
  76. if self.curSelectedUid ~= uid then
  77. local preHeadGo = self:GetActorHeadGo(self.curSelectedUid)
  78. if preHeadGo ~= nil then
  79. LuaBattleBridge.BeginTweenRecTransformPos(preHeadGo,0.1,Vector3(0,0,0))
  80. end
  81. self.curSelectedUid = uid
  82. local headGo = self:GetActorHeadGo(uid)
  83. local actorData = self:GetActorsById(uid)
  84. if actorData ~= nil then
  85. CommonUtil.LoadIcon(self.host, actorData.ProfessionIcon, function (sprite)
  86. self.viewLua.playerDetailNode.jobIcon.image.sprite = sprite
  87. end)
  88. self.viewLua.playerDetailNode.hpBar.image.fillAmount = headGo.hp.image.fillAmount
  89. self.viewLua.playerDetailNode.spBar.image.fillAmount = headGo.sp.image.fillAmount
  90. self.viewLua.playerDetailNode.playerName.text.text = actorData.Name
  91. CommonUtil.LoadIcon(self.host, actorData.BattleBigIcon, function (sprite)
  92. self.viewLua.playerDetailNode.heroHalf.image.sprite = sprite
  93. end)
  94. local dead = self.viewLua.playerDetailNode.hpBar.image.fillAmount == 0
  95. CommonUtil.NeedUIGray(self.viewLua.playerDetailNode.heroHalf.image, dead)
  96. self.viewLua.playerDetailNode.deadNode:SetActive(dead)
  97. if actorData.HasPet then
  98. self.viewLua.playerDetailNode.petNode:SetActive(true)
  99. CommonUtil.LoadIcon(self.host, actorData.PetIcon, function (sprite)
  100. self.viewLua.playerDetailNode.petNode.petIcon.image.sprite = sprite
  101. end)
  102. CommonUtil.NeedUIGray(self.viewLua.playerDetailNode.petNode.petIcon.image, dead)
  103. else
  104. self.viewLua.playerDetailNode.petNode:SetActive(false)
  105. end
  106. end
  107. LuaBattleBridge.BeginTweenRecTransformPos(headGo,0.1,Vector3(0,15,0))
  108. self:ShowSelectedPlayerBuffInfo(uid)
  109. end
  110. end
  111. function BattleHeadsBoxPart:GetActorsById(uid)
  112. if self.ourMembers == nil then
  113. return nil
  114. end
  115. for i=1, #self.ourMembers do
  116. if self.ourMembers[i].ID == uid then
  117. return self.ourMembers[i]
  118. end
  119. end
  120. return nil
  121. end
  122. function BattleHeadsBoxPart:ShowSelectedPlayerBuffInfo(actorId)
  123. local buffs = self:GetActorBuffInfo(actorId)
  124. for i=1, 8 do
  125. self.buffGoes[i]:SetActive(false)
  126. end
  127. for i =1 , #buffs do
  128. if i > 8 then
  129. return
  130. end
  131. self:LoadBuffIcon(self.buffGoes[i],buffs[i].icon,buffs[i].num,buffs[i].desc)
  132. end
  133. end
  134. function BattleHeadsBoxPart:LoadBuffIcon(buffGo,buffIcon,num,buffDesc)
  135. if buffGo == nil or buffIcon == nil then
  136. return
  137. end
  138. local img = buffGo.transform:Find("Image"):GetComponent(Enum.TypeInfo.Image)
  139. if img == nil then
  140. return
  141. end
  142. local numTxt = buffGo.transform:Find("num"):GetComponent(Enum.TypeInfo.TextMeshProUGUI)
  143. if numTxt ~= nil then
  144. if num > 0 then
  145. numTxt.text = tostring(num)
  146. else
  147. numTxt.text = ""
  148. end
  149. end
  150. local btn = buffGo.transform:GetComponent(Enum.TypeInfo.Button)
  151. if btn ~= nil then
  152. self.host.uiBase:AddButtonUniqueEventListener(btn, self, self.OnClickBuff,buffDesc)
  153. end
  154. CommonUtil.LoadIcon(self.host, buffIcon, function (sprite)
  155. if img ~= nil and sprite ~= nil then
  156. img.sprite = sprite
  157. end
  158. end)
  159. buffGo:SetActive(true)
  160. end
  161. function BattleHeadsBoxPart:OnClickBuff(btn,params)
  162. ManagerContainer.LuaUIMgr:ShowMinTips(params[0])
  163. end
  164. function BattleHeadsBoxPart:SetPlayerData(uid,playerNode,actorData)
  165. CommonUtil.SetPlayerHeadAndFrame(self.host,playerNode.headItem,actorData,true, actorData.HeadFrameId)
  166. self:RefreshFighterLife(uid,actorData.Life,actorData.Life)
  167. self:RefreshFighterSp(uid,actorData.Sp,actorData.Sp)
  168. playerNode.deadNode:SetActive(false)
  169. playerNode:SetActive(true)
  170. playerNode.headItem.head.button.interactable = true
  171. self.host.uiBase:AddButtonUniqueEventListener(playerNode.headItem.head.button, self, self.OnClickPlayer, uid)
  172. end
  173. function BattleHeadsBoxPart:OnClickPlayer(btn,param)
  174. local uid = param[0]
  175. self:ShowCurrentSelectPlayerData(uid)
  176. end
  177. function BattleHeadsBoxPart:RefreshFighterLife(actorId,life,maxLife)
  178. local headGo = self:GetActorHeadGo(actorId)
  179. CommonUtil.SetFighterLife(headGo,life,maxLife)
  180. if tostring(self.curSelectedUid) == tostring(actorId) then
  181. self.viewLua.playerDetailNode.hpBar.image.fillAmount = SDataUtil.InvConvert(life) / SDataUtil.InvConvert(maxLife)
  182. local dead = self.viewLua.playerDetailNode.hpBar.image.fillAmount == 0
  183. CommonUtil.NeedUIGray(self.viewLua.playerDetailNode.petNode.petIcon.image, dead)
  184. CommonUtil.NeedUIGray(self.viewLua.playerDetailNode.heroHalf.image, dead)
  185. self.viewLua.playerDetailNode.deadNode:SetActive(dead)
  186. end
  187. end
  188. function BattleHeadsBoxPart:RefreshFighterSp(actorId,sp,maxSp)
  189. local headGo = self:GetActorHeadGo(actorId)
  190. CommonUtil.SetFighterSp(headGo,sp,maxSp)
  191. if tostring(self.curSelectedUid) == tostring(actorId) then
  192. self.viewLua.playerDetailNode.spBar.image.fillAmount = SDataUtil.InvConvert(sp) / SDataUtil.InvConvert(maxSp)
  193. end
  194. end
  195. function BattleHeadsBoxPart:OnRefreshPlayerBuff(actorId,buffIcon,num)
  196. local buffs = self:GetActorBuffInfo(actorId)
  197. if self:HasBuffIcon(buffs,buffIcon) then
  198. self:RefreshBuffNum(buffs,buffIcon,num)
  199. else
  200. local temps = string.split(buffIcon, '/')
  201. local buffDesc = ""
  202. if temps ~= nil and #temps > 0 then
  203. buffDesc = temps[#temps].."_Desc"
  204. end
  205. buffs[#buffs+1] = {icon=buffIcon,num = num,desc = buffDesc}
  206. end
  207. if tostring(self.curSelectedUid) == tostring(actorId) then
  208. self:ShowSelectedPlayerBuffInfo(actorId)
  209. end
  210. end
  211. function BattleHeadsBoxPart:OnRemovePlayerBuff(actorId,buffIcon)
  212. local buffs = self:GetActorBuffInfo(actorId)
  213. if self:HasBuffIcon(buffs,buffIcon) then
  214. self:RemoveBuffIcon(buffs,buffIcon)
  215. if tostring(self.curSelectedUid) == tostring(actorId) then
  216. self:ShowSelectedPlayerBuffInfo(actorId)
  217. end
  218. end
  219. end
  220. function BattleHeadsBoxPart:RemoveBuffIcon(buffList,buffIcon)
  221. if buffList ~= nil then
  222. for i = 1, #buffList do
  223. if buffList[i].icon == buffIcon then
  224. table.remove(buffList, i)
  225. return
  226. end
  227. end
  228. end
  229. end
  230. function BattleHeadsBoxPart:HasBuffIcon(buffList,buffIcon)
  231. if buffList == nil then
  232. return false
  233. end
  234. for i = 1, #buffList do
  235. if buffList[i].icon == buffIcon then
  236. return true
  237. end
  238. end
  239. return false
  240. end
  241. function BattleHeadsBoxPart:RefreshBuffNum(buffList,buffIcon,num)
  242. if buffList == nil then
  243. return
  244. end
  245. for i = 1, #buffList do
  246. if buffList[i].icon == buffIcon then
  247. buffList[i].num = num
  248. return
  249. end
  250. end
  251. end
  252. function BattleHeadsBoxPart:GetHeadGo(idx)
  253. if idx == 1 then
  254. return self.viewLua.playerNode1
  255. end
  256. if idx == 2 then
  257. return self.viewLua.playerNode2
  258. end
  259. if idx == 3 then
  260. return self.viewLua.playerNode3
  261. end
  262. if idx == 4 then
  263. return self.viewLua.playerNode4
  264. end
  265. return nil
  266. end
  267. function BattleHeadsBoxPart:GetActorHeadGo(actorId)
  268. if self.actorHeadMapping == nil then
  269. return nil
  270. end
  271. if actorId == nil then
  272. return nil
  273. end
  274. return self.actorHeadMapping[tostring(actorId)].headBoxItemNew
  275. end
  276. function BattleHeadsBoxPart:GetActorBuffInfo(actorId)
  277. return self.actorBuffs[tostring(actorId)]
  278. end
  279. function BattleHeadsBoxPart:Hide()
  280. if self.curSelectedUid ~= nil then
  281. local headGo = self:GetActorHeadGo(self.curSelectedUid)
  282. LuaBattleBridge.BeginTweenRecTransformPos(headGo,0.1,Vector3(0,0,0))
  283. self.curSelectedUid = nil
  284. end
  285. self:RemoveEventListener()
  286. self.viewLua:SetActive(false)
  287. self:HidePlayerNodes()
  288. self:Clear()
  289. end
  290. function BattleHeadsBoxPart:HidePlayerNodes()
  291. for i =1, 4 do
  292. local go = self:GetHeadGo(i)
  293. go.headPosItem:SetActive(true)
  294. go.headBoxItemNew:SetActive(false)
  295. go.headBoxItemNew.headItem.head.button.interactable = false
  296. end
  297. end
  298. function BattleHeadsBoxPart:Clear()
  299. self.actorHeadMapping = nil
  300. self.ourMembers = nil
  301. end
  302. function BattleHeadsBoxPart:Dispose()
  303. if self.buffGoes ~= nil then
  304. for i = 1, #self.buffGoes do
  305. CommonUtil.DestroyGO(self.buffGoes[i])
  306. end
  307. self.buffGoes = nil
  308. end
  309. self:Hide()
  310. self.host = nil
  311. self.viewLua = nil
  312. end
  313. return BattleHeadsBoxPart