require("Base/BasePanel") TokensPanel = Inherit(BasePanel) local this = TokensPanel local specialConfig = ConfigManager.GetConfig(ConfigName.SpecialConfig) local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig) -- local RechargeCommodityConfig = ConfigManager.GetAllConfigsDataByKey(ConfigName.RechargeCommodityConfig, "Type", GoodsTypeDef.ExpansionRedPacket) local TabBox = require("Modules/Common/TabBox") local TabData = { [1] = {name = GetLanguageStrById(50389)}, [2] = {name = GetLanguageStrById(50390)}, [3] = {name = GetLanguageStrById(50391)}, [4] = {name = GetLanguageStrById(50392)}, } local tilteImg = { [1] = { [1] = { img = "X1_bt_fulibi_bg_03", name = GetLanguageStrById(50393), color = Color.New(255/255,237/255,154/255,255/255) }, [2] = { img = "X1_bt_fulibi_bg_03", name = GetLanguageStrById(50394), color = Color.New(255/255,237/255,154/255,255/255) } }, [2] = { [1] = { img = "X1_bt_fulibi_bg_04", name = GetLanguageStrById(50395), color = Color.New(153/255,170/255,255/255,255/255) } } } local curIndex = 1 local rewards = {} local timeList = {} local itemList = {} function this:InitComponent() this.btnUse = Util.GetGameObject(this.gameObject, "btnUse") this.btnShop = Util.GetGameObject(this.gameObject, "btnShop") this.btnTurnTable = Util.GetGameObject(this.gameObject, "btnTurnTable") this.btnTurnTableRed = Util.GetGameObject(this.gameObject, "btnTurnTable/redpoint") this.btnRedPack = Util.GetGameObject(this.gameObject, "btnRedPack") this.btnBack = Util.GetGameObject(this.gameObject, "btnBack") -- this.scroll = Util.GetGameObject(this.gameObject, "scroll") this.scroll = Util.GetGameObject(this.gameObject, "scroll/grid") this.pre = Util.GetGameObject(this.gameObject, "scroll/pre") -- local v = this.scroll:GetComponent("RectTransform").rect -- this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.scroll.transform, -- this.pre, nil, Vector2.New(v.width, v.height), 1, 1, Vector2.New(0, 5)) -- this.ScrollView.moveTween.MomentumAmount = 1 -- this.ScrollView.moveTween.Strength = 1 this.tabbox = Util.GetGameObject(this.gameObject, "TabBox") -- 初始化Tab管理器 this.TabCtrl = TabBox.New() this.TabCtrl:SetTabAdapter(this.TabAdapter) this.TabCtrl:SetChangeTabCallBack(this.OnTabChange) this.btnHelp = Util.GetGameObject(this.gameObject, "btnHelp") this.helpPosition = this.btnHelp:GetComponent("RectTransform").localPosition end function this:BindEvent() Util.AddClick(this.btnBack, function() self:ClosePanel() end) Util.AddClick(this.btnTurnTable, function() UIManager.OpenPanel(UIName.WelfareTurntablePanel) end) Util.AddClick(this.btnUse, function() JumpManager.GoJump(tonumber(specialConfig[2000].Value)) end) Util.AddClick(this.btnShop, function() UIManager.OpenPanel(UIName.MapShopPanel, tonumber(specialConfig[2001].Value)) end) Util.AddClick(this.btnRedPack, function() UIManager.OpenPanel(UIName.ExpansionRedPacket) end) Util.AddClick(this.btnHelp, function() UIManager.OpenPanel(UIName.HelpPopup, HELP_TYPE.Tokens, this.helpPosition.x, this.helpPosition.y) end) end function this:AddListener() Game.GlobalEvent:AddEvent(GameEvent.Tokens.RefreshRedPoint, this.SetInfo) Game.GlobalEvent:AddEvent(GameEvent.Tokens.RefreshTask, this.OnShow) end function this:RemoveListener() Game.GlobalEvent:RemoveEvent(GameEvent.Tokens.RefreshRedPoint, this.SetInfo) Game.GlobalEvent:RemoveEvent(GameEvent.Tokens.RefreshTask, this.OnShow) end function this:OnOpen() end function this:OnShow() this.TabCtrl:Init(this.tabbox, TabData, curIndex) this.SetInfo() end function this:OnSortingOrderChange() end function this:OnClose() if this.Online then this.Online:Stop() this.Online = nil end end function this:OnDestroy() curIndex = 1 rewards = {} if this.Online then this.Online:Stop() this.Online = nil end itemList = {} end -- tab节点显示自定义 function this.TabAdapter(tab, index, status) local select = Util.GetGameObject(tab, "select") local text = Util.GetGameObject(tab, "Text"):GetComponent("Text") -- local redpoint = Util.GetGameObject(tab, "redpoint") select:SetActive(status == "select") text.text = TabData[index].name if status == "select" then text.color = Color.New(1,0.96,0.96,1) else text.color = Color.New(1,0.96,0.96,0.8) end end local taskState = { [0] = 1, [1] = 2, [2] = 0 } -- tab改变回调事件 function this.OnTabChange(index, lastIndex) curIndex = index local data -- if curIndex == 1 then data = ConfigManager.GetAllConfigsData(ConfigName.CashPointTaskConfig) -- elseif curIndex == 2 then -- data = ConfigManager.GetAllConfigsDataByKey(ConfigName.CashPointTaskConfig, "Type", 2) -- elseif curIndex == 3 then -- data = ConfigManager.GetAllConfigsDataByDoubleKey(ConfigName.CashPointTaskConfig, "Type", 1, "TaskPeriod", 1) -- elseif curIndex == 4 then -- data = ConfigManager.GetAllConfigsDataByDoubleKey(ConfigName.CashPointTaskConfig, "Type", 1, "TaskPeriod", 2) -- end table.sort(data, function (a, b) local aData = TaskManager.GetTypeTaskInfo(TaskTypeDef.Tokens, a.Id) local bData = TaskManager.GetTypeTaskInfo(TaskTypeDef.Tokens, b.Id) if aData.state == bData.state then return a.Id < b.Id else return taskState[aData.state] > taskState[bData.state] end end) timeList = {} -- table.insert(data, {}) -- this.ScrollView:SetData(data, function (i, go) -- if i == #data then -- go:SetActive(false) -- return -- else -- go:SetActive(true) -- end -- this.SingleDataShow(go, data[i]) -- end) -- for i = 1, #itemList do -- this.SingleDataShow(itemList[i]) -- end for i = 1, #data do if not itemList[i] then itemList[i] = newObjToParent(this.pre, this.scroll.transform) end this.SingleDataShow(itemList[i], data[i]) end this.OnlineTimer() end function this.SingleDataShow(go, configData) if curIndex == 1 then go:SetActive(true) elseif curIndex == 2 then go:SetActive(configData.Type == 2) elseif curIndex == 3 then go:SetActive(configData.Type == 1 and configData.TaskPeriod == 1) elseif curIndex == 4 then go:SetActive(configData.Type == 1 and configData.TaskPeriod == 2) end local icon = Util.GetGameObject(go, "icon"):GetComponent("Image") local title = Util.GetGameObject(go, "title"):GetComponent("Text") local desc = Util.GetGameObject(go, "desc"):GetComponent("Text") local reward = Util.GetGameObject(go, "reward"):GetComponent("Text") local progress = Util.GetGameObject(go, "progress"):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 data = TaskManager.GetTypeTaskInfo(TaskTypeDef.Tokens, configData.Id) icon.sprite = Util.LoadSprite(tilteImg[configData.Type][configData.TaskPeriod].img) title.text = GetLanguageStrById(tilteImg[configData.Type][configData.TaskPeriod].name) title.color = tilteImg[configData.Type][configData.TaskPeriod].color desc.text = GetLanguageStrById(configData.Desc) redpoint:SetActive(data.state == 1) SetBtnReceiveState(data.state, btn, btnTxt) if not rewards[go] then rewards[go] = SubUIManager.Open(SubUIConfig.ItemView, reward.transform) end if configData.Reward[1][1] == 0 then reward.text = GetLanguageStrById(50400).."+"..configData.Reward[1][2] else reward.text = "" rewards[go]:OnOpen(false, configData.Reward[1], 0.55) end rewards[go].gameObject:SetActive(configData.Reward[1][1] ~= 0) if configData.TaskType == 3001 then local time = TaskManager.GetOnlineTimeData(TaskTypeDef.Tokens, configData.Id).time-GetTimeStamp() if time <= 0 or data.state ~= 0 then progress.text = GetLanguageStrById(50399)..GetLanguageStrById(22288) else timeList[go] = {txt = progress, id = configData.Id, timeState = true} progress.text = GetLanguageStrById(50399)..TimeToMS(time) end else local cur, max if configData.TaskType == 74 then cur = data.progress/1000 max = configData.TaskValue[2][1]/10 else cur = data.progress max = configData.TaskValue[2][1] end cur = cur > max and max or cur if data.state ~= 0 then cur = max end progress.text = GetLanguageStrById(50399)..cur.."/"..max end Util.AddOnceClick(btn, function () if data.state == 0 then JumpManager.GoJump(configData.Jump) elseif data.state == 1 then NetManager.TakeMissionRewardRequest(TaskTypeDef.Tokens, configData.Id, function (msg) UIManager.OpenPanel(UIName.RewardItemPopup, msg.drop, 1, function () if configData.Reward[1][1] == 0 then PopupTipPanel.ShowTipByLanguageId(GetLanguageStrById(50400).."+"..configData.Reward[1][2]) end timeList = {} data.state = 2 this.OnTabChange(curIndex) end) end) end end) end function this.SetInfo() local icon = Util.GetGameObject(this.gameObject, "icon"):GetComponent("Image") local have = Util.GetGameObject(this.gameObject, "have"):GetComponent("Text") icon.sprite = Util.LoadSprite(GetResourcePath(itemConfig[900010].ResourceID)) have.text = string.format(GetLanguageStrById(50388), BagManager.GetItemCountById(900010)) this.btnTurnTableRed:SetActive(PrivilegeManager.turnTableTime > 0) end function this.OnlineTimer() if this.Online then this.Online:Stop() this.Online = nil end this.Online = Timer.New(function() if NetManager.IsConnect() then--是否在线状态 for key, value in pairs(timeList) do local time = TaskManager.GetOnlineTimeData(TaskTypeDef.Tokens, value.id).time-GetTimeStamp() if time <= 0 and value.timeState then value.timeState = false value.txt.text = GetLanguageStrById(50399)..GetLanguageStrById(22288) TaskManager.SetMissionIdState(TaskTypeDef.Tokens, value.id, 1) Game.GlobalEvent:DispatchEvent(GameEvent.Tokens.RefreshTask) else value.txt.text = GetLanguageStrById(50399)..TimeToMS(time) end end end end, 1, -1, true) this.Online:Start() end return TokensPanel