263 lines
11 KiB
Lua
263 lines
11 KiB
Lua
require("Base/BasePanel")
|
|
local YuJianXingPanel = Inherit(BasePanel)
|
|
local configData = ConfigManager.GetConfigData(ConfigName.RidingSwardConfig,1)
|
|
|
|
--初始化组件(用于子类重写)
|
|
function YuJianXingPanel:InitComponent()
|
|
self.spLoader = SpriteLoader.New()
|
|
--Btns
|
|
self.backBtn = Util.GetGameObject(self.gameObject, "backBtn")
|
|
self.helpBtn = Util.GetGameObject(self.gameObject, "helpBtn")
|
|
self.helpPosition = self.helpBtn:GetComponent("RectTransform").localPosition
|
|
self.btnBet = Util.GetGameObject(self.gameObject, "Bgs/Down/btns/btnBet")
|
|
self.redPointBet = Util.GetGameObject(self.btnBet, "redPoint")
|
|
self.btnRecord = Util.GetGameObject(self.gameObject, "Bgs/Down/btns/btnRecord")
|
|
self.redPoint = Util.GetGameObject(self.btnRecord, "redPoint")
|
|
self.btnRank = Util.GetGameObject(self.gameObject, "Bgs/Down/btns/btnRank")
|
|
self.btnStore = Util.GetGameObject(self.gameObject, "Bgs/Down/btns/btnStore")
|
|
--Text
|
|
self.curActTime = Util.GetGameObject(self.gameObject, "Bgs/Up/Board/time1"):GetComponent("Text")
|
|
self.nextRoundTime = Util.GetGameObject(self.gameObject, "Bgs/Up/Board/time2"):GetComponent("Text")
|
|
self.canBetTime = Util.GetGameObject(self.gameObject, "Bgs/Up/Board/time3"):GetComponent("Text")
|
|
--Bg
|
|
self.bg = Util.GetGameObject(self.gameObject, "Bgs")
|
|
--count
|
|
self.countFrame = Util.GetGameObject(self.gameObject, "StartAni")
|
|
self.countFrame:SetActive(false)
|
|
self.countmask = Util.GetGameObject(self.countFrame, "mask")
|
|
self.countbg = Util.GetGameObject(self.countFrame, "bg")
|
|
self.countText1 = Util.GetGameObject(self.countFrame, "Text1")
|
|
self.countText2 = Util.GetGameObject(self.countFrame, "Text2")
|
|
self.countText3 = Util.GetGameObject(self.countFrame, "Text3")
|
|
self.countText4 = Util.GetGameObject(self.countFrame, "Text4")
|
|
--waiting
|
|
self.waiting = Util.GetGameObject(self.gameObject, "Waiting")
|
|
self.waitTime = Util.GetGameObject(self.waiting, "time"):GetComponent("Text")
|
|
--upview
|
|
self.UpView = SubUIManager.Open(SubUIConfig.UpView, self.bg.transform, { showType = UpViewOpenType.ShowLeft })
|
|
end
|
|
|
|
--绑定事件(用于子类重写)
|
|
function YuJianXingPanel:BindEvent()
|
|
Util.AddOnceClick(self.backBtn,function ()
|
|
SwitchPanel.OpenPanel(nil,function ()
|
|
self:ClosePanel()
|
|
end)
|
|
end)
|
|
|
|
Util.AddOnceClick(self.helpBtn,function ()
|
|
UIManager.OpenPanel(UIName.HelpPopup,HELP_TYPE.YuJianXing,self.helpPosition.x,self.helpPosition.y)
|
|
end)
|
|
|
|
Util.AddOnceClick(self.btnBet,function ()
|
|
if YuJianXingManager.curState == 2 then
|
|
PopupTipPanel.ShowTip("比赛进行中,不可竞猜!")
|
|
return
|
|
end
|
|
if YuJianXingManager.curState == 3 then
|
|
PopupTipPanel.ShowTip("赛季已结束!")
|
|
return
|
|
end
|
|
UIManager.OpenPanel(UIName.GeneralBigPopup,GENERAL_POPUP_TYPE.YuJianBet)
|
|
end)
|
|
|
|
Util.AddOnceClick(self.btnRecord,function ()
|
|
NetManager.RidingSwardInfoRequest(function ()
|
|
if #YuJianXingManager.curRecordList <= 0 then
|
|
PopupTipPanel.ShowTip("暂无竞猜记录!")
|
|
return
|
|
end
|
|
UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.YuJianXingRecord)
|
|
end)
|
|
end)
|
|
|
|
Util.AddOnceClick(self.btnRank,function ()
|
|
UIManager.OpenPanel(UIName.GeneralBigPopup,GENERAL_POPUP_TYPE.YuJianLastResult)
|
|
end)
|
|
|
|
Util.AddOnceClick(self.btnStore,function ()
|
|
if YuJianXingManager.curState == 2 then
|
|
PopupTipPanel.ShowTip("请比赛结束后前往~")
|
|
return
|
|
end
|
|
JumpManager.GoJump(40038)
|
|
end)
|
|
end
|
|
|
|
--添加事件监听(用于子类重写)
|
|
function YuJianXingPanel:AddListener()
|
|
Game.GlobalEvent:AddEvent(GameEvent.FiveAMRefresh.ServerNotifyRefresh, self.MakeRequest,self)
|
|
Game.GlobalEvent:AddEvent(GameEvent.YuJianXing.GameFinished, self.Refresh,self)
|
|
Game.GlobalEvent:AddEvent(GameEvent.YuJianXing.UpdateBetTime, self.SetBetTime,self)
|
|
end
|
|
|
|
--移除事件监听(用于子类重写)
|
|
function YuJianXingPanel:RemoveListener()
|
|
Game.GlobalEvent:RemoveEvent(GameEvent.FiveAMRefresh.ServerNotifyRefresh, self.MakeRequest,self)
|
|
Game.GlobalEvent:RemoveEvent(GameEvent.YuJianXing.GameFinished, self.Refresh,self)
|
|
Game.GlobalEvent:RemoveEvent(GameEvent.YuJianXing.UpdateBetTime, self.SetBetTime,self)
|
|
end
|
|
|
|
function YuJianXingPanel:OnSortingOrderChange()
|
|
end
|
|
|
|
--界面打开时调用(用于子类重写)
|
|
function YuJianXingPanel:OnOpen()
|
|
-- NetManager.RidingSwardInfoRequest()
|
|
end
|
|
|
|
-- 打开,重新打开时回调
|
|
function YuJianXingPanel:OnShow()
|
|
self.UpView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.YuJianXing })
|
|
self:MakeRequest(function ()
|
|
if YuJianXingManager.curState == 2 then
|
|
YuJianXingManager.InWaiting = true
|
|
end
|
|
--开启地图
|
|
YuJianXingManager.OpenMap()
|
|
self:Refresh()
|
|
end)
|
|
end
|
|
|
|
function YuJianXingPanel:MakeRequest(func)
|
|
local id = ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.YuJianXing)
|
|
if id then
|
|
NetManager.RidingSwardActivityRequest(id,function ()
|
|
if func then
|
|
func()
|
|
end
|
|
NetManager.RidingSwardInfoRequest()
|
|
end)
|
|
end
|
|
end
|
|
|
|
function YuJianXingPanel:Refresh()
|
|
YuJianXingManager.HideAllPlayers(not YuJianXingManager.InWaiting)
|
|
self.waiting:SetActive(YuJianXingManager.InWaiting)
|
|
--为小人在地图上下移动做处理
|
|
self.count = 0
|
|
self:SetTime()
|
|
end
|
|
|
|
--比赛开始动画
|
|
function YuJianXingPanel:StartAnimation()
|
|
local thread = coroutine.start(function()
|
|
self.countFrame:SetActive(true)
|
|
self.countmask:SetActive(true)
|
|
self.countbg:SetActive(true)
|
|
self.countText1:SetActive(true)
|
|
self.countText2:SetActive(false)
|
|
self.countText3:SetActive(false)
|
|
self.countText4:SetActive(false)
|
|
PlayUIAnim(self.countmask)
|
|
PlayUIAnim(self.countbg)
|
|
PlayUIAnim(self.countText1)
|
|
coroutine.wait(1)
|
|
self.countText1:SetActive(false)
|
|
self.countText2:SetActive(true)
|
|
PlayUIAnim(self.countText2)
|
|
coroutine.wait(1)
|
|
self.countText2:SetActive(false)
|
|
self.countText3:SetActive(true)
|
|
PlayUIAnim(self.countText3)
|
|
coroutine.wait(1)
|
|
self.countText3:SetActive(false)
|
|
self.countText4:SetActive(true)
|
|
PlayUIAnim(self.countText4)
|
|
coroutine.wait(1)
|
|
self.countbg:SetActive(false)
|
|
self.countText4:SetActive(false)
|
|
self.countFrame:SetActive(false)
|
|
--开始游戏
|
|
YuJianXingManager.SetGameState(true)
|
|
end)
|
|
end
|
|
|
|
function YuJianXingPanel:SetTime()
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
local activityEnd = YuJianXingManager.activityTimeCount - GetTimeStamp()
|
|
local roundEnd = YuJianXingManager.nextTimeCount - GetTimeStamp()
|
|
if activityEnd > 86400 then
|
|
self.curActTime.text = string.format("本期活动倒计时:%s",TimeToDHM(activityEnd))
|
|
else
|
|
self.curActTime.text = string.format("本期活动倒计时:%s",TimeToHMS(activityEnd))
|
|
end
|
|
if YuJianXingManager.curState == 1 then
|
|
self.nextRoundTime.text = string.format("下一轮倒计时:%s",TimeToMS(roundEnd))
|
|
elseif YuJianXingManager.curState == 2 then
|
|
self.nextRoundTime.text = string.format("比赛进行中···")
|
|
elseif YuJianXingManager.curState == 3 then
|
|
self.nextRoundTime.text = string.format("活动结算中···")
|
|
end
|
|
self.canBetTime.text = string.format( "今日可竞猜次数:%s次",configData.JoinCount - YuJianXingManager.joinCount)
|
|
self.redPoint:SetActive(YuJianXingManager.CheckRecordList())
|
|
self.redPointBet:SetActive((configData.JoinCount - YuJianXingManager.joinCount > 0) and (#YuJianXingManager.curBetList < 2) and (YuJianXingManager.curState == 1) )
|
|
self.waitTime.text = string.format("倒计时:%s",TimeToMS(roundEnd))
|
|
self.timer = Timer.New(function ()
|
|
self.redPoint:SetActive(YuJianXingManager.CheckRecordList())
|
|
self.redPointBet:SetActive((configData.JoinCount - YuJianXingManager.joinCount > 0) and (#YuJianXingManager.curBetList < 2) and (YuJianXingManager.curState == 1) )
|
|
--设置人物上下飘动2s重置一次
|
|
if self.count % 2 == 0 then
|
|
YuJianXingManager.ResetPlayerPosVertical()
|
|
end
|
|
self.count = self.count + 1
|
|
--回合倒计时
|
|
roundEnd = roundEnd - 1
|
|
if YuJianXingManager.curState == 1 then
|
|
self.nextRoundTime.text = string.format("下一轮倒计时:%s",TimeToMS(roundEnd))
|
|
if roundEnd <= 0 then
|
|
YuJianXingManager.ReGetInfo(function ()
|
|
roundEnd = YuJianXingManager.nextTimeCount - GetTimeStamp()
|
|
if YuJianXingManager.curState == 2 then--一定要确认请求回来的是2才能开始不然一直请求
|
|
YuJianXingManager.ReloadPlayersData(YuJianXingManager.curResultId)
|
|
self:StartAnimation()
|
|
end
|
|
end)
|
|
end
|
|
elseif YuJianXingManager.curState == 2 then
|
|
self.nextRoundTime.text = string.format("比赛进行中···")
|
|
self.waitTime.text = string.format("倒计时:%s",TimeToMS(roundEnd))
|
|
if roundEnd <= 0 then
|
|
YuJianXingManager.ReGetInfo(function ()
|
|
UIManager.OpenPanel(UIName.GeneralBigPopup,GENERAL_POPUP_TYPE.YuJianLastResult)
|
|
self:Refresh()
|
|
end)
|
|
end
|
|
elseif YuJianXingManager.curState == 3 then
|
|
self.nextRoundTime.text = string.format("活动已结束,赛季结算中")
|
|
end
|
|
--活动倒计时
|
|
activityEnd = activityEnd - 1
|
|
if activityEnd > 86400 then
|
|
self.curActTime.text = string.format("本期活动倒计时:%s",TimeToDHM(activityEnd))
|
|
else
|
|
self.curActTime.text = string.format("本期活动倒计时:%s",TimeToHMS(activityEnd))
|
|
end
|
|
self.canBetTime.text = string.format( "今日可竞猜次数:%s次",configData.JoinCount - YuJianXingManager.joinCount)
|
|
if activityEnd <= 0 then
|
|
self:ClosePanel()
|
|
end
|
|
end,1,-1)
|
|
self.timer:Start()
|
|
end
|
|
|
|
--界面关闭时调用(用于子类重写)
|
|
function YuJianXingPanel:OnClose()
|
|
--关闭地图--直接销毁
|
|
YuJianXingManager.CloseMap()
|
|
self.count = 0
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
end
|
|
|
|
--界面销毁时调用(用于子类重写)
|
|
function YuJianXingPanel:OnDestroy()
|
|
SubUIManager.Close(self.UpView)
|
|
end
|
|
|
|
return YuJianXingPanel |