jx_client_neibu/lua_probject/base_project/Game/View/WitnessView.lua

471 lines
15 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 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 = 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
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
function M:InitView(url)
local room = self._room
BaseView.InitView(self, url)
self.com_logocType = self._view:GetChild("com_logo"):GetController("cType")
self._state = self._view:GetController("state")
self.com_notice = self._view:GetChild("com_notice")
if self._room.self_player.entrust then
self:MarkSelfTuoguan()
end
end
function M:EventInit()
local _gamectr = self._gamectr
local _room = self._room
_gamectr:AddEventListener(GameEvent.PlayerEnter, function(...)
ViewUtil.PlaySound("WitnessView", "base/main_majiang/sound/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)]
if info2.SetPlayer then
info2:SetPlayer(p)
info2:FillData()
end
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
ViewUtil.PlaySound("WitnessView", "base/main_majiang/sound/user_leave.mp3")
end)
_gamectr:AddEventListener(GameEvent.WitnessPlayerEnter, function(...)
ViewUtil.PlaySound("WitnessView", "base/main_majiang/sound/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
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)
_gamectr:AddEventListener(GameEvent.AddScore, handler(self, self.OnAddScoreAnimation))
_gamectr:AddEventListener(
GameEvent.PlayerState,
function(...)
printlog("lingmeng OnEventOnlineState")
local arg = { ... }
local p = arg[1]
local info = self._player_info[self:GetPos(p.seat)]
info._ctr_offline.selectedIndex = p.line_state == 0 and 1 or 0
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
self._view:AddChildAt(com_tuoguan, self._view:GetChildIndex(self._view:GetChild('btn_setting')) - 1)
-- GRoot.inst:AddChild(com_tuoguan)
com_tuoguan:GetChild('btn_cancel_tuoguan').visible = false
com_tuoguan:MakeFullScreen()
com_tuoguan:Center()
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: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: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)
end
end
end
local _left_time = self._left_time or 0
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
end
function M:onLeftTimeOver()
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()
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
return M