| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- local UIStampLvUpView = require("UIPet/UIStampLvUpView_Generate")
- local IconItemCtr = require("Common/IconItemCtr")
- local lastCfgId = 0
- local isMaxLv = false
- local canAdvance = false
- local lackCostId
- function UIStampLvUpView:OnAwake(data)
- self.controller = require("UIPet/UIStampLvUpCtr"):new()
- self.controller:Init(self)
- self.controller:SetData(data)
- end
- function UIStampLvUpView:AddEventListener()
- ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
- ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.PET_STAMP_LEVEL_UP_REFRESH, self, self.OnLvUpNtf)
- end
- function UIStampLvUpView: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 UIStampLvUpView:Init()
- self:Refresh()
- end
- function UIStampLvUpView:Refresh()
- local stampData = self.controller:GetStampData()
- if not stampData then
- return
- end
- local cfgData = ManagerContainer.CfgMgr:GetPetEquipCfgDataById(stampData.cfgId)
- if not cfgData then
- return
- end
- local itemCfgData = ManagerContainer.CfgMgr:GetItemById(stampData.cfgId)
- if not itemCfgData then
- return
- end
- local lvCfgData = ManagerContainer.CfgMgr:GetPetEquipExpCfgDataByLvAndCfgId(stampData.lv, stampData.cfgId)
- if not lvCfgData then
- return
- end
- local nextLvCfgData = ManagerContainer.CfgMgr:GetPetEquipExpCfgDataByLvAndCfgId(stampData.lv + 1, stampData.cfgId)
- local nextStampLvCfgData = ManagerContainer.CfgMgr:GetPetEquipExpCfgDataByLvAndCfgId(1, cfgData.Advance)
- lastCfgId = stampData.cfgId
- IconItemCtr:SetData(self, self.popLvUp.iconItem, stampData)
- self.popLvUp.nameText.uILocalizeScript:SetContent(cfgData.Name)
- self.popLvUp.lV.number.text.text = stampData.lv .."/"..cfgData.MaxLevel
- isMaxLv = stampData.lv >= cfgData.MaxLevel
- canAdvance = cfgData.Advance > 0
- local nextCfgData = ManagerContainer.CfgMgr:GetPetEquipCfgDataById(cfgData.Advance)
- local nextCfgName = nextCfgData and nextCfgData.Name or ""
- self.popLvUp.lVLimit.text.text.text = I18N.T("LV")
- self.popLvUp.lVLimit.number1.text.text = I18N.T(cfgData.Name)
- for i = 1, 5 do
- local attr = lvCfgData.Nature[i]
- local attrItem = self.popLvUp["attr"..i]
- attrItem:SetActive(attr ~= nil)
- if attr ~= nil then
- local val = attr[2]
- attrItem.text.text.text = I18N.T("Attr_" .. attr[1])
- attrItem.number1.text.text = val
- attrItem.number2:SetActive(canAdvance or (not canAdvance and not isMaxLv))
- attrItem.image:SetActive(canAdvance or (not canAdvance and not isMaxLv))
- if isMaxLv then
- if canAdvance then
- local val1 = nextStampLvCfgData.Nature[i] and nextStampLvCfgData.Nature[i][2] or 0
- attrItem.number2.text.text = val1
- end
- else
- local val1 = nextLvCfgData.Nature[i] and nextLvCfgData.Nature[i][2] or 0
- attrItem.number2.text.text = val1
- end
- end
- end
- self.popLvUp.lVLimit:SetActive(isMaxLv)
- self.popLvUp.lVLimit.text:SetActive(not isMaxLv)
- self.popLvUp.lVLimit.image:SetActive(canAdvance or (not canAdvance and not isMaxLv))
- self.popLvUp.lVLimit.number2:SetActive(canAdvance or (not canAdvance and not isMaxLv))
- if canAdvance then
- self.popLvUp.lVLimit.number2.text.text = isMaxLv and I18N.T(nextCfgName) or I18N.T(cfgData.Name)
- end
- if not isMaxLv then
- local lvCfgData = ManagerContainer.CfgMgr:GetPetEquipExpCfgDataByLvAndCfgId(stampData.lv, stampData.cfgId)
- local costs = lvCfgData.Cost
- self:RefresCost(costs, false)
- elseif isMaxLv and canAdvance then
- local costs = cfgData.AdvanceCost
- self:RefresCost(costs, true)
- end
- self.cost:SetActive(canAdvance or (not canAdvance and not isMaxLv))
- self.popLvUp.btnLvUp:SetActive(not isMaxLv)
- self.popLvUp.btnAdvance:SetActive(isMaxLv and canAdvance)
- self.popLvUp.max:SetActive(isMaxLv and not canAdvance)
- end
- function UIStampLvUpView:RefresCost(costs, isAdvence)
- if not costs then
- self.cost1:SetActive(false)
- self.cost1:SetActive(false)
- return
- end
- for i = 1, 2 do
- local cost = costs[i]
- local costItem = self["cost"..i]
- costItem:SetActive(cost ~= nil)
- if cost then
- local cfgData = ManagerContainer.CfgMgr:GetItemById(cost[1])
- local costTb = tolua.getpeer(costItem)
- CommonUtil.LoadIcon(self, cfgData.Icon, function (sprite)
- costItem.icon.image.sprite = sprite
- end, costTb, "costIcon")
- local ownCount = CommonUtil.GetOwnResCountByItemId(cost[1])
- if not isAdvence then
- costItem.number.text.text = CommonUtil.FormatNumber(cost[2])
- CommonUtil.IsConditionOutColor(costItem.number.text, cost[2] > ownCount, cost[2])
- else
- local str = cost[1] ~= Enum.ItemType.Coin and ownCount.."/"..cost[2] or CommonUtil.FormatNumber(cost[2])
- costItem.number.text.text = str
- CommonUtil.IsConditionOutColor(costItem.number.text, cost[2] > ownCount, str)
- end
- if not lackCostId and cost[2] > ownCount then
- lackCostId = cost[1]
- end
- end
- end
- end
- function UIStampLvUpView:RefreshAdvanceSusccess()
- local stampData = self.controller:GetStampData()
- if not stampData then
- return
- end
- local cfgData = ManagerContainer.CfgMgr:GetPetEquipCfgDataById(stampData.cfgId)
- if not cfgData then
- return
- end
- local lastCfgData = ManagerContainer.CfgMgr:GetPetEquipCfgDataById(lastCfgId)
- if not lastCfgData then
- return
- end
- local lastStampLvCfgData = ManagerContainer.CfgMgr:GetPetEquipExpCfgDataByLvAndCfgId(lastCfgData.MaxLevel, lastCfgId)
- local stampLvCfgData = ManagerContainer.CfgMgr:GetPetEquipExpCfgDataByLvAndCfgId(1, stampData.cfgId)
- IconItemCtr:SetData(self, self.popEvolutionOK.iconItem, stampData)
- self.popEvolutionOK.lVLimit.number1.text.text = I18N.T(lastCfgData.Name)
- for i = 1, 5 do
- local attr = lastStampLvCfgData.Nature[i]
- local nextAttr = stampLvCfgData.Nature[i]
- local attrItem = self.popEvolutionOK["attr"..i]
- attrItem:SetActive(attr ~= nil)
- if attr ~= nil then
- local val = attr[2]
- attrItem.text.text.text = I18N.T("Attr_" .. attr[1])
- attrItem.number1.text.text = val
- local val1 = nextAttr[2]
- attrItem.number2.text.text = val1
- end
- end
- self.popEvolutionOK.lVLimit.number2.text.text = I18N.T(cfgData.Name)
- self.popEvolutionOK:SetActive(true)
- self.popLvUp:SetActive(false)
- end
- function UIStampLvUpView:RemoveEventListener()
- ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
- end
- function UIStampLvUpView:AddUIEventListener()
- self.uiBase:AddButtonEventListener(self.AnyBtn.button, self, self.OnCloseClick)
- self.uiBase:AddButtonEventListener(self.popLvUp.btnClose.button, self, self.OnCloseClick)
- self.uiBase:AddButtonEventListener(self.popEvolutionOK.AnyBtn.button, self, self.OnOkCloseClick)
- self.uiBase:AddButtonEventListener(self.popLvUp.btnLvUp.button, self, self.OnLvUpClick)
- self.uiBase:AddButtonEventListener(self.popLvUp.btnAdvance.button, self, self.OnAdvanceClick)
- end
- function UIStampLvUpView:OnCloseClick()
- self:UIClose()
- end
- function UIStampLvUpView:OnOkCloseClick()
- self.popLvUp:SetActive(true)
- self.popEvolutionOK:SetActive(false)
- end
- function UIStampLvUpView:OnLvUpClick()
- if isMaxLv then
- return
- end
- if lackCostId then
- ManagerContainer.LuaUIMgr:ErrorNoticeDisplayWithParam(CommonUtil.GetItemNotEnoughInfo(lackCostId))
- end
- self.controller:SendLvUp()
- end
- function UIStampLvUpView:OnAdvanceClick()
- if not canAdvance then
- return
- end
- if lackCostId then
- ManagerContainer.LuaUIMgr:ErrorNoticeDisplayWithParam(CommonUtil.GetItemNotEnoughInfo(lackCostId))
- end
- self.controller:SendAdvance()
- end
- function UIStampLvUpView:LvUpSuccessDisplay()
- --self.fx_ui_lv_up.uIParticle:PlayCachedParticalSystem(false)
- self.fx_ui_lv_up.uIParticle:PlayCachedParticalSystem(true)
- end
- function UIStampLvUpView:OnLvUpNtf()
- lackCostId = nil
- local state = self.controller:GetState()
- if state == 1 then
- self:LvUpSuccessDisplay()
- elseif state == 2 then
- self:RefreshAdvanceSusccess()
- end
- self:Refresh()
- self.controller:ClearState()
- end
- function UIStampLvUpView:OnHide()
- end
- function UIStampLvUpView:OnShow(data)
- self.controller:SetData(data)
- end
- function UIStampLvUpView:OnClose()
- end
- function UIStampLvUpView:OnDispose()
- self.controller:OnDispose()
- end
- return UIStampLvUpView
|