UIHundredDojoChallengeView.lua 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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 = 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. if areaData and areaData:IsValidData() then
  246. if areaData:IsOccupy() then
  247. self.btnChallenge:SetActive(true)
  248. self.btnCapture:SetActive(false)
  249. local robotId = areaData:GetRobotId()
  250. self.timer:SetActive(not (robotId and robotId > 0))
  251. self:RefreshOccupyTimer()
  252. local guildName = areaData:GetGuildName()
  253. if guildName and guildName ~= '' then
  254. self.tipsTxt.text.text = string.formatbykey('HundredDojoChallengeView1', tostring(areaCfgData.Name), tostring(playName), tostring(guildName))
  255. else
  256. self.tipsTxt.text.text = string.formatbykey('HundredDojoChallengeView2', tostring(areaCfgData.Name), tostring(playName), tostring(guildName))
  257. end
  258. self.questionTxt.text.text = string.formatbykey('HundredDojoChallengeView4')
  259. else
  260. self.btnChallenge:SetActive(false)
  261. self.btnCapture:SetActive(true)
  262. self.timer:SetActive(false)
  263. self.tipsTxt.text.text = string.formatbykey('HundredDojoChallengeView3', tostring(areaCfgData.Name), tostring(playName), tostring(guildName))
  264. self.questionTxt.text.text = string.formatbykey('HundredDojoChallengeView5')
  265. end
  266. else
  267. self.btnChallenge:SetActive(false)
  268. self.btnCapture:SetActive(true)
  269. self.timer:SetActive(false)
  270. self.tipsTxt.text.text = string.formatbykey('HundredDojoView2')
  271. self.questionTxt.text.text = string.formatbykey('HundredDojoView2')
  272. end
  273. return
  274. end
  275. self:RefreshCurrencyItem(self.currency1, nil, 0)
  276. self:RefreshCurrencyItem(self.currency2, nil, 0)
  277. self:RefreshCurrencyItem(self.currency3, nil, 0)
  278. self.titleTxt.text.text = string.formatbykey('HundredDojoView5')
  279. self.tipsTxt.text.text = string.formatbykey('HundredDojoView5')
  280. self.questionTxt.text.text = string.formatbykey('HundredDojoView5')
  281. self.timer:SetActive(false)
  282. self.btnChallenge:SetActive(false)
  283. self.btnCapture:SetActive(false)
  284. if self.itemLua then
  285. self.itemLua:SetActive(false)
  286. self.itemLua = nil
  287. end
  288. self.bubble:SetActive(false)
  289. end
  290. function UIHundredDojoChallengeView:RefreshOccupyTimer()
  291. local areaData = self.controller:GetAreaData()
  292. if not areaData or not areaData:IsOccupy() then
  293. self:RefreshView()
  294. return
  295. end
  296. local isProtected = areaData:IsProtected()
  297. local remainTime = 0
  298. if isProtected then
  299. local endTime = areaData:GetProtectEndTime()
  300. if endTime and endTime > 0 then
  301. remainTime = endTime - ManagerContainer.LuaTimerMgr:CurLuaServerTime()
  302. remainTime = remainTime / 1000
  303. if type(remainTime) == 'userdata' then
  304. remainTime = #remainTime
  305. end
  306. end
  307. self.timerTxt.text.text = DateTimeUtil.convertSeconds2TimeStr1(remainTime, true, true, false)
  308. else
  309. local endTime = areaData:GetEndTime()
  310. if endTime and endTime > 0 then
  311. remainTime = endTime - ManagerContainer.LuaTimerMgr:CurLuaServerTime()
  312. remainTime = remainTime / 1000
  313. if type(remainTime) == 'userdata' then
  314. remainTime = #remainTime
  315. end
  316. end
  317. self.timerTxt.text.text = DateTimeUtil.convertSeconds2TimeStr1(remainTime, true, true, false)
  318. end
  319. if remainTime <= 0 then
  320. if self.occupyTimer then
  321. self.occupyTimer:Stop()
  322. end
  323. else
  324. local validTime = nil
  325. if remainTime >= 86400 then
  326. validTime = remainTime % 3600
  327. if validTime == 0 then validTime = 3600 end
  328. elseif remainTime >= 3600 then
  329. validTime = remainTime % 60
  330. if validTime == 0 then validTime = 60 end
  331. else
  332. validTime = 1
  333. end
  334. if self.occupyTimer then
  335. self.occupyTimer.time = 0
  336. self.occupyTimer.duration = validTime
  337. else
  338. self.occupyTimer = Timer.New(slot(self.RefreshOccupyTimer, self), validTime, -1)
  339. end
  340. if not self.occupyTimer.running then
  341. self.occupyTimer:Start()
  342. end
  343. end
  344. end
  345. function UIHundredDojoChallengeView:RefreshCurrencyItem(currency, reward, rewardRate)
  346. if not currency then return end
  347. currency.icon.image.enabled = false
  348. currency.icon.image.sprite = nil
  349. if reward then
  350. local cfgId = reward[1] or 0
  351. local num = reward[2] or 0
  352. local cfgData = ManagerContainer.CfgMgr:GetItemById(cfgId)
  353. if cfgData then
  354. CommonUtil.LoadIcon(self, cfgData.MiniIcon, function(sprite)
  355. currency.icon.image.sprite = sprite
  356. currency.icon.image.enabled = true
  357. end)
  358. end
  359. if rewardRate and rewardRate > 0 then
  360. currency.text.text.text = tostring(Mathf.Floor(num * rewardRate))
  361. else
  362. currency.text.text.text = '-'
  363. end
  364. currency:SetActive(true)
  365. else
  366. currency:SetActive(false)
  367. end
  368. end
  369. function UIHundredDojoChallengeView:GetAreaItemLua(funType, areaType)
  370. local itemLua = nil
  371. if funType == Enum.HundredDojoFunType.Box then
  372. itemLua = self.hundredDojoBoxSlotItem
  373. elseif funType == Enum.HundredDojoFunType.Normal then
  374. if areaType == Enum.HundredDojoAreaType.FirstArea then
  375. itemLua = self.hundredDojoSlotItem1
  376. elseif areaType == Enum.HundredDojoAreaType.SuperArea then
  377. itemLua = self.hundredDojoSlotItem2
  378. elseif areaType == Enum.HundredDojoAreaType.OneLvArea then
  379. itemLua = self.hundredDojoSlotItem3
  380. elseif areaType == Enum.HundredDojoAreaType.TwoLvArea then
  381. itemLua = self.hundredDojoSlotItem4
  382. elseif areaType == Enum.HundredDojoAreaType.ThreeArea then
  383. itemLua = self.hundredDojoSlotItem5
  384. elseif areaType == Enum.HundredDojoAreaType.FourArea then
  385. itemLua = self.hundredDojoSlotItem6
  386. else
  387. itemLua = self.hundredDojoSlotItem6
  388. end
  389. end
  390. return itemLua
  391. end
  392. return UIHundredDojoChallengeView