UIPartnerLvUpView.lua 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. local UIPartnerLvUpView = require("UIRoleMain/UIPartnerLvUpView_Generate")
  2. local ColorExtension = require("ColorExtension")
  3. local oldAttrs = {}
  4. local newAttrs = {}
  5. local lackLvUp = false
  6. local lackCoin = false
  7. local lackAdvance = false
  8. function UIPartnerLvUpView:OnAwake(data)
  9. self.controller = require("UIRoleMain/UIPartnerLvUpCtr"):new()
  10. self.controller:Init(self)
  11. self.controller:SetData(data)
  12. end
  13. function UIPartnerLvUpView:AddEventListener()
  14. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.REFRESH_TRAIN_ATTRS, function()
  15. self:LvUpSuccessDisplay()
  16. self:Refresh()
  17. --self:RereshLvUpRP()
  18. end)
  19. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.ADVENCE_SUCCESS, function()
  20. self:RefreshAdvenceSuccessWnd()
  21. self:Refresh()
  22. end)
  23. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.ACTOR_SERVER_CHANGE_ATTRS, function(tbArrtDeffrent)
  24. --LogError(Inspect(tbArrtDeffrent))
  25. self:Refresh()
  26. end)
  27. end
  28. function UIPartnerLvUpView:FillContent(data, uiBase)
  29. self.uiBase = uiBase
  30. local gameObject = self.uiBase:GetRoot()
  31. if gameObject ~= nil then
  32. self.gameObject = gameObject
  33. self.transform = gameObject.transform
  34. end
  35. self:InitGenerate(self.transform, data)
  36. self:Init()
  37. end
  38. function UIPartnerLvUpView:Init()
  39. self:Refresh()
  40. end
  41. function UIPartnerLvUpView:LvUpSuccessDisplay()
  42. --self.fx_ui_lv_up.uIParticle:PlayCachedParticalSystem(false)
  43. self.fx_ui_lv_up.uIParticle:PlayCachedParticalSystem(true)
  44. end
  45. function UIPartnerLvUpView:RereshLvUpRP()
  46. local logicData = self.controller:GetHeroLogicData()
  47. local lvData = ManagerContainer.CfgMgr:GetParterAttributeByLv(logicData.baseLevel)
  48. local maxLv = self.controller:GetPartnerCurMaxLv()
  49. local ownExp = ManagerContainer.DataMgr.UserData:GetHeroExp()
  50. local stepData = self.controller:GetHeroStepData()
  51. self.popLvUp.btnLvUp.redPoint1:SetActive(logicData.baseLevel < maxLv and lvData.Exp < ownExp and (stepData == nil and true or logicData.advanceLevel <= #stepData.AddLv))
  52. end
  53. function UIPartnerLvUpView:Refresh()
  54. local logicData = self.controller:GetHeroLogicData()
  55. local cfgData = ManagerContainer.CfgMgr:GetPartnerDataById(logicData.configId)
  56. --HeroHeadIcon:SetInactivationHeroIcon(self, cfgData, self.popLvUp.headItem, logicData)
  57. local curMaxLv, advenceMaxLv = self.controller:GetPartnerCurMaxLv()
  58. -- local maxLv = advenceMaxLv or curMaxLv
  59. local maxLv = advenceMaxLv
  60. if advenceMaxLv == nil or curMaxLv > advenceMaxLv then
  61. maxLv = curMaxLv
  62. end
  63. local stepData = self.controller:GetHeroStepData()
  64. if logicData.baseLevel >= maxLv and logicData.advanceLevel >= #stepData.AddLv then
  65. --self.popLvUp:SetActive(false)
  66. --self.popLvOK.animator:Play("PopWindowOut")
  67. self.AnyBtn.button.onClick:Invoke()
  68. return
  69. end
  70. local actorData = ManagerContainer.LuaActorDataMgr:GetActorsById(logicData.id);
  71. CommonUtil.SetPlayerHeadAndFrame(self, self.popLvUp.headItem, actorData,false,actorData.HeadFrameId)
  72. self.popLvUp.nameText.uILocalizeScript:SetContent(cfgData.Name)
  73. local curLv = logicData.baseLevel
  74. self.popLvUp.lV.number.text.text = CommonUtil.StringConcat(curLv, "/", maxLv)
  75. --for i = 1, 5 do
  76. -- self.popLvUp.grid["step"..i]:SetActive(false)
  77. --end
  78. self.evolution:SetActive(stepData ~= nil)
  79. if stepData ~= nil then
  80. for i = 1, #stepData.AddLv do
  81. local num = math.floor((i- 1) / 5) + 1
  82. local idx = (i - 1) % 5 + 1
  83. local num1 = math.floor((logicData.advanceLevel - 1) / 5 + 1)
  84. local idx1 = (logicData.advanceLevel - 1) % 5 + 1
  85. local step = self.popLvUp.grid["step"..idx]
  86. --LogError("前 num = "..num)
  87. num = num > 5 and 5 or num
  88. num1 = num1 > 5 and 5 or num1
  89. --LogError("num = "..num)
  90. if num < num1 then
  91. step["ic"..num]:SetActive(true)
  92. elseif num == num1 then
  93. step["ic"..num]:SetActive(idx <= idx1)
  94. else
  95. step["ic"..num]:SetActive(false)
  96. end
  97. end
  98. end
  99. for i = 1, 5 do
  100. local attr = self.popLvUp["attr"..i]
  101. attr:SetActive(false)
  102. end
  103. local dic = ManagerContainer.LuaActorDataMgr:GetLvUpLocalPreviewSecondAttrVal(
  104. logicData.id,
  105. logicData.baseLevel
  106. )
  107. if dic == nil then
  108. LogError("cant find follew "..logicData.id)
  109. return
  110. end
  111. local iter = dic:GetEnumerator()
  112. local curAttrs = {}
  113. while iter:MoveNext() do
  114. curAttrs[iter.Current.Key] = iter.Current.Value
  115. end
  116. local dic = ManagerContainer.LuaActorDataMgr:GetLvUpPreviewSecondAttrVal(
  117. logicData.id,
  118. logicData.baseLevel
  119. )
  120. local iter = dic:GetEnumerator()
  121. local SverCurAttrs = {}
  122. while iter:MoveNext() do
  123. SverCurAttrs[iter.Current.Key] = iter.Current.Value
  124. end
  125. if logicData.baseLevel < maxLv then
  126. --升级
  127. local dic = ManagerContainer.LuaActorDataMgr:GetLvUpLocalPreviewSecondAttrVal(
  128. logicData.id,
  129. logicData.baseLevel + 1
  130. )
  131. local iter = dic:GetEnumerator()
  132. local newAttrs = {}
  133. while iter:MoveNext() do
  134. --下一级服务器属性 = 服务器当前 + (本地下一级 - 本地当前) 客户端属性有一部分没有 只算改变差值
  135. local Attr = SverCurAttrs[iter.Current.Key] +
  136. iter.Current.Value - curAttrs[iter.Current.Key]
  137. newAttrs[iter.Current.Key] = math.floor(Attr)
  138. end
  139. self.popLvUp.lVLimit.text.text.text = I18N.T("LV")
  140. self.popLvUp.lVLimit.number1.text.text = logicData.baseLevel
  141. self.popLvUp.lVLimit.number2.text.text = logicData.baseLevel + 1
  142. self.popLvUp.lVLimit:SetActive(true)
  143. local idx = 0
  144. for k,v in pairs(newAttrs) do
  145. if k == Enum.HeroAttrType.Life or (k >= Enum.HeroAttrType.Attack and k <= Enum.HeroAttrType.MagicDefense) then
  146. idx = idx + 1
  147. if idx > 5 then
  148. break
  149. end
  150. local attr = self.popLvUp["attr"..idx]
  151. if attr then
  152. local val = math.floor(SDataUtil.InvConvert(v))
  153. local val1 = math.floor(SverCurAttrs[k])
  154. attr.text.text.text = I18N.T("Attr_" .. k)
  155. attr.number1.text.text = val1
  156. attr.number2.text.text = val
  157. if k == Enum.HeroAttrType.Attack or k == Enum.HeroAttrType.MagicAttack then
  158. attr:SetActive(val ~= val1 and cfgData.JobType ~= 4 and cfgData.JobType ~= 5)
  159. else
  160. attr:SetActive(val ~= val1)
  161. end
  162. end
  163. end
  164. end
  165. self:RefreshTrainCost()
  166. else
  167. local nextMaxLv = self.controller:GetPartnerNextMaxLv()
  168. local stepData = self.controller:GetHeroStepData()
  169. self.popLvUp.lVLimit.text.text.text = I18N.T("LVLimit")
  170. self.popLvUp.lVLimit.number1.text.text = curMaxLv
  171. self.popLvUp.lVLimit:SetActive(true)
  172. local data = stepData["Attribute"..(logicData.advanceLevel + 1)]
  173. if data == nil then
  174. self.popLvUp.lVLimit.number2.text.text = "--"
  175. local idx = 0
  176. for k,v in pairs(SverCurAttrs) do
  177. idx = idx + 1
  178. if idx > 1 then
  179. break
  180. end
  181. local attr = self.popLvUp["attr"..idx]
  182. if attr then
  183. local val = math.floor(SverCurAttrs[k])
  184. attr.text.text.text = I18N.T("Attr_" .. k)
  185. attr.number1.text.text = val
  186. attr.number2.text.text = "--"
  187. attr:SetActive(true)
  188. end
  189. end
  190. else
  191. self.popLvUp.lVLimit.number2.text.text = nextMaxLv
  192. local idx = 0
  193. for k,v in pairs(data) do
  194. idx = idx + 1
  195. if idx > 5 then
  196. break
  197. end
  198. local attr = self.popLvUp["attr"..idx]
  199. if attr then
  200. local val = math.floor(SverCurAttrs[v[1]])
  201. attr.text.text.text = I18N.T("Attr_" .. v[1])
  202. attr.number1.text.text = val
  203. attr.number2.text.text = val + v[2]
  204. attr:SetActive(true)
  205. end
  206. end
  207. end
  208. end
  209. local canAdvence = self.controller:CanAdvence()
  210. self.popLvUp.btnLvUp:SetActive(not canAdvence and logicData.owned and logicData.baseLevel < maxLv)
  211. self.popLvUp.btnAdvance:SetActive(canAdvence)
  212. if canAdvence then
  213. self:RefreshAdvenceCost()
  214. end
  215. self:RefreshSkillRecommend()
  216. --self:RereshLvUpRP()
  217. end
  218. function UIPartnerLvUpView:RefreshTrainCost()
  219. local logicData = self.controller:GetHeroLogicData()
  220. local lvData = ManagerContainer.CfgMgr:GetParterAttributeByLv(logicData.baseLevel)
  221. local ownExp = ManagerContainer.DataMgr.UserData:GetHeroExp()
  222. local num = CommonUtil.FormatNumber(lvData.Exp)
  223. self.popLvUp.cost.number.text.text = num
  224. lackLvUp = ownExp < lvData.Exp
  225. CommonUtil.IsConditionOutColor(self.popLvUp.cost.number.text, lvData.Exp > ownExp, num)
  226. end
  227. function UIPartnerLvUpView:RefreshSkillRecommend()
  228. local skillPreview = self.popLvUp.skillPreview
  229. local lv, skillType, skillId = CommonUtil.FindNextUnlockSkill(self.controller:GetData())
  230. if self.recommendSkillId == nil and skillId == nil then
  231. skillPreview:SetActive(false)
  232. return
  233. end
  234. if self.recommendSkillId == skillId then return end
  235. if self.recommendSkillId ~= nil then
  236. self:RefreshUnLockNewSkill(self.recommendSkillType, self.recommendSkillId)
  237. end
  238. self.recommendSkillId = skillId
  239. self.recommendSkillType = skillType
  240. if skillId == nil then
  241. skillPreview:SetActive(false)
  242. return
  243. end
  244. skillPreview.skillItem.icon.image.sprite = nil
  245. local skillCfgData
  246. if skillType and skillId then
  247. skillCfgData = ManagerContainer.CfgMgr:GetSkillCfgByType(skillType, skillId, 1)
  248. end
  249. if skillCfgData then
  250. skillPreview:SetActive(true)
  251. skillPreview.text.text.text = I18N.SetLanguageValue('UnRockSkill', lv)
  252. CommonUtil.LoadIcon(self, skillCfgData.Icon, function (sprite)
  253. skillPreview.skillItem.icon.image.sprite = sprite
  254. end, self, "SkillPreviewIconAsyncIdx")
  255. skillPreview.skillItem.num.text.text = (I18N.SetLanguageValue('Lv') .. tostring(1))
  256. skillPreview.skillName.text.text = I18N.SetLanguageValue(skillCfgData.Name)
  257. local skillCfgId = CommonUtil.GetSkillCfgIdByIdAndLv(skillId, 1)
  258. local skillLevelCfgData = ManagerContainer.CfgMgr:GetSkillLevelCfgById(skillCfgId)
  259. if skillLevelCfgData then
  260. if skillLevelCfgData.DescParam then
  261. if type(skillLevelCfgData.DescParam) == 'table' then
  262. skillPreview.textDsc.text.text = string.formatbykey(skillLevelCfgData.Desc, unpack(skillLevelCfgData.DescParam))
  263. else
  264. skillPreview.textDsc.text.text = string.formatbykey(skillLevelCfgData.Desc, skillLevelCfgData.DescParam)
  265. end
  266. else
  267. skillPreview.textDsc.text.text = string.formatbykey(skillLevelCfgData.Desc)
  268. end
  269. else
  270. skillPreview.textDsc.text.text = ''
  271. end
  272. else
  273. skillPreview:SetActive(false)
  274. skillPreview.skillItem.num.text.text = ''
  275. skillPreview.skillName.text.text = ''
  276. skillPreview.textDsc.text.text = ''
  277. end
  278. end
  279. function UIPartnerLvUpView:RefreshUnLockNewSkill(skillType, skillId)
  280. local skillCfgData = ManagerContainer.CfgMgr:GetSkillCfgByType(skillType, skillId, 1)
  281. if skillCfgData == nil then return end
  282. local item = self.skillPreviewItem
  283. CommonUtil.LoadIcon(self, skillCfgData.Icon, function (sprite)
  284. item.skillItem.icon.image.sprite = sprite
  285. end, self, "SkillPreview1IconAsyncIdx")
  286. item.skillItem.num.text.text = (I18N.SetLanguageValue('Lv') .. tostring(1))
  287. item.skillName.text.text = I18N.SetLanguageValue(skillCfgData.Name)
  288. local skillCfgId = CommonUtil.GetSkillCfgIdByIdAndLv(skillId, 1)
  289. local skillLevelCfgData = ManagerContainer.CfgMgr:GetSkillLevelCfgById(skillCfgId)
  290. if skillLevelCfgData then
  291. if skillLevelCfgData.DescParam then
  292. if type(skillLevelCfgData.DescParam) == 'table' then
  293. item.desText.text.text = string.formatbykey(skillLevelCfgData.Desc, unpack(skillLevelCfgData.DescParam))
  294. else
  295. item.desText.text.text = string.formatbykey(skillLevelCfgData.Desc, skillLevelCfgData.DescParam)
  296. end
  297. else
  298. item.desText.text.text = string.formatbykey(skillLevelCfgData.Desc)
  299. end
  300. else
  301. item.desText.text.text = ''
  302. end
  303. local skillShowData = ManagerContainer.CfgMgr:GetSkillShowCfgById(skillId)
  304. local tags = nil
  305. local num = 0
  306. if skillShowData then
  307. tags = skillShowData.Label
  308. if tags then
  309. if type(tags[1]) == 'number' then
  310. tags = {tags}
  311. end
  312. num = #tags
  313. end
  314. end
  315. for i = 1, 4 do
  316. local skillTagItem = item['skillTagItem' .. i]
  317. if skillTagItem then
  318. if i <= num then
  319. local tagId = tags[i][1]
  320. local colorId = tags[i][2]
  321. skillTagItem:SetActive(true)
  322. skillTagItem.bgColorID.image.color = ColorExtension.HexStringToColor(I18N.SetLanguageValue('ColorID' .. tostring(colorId)))
  323. skillTagItem.textSkillID.uILocalizeScript:SetContent('SkillTagID' .. tostring(tagId))
  324. else
  325. skillTagItem:SetActive(false)
  326. end
  327. end
  328. end
  329. self.popSkillUnlock:SetActive(true)
  330. end
  331. function UIPartnerLvUpView:RefreshAdvenceCost()
  332. local logicData = self.controller:GetHeroLogicData()
  333. local stepData = self.controller:GetHeroStepData()
  334. local ownCoin = ManagerContainer.DataMgr.UserData:GetOwnCoin()
  335. local num = logicData.advanceLevel + 1 <= #stepData.CostMoney and CommonUtil.FormatNumber(stepData.CostMoney[logicData.advanceLevel + 1]) or 0
  336. self.popLvUp.cost1.number.text.text = num
  337. if logicData.advanceLevel + 1 <= #stepData.CostMoney then
  338. lackCoin = ownCoin < stepData.CostMoney[logicData.advanceLevel + 1]
  339. CommonUtil.IsConditionOutColor(self.popLvUp.cost1.number.text, stepData.CostMoney[logicData.advanceLevel + 1] > ownCoin, num)
  340. end
  341. local stoneData = ManagerContainer.CfgMgr:GetItemById(Enum.ItemIndex.PartnerStone)
  342. CommonUtil.LoadIcon(self, stoneData.Icon, function (sprite)
  343. self.popLvUp.cost2.icon.image.sprite = sprite
  344. end)
  345. local ownStone = CommonUtil.GetOwnResCountByItemId(Enum.ItemIds.AngelTear)
  346. local num = logicData.advanceLevel + 1 <= #stepData.CostStone and CommonUtil.FormatNumber(stepData.CostStone[logicData.advanceLevel + 1]) or 0
  347. self.popLvUp.cost2.number.text.text = num
  348. if logicData.advanceLevel + 1 <= #stepData.CostMoney then
  349. lackAdvance = ownStone < stepData.CostStone[logicData.advanceLevel + 1]
  350. CommonUtil.IsConditionOutColor(self.popLvUp.cost2.number.text, stepData.CostStone[logicData.advanceLevel + 1] > ownStone, num)
  351. end
  352. end
  353. function UIPartnerLvUpView:RefreshAdvenceSuccessWnd()
  354. local curMaxLv = self.controller:GetPartnerCurMaxLv()
  355. local lastMaxLv = self.controller:GetPartmerLastMaxLv()
  356. local stepData = self.controller:GetHeroStepData()
  357. local logicData = self.controller:GetHeroLogicData()
  358. local headLua = self.popEvolutionOK.headItem
  359. local actorData = ManagerContainer.LuaActorDataMgr:GetActorsById(logicData.id);
  360. CommonUtil.SetPlayerHeadAndFrame(self, headLua, actorData,false,actorData.HeadFrameId)
  361. local data = stepData["Attribute"..logicData.advanceLevel]
  362. if data == nil then
  363. LogError(logicData.configId.." 伙伴上一阶 "..(logicData.advanceLevel - 1).." 进阶属性错误")
  364. end
  365. -- for i = 1, self.popEvolutionOK.grid.transform.childCount do
  366. -- self.popEvolutionOK.grid.transform:GetChild(i - 1).gameObject:SetActive(false)
  367. -- end
  368. self.popEvolutionOK.grid:SetActive(stepData ~= nil)
  369. if stepData ~= nil then
  370. for i = 1, #stepData.AddLv do
  371. local num = math.floor((i- 1) / 5) + 1
  372. local idx = (i - 1) % 5 + 1
  373. local num1 = math.floor((logicData.advanceLevel - 1) / 5 + 1)
  374. local idx1 = (logicData.advanceLevel - 1) % 5 + 1
  375. local step = self.popEvolutionOK.grid["step"..idx]
  376. num = num > 5 and 5 or num
  377. num1 = num1 > 5 and 5 or num1
  378. if num < num1 then
  379. step["ic"..num]:SetActive(true)
  380. elseif num == num1 then
  381. step["ic"..num]:SetActive(idx <= idx1)
  382. else
  383. step["ic"..num]:SetActive(false)
  384. end
  385. end
  386. end
  387. self.popEvolutionOK.lVLimit.number1.text.text = lastMaxLv
  388. self.popEvolutionOK.lVLimit.number2.text.text = curMaxLv
  389. self.popEvolutionOK.lVLimit:SetActive(true)
  390. for i = 1, 5 do
  391. local attr = self.popEvolutionOK["attr"..i]
  392. attr:SetActive(data[i] ~= nil)
  393. if data[i] then
  394. local val = math.floor(SDataUtil.InvConvert(logicData.attrs[data[i][1]]))
  395. attr.text.text.text = I18N.T("Attr_" .. data[i][1])
  396. attr.number1.text.text = val
  397. attr.number2.text.text = data[i][2] + val
  398. end
  399. end
  400. self.popEvolutionOK:SetActive(true)
  401. end
  402. function UIPartnerLvUpView:RemoveEventListener()
  403. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  404. end
  405. function UIPartnerLvUpView:AddUIEventListener()
  406. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  407. self.popLvUp.btnLvUp.repeatButton:AddRepeatClickEventListener(function (index, isOver)
  408. if lackLvUp then
  409. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("LackExpPartner")
  410. return
  411. end
  412. self.controller:PartnerLvUpReq(self.controller:GetHeroLogicId())
  413. end)
  414. self.uiBase:AddButtonEventListener(self.popLvUp.btnAdvance.button, function ()
  415. if lackCoin then
  416. CommonUtil.ItemNotEnoughHandle(Enum.ItemType.Coin)
  417. return
  418. end
  419. if lackAdvance then
  420. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("LackAngelsTears")
  421. return
  422. end
  423. self.controller:PartnerAdvenceLvUpReq(self.controller:GetHeroLogicId())
  424. end)
  425. self.uiBase:AddButtonEventListener(self.AnyBtn.button, function ()
  426. self:UIClose()
  427. end)
  428. self.uiBase:AddButtonEventListener(self.popLvUp.btnClose.button, function ()
  429. self:UIClose()
  430. end)
  431. end
  432. function UIPartnerLvUpView:OnHide()
  433. end
  434. function UIPartnerLvUpView:OnShow(data)
  435. self.controller:SetData(data)
  436. end
  437. function UIPartnerLvUpView:OnClose()
  438. end
  439. function UIPartnerLvUpView:OnDispose()
  440. self.controller:OnDispose()
  441. end
  442. return UIPartnerLvUpView