| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- local UIBoliShopUpLvTipsView = require("UIRuneShop/UIBoliShopUpLvTipsView_Generate")
- function UIBoliShopUpLvTipsView:OnAwake(data)
- self.controller = require("UIRuneShop/UIBoliShopUpLvTipsCtr"):new()
- self.controller:Init(self)
- self.controller:SetData(data)
- end
- function UIBoliShopUpLvTipsView:AddEventListener()
- ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
- end
- function UIBoliShopUpLvTipsView:FillContent(data, uiBase)
- self.uiBase = uiBase
- local gameObject = self.uiBase:GetRoot()
- if gameObject ~= nil then
- self.gameObject = gameObject
- self.transform = gameObject.transform
- end
- self:InitGenerate(self.transform, data)
- self:Init()
- end
- function UIBoliShopUpLvTipsView:Init()
- self.curExp = ManagerContainer.DataMgr.BoliShopData:GetCurExp()
- self.curLv = ManagerContainer.DataMgr.BoliShopData:GetCurLv()
- local BoliVipCfg = ManagerContainer.CfgMgr:GetBoliVipCfg()
- self.maxCfgData = BoliVipCfg[#BoliVipCfg]
- local maxcfgData = BoliVipCfg[#BoliVipCfg - 1]
- if maxcfgData then
- self.maxExp = maxcfgData.VipExp
- end
- self.allExpData = self:InitAllExpData(BoliVipCfg)
- self.curCfgData = ManagerContainer.CfgMgr:GetBoLiVipCfgById(self.curLv)
- local table = GlobalConfig.Instance:GetConfigStrValue(358)
- local ratetab = CommonUtil.DeserializeGlobalStrToNumberTable(table)
- self.rate = ratetab and ratetab [1] and ratetab[1][1] or 1
- self.maxNum = self:RefreshMaxNum()
- self:InitSliderUI()
- end
- function UIBoliShopUpLvTipsView:InitAllExpData(data)
- local tab = {}
- if data then
- for k, v in pairs(data) do
- table.insert(tab,v.VipExp)
- end
- end
- table.sort(tab)
- return tab
- end
- function UIBoliShopUpLvTipsView:InitSliderUI()
- if self.maxNum == 0 then
- self.numBox.slider.slider.maxValue = 1
- else
- self.numBox.slider.slider.maxValue = self.maxNum
- end
- self:RefreshSliderUI(1)
- end
- function UIBoliShopUpLvTipsView:RefreshSliderUI(val)
- if self.maxNum == 0 then
- self.numBox.slider.slider.value = 1
- self.btnUpgrade.number.text.text = string.format(Constant.RedColorText,1)
- self.numBox.num.text.text = tostring(1)
- else
- self.numBox.slider.slider.value = val
- self.btnUpgrade.number.text.text = string.format(val * self.rate)
- self.numBox.num.text.text = tostring(val)
- end
- local value = self.numBox.slider.slider.value
- local exp = (self.curCfgData.Lv == self.maxCfgData.Lv) and self.maxExp or self.curCfgData.VipExp
- self.expYellow.image.fillAmount = self.curExp / exp
- self.expGreen.image.fillAmount = (self.curExp + value)*1.0 / exp
- self.numexp.text.text = self.curExp + value .."/".. exp
- self.max:SetActive(self.curCfgData.Lv == self.maxCfgData.Lv)
- self.lvTxt.text.text = tostring(self.curCfgData.Lv)
- end
- function UIBoliShopUpLvTipsView:RefreshMaxNum()
- local roCoins = CommonUtil.GetOwnResCountByItemId(Enum.ItemType.ROCoin)
- local canUseroCoins = math.floor(roCoins/self.rate)
- local costExp = self.maxExp
- if canUseroCoins > (costExp - self.curExp) then
- return costExp - self.curExp
- else
- return canUseroCoins
- end
- end
- function UIBoliShopUpLvTipsView:RemoveEventListener()
- ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
- self.numBox.btnMinus.repeatButton:AddRepeatClickEventListener(nil, nil)
- self.numBox.btnPlus.repeatButton:AddRepeatClickEventListener(nil, nil)
- end
- function UIBoliShopUpLvTipsView:AddUIEventListener()
- self.uiBase:AddButtonUniqueEventListener(self.btnClose.button, self, self.OnClickCloseBtn)
- self.uiBase:AddButtonUniqueEventListener(self.AnyBtn.button, self, self.OnClickCloseBtn)
- self.uiBase:AddButtonUniqueEventListener(self.btnUpgrade.button, self, self.OnClickUpgradeBtn)
- -- self.uiBase:AddButtonEventListener(self.numBox.btnMinus.button,self, self.OnReduceClick)
- -- self.uiBase:AddButtonEventListener(self.numBox.btnPlus.button,self, self.OnSumClick)
- self.numBox.btnMinus.repeatButton:AddRepeatClickEventListener(self, self.OnReduceClick)
- self.numBox.btnPlus.repeatButton:AddRepeatClickEventListener(self, self.OnSumClick)
- self.numBox.slider.slider.onValueChanged:RemoveAllListeners()
- self.numBox.slider.slider.onValueChanged:AddListener(function(value)
- self:OnValueChangedSlider(value)
- end)
- end
- function UIBoliShopUpLvTipsView:OnValueChangedSlider(value)
- self:RefreshCurCfgData(value + self.curExp)
- if math.round(value) == 0 then
- self:RefreshSliderUI(1)
- return
- end
- self:RefreshSliderUI(math.round(value))
- end
- function UIBoliShopUpLvTipsView:OnClickUpgradeBtn()
- if self.maxNum == 0 then
- CommonUtil.ItemNotEnoughHandle(Enum.ItemType.ROCoin)
- else
- local value = self.numBox.slider.slider.value
- ManagerContainer.DataMgr.BoliShopData:SendBoliShopLevelUpReq(value)
- end
- self:OnClickCloseBtn()
- end
- function UIBoliShopUpLvTipsView:RefreshCurCfgData(lv)
- local tab = self.allExpData
- if tab then
- for i = 1, #tab - 1 do
- if lv < tab[i] then
- self.curCfgData = ManagerContainer.CfgMgr:GetBoLiVipCfgById(i - 2)
- break
- elseif tab[i] <= lv and tab[i + 1] > lv then
- self.curCfgData = ManagerContainer.CfgMgr:GetBoLiVipCfgById(i - 1)
- break
- elseif i == self.maxCfgData.Lv then
- self.curCfgData = ManagerContainer.CfgMgr:GetBoLiVipCfgById(i)
- break
- end
- end
- if not self.curCfgData then
- self.curCfgData = ManagerContainer.CfgMgr:GetBoLiVipCfgById(self.curLv)
- end
- end
- end
- function UIBoliShopUpLvTipsView:OnReduceClick()
- if self.maxNum == 0 then
- return
- end
- local val = self.numBox.slider.slider.value - 1
- if val <= 0 then
- return
- end
- self.numBox.slider.slider.value = val
- end
- function UIBoliShopUpLvTipsView:OnSumClick()
- if self.maxNum == 0 then
- return
- end
- local val = self.numBox.slider.slider.value + 1
- if val > self.maxNum then
- return
- end
- self.numBox.slider.slider.value = val
- end
- function UIBoliShopUpLvTipsView:OnHide()
- end
- function UIBoliShopUpLvTipsView:OnClickCloseBtn()
- ManagerContainer.LuaUIMgr:OpenSourceUI(self)
- end
- function UIBoliShopUpLvTipsView:OnShow(data)
- self.controller:SetData(data)
- end
- function UIBoliShopUpLvTipsView:OnClose()
- end
- function UIBoliShopUpLvTipsView:OnDispose()
- self.controller:OnDispose()
- self.numBox.slider.slider.onValueChanged:RemoveAllListeners()
- end
- return UIBoliShopUpLvTipsView
|