1088 lines
36 KiB
Lua
1088 lines
36 KiB
Lua
local MainRightPanelView = import('.MainRightPanelView')
|
||
local PlayerInfoView = import('.PlayerInfoView')
|
||
local ChatView = import('.ChatView')
|
||
local DismissRoomWindow = import('.DismissRoomWindow')
|
||
local SettingView = import('.SettingView')
|
||
local PlayerDistanceView = import('.PlayerDistanceView')
|
||
local FGAssistView = import('.FGAssistView')
|
||
|
||
-- MainView
|
||
MainView = {}
|
||
|
||
-- 继承 BaseView
|
||
setmetatable(MainView, {
|
||
__index = BaseView
|
||
})
|
||
|
||
local M = MainView
|
||
|
||
-- 语音是否禁止
|
||
local record_baned = 0
|
||
|
||
function M:init()
|
||
TimerManager.Clear()
|
||
self._gamectr = ControllerManager.GetController(GameController)
|
||
self._room = DataManager.CurrenRoom
|
||
self._allow_dissmiss = true -- 游戏开始后显示解散房间按钮
|
||
self._multilingual = false -- 游戏支持多语言切换
|
||
self._language = 0 -- 语言默认0,1可以设为需要的方言
|
||
self._style = 1 -- 游戏风格
|
||
self._hide_assist = false -- 是否隐藏牌友圈助手
|
||
self._gps_style = 1
|
||
self.dismiss_cd = 0
|
||
UIPackage.AddPackage('base/chat/ui/Chat')
|
||
self.Fix_Msg_Chat = ViewUtil.Fix_Msg_Chat -- 自动回复消息列表
|
||
self.Fix_Msg_Chat2 = nil -- 自动回复列表2
|
||
self:InitView()
|
||
self:SetTuoGuanState()
|
||
end
|
||
|
||
function M:SetTuoGuanState()
|
||
-- printlog("初始化设置托管状态")
|
||
if ControllerManager.enterPlayerData and #ControllerManager.enterPlayerData > 0 then
|
||
-- pt(ControllerManager.enterPlayerData)
|
||
for i = 1, #ControllerManager.enterPlayerData do
|
||
local p = self._player_info[self:GetPos(ControllerManager.enterPlayerData[i].seat)]
|
||
-- p.seat=ControllerManager.enterPlayerData[i].seat
|
||
local t = ControllerManager.enterPlayerData[i].entrust_time
|
||
-- local isShow=ControllerManager.enterPlayerData[i].entrust
|
||
-- if isShow==nil then return end
|
||
|
||
if t and t > 0 then
|
||
p:IsShowTGTips(true, t)
|
||
else
|
||
|
||
end
|
||
|
||
end
|
||
ControllerManager.enterPlayerData = nil
|
||
end
|
||
end
|
||
|
||
function M:InitView(url, isHideIpAdds)
|
||
-- print("url===>>>")
|
||
-- print(url)
|
||
-- print(debug.traceback())
|
||
BaseView.InitView(self, url)
|
||
--
|
||
|
||
--[[ 多语言切换(适用于设置界面使用Main_Majiang中SettingView2的游戏)
|
||
在EXMainView中进行以下操作
|
||
1.在调用 MainView.InitView()前设置self._multilingual = true
|
||
2.(没重写M:NewSettingView()就无视这条)
|
||
2.1在NewSettingView方法中,创建SettingView对象时第二个参数传true,SettingView.new(self._root_view, true)
|
||
2.2加上切换语言回调 settingView.onChangeLanguageCallback:Add(function(languauge) self._language = languauge end)
|
||
3.在扩展EXMainView中直接使用self._language判断语言,根据需要重写PlaySound和PlayChatSound
|
||
]]
|
||
if self._multilingual then
|
||
self:SetLanguage(PlayerPrefs.GetInt('Languauge' .. DataManager.CurrenRoom.game_id))
|
||
end
|
||
|
||
self._gcm_chat = self._view:GetChild('gcm_chat')
|
||
if self._gcm_chat then
|
||
if self._room.ban_chat2 then
|
||
self._gcm_chat:GetController('sdk').selectedIndex = 1
|
||
self._gcm_chat.visible = false
|
||
end
|
||
if self._room.room_config and self._room.room_config.isHidden and self._room.room_config.isHidden == 1 then
|
||
self._gcm_chat.visible = false
|
||
end
|
||
end
|
||
|
||
local _view = self._view
|
||
local _room = self._room
|
||
self._state = _view:GetController('state')
|
||
self._ctr_action = _view:GetController("action")
|
||
|
||
self:InitPlayerInfoView(isHideIpAdds)
|
||
|
||
-- 风格1是屏幕上方左右两个组件显示信息
|
||
if self._style == 1 then
|
||
-- 风格2,屏幕上方一个组件显示信息,所有按钮放在一个单独的下拉菜单中
|
||
local rightpanel = self._view:GetChild('right_panel')
|
||
if rightpanel then
|
||
self._rightPanelView = MainRightPanelView.new(self, rightpanel)
|
||
if self._rightPanelView then
|
||
self._rightPanelView:_ShowTime()
|
||
end
|
||
end
|
||
local roominfo_panel = _view:GetChild('roominfo_panel')
|
||
self:FillRoomConfig(roominfo_panel, _room)
|
||
local roominfo_panel1 = _view:GetChild('roominfo_panel1')
|
||
self:FillRoomConfig(roominfo_panel1, _room)
|
||
|
||
-- 显示玩家距离
|
||
self.btn_distance = self._view:GetChild('btn_distance')
|
||
-- self.btn_distance.displayObject.gameObject:SetActive(false)
|
||
if self.btn_distance then
|
||
self.btn_distance.onClick:Add(function()
|
||
if self._room.self_player.seat == 0 then
|
||
return
|
||
end
|
||
self.distance_view = PlayerDistanceView.new(false, self._gps_style, function(v)
|
||
self:continue_game(v)
|
||
end)
|
||
self.distance_view._view:GetController("state").selectedIndex =
|
||
self._state.selectedIndex > 0 and self._state.selectedIndex < 3 and 1 or 0
|
||
self.distance_view:Show()
|
||
end)
|
||
end
|
||
|
||
local btn_rule = self._view:GetChild('btn_rule')
|
||
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 _view:GetChild('tex_version') ~= nil then
|
||
_view:GetChild('tex_version').text = 'v' .. ExtendManager.GetGameData(_room.game_id).version
|
||
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()
|
||
while true do
|
||
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)
|
||
end
|
||
|
||
local list = _room.player_list
|
||
for i = 1, #list do
|
||
local p = list[i]
|
||
if (p.seat ~= 0) then
|
||
local info = self._player_info[self:GetPos(p.seat)]
|
||
info._view.visible = true
|
||
info:FillData(p)
|
||
end
|
||
end
|
||
|
||
-- 语音Stard
|
||
local gcm_chat = _view:GetChild('gcm_chat')
|
||
-- gcm_chat.displayObject.gameObject:SetActive(false)
|
||
if gcm_chat then
|
||
gcm_chat.visible = false
|
||
local _btn_chat = gcm_chat:GetChild('n1')
|
||
_btn_chat.onClick:Add(function()
|
||
if self.chat_view == nil then
|
||
self.chat_view = ChatView.new(self)
|
||
end
|
||
if self._room.ban_chat1 then
|
||
if self.chat_view.HideInputField then
|
||
self.chat_view:HideInputField()
|
||
end
|
||
end
|
||
self.chat_view:Show()
|
||
end)
|
||
|
||
self._ctr_voice = gcm_chat:GetController('voice')
|
||
|
||
self._btn_record = gcm_chat:GetChild('btn_record')
|
||
self._btn_record.displayObject.gameObject:SetActive(false)
|
||
self.ctr_record_ban = self._btn_record:GetController('ban')
|
||
self.ctr_record_ban.selectedIndex = record_baned
|
||
self._record_time = 0
|
||
--[[self._btn_record.onTouchBegin:Set(function()
|
||
if record_baned == 1 then
|
||
self:__SetRecordEnable()
|
||
else
|
||
self._record_time = 0
|
||
GameApplication.Instance.StopMusic = GameApplication.Instance.StopMusic + 1
|
||
self._btn_record.onTouchEnd:Set(self.__RecordTouchEnd, self)
|
||
Voice.BeginRecord()
|
||
self._ctr_voice.selectedIndex = 1
|
||
self.__runwait_record = nil
|
||
self.__runwait_record = coroutine.start(self.__WaitRecord, self)
|
||
end
|
||
end)--]]
|
||
end
|
||
|
||
local btn_ready = _view:GetChild('btn_ready')
|
||
btn_ready.onClick:Set(function()
|
||
self._gamectr:PlayerReady()
|
||
end)
|
||
|
||
local btn_xipai = _view:GetChild('btn_xipai')
|
||
if btn_xipai then
|
||
btn_xipai.onClick:Set(function()
|
||
self._gamectr:PlayerXiPai()
|
||
end)
|
||
end
|
||
|
||
local btn_start = _view:GetChild('btn_start')
|
||
btn_start.onClick:Set(function()
|
||
self._gamectr:StartGame()
|
||
end)
|
||
|
||
local _btn_wxyqhy = _view:GetChild('btn_wxyqhy')
|
||
if _btn_wxyqhy then
|
||
_btn_wxyqhy.visible = false
|
||
end
|
||
|
||
self:EventInit()
|
||
self._popEvent = true
|
||
self._left_time = 0
|
||
self.dismiss_room_cd_time = 0
|
||
local btn_back_exit = _view:GetChild('btn_back_exit')
|
||
-- btn_back_exit.displayObject.gameObject:SetActive(false)
|
||
if btn_back_exit ~= nil then
|
||
btn_back_exit.onClick:Set(function()
|
||
local tip_owner = '您是否退出房间?\n(退出房间后房间将解散)'
|
||
local tip = '您是否退出房间?'
|
||
local tipStr = ''
|
||
if self._room.agent then
|
||
tipStr = '您是否退出房间?'
|
||
else
|
||
tipStr = self._room.owner_id == self._room.self_player.self_user.account_id and tip_owner or tip
|
||
end
|
||
local _curren_msg = MsgWindow.new(self._root_view, tipStr, MsgWindow.MsgMode.OkAndCancel)
|
||
_curren_msg.onOk:Add(function()
|
||
if self._state.selectedIndex > 0 and self._state.selectedIndex < 3 then
|
||
ViewUtil.ErrorTip(nil, '房间已开始,无法退出游戏。')
|
||
else
|
||
ViewUtil.ShowModalWait(self._root_view)
|
||
self._gamectr:LevelRoom(function(res)
|
||
ViewUtil.CloseModalWait()
|
||
if res.ReturnCode == 0 then
|
||
ViewManager.ChangeView(ViewManager.View_Lobby)
|
||
else
|
||
ViewUtil.ErrorTip(res.ReturnCode)
|
||
end
|
||
end)
|
||
end
|
||
end)
|
||
_curren_msg:Show()
|
||
end)
|
||
end
|
||
local btn_back_lobby = _view:GetChild('btn_back_lobby')
|
||
if btn_back_lobby ~= nil then
|
||
btn_back_lobby.onClick:Set(function()
|
||
local tip_owner = '您是否退出房间?\n(退出房间后房间将解散)'
|
||
local tip = '您是否退出房间?' -- \n (请注意,申请洗牌后退出,不会返还洗牌分)
|
||
local tipStr = ''
|
||
if self._room.agent then
|
||
tipStr = '您是否退出房间?'
|
||
else
|
||
tipStr = self._room.owner_id == self._room.self_player.self_user.account_id and tip_owner or tip
|
||
end
|
||
local _curren_msg = MsgWindow.new(self._root_view, tipStr, MsgWindow.MsgMode.OkAndCancel)
|
||
_curren_msg.onOk:Add(function()
|
||
if self._state.selectedIndex > 0 and self._state.selectedIndex < 3 then
|
||
ViewUtil.ErrorTip(nil, '房间已开始,无法退出游戏。')
|
||
else
|
||
ViewUtil.ShowModalWait(self._root_view)
|
||
self._gamectr:LevelRoom(function(res)
|
||
ViewUtil.CloseModalWait()
|
||
if res.ReturnCode == 0 then
|
||
ViewManager.ChangeView(ViewManager.View_Lobby)
|
||
else
|
||
ViewUtil.ErrorTip(res.ReturnCode)
|
||
end
|
||
end)
|
||
end
|
||
end)
|
||
_curren_msg:Show()
|
||
end)
|
||
end
|
||
--[[local btn_back_lobby = _view:GetChild('btn_back_lobby')
|
||
btn_back_lobby.displayObject.gameObject:SetActive(false)
|
||
if btn_back_lobby ~= nil then
|
||
btn_back_lobby.onClick:Set(
|
||
function()
|
||
if self._state.selectedIndex > 0 and self._state.selectedIndex < 3 then
|
||
ViewUtil.ErrorTip(nil, '房间已开始,无法退出游戏。')
|
||
else
|
||
self._gamectr.tmpRoomID = self._room.room_id
|
||
self._gamectr.tmpGroupID = self._room.group_id
|
||
ViewManager.ChangeView(ViewManager.View_Lobby)
|
||
end
|
||
end
|
||
)
|
||
end--]]
|
||
|
||
local btn_leave_lobby = _view:GetChild('btn_leave_lobby')
|
||
if btn_leave_lobby ~= nil then
|
||
btn_leave_lobby.onClick:Set(function()
|
||
self._gamectr.tmpRoomID = self._room.room_id
|
||
self._gamectr.tmpGroupID = self._room.group_id
|
||
ViewManager.ChangeView(ViewManager.View_Lobby)
|
||
end)
|
||
end
|
||
|
||
UpdateBeat:Add(self.OnUpdate, self)
|
||
if self._room.room_config.people_num <= 4 and self._room.room_config.people_num >= 3 and self._gamectr:CheckGPS() then
|
||
self._show_distance = true
|
||
end
|
||
|
||
-- 显示牌友圈助手
|
||
if self._room.group_id ~= 0 and not self._hide_assist then
|
||
|
||
local bShow = true
|
||
local l_groups = DataManager.groups
|
||
local group = l_groups:get(self._room.group_id)
|
||
if group ~= nil then
|
||
local option = group.option or 0
|
||
if bit:_and(option, 8) > 0 then
|
||
bShow = false
|
||
end
|
||
end
|
||
if bShow then
|
||
-- self:ShowFGAssist()
|
||
end
|
||
|
||
end
|
||
if self._room.self_player.entrust then
|
||
self:MarkSelfTuoguan()
|
||
end
|
||
|
||
--[[local gameCommonBtn = UIPackage.CreateObjectFromURL('ui://Common/gameCommonPanel')
|
||
if gameCommonBtn then
|
||
self._view:AddChild(gameCommonBtn)
|
||
local shuaxingameBtn=gameCommonBtn:GetChild("shuaxinbtn")
|
||
if shuaxingameBtn then
|
||
shuaxingameBtn.onClick:Set(
|
||
function ()
|
||
ViewManager.refreshGameView()
|
||
end
|
||
)
|
||
end
|
||
end--]]
|
||
|
||
end
|
||
|
||
function M:continue_game(continue)
|
||
if continue then
|
||
self.distance_view:Destroy()
|
||
else
|
||
local tip_owner = '您是否退出房间?\n(退出房间后房间将解散)'
|
||
local tip = '您是否退出房间?'
|
||
local tipStr = ''
|
||
if self._room.agent then
|
||
tipStr = '您是否返回大厅?'
|
||
else
|
||
tipStr = self._room.owner_id == self._room.self_player.self_user.account_id and tip_owner or tip
|
||
end
|
||
local _curren_msg = MsgWindow.new(self._root_view, tipStr, MsgWindow.MsgMode.OkAndCancel)
|
||
_curren_msg.onOk:Add(function()
|
||
if self._state.selectedIndex > 0 and self._state.selectedIndex < 3 then
|
||
ViewUtil.ErrorTip(nil, '房间已开始,无法退出游戏。')
|
||
else
|
||
ViewUtil.ShowModalWait(self._root_view)
|
||
self._gamectr:LevelRoom(function(res)
|
||
ViewUtil.CloseModalWait()
|
||
if res.ReturnCode == 0 then
|
||
ViewManager.ChangeView(ViewManager.View_Lobby)
|
||
else
|
||
ViewUtil.ErrorTip(res.ReturnCode)
|
||
end
|
||
end)
|
||
end
|
||
end)
|
||
_curren_msg:Show()
|
||
end
|
||
end
|
||
|
||
-- 公用的playerinfoview方法,如果扩展有改动可以重写
|
||
function M:InitPlayerInfoView(isHideIpAdds)
|
||
self._player_info = {}
|
||
local _player_info = self._player_info
|
||
for i = 1, self._room.room_config.people_num do
|
||
local tem = self._view:GetChild('player_info' .. i)
|
||
_player_info[i] = PlayerInfoView.new(tem, self, isHideIpAdds)
|
||
tem.visible = false
|
||
end
|
||
end
|
||
|
||
-- 显示牌友圈助手
|
||
function M:ShowFGAssist()
|
||
UIPackage.AddPackage('base/newgroup/ui/FGAssist')
|
||
local btn_assist = UIPackage.CreateObjectFromURL('ui://FGAssist/btn_assist')
|
||
self.btn_assist = btn_assist
|
||
self._view:AddChild(btn_assist)
|
||
local panel_assist = FGAssistView.new(self._root_view, function()
|
||
btn_assist.touchable = true
|
||
end)
|
||
if self._full then
|
||
btn_assist.x = 40
|
||
else
|
||
btn_assist.x = (GRoot.inst.width - 1334) * -0.5 + 40
|
||
end
|
||
btn_assist.y = panel_assist._root_view.height / 3 - 0.5 * btn_assist.height
|
||
|
||
btn_assist.onClick:Set(function()
|
||
panel_assist:ReloadView()
|
||
panel_assist:Show()
|
||
btn_assist.touchable = false
|
||
end)
|
||
self.panel_assist = panel_assist
|
||
self._state.onChanged:Set(function()
|
||
btn_assist.visible = self._state.selectedIndex == 0
|
||
if self._state.selectedIndex == 1 then
|
||
if panel_assist then
|
||
panel_assist:Close()
|
||
end
|
||
end
|
||
end)
|
||
end
|
||
|
||
-- 设置助手按钮的位置
|
||
function M:SetBtnAssistPos(x, y)
|
||
if not self.btn_assist then
|
||
return
|
||
end
|
||
if self._full then
|
||
self.btn_assist.x = x
|
||
else
|
||
self.btn_assist.x = (GRoot.inst.width - 1334) * -0.5 + x
|
||
end
|
||
self.btn_assist.y = y
|
||
end
|
||
|
||
function M:NewSettingView()
|
||
local settingView = SettingView.new(self._root_view)
|
||
settingView:FillBgSection(function(url)
|
||
LoadGameBg(url, self._root_view)
|
||
end, self._room.game_id, 5)
|
||
return settingView
|
||
end
|
||
|
||
function M:__RecordTouchEnd()
|
||
if (self.__runwait_record ~= nil) then
|
||
coroutine.stop(self.__runwait_record)
|
||
end
|
||
if self._record_time < 0.3 then
|
||
self:__SetRecordEnable()
|
||
end
|
||
self.__runwait_record = nil
|
||
self._ctr_voice.selectedIndex = 0
|
||
GameApplication.Instance.StopMusic = GameApplication.Instance.StopMusic - 1
|
||
self._btn_record.onTouchEnd:Remove(self.__RecordTouchEnd, self)
|
||
local room = self._room
|
||
Voice.EndRecord(room.room_id, DataManager.SelfUser.account_id, function(filename)
|
||
local _gamectr = ControllerManager.GetController(GameController)
|
||
_gamectr:SendInteraction(DataManager.SelfUser.account_id, 3, filename)
|
||
end)
|
||
end
|
||
|
||
function M:__WaitRecord()
|
||
coroutine.wait(20)
|
||
self:__RecordTouchEnd()
|
||
end
|
||
|
||
function M:__SetRecordEnable()
|
||
record_baned = 1 - record_baned
|
||
self.ctr_record_ban.selectedIndex = record_baned
|
||
end
|
||
|
||
function M:FillRoomConfig(roominfo_panel, _room)
|
||
if roominfo_panel ~= nil then
|
||
local tex_roomid = roominfo_panel:GetChild('tex_roomid')
|
||
tex_roomid.text = _room.room_id
|
||
if _room.room_config.isHidden and _room.room_config.isHidden == 1 then
|
||
-- tex_roomid.text = "000000"
|
||
end
|
||
local tex_gametype = roominfo_panel:GetChild('tex_gametype')
|
||
if (tex_gametype ~= nil) then
|
||
tex_gametype.text = _room.room_config:GetGameName()
|
||
end
|
||
local tex_roomconfig = roominfo_panel:GetChild('tex_roomconfig')
|
||
if (tex_roomconfig ~= nil) then
|
||
tex_roomconfig.text = _room.room_config:GetDes()
|
||
end
|
||
local tex_times = roominfo_panel:GetChild('tex_times')
|
||
if DataManager.CurrenRoom.hpOnOff == 1 and DataManager.CurrenRoom.score_times ~= 1 then
|
||
if tex_times then
|
||
tex_times.text = DataManager.CurrenRoom.score_times .. '倍'
|
||
end
|
||
end
|
||
end
|
||
end
|
||
|
||
function M:EventInit()
|
||
local _gamectr = self._gamectr
|
||
local _player_info = self._player_info
|
||
local _room = self._room
|
||
|
||
_gamectr:AddEventListener(GameEvent.PlayerEnter, handler(self, self.OnPlayerEnter))
|
||
|
||
_gamectr:AddEventListener(GameEvent.PlayerState, function(...)
|
||
local arg = {...}
|
||
local p = arg[1]
|
||
local info = _player_info[self:GetPos(p.seat)]
|
||
info._ctr_offline.selectedIndex = p.line_state == 0 and 1 or 0
|
||
self:PlayerChangeLineState()
|
||
end)
|
||
_gamectr:AddEventListener(GameEvent.OnUpdateInfo, handler(self, self.OnUpdateInfo))
|
||
|
||
_gamectr:AddEventListener(GameEvent.PlayerLeave, handler(self, self.OnPlayerLeave))
|
||
|
||
_gamectr:AddEventListener(GameEvent.PlayerReady, handler(self, self.OnPlayerReady))
|
||
|
||
_gamectr:AddEventListener(GameEvent.DeskBreak, function(...)
|
||
local arg = {...}
|
||
local code = arg[1]
|
||
if code == 0 then
|
||
if self.dismissWin == nil then
|
||
self.dismissWin = DismissRoomWindow.new(self._root_view)
|
||
end
|
||
self.dismissWin:FillData(arg[2])
|
||
self.dismissWin:Show()
|
||
elseif code == 1 then
|
||
ViewManager.ChangeView(ViewManager.View_Lobby)
|
||
ViewUtil.ShowTips('房间已解散!')
|
||
elseif code == 2 then
|
||
-- self:DismissRoomAgree(p,result)
|
||
local p = arg[2]
|
||
local result = arg[3]
|
||
elseif code == 3 then
|
||
if self.dismissWin ~= nil then
|
||
self.dismissWin:Destroy()
|
||
end
|
||
self.dismissWin = nil
|
||
self.dismiss_room_cd_time = 30
|
||
ViewUtil.ShowTips('解散失败!')
|
||
end
|
||
end)
|
||
|
||
_gamectr:AddEventListener(GameEvent.Interaction, function(...)
|
||
local arg = {...}
|
||
local p = arg[1]
|
||
if not p or not p.seat or p.seat == 0 then
|
||
return
|
||
end
|
||
if DataManager.BanInteractRoom == _room.room_id and p.seat ~= _room.self_player.seat then
|
||
return
|
||
end
|
||
local info = self._player_info[self:GetPos(p.seat)]
|
||
local ttype = arg[2]
|
||
if ttype == 5 then
|
||
local parm = arg[3]
|
||
local array = split(parm, '_')
|
||
local tp = self._room:GetPlayerById(tonumber(array[2]))
|
||
if not tp or not tp.seat or tp.seat == 0 then
|
||
return
|
||
end
|
||
local pos = self._view:GlobalToLocal(info._view:LocalToGlobal(info:GetHeadCenter()))
|
||
if tp.seat == p.seat then
|
||
for i = 1, #_room.player_list do
|
||
local player = _room.player_list[i]
|
||
if player.seat ~= tp.seat then
|
||
tinfo = self._player_info[self:GetPos(player.seat)]
|
||
tpos = self._view:GlobalToLocal(tinfo._view:LocalToGlobal(tinfo:GetHeadCenter()))
|
||
self:PlayInteractAnimation(array[1], pos, tpos)
|
||
end
|
||
end
|
||
else
|
||
local tinfo = self._player_info[self:GetPos(tp.seat)]
|
||
local tpos = self._view:GlobalToLocal(tinfo._view:LocalToGlobal(tinfo:GetHeadCenter()))
|
||
self:PlayInteractAnimation(array[1], pos, tpos)
|
||
end
|
||
elseif ttype == 3 then
|
||
if record_baned == 0 then
|
||
info:ShowInteraction(ttype, arg[3])
|
||
end
|
||
else
|
||
info:ShowInteraction(ttype, arg[3])
|
||
end
|
||
end)
|
||
|
||
_gamectr:AddEventListener(GameEvent.OnKicked, function()
|
||
printlog("GameEvent.OnKicked====》》》》》")
|
||
self:UnmarkSelfTuoguan()
|
||
local _curren_msg = MsgWindow.new(self._root_view, '由于长时间未准备,你已被踢出房间!',
|
||
MsgWindow.MsgMode.OnlyOk)
|
||
_curren_msg.onOk:Add(function()
|
||
ViewManager.ChangeView(ViewManager.View_Lobby)
|
||
end)
|
||
_curren_msg:Show()
|
||
end)
|
||
|
||
_gamectr:AddEventListener(GameEvent.TupGuanOpen, function(...)
|
||
-- print("刷新托管数据=====")
|
||
local arg = {...}
|
||
local p = arg[1]
|
||
local info = self._player_info[self:GetPos(p.seat)]
|
||
|
||
if info and info.IsShowTGTips then
|
||
info:IsShowTGTips(arg[2], arg[3])
|
||
end
|
||
|
||
if info and info.SetShowTGTips then
|
||
info:SetShowTGTips(arg[2], arg[3])
|
||
end
|
||
|
||
end)
|
||
|
||
end
|
||
|
||
-- 设置能否互动,1允许,0禁止
|
||
function M:SetInteractEnabled(val)
|
||
if val == 0 then
|
||
DataManager.BanInteractRoom = self._room.room_id
|
||
else
|
||
DataManager.BanInteractRoom = nil
|
||
end
|
||
end
|
||
|
||
-- 获取能否互动状态
|
||
function M:GetInteractEnabled()
|
||
return DataManager.BanInteractRoom == self._room.room_id and 0 or 1
|
||
end
|
||
|
||
-- 桌面动画效果
|
||
function M:PlayInteractAnimation(str, mypos, pos)
|
||
local eff = UIPackage.CreateObjectFromURL('ui://Common/Eff' .. str)
|
||
local myEff = UIPackage.CreateObjectFromURL('ui://Common/myEff' .. str)
|
||
self._view:AddChild(myEff)
|
||
myEff.x = mypos.x
|
||
myEff.y = mypos.y
|
||
local offsetX = pos.x - mypos.x
|
||
local offsetY = pos.y - mypos.y
|
||
|
||
if str ~= '5' and str ~= '1' then
|
||
local total_rotation = (offsetY + offsetX) / 100 * 50
|
||
self._run_move = TweenUtils.TweenFloat(0, 1, 0.5, function(value)
|
||
myEff.x = mypos.x + offsetX * value
|
||
myEff.y = mypos.y + offsetY * value
|
||
if str == '2' then
|
||
myEff.rotation = total_rotation * value
|
||
end
|
||
end)
|
||
end
|
||
|
||
self._run_eff = coroutine.start(function()
|
||
if str ~= '1' then
|
||
coroutine.wait(0.5)
|
||
else
|
||
local degree = math.atan2(offsetX, offsetY) * 180 / math.pi - 90
|
||
if degree < -180 then
|
||
degree = 360 + degree
|
||
end
|
||
degree = degree * -1
|
||
if degree > 90 or degree < -90 then
|
||
degree = degree + 180 * (degree > 90 and -1 or 1)
|
||
myEff.scaleX = -1
|
||
end
|
||
myEff.rotation = degree
|
||
coroutine.wait(0.2)
|
||
end
|
||
self._view:AddChild(eff)
|
||
eff.x = pos.x
|
||
eff.y = pos.y
|
||
coroutine.wait(1.5)
|
||
eff:Dispose()
|
||
myEff:Dispose()
|
||
end)
|
||
end
|
||
|
||
function M:GetReadyNum()
|
||
local readyNum = 0
|
||
local list = self._room.player_list
|
||
for i = 1, #list do
|
||
local p = list[i]
|
||
if p.ready then
|
||
readyNum = readyNum + 1
|
||
end
|
||
end
|
||
return readyNum
|
||
end
|
||
|
||
function M:OnPlayerEnter(...)
|
||
printlog("进入房间222222222222222222++++++++++++++++++++++++++++")
|
||
local arg = {...}
|
||
local p = arg[1]
|
||
if p ~= self._room.self_player and self._room.room_config.people_num <= 4 and self._room.room_config.people_num >= 3 and
|
||
self._gamectr:CheckGPS() then
|
||
if self._room.self_player.seat == 0 then
|
||
return
|
||
end
|
||
if self.distance_view then
|
||
self.distance_view:Destroy()
|
||
end
|
||
self.distance_view = PlayerDistanceView.new(true, self._gps_style, function(v)
|
||
self:continue_game(v)
|
||
end)
|
||
self.distance_view._view:GetController("state").selectedIndex =
|
||
self._state.selectedIndex > 0 and self._state.selectedIndex < 3 and 1 or 0
|
||
self.distance_view:Show()
|
||
if self.btn_distance then
|
||
self.btn_distance:GetController("state").selectedIndex = 1
|
||
end
|
||
end
|
||
local info = self._player_info[self:GetPos(p.seat)]
|
||
info:FillData(p)
|
||
info._view.visible = true
|
||
end
|
||
|
||
function M:OnPlayerReady(...)
|
||
local arg = {...}
|
||
local p = arg[1]
|
||
|
||
if p.isSendCardState ~= nil and p.isSendCardState == true then
|
||
p.isSendCardState = false
|
||
ControllerManager.IsSendCard = false
|
||
-- print("进入设置计时器控制==========")
|
||
coroutine.start(function()
|
||
-- print("计时器倒计时5s=============")
|
||
coroutine.wait(5)
|
||
-- print("当前状态==============")
|
||
-- print(ControllerManager.IsSendCard)
|
||
if ControllerManager.IsSendCard == true then
|
||
-- print("以发送开牌======================")
|
||
return
|
||
else
|
||
-- print("开始断线重连")
|
||
-- ControllerManager.OnConnect(SocketCode.TimeoutDisconnect)
|
||
ViewManager.refreshGameView()
|
||
end
|
||
ControllerManager.IsSendCard = false
|
||
end)
|
||
end
|
||
|
||
if p.seat == self._room.self_player.seat then
|
||
if self._ctr_action then
|
||
self._ctr_action.selectedIndex = 0
|
||
end
|
||
end
|
||
local info = self._player_info[self:GetPos(p.seat)]
|
||
info:Ready(true)
|
||
printlog("基类准备++++++++++++++++++++++++++")
|
||
end
|
||
|
||
function M:OnUpdateInfo(...)
|
||
local arg = {...}
|
||
local p = arg[1]
|
||
local t = arg[2]
|
||
-- 托管状态变化
|
||
if t == 5 then
|
||
if p == DataManager.CurrenRoom.self_player then
|
||
if p.entrust then
|
||
self:closeTipOnTuoguan()
|
||
self:MarkSelfTuoguan()
|
||
else
|
||
self:UnmarkSelfTuoguan()
|
||
end
|
||
else
|
||
local player_info = self._player_info[self:GetPos(p.seat)]
|
||
if p.entrust then
|
||
player_info:MarkTuoguan()
|
||
else
|
||
player_info:UnmarkTuoguan()
|
||
end
|
||
end
|
||
end
|
||
end
|
||
|
||
-- 标记自己托管
|
||
function M:MarkSelfTuoguan()
|
||
if self._com_tuoguan then
|
||
return
|
||
end
|
||
|
||
self._com_tuoguan = UIPackage.CreateObjectFromURL('ui://Common/com_tuoguan_self')
|
||
local com_tuoguan = self._com_tuoguan
|
||
GRoot.inst:AddChild(com_tuoguan)
|
||
-- com_tuoguan:Center()
|
||
-- com_tuoguan.y = GRoot.inst.height - com_tuoguan.height
|
||
-- com_tuoguan.x = (GRoot.inst.width - com_tuoguan.width) * 0.5
|
||
local _msg_view = nil
|
||
com_tuoguan:GetChild('n0').onClick:Set(function()
|
||
if _msg_view then
|
||
_msg_view:Dispose()
|
||
end
|
||
local _curren_msg = UIPackage.CreateObjectFromURL('ui://Common/MessageBox')
|
||
_msg_view = _curren_msg
|
||
_msg_view:GetChild('btn_ok').onClick:Set(function()
|
||
_msg_view:Dispose()
|
||
_msg_view = nil
|
||
self._gamectr:Entrust(false)
|
||
end)
|
||
_msg_view:GetChild('btn_close').onClick:Set(function()
|
||
_msg_view:Dispose()
|
||
_msg_view = nil
|
||
end)
|
||
|
||
_msg_view:GetChild('btn_close1').onClick:Set(function()
|
||
_msg_view:Dispose()
|
||
_msg_view = nil
|
||
end)
|
||
local roate = GRoot.inst.width / GRoot.inst.height
|
||
local num = 100
|
||
if roate < 1.9 then
|
||
num = 250
|
||
end
|
||
com_tuoguan:AddChild(_msg_view)
|
||
_msg_view:GetChild('tex_message').text = '确定要取消托管吗?'
|
||
_msg_view.x = (com_tuoguan.width - _msg_view.width) * 0.5 - num
|
||
_msg_view.y = (com_tuoguan.height - com_tuoguan.y - _msg_view.height) * 0.5
|
||
end)
|
||
end
|
||
|
||
-- 取消标记自己托管
|
||
function M:UnmarkSelfTuoguan()
|
||
if self._com_tuoguan then
|
||
self._com_tuoguan:Dispose()
|
||
self._com_tuoguan = nil
|
||
end
|
||
end
|
||
|
||
function M:OnPlayerLeave(...)
|
||
local arg = {...}
|
||
local p = arg[1]
|
||
local info = self._player_info[self:GetPos(p.seat)]
|
||
info._view.visible = false
|
||
if not self._gamectr:CheckGPS() then
|
||
self.btn_distance:GetController("state").selectedIndex = 0
|
||
end
|
||
end
|
||
|
||
function M:PlayerChangeLineState()
|
||
end
|
||
|
||
function M:ReloadInteractView()
|
||
if self.chat_view then
|
||
self.chat_view:FillChatMsg()
|
||
end
|
||
end
|
||
|
||
function M:PlayChatSound(sex, chat_index)
|
||
local sex_path = ViewUtil.Sex_Chat[sex]
|
||
local path1 = string.format('base/common/sound/%s/chat_%s.mp3', sex_path, tostring(chat_index - 1))
|
||
GameApplication.Instance:PlaySound('base_chat', path1)
|
||
-- GameApplication.Instance:PlaySound(path1)
|
||
end
|
||
|
||
-- 获取语言
|
||
function M:GetLanguage()
|
||
if self._multilingual then
|
||
return self._language
|
||
else
|
||
return 0
|
||
end
|
||
end
|
||
|
||
-- 设置语言
|
||
function M:SetLanguage(language)
|
||
if self._multilingual then
|
||
self._language = language
|
||
end
|
||
end
|
||
|
||
-- 获取消息使用的语言、序号
|
||
function M:GetChatMsgLanguage(msg_index)
|
||
local language = math.modf(msg_index / 100)
|
||
local index = math.fmod(msg_index, 100)
|
||
return language, index
|
||
end
|
||
|
||
function M:DismissRoomAgree(p, result)
|
||
local index = self:GetPos(p.seat)
|
||
self._player_info[index]:DismissRoom(result)
|
||
end
|
||
|
||
function M:PlaySound(sex, path)
|
||
end
|
||
|
||
function M:OnUpdate()
|
||
local deltaTime = Time.deltaTime
|
||
if (self._popEvent) then
|
||
local func = self._gamectr:PopEvent()
|
||
if (func ~= nil) then
|
||
if pcall(func) then
|
||
|
||
else
|
||
self._gamectr = ControllerManager.GetController(GameController)
|
||
if self._gamectr then
|
||
self._gamectr:ResetConnect()
|
||
end
|
||
end
|
||
-- func()
|
||
end
|
||
end
|
||
if self._view:GetChild('gcm_chat') then
|
||
self._record_time = self._record_time + deltaTime
|
||
end
|
||
local _left_time = self._left_time
|
||
if (_left_time > 0) then
|
||
_left_time = _left_time - deltaTime
|
||
_left_time = math.max(0, _left_time)
|
||
local leftTime = math.floor(_left_time)
|
||
if leftTime < 10 then
|
||
self._tex_leftTime.text = '0' .. tostring(leftTime)
|
||
for i = 2, 4 do
|
||
local text = self["_tex_leftTime" .. i]
|
||
if text then
|
||
text.text = '0' .. tostring(leftTime)
|
||
end
|
||
end
|
||
else
|
||
self._tex_leftTime.text = tostring(leftTime)
|
||
for i = 2, 4 do
|
||
local text = self["_tex_leftTime" .. i]
|
||
if text then
|
||
text.text = tostring(leftTime)
|
||
end
|
||
end
|
||
end
|
||
self._left_time = _left_time
|
||
-- 桌面計時器聲音
|
||
if not self._curtime then
|
||
self._curtime = 15
|
||
end
|
||
if leftTime <= 3 and self._curtime ~= leftTime and leftTime ~= 0 then
|
||
self._curtime = leftTime
|
||
GameApplication.Instance:PlaySound('base/sound/daojishi1.mp3')
|
||
end
|
||
else
|
||
self:onLeftTimeOver()
|
||
if self._tex_leftTime then
|
||
self._tex_leftTime.text = '00'
|
||
end
|
||
for i = 2, 4 do
|
||
local text = self["_tex_leftTime" .. i]
|
||
if text then
|
||
text.text = '00'
|
||
end
|
||
end
|
||
end
|
||
if (self.dismiss_room_cd_time > 0) then
|
||
self.dismiss_room_cd_time = self.dismiss_room_cd_time - deltaTime
|
||
self.dismiss_room_cd_time = math.max(0, self.dismiss_room_cd_time)
|
||
end
|
||
|
||
if self._style == 1 then
|
||
if (self._rightPanelView) then
|
||
self._rightPanelView:OnUpdate(deltaTime)
|
||
end
|
||
end
|
||
|
||
if (self.dismissWin) then
|
||
-- local ctr = ControllerManager.GetCurrenController()
|
||
-- if(ctr.baseType ~= GameController) then
|
||
-- self.dismissWin:Destroy()
|
||
-- self.dismissWin = nil
|
||
-- else
|
||
self.dismissWin:OnUpdate(deltaTime)
|
||
-- end
|
||
end
|
||
|
||
if self.OnMuShiUpdate then
|
||
self:OnMuShiUpdate()
|
||
end
|
||
end
|
||
function M:onLeftTimeOver()
|
||
|
||
end
|
||
function M:Clear()
|
||
-- self:__CloseTip()
|
||
for i = 1, #self._player_info do
|
||
self._player_info[i]:Clear()
|
||
end
|
||
end
|
||
|
||
function M:DestroyPlayerInfo()
|
||
for i = 1, #self._player_info do
|
||
self._player_info[i]:Destroy()
|
||
end
|
||
end
|
||
|
||
function M:GetPos(seat)
|
||
return ViewUtil.GetPos(self._room.self_player.seat, seat, self._room.room_config.people_num)
|
||
end
|
||
|
||
-- 托管时关闭一些提示窗口,如起手胡、吃碰提示、海底,由扩展实现
|
||
function M:closeTipOnTuoguan()
|
||
end
|
||
|
||
local last_pause_time = 0
|
||
-- 游戏暂停
|
||
function M:OnApplicationPause()
|
||
if self.panel_assist then
|
||
self.panel_assist:Close()
|
||
end
|
||
last_pause_time = os.time()
|
||
end
|
||
|
||
-- 游戏激活
|
||
function M:OnApplicationActive()
|
||
-- print("游戏激活================")
|
||
if os.time() - last_pause_time > 15 then
|
||
last_pause_time = os.time()
|
||
ControllerManager.WebClient:clearActionQueue()
|
||
local ctr = ControllerManager.GetCurrenController()
|
||
if (ctr.baseType == GameController) then
|
||
ControllerManager.OnConnect(SocketCode.TimeoutDisconnect)
|
||
end
|
||
end
|
||
end
|
||
|
||
function M:Show()
|
||
BaseView.Show(self)
|
||
if self._state.selectedIndex == 0 and self._show_distance then
|
||
if self._room.self_player.seat == 0 then
|
||
return
|
||
end
|
||
self.distance_view = PlayerDistanceView.new(true, self._gps_style, function(v)
|
||
self:continue_game(v)
|
||
end)
|
||
self.distance_view._view:GetController("state").selectedIndex =
|
||
self._state.selectedIndex > 0 and self._state.selectedIndex < 3 and 1 or 0
|
||
self.distance_view:Show()
|
||
self.btn_distance:GetController("state").selectedIndex = 1
|
||
end
|
||
end
|
||
|
||
function M:Destroy()
|
||
TimerManager.Clear()
|
||
self:UnmarkSelfTuoguan()
|
||
self:DestroyPlayerInfo()
|
||
DSTweenManager.ClearTween()
|
||
|
||
NetResetConnectWindow.CloseNetReset()
|
||
Voice.CrealRecord()
|
||
ControllerManager.resetJionRoom = false
|
||
self._popEvent = false
|
||
GRoot.inst:HidePopup()
|
||
ViewUtil.CloseModalWait()
|
||
GameApplication.Instance.StopMusic = 0
|
||
coroutine.stopAll()
|
||
UpdateBeat:Remove(self.OnUpdate, self)
|
||
BaseView.Destroy(self)
|
||
BaseWindow.DestroyAll()
|
||
ResourcesManager.UnLoadGroup('base_chat')
|
||
|
||
end
|