hengyang_client/lua_probject/base_project/Game/View/MainView.lua

1550 lines
52 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.

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')
local MissileSender = import(".MissileSender")
local function GetSeat(self, uId)
for _, player in pairs(self._room.player_list) do
if player.self_user.account_id == uId then
return player.seat
end
end
end
local function RefalshBtnClose(self)
local btn_close = self._view:GetChild("btn_closeRoom")
local btn_close_cSytle = btn_close:GetController("cStyle")
local roomOwner = self._room.player_list[1].self_user.account_id
if roomOwner == DataManager.SelfUser.account_id then
btn_close_cSytle.selectedIndex = 0
else
btn_close_cSytle.selectedIndex = 1
end
end
local function GetPlayer(self, playerId)
for _, p in pairs(self._room.player_list) do
if playerId == p.self_user.account_id then
return p
end
end
return nil
end
local function LoadClickData()
local json_data = Utils.LoadLocalFile("clickMode")
if json_data == nil or json_data == "null" then
return "double"
end
return json.decode(json_data)
end
local function IsRoomOwer()
--local roomOwner = self._room.player_list[1].self_user.account_id
local roomOwner = DataManager.CurrenRoom.player_list[1].self_user.account_id
return roomOwner == DataManager.SelfUser.account_id
end
-- 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._scale = true
self._full_offset = false
self.class = "MainView"
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)
self.clickMode = LoadClickData()
--
--[[ 多语言切换(适用于设置界面使用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
-- ------lingmeng-----暂时去除gps位置判定
-- 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._ctr_more then
--现在只有麻将才有_ctr_more
self._ctr_more.selectedIndex = 0
end
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
end
end)
end
local chatText = _view:GetChild('btn_sendText')
if chatText then
chatText.onClick:Add(function()
if self._ctr_more then
--现在只有麻将才有_ctr_more
self._ctr_more.selectedIndex = 0
end
if self._room.room_config.config.hpData.BanChat == 1 then
ViewUtil.ErrorTip(-1, "本房间禁止快捷聊天")
return
end
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
]]
--[[
local group = DataManager.groups:get(self._room.group_id)
local play = group:getPlay(self._room.play_id)
local hpData = json.decode(play.hpData)
if hpData.BanChat and hpData.BanChat == 1 then
ViewUtil.ShowTips("本房间禁止快捷聊天")
return
end
]]
self.chat_view:Show()
end)
end
self._chat_Talk = _view:GetChild('btn_sendTalk')
if self._chat_Talk then
self._ctr_voice = _view:GetController('voice')
self._chat_Talk.onTouchBegin:Set(function(context)
if self._room.room_config.config.hpData.BanChat == 1 then
ViewUtil.ErrorTip(-1, "本房间禁止快捷聊天")
return
end
if record_baned == 1 then
self:__SetRecordEnable()
else
self._record_time = 0
self._record_pos = Vector2.New(context.inputEvent.x, context.inputEvent.y)
self._record_view = _view:GetChild('comp_voice')
self._record_view_ctr = self._record_view:GetController('ctr_cancel')
GameApplication.Instance.StopMusic = GameApplication.Instance.StopMusic + 1
self._chat_Talk.onTouchEnd:Set(self.__RecordTouchEnd, self)
self._chat_Talk.onTouchMove:Set(handler(self, self.__RecordTouchMove))
Voice.BeginRecord()
self._record_view_ctr.selectedIndex = 0
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')
if btn_ready ~= nil then
btn_ready.onClick:Set(function()
self._gamectr:PlayerReady()
end)
end
local Btn_Ready = _view:GetChild('Btn_Ready')
if Btn_Ready ~= nil then
Btn_Ready.onClick:Set(function()
self._gamectr:PlayerReady()
end)
end
if self._room.room_config.people_num ~= 2 then
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)
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
print("lingmeng _left_time1", self._left_time)
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_closeRoom = self._view:GetChild('btn_closeRoom')
if btn_closeRoom then
btn_closeRoom.onClick:Set(function()
if IsRoomOwer() then
self._gamectr:AskDismissRoom(
function(res)
ViewUtil.CloseModalWait()
if res.ReturnCode == 0 then
ViewManager.ChangeView(ViewManager.View_Family)
else
ViewUtil.ErrorTip(res.ReturnCode)
end
end)
return
end
self._gamectr:LevelRoom(function(res)
if res.ReturnCode ~= 0 then
ViewUtil.ErrorTip(res.ReturnCode)
end
ViewManager.ChangeView(ViewManager.View_Family)
end)
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--]]
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
------lingmeng-----暂时去除gps位置判定
-- 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--]]
-------------------------lingmeng---------------------------
_view:GetChild('text_roomId').text = string.format("房间:%s", self._room.room_id)
local btn_inviteFamily = self._view:GetChild('btn_inviteFamily')
if btn_inviteFamily then
UIPackage.AddPackage('base/newgroup/ui/FGAssist')
btn_inviteFamily.onClick:Set(function()
local panel_assist = FGAssistView.new(self._root_view, self._room.group_id, function()
print("lingmeng assistcallback")
end)
panel_assist:ReloadView()
panel_assist:Show()
end)
end
self._viewBtn_pangGuang = self._view:GetChild('btn_pangGuang')
self._view_WitnessPlayer = self._view:GetChild('comp_witness')
self._ctr_showWitness = self._view:GetController('witness')
if self._viewBtn_pangGuang and self._view_WitnessPlayer and self._ctr_showWitness then
self._viewBtn_pangGuang.onClick:Set(function()
if self._ctr_more then
--现在只有麻将才有_ctr_more
self._ctr_more.selectedIndex = 0
end
self._ctr_showWitness.selectedIndex = 1
self:ShowWitnessPlayer()
end)
end
RefalshBtnClose(self)
------------------------------------------------------------
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
--展示观战
function M:ShowWitnessPlayer()
local view_witness = self._ctr_showWitness
local player_list = view_witness:GetChild('list_players')
local witnessPlayer = self._room.witnessPlayers
player_list:SetVirtual()
player_list.itemRenderer = function(index, obj)
obj:GetChild('text_name').text = witnessPlayer[index + 1].nick
end
if witnessPlayer then
player_list.numItems = #witnessPlayer
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:__RecordTouchMove(context)
if Mathf.Abs(context.inputEvent.x - self._record_pos.x) >= 67 or Mathf.Abs(context.inputEvent.y - self._record_pos.y) >= 67 then
self._record_view_ctr.selectedIndex = 1
else
self._record_view_ctr.selectedIndex = 0
end
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._chat_Talk.onTouchEnd:Remove(self.__RecordTouchEnd, self)
local room = self._room
if self._record_view_ctr.selectedIndex == 0 then
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
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()
print("lingmengEventInit")
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.AddScore, handler(self, self.OnAddScoreAnimation))
--_gamectr:AddEventListener(GameEvent.MISSILE, handler(self, self.OnMissile))
_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_Family)
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 data = arg[1]
local _type = arg[2]
-- 扔番茄
if _type == 7 then
local sendSeat = arg[3].sendSeat
local targetSeat = arg[3].targetSeat
local Missile = arg[3].Missile
self:Missile(sendSeat, targetSeat, Missile)
end
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, handler(self, self.OnTupGuanOpen))
_gamectr:AddEventListener(GameEvent.WitnessPlayerEnter, handler(self, self.OnPlayerWitnessEnter))
_gamectr:AddEventListener(GameEvent.WitnessPlayerLeave, handler(self, self.OnPlayerWitnessLeave))
_gamectr:AddEventListener(GameEvent.HOMESTATE, function(...)
local arg = { ... }
local uid = arg[1].uid
local setHome = arg[1].setHome
local gameStatus = arg[1].gameStatus
local seat = GetSeat(self, uid)
local info = self._player_info[self:GetPos(seat)]
if gameStatus == "out" then
info:UpdateLineState(0)
elseif gameStatus == "enter" then
info:UpdateLineState(1)
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:OnTupGuanOpen(...)
---- print("刷新托管数据=====")
local arg = { ... }
local p = arg[1]
local info = self._player_info[self:GetPos(p.seat)]
self._left_time = tonumber(arg[3]) or 0
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
function M:OnPlayerWitnessEnter(...)
---- print("刷新托管数据=====")
local arg = { ... }
local witnessPlayerList = arg[1]
self._room.witness_player_list = witnessPlayerList
end
function M:OnPlayerWitnessLeave(...)
---- print("刷新托管数据=====")
local arg = { ... }
local player = arg[1]
local witnessPlayerList = self._room.witness_player_list
for i, _player in ipairs(witnessPlayerList) do
if _player.uid == player then
table.remove(witnessPlayerList, i)
return
end
end
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
-- ------lingmeng-----暂时去除gps位置判定
-- 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(...)
print("lingmengOnPlayerReady")
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:OnAddScoreAnimation(...)
print("OnAddScoreAnimation")
local arg = { ... }
local totalScoreList = arg[2].totalScoreList
local playerList = arg[2].playerList
local addScoreList = arg[2].addScoreList
pt(arg)
local scoreData = {}
for i = 1, #totalScoreList do
local p = {}
p.totalScore = totalScoreList[i]
p.player = playerList[i]
p.addScore = addScoreList[i]
scoreData[#scoreData + 1] = p
end
for _, p in pairs(scoreData) do
local infoView = self:GetPlayerInfo(p.player)
local player = GetPlayer(self, p.player)
player.cur_hp = p.totalScore
if p.addScore ~= 0 then
infoView:ScoreAnimation(p.addScore)
if player.cur_hp >= 0 then
infoView._view:GetChild("text_jifen").text = "+" .. player.cur_hp
else
infoView._view:GetChild("text_jifen").text = player.cur_hp
end
end
end
end
--[[
function M:OnMissile(...)
local arg = {...}
print("OnMissile 有人发表情了")
pt(arg)
--self:Missile()
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
local player_info = self._player_info[self:GetPos(p.seat)]
if p.entrust then
self:closeTipOnTuoguan()
self:MarkSelfTuoguan()
player_info:MarkTuoguan()
else
self:UnmarkSelfTuoguan()
player_info:UnmarkTuoguan()
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._player_card_info then
local info = self._player_card_info[1]
if info._ctr_tip then
info._ctr_tip.selectedIndex = 0
end
if info.ctr_put_card_option then
info.ctr_put_card_option.selectedIndex = 0
end
if info._ctr_showGuoHu then
info._ctr_showGuoHu.selectedIndex = 0
end
end
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:MakeFullScreen()
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:Center()
-- _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:Missile(seat, targetSeat, Missile)
local animUrl = ""
local url = ""
if Missile == "boom" then
animUrl = "ui://Main_Majiang/bomb"
url = "ui://Common/boom"
elseif Missile == "egg" then
animUrl = "ui://Main_Majiang/egg"
url = "ui://Common/egg"
elseif Missile == "diamo" then
animUrl = "ui://Main_Majiang/jiezhi"
url = "ui://Common/diamo"
elseif Missile == "flower" then
animUrl = "ui://Main_Majiang/flower"
url = "ui://Common/flower"
end
local send = self._player_info[self:GetPos(seat)]
local target = self._player_info[self:GetPos(targetSeat)]
MissileSender.Send(url, send, target, self, animUrl, Missile, 5, 1)
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
local result, resultInfo = pcall(func)
if result then
else
print("error", resultInfo)
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
if self._record_view then
self._record_view.title = math.floor(self._record_time) .. "\""
end
elseif self._record_time then
self._record_time = self._record_time + deltaTime
if self._record_view then
self._record_view.title = math.floor(self._record_time) .. "\""
end
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._tex_leftTime.text = string.format("%02d", _left_time)
self._left_time = _left_time
-- 桌面計時器聲音
if not self._curtime then
self._curtime = 15
end
if leftTime <= self._leftTime_xiangling and self._curtime ~= leftTime and leftTime ~= 0 then
self._curtime = leftTime
GameApplication.Instance:PlaySound('base/common/sound/timeup_alarm.mp3')
end
if self._leftTime_bianhong then
if leftTime <= 5 then
if self._tex_leftTime:GetController('poker_Color') then
self._tex_leftTime:GetController('poker_Color').selectedIndex = 1
end
else
if self._tex_leftTime:GetController('poker_Color') then
self._tex_leftTime:GetController('poker_Color').selectedIndex = 0
end
end
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:GetPlayerInfo(playId)
for _, info in pairs(self._player_info) do
if info._player.self_user.account_id == playId then
return info
end
end
end
function M:GetPlayer(playId)
for _, player in pairs(self._room.player_list) do
if player.self_user.account_id == playId then
return player
end
end
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
-- ------lingmeng-----暂时去除gps位置判定
-- 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()
MissileSender.Clear()
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