sk-client/Assets/ManagedResources/~Lua/Modules/Pay/DiscountPanel.lua

272 lines
9.7 KiB
Lua

require("Base/BasePanel")
DiscountPanel = Inherit(BasePanel)
local this = DiscountPanel
local ItemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
local discountList = {0, 900001, 900002, 900003, 900004}
local discountID
local tokensItem = nil
local isAnim = false
local curIndex = 1
local openType = 1--1贬值器 2提示
function this:InitComponent()
this.mask = Util.GetGameObject(this.gameObject, "mask")
this.btnBack = Util.GetGameObject(this.gameObject, "btnBack")
this.icon = Util.GetGameObject(this.gameObject, "bg/icon"):GetComponent("Image")
this.price = Util.GetGameObject(this.gameObject, "bg/price"):GetComponent("Text")
this.originalPrice = Util.GetGameObject(this.gameObject, "bg/originalPrice"):GetComponent("Text")
this.btnDiscounts = {}
this.grid = Util.GetGameObject(this.gameObject, "bg/grid")
for i = 1, this.grid.transform.childCount do
this.btnDiscounts[i] = this.grid.transform:GetChild(i-1).gameObject
end
this.btnBuy = Util.GetGameObject(this.gameObject, "bg/btnBuy")
this.discount = Util.GetGameObject(this.gameObject, "bg")
this.tip = Util.GetGameObject(this.gameObject, "tip")
this.pos = Util.GetGameObject(this.tip, "pos")
this.btnTokens = Util.GetGameObject(this.tip, "btnTokens")
this.btnRecharge = Util.GetGameObject(this.tip, "btnRecharge")
this.effect = Util.GetGameObject(this.gameObject, "bg/x1_bianzhi_effect")
local devalue = ConfigManager.GetConfigDataByKey(ConfigName.DeValueShow, "LuaName", "DiscountPanel")
Util.GetGameObject(this.gameObject, "DeValusTip"):SetActive(devalue and devalue.IsShow == 1)
end
function this:BindEvent()
Util.AddClick(this.mask, function()
this:ClosePanel()
end)
Util.AddClick(this.btnBack, function()
this:ClosePanel()
end)
Util.AddClick(this.tip, function()
if openType == 1 then
this.tip:SetActive(false)
elseif openType == 2 then
this:ClosePanel()
end
end)
Util.AddClick(this.btnBuy, function()
if this.config.CashPointPay then
if this.config.CashPointPay == 1 then
this.SetTipPanel()
this.tip:SetActive(true)
elseif this.config.CashPointPay == 0 then
this.func(true, discountID)
this:ClosePanel()
else
this.func(false, discountID)
this:ClosePanel()
end
else
this.func(false, discountID)
this:ClosePanel()
end
end)
for i = 1, #this.btnDiscounts do
Util.AddOnceClick(this.btnDiscounts[i], function ()
this.DisCountClicked(i)
end)
end
Util.AddClick(this.btnRecharge, function ()
this.func(true, discountID)
this:ClosePanel()
end)
end
function this:AddListener()
end
function this:RemoveListener()
end
function this:OnOpen(args, func)
discountID = 0
this.configType = args.configType
this.config = args.config
openType = args.openType
this.func = func
if args.configType == 1 then
this.originalCost = MoneyUtil.GetMoneyNoUnit(this.config.Price)
elseif args.configType == 2 then
if args.shopType then
local costId, finalCost, orignalCost = ShopManager.calculateBuyCost(args.shopType, args.config.Id, 1)
this.originalCost = finalCost
else
this.originalCost = args.config.Cost[2][4]
end
this.icon.sprite = Util.LoadSprite(GetResourcePath(ItemConfig[args.config.Cost[1][1]].ResourceID))
end
this.icon.gameObject:SetActive(args.configType == 2)
this.discount:SetActive(openType == 1)
this.tip:SetActive(openType == 2)
if openType == 1 then
this.DisCountClicked(1, true)
elseif openType == 2 then
this.SetTipPanel()
end
end
function this:OnShow()
end
function this:OnSortingOrderChange()
end
function this:OnClose()
this.func = nil
isAnim = false
end
function this:OnDestroy()
tokensItem = nil
end
local ItemColor = {
[1] = {
image = "X1_bt_bianzhiqi_anniu_03",
color = Color.New(105/255,105/255,152/255,128/255)
},
[2] = {
image = "X1_bt_bianzhiqi_anniu_04",
color = Color.New(205/255,142/255,253/255,128/255)
}
}
function this.DisCountClicked(index, isFrist)
if isAnim then
return
end
for i = 1, #this.btnDiscounts do
if i ~= 1 then
local haveNum = BagManager.GetItemCountById(discountList[i])
if i == index and haveNum < 1 then
this.DisCountClicked(curIndex)
return
end
end
if isFrist then
if i == 1 then
Util.GetGameObject(this.btnDiscounts[i], "icon"):GetComponent("Image").sprite = Util.LoadSprite("X1_icon_item_zhekouquan0")
this.originalPrice.text = this.originalCost
else
local haveNum = BagManager.GetItemCountById(discountList[i])
local str = string.format("%s <size=36>x%s</size>", GetLanguageStrById(ItemConfig[discountList[i]].Name), haveNum)
Util.GetGameObject(this.btnDiscounts[i], "title"):GetComponent("Text").text = str
Util.GetGameObject(this.btnDiscounts[i], "icon"):GetComponent("Image").sprite = Util.LoadSprite(GetResourcePath(ItemConfig[discountList[i]].ResourceID))
local price = this.config.PriceDevalue[i-1][2]
if this.configType == 1 then
price = GetLanguageStrById(50485).."<size=36><B><color=#FFD12B>"..MoneyUtil.GetMoney(price).."</color></b></size>"
elseif this.configType == 2 then
price = GetLanguageStrById(50485).."<size=36><B><color=#FFD12B>"..price.."</color></b></size>"
end
Util.GetGameObject(this.btnDiscounts[i], "Text"):GetComponent("Text").text = price
end
this.startNum = this.originalCost
end
if i == index then
this.btnDiscounts[i]:GetComponent("Image").sprite = Util.LoadSprite(ItemColor[2].image)
Util.GetGameObject(this.btnDiscounts[i], "diwen"):GetComponent("Image").color = ItemColor[2].color
if i == 1 then
if this.configType == 1 then
this.Anim(this.startNum, MoneyUtil.GetMoneyNoUnit(this.config.Price))
elseif this.configType == 2 then
this.Anim(this.startNum, this.originalCost)
end
else
if curIndex == index then
return
end
this.effect:SetActive(false)
this.effect:SetActive(true)
if this.configType == 1 then
this.Anim(this.startNum, MoneyUtil.GetMoneyNoUnit(this.config.PriceDevalue[i-1][2]))
elseif this.configType == 2 then
this.Anim(this.startNum, this.config.PriceDevalue[i-1][2])
end
end
this.originalPrice.gameObject:SetActive(i ~= 1)
discountID = discountList[index]
curIndex = index
else
this.btnDiscounts[i]:GetComponent("Image").sprite = Util.LoadSprite(ItemColor[1].image)
Util.GetGameObject(this.btnDiscounts[i], "diwen"):GetComponent("Image").color = ItemColor[1].color
end
Util.GetGameObject(this.btnDiscounts[i], "Text"):SetActive(i ~= index)
Util.GetGameObject(this.btnDiscounts[i], "select"):SetActive(i == index)
end
end
function this.Anim(startNum, endNum)
local p = endNum
local multiple = false--美金小数显示问题
if MoneyUtil.multiLanguageData.Exchange == "Price_2" then
startNum = startNum*100
endNum = endNum*100
multiple = true
end
isAnim = true
DoTween.To(DG.Tweening.Core.DOGetter_int(function()
return 0
end),
DG.Tweening.Core.DOSetter_int(function(progress)
local e = startNum-progress
if multiple then
e = (startNum-progress)/100
end
if this.configType == 1 then
this.price.text = string.format("<size=108>%s</size>%s", MoneyUtil.GetCurrencyUnit(), e)
elseif this.configType == 2 then
this.price.text = " "..e
end
end),
startNum-endNum,
0.4):SetEase(Ease.Linear):OnComplete(function()
if multiple then
if this.configType == 1 then
this.price.text = string.format("<size=108>%s</size>%s", MoneyUtil.GetCurrencyUnit(), p)
elseif this.configType == 2 then
this.price.text = " "..p
end
end
this.startNum = p
isAnim = false
end)
end
function this.SetTipPanel()
if not tokensItem then
tokensItem = SubUIManager.Open(SubUIConfig.ItemView, this.pos.transform)
end
tokensItem:OnOpen(false, {900010, 0}, 0.8)
local haveNum = BagManager.GetItemCountById(900010)
local needNum = 0
if discountID == 0 then
if this.configType == 1 then
needNum = MoneyUtil.GetMoneyNoUnit(this.config.Price)
elseif this.configType == 2 then
needNum = this.config.Cost[2][4]
end
else
for i = 1, #this.config.PriceDevalue do
if this.config.PriceDevalue[i][1] == discountID then
needNum = MoneyUtil.GetMoneyNoUnit(this.config.PriceDevalue[i][2])
end
end
end
tokensItem:SetNum(GetNumUnenoughColor(haveNum, needNum, haveNum, needNum))
tokensItem:ShowNum(true)
Util.AddOnceClick(this.btnTokens, function ()
if haveNum < needNum then
PopupTipPanel.ShowTipByLanguageId(50435)
return
end
this.func(false, discountID)
this:ClosePanel()
end)
end
return DiscountPanel