BattleHeadsBoxPart.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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_DifMode(actorId)
  123. local buffs = self:GetActorBuffInfo(actorId)
  124. for i=1, 8 do
  125. self.buffGoes[i]:SetActive(false)
  126. end
  127. --LogError("=====================困難===Icon==")
  128. local debuffcfg = ManagerContainer.LuaBattleMgr:GetCurLeveDebuffCfg()
  129. local desc = I18N.SetLanguageValue("ic_buff_100011_Desc",-debuffcfg[1][2],-debuffcfg[2][2],-debuffcfg[3][2])
  130. self:LoadBuffIcon(self.buffGoes[1],"buff/ic_buff_018",0,desc)
  131. for i =2 , #buffs do
  132. if i > 8 then
  133. return
  134. end
  135. self:LoadBuffIcon(self.buffGoes[i],buffs[i].icon,buffs[i].num,buffs[i].desc)
  136. end
  137. end
  138. function BattleHeadsBoxPart:ShowSelectedPlayerBuffInfo_Nor(actorId)
  139. local buffs = self:GetActorBuffInfo(actorId)
  140. for i=1, 8 do
  141. self.buffGoes[i]:SetActive(false)
  142. end
  143. for i =1 , #buffs do
  144. if i > 8 then
  145. return
  146. end
  147. self:LoadBuffIcon(self.buffGoes[i],buffs[i].icon,buffs[i].num,buffs[i].desc)
  148. end
  149. end
  150. function BattleHeadsBoxPart:ShowSelectedPlayerBuffInfo(actorId)
  151. --LogError("========================Icon=="..actorId)
  152. -- if ManagerContainer.LuaBattleMgr:GetFightState() and ManagerContainer.LuaBattleMgr:GetBattleMode() == 1 then
  153. -- self:ShowSelectedPlayerBuffInfo_DifMode(actorId)
  154. -- else
  155. -- self:ShowSelectedPlayerBuffInfo_Nor(actorId)
  156. -- end
  157. self:ShowSelectedPlayerBuffInfo_Nor(actorId)
  158. end
  159. function BattleHeadsBoxPart:LoadBuffIcon(buffGo,buffIcon,num,buffDesc)
  160. if buffGo == nil or buffIcon == nil then
  161. return
  162. end
  163. local img = buffGo.transform:Find("Image"):GetComponent(Enum.TypeInfo.Image)
  164. if img == nil then
  165. return
  166. end
  167. local numTxt = buffGo.transform:Find("num"):GetComponent(Enum.TypeInfo.TextMeshProUGUI)
  168. if numTxt ~= nil then
  169. if num > 0 then
  170. numTxt.text = tostring(num)
  171. else
  172. numTxt.text = ""
  173. end
  174. end
  175. local btn = buffGo.transform:GetComponent(Enum.TypeInfo.Button)
  176. if btn ~= nil then
  177. self.host.uiBase:AddButtonUniqueEventListener(btn, self, self.OnClickBuff,buffDesc)
  178. end
  179. CommonUtil.LoadIcon(self.host, buffIcon, function (sprite)
  180. if img ~= nil and sprite ~= nil then
  181. img.sprite = sprite
  182. end
  183. end)
  184. buffGo:SetActive(true)
  185. end
  186. function BattleHeadsBoxPart:OnClickBuff(btn,params)
  187. ManagerContainer.LuaUIMgr:ShowMinTips(params[0])
  188. end
  189. function BattleHeadsBoxPart:SetPlayerData(uid,playerNode,actorData)
  190. CommonUtil.SetPlayerHeadAndFrame(self.host,playerNode.headItem,actorData,true, actorData.HeadFrameId)
  191. self:RefreshFighterLife(uid,actorData.Life,actorData.Life)
  192. self:RefreshFighterSp(uid,actorData.Sp,actorData.Sp)
  193. playerNode.deadNode:SetActive(false)
  194. playerNode:SetActive(true)
  195. playerNode.headItem.head.button.interactable = true
  196. self.host.uiBase:AddButtonUniqueEventListener(playerNode.headItem.head.button, self, self.OnClickPlayer, uid)
  197. end
  198. function BattleHeadsBoxPart:OnClickPlayer(btn,param)
  199. local uid = param[0]
  200. self:ShowCurrentSelectPlayerData(uid)
  201. end
  202. function BattleHeadsBoxPart:RefreshFighterLife(actorId,life,maxLife)
  203. local headGo = self:GetActorHeadGo(actorId)
  204. CommonUtil.SetFighterLife(headGo,life,maxLife)
  205. if tostring(self.curSelectedUid) == tostring(actorId) then
  206. self.viewLua.playerDetailNode.hpBar.image.fillAmount = SDataUtil.InvConvert(life) / SDataUtil.InvConvert(maxLife)
  207. local dead = self.viewLua.playerDetailNode.hpBar.image.fillAmount == 0
  208. CommonUtil.NeedUIGray(self.viewLua.playerDetailNode.petNode.petIcon.image, dead)
  209. CommonUtil.NeedUIGray(self.viewLua.playerDetailNode.heroHalf.image, dead)
  210. self.viewLua.playerDetailNode.deadNode:SetActive(dead)
  211. end
  212. end
  213. function BattleHeadsBoxPart:RefreshFighterSp(actorId,sp,maxSp)
  214. local headGo = self:GetActorHeadGo(actorId)
  215. CommonUtil.SetFighterSp(headGo,sp,maxSp)
  216. if tostring(self.curSelectedUid) == tostring(actorId) then
  217. self.viewLua.playerDetailNode.spBar.image.fillAmount = SDataUtil.InvConvert(sp) / SDataUtil.InvConvert(maxSp)
  218. end
  219. end
  220. function BattleHeadsBoxPart:OnRefreshPlayerBuff(actorId,buffIcon,num)
  221. local buffs = self:GetActorBuffInfo(actorId)
  222. if self:HasBuffIcon(buffs,buffIcon) then
  223. self:RefreshBuffNum(buffs,buffIcon,num)
  224. else
  225. local temps = string.split(buffIcon, '/')
  226. local buffDesc = ""
  227. if temps ~= nil and #temps > 0 then
  228. buffDesc = temps[#temps].."_Desc"
  229. end
  230. buffs[#buffs+1] = {icon=buffIcon,num = num,desc = buffDesc}
  231. end
  232. if tostring(self.curSelectedUid) == tostring(actorId) then
  233. self:ShowSelectedPlayerBuffInfo(actorId)
  234. end
  235. end
  236. function BattleHeadsBoxPart:OnRemovePlayerBuff(actorId,buffIcon)
  237. local buffs = self:GetActorBuffInfo(actorId)
  238. if self:HasBuffIcon(buffs,buffIcon) then
  239. self:RemoveBuffIcon(buffs,buffIcon)
  240. if tostring(self.curSelectedUid) == tostring(actorId) then
  241. self:ShowSelectedPlayerBuffInfo(actorId)
  242. end
  243. end
  244. end
  245. function BattleHeadsBoxPart:RemoveBuffIcon(buffList,buffIcon)
  246. if buffList ~= nil then
  247. for i = 1, #buffList do
  248. if buffList[i].icon == buffIcon then
  249. table.remove(buffList, i)
  250. return
  251. end
  252. end
  253. end
  254. end
  255. function BattleHeadsBoxPart:HasBuffIcon(buffList,buffIcon)
  256. if buffList == nil then
  257. return false
  258. end
  259. for i = 1, #buffList do
  260. if buffList[i].icon == buffIcon then
  261. return true
  262. end
  263. end
  264. return false
  265. end
  266. function BattleHeadsBoxPart:RefreshBuffNum(buffList,buffIcon,num)
  267. if buffList == nil then
  268. return
  269. end
  270. for i = 1, #buffList do
  271. if buffList[i].icon == buffIcon then
  272. buffList[i].num = num
  273. return
  274. end
  275. end
  276. end
  277. function BattleHeadsBoxPart:GetHeadGo(idx)
  278. if idx == 1 then
  279. return self.viewLua.playerNode1
  280. end
  281. if idx == 2 then
  282. return self.viewLua.playerNode2
  283. end
  284. if idx == 3 then
  285. return self.viewLua.playerNode3
  286. end
  287. if idx == 4 then
  288. return self.viewLua.playerNode4
  289. end
  290. return nil
  291. end
  292. function BattleHeadsBoxPart:GetActorHeadGo(actorId)
  293. if self.actorHeadMapping == nil then
  294. return nil
  295. end
  296. if actorId == nil then
  297. return nil
  298. end
  299. return self.actorHeadMapping[tostring(actorId)].headBoxItemNew
  300. end
  301. function BattleHeadsBoxPart:GetActorBuffInfo(actorId)
  302. return self.actorBuffs[tostring(actorId)]
  303. end
  304. function BattleHeadsBoxPart:Hide()
  305. if self.curSelectedUid ~= nil then
  306. local headGo = self:GetActorHeadGo(self.curSelectedUid)
  307. LuaBattleBridge.BeginTweenRecTransformPos(headGo,0.1,Vector3(0,0,0))
  308. self.curSelectedUid = nil
  309. end
  310. self:RemoveEventListener()
  311. self.viewLua:SetActive(false)
  312. self:HidePlayerNodes()
  313. self:Clear()
  314. end
  315. function BattleHeadsBoxPart:HidePlayerNodes()
  316. for i =1, 4 do
  317. local go = self:GetHeadGo(i)
  318. go.headPosItem:SetActive(true)
  319. go.headBoxItemNew:SetActive(false)
  320. go.headBoxItemNew.headItem.head.button.interactable = false
  321. end
  322. end
  323. function BattleHeadsBoxPart:Clear()
  324. self.actorHeadMapping = nil
  325. self.ourMembers = nil
  326. end
  327. function BattleHeadsBoxPart:Dispose()
  328. if self.buffGoes ~= nil then
  329. for i = 1, #self.buffGoes do
  330. CommonUtil.DestroyGO(self.buffGoes[i])
  331. end
  332. self.buffGoes = nil
  333. end
  334. self:Hide()
  335. self.host = nil
  336. self.viewLua = nil
  337. end
  338. return BattleHeadsBoxPart