413 lines
13 KiB
Lua
413 lines
13 KiB
Lua
local MJMainView = require("main.majiang.MJMainView")
|
||
local MissileSender = import(".MissileSender")
|
||
|
||
local WitnessView = {}
|
||
|
||
local M = WitnessView
|
||
setmetatable(M, { __index = BaseView })
|
||
function M:init()
|
||
self._gamectr = ControllerManager.GetController(GameController)
|
||
self._room = DataManager.CurrenRoom
|
||
self._room.Witness = true
|
||
|
||
UIPackage.AddPackage('base/chat/ui/Chat')
|
||
|
||
self._eventmap = {}
|
||
self._scale = true
|
||
self._full_offset = false
|
||
self.class = "MainView"
|
||
self._style = 1
|
||
self._popEvent = true
|
||
self.Fix_Msg_Chat = ViewUtil.Fix_Msg_Chat -- 自动回复消息列表
|
||
self:InitView()
|
||
end
|
||
|
||
-- 语音是否禁止
|
||
local record_baned = 0
|
||
|
||
function M:InitView(url)
|
||
local room = self._room
|
||
BaseView.InitView(self, url)
|
||
|
||
|
||
|
||
self.com_logocType = self._view:GetChild("com_logo"):GetController("cType")
|
||
|
||
self.com_notice = self._view:GetChild("com_notice")
|
||
end
|
||
|
||
function M:EventInit()
|
||
local _gamectr = self._gamectr
|
||
local _room = self._room
|
||
|
||
_gamectr:AddEventListener(GameEvent.PlayerEnter, function(...)
|
||
self:PlayMJSound("user_enter.mp3")
|
||
local arg = { ... }
|
||
local p = arg[1]
|
||
local info1 = self._player_info[self:GetPos(p.seat)]
|
||
info1:FillData(p)
|
||
info1._view.visible = true
|
||
|
||
local info2 = self._player_card_info[self:GetPos(p.seat)]
|
||
info2:SetPlayer(p)
|
||
info2:FillData()
|
||
end)
|
||
|
||
_gamectr:AddEventListener(GameEvent.PlayerLeave, function(...)
|
||
local arg = { ... }
|
||
local p = arg[1]
|
||
local info1 = self._player_info[self:GetPos(p.seat)]
|
||
info1._view.visible = false
|
||
self:PlayMJSound("user_leave.mp3")
|
||
end)
|
||
|
||
_gamectr:AddEventListener(GameEvent.WitnessPlayerEnter, function(...)
|
||
self:PlayMJSound("user_enter.mp3")
|
||
local arg = { ... }
|
||
local witnessPlayerList = arg[1]
|
||
self._room.witness_player_list = witnessPlayerList
|
||
|
||
local _room = DataManager.CurrenRoom
|
||
local viewList_witness = self._view:GetChild('comp_witness'):GetChild('list_players')
|
||
if viewList_witness.numItems == #_room.witness_player_list then
|
||
viewList_witness:RefreshVirtualList()
|
||
else
|
||
viewList_witness.numItems = #_room.witness_player_list
|
||
end
|
||
end)
|
||
|
||
_gamectr:AddEventListener(GameEvent.WitnessPlayerLeave, function(...)
|
||
---- print("刷新托管数据=====")
|
||
local arg = { ... }
|
||
local player = arg[1]
|
||
local witnessPlayerList = self._room.witness_player_list
|
||
for i, _player in ipairs(witnessPlayerList) do
|
||
if _player.aid == player then
|
||
table.remove(witnessPlayerList, i)
|
||
break
|
||
end
|
||
end
|
||
|
||
local _room = DataManager.CurrenRoom
|
||
local viewList_witness = self._view:GetChild('comp_witness'):GetChild('list_players')
|
||
print("linemng", _room._flag_updateWitness, #_room.witness_player_list, viewList_witness.numItems)
|
||
if viewList_witness.numItems == #_room.witness_player_list then
|
||
viewList_witness:RefreshVirtualList()
|
||
else
|
||
viewList_witness.numItems = #_room.witness_player_list
|
||
end
|
||
end)
|
||
|
||
_gamectr:AddEventListener(
|
||
GameEvent.TupGuanOpen,
|
||
function(...)
|
||
---- 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
|
||
)
|
||
|
||
_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.OnUpdateInfo, function(...)
|
||
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)
|
||
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:closeTipOnTuoguan()
|
||
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:GetChatMsgLanguage(msg_index)
|
||
local language = math.modf(msg_index / 100)
|
||
local index = math.fmod(msg_index, 100)
|
||
return language, index
|
||
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:Show()
|
||
getmetatable(WitnessView).__index.Show(self)
|
||
self:DoNoticeAnimation()
|
||
end
|
||
|
||
function M:DoNoticeAnimation()
|
||
self.noticeIndex = self.noticeIndex or 1
|
||
if not DataManager.GameNotice or #DataManager.GameNotice == 0 then
|
||
return
|
||
end
|
||
|
||
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
|
||
|
||
local tween = text_notice:TweenMove(Vector2(-text_notice.width, text_notice.y), time):OnComplete(function()
|
||
self:DoNoticeAnimation()
|
||
end)
|
||
|
||
tween:SetEase(EaseType.Linear)
|
||
|
||
self.noticeIndex = self.noticeIndex + 1
|
||
if self.noticeIndex > #DataManager.GameNotice then
|
||
self.noticeIndex = 1
|
||
end
|
||
|
||
--强制让牌类型为1,只有一种牌
|
||
self._room.card_type = 1
|
||
end
|
||
|
||
function M:OnUpdate()
|
||
local deltaTime = Time.deltaTime
|
||
if (self._popEvent) then
|
||
local func = self._gamectr:PopEvent()
|
||
if (func ~= nil) then
|
||
local success, result = pcall(func)
|
||
if success then
|
||
|
||
else
|
||
print("witness error")
|
||
print(result)
|
||
error(result)
|
||
-- self._gamectr = ControllerManager.GetController(GameController)
|
||
-- if self._gamectr then
|
||
-- self._gamectr:ResetConnect()
|
||
-- end
|
||
end
|
||
--func()
|
||
end
|
||
end
|
||
|
||
local _left_time = self._left_time
|
||
if _left_time and (_left_time > 0) then
|
||
_left_time = _left_time - deltaTime
|
||
_left_time = math.max(0, _left_time)
|
||
local leftTime = math.floor(_left_time)
|
||
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 <= 3 and self._curtime ~= leftTime and leftTime ~= 0 then
|
||
self._curtime = leftTime
|
||
GameApplication.Instance:PlaySound('base/common/sound/timeup_alarm.mp3')
|
||
end
|
||
else
|
||
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
|
||
end
|
||
|
||
function M:DestroyPlayerInfo()
|
||
for i = 1, #self._player_info do
|
||
self._player_info[i]:Destroy()
|
||
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
|
||
|
||
return M
|