UIGuildWarView.lua 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506
  1. local UIGuildWarView = require("UIGuildWar/UIGuildWarView_Generate")
  2. local ColorExtension = require('ColorExtension')
  3. local THRONE_PATHS = {
  4. [1] = {'GuildWarPlace/GuildWar_SpotA1', 'GuildWarPlace/GuildWar_SpotA2', 'GuildWarPlace/GuildWar_SpotA3'},
  5. [2] = {'GuildWarPlace/GuildWar_SpotB1', 'GuildWarPlace/GuildWar_SpotB2', 'GuildWarPlace/GuildWar_SpotB3'},
  6. [3] = {'GuildWarPlace/GuildWar_SpotC1', 'GuildWarPlace/GuildWar_SpotC2', 'GuildWarPlace/GuildWar_SpotC3'}
  7. }
  8. local GUILD_COLOR_ID1 = ColorExtension.HexStringToColor(string.formatbykey('ColorID3'))
  9. local GUILD_COLOR_ID2 = ColorExtension.HexStringToColor(string.formatbykey('ColorID6'))
  10. local GUILD_COLOR_DEFAULT = ColorExtension.HexStringToColor(string.formatbykey('ColorID1'))
  11. local SCROE_INTERVAL = 2
  12. local AREA_INTERVAL = 5
  13. function UIGuildWarView:OnAwake(data)
  14. self.controller = require("UIGuildWar/UIGuildWarCtr"):new()
  15. self.controller:Init(self)
  16. self.controller:SetData(data)
  17. end
  18. function UIGuildWarView:AddEventListener()
  19. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.GUILD_WAR_BATTLE_FIELD_INFO_CHANGED, self, self.OnBattleInfoChanged)
  20. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.GUILD_WAR_BATTLE_SCORE_DATA_CHANGED, self, self.OnScoreDataChanged)
  21. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.GUILD_WAR_BATTLE_AREA_DATA_CHANGED, self, self.OnAreaDataChanged)
  22. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.GUILD_WAR_BATTLE_SELF_DATA_CHANGED, self, self.OnSelfDataChanged)
  23. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.GUILD_WAR_OPEN_STATE_CHANGED, self, self.OnOpenStateChanged)
  24. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.GUILD_WAR_BATTLE_FIELD_ENDED, self, self.OnBattleFieldEnded)
  25. end
  26. function UIGuildWarView:FillContent(data, uiBase)
  27. self.uiBase = uiBase
  28. local gameObject = self.uiBase:GetRoot()
  29. if gameObject ~= nil then
  30. self.gameObject = gameObject
  31. self.transform = gameObject.transform
  32. end
  33. self:InitGenerate(self.transform, data)
  34. self:Init()
  35. end
  36. function UIGuildWarView:Init()
  37. self.controller:InitData()
  38. local initParam = SuperScrollView.LoopGridViewInitParam()
  39. initParam.mSmoothDumpRate = 0.05
  40. self.scrollView.loopGridView.ItemSnapEnable = false
  41. self.scrollView.loopGridView:InitGridView(0, function(gridView, itemIndex, row, column)
  42. return self:GetItemByRowColumn(gridView, itemIndex, row, column)
  43. end, function(gridView, itemIndex, row, column, loopGridViewItem)
  44. self:RecycleItem(gridView, itemIndex, row, column, loopGridViewItem)
  45. end, nil, initParam)
  46. self.isInitGrid = nil
  47. self.alignAreaId = nil
  48. self.isInitScore = nil
  49. self:RefreshPanel()
  50. self:CloseMenu()
  51. local errorCode = self.controller:SendGuildWarInfoReq()
  52. if errorCode ~= 0 then
  53. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  54. end
  55. end
  56. function UIGuildWarView:RemoveEventListener()
  57. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  58. self.scrollView.loopGridView.mOnBeginDragAction = nil
  59. self.scrollView.loopGridView.mOnEndDragAction = nil
  60. self.scrollView.loopGridView.mOnSnapItemFinished = nil
  61. end
  62. function UIGuildWarView:AddUIEventListener()
  63. self.uiBase:AddButtonUniqueEventListener(self.btnBack.button, self, self.OnClickCloseBtn)
  64. self.uiBase:AddButtonUniqueEventListener(self.btnHelp.button, self, self.OnClickHelpBtn)
  65. self.uiBase:AddButtonUniqueEventListener(self.btnLog.button, self, self.OnClickLogBtn)
  66. self.uiBase:AddButtonUniqueEventListener(self.btnRank.button, self, self.OnClickRankBtn)
  67. self.uiBase:AddButtonUniqueEventListener(self.infoPanel.button, self, self.OnClickRankBtn)
  68. self.uiBase:AddToggleUniqueEventListener(self.challenge.toggle.toggle, self, self.OnClickChallengeToggle)
  69. self.uiBase:AddButtonUniqueEventListener(self.challenge.btnAdd.button, self, self.OnClickChallengeAddBtn)
  70. self.uiBase:AddToggleUniqueEventListener(self.reborn.toggle.toggle, self, self.OnClickRebornToggle)
  71. self.uiBase:AddButtonUniqueEventListener(self.reborn.btnAdd.button, self, self.OnClickRebornAddBtn)
  72. self.uiBase:AddButtonUniqueEventListener(self.buffUpBtn.button, self, self.OnClickBuffUpBtn)
  73. self.uiBase:AddButtonUniqueEventListener(self.menu.AnyBtn.button, self, self.OnClickMenuCloseBtn)
  74. self.uiBase:AddButtonUniqueEventListener(self.menu.btnClg.button, self, self.OnClickMenuChallengeBtn)
  75. self.uiBase:AddButtonUniqueEventListener(self.menu.btnInfo.button, self, self.OnClickMenuInfoBtn)
  76. self.uiBase:AddButtonUniqueEventListener(self.btnChat.button, self, self.OpenWorldChat)
  77. self.scrollView.loopGridView.mOnBeginDragAction = function(gridView)
  78. self:OnBeginDragAction(gridView)
  79. end
  80. self.scrollView.loopGridView.mOnEndDragAction = function(gridView)
  81. self:OnEndDragAction(gridView)
  82. end
  83. self.scrollView.loopGridView.mOnSnapItemFinished = function(gridView, gridViewItem)
  84. self:OnSnapItemFinished(gridView, gridViewItem)
  85. end
  86. end
  87. function UIGuildWarView:OpenWorldChat()
  88. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIChat)
  89. end
  90. function UIGuildWarView:OnHide()
  91. if self.scoreTimer then
  92. self.scoreTimer:Stop()
  93. end
  94. if self.areaTimer then
  95. self.areaTimer:Stop()
  96. end
  97. if self.battleTimer then
  98. self.battleTimer:Stop()
  99. end
  100. if self.rebornTimer then
  101. self.rebornTimer:Stop()
  102. end
  103. end
  104. function UIGuildWarView:OnShow(data)
  105. self.controller:SetData(data)
  106. if self.scoreTimer then
  107. self.scoreTimer.func()
  108. end
  109. if self.areaTimer then
  110. self.areaTimer.func()
  111. end
  112. if self.battleTimer then
  113. self.battleTimer.func()
  114. end
  115. if self.rebornTimer then
  116. self.rebornTimer.func()
  117. end
  118. end
  119. function UIGuildWarView:OnClose()
  120. end
  121. function UIGuildWarView:OnDispose()
  122. if self.scoreTimer then
  123. self.scoreTimer:Stop()
  124. self.scoreTimer = nil
  125. end
  126. if self.areaTimer then
  127. self.areaTimer:Stop()
  128. self.areaTimer = nil
  129. end
  130. if self.battleTimer then
  131. self.battleTimer:Stop()
  132. self.battleTimer = nil
  133. end
  134. if self.rebornTimer then
  135. self.rebornTimer:Stop()
  136. self.rebornTimer = nil
  137. end
  138. self.isInitGrid = nil
  139. self.alignAreaId = nil
  140. self.isInitScore = nil
  141. self.scrollView.loopGridView:Dispose()
  142. self:CloseMenu()
  143. self:DisposeRawItemLua()
  144. self:DisposeAreaItemLua()
  145. self.controller:OnDispose()
  146. end
  147. function UIGuildWarView:OnBattleInfoChanged(battleIdxChanged)
  148. if battleIdxChanged then
  149. self.controller:ResetBattleIdx()
  150. self:CloseMenu()
  151. self.isInitScore = nil
  152. end
  153. self:RefreshPanel()
  154. end
  155. function UIGuildWarView:OnScoreDataChanged()
  156. self:RefreshScore()
  157. end
  158. function UIGuildWarView:OnAreaDataChanged(areaChangeIds)
  159. if not self.isInitGrid then
  160. self:RefreshArea()
  161. return
  162. end
  163. if not areaChangeIds then
  164. return
  165. end
  166. for _, id in pairs(areaChangeIds) do
  167. self:RefreshItemLua(id)
  168. if self.curSelectAreaId == id then
  169. self:OpenMenu(self.curSelectAreaId)
  170. end
  171. end
  172. end
  173. function UIGuildWarView:OnSelfDataChanged()
  174. self:RefreshFunPanel()
  175. end
  176. function UIGuildWarView:OnOpenStateChanged(isOpen)
  177. if isOpen then return end
  178. if ManagerContainer.LuaUIMgr:HasOpenPage(Enum.UIPageName.UIChat) then
  179. ManagerContainer.LuaUIMgr:ClosePage(Enum.UIPageName.UIChat)
  180. end
  181. self:UIClose()
  182. end
  183. function UIGuildWarView:OnBattleFieldEnded(battleIdx)
  184. local battleFieldData = self.controller:GetBattleFieldData()
  185. if not battleFieldData then
  186. return
  187. end
  188. if battleFieldData.id ~= battleIdx then
  189. return
  190. end
  191. if ManagerContainer.LuaUIMgr:HasOpenPage(Enum.UIPageName.UIChat) then
  192. ManagerContainer.LuaUIMgr:ClosePage(Enum.UIPageName.UIChat, true)
  193. end
  194. if ManagerContainer.LuaUIMgr:HasOpenPage(Enum.UIPageName.UIGuildWarRank) then
  195. return
  196. end
  197. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIGuildWarRank, battleIdx)
  198. if battleFieldData.isFinish then
  199. if self.battleTimer then
  200. if self.battleTimer.running then
  201. self.battleTimer:Stop()
  202. end
  203. end
  204. self.endTimerTxt.text.text = string.formatbykey('GuildWarBattle20')
  205. end
  206. end
  207. function UIGuildWarView:OnClickCloseBtn()
  208. self:UIClose()
  209. if self.uiBase.MSourceUIID > 0 then
  210. ManagerContainer.LuaUIMgr:Open(self.uiBase.MSourceUIID, nil, nil, false)
  211. end
  212. end
  213. function UIGuildWarView:OnClickHelpBtn()
  214. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPlayRule, {'PlayExplainTitle', 'GuildWarBattleText'})
  215. end
  216. function UIGuildWarView:OnClickLogBtn()
  217. local battleFieldData = self.controller:GetBattleFieldData()
  218. if not battleFieldData then
  219. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('GuildWarBattle10')
  220. return
  221. end
  222. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIGuildWarLog, battleFieldData.id)
  223. end
  224. function UIGuildWarView:OnClickRankBtn()
  225. local battleFieldData = self.controller:GetBattleFieldData()
  226. if not battleFieldData then
  227. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('GuildWarBattle10')
  228. return
  229. end
  230. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIGuildWarRank, battleFieldData.id)
  231. end
  232. function UIGuildWarView:SureAutoBuyChallengeNum(isOn)
  233. if not self:IsBattleMy() then
  234. return
  235. end
  236. local errorCode, costCfgId = self.controller:SendGuildWarSettingReq(isOn)
  237. if errorCode ~= 0 then
  238. if errorCode == 1 then
  239. CommonUtil.ItemNotEnoughHandle(costCfgId, Enum.UIPageName.UIGuildWar)
  240. else
  241. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  242. end
  243. end
  244. end
  245. function UIGuildWarView:OnClickChallengeToggle(toggle, _, isOn)
  246. local battleFieldData = self.controller:GetBattleFieldData()
  247. if not self:IsBattleMy() then
  248. toggle.isOn = battleFieldData.autoChallenge
  249. return
  250. end
  251. if battleFieldData.autoChallenge == isOn then
  252. return
  253. end
  254. toggle.isOn = battleFieldData.autoChallenge
  255. if not isOn then
  256. self:SureAutoBuyChallengeNum(false)
  257. return
  258. end
  259. local costCfgId, costNum = self.controller:GetBuyChallengeCountCost()
  260. local ownNum = self.controller:GetOwnResCountByItemId(costCfgId)
  261. if ownNum < costNum then
  262. CommonUtil.ItemNotEnoughHandle(costCfgId, Enum.UIPageName.UIGuildWar)
  263. return
  264. end
  265. local itemName = tostring(costNum)
  266. local cfgData = ManagerContainer.CfgMgr:GetItemById(costCfgId)
  267. if cfgData then
  268. itemName = itemName .. string.formatbykey(cfgData.Name)
  269. end
  270. local data = {"GuildWarAutoChangllengeTip", {itemName}, isOn, self, self.SureAutoBuyChallengeNum}
  271. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UINoticeTips, data)
  272. end
  273. function UIGuildWarView:SureBuyChallengeNum()
  274. if not self:IsBattleMy() then
  275. return
  276. end
  277. local errorCode, costCfgId = self.controller:SendGuildWarBuyChallengeNumReq()
  278. if errorCode ~= 0 then
  279. if errorCode == 1 then
  280. CommonUtil.ItemNotEnoughHandle(costCfgId, Enum.UIPageName.UIGuildWar)
  281. else
  282. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  283. end
  284. end
  285. end
  286. function UIGuildWarView:OnClickChallengeAddBtn()
  287. if not self:IsBattleMy() then
  288. return
  289. end
  290. local costCfgId, costNum = self.controller:GetBuyChallengeCountCost()
  291. local ownNum = self.controller:GetOwnResCountByItemId(costCfgId)
  292. if ownNum < costNum then
  293. CommonUtil.ItemNotEnoughHandle(costCfgId, Enum.UIPageName.UIGuildWar)
  294. return
  295. end
  296. local itemName = tostring(costNum)
  297. local cfgData = ManagerContainer.CfgMgr:GetItemById(costCfgId)
  298. if cfgData then
  299. itemName = itemName .. string.formatbykey(cfgData.Name)
  300. end
  301. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIDojoBuyTimes, {costNum, nil, self.SureBuyChallengeNum, self})
  302. end
  303. function UIGuildWarView:SureAutoBuyReborn(isOn)
  304. if not self:IsBattleMy() then
  305. return
  306. end
  307. local errorCode, costCfgId = self.controller:SendGuildWarSettingReq(nil, isOn)
  308. if errorCode ~= 0 then
  309. if errorCode == 1 then
  310. CommonUtil.ItemNotEnoughHandle(costCfgId, Enum.UIPageName.UIGuildWar)
  311. else
  312. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  313. end
  314. end
  315. end
  316. function UIGuildWarView:OnClickRebornToggle(toggle, _, isOn)
  317. local battleFieldData = self.controller:GetBattleFieldData()
  318. if not self:IsBattleMy() then
  319. toggle.isOn = battleFieldData.autoReborn
  320. return
  321. end
  322. if battleFieldData.autoReborn == isOn then
  323. return
  324. end
  325. toggle.isOn = battleFieldData.autoReborn
  326. if not isOn then
  327. self:SureAutoBuyReborn(false)
  328. return
  329. end
  330. local costCfgId, costNum = self.controller:GetBuyRebornCost()
  331. local ownNum = self.controller:GetOwnResCountByItemId(costCfgId)
  332. if ownNum < costNum then
  333. CommonUtil.ItemNotEnoughHandle(costCfgId, Enum.UIPageName.UIGuildWar)
  334. return
  335. end
  336. local itemName = tostring(costNum)
  337. local cfgData = ManagerContainer.CfgMgr:GetItemById(costCfgId)
  338. if cfgData then
  339. itemName = itemName .. string.formatbykey(cfgData.Name)
  340. end
  341. local data = {"GuildWarAutoRebornTip", {itemName}, isOn, self, self.SureAutoBuyReborn}
  342. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UINoticeTips, data)
  343. end
  344. function UIGuildWarView:SureBuyReborn()
  345. if not self:IsBattlingMy() then
  346. return
  347. end
  348. local errorCode, costCfgId = self.controller:SendGuildWarBuyRebornReq()
  349. if errorCode ~= 0 then
  350. if errorCode == 1 then
  351. CommonUtil.ItemNotEnoughHandle(costCfgId, Enum.UIPageName.UIGuildWar)
  352. else
  353. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  354. end
  355. end
  356. end
  357. function UIGuildWarView:OnClickRebornAddBtn()
  358. if not self:IsBattlingMy() then
  359. return
  360. end
  361. local costCfgId, costNum = self.controller:GetBuyRebornCost()
  362. local ownNum = self.controller:GetOwnResCountByItemId(costCfgId)
  363. if ownNum < costNum then
  364. CommonUtil.ItemNotEnoughHandle(costCfgId, Enum.UIPageName.UIGuildWar)
  365. return
  366. end
  367. local itemName = tostring(costNum)
  368. local cfgData = ManagerContainer.CfgMgr:GetItemById(costCfgId)
  369. if cfgData then
  370. itemName = itemName .. string.formatbykey(cfgData.Name)
  371. end
  372. local data = {"GuildWarBuyRebornTip", {itemName}, nil, self, self.SureBuyReborn}
  373. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UINoticeTips, data)
  374. end
  375. function UIGuildWarView:OnClickBuffUpBtn()
  376. if not self:IsBattleMy() then
  377. return
  378. end
  379. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIGuildWarBuff)
  380. end
  381. function UIGuildWarView:OnClickAreaSlotItem(btn, params)
  382. if not self:IsBattlingMy() then
  383. return
  384. end
  385. local itemLua = params[0]
  386. if not itemLua then return end
  387. if self.curSelectAreaItemLua == itemLua then return end
  388. local areaId = itemLua.areaId
  389. local areaData = self.controller:GetAreaDataById(areaId)
  390. if not areaData or not areaData:IsValidData() then
  391. -- ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('GuildWarBattle10')
  392. return
  393. end
  394. if not areaData:IsPeopleOccupy() then
  395. self:CloseMenu()
  396. if not self:IsBattlingMy() then
  397. return
  398. end
  399. local errorCode = self.controller:SendGuildWarChallengeReq(areaId)
  400. if errorCode ~= 0 then
  401. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  402. end
  403. return
  404. end
  405. if self.controller:IsSelfArea(areaId) then
  406. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('GuildWarBattle8')
  407. return
  408. end
  409. if self.controller:IsSameGuildArea(areaId) then
  410. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('GuildWarBattle9')
  411. return
  412. end
  413. self:LocationAndOpenMenu(areaId)
  414. end
  415. function UIGuildWarView:OnBeginDragAction(gridView)
  416. gridView.ItemSnapEnable = false
  417. self.alignAreaId = nil
  418. self:StopRefreshArea()
  419. -- self:CloseSlogan()
  420. end
  421. function UIGuildWarView:OnEndDragAction(gridView)
  422. gridView.ItemSnapEnable = false
  423. self.alignAreaId = nil
  424. self:StartRefreshArea(true)
  425. -- self:OpenSlogan()
  426. end
  427. function UIGuildWarView:OnSnapItemFinished(gridView, gridViewItem)
  428. gridView.ItemSnapEnable = false
  429. self:StartRefreshArea(true)
  430. if not self.alignAreaId then return end
  431. local itemIdx, idx = self.controller:GetRawIdxByAreaId(self.alignAreaId)
  432. if itemIdx == 0
  433. or itemIdx == gridViewItem.ItemIndex
  434. or (itemIdx + 1) == self.controller:GetRawCount() then
  435. self:OpenMenu(self.alignAreaId)
  436. end
  437. self.alignAreaId = nil
  438. -- self:OpenSlogan()
  439. end
  440. function UIGuildWarView:RefreshPanel()
  441. self:RefreshInfoPanel()
  442. self:RefreshFunPanel()
  443. end
  444. function UIGuildWarView:RefreshInfoPanel()
  445. if self.battleTimer and self.battleTimer.running then
  446. self.battleTimer:Stop()
  447. end
  448. self:RefreshScore()
  449. self:RefreshArea()
  450. local battleFieldData = self.controller:GetBattleFieldData()
  451. if not battleFieldData then
  452. self.btnLog:SetActive(false)
  453. self.btnRank:SetActive(false)
  454. self.guildInfo:SetActive(false)
  455. self.beforeBattle:SetActive(false)
  456. self.battle:SetActive(false)
  457. self.infoPanel:SetActive(false)
  458. self:StopRefreshScore()
  459. self:StopRefreshArea()
  460. return
  461. end
  462. self.infoPanel:SetActive(true)
  463. self.guildInfo:SetActive(true)
  464. self.guildNameTxt1.text.text = string.formatbykey('GuildWarBattle5', battleFieldData.guildName1)
  465. self.guildNameTxt2.text.text = string.formatbykey('GuildWarBattle7', battleFieldData.guildName2)
  466. self:RefreshBadgeImg(self.guildBadgeImg1.image, battleFieldData.guildBadge1)
  467. self:RefreshBadgeImg(self.guildBadgeImg2.image, battleFieldData.guildBadge2)
  468. self.btnLog:SetActive(true)
  469. self.btnRank:SetActive(true)
  470. local serverTime = ManagerContainer.LuaTimerMgr:CurLuaServerTime()
  471. local remainTime = 0
  472. if battleFieldData.startTime then
  473. remainTime = battleFieldData.startTime - serverTime
  474. end
  475. if remainTime > 0 then
  476. self.beforeBattle:SetActive(true)
  477. local langKey = nil
  478. if battleFieldData.id >= 4 then
  479. langKey = 'GuildWarBattle1'
  480. elseif battleFieldData.id >= 2 then
  481. langKey = 'GuildWarBattle2'
  482. elseif battleFieldData.id >= 1 then
  483. langKey = 'GuildWarBattle3'
  484. end
  485. self.battleTxt.text.text = langKey and string.formatbykey(langKey) or ''
  486. self.battle:SetActive(false)
  487. self:StopRefreshScore()
  488. self:StopRefreshArea()
  489. else
  490. if battleFieldData.endTime then
  491. remainTime = battleFieldData.endTime - serverTime
  492. end
  493. self.beforeBattle:SetActive(false)
  494. self.battle:SetActive(true)
  495. if remainTime > 0 then
  496. self:StartRefreshScore()
  497. self:StartRefreshArea()
  498. else
  499. self:StopRefreshScore()
  500. self:StopRefreshArea()
  501. end
  502. end
  503. self:RefreshBattleTimer(true)
  504. end
  505. function UIGuildWarView:RefreshBattleTimer(reset)
  506. local battleFieldData = self.controller:GetBattleFieldData()
  507. if not battleFieldData or battleFieldData.isFinish then
  508. if self.battleTimer and self.battleTimer.running then
  509. self.battleTimer:Stop()
  510. end
  511. return
  512. end
  513. local serverTime = ManagerContainer.LuaTimerMgr:CurLuaServerTime()
  514. local remainTime = nil
  515. local isStart = nil
  516. if reset or not self.battleTimer then
  517. isStart = true
  518. if battleFieldData.startTime then
  519. remainTime = battleFieldData.startTime - serverTime
  520. end
  521. if not remainTime or remainTime <= 0 then
  522. isStart = false
  523. if battleFieldData.endTime then
  524. remainTime = battleFieldData.endTime - serverTime
  525. end
  526. end
  527. else
  528. isStart = self.battleTimer.isStart
  529. if isStart then
  530. if battleFieldData.startTime then
  531. remainTime = battleFieldData.startTime - serverTime
  532. end
  533. else
  534. if battleFieldData.endTime then
  535. remainTime = battleFieldData.endTime - serverTime
  536. end
  537. end
  538. end
  539. if remainTime and remainTime > 0 then
  540. remainTime = remainTime / 1000
  541. if type(remainTime) == 'userdata' then
  542. remainTime = #remainTime
  543. end
  544. if remainTime <= 0 then
  545. remainTime = 1
  546. end
  547. else
  548. remainTime = 0
  549. end
  550. if isStart then
  551. self.beginTimerTxt.text.text = string.formatbykey('GuildWarBattle4', DateTimeUtil.convertSeconds2TimeStr1(remainTime, true, true, true))
  552. else
  553. self.endTimerTxt.text.text = string.formatbykey('GuildWarBattle15', DateTimeUtil.convertSeconds2TimeStr1(remainTime, true, true, true))
  554. end
  555. if not remainTime or remainTime <= 0 then
  556. if self.battleTimer then
  557. if self.battleTimer.running then
  558. self.battleTimer:Stop()
  559. end
  560. if isStart then
  561. self:RefreshInfoPanel()
  562. else
  563. self:OnBattleFieldEnded(battleFieldData.id)
  564. end
  565. end
  566. else
  567. local validTime = nil
  568. if remainTime >= 86400 then
  569. validTime = remainTime % 3600
  570. if validTime == 0 then validTime = 3600 end
  571. elseif remainTime >= 3600 then
  572. validTime = remainTime % 60
  573. if validTime == 0 then validTime = 60 end
  574. else
  575. validTime = 1
  576. end
  577. if validTime then
  578. if not self.battleTimer then
  579. self.battleTimer = Timer.New(slot(self.RefreshBattleTimer, self), validTime, -1)
  580. else
  581. self.battleTimer.duration = validTime
  582. end
  583. self.battleTimer.isStart = isStart
  584. if not self.battleTimer.running then
  585. self.battleTimer:Start()
  586. end
  587. else
  588. if self.battleTimer then
  589. if self.battleTimer.running then
  590. self.battleTimer:Stop()
  591. end
  592. if isStart then
  593. self:RefreshInfoPanel()
  594. else
  595. self:OnBattleFieldEnded(battleFieldData.id)
  596. end
  597. end
  598. end
  599. end
  600. end
  601. function UIGuildWarView:RefreshBadgeImg(image, badge)
  602. if not image or not badge then return end
  603. local badgeCfgData = ManagerContainer.CfgMgr:GetGuildBadgeCfgById(badge)
  604. if not badgeCfgData then return end
  605. image.enabled = false
  606. image.sprite = nil
  607. CommonUtil.LoadIcon(self, badgeCfgData.Pic, function (sprite)
  608. if sprite then
  609. image.sprite = sprite
  610. image.enabled = true
  611. end
  612. end)
  613. end
  614. function UIGuildWarView:RefreshFunPanel()
  615. local battleFieldData = self.controller:GetBattleFieldData()
  616. if not battleFieldData or not battleFieldData:IsBattlingMy() then
  617. self.funPanel:SetActive(false)
  618. if self.rebornTimer and self.rebornTimer.running then
  619. self.rebornTimer:Stop()
  620. end
  621. else
  622. self.funPanel:SetActive(true)
  623. self.challenge.toggle.toggle.isOn = battleFieldData.autoChallenge
  624. self.challenge.text.text.text = string.formatbykey('ChallengeTimes', battleFieldData.challengeNum and tostring(battleFieldData.challengeNum) or '0')
  625. self.reborn.toggle.toggle.isOn = battleFieldData.autoReborn
  626. self:RefreshRebornTimer()
  627. local buffDic = battleFieldData.buffDic
  628. if buffDic then
  629. self:RefreshBuffItem(self.buff1, 1, buffDic[1])
  630. self:RefreshBuffItem(self.buff2, 2, buffDic[2])
  631. else
  632. self:RefreshBuffItem(self.buff1, 1)
  633. self:RefreshBuffItem(self.buff2, 2)
  634. end
  635. end
  636. end
  637. function UIGuildWarView:RefreshRebornTimer()
  638. local battleFieldData = self.controller:GetBattleFieldData()
  639. if not battleFieldData or not battleFieldData:IsBattlingMy() then
  640. if self.rebornTimer and self.rebornTimer.running then
  641. self.rebornTimer:Stop()
  642. end
  643. self.reborn.times:SetActive(false)
  644. self:RefreshFunPanel()
  645. return
  646. end
  647. if battleFieldData.rebornTime and battleFieldData.rebornTime >= 0 then
  648. local remainTime = battleFieldData.rebornTime - ManagerContainer.LuaTimerMgr:CurLuaServerTime()
  649. if remainTime > 0 then
  650. if type(remainTime) == 'userdata' then
  651. remainTime = #remainTime
  652. end
  653. remainTime = remainTime / 1000
  654. local rebornMaxTime = self.controller:GetRebornMaxTime()
  655. self.reborn.times:SetActive(true)
  656. if remainTime >= 3.5 then
  657. self.reborn.times.canvasGroup.alpha = 1
  658. elseif remainTime >= 3 then
  659. self.reborn.times.canvasGroup.alpha = (remainTime - 3) * 2
  660. elseif remainTime >= 2.5 then
  661. self.reborn.times.canvasGroup.alpha = (3 - remainTime) * 2
  662. elseif remainTime >= 2 then
  663. self.reborn.times.canvasGroup.alpha = (remainTime - 2) * 2
  664. elseif remainTime >= 1.5 then
  665. self.reborn.times.canvasGroup.alpha = (2 - remainTime) * 2
  666. elseif remainTime >= 1 then
  667. self.reborn.times.canvasGroup.alpha = (remainTime - 1) * 2
  668. elseif remainTime >= 0.5 then
  669. self.reborn.times.canvasGroup.alpha = (1 - remainTime) * 2
  670. else
  671. self.reborn.times.canvasGroup.alpha = remainTime * 2
  672. end
  673. self.reborn.text.text.text = string.formatbykey('ReviveCountDown', DateTimeUtil.convertSeconds2TimeStr1(remainTime, false, true, false))
  674. self.reborn.slider.value = Mathf.Clamp01(remainTime / rebornMaxTime)
  675. if not self.rebornTimer then
  676. self.rebornTimer = FrameTimer.New(slot(self.RefreshRebornTimer, self), 1, -1)
  677. end
  678. if not self.rebornTimer.running then
  679. self.rebornTimer:Start()
  680. end
  681. return
  682. end
  683. end
  684. if self.rebornTimer and self.rebornTimer.running then
  685. self.rebornTimer:Stop()
  686. end
  687. self.reborn.times:SetActive(false)
  688. end
  689. function UIGuildWarView:RefreshBuffItem(buffLua, cfgId, lv)
  690. if not buffLua then return end
  691. buffLua.icon.image.enabled = false
  692. buffLua.icon.image.sprite = nil
  693. if cfgId then
  694. local cfgData = ManagerContainer.CfgMgr:GetGuildWarBuffCfgById(cfgId)
  695. if cfgData then
  696. CommonUtil.LoadIcon(self, cfgData.Icon, function (sprite)
  697. if sprite then
  698. buffLua.icon.image.sprite = sprite
  699. buffLua.icon.image.enabled = true
  700. end
  701. end)
  702. end
  703. end
  704. buffLua.level.text.text = lv and tostring(lv) or '0'
  705. end
  706. function UIGuildWarView:StartRefreshScore()
  707. if not self.scoreTimer then
  708. self.scoreTimer = Timer.New(slot(self.RefreshScoreTimer, self), SCROE_INTERVAL, -1)
  709. end
  710. if not self.scoreTimer.running then
  711. self.scoreTimer:Start()
  712. end
  713. if not self.scoreTimer.lastUpdateTime then
  714. self:RefreshScoreTimer()
  715. else
  716. local remainTime = (ManagerContainer.LuaTimerMgr:CurLuaServerTime() - self.scoreTimer.lastUpdateTime)
  717. if remainTime > 0 then
  718. remainTime = remainTime / 1000
  719. if type(remainTime) == 'userdata' then
  720. remainTime = #remainTime
  721. end
  722. self.scoreTimer.time = remainTime
  723. else
  724. self:RefreshScoreTimer()
  725. end
  726. end
  727. end
  728. function UIGuildWarView:StopRefreshScore()
  729. if self.scoreTimer and self.scoreTimer.running then
  730. self.scoreTimer:Stop()
  731. end
  732. end
  733. function UIGuildWarView:RefreshScoreTimer()
  734. local battleFieldData = self.controller:GetBattleFieldData()
  735. if not battleFieldData then
  736. self:StopRefreshScore()
  737. return
  738. end
  739. if battleFieldData.isFinish then
  740. self:StopRefreshScore()
  741. return
  742. end
  743. local serverTime = ManagerContainer.LuaTimerMgr:CurLuaServerTime()
  744. if not battleFieldData.startTime or battleFieldData.startTime > serverTime then
  745. self:StopRefreshScore()
  746. return
  747. end
  748. if not battleFieldData.endTime or battleFieldData.endTime < serverTime then
  749. self:StopRefreshScore()
  750. return
  751. end
  752. self.scoreTimer.lastUpdateTime = serverTime
  753. self.controller:SendGuildWarScoreDataReq()
  754. end
  755. function UIGuildWarView:RefreshScore()
  756. local dojoName = string.formatbykey('GuildWarBattle14')
  757. local battleFieldData = self.controller:GetBattleFieldData()
  758. if not battleFieldData then
  759. self.scoreSlider.slider:DOValue(0.5, 0)
  760. self.scoreTxt1.text.text = '0'
  761. self.scoreTxt2.text.text = '0'
  762. self.dojoNumTxt1.text.text = '0' .. tostring(dojoName)
  763. self.dojoNumTxt2.text.text = '0' .. tostring(dojoName)
  764. return
  765. end
  766. local time = SCROE_INTERVAL
  767. if not self.isInitScore then
  768. time = 0
  769. self.isInitScore = true
  770. end
  771. local score1 = battleFieldData.guildScore1
  772. if not score1 or score1 <= 0 then score1 = 0 end
  773. local score2 = battleFieldData.guildScore2
  774. if not score2 or score2 <= 0 then score2 = 0 end
  775. local score = score1 + score2
  776. if score <= 0 then
  777. self.scoreSlider.slider:DOValue(0.5, time)
  778. else
  779. self.scoreSlider.slider:DOValue(score2 / score, time)
  780. end
  781. self.scoreTxt1.text.text = tostring(score1)
  782. self.scoreTxt2.text.text = tostring(score2)
  783. local occupy1 = battleFieldData.guildOccupy1
  784. if not occupy1 or occupy1 <= 0 then occupy1 = 0 end
  785. local occupy2 = battleFieldData.guildOccupy2
  786. if not occupy2 or occupy2 <= 0 then occupy2 = 0 end
  787. self.dojoNumTxt1.text.text = tostring(occupy1) .. tostring(dojoName)
  788. self.dojoNumTxt2.text.text = tostring(occupy2) .. tostring(dojoName)
  789. end
  790. function UIGuildWarView:StartRefreshArea(forceUpdate)
  791. if not self.areaTimer then
  792. self.areaTimer = Timer.New(slot(self.RefreshAreaTimer, self), AREA_INTERVAL, -1)
  793. end
  794. if forceUpdate then
  795. local battleFieldData = self.controller:GetBattleFieldData()
  796. if not battleFieldData then
  797. return
  798. end
  799. if battleFieldData.isFinish then
  800. return
  801. end
  802. local serverTime = ManagerContainer.LuaTimerMgr:CurLuaServerTime()
  803. if not battleFieldData.startTime or battleFieldData.startTime > serverTime then
  804. return
  805. end
  806. if not battleFieldData.endTime or battleFieldData.endTime < serverTime then
  807. return
  808. end
  809. self.areaTimer.lastUpdateTime = serverTime - 1000
  810. end
  811. if not self.areaTimer.running then
  812. self.areaTimer:Start()
  813. end
  814. if not self.areaTimer.lastUpdateTime then
  815. self:RefreshAreaTimer()
  816. else
  817. local remainTime = (ManagerContainer.LuaTimerMgr:CurLuaServerTime() - self.areaTimer.lastUpdateTime)
  818. if remainTime > 0 then
  819. remainTime = remainTime / 1000
  820. if type(remainTime) == 'userdata' then
  821. remainTime = #remainTime
  822. end
  823. self.areaTimer.time = remainTime
  824. else
  825. self:RefreshAreaTimer()
  826. end
  827. end
  828. end
  829. function UIGuildWarView:StopRefreshArea()
  830. if self.areaTimer and self.areaTimer.running then
  831. self.areaTimer:Stop()
  832. end
  833. end
  834. function UIGuildWarView:RefreshAreaTimer()
  835. local battleFieldData = self.controller:GetBattleFieldData()
  836. if not battleFieldData then
  837. self:StopRefreshArea()
  838. return
  839. end
  840. if battleFieldData.isFinish then
  841. self:StopRefreshArea()
  842. return
  843. end
  844. local serverTime = ManagerContainer.LuaTimerMgr:CurLuaServerTime()
  845. if not battleFieldData.startTime or battleFieldData.startTime > serverTime then
  846. self:StopRefreshArea()
  847. return
  848. end
  849. if not battleFieldData.endTime or battleFieldData.endTime < serverTime then
  850. self:StopRefreshArea()
  851. return
  852. end
  853. self.areaTimer.lastUpdateTime = serverTime
  854. local showRawIdxs = self.controller:GetShowRawIdxs()
  855. local startId, endId
  856. for i = 1, #showRawIdxs do
  857. local startId1, endId1 = self.controller:GetRawAreaStartAndEnd(showRawIdxs[i])
  858. if not startId or not endId then
  859. startId = startId1
  860. endId = endId1
  861. else
  862. if startId > startId1 then
  863. startId = startId1
  864. end
  865. if endId < endId1 then
  866. endId = endId1
  867. end
  868. end
  869. end
  870. if not startId or not endId then
  871. LogError('[wboy] not find need get data')
  872. return
  873. end
  874. if endId < startId then
  875. LogError('[wboy] not find need get valid data')
  876. return
  877. end
  878. local areaIds = {}
  879. if (endId - startId) > 30 then
  880. LogWarning('[Wboy] Need Get Data is Num' .. tostring((endId - startId)))
  881. end
  882. for i = startId, endId do
  883. local areaCfgData = ManagerContainer.CfgMgr:GetGuildWarDojoCfgById(i)
  884. if areaCfgData then
  885. areaIds[#areaIds+1] = i
  886. end
  887. end
  888. self.controller:SendGuildWarAreaDatasReq(areaIds)
  889. end
  890. function UIGuildWarView:RefreshArea()
  891. local loopGridView = self.scrollView.loopGridView
  892. local battleFieldData = self.controller:GetBattleFieldData()
  893. if not battleFieldData then
  894. loopGridView:RefreshListByIndex(0, 0)
  895. self.isInitGrid = nil
  896. return
  897. end
  898. local itemCount = loopGridView.ItemTotalCount
  899. local count = self.controller:GetRawCount()
  900. if itemCount ~= count then
  901. local areaId = self.controller:GetLastAttackAreaId()
  902. if areaId and areaId > 0 then
  903. local padding = loopGridView.Padding
  904. local height = (loopGridView.ViewPortHeight - loopGridView.ItemSizeWithPadding.y) * 0.5 - padding.top
  905. local itemIdx = self.controller:GetRawIdxByAreaId(areaId)
  906. loopGridView:RefreshListByIndex(count, itemIdx, 0, -height)
  907. else
  908. loopGridView:RefreshListByIndex(count, 0)
  909. end
  910. self.isInitGrid = true
  911. end
  912. end
  913. function UIGuildWarView:GetItemByRowColumn(gridView, itemIndex, row, column)
  914. self.controller:AddShowRawIdx(itemIndex)
  915. local startId, endId = self.controller:GetRawAreaStartAndEnd(itemIndex)
  916. local item = gridView:NewListViewItem('GuildWarRawItem')
  917. local itemLua = self:GetRawItemLua(item.gameObject)
  918. if itemLua then
  919. for i = startId, endId do
  920. self:RefreshAreaItemLuaByAreaId(itemLua, i)
  921. end
  922. end
  923. ManagerContainer.LuaUIMgr:ForceRebuildLayoutImmediate(item.CachedRectTransform)
  924. return item
  925. end
  926. function UIGuildWarView:RecycleItem(gridView, itemIndex, row, column, loopGridViewItem)
  927. self.controller:RemoveShowRawIdx(itemIndex)
  928. local itemLua = self:GetRawItemLua(loopGridViewItem.gameObject)
  929. if not itemLua then return end
  930. local childrenLua = itemLua.childrenLua
  931. if childrenLua then
  932. for _, areaItemLua in pairs(childrenLua) do
  933. self:ReleaseAreaItemLua(areaItemLua)
  934. end
  935. end
  936. itemLua.childrenLua = nil
  937. end
  938. function UIGuildWarView:GetRawItemLua(go)
  939. local itemLua = nil
  940. if self.rawItemDic then
  941. itemLua = self.rawItemDic[go]
  942. else
  943. self.rawItemDic = {}
  944. end
  945. if not itemLua then
  946. itemLua =
  947. {
  948. gameObject = go,
  949. transform = go.transform,
  950. }
  951. self.rawItemDic[go] = itemLua
  952. end
  953. return itemLua
  954. end
  955. function UIGuildWarView:DisposeRawItemLua()
  956. self.rawItemDic = nil
  957. end
  958. function UIGuildWarView:FindAreaItemLuaByAreaId(areaId)
  959. local itemIdx, idx = self.controller:GetRawIdxByAreaId(areaId)
  960. local item = self.scrollView.loopGridView:GetShownItemByItemIndex(itemIdx)
  961. if item then
  962. local itemLua = self:GetRawItemLua(item.gameObject)
  963. if itemLua then
  964. if itemLua.childrenLua then
  965. return itemLua.childrenLua[idx]
  966. end
  967. end
  968. end
  969. return nil
  970. end
  971. function UIGuildWarView:RefreshItemLua(areaId)
  972. if not areaId then return end
  973. local itemIdx, idx = self.controller:GetRawIdxByAreaId(areaId)
  974. local item = self.scrollView.loopGridView:GetShownItemByItemIndex(itemIdx)
  975. if item then
  976. local itemLua = self:GetRawItemLua(item.gameObject)
  977. if itemLua then
  978. self:RefreshAreaItemLuaByAreaId(itemLua, areaId)
  979. end
  980. end
  981. end
  982. function UIGuildWarView:RefreshAreaItemLuaByAreaId(itemLua, areaId)
  983. local childrenLua = itemLua.childrenLua
  984. if not childrenLua then
  985. childrenLua = {}
  986. itemLua.childrenLua = childrenLua
  987. end
  988. local areaCfgData = ManagerContainer.CfgMgr:GetGuildWarDojoCfgById(areaId)
  989. if areaCfgData then
  990. local itemIdx, idx = self.controller:GetRawIdxByAreaId(areaId)
  991. local areaItemLua = childrenLua[idx]
  992. if not areaItemLua then
  993. self:ReleaseAreaItemLua(areaItemLua)
  994. areaItemLua = self:GetAreaItemLua(itemLua.transform)
  995. childrenLua[idx] = areaItemLua
  996. end
  997. self:RefreshAreaItemLua(areaItemLua, areaId)
  998. end
  999. end
  1000. function UIGuildWarView:RefreshAreaItemLua(areaItemLua, areaId, hideName)
  1001. if not areaItemLua then return end
  1002. areaItemLua.areaId = areaId
  1003. local areaCfgData = ManagerContainer.CfgMgr:GetGuildWarDojoCfgById(areaId)
  1004. if areaCfgData then
  1005. areaItemLua:SetActive(true)
  1006. local heroCutePath = nil
  1007. local areaData = self.controller:GetAreaDataById(areaId)
  1008. local picIdx = 1
  1009. if areaData and areaData:IsOccupy() then
  1010. local color = nil
  1011. local battleFieldData = self.controller:GetBattleFieldData()
  1012. if battleFieldData then
  1013. if battleFieldData.guildId1 == areaData.guildId then
  1014. picIdx = 2
  1015. color = GUILD_COLOR_ID1
  1016. elseif battleFieldData.guildId2 == areaData.guildId then
  1017. picIdx = 3
  1018. color = GUILD_COLOR_ID2
  1019. end
  1020. end
  1021. if not color then
  1022. color = GUILD_COLOR_DEFAULT
  1023. end
  1024. local playBrief = areaData:GetPlayBrief()
  1025. if playBrief and playBrief.uid and playBrief.uid > 0 then
  1026. local playName = nil
  1027. local atkPower = playBrief.fightPower
  1028. if self.controller:IsSelfArea(areaId) then
  1029. playName = self.controller:GetUserNickname()
  1030. local roleId = self.controller:GetUserRoleId()
  1031. local roleCfgData = ManagerContainer.CfgMgr:GetRoleDataById(roleId)
  1032. if roleCfgData then
  1033. heroCutePath = roleCfgData.HeroCute
  1034. end
  1035. else
  1036. playName = playBrief.nickName
  1037. local roleId = CommonUtil.JobIdToRoleId(playBrief.configId, playBrief.gender)
  1038. local roleCfgData = ManagerContainer.CfgMgr:GetRoleDataById(roleId)
  1039. if roleCfgData then
  1040. heroCutePath = roleCfgData.HeroCute
  1041. end
  1042. end
  1043. areaItemLua.nameBoard.bG.image.color = color
  1044. areaItemLua.nameBoard.nameTxt.text.text = (playName and tostring(playName) or '')
  1045. areaItemLua.nameBoard.power.text.text = tostring(atkPower)
  1046. if hideName then
  1047. areaItemLua.nameBoard:SetActive(false)
  1048. else
  1049. areaItemLua.nameBoard:SetActive(true)
  1050. end
  1051. if not heroCutePath or heroCutePath == '' then
  1052. heroCutePath = self.controller:GetDefaultHeroCute()
  1053. end
  1054. else
  1055. areaItemLua.nameBoard:SetActive(false)
  1056. end
  1057. if areaData:IsFighting() then
  1058. areaItemLua.animator:Play('BattleKeep')
  1059. else
  1060. areaItemLua.animator:Play('NormalKeep')
  1061. end
  1062. elseif not areaData or not areaData:IsValidData() then
  1063. -- if not heroCutePath or heroCutePath == '' then
  1064. -- heroCutePath = self.controller:GetDefaultHeroCute()
  1065. -- end
  1066. areaItemLua.animator:Play('NormalKeep')
  1067. areaItemLua.nameBoard:SetActive(false)
  1068. else
  1069. if areaData:IsFighting() then
  1070. areaItemLua.animator:Play('BattleKeep')
  1071. else
  1072. areaItemLua.animator:Play('EmptyKeep')
  1073. end
  1074. areaItemLua.nameBoard:SetActive(false)
  1075. end
  1076. areaItemLua.player.image.enabled = false
  1077. areaItemLua.player.image.sprite = nil
  1078. areaItemLua.shadow:SetActive(false)
  1079. CommonUtil.LoadIcon(self, heroCutePath, function(sprite)
  1080. areaItemLua.player.image.sprite = sprite
  1081. areaItemLua.player.image.enabled = true
  1082. areaItemLua.shadow:SetActive(true)
  1083. end, areaItemLua, 'AreaItemHeroCuteAsyncIdx')
  1084. local thronePaths = THRONE_PATHS[areaCfgData.AreaType]
  1085. local thronePath = thronePaths and thronePaths[picIdx] or nil
  1086. areaItemLua.imgThrone.image.enabled = false
  1087. areaItemLua.imgThrone.image.sprite = nil
  1088. CommonUtil.LoadIcon(self, thronePath, function(sprite)
  1089. if sprite then
  1090. areaItemLua.imgThrone.image.sprite = sprite
  1091. areaItemLua.imgThrone.image.enabled = true
  1092. end
  1093. end, areaItemLua, 'ImgThroneAsyncIdx')
  1094. else
  1095. areaItemLua:SetActive(false)
  1096. end
  1097. end
  1098. function UIGuildWarView:GetAreaItemLua(parent)
  1099. if self.areaPool then
  1100. if self.areaPool then
  1101. local item = self.areaPool[#self.areaPool]
  1102. if item then
  1103. self.areaPool[#self.areaPool] = nil
  1104. item.transform:SetParent(parent)
  1105. item.transform.localPosition = Vector3.zero
  1106. item.transform.localScale = Vector3.one
  1107. item.transform.localRotation = Quaternion.identity
  1108. item:SetActive(true)
  1109. return item
  1110. end
  1111. end
  1112. end
  1113. local source = self.guildWarSlotItem
  1114. if not source then return nil end
  1115. local newGo = UnityEngine.GameObject.Instantiate(source.gameObject)
  1116. local itemLua = CommonUtil.BindGridViewItem2Lua(self, source.prefabName, newGo)
  1117. itemLua.transform:SetParent(parent)
  1118. itemLua.transform.localPosition = Vector3.zero
  1119. itemLua.transform.localScale = Vector3.one
  1120. itemLua.transform.localRotation = Quaternion.identity
  1121. itemLua:SetActive(true)
  1122. self.uiBase:AddButtonUniqueEventListener(itemLua.button, self, self.OnClickAreaSlotItem, itemLua)
  1123. return itemLua
  1124. end
  1125. function UIGuildWarView:ReleaseAreaItemLua(itemLua)
  1126. if not itemLua then return end
  1127. if not self.areaPool then
  1128. self.areaPool = {}
  1129. end
  1130. itemLua.transform:SetParent(self.scrollView.transform)
  1131. itemLua:SetActive(false)
  1132. self.areaPool[#self.areaPool + 1] = itemLua
  1133. end
  1134. function UIGuildWarView:DisposeAreaItemLua()
  1135. if not self.areaPool then
  1136. return
  1137. end
  1138. for _, itemLua in pairs(self.areaPool) do
  1139. if itemLua.gameObject then
  1140. CommonUtil.DestroyGO(itemLua.gameObject)
  1141. end
  1142. end
  1143. self.areaPool = nil
  1144. end
  1145. function UIGuildWarView:LocationAndOpenMenu(areaId)
  1146. local itemIdx = self.controller:GetRawIdxByAreaId(areaId)
  1147. local loopGridView = self.scrollView.loopGridView
  1148. local pair1 = loopGridView:GetRowColumnByItemIndex(itemIdx)
  1149. local pair2 = loopGridView:GetRowColumnByItemIndex(itemIdx + 1)
  1150. local offset = loopGridView.ContainerTrans.anchoredPosition
  1151. local itemPosStart = loopGridView:GetItemPos(pair1.mRow, pair1.mColumn) + offset
  1152. local itemPosEnd = loopGridView:GetItemPos(pair2.mRow, pair2.mColumn) + offset
  1153. local rect = self.viewRect.rectTransform.rect
  1154. local min = self.viewRect.rectTransform:TransformPoint(rect.min)
  1155. local max = self.viewRect.rectTransform:TransformPoint(rect.max)
  1156. local scrollRect = loopGridView.ScrollRect
  1157. local viewport = scrollRect.viewport
  1158. min = viewport:InverseTransformPoint(min)
  1159. max = viewport:InverseTransformPoint(max)
  1160. local isStart1 = ((itemPosStart.y - min.y) >= 0.001)
  1161. local isStart2 = ((itemPosStart.y - max.y) <= 0.001)
  1162. local isEnd1 = ((itemPosEnd.y - min.y) >= 0.001)
  1163. local isEnd2 = ((itemPosEnd.y - max.y) <= 0.001 )
  1164. if isStart1 and isStart2 and isEnd1 and isEnd2 then
  1165. self:OpenMenu(areaId)
  1166. return
  1167. end
  1168. local val = scrollRect.verticalNormalizedPosition
  1169. if val <= 0 or val >= 1 then
  1170. self:OpenMenu(areaId)
  1171. return
  1172. end
  1173. -- self:CloseSlogan()
  1174. self.alignAreaId = areaId
  1175. if self.areaTimer then
  1176. self.areaTimer:Stop()
  1177. end
  1178. loopGridView.ItemSnapEnable = true
  1179. loopGridView:SetSnapTargetItemRowColumn(pair1.mRow, pair1.mColumn)
  1180. local rect1 = viewport.rect
  1181. if isEnd1 then
  1182. loopGridView.ItemSnapPivot = Vector2.one
  1183. local pivotOffset = (rect1.yMax - max.y)
  1184. if pivotOffset <= 0 then
  1185. pivotOffset = 1
  1186. else
  1187. pivotOffset = 1 - pivotOffset / rect1.height
  1188. end
  1189. loopGridView.ViewPortSnapPivot = Vector2(0, pivotOffset)
  1190. return
  1191. end
  1192. loopGridView.ItemSnapPivot = Vector2.zero
  1193. local pivotOffset = (min.y - rect1.yMin)
  1194. if pivotOffset <= 0 then
  1195. pivotOffset = 0
  1196. else
  1197. pivotOffset = pivotOffset / rect1.height
  1198. end
  1199. loopGridView.ViewPortSnapPivot = Vector2(0, pivotOffset)
  1200. end
  1201. function UIGuildWarView:OpenMenu(areaId)
  1202. local battleFieldData = self.controller:GetBattleFieldData()
  1203. if not battleFieldData then
  1204. self:CloseMenu()
  1205. return
  1206. end
  1207. local isBattlingMy = battleFieldData:IsBattlingMy()
  1208. if not areaId then
  1209. self:CloseMenu()
  1210. return
  1211. end
  1212. self.curSelectAreaId = areaId
  1213. if self.controller:IsSelfArea(areaId) then
  1214. self:CloseMenu()
  1215. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('GuildWarBattle8')
  1216. return
  1217. end
  1218. local areaData = battleFieldData:GetAreaDataById(areaId)
  1219. if not areaData or not areaData:IsValidData() then
  1220. self:CloseMenu()
  1221. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('GuildWarBattle10')
  1222. return
  1223. else
  1224. if not areaData:IsPeopleOccupy() then
  1225. self:CloseMenu()
  1226. if isBattlingMy then
  1227. local errorCode = self.controller:SendGuildWarChallengeReq(areaId)
  1228. if errorCode ~= 0 then
  1229. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  1230. end
  1231. end
  1232. return
  1233. end
  1234. end
  1235. local itemIdx, idx = self.controller:GetRawIdxByAreaId(areaId)
  1236. local item = self.scrollView.loopGridView:GetShownItemByItemIndex(itemIdx)
  1237. if not item then
  1238. self:CloseMenu()
  1239. return
  1240. end
  1241. local itemLua = self:GetRawItemLua(item.gameObject)
  1242. if not itemLua then
  1243. self:CloseMenu()
  1244. return
  1245. end
  1246. local childrenLua = itemLua.childrenLua
  1247. if not childrenLua then
  1248. self:CloseMenu()
  1249. return
  1250. end
  1251. local areaItemLua = childrenLua[idx]
  1252. if not areaItemLua then
  1253. self:CloseMenu()
  1254. return
  1255. end
  1256. local areaCfgData = ManagerContainer.CfgMgr:GetGuildWarDojoCfgById(areaId)
  1257. if not areaCfgData then
  1258. self:CloseMenu()
  1259. return
  1260. end
  1261. local playName = nil
  1262. local atkPower = 0
  1263. local color = nil
  1264. local playBrief = areaData:GetPlayBrief()
  1265. if playBrief then
  1266. playName = playBrief.nickName
  1267. atkPower = playBrief.fightPower
  1268. end
  1269. if battleFieldData then
  1270. if battleFieldData.guildId1 == areaData.guildId then
  1271. color = GUILD_COLOR_ID1
  1272. elseif battleFieldData.guildId2 == areaData.guildId then
  1273. color = GUILD_COLOR_ID2
  1274. end
  1275. end
  1276. if not color then
  1277. color = GUILD_COLOR_DEFAULT
  1278. end
  1279. self.menu:SetActive(true)
  1280. if not self.curSelectAreaItemLua then
  1281. self.curSelectAreaItemLua = self:GetAreaItemLua(self.menu.transform)
  1282. end
  1283. if self.curSelectAreaItemLua then
  1284. self.curSelectAreaItemLua.transform.position = areaItemLua.transform.position
  1285. self:RefreshAreaItemLua(self.curSelectAreaItemLua, areaId, true)
  1286. end
  1287. self.menu.panel.transform.position = areaItemLua.transform.position
  1288. self.menu.panel.transform:SetAsLastSibling()
  1289. self.menu.nameBoard.bG.image.color = color
  1290. self.menu.nameBoard.nameTxt.text.text = (playName and tostring(playName) or '')
  1291. self.menu.nameBoard.power.text.text = tostring(atkPower)
  1292. self.menu.nameBoard:SetActive(true)
  1293. self.menu.btnInfo:SetActive(true)
  1294. self.menu.btnClg:SetActive(isBattlingMy and areaData:GetGuildId() ~= battleFieldData.guildId)
  1295. -- self:ReleaseOtherSloganByAreaId(areaId)
  1296. end
  1297. function UIGuildWarView:CloseMenu()
  1298. self.curSelectAreaId = nil
  1299. if self.curSelectAreaItemLua then
  1300. self:ReleaseAreaItemLua(self.curSelectAreaItemLua)
  1301. self.curSelectAreaItemLua = nil
  1302. end
  1303. self.menu:SetActive(false)
  1304. end
  1305. function UIGuildWarView:OnClickMenuCloseBtn()
  1306. self:CloseMenu()
  1307. end
  1308. function UIGuildWarView:OnClickMenuChallengeBtn()
  1309. local areaId = self.curSelectAreaId
  1310. if not areaId then return end
  1311. if not self:IsBattlingMy() then
  1312. return
  1313. end
  1314. local areaData = self.controller:GetAreaDataById(areaId)
  1315. if not areaData or not areaData:IsValidData() then
  1316. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('GuildWarBattle10')
  1317. return
  1318. end
  1319. if areaData:IsPeopleOccupy() then
  1320. if self.controller:IsSelfArea(areaId) then
  1321. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('GuildWarBattle8')
  1322. return
  1323. end
  1324. if self.controller:IsSameGuildArea(areaId) then
  1325. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('GuildWarBattle9')
  1326. return
  1327. end
  1328. end
  1329. self:CloseMenu()
  1330. local errorCode = self.controller:SendGuildWarChallengeReq(areaId)
  1331. if errorCode ~= 0 then
  1332. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  1333. end
  1334. end
  1335. function UIGuildWarView:OnClickMenuInfoBtn()
  1336. local areaId = self.curSelectAreaId
  1337. if not areaId then return end
  1338. local areaData = self.controller:GetAreaDataById(areaId)
  1339. if not areaData or not areaData:IsValidData() then
  1340. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('GuildWarBattle10')
  1341. return
  1342. end
  1343. if not areaData:IsPeopleOccupy() then
  1344. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('GuildWarBattle10')
  1345. return
  1346. end
  1347. if self.controller:IsSelfArea(areaId) then
  1348. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('GuildWarBattle8')
  1349. return
  1350. end
  1351. self:CloseMenu()
  1352. local playBrief = areaData:GetPlayBrief()
  1353. if playBrief then
  1354. ManagerContainer.LuaUIMgr:OpenRoleMessagePanel(playBrief.uid)
  1355. end
  1356. end
  1357. function UIGuildWarView:IsBattleMy()
  1358. local battleFieldData = self.controller:GetBattleFieldData()
  1359. if not battleFieldData then
  1360. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('GuildWarBattle10')
  1361. return false
  1362. end
  1363. if battleFieldData.isFinish then
  1364. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('GuildWarBattle20')
  1365. return false
  1366. end
  1367. if not battleFieldData:IsBattlingMy() then
  1368. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('GuildWarBattle11')
  1369. return false
  1370. end
  1371. local serverTime = ManagerContainer.LuaTimerMgr:CurLuaServerTime()
  1372. if not battleFieldData.endTime or battleFieldData.endTime < serverTime then
  1373. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('GuildWarBattle20')
  1374. return false
  1375. end
  1376. return true
  1377. end
  1378. function UIGuildWarView:IsBattlingMy()
  1379. local battleFieldData = self.controller:GetBattleFieldData()
  1380. if not battleFieldData then
  1381. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('GuildWarBattle10')
  1382. return false
  1383. end
  1384. if battleFieldData.isFinish then
  1385. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('GuildWarBattle20')
  1386. return false
  1387. end
  1388. if not battleFieldData:IsBattlingMy() then
  1389. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('GuildWarBattle11')
  1390. return false
  1391. end
  1392. local serverTime = ManagerContainer.LuaTimerMgr:CurLuaServerTime()
  1393. if not battleFieldData.startTime or battleFieldData.startTime > serverTime then
  1394. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('GuildWarBattle19')
  1395. return false
  1396. end
  1397. if not battleFieldData.endTime or battleFieldData.endTime < serverTime then
  1398. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('GuildWarBattle20')
  1399. return false
  1400. end
  1401. return true
  1402. end
  1403. return UIGuildWarView