sk-client/Assets/ManagedResources/~Lua/Modules/ExchangeAction/ExchangeAction.lua

193 lines
6.8 KiB
Lua

require("Base/BasePanel")
local ExchangeAction = Inherit(BasePanel)
local this = ExchangeAction
local AcitvityShowTheme = ConfigManager.GetConfig(ConfigName.AcitvityShowTheme)
local GlobalActivity = ConfigManager.GetConfig(ConfigName.GlobalActivity)
local myParent
local mActivityId
local itemList = {}
function ExchangeAction:InitComponent(go)
this.banner = Util.GetGameObject(go, "banner"):GetComponent("Image")
this.time = Util.GetGameObject(go, "time")
this.timeTxt = Util.GetGameObject(go, "time/Text"):GetComponent("Text")
this.itemGrid = Util.GetGameObject(go, "ItemGrid")
this.tip = Util.GetGameObject(go, "tip"):GetComponent("Text")
this.scroll = Util.GetGameObject(go, "scroll")
this.pre = Util.GetGameObject(go, "pre")
local rootHight = this.scroll.transform.rect.height
local width = this.scroll.transform.rect.width
this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.scroll.transform,
this.pre, nil, Vector2.New(width, rootHight), 1, 1, Vector2.New(0, 7))
this.ScrollView.moveTween.MomentumAmount = 1
this.ScrollView.moveTween.Strength = 2
end
function ExchangeAction:BindEvent()
end
--添加事件监听(用于子类重写)
function ExchangeAction:AddListener()
end
--移除事件监听(用于子类重写)
function ExchangeAction:RemoveListener()
end
-- 打开时调用
function ExchangeAction:OnOpen()
end
function ExchangeAction:OnShow(parent, activityId)
myParent = parent
mActivityId = activityId
if itemList then
for index, value in ipairs(itemList) do
for i = 1, #value do
value[i].gameObject:SetActive(false)
end
end
end
CheckRedPointStatus(RedPointType.ExchangeAction)
-- this.activityId = ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.Exchange)
local allData = ConfigManager.GetAllConfigsDataByKey(ConfigName.WordExchangeConfig, "ActivityId", mActivityId)
table.sort(allData, function (a, b)
return a.Sort < b.Sort
end)
this.ScrollView:SetData(allData, function (index, go)
this:SingleDataShow(go, allData[index])
go:SetActive(true)
end)
local config = GlobalActivity[mActivityId]
local showArtId = config.ShowArt
local showArt = AcitvityShowTheme[showArtId]
this.banner.sprite = Util.LoadSprite(GetPictureFont(showArt.Compent))
this.tip.text = GetLanguageStrById(GlobalActivity[mActivityId].ExpertDec)
if not itemList[this.itemGrid] then
itemList[this.itemGrid] = {}
end
for i = 1, #itemList[this.itemGrid] do
itemList[this.itemGrid][i].gameObject:SetActive(false)
end
for i = 1, #config.CostItem do
if not itemList[this.itemGrid][i] then
itemList[this.itemGrid][i] = SubUIManager.Open(SubUIConfig.ItemView, this.itemGrid.transform)
end
itemList[this.itemGrid][i]:OnOpen(false, {config.CostItem[i], BagManager.GetItemCountById(config.CostItem[i])}, 0.6)
itemList[this.itemGrid][i]:ShowNum(true)
itemList[this.itemGrid][i].gameObject:SetActive(true)
end
local activityInfo = ActivityGiftManager.GetActivityTypeInfo(ActivityTypeDef.Exchange)
if activityInfo then
this.TimeDown(this.timeTxt, activityInfo.endTime - GetTimeStamp())
end
end
function ExchangeAction:OnHide()
end
--界面关闭时调用(用于子类重写)
function ExchangeAction:OnClose()
if this.timer then
this.timer:Stop()
this.timer = nil
end
end
--界面销毁时调用(用于子类重写)
function ExchangeAction:OnDestroy()
itemList = {}
if this.timer then
this.timer:Stop()
this.timer = nil
end
end
function ExchangeAction:SingleDataShow(go, data)
local ItemGrid = Util.GetGameObject(go, "ItemGrid")
local exchangeItem = Util.GetGameObject(go, "exchangeItem")
local btn = Util.GetGameObject(go, "btn")
local btnTxt = Util.GetGameObject(go, "btn/Text"):GetComponent("Text")
local limit = Util.GetGameObject(go, "limit"):GetComponent("Text")
local limitTxt = Util.GetGameObject(go, "limit/Text"):GetComponent("Text")
if not itemList[go] then
itemList[go] = {}
end
for i = 1, #itemList[go] do
itemList[go][i].gameObject:SetActive(false)
end
for i = 1, #data.DeductItem+1 do
if not itemList[go][i] then
local parent
if i == 1 then
parent = exchangeItem
else
parent = ItemGrid
end
itemList[go][i] = SubUIManager.Open(SubUIConfig.ItemView, parent.transform)
end
if i == 1 then
itemList[go][i]:OnOpen(false, data.RewardItem[i], 0.65)
else
itemList[go][i]:OnOpen(false, data.DeductItem[i-1], 0.6)
itemList[go][i]:CompareNum(BagManager.GetItemCountById(data.DeductItem[i-1][1]), data.DeductItem[i-1][2])
end
itemList[go][i].gameObject:SetActive(true)
end
if data.LimitBuyType == 0 then
limit.text = ""
elseif data.LimitBuyType == 1 then
limit.text = GetLanguageStrById(50459)
elseif data.LimitBuyType == 2 then
limit.text = GetLanguageStrById(50460)
end
local serverData = ActivityGiftManager.GetActivityInfo(mActivityId, data.Id)
if not serverData then
LogError(mActivityId.."无数据")
return
end
if data.LimitBuyType == 0 then
limitTxt.text = ""
Util.SetGray(btn, false)
btn:GetComponent("Button").enabled = true
btnTxt.text = GetLanguageStrById(50453)
else
limitTxt.text = "("..serverData.progress.."/"..data.LimitBuyNum..")"
Util.SetGray(btn, data.LimitBuyNum-serverData.progress == 0 and data.LimitBuyType ~= 0)
btn:GetComponent("Button").enabled = data.LimitBuyNum-serverData.progress > 0 or data.LimitBuyType ~= 0
btnTxt.text = data.LimitBuyNum-serverData.progress > 0 and GetLanguageStrById(50453) or GetLanguageStrById(50454)
end
Util.AddOnceClick(btn, function ()
NetManager.GetActivityRewardRequest(data.Id, mActivityId, function(drop)
UIManager.OpenPanel(UIName.RewardItemPopup, drop, 1, function ()
this:OnShow(myParent, mActivityId)
end)
end)
end)
end
--倒计时
function this.TimeDown(txt, timeDown)
txt.text = GetLanguageStrById(10028)..TimeToDHMS(timeDown)
if this.timer then
this.timer:Stop()
this.timer = nil
end
this.timer = Timer.New(function()
txt.text = GetLanguageStrById(10028) .. TimeToDHMS(timeDown)
if timeDown < 0 then
this.timer:Stop()
this.timer = nil
Game.GlobalEvent:DispatchEvent(GameEvent.ExchangeAction.ExchangeActionRefresh)
end
timeDown = timeDown - 1
end, 1, -1, true)
this.timer:Start()
end
return ExchangeAction