UIStampLvUpView.lua 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. local UIStampLvUpView = require("UIPet/UIStampLvUpView_Generate")
  2. local IconItemCtr = require("Common/IconItemCtr")
  3. local lastCfgId = 0
  4. local isMaxLv = false
  5. local canAdvance = false
  6. local lackCostId
  7. function UIStampLvUpView:OnAwake(data)
  8. self.controller = require("UIPet/UIStampLvUpCtr"):new()
  9. self.controller:Init(self)
  10. self.controller:SetData(data)
  11. end
  12. function UIStampLvUpView:AddEventListener()
  13. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  14. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.PET_STAMP_LEVEL_UP_REFRESH, self, self.OnLvUpNtf)
  15. end
  16. function UIStampLvUpView:FillContent(data, uiBase)
  17. self.uiBase = uiBase
  18. local gameObject = self.uiBase:GetRoot()
  19. if gameObject ~= nil then
  20. self.gameObject = gameObject
  21. self.transform = gameObject.transform
  22. end
  23. self:InitGenerate(self.transform, data)
  24. self:Init()
  25. end
  26. function UIStampLvUpView:Init()
  27. self:Refresh()
  28. end
  29. function UIStampLvUpView:Refresh()
  30. local stampData = self.controller:GetStampData()
  31. if not stampData then
  32. return
  33. end
  34. local cfgData = ManagerContainer.CfgMgr:GetPetEquipCfgDataById(stampData.cfgId)
  35. if not cfgData then
  36. return
  37. end
  38. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(stampData.cfgId)
  39. if not itemCfgData then
  40. return
  41. end
  42. local lvCfgData = ManagerContainer.CfgMgr:GetPetEquipExpCfgDataByLvAndCfgId(stampData.lv, stampData.cfgId)
  43. if not lvCfgData then
  44. return
  45. end
  46. local nextLvCfgData = ManagerContainer.CfgMgr:GetPetEquipExpCfgDataByLvAndCfgId(stampData.lv + 1, stampData.cfgId)
  47. local nextStampLvCfgData = ManagerContainer.CfgMgr:GetPetEquipExpCfgDataByLvAndCfgId(1, cfgData.Advance)
  48. lastCfgId = stampData.cfgId
  49. IconItemCtr:SetData(self, self.popLvUp.iconItem, stampData)
  50. self.popLvUp.nameText.uILocalizeScript:SetContent(cfgData.Name)
  51. self.popLvUp.lV.number.text.text = stampData.lv .."/"..cfgData.MaxLevel
  52. isMaxLv = stampData.lv >= cfgData.MaxLevel
  53. canAdvance = cfgData.Advance > 0
  54. local nextCfgData = ManagerContainer.CfgMgr:GetPetEquipCfgDataById(cfgData.Advance)
  55. local nextCfgName = nextCfgData and nextCfgData.Name or ""
  56. self.popLvUp.lVLimit.text.text.text = I18N.T("LV")
  57. self.popLvUp.lVLimit.number1.text.text = I18N.T(cfgData.Name)
  58. for i = 1, 5 do
  59. local attr = lvCfgData.Nature[i]
  60. local attrItem = self.popLvUp["attr"..i]
  61. attrItem:SetActive(attr ~= nil)
  62. if attr ~= nil then
  63. local val = attr[2]
  64. attrItem.text.text.text = I18N.T("Attr_" .. attr[1])
  65. attrItem.number1.text.text = val
  66. attrItem.number2:SetActive(canAdvance or (not canAdvance and not isMaxLv))
  67. attrItem.image:SetActive(canAdvance or (not canAdvance and not isMaxLv))
  68. if isMaxLv then
  69. if canAdvance then
  70. local val1 = nextStampLvCfgData.Nature[i] and nextStampLvCfgData.Nature[i][2] or 0
  71. attrItem.number2.text.text = val1
  72. end
  73. else
  74. local val1 = nextLvCfgData.Nature[i] and nextLvCfgData.Nature[i][2] or 0
  75. attrItem.number2.text.text = val1
  76. end
  77. end
  78. end
  79. self.popLvUp.lVLimit:SetActive(isMaxLv)
  80. self.popLvUp.lVLimit.text:SetActive(not isMaxLv)
  81. self.popLvUp.lVLimit.image:SetActive(canAdvance or (not canAdvance and not isMaxLv))
  82. self.popLvUp.lVLimit.number2:SetActive(canAdvance or (not canAdvance and not isMaxLv))
  83. if canAdvance then
  84. self.popLvUp.lVLimit.number2.text.text = isMaxLv and I18N.T(nextCfgName) or I18N.T(cfgData.Name)
  85. end
  86. if not isMaxLv then
  87. local lvCfgData = ManagerContainer.CfgMgr:GetPetEquipExpCfgDataByLvAndCfgId(stampData.lv, stampData.cfgId)
  88. local costs = lvCfgData.Cost
  89. self:RefresCost(costs, false)
  90. elseif isMaxLv and canAdvance then
  91. local costs = cfgData.AdvanceCost
  92. self:RefresCost(costs, true)
  93. end
  94. self.cost:SetActive(canAdvance or (not canAdvance and not isMaxLv))
  95. self.popLvUp.btnLvUp:SetActive(not isMaxLv)
  96. self.popLvUp.btnAdvance:SetActive(isMaxLv and canAdvance)
  97. self.popLvUp.max:SetActive(isMaxLv and not canAdvance)
  98. end
  99. function UIStampLvUpView:RefresCost(costs, isAdvence)
  100. if not costs then
  101. self.cost1:SetActive(false)
  102. self.cost1:SetActive(false)
  103. return
  104. end
  105. for i = 1, 2 do
  106. local cost = costs[i]
  107. local costItem = self["cost"..i]
  108. costItem:SetActive(cost ~= nil)
  109. if cost then
  110. local cfgData = ManagerContainer.CfgMgr:GetItemById(cost[1])
  111. local costTb = tolua.getpeer(costItem)
  112. CommonUtil.LoadIcon(self, cfgData.Icon, function (sprite)
  113. costItem.icon.image.sprite = sprite
  114. end, costTb, "costIcon")
  115. local ownCount = CommonUtil.GetOwnResCountByItemId(cost[1])
  116. if not isAdvence then
  117. costItem.number.text.text = CommonUtil.FormatNumber(cost[2])
  118. CommonUtil.IsConditionOutColor(costItem.number.text, cost[2] > ownCount, cost[2])
  119. else
  120. local str = cost[1] ~= Enum.ItemType.Coin and ownCount.."/"..cost[2] or CommonUtil.FormatNumber(cost[2])
  121. costItem.number.text.text = str
  122. CommonUtil.IsConditionOutColor(costItem.number.text, cost[2] > ownCount, str)
  123. end
  124. if not lackCostId and cost[2] > ownCount then
  125. lackCostId = cost[1]
  126. end
  127. end
  128. end
  129. end
  130. function UIStampLvUpView:RefreshAdvanceSusccess()
  131. local stampData = self.controller:GetStampData()
  132. if not stampData then
  133. return
  134. end
  135. local cfgData = ManagerContainer.CfgMgr:GetPetEquipCfgDataById(stampData.cfgId)
  136. if not cfgData then
  137. return
  138. end
  139. local lastCfgData = ManagerContainer.CfgMgr:GetPetEquipCfgDataById(lastCfgId)
  140. if not lastCfgData then
  141. return
  142. end
  143. local lastStampLvCfgData = ManagerContainer.CfgMgr:GetPetEquipExpCfgDataByLvAndCfgId(lastCfgData.MaxLevel, lastCfgId)
  144. local stampLvCfgData = ManagerContainer.CfgMgr:GetPetEquipExpCfgDataByLvAndCfgId(1, stampData.cfgId)
  145. IconItemCtr:SetData(self, self.popEvolutionOK.iconItem, stampData)
  146. self.popEvolutionOK.lVLimit.number1.text.text = I18N.T(lastCfgData.Name)
  147. for i = 1, 5 do
  148. local attr = lastStampLvCfgData.Nature[i]
  149. local nextAttr = stampLvCfgData.Nature[i]
  150. local attrItem = self.popEvolutionOK["attr"..i]
  151. attrItem:SetActive(attr ~= nil)
  152. if attr ~= nil then
  153. local val = attr[2]
  154. attrItem.text.text.text = I18N.T("Attr_" .. attr[1])
  155. attrItem.number1.text.text = val
  156. local val1 = nextAttr[2]
  157. attrItem.number2.text.text = val1
  158. end
  159. end
  160. self.popEvolutionOK.lVLimit.number2.text.text = I18N.T(cfgData.Name)
  161. self.popEvolutionOK:SetActive(true)
  162. self.popLvUp:SetActive(false)
  163. end
  164. function UIStampLvUpView:RemoveEventListener()
  165. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  166. end
  167. function UIStampLvUpView:AddUIEventListener()
  168. self.uiBase:AddButtonEventListener(self.AnyBtn.button, self, self.OnCloseClick)
  169. self.uiBase:AddButtonEventListener(self.popLvUp.btnClose.button, self, self.OnCloseClick)
  170. self.uiBase:AddButtonEventListener(self.popEvolutionOK.AnyBtn.button, self, self.OnOkCloseClick)
  171. self.uiBase:AddButtonEventListener(self.popLvUp.btnLvUp.button, self, self.OnLvUpClick)
  172. self.uiBase:AddButtonEventListener(self.popLvUp.btnAdvance.button, self, self.OnAdvanceClick)
  173. end
  174. function UIStampLvUpView:OnCloseClick()
  175. self:UIClose()
  176. end
  177. function UIStampLvUpView:OnOkCloseClick()
  178. self.popLvUp:SetActive(true)
  179. self.popEvolutionOK:SetActive(false)
  180. end
  181. function UIStampLvUpView:OnLvUpClick()
  182. if isMaxLv then
  183. return
  184. end
  185. if lackCostId then
  186. ManagerContainer.LuaUIMgr:ErrorNoticeDisplayWithParam(CommonUtil.GetItemNotEnoughInfo(lackCostId))
  187. end
  188. self.controller:SendLvUp()
  189. end
  190. function UIStampLvUpView:OnAdvanceClick()
  191. if not canAdvance then
  192. return
  193. end
  194. if lackCostId then
  195. ManagerContainer.LuaUIMgr:ErrorNoticeDisplayWithParam(CommonUtil.GetItemNotEnoughInfo(lackCostId))
  196. end
  197. self.controller:SendAdvance()
  198. end
  199. function UIStampLvUpView:LvUpSuccessDisplay()
  200. --self.fx_ui_lv_up.uIParticle:PlayCachedParticalSystem(false)
  201. self.fx_ui_lv_up.uIParticle:PlayCachedParticalSystem(true)
  202. end
  203. function UIStampLvUpView:OnLvUpNtf()
  204. lackCostId = nil
  205. local state = self.controller:GetState()
  206. if state == 1 then
  207. self:LvUpSuccessDisplay()
  208. elseif state == 2 then
  209. self:RefreshAdvanceSusccess()
  210. end
  211. self:Refresh()
  212. self.controller:ClearState()
  213. end
  214. function UIStampLvUpView:OnHide()
  215. end
  216. function UIStampLvUpView:OnShow(data)
  217. self.controller:SetData(data)
  218. end
  219. function UIStampLvUpView:OnClose()
  220. end
  221. function UIStampLvUpView:OnDispose()
  222. self.controller:OnDispose()
  223. end
  224. return UIStampLvUpView