202 lines
7.6 KiB
Lua
202 lines
7.6 KiB
Lua
require("Base/BasePanel")
|
|
DiscountTaskPanel = Inherit(BasePanel)
|
|
local this = DiscountTaskPanel
|
|
local ItemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
|
|
local discountItems = {}
|
|
local jumpItems = {}
|
|
local taskRewards = {}
|
|
local discount = {900001, 900002, 900003, 900004}
|
|
|
|
function this:InitComponent()
|
|
this.mask = Util.GetGameObject(this.gameObject, "mask")
|
|
this.btnHelp = Util.GetGameObject(this.gameObject, "btnHelp")
|
|
this.helpPosition = this.btnHelp.transform:GetComponent("RectTransform").localPosition
|
|
this.btnBack = Util.GetGameObject(this.gameObject, "btnBack")
|
|
|
|
this.discountGrid = Util.GetGameObject(this.gameObject, "grid")
|
|
this.discountPre = Util.GetGameObject(this.gameObject, "grid/pre")
|
|
|
|
this.scroll = Util.GetGameObject(this.gameObject, "scroll")
|
|
this.taskPre = Util.GetGameObject(this.gameObject, "scroll/pre")
|
|
local v = this.scroll:GetComponent("RectTransform").rect
|
|
this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.scroll.transform,
|
|
this.taskPre, nil, Vector2.New(v.width, v.height), 1, 1, Vector2.New(0, 5))
|
|
this.ScrollView.moveTween.MomentumAmount = 1
|
|
this.ScrollView.moveTween.Strength = 1
|
|
end
|
|
|
|
function this:BindEvent()
|
|
Util.AddClick(this.mask, function()
|
|
this:ClosePanel()
|
|
end)
|
|
Util.AddClick(this.btnBack, function()
|
|
this:ClosePanel()
|
|
end)
|
|
Util.AddClick(this.btnHelp, function()
|
|
UIManager.OpenPanel(UIName.HelpPopup, HELP_TYPE.Discount, this.helpPosition.x, this.helpPosition.y)
|
|
end)
|
|
end
|
|
|
|
function this:AddListener()
|
|
end
|
|
|
|
function this:RemoveListener()
|
|
end
|
|
|
|
function this:OnOpen()
|
|
end
|
|
|
|
function this:OnShow()
|
|
this.SetItemNum()
|
|
this.SetOnlineReward()
|
|
this.SetTaskItem()
|
|
this.SetJumpItem()
|
|
end
|
|
|
|
function this:OnSortingOrderChange()
|
|
end
|
|
|
|
function this:OnClose()
|
|
if this.discountTimer then
|
|
this.discountTimer:Stop()
|
|
this.discountTimer = nil
|
|
end
|
|
end
|
|
|
|
function this:OnDestroy()
|
|
if this.discountTimer then
|
|
this.discountTimer:Stop()
|
|
this.discountTimer = nil
|
|
end
|
|
discountItems = {}
|
|
jumpItems = {}
|
|
this.onlineItem = nil
|
|
end
|
|
|
|
function this.SetItemNum()
|
|
for i = 1, #discount do
|
|
if not discountItems[i] then
|
|
discountItems[i] = newObjToParent(this.discountPre, this.discountGrid.transform)
|
|
end
|
|
Util.GetGameObject(discountItems[i], "icon"):GetComponent("Image").sprite = Util.LoadSprite(GetResourcePath(ItemConfig[discount[i]].ResourceID))
|
|
local haveNum = BagManager.GetItemCountById(discount[i])
|
|
local str = string.format("%sx<size=36>%s</size>", GetLanguageStrById(ItemConfig[discount[i]].Name), haveNum)
|
|
Util.GetGameObject(discountItems[i], "Text"):GetComponent("Text").text = str
|
|
discountItems[i].gameObject.name = "discountItem"..i
|
|
discountItems[i]:SetActive(true)
|
|
Util.AddOnceClick(discountItems[i], function ()
|
|
UIManager.OpenPanel(UIName.RewardItemSingleShowPopup, discount[i], function ()
|
|
this.SetItemNum()
|
|
end)
|
|
end)
|
|
end
|
|
end
|
|
|
|
function this.SetOnlineReward()
|
|
local data = ConfigManager.GetConfigDataByKey(ConfigName.DeValueConfig, "Type", 3)
|
|
local pos = Util.GetGameObject(this.gameObject, "item")
|
|
local timeTxt = Util.GetGameObject(this.gameObject, "item/time"):GetComponent("Text")
|
|
if not this.onlineItem then
|
|
this.onlineItem = SubUIManager.Open(SubUIConfig.ItemView, pos.transform)
|
|
end
|
|
this.onlineItem:OnOpen(false, data.Reward[1], 0.6)
|
|
local taskData = TaskManager.GetTypeTaskInfo(TaskTypeDef.Discount, data.Id)
|
|
local time = TaskManager.GetOnlineTimeData(TaskTypeDef.Discount, data.Id).time-GetTimeStamp()
|
|
if time <= 0 and taskData.state ~= 2 then
|
|
timeTxt.text = GetLanguageStrById(10471)
|
|
this.onlineItem:SetRedPointState(true)
|
|
elseif taskData.state == 2 then
|
|
timeTxt.text = GetLanguageStrById(10350)
|
|
this.onlineItem:SetRedPointState(false)
|
|
else
|
|
timeTxt.text = TimeToMS(time)
|
|
this.DiscountOnlineRewardTimer(timeTxt)
|
|
this.onlineItem:SetRedPointState(false)
|
|
end
|
|
this.onlineItem:ClickEvent(function ()
|
|
if taskData.state ~= 2 then
|
|
NetManager.TakeMissionRewardRequest(TaskTypeDef.Discount, data.Id, function(msg)
|
|
UIManager.OpenPanel(UIName.RewardItemPopup, msg.drop, 1, function ()
|
|
taskData.state = 2
|
|
this.SetOnlineReward()
|
|
this.SetItemNum()
|
|
CheckRedPointStatus(RedPointType.Discount)
|
|
end)
|
|
end)
|
|
end
|
|
end)
|
|
end
|
|
|
|
function this.DiscountOnlineRewardTimer(timeTxt)
|
|
if this.discountTimer then
|
|
this.discountTimer:Stop()
|
|
this.discountTimer = nil
|
|
end
|
|
this.discountTimer = Timer.New(function()
|
|
if NetManager.IsConnect() then--是否在线状态
|
|
local data = ConfigManager.GetConfigDataByKey(ConfigName.DeValueConfig, "Type", 3)
|
|
local time = TaskManager.GetOnlineTimeData(TaskTypeDef.Discount, data.Id).time-GetTimeStamp()
|
|
if time <= 0 then
|
|
this.discountTimer:Stop()
|
|
this.discountTimer = nil
|
|
timeTxt.text = GetLanguageStrById(10471)
|
|
else
|
|
timeTxt.text = TimeToMS(time)
|
|
end
|
|
end
|
|
end, 1, -1, true)
|
|
this.discountTimer:Start()
|
|
end
|
|
|
|
function this.SetTaskItem()
|
|
local data = ConfigManager.GetAllConfigsDataByKey(ConfigName.DeValueConfig, "Type", 2)
|
|
this.ScrollView:SetData(data, function (index, go)
|
|
local pos = Util.GetGameObject(go, "pos")
|
|
local desc = Util.GetGameObject(go, "desc"):GetComponent("Text")
|
|
local btn = Util.GetGameObject(go, "btn")
|
|
local btnTxt = Util.GetGameObject(go, "btn/Text"):GetComponent("Text")
|
|
local redpoint = Util.GetGameObject(go, "btn/redpoint")
|
|
|
|
local taskData = TaskManager.GetTypeTaskInfo(TaskTypeDef.Discount, data[index].Id)
|
|
redpoint:SetActive(taskData.state == 1)
|
|
desc.text = GetLanguageStrById(data[index].Desc)
|
|
if not taskRewards[go] then
|
|
taskRewards[go] = SubUIManager.Open(SubUIConfig.ItemView, pos.transform)
|
|
end
|
|
taskRewards[go]:OnOpen(false, data[index].Reward[1], 0.55)
|
|
SetBtnReceiveState(taskData.state, btn, btnTxt)
|
|
|
|
Util.AddOnceClick(btn, function ()
|
|
if taskData.state == 0 then
|
|
JumpManager.GoJump(data[index].JumpID)
|
|
elseif taskData.state == 1 then
|
|
NetManager.TakeMissionRewardRequest(TaskTypeDef.Discount, data[index].Id, function(msg)
|
|
UIManager.OpenPanel(UIName.RewardItemPopup, msg.drop, 1, function ()
|
|
this.SetTaskItem()
|
|
this.SetItemNum()
|
|
end)
|
|
end)
|
|
end
|
|
end)
|
|
end)
|
|
end
|
|
|
|
function this.SetJumpItem()
|
|
local jumpGrid = Util.GetGameObject(this.gameObject, "jumpGrid")
|
|
local pre = Util.GetGameObject(this.gameObject, "jumpGrid/pre")
|
|
local data = ConfigManager.GetAllConfigsDataByKey(ConfigName.DeValueConfig, "Type", 1)
|
|
for i = 1, #data do
|
|
if not jumpItems[i] then
|
|
jumpItems[i] = newObjToParent(pre, jumpGrid.transform)
|
|
end
|
|
Util.GetGameObject(jumpItems[i], "icon"):GetComponent("Image").sprite = Util.LoadSprite(data[i].IconName)
|
|
Util.GetGameObject(jumpItems[i], "Text"):GetComponent("Text").text = GetLanguageStrById(data[i].Desc)
|
|
jumpItems[i].gameObject.name = "jumpItem"..i
|
|
jumpItems[i]:SetActive(true)
|
|
Util.AddOnceClick(jumpItems[i], function ()
|
|
JumpManager.GoJump(data[i].JumpID)
|
|
end)
|
|
end
|
|
end
|
|
|
|
return DiscountTaskPanel |