miduo_client/Assets/ManagedResources/~Lua/Modules/LingMaiMiJing/LingMaiMiJingPanel.lua

226 lines
8.6 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

require("Base/BasePanel")
local LingMaiMiJingPanel = Inherit(BasePanel)
local lodeConfig = ConfigManager.GetConfig(ConfigName.LodeConfig)
local TEXTLIST = {
[1] = "距灵脉秘境结束:%s",
[2] = "距灵脉秘境开启:%s",
[3] = "距灵脉秘境关闭:%s",
[4] = "当前state为0",
}
--初始化组件(用于子类重写)
function LingMaiMiJingPanel:InitComponent()
self.spLoader = SpriteLoader.New()
-- 屏幕适配修改
self.UpView = SubUIManager.Open(SubUIConfig.UpView, self.gameObject.transform)
self.backBtn = Util.GetGameObject(self.gameObject,"backBtn")
self.helpBtn = Util.GetGameObject(self.gameObject,"HelpBtn")
self.helpPosition=self.helpBtn:GetComponent("RectTransform").localPosition
--top
self.topBar = Util.GetGameObject(self.gameObject,"topBar")
self.leftTime = Util.GetGameObject(self.topBar,"Text"):GetComponent("Text")
--bottom
self.bottom = Util.GetGameObject(self.gameObject,"bottomBar")
self.time = Util.GetGameObject(self.bottom,"time")
self.TextTip = Util.GetGameObject(self.bottom,"Text")
self.mytime = Util.GetGameObject(self.bottom,"time/Text"):GetComponent("Text")
self.rewardGrid = Util.GetGameObject(self.bottom,"grid")
self.rewardPre = Util.GetGameObject(self.rewardGrid,"rewardPre")
self.rewardList = {}
self.jump = Util.GetGameObject(self.bottom,"Jump")
self.jumpBtn = Util.GetGameObject(self.jump,"btnJump")
self.leftTime = Util.GetGameObject(self.jump,"Time/Text"):GetComponent("Text")
self.inputField = Util.GetGameObject(self.jump, "Input/InputField"):GetComponent("InputField")
--rightBtns
self.rightBtns = Util.GetGameObject(self.gameObject,"rightBtns")
self.sortBtn = Util.GetGameObject(self.rightBtns,"sortBtn")
self.rewardBtn = Util.GetGameObject(self.rightBtns,"rewardBtn")
self.recordBtn = Util.GetGameObject(self.rightBtns,"recordBtn")
--contentgrid
self.contentGrid = Util.GetGameObject(self.gameObject,"ContentGrid")
self.veinList = {}
self.itemList = {}
for i = 1, 5 do
self.veinList[i] = Util.GetGameObject(self.contentGrid,"VeinPre ("..i..")")
end
--左右切换按钮
self.lastBtn = Util.GetGameObject(self.gameObject,"lastBtn")
self.nextBtn = Util.GetGameObject(self.gameObject,"nextBtn")
end
--绑定事件(用于子类重写)
function LingMaiMiJingPanel:BindEvent()
Util.AddClick(self.backBtn,function()
LingMaiMiJingManager.curPage = 0
self:ClosePanel()
end)
Util.AddOnceClick(self.helpBtn, function()
UIManager.OpenPanel(UIName.HelpPopup,HELP_TYPE.LingMaiMiJing,self.helpPosition.x,self.helpPosition.y)
end)
Util.AddOnceClick(self.recordBtn, function()
LingMaiMiJingManager.OpenRecord()
end)
Util.AddOnceClick(self.rewardBtn, function()
UIManager.OpenPanel(UIName.GeneralRankRewardPanel,5,LingMaiMiJingManager.myPlaceId%250)--需要活动id和我的排名
end)
Util.AddOnceClick(self.sortBtn, function()
UIManager.OpenPanel(UIName.RankingSingleListPanel,rankKingList[33])
end)
Util.AddClick(self.lastBtn,function()
LingMaiMiJingManager.curPage = LingMaiMiJingManager.curPage - 1
self:OnShow()
end)
Util.AddClick(self.nextBtn,function()
LingMaiMiJingManager.curPage = LingMaiMiJingManager.curPage + 1
self:OnShow()
end)
Util.AddClick(self.jumpBtn,function()
if self.inputField.text ~= "" then
local num = tonumber(self.inputField.text)
if num > 50 then
num = 50
elseif num < 0 then
num = 1
end
LingMaiMiJingManager.curPage = num
self:OnShow()
self.inputField.text = ""
else
PopupTipPanel.ShowTip("请输入要前往的位置")
end
end)
end
--添加事件监听(用于子类重写)
function LingMaiMiJingPanel:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.LingMaiMiJing.RefreshPanel, self.OnShow,self)
end
--移除事件监听(用于子类重写)
function LingMaiMiJingPanel:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.LingMaiMiJing.RefreshPanel, self.OnShow,self)
end
--跨服
function LingMaiMiJingPanel:OnOpen()
self.UpView:OnOpen({showType = UpViewOpenType.ShowLeft, panelType = PanelType.Main})
end
--界面打开时调用(用于子类重写)
function LingMaiMiJingPanel:OnShow()
NetManager.GetLingMaiInfoRequest(LingMaiMiJingManager.curPage,function ()
self.data = LingMaiMiJingManager.GetData()
self:SetTime()
self:SetMydata()
self:SetVeins()
self.lastBtn:SetActive(LingMaiMiJingManager.curPage - 1 > 0)
self.nextBtn:SetActive(LingMaiMiJingManager.curPage + 1 <= 50)
end)
end
function LingMaiMiJingPanel:SetMydata()
if self.data.myPlaceId > 0 then
self.time:SetActive(true)
self.TextTip:SetActive(false)
self.rewardGrid:SetActive(true)
local configData = lodeConfig[self.data.myPlaceId]
for i = 1, #self.rewardList do
self.rewardList[i]:SetActive(false)
end
for j = 1, #configData.RewardList do
local item = self.rewardList[j]
if not item then
item = newObjToParent(self.rewardPre,self.rewardGrid.transform)
self.rewardList[j] = item
end
item:SetActive(true)
Util.GetGameObject(item,"icon"):GetComponent("Image").sprite = self.spLoader:LoadSprite(GetSpriteNameByItemId(configData.RewardList[j][1]))
Util.GetGameObject(item,"Text"):GetComponent("Text").text = string.format( "%s/分",configData.RewardList[j][2])
end
else
self.time:SetActive(false)
self.TextTip:SetActive(true)
self.rewardGrid:SetActive(false)
end
ForceRebuildLayout(self.bottom.transform)
end
function LingMaiMiJingPanel:SetVeins()
for i = 1, 5 do
local go = self.veinList[i]
local data = self.data.lingmaiData[i]
local title = Util.GetGameObject(go,"title/Name"):GetComponent("Text")
local num = Util.GetGameObject(go,"title/Num"):GetComponent("Text")
local name = Util.GetGameObject(go,"obtain/name"):GetComponent("Text")
local grid = Util.GetGameObject(go,"obtain/grid")
local rewardPre = Util.GetGameObject(grid,"rewardPre")
rewardPre:SetActive(false)
title.text = data.veinName
num.text = data.No
name.text = string.format( "%s %s",data.servername,data.name)
if not self.itemList[i] then
self.itemList[i] = {}
end
for k = 1, #self.itemList[i] do
self.itemList[i][k]:SetActive(false)
end
for j = 1, #data.RewardList do
local item = self.itemList[i][j]
if not item then
item = newObjToParent(rewardPre,grid.transform)
self.itemList[i][j] = item
end
item:SetActive(true)
Util.GetGameObject(item,"icon"):GetComponent("Image").sprite = self.spLoader:LoadSprite(GetSpriteNameByItemId(data.RewardList[j][1]))
Util.GetGameObject(item,"Text"):GetComponent("Text").text = string.format( "%s/分",data.RewardList[j][2])
end
Util.AddOnceClick(go,function ()
UIManager.OpenPanel(UIName.PlayerInfoPopup, data.uid,PLAYER_INFO_VIEW_TYPE.LINGMAIMIJING,data.serverName and data.serverName or nil,data)
end)
end
end
function LingMaiMiJingPanel:SetTime()
if self.data.state == 0 then
self:ClosePanel()
end
if self.timer then
self.timer:Stop()
self.timer = nil
end
local time = self.data.endTime - GetTimeStamp()
local timeStayAtHere = GetTimeStamp() - self.data.startTime
self.mytime.text = string.format("%s分",math.floor( timeStayAtHere/60 ))
local text = TEXTLIST[self.data.state]
self.leftTime.text = string.format(text,TimeToFelaxible(time))
self.timer = Timer.New(function ()
time = time - 1
timeStayAtHere = timeStayAtHere + 1
self.leftTime.text = string.format(text,TimeToFelaxible(time))
self.mytime.text = string.format("%s分",math.floor( timeStayAtHere/60 ))
if time <= 0 then
self:OnShow()
end
end, 1, -1, true)
self.timer:Start()
end
--界面关闭时调用(用于子类重写)
function LingMaiMiJingPanel:OnClose()
if self.timer then
self.timer:Stop()
self.timer = nil
end
end
--界面销毁时调用(用于子类重写)
function LingMaiMiJingPanel:OnDestroy()
self.spLoader:Destroy()
self.veinList = {}
self.rewardList = {}
self.itemList = {}
end
return LingMaiMiJingPanel