2021-04-21 13:12:04 +08:00
|
|
|
|
require("Base/BasePanel")
|
2020-05-09 13:31:21 +08:00
|
|
|
|
local ItemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
|
|
|
|
|
CarbonBuyCountPopup = Inherit(BasePanel)
|
|
|
|
|
local this = CarbonBuyCountPopup
|
|
|
|
|
local curBuyCount = 0
|
|
|
|
|
local costNeed = 0
|
|
|
|
|
local itemID = 0
|
|
|
|
|
|
|
|
|
|
--初始化组件(用于子类重写)
|
|
|
|
|
function CarbonBuyCountPopup:InitComponent()
|
2021-04-21 13:12:04 +08:00
|
|
|
|
this.spLoader = SpriteLoader.New()
|
2020-05-09 13:31:21 +08:00
|
|
|
|
|
|
|
|
|
this.mask = Util.GetGameObject(self.gameObject, "BackMask")
|
|
|
|
|
this.title = Util.GetGameObject(self.gameObject, "bg/title"):GetComponent("Text")
|
|
|
|
|
this.leftBuyCount = Util.GetGameObject(self.gameObject, "bg/content"):GetComponent("Text")
|
|
|
|
|
this.icon = Util.GetGameObject(self.gameObject, "bg/icon"):GetComponent("Image")
|
|
|
|
|
this.btnConfirm = Util.GetGameObject(self.gameObject, "bg/Confirm")
|
|
|
|
|
this.btnCancel = Util.GetGameObject(self.gameObject, "bg/btnBack")
|
|
|
|
|
this.textCost = Util.GetGameObject(self.gameObject, "bg/cost"):GetComponent("Text")
|
|
|
|
|
this.textFreshInfo = Util.GetGameObject(self.gameObject, "bg/info"):GetComponent("Text")
|
|
|
|
|
this.textBuyNum = Util.GetGameObject(self.gameObject, "bg/Slider/numText"):GetComponent("Text")
|
|
|
|
|
|
|
|
|
|
-- 滑条
|
|
|
|
|
this.slider = Util.GetGameObject(self.gameObject, "bg/Slider")
|
|
|
|
|
this.chooseNum = Util.GetGameObject( this.slider, "numText"):GetComponent("Text")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--绑定事件(用于子类重写)
|
|
|
|
|
function CarbonBuyCountPopup:BindEvent()
|
|
|
|
|
|
|
|
|
|
-- 关闭按钮事件监听
|
|
|
|
|
Util.AddClick(this.btnCancel, function()
|
|
|
|
|
self:ClosePanel()
|
|
|
|
|
end)
|
|
|
|
|
Util.AddClick(this.mask, function()
|
|
|
|
|
self:ClosePanel()
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
Util.AddSlider(this.slider, function(go, value)
|
|
|
|
|
this.OnSliderValueChange(value)
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
-- 确认按钮事件
|
|
|
|
|
Util.AddClick(this.btnConfirm, function()
|
|
|
|
|
|
|
|
|
|
if curBuyCount == 0 then
|
2021-03-02 16:53:12 +08:00
|
|
|
|
PopupTipPanel.ShowTip(Language[11463])
|
2020-05-09 13:31:21 +08:00
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if CarbonManager.getLeftBuyCount() <= 0 then
|
2021-03-02 16:53:12 +08:00
|
|
|
|
PopupTipPanel.ShowTip(Language[11464])
|
2020-05-09 13:31:21 +08:00
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 当前剩余挑战次数
|
|
|
|
|
local leftChallengeCount = CarbonManager.getLeftChallengeCount()
|
|
|
|
|
-- 副本购买上限
|
|
|
|
|
local maxLimitCount = CarbonManager.getMaxLimitCount()
|
|
|
|
|
if leftChallengeCount >= maxLimitCount then
|
2021-03-02 16:53:12 +08:00
|
|
|
|
PopupTipPanel.ShowTip(Language[11465])
|
2020-05-09 13:31:21 +08:00
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 购买后的总量大于上限,只给购买到上限
|
|
|
|
|
if curBuyCount + leftChallengeCount > maxLimitCount then
|
|
|
|
|
local canBuy = maxLimitCount - leftChallengeCount
|
2021-03-02 16:53:12 +08:00
|
|
|
|
PopupTipPanel.ShowTip(Language[11466] .. canBuy .. Language[10048])
|
2020-05-09 13:31:21 +08:00
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if costNeed > BagManager.GetItemCountById(itemID) then
|
2021-03-02 16:53:12 +08:00
|
|
|
|
PopupTipPanel.ShowTip(Language[11467])
|
2020-05-09 13:31:21 +08:00
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
NetManager.BuyFightCountRequest(curBuyCount, function ()
|
|
|
|
|
-- 关闭当前界面
|
|
|
|
|
self:ClosePanel()
|
|
|
|
|
-- 刷新物品数量
|
|
|
|
|
--改为后端刷新了
|
|
|
|
|
--BagManager.UpdateItemsNum(itemID, costNeed)
|
|
|
|
|
-- 发送事件更新界面显示
|
|
|
|
|
Game.GlobalEvent:DispatchEvent(GameEvent.Carbon.CarbonCountChange)
|
2021-03-02 16:53:12 +08:00
|
|
|
|
PopupTipPanel.ShowTip(Language[11468])
|
2020-05-09 13:31:21 +08:00
|
|
|
|
end)
|
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--添加事件监听(用于子类重写)
|
|
|
|
|
function CarbonBuyCountPopup:AddListener()
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--移除事件监听(用于子类重写)
|
|
|
|
|
function CarbonBuyCountPopup:RemoveListener()
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--界面打开时调用(用于子类重写)
|
|
|
|
|
function CarbonBuyCountPopup:OnOpen(count)
|
|
|
|
|
|
|
|
|
|
local sliderComp = this.slider:GetComponent("Slider")
|
|
|
|
|
local maxValue = CarbonManager.getLeftBuyCount()
|
|
|
|
|
sliderComp.maxValue = maxValue
|
|
|
|
|
sliderComp.enabled = maxValue > 1
|
2020-12-28 20:10:45 +08:00
|
|
|
|
sliderComp.minValue = 1
|
2020-05-09 13:31:21 +08:00
|
|
|
|
sliderComp.value = 1
|
|
|
|
|
|
|
|
|
|
-- 刷新选择条数据
|
|
|
|
|
this.RefreshData(count)
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--根据Slider的数据刷新面板上的数据
|
|
|
|
|
function this.RefreshData(chooseNum)
|
|
|
|
|
|
|
|
|
|
-- 剩余可购买次数
|
|
|
|
|
local leftBuyCount = CarbonManager.getLeftBuyCount()
|
|
|
|
|
local curLeftBuyCount = leftBuyCount - chooseNum
|
|
|
|
|
if curLeftBuyCount < 0 then
|
|
|
|
|
chooseNum = leftBuyCount
|
|
|
|
|
curLeftBuyCount = 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 设置当前
|
|
|
|
|
this.slider:GetComponent("Slider").value = chooseNum
|
|
|
|
|
|
|
|
|
|
-- 当前选择购买次数
|
|
|
|
|
this.chooseNum.text = chooseNum
|
|
|
|
|
|
|
|
|
|
-- 当前购买次数
|
|
|
|
|
curBuyCount = chooseNum
|
|
|
|
|
itemID, costNeed = CarbonManager.calBuyCountCost(chooseNum)
|
|
|
|
|
|
|
|
|
|
--刷新显示
|
2021-04-21 13:12:04 +08:00
|
|
|
|
this.icon.sprite = this.spLoader:LoadSprite(GetResourcePath(ItemConfig[itemID].ResourceID))
|
2021-03-02 16:53:12 +08:00
|
|
|
|
this.title.text = Language[11469]
|
|
|
|
|
this.leftBuyCount.text = Language[11470]..curLeftBuyCount..")"
|
2020-05-09 13:31:21 +08:00
|
|
|
|
this.textCost.text = chooseNum > 0 and costNeed or 0
|
2021-03-02 16:53:12 +08:00
|
|
|
|
this.textFreshInfo.text = Language[11471]
|
2020-05-09 13:31:21 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function this.OnSliderValueChange(value)
|
|
|
|
|
this.RefreshData(value)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--界面关闭时调用(用于子类重写)
|
|
|
|
|
function CarbonBuyCountPopup:OnClose()
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--界面销毁时调用(用于子类重写)
|
|
|
|
|
function CarbonBuyCountPopup:OnDestroy()
|
2021-04-21 13:12:04 +08:00
|
|
|
|
this.spLoader:Destroy()
|
2020-05-09 13:31:21 +08:00
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
2020-06-23 18:36:24 +08:00
|
|
|
|
return CarbonBuyCountPopup
|