212 lines
9.4 KiB
Lua
212 lines
9.4 KiB
Lua
require("Base/BasePanel")
|
|
local ShopBuyPopup = Inherit(BasePanel)
|
|
local this = ShopBuyPopup
|
|
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
|
|
this.backFun = nil
|
|
--初始化组件(用于子类重写)
|
|
function ShopBuyPopup:InitComponent()
|
|
this.spLoader = SpriteLoader.New()
|
|
this.itemBg = Util.GetGameObject(self.gameObject, "tipImage/item/bg"):GetComponent("Image")
|
|
this.itemIcon = Util.GetGameObject(self.gameObject, "tipImage/item/icon"):GetComponent("Image")
|
|
this.circleFrame = Util.GetGameObject(this.itemIcon.gameObject, "circleFrame"):GetComponent("Image")
|
|
this.itemNum = Util.GetGameObject(self.gameObject, "tipImage/item/num"):GetComponent("Text")
|
|
this.itemCount = Util.GetGameObject(self.gameObject, "tipImage/item/count"):GetComponent("Text")
|
|
this.itemName = Util.GetGameObject(self.gameObject, "tipImage/item/name"):GetComponent("Text")
|
|
this.itemContent = Util.GetGameObject(self.gameObject, "tipImage/item/content"):GetComponent("Text")
|
|
|
|
this.costNum = Util.GetGameObject(self.gameObject, "tipImage/cost/ncost"):GetComponent("Text")
|
|
this.discostNum1 = Util.GetGameObject(self.gameObject, "tipImage/cost/discost1"):GetComponent("Text")
|
|
this.discostNum2 = Util.GetGameObject(self.gameObject, "tipImage/cost/discost2"):GetComponent("Text")
|
|
this.costIcon = Util.GetGameObject(self.gameObject, "tipImage/cost/icon"):GetComponent("Image")
|
|
|
|
this.slider = Util.GetGameObject(self.gameObject, "tipImage/Slider"):GetComponent("Slider")
|
|
this.leftBtn = Util.GetGameObject(this.slider.gameObject, "leftbtn")
|
|
this.rightBtn = Util.GetGameObject(this.slider.gameObject, "rightbtn")
|
|
this.buyNumLab = Util.GetGameObject(this.slider.gameObject, "count"):GetComponent("Text")
|
|
|
|
this.backBtn = Util.GetGameObject(self.gameObject, "tipImage/btnReturn")
|
|
this.cancelBtn = Util.GetGameObject(self.gameObject, "tipImage/op/btnLeft")
|
|
this.confirmBtn = Util.GetGameObject(self.gameObject, "tipImage/op/btnRight")
|
|
|
|
this.vipTip = Util.GetGameObject(self.gameObject, "tipImage/vipTips")
|
|
this.costTip = Util.GetGameObject(self.gameObject, "tipImage/costTips")
|
|
end
|
|
|
|
|
|
--绑定事件(用于子类重写)
|
|
function ShopBuyPopup:BindEvent()
|
|
Util.AddClick(this.backBtn, function()
|
|
self:ClosePanel()
|
|
end)
|
|
Util.AddClick(this.cancelBtn, function()
|
|
self:ClosePanel()
|
|
end)
|
|
Util.AddClick(this.confirmBtn, function()
|
|
local count = this.slider.value
|
|
|
|
local itemLimitNum = ShopManager.GetShopItemMaxBuy(this.shopType, this.shopItemId)
|
|
if itemLimitNum == 0 or itemLimitNum < count then
|
|
local costId = this.shopItemInfo.Cost[1][1]
|
|
NotEnoughPopup:Show(costId, function()
|
|
this:ClosePanel()
|
|
end)
|
|
return
|
|
end
|
|
|
|
ShopManager.RequestBuyShopItem(this.shopType, this.shopItemId, count, function()
|
|
Game.GlobalEvent:DispatchEvent(GameEvent.Shop.RefreshItem)
|
|
self:ClosePanel()
|
|
if this.backFun then
|
|
this.backFun(count)
|
|
this.backFun = nil
|
|
end
|
|
end)
|
|
end)
|
|
|
|
|
|
Util.AddSlider(this.slider.gameObject, function(go, value)
|
|
this.OnSliderValueChange(value)
|
|
end)
|
|
|
|
|
|
Util.AddClick(this.leftBtn, function()
|
|
local curCount = this.slider.value
|
|
if curCount <= 1 then return end
|
|
this.slider.value = curCount - 1
|
|
end)
|
|
Util.AddClick(this.rightBtn, function()
|
|
if this.maxNum <= 0 then
|
|
PopupTipPanel.ShowTip(Language[11891])
|
|
return
|
|
end
|
|
local curCount = this.slider.value
|
|
if curCount >= 999 then
|
|
PopupTipPanel.ShowTip(Language[11664])
|
|
return
|
|
end
|
|
if curCount >= this.maxNum then return end
|
|
this.slider.value = curCount + 1
|
|
end)
|
|
end
|
|
|
|
--添加事件监听(用于子类重写)
|
|
function ShopBuyPopup:AddListener()
|
|
end
|
|
|
|
--移除事件监听(用于子类重写)
|
|
function ShopBuyPopup:RemoveListener()
|
|
end
|
|
|
|
--界面打开时调用(用于子类重写)
|
|
function ShopBuyPopup:OnOpen(shopType, shopItemId,backFun)
|
|
-- 获取数据
|
|
this.shopType = shopType
|
|
this.shopItemId = shopItemId
|
|
this.shopItemInfo = ShopManager.GetShopItemInfo(shopItemId)
|
|
--LogGreen(shopItemId..":shopItemId")
|
|
this.backFun = backFun
|
|
this.shopItemData = ShopManager.GetShopItemData(shopType, shopItemId)
|
|
|
|
-- 商品基础信息显示
|
|
-- this.itemName.text = this.shopItemInfo.GoodsName
|
|
this.itemName.text = GetLanguageStrById(itemConfig[this.shopItemInfo.Goods[1][1]].Name)
|
|
this.goods = ShopManager.GetShopItemGoodsInfo(this.shopItemId)
|
|
local goodsId = this.goods[1][1]
|
|
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
|
|
this.itemContent.text = string.gsub(GetLanguageStrById(itemConfig[goodsId].ItemDescribe), "\\n", "\n")
|
|
this.itemIcon.sprite = SetIcon(this.spLoader, goodsId)
|
|
this.itemIcon.gameObject:GetComponent("RectTransform").localScale = Vector3.one
|
|
--LogGreen("ItemType:"..itemConfig[this.shopItemInfo.Goods[1][1]].ItemType)
|
|
this.itemBg.sprite = SetFrame(this.spLoader, goodsId)
|
|
this.circleFrame.gameObject:SetActive(false)
|
|
if itemConfig[this.shopItemInfo.Goods[1][1]].ItemType == 2 then
|
|
Util.GetGameObject(self.gameObject,"tipImage/item/chip").gameObject:SetActive(true)
|
|
Util.GetGameObject(self.gameObject,"tipImage/item/chip"):GetComponent("Image").sprite = this.spLoader:LoadSprite(GetHeroChipQuantityImageByquality(itemConfig[this.shopItemInfo.Goods[1][1]].Quantity))
|
|
if itemConfig[this.shopItemInfo.Goods[1][1]].PropertyName and itemConfig[this.shopItemInfo.Goods[1][1]].PropertyName > 0 then
|
|
Util.GetGameObject(self.gameObject, "tipImage/item/proima"):SetActive(true)
|
|
Util.GetGameObject(self.gameObject, "tipImage/item/proima"):GetComponent("Image").sprite = this.spLoader:LoadSprite(GetJobSpriteStrByJobNum(itemConfig[this.shopItemInfo.Goods[1][1]].PropertyName))
|
|
else
|
|
Util.GetGameObject(self.gameObject, "tipImage/item/proima"):SetActive(false)
|
|
end
|
|
elseif itemConfig[this.shopItemInfo.Goods[1][1]].ItemType == 13 then
|
|
this.itemIcon.gameObject:GetComponent("RectTransform").localScale = Vector3.one*0.9
|
|
this.circleFrame.gameObject:SetActive(true)
|
|
this.circleFrame.gameObject:GetComponent("RectTransform").localScale = Vector3.one*1.2
|
|
-- LogPink(tostring(this.shopItemInfo.Goods[1][1]).." "..tostring(itemConfig[this.shopItemInfo.Goods[1][1]].Quantity).." "..tostring(SoulPrintSpriteByQuantity[itemConfig[this.shopItemInfo.Goods[1][1]].Quantity].circleBg2))
|
|
this.circleFrame.sprite = this.spLoader:LoadSprite(SoulPrintSpriteByQuantity[itemConfig[this.shopItemInfo.Goods[1][1]].Quantity].circle)
|
|
Util.GetGameObject(self.gameObject,"tipImage/item/chip").gameObject:SetActive(false)
|
|
Util.GetGameObject(self.gameObject, "tipImage/item/proima"):SetActive(false)
|
|
else
|
|
Util.GetGameObject(self.gameObject,"tipImage/item/chip").gameObject:SetActive(false)
|
|
Util.GetGameObject(self.gameObject, "tipImage/item/proima"):SetActive(false)
|
|
end
|
|
this.itemNum.text = this.goods[1][2]
|
|
-- 计算最大可购买的数量
|
|
local countLimitNum = ShopManager.GetShopItemLimitBuyCount(shopItemId)
|
|
local countLeftNum = countLimitNum >= 0 and countLimitNum - this.shopItemData.buyNum or math.huge
|
|
this.itemCount.text = countLimitNum == -1 and "" or string.format(Language[11662], countLeftNum, countLimitNum)
|
|
|
|
-- 判断最大值
|
|
local itemLimitNum = ShopManager.GetShopItemMaxBuy(shopType, shopItemId)
|
|
this.maxNum = math.min(itemLimitNum, countLeftNum)
|
|
this.maxNum = this.maxNum > 999 and 999 or this.maxNum
|
|
-- 设置滑动范围
|
|
this.slider.enabled = this.maxNum > 1
|
|
this.slider.maxValue = this.maxNum
|
|
this.slider.minValue = 0
|
|
this.slider.value = this.maxNum > 0 and 1 or 0
|
|
-- 设置颜色
|
|
this.buyNumLab.color = this.maxNum > 0 and Color.New(0.55,0.59,0.62,1) or UIColor.NOT_ENOUGH_RED
|
|
Util.SetGray(this.confirmBtn, this.maxNum <= 0)
|
|
|
|
-- 刷新花费
|
|
this.RefreshCostShow()
|
|
|
|
-- 商店购买界面提示显示设置
|
|
this.vipTip:SetActive(this.shopItemInfo.RelatedtoVIP == 1)
|
|
local abcd = this.shopItemInfo.Cost[2]-- 公式常数
|
|
this.costTip:SetActive(this.shopItemInfo.PremiumType == 2 or abcd[1] > 0 or abcd[2] > 0 or abcd[3] > 0 )
|
|
end
|
|
|
|
--- 滑动条值改变回调
|
|
function this.OnSliderValueChange(value)
|
|
this.RefreshCostShow()
|
|
end
|
|
|
|
--- 根据slider值刷新显示
|
|
function this.RefreshCostShow()
|
|
-- 购买数量
|
|
this.buyNumLab.text = this.slider.value
|
|
-- 计算数据
|
|
local count = this.slider.value == 0 and 1 or this.slider.value
|
|
local costId, discostnum, costnum = ShopManager.calculateBuyCost(this.shopType, this.shopItemId, count)
|
|
-- 判断显示
|
|
local isDiscount = this.shopItemInfo.IsDiscount == 1
|
|
this.costNum.gameObject:SetActive(not isDiscount)
|
|
this.discostNum1.gameObject:SetActive(isDiscount)
|
|
this.discostNum2.gameObject:SetActive(isDiscount)
|
|
-- 原价
|
|
this.costNum.text = costnum
|
|
this.discostNum1.text = costnum
|
|
-- 折后价
|
|
this.discostNum2.text = discostnum
|
|
-- 物品icon
|
|
this.costIcon.sprite = SetIcon(this.spLoader, costId)
|
|
-- 物品获取数量
|
|
this.itemNum.text = this.goods[1][2] * count
|
|
end
|
|
|
|
|
|
|
|
--界面关闭时调用(用于子类重写)
|
|
function ShopBuyPopup:OnClose()
|
|
end
|
|
|
|
--界面销毁时调用(用于子类重写)
|
|
function ShopBuyPopup:OnDestroy()
|
|
this.spLoader:Destroy()
|
|
end
|
|
|
|
return ShopBuyPopup
|
|
|