UIPartnerLvUpView.lua 16 KB

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