miduo_client/Assets/ManagedResources/~Lua/Modules/YuJianXing/YuJianXingPanel.lua

236 lines
9.1 KiB
Lua
Raw Normal View History

2021-09-28 10:34:05 +08:00
require("Base/BasePanel")
local YuJianXingPanel = Inherit(BasePanel)
2021-10-13 17:38:32 +08:00
local configData = ConfigManager.GetConfigData(ConfigName.RidingSwardConfig,1)
2021-09-28 10:34:05 +08:00
--初始化组件(用于子类重写)
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.btnRecord = Util.GetGameObject(self.gameObject, "Bgs/Down/btns/btnRecord")
2021-10-14 15:30:46 +08:00
self.redPoint = Util.GetGameObject(self.btnRecord, "redPoint")
2021-09-28 10:34:05 +08:00
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
2021-10-14 19:57:40 +08:00
self.bg = Util.GetGameObject(self.gameObject, "Bgs")
2021-10-11 17:25:48 +08:00
--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")
2021-10-12 11:26:48 +08:00
--waiting
self.waiting = Util.GetGameObject(self.gameObject, "Waiting")
self.waitTime = Util.GetGameObject(self.waiting, "time"):GetComponent("Text")
2021-10-14 11:25:44 +08:00
--upview
2021-10-14 19:57:40 +08:00
self.UpView = SubUIManager.Open(SubUIConfig.UpView, self.bg.transform, { showType = UpViewOpenType.ShowLeft })
2021-09-28 10:34:05 +08:00
end
--绑定事件(用于子类重写)
function YuJianXingPanel:BindEvent()
Util.AddOnceClick(self.backBtn,function ()
2021-10-12 11:26:48 +08:00
SwitchPanel.OpenPanel(nil,function ()
self:ClosePanel()
end)
2021-09-28 10:34:05 +08:00
end)
Util.AddOnceClick(self.helpBtn,function ()
UIManager.OpenPanel(UIName.HelpPopup,HELP_TYPE.YuJianXing,self.helpPosition.x,self.helpPosition.y)
2021-09-28 10:34:05 +08:00
end)
Util.AddOnceClick(self.btnBet,function ()
if YuJianXingManager.curState == 2 then
PopupTipPanel.ShowTip("比赛进行中,不可竞猜!")
return
end
2021-10-08 20:49:25 +08:00
UIManager.OpenPanel(UIName.GeneralBigPopup,GENERAL_POPUP_TYPE.YuJianBet)
2021-09-28 10:34:05 +08:00
end)
Util.AddOnceClick(self.btnRecord,function ()
2021-10-14 18:02:30 +08:00
NetManager.RidingSwardInfoRequest(function ()
if #YuJianXingManager.curRecordList <= 0 then
PopupTipPanel.ShowTip("暂无竞猜纪录!")
return
end
UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.YuJianXingRecord)
end)
2021-09-28 10:34:05 +08:00
end)
Util.AddOnceClick(self.btnRank,function ()
2021-10-08 20:49:25 +08:00
UIManager.OpenPanel(UIName.GeneralBigPopup,GENERAL_POPUP_TYPE.YuJianLastResult)
2021-09-28 10:34:05 +08:00
end)
Util.AddOnceClick(self.btnStore,function ()
if YuJianXingManager.curState == 2 then
PopupTipPanel.ShowTip("请比赛结束后前往~")
return
end
2021-10-15 11:15:42 +08:00
JumpManager.GoJump(40038)
2021-09-28 17:48:28 +08:00
end)
2021-09-28 10:34:05 +08:00
end
--添加事件监听(用于子类重写)
function YuJianXingPanel:AddListener()
2021-10-15 14:02:33 +08:00
Game.GlobalEvent:AddEvent(GameEvent.FiveAMRefresh.ServerNotifyRefresh, self.MakeRequest,self)
2021-10-12 11:26:48 +08:00
Game.GlobalEvent:AddEvent(GameEvent.YuJianXing.GameFinished, self.Refresh,self)
2021-10-13 19:15:39 +08:00
Game.GlobalEvent:AddEvent(GameEvent.YuJianXing.UpdateBetTime, self.SetBetTime,self)
2021-09-28 10:34:05 +08:00
end
--移除事件监听(用于子类重写)
function YuJianXingPanel:RemoveListener()
2021-10-15 14:02:33 +08:00
Game.GlobalEvent:RemoveEvent(GameEvent.FiveAMRefresh.ServerNotifyRefresh, self.MakeRequest,self)
2021-10-12 11:26:48 +08:00
Game.GlobalEvent:RemoveEvent(GameEvent.YuJianXing.GameFinished, self.Refresh,self)
2021-10-13 19:15:39 +08:00
Game.GlobalEvent:RemoveEvent(GameEvent.YuJianXing.UpdateBetTime, self.SetBetTime,self)
2021-09-28 10:34:05 +08:00
end
function YuJianXingPanel:OnSortingOrderChange()
end
--界面打开时调用(用于子类重写)
function YuJianXingPanel:OnOpen()
2021-10-14 17:10:40 +08:00
NetManager.RidingSwardInfoRequest()
2021-09-28 10:34:05 +08:00
end
-- 打开,重新打开时回调
function YuJianXingPanel:OnShow()
2021-10-14 11:25:44 +08:00
self.UpView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.YuJianXing })
if YuJianXingManager.curState == 2 then
YuJianXingManager.InWaiting = true
end
2021-10-11 14:37:33 +08:00
--开启地图
2021-10-08 15:45:28 +08:00
YuJianXingManager.OpenMap()
2021-10-11 17:25:48 +08:00
self:Refresh()
end
2021-10-15 14:02:33 +08:00
function YuJianXingPanel:MakeRequest()
local id = ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.YuJianXing)
if id then
NetManager.RidingSwardActivityRequest(id)
NetManager.RidingSwardInfoRequest()
end
end
2021-10-11 17:25:48 +08:00
function YuJianXingPanel:Refresh()
2021-10-13 15:39:47 +08:00
YuJianXingManager.HideAllPlayers(not YuJianXingManager.InWaiting)
2021-10-12 11:26:48 +08:00
self.waiting:SetActive(YuJianXingManager.InWaiting)
2021-10-11 14:37:33 +08:00
--为小人在地图上下移动做处理
2021-10-09 16:24:34 +08:00
self.count = 0
2021-10-11 17:25:48 +08:00
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)
2021-10-12 11:26:48 +08:00
--开始游戏
2021-10-11 17:25:48 +08:00
YuJianXingManager.SetGameState(true)
end)
end
function YuJianXingPanel:SetTime()
2021-10-09 16:24:34 +08:00
if self.timer then
self.timer:Stop()
self.timer = nil
end
2021-10-11 17:25:48 +08:00
local activityEnd = YuJianXingManager.activityTimeCount - GetTimeStamp()
local roundEnd = YuJianXingManager.nextTimeCount - GetTimeStamp()
self.curActTime.text = string.format("本期活动倒计时:%s",TimeToDHM(activityEnd))
2021-10-12 11:26:48 +08:00
if YuJianXingManager.curState == 1 then
self.nextRoundTime.text = string.format("下一轮倒计时:%s",TimeToMS(roundEnd))
elseif YuJianXingManager.curState == 2 then
self.nextRoundTime.text = string.format("比赛进行中···")
end
2021-10-15 14:02:33 +08:00
self.canBetTime.text = string.format( "今日可竞猜次数:%s次",configData.JoinCount - YuJianXingManager.joinCount)
2021-10-14 17:10:40 +08:00
self.redPoint:SetActive(YuJianXingManager.CheckRecordList())
2021-10-09 16:24:34 +08:00
self.timer = Timer.New(function ()
2021-10-14 17:10:40 +08:00
self.redPoint:SetActive(YuJianXingManager.CheckRecordList())
2021-10-11 17:25:48 +08:00
--设置人物上下飘动2s重置一次
2021-10-09 16:24:34 +08:00
if self.count % 2 == 0 then
YuJianXingManager.ResetPlayerPosVertical()
end
self.count = self.count + 1
2021-10-11 17:25:48 +08:00
--回合倒计时
roundEnd = roundEnd - 1
if YuJianXingManager.curState == 1 then
self.nextRoundTime.text = string.format("下一轮倒计时:%s",TimeToMS(roundEnd))
if roundEnd <= 0 then
2021-10-12 11:26:48 +08:00
YuJianXingManager.ReGetInfo(function ()
2021-10-13 15:39:47 +08:00
roundEnd = YuJianXingManager.nextTimeCount - GetTimeStamp()
YuJianXingManager.ReloadPlayersData(YuJianXingManager.curResultId)
2021-10-12 11:26:48 +08:00
self:StartAnimation()
end)
2021-10-11 17:25:48 +08:00
end
elseif YuJianXingManager.curState == 2 then
self.nextRoundTime.text = string.format("比赛进行中···")
2021-10-12 11:26:48 +08:00
self.waitTime.text = string.format("倒计时:%s",TimeToMS(roundEnd))
if roundEnd <= 0 then
YuJianXingManager.ReGetInfo(function ()
2021-10-13 15:39:47 +08:00
if YuJianXingManager.curState == 1 then
self:Refresh()
end
2021-10-12 11:26:48 +08:00
end)
end
2021-10-11 17:25:48 +08:00
end
--活动倒计时
activityEnd = activityEnd - 1
self.curActTime.text = string.format("本期活动倒计时:%s",TimeToDHM(activityEnd))
2021-10-15 14:02:33 +08:00
self.canBetTime.text = string.format( "今日可竞猜次数:%s次",configData.JoinCount - YuJianXingManager.joinCount)
2021-10-11 17:25:48 +08:00
if activityEnd <= 0 then
self:ClosePanel()
end
2021-10-09 18:17:59 +08:00
end,1,-1)
self.timer:Start()
2021-09-28 10:34:05 +08:00
end
--界面关闭时调用(用于子类重写)
function YuJianXingPanel:OnClose()
2021-10-11 14:37:33 +08:00
--关闭地图--直接销毁
2021-10-08 15:45:28 +08:00
YuJianXingManager.CloseMap()
2021-10-09 16:24:34 +08:00
self.count = 0
if self.timer then
self.timer:Stop()
self.timer = nil
end
2021-09-28 10:34:05 +08:00
end
--界面销毁时调用(用于子类重写)
function YuJianXingPanel:OnDestroy()
2021-10-14 11:25:44 +08:00
SubUIManager.Close(self.UpView)
2021-09-28 10:34:05 +08:00
end
return YuJianXingPanel