hengyang_client/lua_probject/extend_project/extend/majiang/nancheng/EXPlayBackView.lua

696 lines
26 KiB
Lua

local MJPlayBackView = require("main.majiang.MJPlayBackView")
local EXRoomConfig = import(".EXRoomConfig")
local EXClearingView = import(".EXClearingView")
local HuCardImg = import(".HuCardImg")
local FZTipList = require("main.majiang.FZData")
local MJPlayerCardInfoView = require("main.majiang.MJPlayerCardInfoView")
local Record_Event = import(".RecordEvent")
local M = {}
--- Create a new
function M.new()
setmetatable(M, { __index = MJPlayBackView })
local self = setmetatable({}, { __index = M })
self.class = "PlayBackView"
self:init()
return self
end
function M:InitView(url)
local room = self._room
UIPackage.AddPackage("extend/majiang/nancheng/ui/Extend_MJ_NanCheng")
MJPlayBackView.InitView(self, string.format("ui://Main_Majiang/Main_new_%d_jiangxi", room.room_config.people_num))
local _cardbox = self._view:GetChild("cardbox")
--self._view:GetChild("panel_record"):GetChild("btn_LastStep").enabled = false
self._ctr_cardbox = _cardbox:GetController("c1")
self._tex_round = self._view:GetChild("tex_round")
self._tex_LeftCard = self._view:GetChild("remaining_card")
self._anchor = self._view:GetChild("mask_tips")
self.jing = self._view:GetChild('jing')
self.HuCardImg = setmetatable(HuCardImg, { __index = self.HuCardImg })
self.asset_group = "NanCheng_MJ"
self.HuCardImg_path = "ui://Extend_MJ_NanCheng/"
self.Sound_path = "extend/majiang/nancheng/sound/"
self._eventmap = {}
self._cmdmap = {}
self._cmdmap[Record_Event.Evt_GetCard] = self.CmdGetCard
self._cmdmap[Record_Event.Evt_OutCard] = self.CmdOutCard
self._cmdmap[Record_Event.Evt_Action] = self.CmdAction
self._cmdmap[Record_Event.Evt_Win] = self.CmdWin
self._cmdmap[Record_Event.Evt_Niao] = self.CmdNiao
self._cmdmap[Record_Event.Evt_Piao] = self.CmdPiao
self._cmdmap[Record_Event.Evt_Result] = self.CmdResult
self._cmdmap[Record_Event.Evt_FZTip] = self.CmdFZTip
self._cmdmap[Record_Event.Evt_GangScore] = self.GangScore
self.com_logocType.selectedIndex = 1
end
function M:FillRoomData(data)
MJPlayBackView.FillRoomData(self)
if self._win_pic then self._win_pic:Dispose() end
if self._niao then self._niao:Dispose() end
self._currentStep = 0
local room = DataManager.CurrenRoom
local _player_card_info = self._player_card_info
local left_count = data.info.left_card
self:UpdateLeftCard(left_count)
local round = data.info.round
self:UpdateRound(round)
self:ShowJing()
local roominfo_panel = self._view:GetChild("roominfo_panel1")
roominfo_panel:GetChild("tex_roomid").text = room.room_id
roominfo_panel:GetChild("tex_gametype").text = room.room_config:GetGameName()
for i = 1, #room.player_list do
local p = room.player_list[i]
local card_info = _player_card_info[self:GetPos(p.seat)]
card_info:Clear()
table.sort(p.card_list, self.HandCardSortAndJing)
card_info:UpdateHandCard(false, true)
self._player_info[i]._view:GetController("piao_niao").selectedIndex = 0
end
self:GenerateAllStepData(data)
self:UpdateStep(1)
self:Play()
self._laiziMove:Play()
self._touxiangMove:Play()
-- self:ShowStep(0)
end
function M:ShowStep(index)
local step = self._step[index + 1]
self:UpdateLeftCard(step.left_card)
-- self._ctr_cardbox.selectedIndex = step.current_out_seat
self:UpdateCardBox(self:GetPos(step.current_out_seat))
self:UpdateStep(index + 1)
if step.cmd ~= Record_Event.Evt_OutCard then
self:RemoveCursor()
end
for i = 1, #step.player_card_data do
local p = self._room:GetPlayerBySeat(i)
local info = self._player_card_info[self:GetPos(i)]
p.card_list = step.player_card_data[i].card_list
p.outcard_list = step.player_card_data[i].outcard_list
p.fz_list = step.player_card_data[i].fz_list
p.hand_left_count = #p.card_list
-- info:Clear()
-- info:ResetFzList()
p.piao_niao = step.player_card_data[i].piao_niao
local head_info = self._player_info[self:GetPos(i)]
if p.piao_niao and p.piao_niao > 0 then
head_info._view:GetChild("mask_piao").title = "飘分 " .. p.piao_niao
head_info._view:GetController("piao_niao").selectedIndex = 1
else
head_info._view:GetController("piao_niao").selectedIndex = 0
end
if step.cmd == Record_Event.Evt_OutCard and i == step.last_out_seat then
local card = p.outcard_list[#p.outcard_list]
info:UpdateOutCardList(nil, card, self._cursor)
self:PlayMJSound("chupai.mp3")
self:PlaySound("NanCheng_MJ", p.self_user.sex, tostring(card))
else
info:UpdateOutCardList()
end
---显示提示按钮
local _ctr_tips = info._view:GetController('tip2')
local _lit_fanzi = info._view:GetChild("Comp_Back_FZTips")
local _flag_tipGetCard = false
if step.cmd == Record_Event.Evt_FZTip then
if p.seat == step.seat then
local tip = step.tiplist
local _tlist = tip.tip_sortList
_lit_fanzi.itemRenderer = function(index, obj)
local type = obj:GetController('type')
if index == tip.tip_num then
type.selectedIndex = 0
else
index = index + 1
if _tlist[index].type == FZType.HU then
type.selectedIndex = 4
obj:GetChild('btn_Card1').icon = string.format('ui://Main_Majiang/b202_%d',
_tlist[index].card)
_flag_tipGetCard = self.last_get_seat ~= step.seat
elseif _tlist[index].type == FZType.Chi then
type.selectedIndex = FZType.Chi
for i = 1, 3 do
obj:GetChild(string.format('btn_Card%d', i)).icon = string.format(
'ui://Main_Majiang/b202_%d',
_tlist[index].opcard[i])
end
elseif _tlist[index].type == FZType.Peng then
type.selectedIndex = FZType.Peng
for i = 1, 3 do
obj:GetChild(string.format('btn_Card%d', i)).icon = string.format(
'ui://Main_Majiang/b202_%d',
_tlist[index].card)
end
else
for i = 1, 4 do
obj:GetChild(string.format('btn_Card%d', i)).icon = string.format(
'ui://Main_Majiang/b202_%d',
_tlist[index].card)
end
type.selectedIndex = FZType.Gang
if _tlist[index].type == FZType.Gang_An then
obj:GetChild('btn_Card4').icon = 'ui://Main_Majiang/b202_00'
end
_flag_tipGetCard = true
end
end
end
_ctr_tips.selectedIndex = 1
_lit_fanzi.numItems = tip.tip_num + 1
end
else
_ctr_tips.selectedIndex = 0
_lit_fanzi.numItems = 0
end
----多人胡的时候,同时显示胡
if step.cmd == Record_Event.Evt_Result then
--所有都显示胡吧,暂时没做胡和自摸的判断
if not self.result then
if step.result_data.info_list[i].is_win then
local info2 = self._player_card_info[self:GetPos(step.result_data.info_list[i].seat)]
local loader_HuEffect = info2._viewLoader_selfHuCardEffect
local isZiMo = false
DataManager.CurrenRoom.isZiMoHu = isZiMo
local hu_sound = isZiMo and ("zimo") or ("hu")
printlog("声音====>>>", hu_sound)
self:PlaySound(self.asset_group, p.self_user.sex, hu_sound)
local effects = isZiMo and ("tile_zimo") or ("tile_hu")
loader_HuEffect.visible = true
loader_HuEffect.url = "ui://Main_Majiang/" .. effects
loader_HuEffect:SetScale(2, 2)
local hu_tween = loader_HuEffect:TweenScale(Vector2(1, 1), 0.3)
hu_tween:SetEase(EaseType.QuartOut)
hu_tween:OnComplete(function()
loader_HuEffect.visible = false
end)
end
end
end
if step.cmd ~= Record_Event.Evt_OutCard and step.cmd ~= Record_Event.Evt_GangScore and step.cmd ~= Record_Event.Evt_Win and step.cmd ~= Record_Event.Evt_Niao and p.seat == step.current_out_seat or step.cmd == Record_Event.Evt_Result then
if step.cmd == Record_Event.Evt_Action then
pt("lingmeng step ", step)
local fz = step.fz
local info = self._player_card_info[self:GetPos(i)]
local loader_HuEffect = info._viewClip_Peng_Gang
local effects = ""
if fz.type == FZType.Peng then
self:PlaySound("Main_Majiang", p.self_user.sex, "peng")
effects = "clip_peng"
elseif fz.type == FZType.Chi then
else
self:PlaySound("Main_Majiang", p.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
info:UpdateFzList(fz, index, true, self:GetPos(fz.from_seat))
end
printlog("lingmeng UpdateHandCard", step.cmd, p.seat, step.fz and step.fz.type or -1, FZType.Peng,
_flag_tipGetCard)
if step.cmd == Record_Event.Evt_Action and step.fz.type ~= FZType.Peng then
info:UpdateHandCard(false, true)
elseif step.cmd == Record_Event.Evt_FZTip and not _flag_tipGetCard then
info:UpdateHandCard(false, true)
elseif step.cmd == Record_Event.Evt_Result then
local _flag_result = false
for i = 1, #step.result_data.info_list do
printlog("lingmeng UpdateHandCard3", step.result_data.info_list[i].is_win,
step.result_data.info_list[i].seat)
if step.result_data.info_list[i].is_win and p.seat == step.result_data.info_list[i].seat then
_flag_result = true
end
end
printlog("lingmeng UpdateHandCard3", _flag_result)
info:UpdateHandCard(_flag_result, true)
else
info:UpdateHandCard(true, true)
end
else
if step.cmd == Record_Event.Evt_Win or step.cmd == Record_Event.Evt_Niao then
else
info:UpdateHandCard(false, true)
end
end
end
--统一在大结算时显示
if step.cmd == Record_Event.Evt_Win then
else
if self._win_pic then
self._win_pic:Dispose()
end
end
--统一在大结算时显示
if step.cmd == Record_Event.Evt_Niao then
local niao_list = step.niao
else
end
if step.cmd == Record_Event.Evt_Result then
print("lingmeng playerback", self.result)
if not self.result then
local result = step.result_data
result.cardList = step.residual_card
self.result = EXClearingView.new(self, { flag_back = true })
self.result:InitData(0, self._room, result)
self.result._view.x = (GRoot.inst.width - self.result._view.width) * -0.5
self.result._view.width = GRoot.inst.width
self.result._view.height = GRoot.inst.height
self._anchor:AddChild(self.result._view)
self.result._view.visible = false
self.result._view.x = self._anchor.x * -1
self.result._view.y = self._anchor.y * -1
local liuju = result and result.liuju or nil
coroutine.start(function()
coroutine.wait(0.3)
--逐个显示胡的特效
for i = 1, #result.info_list do
local hu_info = result.info_list[i]
local player = self._room:GetPlayerBySeat(hu_info.seat)
local info = self._player_card_info[self:GetPos(hu_info.seat)]
if hu_info.is_win then
local win_list = hu_info.win_list
local list_HuCardEffect = info._viewList_HuEffect
local Effects = {}
--先循环一遍把杠上开花放在最前面
for i = 1, #win_list do
local HuMsg = win_list[i]
if HuMsg.type > 2 and HuMsg.type < 60 then
if self.HuCardImg[HuMsg.type][1] == "tile_cs_gangshanghua" then
local imgPath = "ui://Main_Majiang/tile_cs_gangshanghua"
local imgObj = list_HuCardEffect:AddItemFromPool()
local imgLoader = imgObj:GetChild("loader_img")
imgLoader.url = imgPath
imgObj.visible = false
Effects[#Effects + 1] = imgObj
table.remove(win_list, i)
break
end
end
end
for i = 1, #win_list do
local HuMsg = win_list[i]
-- ↓↓↓先排列好特效图片
if HuMsg.type > 2 and HuMsg.type < 60 then
local sound_name = string.format(self.Sound_path .. "%s/%s.mp3",
ViewUtil.Sex_Chat[player.self_user.sex],
"he" .. HuMsg.type)
ViewUtil.PlaySound(self.asset_group, sound_name)
local imgList = self.HuCardImg[HuMsg.type]
for _, img in pairs(imgList) do
local imgPath = "ui://Main_Majiang/" .. img
local imgObj = list_HuCardEffect:AddItemFromPool()
local imgLoader = imgObj:GetChild("loader_img")
imgLoader.url = imgPath
imgObj.visible = false
Effects[#Effects + 1] = imgObj
end
end
end
--小于四个字段时动态调整胡特效
if info._viewText_cardInfo["huEffet_columnGap"] and #Effects < 4 then
list_HuCardEffect.columnGap = tonumber(info._viewText_cardInfo["huEffet_columnGap"])
else
list_HuCardEffect.columnGap = 0
end
-- ↓↓↓播放动画
for _, imgObj in pairs(Effects) do
imgObj.visible = true
local effect_xingxing = imgObj:GetChild("effect_xingxing")
effect_xingxing:SetPlaySettings(0, -1, 1, -1);
effect_xingxing.visible = true
effect_xingxing.playing = true
effect_xingxing.onPlayEnd:Set(function()
effect_xingxing.visible = false
end)
local imgLoader = imgObj:GetChild("loader_img")
imgLoader:SetScale(2, 2)
imgLoader:Center()
imgLoader:TweenScale(Vector2(1, 1), 0.3)
coroutine.wait(0.5)
end
coroutine.wait(0.3)
list_HuCardEffect:RemoveChildrenToPool()
end
end
--展示摸鸟
local niao_list = result.niao
self._niao = UIPackage.CreateObject("Extend_MJ_NanCheng", "Panel_Birds")
self._view:GetChild('jiangma_show'):AddChild(self._niao)
self._niao:Center()
local list_niao_card = self._niao:GetChild("Lst_birds")
list_niao_card:RemoveChildrenToPool()
for i = 1, #niao_list do
--顯示正面
local item = list_niao_card:AddItemFromPool()
local card = niao_list[i].card
item.icon = UIPackage.GetItemURL("Main_Majiang", "b202_" .. card)
if niao_list[i].score > 0 then
item:GetController("select").selectedIndex = 1
else
item:GetController("select").selectedIndex = 0
end
coroutine.wait(2 / #niao_list)
end
coroutine.wait(0.3)
self._niao:Dispose()
--统一显示弹出分数
for i = 1, #result.info_list do
local hu_info = result.info_list[i]
local head_info = self._player_info[self:GetPos(hu_info.seat)]
-- 扣分动画
head_info:UpdateScore(hu_info.total_score, true)
end
coroutine.wait(0.3)
if liuju then
self:PlayMJSound("liuju.mp3")
coroutine.wait(3)
self:PlayMJSound("end_music.mp3")
else
self:PlayMJSound("end_music.mp3")
end
coroutine.wait(0.5)
self.result._view.visible = true
end)
else
-- self.result._view.visible = true
end
end
--显示杠分
if step.cmd == Record_Event.Evt_GangScore then
local totalScoreList = step.totalScoreList
local playerList = step.playerList
local addScoreList = step.addScoreList
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 player = self._room:GetPlayerById(p.player)
local infoView = self._player_info[self:GetPos(player.seat)]
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
end
function M:GenerateAllStepData(data)
local cmdList = self.cmdList
self._step = {}
local step = {}
local info = data.info
step.cmd = ""
step.left_card = info.left_card
step.last_get_seat = 0
step.last_out_seat = 0
step.current_out_seat = 1
step.win = 0
step.niao = 0
step.residual_card = info.residual_card
step.player_card_data = {}
for i = 1, #self._room.player_list do
local p = info.playerData[i]
local u = {}
u.seat = p.seat
u.card_list = p.hand_card
u.hand_left_count = #u.card_list
u.fz_list = {}
u.outcard_list = {}
u.piao_niao = p.piao_niao
step.player_card_data[u.seat] = u
end
self._step[#self._step + 1] = step
for i = 1, #cmdList do
local tem = cmdList[i]
self._cmdmap[tem.cmd](self, tem, i)
end
end
function M:CmdGetCard(cmd, index)
local data = self:CopyLastStep(index)
data.cmd = cmd.cmd
data.current_out_seat = cmd.seat
data.last_get_seat = cmd.seat
data.left_card = cmd.data.left_count
local u = data.player_card_data[cmd.seat]
u.card_list[#u.card_list + 1] = cmd.data.card
end
function M:CmdOutCard(cmd, index)
local data = self:CopyLastStep(index)
data.cmd = cmd.cmd
data.last_out_seat = cmd.seat
local u = data.player_card_data[cmd.seat]
list_remove(u.card_list, cmd.data.card)
table.sort(u.card_list, self.HandCardSortAndJing)
u.outcard_list[#u.outcard_list + 1] = cmd.data.card
end
function M:CmdAction(cmd, index)
local data = self:CopyLastStep(index)
data.cmd = cmd.cmd
data.last_out_seat = 0
data.current_out_seat = cmd.seat
local u = data.player_card_data[cmd.seat]
local fz = nil
local index = -1
local ftype = cmd.data.type
if (ftype == FZType.Gang_Peng) then
for i = 1, #u.fz_list do
if (u.fz_list[i].card == cmd.data.card) then
u.fz_list[i].card = cmd.data.card
fz = u.fz_list[i]
fz.type = cmd.data.type
index = i - 1
break
end
end
end
fz = {}
fz.card = cmd.data.card
fz.type = cmd.data.type
if (index == -1) then
u.fz_list[#u.fz_list + 1] = fz
end
fz.from_seat = cmd.data.from_seat
local remove_num = #cmd.data.opcard
for i = 1, remove_num do
if ftype == FZType.Gang_Peng then
list_remove(u.card_list, cmd.data.card)
else
list_remove(u.card_list, cmd.data.opcard[i])
end
end
u.hand_left_count = u.hand_left_count - remove_num
if cmd.data.from_seat ~= u.seat and ftype ~= FZType.Gang_Peng then
local u = data.player_card_data[cmd.data.from_seat]
table.remove(u.outcard_list, #u.outcard_list)
end
data.fz = fz
end
function M:CmdWin(cmd, index)
local data = self:CopyLastStep(index)
data.cmd = cmd.cmd
data.win = cmd.seat
end
function M:CmdNiao(cmd, index)
local data = self:CopyLastStep(index)
data.cmd = cmd.cmd
data.niao = cmd.data.niao
end
function M:CmdPiao(cmd, index)
local data = self:CopyLastStep(index)
data.cmd = cmd.cmd
data.player_card_data[cmd.seat].piao_niao = cmd.data.num
end
function M:CmdFZTip(cmd, index)
local data = self:CopyLastStep(index)
data.cmd = cmd.cmd
data.seat = cmd.seat
local tiplist = FZTipList.new()
local list = cmd.data.tip_list
for i = 1, #list do
local dtip = list[i]
local tip = {}
tip.id = dtip["id"]
tip.weight = dtip["weight"]
tip.card = dtip["card"]
tip.type = dtip["type"]
tip.opcard = dtip["opcard"]
tiplist:AddTip(tip)
end
--排序规则,胡杠碰
tiplist:SortList(function(a, b)
return a.type < b.type
end)
data.tiplist = tiplist
data.weight = cmd.data.weight
end
function M:GangScore(cmd, index)
local data = self:CopyLastStep(index)
data.cmd = cmd.cmd
data.seat = cmd.seat
data.totalScoreList = cmd.data.totalScoreList
data.playerList = cmd.data.playerList
data.addScoreList = cmd.data.addScoreList
end
function M:CmdResult(cmd, index)
local data = self:CopyLastStep(index)
data.cmd = cmd.cmd
data.seat = 0
data.result_data = cmd.data
if not data._flag_result then
for i = 1, #cmd.data.info_list do
local info = cmd.data.info_list[i]
if info.is_win and info.seat ~= data.current_out_seat then
local u = data.player_card_data[info.seat]
u.card_list[#u.card_list + 1] = info.win_card
local u = data.player_card_data[data.last_out_seat]
table.remove(u.outcard_list, #u.outcard_list)
end
end
end
data._flag_result = true
end
function M:CopyLastStep(index)
local step = {}
local last_step = self._step[index]
step = membe_deep_clone(last_step)
self._step[#self._step + 1] = step
step.result_data = nil
return step
end
function M:UpdateLeftCard(num)
self._tex_LeftCard.text = "" .. num .. ""
end
function M:UpdateCardBox(seat)
local index = seat
local people_num = self._room.room_config.people_num
if people_num == 2 and seat == 2 then
index = 3
elseif people_num == 3 and seat == 3 then
index = 4
end
self._ctr_cardbox.selectedIndex = index
end
function M:UpdateRound()
self._view:GetChild("text_round").text = string.format("局数:%d /%d", self._room.curren_round,
self._room.room_config.round)
end
function M:ShowJing()
print("lingmeng jing ", self._room.jing)
if self._room.jing then
self.jing.visible = true
MJPlayerCardInfoView.fillCard2(self, self.jing, "b202_", self._room.jing)
else
self.jing.visible = false
end
end
function M:UpdateStep(step)
self._record:GetChild("tex_step").text = "" .. step .. " / " .. #self._step .. ""
end
function M.HandCardSortAndJing(a, b)
local jing = DataManager.CurrenRoom.jing
if a == jing or b == jing then
if a == b then
return a < b
end
return a == jing
else
if a < 200 then
a = a + 1000
elseif a < 300 then
a = a + 3000
elseif a < 400 then
a = a + 2000
else
a = a + 4000
end
if b < 200 then
b = b + 1000
elseif b < 300 then
b = b + 3000
elseif b < 400 then
b = b + 2000
else
b = b + 4000
end
return a < b
end
end
return M