UIBoliShopUpLvTipsView.lua 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. local UIBoliShopUpLvTipsView = require("UIRuneShop/UIBoliShopUpLvTipsView_Generate")
  2. function UIBoliShopUpLvTipsView:OnAwake(data)
  3. self.controller = require("UIRuneShop/UIBoliShopUpLvTipsCtr"):new()
  4. self.controller:Init(self)
  5. self.controller:SetData(data)
  6. end
  7. function UIBoliShopUpLvTipsView:AddEventListener()
  8. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  9. end
  10. function UIBoliShopUpLvTipsView:FillContent(data, uiBase)
  11. self.uiBase = uiBase
  12. local gameObject = self.uiBase:GetRoot()
  13. if gameObject ~= nil then
  14. self.gameObject = gameObject
  15. self.transform = gameObject.transform
  16. end
  17. self:InitGenerate(self.transform, data)
  18. self:Init()
  19. end
  20. function UIBoliShopUpLvTipsView:Init()
  21. self.curExp = ManagerContainer.DataMgr.BoliShopData:GetCurExp()
  22. self.curLv = ManagerContainer.DataMgr.BoliShopData:GetCurLv()
  23. local BoliVipCfg = ManagerContainer.CfgMgr:GetBoliVipCfg()
  24. self.maxCfgData = BoliVipCfg[#BoliVipCfg]
  25. local maxcfgData = BoliVipCfg[#BoliVipCfg - 1]
  26. if maxcfgData then
  27. self.maxExp = maxcfgData.VipExp
  28. end
  29. self.allExpData = self:InitAllExpData(BoliVipCfg)
  30. self.curCfgData = ManagerContainer.CfgMgr:GetBoLiVipCfgById(self.curLv)
  31. local table = GlobalConfig.Instance:GetConfigStrValue(358)
  32. local ratetab = CommonUtil.DeserializeGlobalStrToNumberTable(table)
  33. self.rate = ratetab and ratetab [1] and ratetab[1][1] or 1
  34. self.maxNum = self:RefreshMaxNum()
  35. self:InitSliderUI()
  36. end
  37. function UIBoliShopUpLvTipsView:InitAllExpData(data)
  38. local tab = {}
  39. if data then
  40. for k, v in pairs(data) do
  41. table.insert(tab,v.VipExp)
  42. end
  43. end
  44. table.sort(tab)
  45. return tab
  46. end
  47. function UIBoliShopUpLvTipsView:InitSliderUI()
  48. if self.maxNum == 0 then
  49. self.numBox.slider.slider.maxValue = 1
  50. else
  51. self.numBox.slider.slider.maxValue = self.maxNum
  52. end
  53. self:RefreshSliderUI(1)
  54. end
  55. function UIBoliShopUpLvTipsView:RefreshSliderUI(val)
  56. if self.maxNum == 0 then
  57. self.numBox.slider.slider.value = 1
  58. self.btnUpgrade.number.text.text = string.format(Constant.RedColorText,1)
  59. self.numBox.num.text.text = tostring(1)
  60. else
  61. self.numBox.slider.slider.value = val
  62. self.btnUpgrade.number.text.text = string.format(val * self.rate)
  63. self.numBox.num.text.text = tostring(val)
  64. end
  65. local value = self.numBox.slider.slider.value
  66. local exp = (self.curCfgData.Lv == self.maxCfgData.Lv) and self.maxExp or self.curCfgData.VipExp
  67. self.expYellow.image.fillAmount = self.curExp / exp
  68. self.expGreen.image.fillAmount = (self.curExp + value)*1.0 / exp
  69. self.numexp.text.text = self.curExp + value .."/".. exp
  70. self.max:SetActive(self.curCfgData.Lv == self.maxCfgData.Lv)
  71. self.lvTxt.text.text = tostring(self.curCfgData.Lv)
  72. end
  73. function UIBoliShopUpLvTipsView:RefreshMaxNum()
  74. local roCoins = CommonUtil.GetOwnResCountByItemId(Enum.ItemType.ROCoin)
  75. local canUseroCoins = math.floor(roCoins/self.rate)
  76. local costExp = self.maxExp
  77. if canUseroCoins > (costExp - self.curExp) then
  78. return costExp - self.curExp
  79. else
  80. return canUseroCoins
  81. end
  82. end
  83. function UIBoliShopUpLvTipsView:RemoveEventListener()
  84. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  85. self.numBox.btnMinus.repeatButton:AddRepeatClickEventListener(nil, nil)
  86. self.numBox.btnPlus.repeatButton:AddRepeatClickEventListener(nil, nil)
  87. end
  88. function UIBoliShopUpLvTipsView:AddUIEventListener()
  89. self.uiBase:AddButtonUniqueEventListener(self.btnClose.button, self, self.OnClickCloseBtn)
  90. self.uiBase:AddButtonUniqueEventListener(self.AnyBtn.button, self, self.OnClickCloseBtn)
  91. self.uiBase:AddButtonUniqueEventListener(self.btnUpgrade.button, self, self.OnClickUpgradeBtn)
  92. -- self.uiBase:AddButtonEventListener(self.numBox.btnMinus.button,self, self.OnReduceClick)
  93. -- self.uiBase:AddButtonEventListener(self.numBox.btnPlus.button,self, self.OnSumClick)
  94. self.numBox.btnMinus.repeatButton:AddRepeatClickEventListener(self, self.OnReduceClick)
  95. self.numBox.btnPlus.repeatButton:AddRepeatClickEventListener(self, self.OnSumClick)
  96. self.numBox.slider.slider.onValueChanged:RemoveAllListeners()
  97. self.numBox.slider.slider.onValueChanged:AddListener(function(value)
  98. self:OnValueChangedSlider(value)
  99. end)
  100. end
  101. function UIBoliShopUpLvTipsView:OnValueChangedSlider(value)
  102. self:RefreshCurCfgData(value + self.curExp)
  103. if math.round(value) == 0 then
  104. self:RefreshSliderUI(1)
  105. return
  106. end
  107. self:RefreshSliderUI(math.round(value))
  108. end
  109. function UIBoliShopUpLvTipsView:OnClickUpgradeBtn()
  110. if self.maxNum == 0 then
  111. CommonUtil.ItemNotEnoughHandle(Enum.ItemType.ROCoin)
  112. else
  113. local value = self.numBox.slider.slider.value
  114. ManagerContainer.DataMgr.BoliShopData:SendBoliShopLevelUpReq(value)
  115. end
  116. self:OnClickCloseBtn()
  117. end
  118. function UIBoliShopUpLvTipsView:RefreshCurCfgData(lv)
  119. local tab = self.allExpData
  120. if tab then
  121. for i = 1, #tab - 1 do
  122. if lv < tab[i] then
  123. self.curCfgData = ManagerContainer.CfgMgr:GetBoLiVipCfgById(i - 2)
  124. break
  125. elseif tab[i] <= lv and tab[i + 1] > lv then
  126. self.curCfgData = ManagerContainer.CfgMgr:GetBoLiVipCfgById(i - 1)
  127. break
  128. elseif i == self.maxCfgData.Lv then
  129. self.curCfgData = ManagerContainer.CfgMgr:GetBoLiVipCfgById(i)
  130. break
  131. end
  132. end
  133. if not self.curCfgData then
  134. self.curCfgData = ManagerContainer.CfgMgr:GetBoLiVipCfgById(self.curLv)
  135. end
  136. end
  137. end
  138. function UIBoliShopUpLvTipsView:OnReduceClick()
  139. if self.maxNum == 0 then
  140. return
  141. end
  142. local val = self.numBox.slider.slider.value - 1
  143. if val <= 0 then
  144. return
  145. end
  146. self.numBox.slider.slider.value = val
  147. end
  148. function UIBoliShopUpLvTipsView:OnSumClick()
  149. if self.maxNum == 0 then
  150. return
  151. end
  152. local val = self.numBox.slider.slider.value + 1
  153. if val > self.maxNum then
  154. return
  155. end
  156. self.numBox.slider.slider.value = val
  157. end
  158. function UIBoliShopUpLvTipsView:OnHide()
  159. end
  160. function UIBoliShopUpLvTipsView:OnClickCloseBtn()
  161. ManagerContainer.LuaUIMgr:OpenSourceUI(self)
  162. end
  163. function UIBoliShopUpLvTipsView:OnShow(data)
  164. self.controller:SetData(data)
  165. end
  166. function UIBoliShopUpLvTipsView:OnClose()
  167. end
  168. function UIBoliShopUpLvTipsView:OnDispose()
  169. self.controller:OnDispose()
  170. self.numBox.slider.slider.onValueChanged:RemoveAllListeners()
  171. end
  172. return UIBoliShopUpLvTipsView