426 lines
15 KiB
Lua
426 lines
15 KiB
Lua
-- Edit By ChenGY
|
|
-- 回放界面,实现上一局、下一局,加速、减速播放 按钮逻辑
|
|
-- 定义了ShowStep()方法,作用是播放录像,需要在子类中自己定义逻辑
|
|
--
|
|
|
|
local MainRightPanelView = import('.MainRightPanelView')
|
|
local PlayerInfoView = import('.PlayerInfoView2')
|
|
|
|
PlayBackView = {
|
|
_currentStep = 0,
|
|
_lastStep = 0,
|
|
_currentId = '',
|
|
_currentRound = 0,
|
|
_totalRound = 0,
|
|
_play = false,
|
|
_playFoward = true,
|
|
_speed = 1,
|
|
_timer = 0
|
|
}
|
|
|
|
local M = PlayBackView
|
|
|
|
function M:init()
|
|
self._gamectr = ControllerManager.GetController(GameController)
|
|
self._room = DataManager.CurrenRoom
|
|
self._room.playback = true
|
|
UIPackage.AddPackage('base/chat/ui/Chat')
|
|
self.cmdList = self._room.cmdList
|
|
self._eventmap = {}
|
|
-- self._full = true
|
|
self._put_map = false
|
|
self._new_hide = false
|
|
self._queue = false
|
|
self._style = 1
|
|
self:InitView()
|
|
end
|
|
|
|
function M:InitView(url)
|
|
BaseView.InitView(self, url)
|
|
local contentPane = self._root_view:GetChild('contentPane')
|
|
contentPane:AddChild(self._view)
|
|
contentPane.height = self._view.height
|
|
contentPane:Center()
|
|
|
|
self.com_notice = self._view:GetChild("com_notice")
|
|
local panel_record = self._view:GetChild('panel_record')
|
|
self._record = panel_record
|
|
local btn_LastRound = panel_record:GetChild('btn_LastRound')
|
|
local btn_NextRound = panel_record:GetChild('btn_NextRound')
|
|
local btn_LastStep = panel_record:GetChild('btn_LastStep')
|
|
local btn_NextStep = panel_record:GetChild('btn_NextStep')
|
|
local btn_return = panel_record:GetChild('btn_return')
|
|
local btn_play = panel_record:GetChild('btn_play')
|
|
local btn_restart = panel_record:GetChild('btn_restart')
|
|
btn_return.onClick:Add(handler(self, self.MaxSpeedArriws))
|
|
btn_LastStep.onClick:Add(handler(self, self.CmdLeftArrows))
|
|
btn_NextStep.onClick:Add(handler(self, self.CmdRightArrows))
|
|
btn_LastRound.onClick:Add(handler(self, self.LastRecordPlay))
|
|
btn_NextRound.onClick:Add(handler(self, self.NextRecordPlay))
|
|
btn_restart.onClick:Add(handler(self, self.RestartRecordPlay))
|
|
btn_play.onClick:Add(handler(self, self.Play))
|
|
|
|
self._viewGroup_huifang = self._view:GetChild('huifang')
|
|
self.com_logocType = self._view:GetChild("com_logo"):GetController("cType")
|
|
local _view = self._view
|
|
local _room = self._room
|
|
self._player_info = {}
|
|
|
|
local _player_info = self._player_info
|
|
for i = 1, _room.room_config.people_num do
|
|
local tem
|
|
if _room.room_config.config.game_id == 66 then
|
|
tem = _view:GetChild(string.format("player_info%d", i))
|
|
else
|
|
tem = _view:GetChild(string.format("player_info%d_%d", i, 2))
|
|
end
|
|
_player_info[i] = PlayerInfoView.new(tem, self)
|
|
tem.visible = false
|
|
end
|
|
|
|
local list = _room.player_list
|
|
for i = 1, #list do
|
|
local p = list[i]
|
|
local info = _player_info[self:GetPos(p.seat)]
|
|
info._view.visible = true
|
|
info:FillData(p)
|
|
info:MarkBank(p.seat == _room.banker_seat)
|
|
info:Ready(false)
|
|
end
|
|
|
|
local btn_back_lobby = _view:GetChild('btn_back_lobby')
|
|
if btn_back_lobby then
|
|
btn_back_lobby.onClick:Set(handler(self, self.CmdBackToLobby))
|
|
end
|
|
|
|
|
|
local btn_rule = self._view:GetChild('btn_rule_back')
|
|
if btn_rule ~= nil then
|
|
btn_rule.onClick:Set(function()
|
|
if self.RuleView == nil or self.RuleView._is_destroy then
|
|
self.RuleView = RoomInfoView.new(self._room)
|
|
end
|
|
self.RuleView:Show()
|
|
end)
|
|
end
|
|
|
|
if self._style == 1 then
|
|
local rightpanel = self._view:GetChild('right_panel')
|
|
local btn_rule = self._view:GetChild('btn_rule')
|
|
if btn_rule then
|
|
btn_rule.onClick:Set(
|
|
function()
|
|
self.RuleView = RoomInfoView.new(self._room)
|
|
self.RuleView:Show()
|
|
end
|
|
)
|
|
end
|
|
elseif self._style == 2 then
|
|
local com_roominfo = self._view:GetChild('com_roominfo')
|
|
com_roominfo:GetChild('tex_roomid').text = _room.room_id
|
|
local times = _room.score_times
|
|
local str_des = _room.room_config:GetGameName()
|
|
if times ~= 1 then
|
|
str_des = string.format('%s %s倍', str_des, times)
|
|
end
|
|
str_des = string.format('%s %s', str_des, _room.room_config:GetDes())
|
|
com_roominfo:GetChild('tex_detail').text = str_des
|
|
local tex_time = com_roominfo:GetChild('tex_time')
|
|
self._co_timer =
|
|
coroutine.start(
|
|
function()
|
|
tex_time.text = os.date('%m-%d %H:%M')
|
|
local _client = ControllerManager.GameNetClinet
|
|
if not _client then
|
|
return
|
|
end
|
|
local ping = _client:getAveragePingTime()
|
|
if not ping then
|
|
return
|
|
end
|
|
local ctr_xh = com_roominfo:GetChild('gcm_xinhao'):GetController('c1')
|
|
ping = math.floor(ping / 2)
|
|
if ping > 300 then
|
|
ping = 300
|
|
end
|
|
if ping <= 100 then
|
|
ctr_xh.selectedIndex = 0
|
|
elseif ping <= 300 then
|
|
ctr_xh.selectedIndex = 1
|
|
else
|
|
ctr_xh.selectedIndex = 2
|
|
end
|
|
coroutine.wait(10)
|
|
end
|
|
)
|
|
end
|
|
|
|
local bg_image = self._view:GetChild('bg_playback')
|
|
if bg_image then
|
|
bg_image.onClick:Set(function()
|
|
self:ChangeAlpha()
|
|
end)
|
|
end
|
|
|
|
--没有update先不显示跑马灯
|
|
self.com_notice.visible = false
|
|
-- local text_notice = self.com_notice:GetChild("text_notice")
|
|
-- text_notice.text = DataManager.GameNotice[self.noticeIndex]
|
|
-- local speed = 44
|
|
-- local time = text_notice.width / speed
|
|
|
|
-- text_notice.x = self.com_notice.width
|
|
|
|
self._eventmap = {}
|
|
end
|
|
|
|
local function __CmdAction(self, currentStep)
|
|
if self._currentStep > #self.cmdList then
|
|
return
|
|
end
|
|
self:ShowStep(currentStep)
|
|
end
|
|
|
|
function M:ShowStep(step)
|
|
end
|
|
|
|
function M:Play()
|
|
end
|
|
|
|
function M:CmdLeftArrows()
|
|
end
|
|
|
|
function M:MaxSpeedArriws()
|
|
|
|
end
|
|
|
|
function M:CmdRightArrows()
|
|
end
|
|
|
|
function M:RestartRecordPlay()
|
|
end
|
|
|
|
function M:NextCmdAction()
|
|
self._lastStep = self._currentStep
|
|
self._currentStep = self._currentStep + 1
|
|
if self._currentStep > #self.cmdList then
|
|
self._currentStep = #self.cmdList
|
|
return
|
|
end
|
|
self:ChangeButtonEnabled()
|
|
__CmdAction(self, self._currentStep)
|
|
end
|
|
|
|
function M:BackCmdAction()
|
|
self._lastStep = self._currentStep
|
|
self._currentStep = self._currentStep - 1
|
|
if self._currentStep < 0 then
|
|
self._currentStep = 0
|
|
return
|
|
end
|
|
self:ChangeButtonEnabled()
|
|
__CmdAction(self, self._currentStep)
|
|
end
|
|
|
|
function M:NextRecordPlay()
|
|
if self._currentRound < self._totalRound then
|
|
if DataManager.SelfUser.playback[self._currentId][self._currentRound + 1] ~= nil then
|
|
-- self:ChangeButtonEnabled()
|
|
self._currentRound = self._currentRound + 1
|
|
local game_id = DataManager.CurrenRoom.game_id
|
|
local room = ExtendManager.GetExtendConfig(game_id):NewRoom()
|
|
local extend = ExtendManager.GetExtendConfig(game_id)
|
|
room.game_id = game_id
|
|
DataManager.CurrenRoom = room
|
|
self._room = DataManager.CurrenRoom
|
|
extend:FillPlayBackData(DataManager.SelfUser.playback[self._currentId][self._currentRound])
|
|
if not room.self_player then
|
|
room.self_player = room:GetPlayerBySeat(1)
|
|
end
|
|
self.cmdList = self._room.cmdList
|
|
self:FillRoomData(DataManager.SelfUser.playback[self._currentId][self._currentRound])
|
|
self:ChangeAlpha()
|
|
else
|
|
ViewUtil.ShowModalWait(self._view)
|
|
local _data = {}
|
|
_data['military_id'] = self._currentId
|
|
_data['round'] = tostring(self._currentRound + 1)
|
|
local loddyCtr = ControllerManager.GetController(LoddyController)
|
|
loddyCtr:RequestPlayBack(
|
|
_data,
|
|
function(code, data)
|
|
ViewUtil.CloseModalWait()
|
|
if code == 0 then
|
|
-- self:ChangeButtonEnabled()
|
|
self._currentRound = self._currentRound + 1
|
|
|
|
DataManager.SelfUser.playback[self._currentId][self._currentRound] = data
|
|
local game_id = DataManager.CurrenRoom.game_id
|
|
local room = ExtendManager.GetExtendConfig(game_id):NewRoom()
|
|
local extend = ExtendManager.GetExtendConfig(game_id)
|
|
room.game_id = game_id
|
|
DataManager.CurrenRoom = room
|
|
self._room = DataManager.CurrenRoom
|
|
extend:FillPlayBackData(data)
|
|
if not room.self_player then
|
|
room.self_player = room:GetPlayerBySeat(1)
|
|
end
|
|
self.cmdList = self._room.cmdList
|
|
self:FillRoomData(data)
|
|
self:ChangeAlpha()
|
|
elseif code == 25 then
|
|
ViewUtil.ErrorTip(res.ReturnCode, '回放未找到!')
|
|
end
|
|
end
|
|
)
|
|
end
|
|
return true
|
|
else
|
|
ViewUtil.ErrorTip(nil, '当前已经是最后一局了')
|
|
return false
|
|
end
|
|
end
|
|
|
|
function M:LastRecordPlay()
|
|
if self._currentRound > 1 then
|
|
if DataManager.SelfUser.playback[self._currentId][self._currentRound - 1] ~= nil then
|
|
-- self:ChangeButtonEnabled()
|
|
self._currentRound = self._currentRound - 1
|
|
local game_id = DataManager.CurrenRoom.game_id
|
|
local room = ExtendManager.GetExtendConfig(game_id):NewRoom()
|
|
local extend = ExtendManager.GetExtendConfig(game_id)
|
|
room.game_id = game_id
|
|
DataManager.CurrenRoom = room
|
|
self._room = DataManager.CurrenRoom
|
|
extend:FillPlayBackData(DataManager.SelfUser.playback[self._currentId][self._currentRound])
|
|
if not room.self_player then
|
|
room.self_player = room:GetPlayerBySeat(1)
|
|
end
|
|
self.cmdList = self._room.cmdList
|
|
self:FillRoomData(DataManager.SelfUser.playback[self._currentId][self._currentRound])
|
|
self:ChangeAlpha()
|
|
else
|
|
ViewUtil.ShowModalWait(self._view)
|
|
local _data = {}
|
|
_data['military_id'] = self._currentId
|
|
_data['round'] = tostring(self._currentRound - 1)
|
|
local loddyCtr = ControllerManager.GetController(LoddyController)
|
|
loddyCtr:RequestPlayBack(
|
|
_data,
|
|
function(code, data)
|
|
ViewUtil.CloseModalWait()
|
|
if code == 0 then
|
|
-- self:ChangeButtonEnabled()
|
|
self._currentRound = self._currentRound - 1
|
|
DataManager.SelfUser.playback[self._currentId][self._currentRound] = data
|
|
local game_id = DataManager.CurrenRoom.game_id
|
|
local room = ExtendManager.GetExtendConfig(game_id):NewRoom()
|
|
local extend = ExtendManager.GetExtendConfig(game_id)
|
|
room.game_id = game_id
|
|
DataManager.CurrenRoom = room
|
|
self._room = DataManager.CurrenRoom
|
|
extend:FillPlayBackData(data)
|
|
if not room.self_player then
|
|
room.self_player = room:GetPlayerBySeat(1)
|
|
end
|
|
self.cmdList = self._room.cmdList
|
|
self:FillRoomData(data)
|
|
self:ChangeAlpha()
|
|
elseif code == 25 then
|
|
ViewUtil.ErrorTip(res.ReturnCode, '回放未找到!')
|
|
end
|
|
end
|
|
)
|
|
end
|
|
return true
|
|
else
|
|
ViewUtil.ErrorTip(nil, '当前已经是第一局了')
|
|
return false
|
|
end
|
|
end
|
|
|
|
function M:CmdBackToLobby()
|
|
self:ChangeAlpha()
|
|
local tipStr = '是否返回大厅'
|
|
-- local _curren_msg = MsgWindow.new(self._root_view, tipStr, MsgWindow.MsgMode.OkAndCancel)
|
|
-- _curren_msg.onOk:Add(
|
|
-- function()
|
|
ExtendManager.GetExtendConfig(self._room.game_id):UnAssets()
|
|
self:Destroy()
|
|
-- end
|
|
-- )
|
|
-- _curren_msg:Show()
|
|
end
|
|
|
|
function M:GetPos(seat, myseat)
|
|
local my_seat = 1
|
|
if myseat == nil then
|
|
for i = 1, #self._room.player_list do
|
|
if DataManager.SelfUser.account_id == self._room.player_list[i].self_user.account_id then
|
|
my_seat = self._room.player_list[i].seat
|
|
end
|
|
end
|
|
else
|
|
my_seat = myseat
|
|
end
|
|
return ViewUtil.GetPos(my_seat, seat, self._room.room_config.people_num)
|
|
end
|
|
|
|
function M:SetButtonEnabled(btn, enabled)
|
|
self._view:GetChild('panel_record'):GetChild(btn).enabled = enabled
|
|
end
|
|
|
|
function M:CheckButtonEnabled(btn)
|
|
return self._view:GetChild('panel_record'):GetChild(btn).enabled
|
|
end
|
|
|
|
function M:ChangeButtonEnabled()
|
|
if self._currentStep == 0 and self:CheckButtonEnabled('btn_LastStep') then
|
|
self:SetButtonEnabled('btn_LastStep', false)
|
|
elseif self._currentStep > 0 and not self:CheckButtonEnabled('btn_LastStep') then
|
|
self:SetButtonEnabled('btn_LastStep', true)
|
|
end
|
|
if self._currentStep == #self.cmdList and self:CheckButtonEnabled('btn_NextStep') then
|
|
self:SetButtonEnabled('btn_NextStep', false)
|
|
elseif self._currentStep < #self.cmdList and not self:CheckButtonEnabled('btn_NextStep') then
|
|
self:SetButtonEnabled('btn_NextStep', true)
|
|
end
|
|
self:ChangeAlpha()
|
|
end
|
|
|
|
function M:ChangeAlpha(...)
|
|
if self._record_alpha then
|
|
coroutine.stop(self._record_alpha)
|
|
self._record_alpha = nil
|
|
end
|
|
self._record_alpha =
|
|
coroutine.start(
|
|
function()
|
|
self._viewGroup_huifang.visible = true
|
|
-- self._record.alpha = 1
|
|
coroutine.wait(2)
|
|
-- self._record.alpha = 0
|
|
self._viewGroup_huifang.visible = false
|
|
end
|
|
)
|
|
end
|
|
|
|
function M:Show()
|
|
AddPanel(self._root_view)
|
|
self._state = self._view:GetController('state')
|
|
self._state.selectedIndex = 3
|
|
end
|
|
|
|
function M:Destroy()
|
|
-- self._root_view:Dispose()
|
|
if self.RuleView then
|
|
self.RuleView:Destroy()
|
|
end
|
|
GameApplication.Instance.StopMusic = 0
|
|
if self._record_alpha then
|
|
coroutine.stop(self._record_alpha)
|
|
self._record_alpha = nil
|
|
end
|
|
BaseView.Destroy(self)
|
|
end
|