UIHundredDojoChallengeView.lua 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. local UIHundredDojoChallengeView = require("UIHundredDojo/UIHundredDojoChallengeView_Generate")
  2. local ColorExtension = require('ColorExtension')
  3. function UIHundredDojoChallengeView:OnAwake(data)
  4. self.controller = require("UIHundredDojo/UIHundredDojoChallengeCtr"):new()
  5. self.controller:Init(self)
  6. self.controller:SetData(data)
  7. end
  8. function UIHundredDojoChallengeView:AddEventListener()
  9. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.HUNDRED_DOJO_SELF_AREA_DATA_CHANGED, self, self.OnSelfAreaDataChanged)
  10. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.HUNDRED_DOJO_OTHER_AREA_DATA_CHANGED, self, self.OnOtherAreaDataChanged)
  11. end
  12. function UIHundredDojoChallengeView:FillContent(data, uiBase)
  13. self.uiBase = uiBase
  14. local gameObject = self.uiBase:GetRoot()
  15. if gameObject ~= nil then
  16. self.gameObject = gameObject
  17. self.transform = gameObject.transform
  18. end
  19. self:InitGenerate(self.transform, data)
  20. self:Init()
  21. end
  22. function UIHundredDojoChallengeView:Init()
  23. self.controller:InitData()
  24. self:RefreshView()
  25. end
  26. function UIHundredDojoChallengeView:RemoveEventListener()
  27. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  28. end
  29. function UIHundredDojoChallengeView:AddUIEventListener()
  30. self.uiBase:AddButtonUniqueEventListener(self.AnyBtn.button,self, self.OnClickCloseBtn)
  31. self.uiBase:AddButtonUniqueEventListener(self.btnClose.button, self, self.OnClickCloseBtn)
  32. self.uiBase:AddButtonUniqueEventListener(self.btnCancle.button, self, self.OnClickCloseBtn)
  33. self.uiBase:AddButtonUniqueEventListener(self.btnChallenge.button, self, self.OnClickChallengeBtn)
  34. self.uiBase:AddButtonUniqueEventListener(self.btnCapture.button, self, self.OnClickCaptureBtn)
  35. end
  36. function UIHundredDojoChallengeView:OnHide()
  37. end
  38. function UIHundredDojoChallengeView:OnShow(data)
  39. self.controller:SetData(data)
  40. end
  41. function UIHundredDojoChallengeView:OnClose()
  42. end
  43. function UIHundredDojoChallengeView:OnDispose()
  44. if self.occupyTimer then
  45. self.occupyTimer:Stop()
  46. self.occupyTimer = nil
  47. end
  48. self.controller:OnDispose()
  49. end
  50. function UIHundredDojoChallengeView:OnSelfAreaDataChanged(oldId, newId)
  51. local curId = self.controller:GetData()
  52. if curId == oldId or curId == newId then
  53. self:RefreshView()
  54. end
  55. end
  56. function UIHundredDojoChallengeView:OnOtherAreaDataChanged(areaChangeIds)
  57. if not areaChangeIds then return end
  58. local curId = self.controller:GetData()
  59. for _, Id in pairs(areaChangeIds) do
  60. if curId == Id then
  61. self:RefreshView()
  62. break
  63. end
  64. end
  65. end
  66. function UIHundredDojoChallengeView:OnClickCloseBtn()
  67. self:UIClose()
  68. end
  69. function UIHundredDojoChallengeView:OnClickChallengeBtn()
  70. local errorCode = self.controller:SendChallengeReq()
  71. if errorCode == 0 then
  72. self:OnClickCloseBtn()
  73. else
  74. if errorCode == 1 then
  75. self:OnClickCloseBtn()
  76. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('HundredDojoView5')
  77. elseif errorCode == 2 then
  78. local costCfgId, costNum = self.controller:GetBuyChallengeCountCost()
  79. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIDojoBuyTimes, {costNum, nil, self.SureBuyChallengeNum, self})
  80. else
  81. self:OnClickCloseBtn()
  82. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  83. end
  84. end
  85. end
  86. function UIHundredDojoChallengeView:SureOpenRuneShop()
  87. self:OnClickCloseBtn()
  88. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopBT, {Enum.RuneShopType.Gifts, Enum.RuneShopSubType.Gold}, Enum.UIPageName.UIHundredDojo)
  89. end
  90. function UIHundredDojoChallengeView:SureBuyChallengeNum()
  91. local errorCode, costCfgId = self.controller:SendBuyChallengeNumReq()
  92. if errorCode ~= 0 then
  93. if errorCode == 1 then
  94. if Constant.OpenPay then
  95. local cfgData = ManagerContainer.CfgMgr:GetItemById(costCfgId)
  96. if cfgData then
  97. if cfgData.ResType == Enum.ItemType.Diamond then
  98. local data = {"NoDiamondTip", nil, nil, self, self.SureOpenRuneShop}
  99. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UINoticeTips, data)
  100. return
  101. end
  102. end
  103. end
  104. ManagerContainer.LuaUIMgr:ErrorNoticeDisplayWithParam(CommonUtil.GetItemNotEnoughInfo(costCfgId))
  105. else
  106. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  107. end
  108. end
  109. end
  110. function UIHundredDojoChallengeView:OnClickCaptureBtn()
  111. local errorCode = self.controller:SendChallengeReq()
  112. if errorCode == 0 then
  113. self:OnClickCloseBtn()
  114. else
  115. if errorCode == 1 then
  116. self:OnClickCloseBtn()
  117. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('HundredDojoView5')
  118. elseif errorCode == 2 then
  119. local costCfgId, costNum = self.controller:GetBuyChallengeCountCost()
  120. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIDojoBuyTimes, {costNum, nil, self.SureBuyChallengeNum, self})
  121. else
  122. self:OnClickCloseBtn()
  123. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  124. end
  125. end
  126. end
  127. function UIHundredDojoChallengeView:RefreshView()
  128. if self.occupyTimer then
  129. self.occupyTimer:Stop()
  130. end
  131. local curId = self.controller:GetData()
  132. local areaCfgData = ManagerContainer.CfgMgr:GetHundredDojoCfgById(curId)
  133. if areaCfgData then
  134. self.titleTxt.text.text = string.formatbykey(areaCfgData.Name)
  135. local rewards = areaCfgData.ShowRewardList
  136. local rewardRate = self.controller:GetRewardRate()
  137. self:RefreshCurrencyItem(self.currency1, rewards[1], rewardRate)
  138. self:RefreshCurrencyItem(self.currency2, rewards[2], rewardRate)
  139. self:RefreshCurrencyItem(self.currency3, rewards[3], rewardRate)
  140. local areaData = self.controller:GetAreaData()
  141. self.itemLua = self:GetAreaItemLua(areaCfgData.FunType, areaCfgData.AreaType)
  142. local playName = nil
  143. if self.itemLua then
  144. self.itemLua:SetActive(true)
  145. local slogan = nil
  146. if areaCfgData.FunType == Enum.HundredDojoFunType.Normal then
  147. local heroCutePath = nil
  148. if areaData and areaData:IsOccupy() then
  149. local robotId = areaData:GetRobotId()
  150. local atkPower = 0
  151. local color = nil
  152. if robotId and robotId > 0 then
  153. heroCutePath = self.controller:GetRobotHeroCute()
  154. local robotCfgData = ManagerContainer.CfgMgr:GetRobotDataByCfgId(robotId)
  155. if robotCfgData then
  156. playName = I18N.T(robotCfgData.RobotName)
  157. atkPower = robotCfgData.FightPower and robotCfgData.FightPower[1] or 0
  158. end
  159. color = ColorExtension.HexStringToColor(string.formatbykey('ColorID4'))
  160. else
  161. local isSelfArea = self.controller:IsSelfArea(curId)
  162. local uid = nil
  163. if isSelfArea then
  164. slogan = self.controller:GetSelfSlogan()
  165. playName = self.controller:GetUserNickname()
  166. atkPower = self.controller:GetTotalFightPower()
  167. local roleId = self.controller:GetUserRoleId()
  168. local roleCfgData = ManagerContainer.CfgMgr:GetRoleDataById(roleId)
  169. if roleCfgData then
  170. heroCutePath = roleCfgData.HeroCute
  171. end
  172. else
  173. slogan = areaData:GetSlogan()
  174. local playBrief = areaData:GetPlayBrief()
  175. if playBrief then
  176. playName = playBrief.nickName
  177. atkPower = playBrief.fightPower
  178. uid = playBrief.uid
  179. local roleId = CommonUtil.JobIdToRoleId(playBrief.configId, playBrief.gender)
  180. local roleCfgData = ManagerContainer.CfgMgr:GetRoleDataById(roleId)
  181. if roleCfgData then
  182. heroCutePath = roleCfgData.HeroCute
  183. end
  184. end
  185. end
  186. if isSelfArea then
  187. color = ColorExtension.HexStringToColor(string.formatbykey('ColorID2'))
  188. elseif self.controller:IsLastBeAtkArea(uid) then
  189. color = ColorExtension.HexStringToColor(string.formatbykey('ColorID6'))
  190. elseif self.controller:IsSameGuild(areaData:GetGuildId()) then
  191. color = ColorExtension.HexStringToColor(string.formatbykey('ColorID3'))
  192. else
  193. color = ColorExtension.HexStringToColor(string.formatbykey('ColorID5'))
  194. end
  195. end
  196. if not color then
  197. color = ColorExtension.HexStringToColor(string.formatbykey('ColorID1'))
  198. end
  199. if areaData:IsProtected() then
  200. self.itemLua.animator:Play('ShieldKeep')
  201. elseif areaData:IsFighting() then
  202. self.itemLua.animator:Play('BattleKeep')
  203. else
  204. self.itemLua.animator:Play('NormalKeep')
  205. end
  206. self.itemLua.nameBoard.bG.image.color = color
  207. self.itemLua.nameBoard.nameTxt.text.text = (playName and tostring(playName) or '')
  208. self.itemLua.nameBoard.power.text.text = tostring(atkPower)
  209. self.itemLua.nameBoard:SetActive(true)
  210. if not heroCutePath or heroCutePath == '' then
  211. heroCutePath = self.controller:GetDefaultHeroCute()
  212. end
  213. elseif not areaData or not areaData:IsValidData() then
  214. if not heroCutePath or heroCutePath == '' then
  215. heroCutePath = self.controller:GetDefaultHeroCute()
  216. end
  217. self.itemLua.animator:Play('NormalKeep')
  218. self.itemLua.nameBoard:SetActive(false)
  219. else
  220. if areaData:IsFighting() then
  221. self.itemLua.animator:Play('BattleKeep')
  222. else
  223. self.itemLua.animator:Play('EmptyKeep')
  224. end
  225. self.itemLua.nameBoard:SetActive(false)
  226. end
  227. self.itemLua.player.image.enabled = false
  228. self.itemLua.player.image.sprite = nil
  229. self.itemLua.shadow:SetActive(false)
  230. CommonUtil.LoadIcon(self, heroCutePath, function(sprite)
  231. self.itemLua.player.image.sprite = sprite
  232. self.itemLua.player.image.enabled = true
  233. self.itemLua.shadow:SetActive(true)
  234. end, self.itemLua, 'AreaItemHeroCute')
  235. end
  236. if not slogan or slogan == '' then
  237. self.bubble:SetActive(false)
  238. else
  239. self.bubble:SetActive(true)
  240. self.bubble.slogan.text.text = tostring(slogan)
  241. end
  242. else
  243. self.bubble:SetActive(false)
  244. end
  245. local acfName = I18N.T(areaCfgData.Name)
  246. if areaData and areaData:IsValidData() then
  247. if areaData:IsOccupy() then
  248. self.btnChallenge:SetActive(true)
  249. self.btnCapture:SetActive(false)
  250. local robotId = areaData:GetRobotId()
  251. self.timer:SetActive(not (robotId and robotId > 0))
  252. self:RefreshOccupyTimer()
  253. local guildName = areaData:GetGuildName()
  254. if guildName and guildName ~= '' then
  255. self.tipsTxt.text.text = string.formatbykey('HundredDojoChallengeView1', tostring(acfName), tostring(playName), tostring(guildName))
  256. else
  257. self.tipsTxt.text.text = string.formatbykey('HundredDojoChallengeView2', tostring(acfName), tostring(playName), tostring(guildName))
  258. end
  259. self.questionTxt.text.text = string.formatbykey('HundredDojoChallengeView4')
  260. else
  261. self.btnChallenge:SetActive(false)
  262. self.btnCapture:SetActive(true)
  263. self.timer:SetActive(false)
  264. self.tipsTxt.text.text = string.formatbykey('HundredDojoChallengeView3', tostring(acfName), tostring(playName), tostring(guildName))
  265. self.questionTxt.text.text = string.formatbykey('HundredDojoChallengeView5')
  266. end
  267. else
  268. self.btnChallenge:SetActive(false)
  269. self.btnCapture:SetActive(true)
  270. self.timer:SetActive(false)
  271. self.tipsTxt.text.text = string.formatbykey('HundredDojoView2')
  272. self.questionTxt.text.text = string.formatbykey('HundredDojoView2')
  273. end
  274. return
  275. end
  276. self:RefreshCurrencyItem(self.currency1, nil, 0)
  277. self:RefreshCurrencyItem(self.currency2, nil, 0)
  278. self:RefreshCurrencyItem(self.currency3, nil, 0)
  279. self.titleTxt.text.text = string.formatbykey('HundredDojoView5')
  280. self.tipsTxt.text.text = string.formatbykey('HundredDojoView5')
  281. self.questionTxt.text.text = string.formatbykey('HundredDojoView5')
  282. self.timer:SetActive(false)
  283. self.btnChallenge:SetActive(false)
  284. self.btnCapture:SetActive(false)
  285. if self.itemLua then
  286. self.itemLua:SetActive(false)
  287. self.itemLua = nil
  288. end
  289. self.bubble:SetActive(false)
  290. end
  291. function UIHundredDojoChallengeView:RefreshOccupyTimer()
  292. local areaData = self.controller:GetAreaData()
  293. if not areaData or not areaData:IsOccupy() then
  294. self:RefreshView()
  295. return
  296. end
  297. local isProtected = areaData:IsProtected()
  298. local remainTime = 0
  299. if isProtected then
  300. local endTime = areaData:GetProtectEndTime()
  301. if endTime and endTime > 0 then
  302. remainTime = endTime - ManagerContainer.LuaTimerMgr:CurLuaServerTime()
  303. remainTime = remainTime / 1000
  304. if type(remainTime) == 'userdata' then
  305. remainTime = #remainTime
  306. end
  307. end
  308. self.timerTxt.text.text = DateTimeUtil.convertSeconds2TimeStr1(remainTime, true, true, false)
  309. else
  310. local endTime = areaData:GetEndTime()
  311. if endTime and endTime > 0 then
  312. remainTime = endTime - ManagerContainer.LuaTimerMgr:CurLuaServerTime()
  313. remainTime = remainTime / 1000
  314. if type(remainTime) == 'userdata' then
  315. remainTime = #remainTime
  316. end
  317. end
  318. self.timerTxt.text.text = DateTimeUtil.convertSeconds2TimeStr1(remainTime, true, true, false)
  319. end
  320. if remainTime <= 0 then
  321. if self.occupyTimer then
  322. self.occupyTimer:Stop()
  323. end
  324. else
  325. local validTime = nil
  326. if remainTime >= 86400 then
  327. validTime = remainTime % 3600
  328. if validTime == 0 then validTime = 3600 end
  329. elseif remainTime >= 3600 then
  330. validTime = remainTime % 60
  331. if validTime == 0 then validTime = 60 end
  332. else
  333. validTime = 1
  334. end
  335. if self.occupyTimer then
  336. self.occupyTimer.time = 0
  337. self.occupyTimer.duration = validTime
  338. else
  339. self.occupyTimer = Timer.New(slot(self.RefreshOccupyTimer, self), validTime, -1)
  340. end
  341. if not self.occupyTimer.running then
  342. self.occupyTimer:Start()
  343. end
  344. end
  345. end
  346. function UIHundredDojoChallengeView:RefreshCurrencyItem(currency, reward, rewardRate)
  347. if not currency then return end
  348. currency.icon.image.enabled = false
  349. currency.icon.image.sprite = nil
  350. if reward then
  351. local cfgId = reward[1] or 0
  352. local num = reward[2] or 0
  353. local cfgData = ManagerContainer.CfgMgr:GetItemById(cfgId)
  354. if cfgData then
  355. CommonUtil.LoadIcon(self, cfgData.MiniIcon, function(sprite)
  356. currency.icon.image.sprite = sprite
  357. currency.icon.image.enabled = true
  358. end)
  359. end
  360. if rewardRate and rewardRate > 0 then
  361. currency.text.text.text = tostring(Mathf.Floor(num * rewardRate))
  362. else
  363. currency.text.text.text = '-'
  364. end
  365. currency:SetActive(true)
  366. else
  367. currency:SetActive(false)
  368. end
  369. end
  370. function UIHundredDojoChallengeView:GetAreaItemLua(funType, areaType)
  371. local itemLua = nil
  372. if funType == Enum.HundredDojoFunType.Box then
  373. itemLua = self.hundredDojoBoxSlotItem
  374. elseif funType == Enum.HundredDojoFunType.Normal then
  375. if areaType == Enum.HundredDojoAreaType.FirstArea then
  376. itemLua = self.hundredDojoSlotItem1
  377. elseif areaType == Enum.HundredDojoAreaType.SuperArea then
  378. itemLua = self.hundredDojoSlotItem2
  379. elseif areaType == Enum.HundredDojoAreaType.OneLvArea then
  380. itemLua = self.hundredDojoSlotItem3
  381. elseif areaType == Enum.HundredDojoAreaType.TwoLvArea then
  382. itemLua = self.hundredDojoSlotItem4
  383. elseif areaType == Enum.HundredDojoAreaType.ThreeArea then
  384. itemLua = self.hundredDojoSlotItem5
  385. elseif areaType == Enum.HundredDojoAreaType.FourArea then
  386. itemLua = self.hundredDojoSlotItem6
  387. else
  388. itemLua = self.hundredDojoSlotItem6
  389. end
  390. end
  391. return itemLua
  392. end
  393. return UIHundredDojoChallengeView