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 ) 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