235 lines
7.7 KiB
Lua
235 lines
7.7 KiB
Lua
local WitnessView = require("Game.View.WitnessView")
|
||
local TableBG = require("Game.Data.TableBG")
|
||
local HuCardImg = import(".HuCardImg")
|
||
local MJSettingView = require("main.majiang.MJSettingViewNew")
|
||
local TX_GameEvent = import(".TX_GameEvent")
|
||
|
||
|
||
local bg_config = {
|
||
{ id = 1, url = "base/main_majiang/bg/bg1", thumb = "ui://Main_Majiang/b01" },
|
||
{ id = 2, url = "base/main_majiang/bg/bg2", thumb = "ui://Main_Majiang/b02" },
|
||
{ id = 3, url = "base/main_majiang/bg/bg3", thumb = "ui://Main_Majiang/b03" },
|
||
{ id = 3, url = "base/main_majiang/bg/bg4", thumb = "ui://Main_Majiang/b04" }
|
||
}
|
||
|
||
local M = {}
|
||
setmetatable(M, { __index = WitnessView })
|
||
M.HuCardImg = HuCardImg
|
||
--- Create a new
|
||
function M.new()
|
||
local self = setmetatable({}, { __index = M })
|
||
self.class = "MJMJWitness"
|
||
self:init()
|
||
|
||
return self
|
||
end
|
||
|
||
function M:init()
|
||
getmetatable(M).__index.init(self)
|
||
|
||
UIPackage.AddPackage("base/main_majiang/ui/Main_Majiang")
|
||
end
|
||
|
||
function M:InitView()
|
||
local room = self._room
|
||
UIPackage.AddPackage("base/main_majiang/ui/Main_Majiang")
|
||
getmetatable(M).__index.InitView(self,
|
||
string.format("ui://Main_Majiang/Main_new_%d_jiangxi", room.room_config.people_num))
|
||
|
||
--切换桌布功能
|
||
local default_bg = 1
|
||
local changeTable = self._view:GetChild('btn_change')
|
||
if changeTable then
|
||
changeTable.onClick:Set(function()
|
||
default_bg = default_bg + 1 > #bg_config and 1 or default_bg + 1
|
||
TableBG.LoadTableBG(default_bg, self._room.game_id, self._root_view, bg_config)
|
||
end)
|
||
end
|
||
TableBG.LoadTableBG(default_bg, self._room.game_id, self._root_view, bg_config)
|
||
|
||
self.btn_setting = self._view:GetChild("btn_setting")
|
||
self.btn_setting.onClick:Set(handler(self, self.ClickSetting))
|
||
self._view_clearingFather = self._view:GetChild('clearing_show')
|
||
|
||
local config = ExtendManager.GetExtendConfig(room.game_id)
|
||
local mode = config:GetGameInfo()
|
||
local gamePlay = mode:LoadConfigToDetailOnlyPlay(json.encode(room.room_config.config),
|
||
json.encode(room.room_config.config.hpData))
|
||
self._view:GetChild('wanfa_text').text = gamePlay
|
||
|
||
self._laiziMove = self._view:GetTransition('laiziMove')
|
||
self._leftTime_xiangling = 3
|
||
self._left_time = 0
|
||
end
|
||
|
||
function M:ClickSetting()
|
||
local view = MJSettingView.new(self, true)
|
||
view:Show()
|
||
end
|
||
|
||
function M:Show()
|
||
getmetatable(M).__index.Show(self)
|
||
self:PlayMJMusic("game_backmusic.mp3")
|
||
end
|
||
|
||
local majiang_asset_path = "base/main_majiang/sound/"
|
||
function M:PlayMJSound(path)
|
||
ViewUtil.PlaySound(self.asset_group, majiang_asset_path .. path)
|
||
end
|
||
|
||
function M:PlayMJMusic(path)
|
||
ViewUtil.PlayMuisc(self.asset_group, majiang_asset_path .. path)
|
||
end
|
||
|
||
function M:PlaySound(group, sex, path)
|
||
local sex_path = ViewUtil.Sex_Chat[sex]
|
||
local path1 = majiang_asset_path .. string.format("%s/%s.mp3", sex_path, path)
|
||
ViewUtil.PlaySound(group, path1)
|
||
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:EventInit()
|
||
getmetatable(M).__index.EventInit(self)
|
||
local _gamectr = self._gamectr
|
||
local _room = self._room
|
||
|
||
_gamectr:AddEventListener(TX_GameEvent.SendCards, function(...)
|
||
self:ShowJing()
|
||
self._laiziMove:Play()
|
||
if self._clearingView then
|
||
self._clearingView:Destroy()
|
||
self._clearingView = nil
|
||
local list = _room.player_list
|
||
for i = 1, #list do
|
||
local p = list[i]
|
||
local info = self._player_info[self:GetPos(p.seat)]
|
||
info:MarkBank(p.seat == _room.banker_seat)
|
||
info:Ready(false)
|
||
local card_info = self._player_card_info[self:GetPos(p.seat)]
|
||
card_info:Clear()
|
||
card_info:UpdateHandCardWitness()
|
||
--发牌的时候清理一遍
|
||
p.outcard_list = {}
|
||
end
|
||
else
|
||
local list = _room.player_list
|
||
for i = 1, #list do
|
||
local p = list[i]
|
||
local info = self._player_info[self:GetPos(p.seat)]
|
||
info:FillData(p)
|
||
info:MarkBank(p.seat == _room.banker_seat)
|
||
info:Ready(false)
|
||
local card_info = self._player_card_info[self:GetPos(p.seat)]
|
||
card_info:Clear()
|
||
card_info:UpdateHandCardWitness()
|
||
--发牌的时候清理一遍
|
||
p.outcard_list = {}
|
||
end
|
||
end
|
||
self:UpdateRound()
|
||
self:RemoveCursor()
|
||
self._state.selectedIndex = 4
|
||
end)
|
||
|
||
_gamectr:AddEventListener(TX_GameEvent.EventTurn, function(...)
|
||
local arg = { ... }
|
||
if not self._left_time or self._left_time <= 15 then
|
||
self._left_time = 15
|
||
end
|
||
local seat = arg[1]
|
||
self:UpdateCardBox(self:GetPos(seat))
|
||
local info = self._player_card_info[self:GetPos(seat)]
|
||
info._player.hand_left_count = info._player.hand_left_count + 1
|
||
info:UpdateHandCardWitness(true)
|
||
end)
|
||
|
||
_gamectr:AddEventListener(TX_GameEvent.OutCard, function(...)
|
||
local arg = { ... }
|
||
local p = arg[1]
|
||
local card = arg[2]
|
||
local seat = p.seat
|
||
local info = self._player_card_info[self:GetPos(seat)]
|
||
|
||
self:RemoveCursor()
|
||
|
||
info:UpdateHandCardWitness(false)
|
||
|
||
info:UpdateOutCardList(nil, nil, self._cursor)
|
||
self:PlayMJSound("chupai.mp3")
|
||
self:PlaySound("LiChuan_MJ", p.self_user.sex, tostring(card))
|
||
if seat == _room.self_player.seat then
|
||
_room.curren_outcard_seat = -1
|
||
end
|
||
end)
|
||
|
||
_gamectr:AddEventListener(TX_GameEvent.FangziAction, handler(self, self.OnFangziAction))
|
||
end
|
||
|
||
function M:OnFangziAction(...)
|
||
local arg = { ... }
|
||
local _player_card_info = self._player_card_info
|
||
local fz = arg[1]
|
||
local player = arg[2]
|
||
local index = arg[3]
|
||
local info = _player_card_info[self:GetPos(player.seat)]
|
||
-- local pNode = info._mask_liangpai
|
||
|
||
|
||
|
||
local arg = { ... }
|
||
local _player_card_info = self._player_card_info
|
||
local fz = arg[1]
|
||
local player = arg[2]
|
||
local index = arg[3]
|
||
local info = _player_card_info[self:GetPos(player.seat)]
|
||
local loader_HuEffect = info._viewClip_Peng_Gang
|
||
local effects = ""
|
||
if fz.type == FZType.Peng then
|
||
self:PlaySound("Main_Majiang", player.self_user.sex, "peng")
|
||
effects = "clip_peng"
|
||
elseif fz.type == FZType.Chi then
|
||
|
||
else
|
||
self:PlaySound("Main_Majiang", player.self_user.sex, "gang")
|
||
effects = "clip_gang"
|
||
end
|
||
local clip = UIPackage.CreateObjectFromURL(string.format("ui://Main_Majiang/%s", effects))
|
||
clip:SetSize(loader_HuEffect.width, loader_HuEffect.height)
|
||
loader_HuEffect:AddChild(clip)
|
||
clip:SetPlaySettings(0, -1, 1, -1)
|
||
clip.onPlayEnd:Add(function()
|
||
if clip.parent then
|
||
clip.parent:RemoveChild(clip)
|
||
end
|
||
clip:Dispose()
|
||
end)
|
||
clip.playing = true
|
||
coroutine.start(function()
|
||
coroutine.wait(0.3)
|
||
self._popEvent = true
|
||
end)
|
||
|
||
self:RemoveCursor()
|
||
if (player.seat ~= fz.from_seat) then
|
||
local fs_info = _player_card_info[self:GetPos(fz.from_seat)]
|
||
fs_info:UpdateOutCardList()
|
||
end
|
||
local seat = (self._room.room_config.people_num == 2 and fz.from_seat == 2) and 2 or fz.from_seat - 1
|
||
info:UpdateFzList(fz, index, true, seat)
|
||
|
||
--因为观战没有手牌,等预处理完扣牌数之后矫正一次(最粗暴的修正方式,手牌数等于13-3*吃碰数)
|
||
|
||
info._player.hand_left_count = 14 - 3 * #info._player.fz_list
|
||
info:UpdateHandCardWitness(true)
|
||
-- self:__CloseTip()
|
||
end
|
||
|
||
return M
|