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

458 lines
18 KiB
Lua
Raw Normal View History

2025-04-01 10:48:36 +08:00
require("Game.View.ResultView")
local Hu_Type_Name = import(".CS_Win_Type")
local EXClearingView = {}
local M = EXClearingView
2025-09-18 13:32:05 +08:00
function EXClearingView.new(root, data)
2025-04-21 18:55:46 +08:00
setmetatable(M, { __index = ResultView })
local self = setmetatable({}, { __index = M })
self._full = true
ResultView.init(self, "ui://Main_Majiang/clearing")
2025-04-01 10:48:36 +08:00
2025-07-29 01:51:56 +08:00
self._root_view:GetChild("win_mode").visible = false
2025-04-21 18:55:46 +08:00
self._currenIndex = 0
2025-09-18 13:32:05 +08:00
self._root = root
2025-04-21 18:55:46 +08:00
self._close_zone = false
2025-09-03 16:52:14 +08:00
if data then
self.flag_back = data.flag_back
end
2025-04-21 18:55:46 +08:00
-- self:InitMaPai()
2025-04-01 10:48:36 +08:00
2025-04-21 18:55:46 +08:00
return self
2025-04-01 10:48:36 +08:00
end
2025-04-21 18:55:46 +08:00
-- function M:InitMaPai()
-- self.maPaiCtr = self._view:GetController("mapai")
-- self.maPaiCtr.selectedIndex = 0
2025-04-01 10:48:36 +08:00
2025-04-21 18:55:46 +08:00
-- self.maPaiList = {}
2025-04-01 10:48:36 +08:00
2025-04-21 18:55:46 +08:00
-- for i = 1, 8 do
-- local tempMP = self._view:GetChild("niao" .. i)
-- table.insert(self.maPaiList, tempMP)
-- end
-- end
2025-04-01 10:48:36 +08:00
2025-07-18 18:58:58 +08:00
function M:InitData(over, room, result, total_result, callback, isWitness, witnessCallbak)
2025-04-21 18:55:46 +08:00
-- print("===============================InitData===========================", over, room, result, total_result)
-- pt(room)
-- pt(result)
-- Pt(total_result)
self._callback = callback
2025-07-18 18:58:58 +08:00
self._witnessCallbak = witnessCallbak
2025-04-21 18:55:46 +08:00
local showClearMainBtn = self._view:GetChild("btn_showClearMain")
local nextRoundBtn = self._view:GetChild("btn_nextRound")
local nextRoundBtn2 = self._view:GetChild("Btn_NextRound2")
local endRound = self._view:GetChild("Btn_EndRound")
local _overCtr = self._view:GetController("over")
local mainCtr = self._view:GetController("main")
local playerNum = self._view:GetController("playerNum")
local showBtnTypeCtr = self._view:GetController("showType")
local Text_BoJing = self._view:GetChild('Text_BoJing')
Text_BoJing.visible = false
2025-04-21 18:55:46 +08:00
2025-09-03 16:52:14 +08:00
--回放不需要显示还剩下多少牌
if self.flag_back then
result.cardList = {}
mainCtr.selectedIndex = 1
nextRoundBtn2.touchable = false
else
if result then
if result.cardList then
result.cardList = json.decode(result.cardList)
end
end
2025-07-18 19:26:03 +08:00
end
2025-07-18 18:58:58 +08:00
self.list_lastCard = self._view:GetChild('list_lastCard')
self.list_lastCard:SetVirtual()
self.list_lastCard.itemRenderer = function(index, obj)
self:RemindCardRender(result.cardList[index + 1], obj)
end
2025-04-21 18:55:46 +08:00
local peopleNum = room.room_config.people_num
playerNum.selectedIndex = peopleNum - 2
showClearMainBtn.onClick:Set(function()
mainCtr.selectedIndex = 1
end)
nextRoundBtn.onClick:Set(function()
2025-09-27 17:59:31 +08:00
if self._callback_jiangma then
self._callback_jiangma()
end
2025-07-18 18:58:58 +08:00
if isWitness and isWitness == 1 then
if self._witnessCallbak then
self._witnessCallbak()
end
self:DestroyWithCallback()
else
if over == 0 then
local _gamectr = ControllerManager.GetController(GameController)
_gamectr:PlayerReady()
self:DestroyWithCallback()
else
mainCtr.selectedIndex = 1
_overCtr.selectedIndex = 1
end
2025-07-18 18:58:58 +08:00
end
2025-04-21 18:55:46 +08:00
end)
endRound.onClick:Set(function()
ViewManager.ChangeView(ViewManager.View_Family)
end)
if over == 0 then
showBtnTypeCtr.selectedIndex = 0
_overCtr.selectedIndex = 0
self:fillResult0(room, peopleNum, result)
nextRoundBtn2.onClick:Set(function()
2025-09-27 17:59:31 +08:00
if self._callback_jiangma then
self._callback_jiangma()
end
2025-07-18 18:58:58 +08:00
if isWitness and isWitness == 1 then
if self._witnessCallbak then
self._witnessCallbak()
end
self:DestroyWithCallback()
else
local _gamectr = ControllerManager.GetController(GameController)
_gamectr:PlayerReady()
self:DestroyWithCallback()
end
2025-04-21 18:55:46 +08:00
end)
elseif over == 1 then
self:fillResult1(room, peopleNum, total_result)
if result then
_overCtr.selectedIndex = 0
2025-04-21 18:55:46 +08:00
self:fillResult0(room, peopleNum, result)
nextRoundBtn2.onClick:Set(function()
_overCtr.selectedIndex = 1
end)
else
showBtnTypeCtr.selectedIndex = 1
2025-04-21 18:55:46 +08:00
_overCtr.selectedIndex = 1
end
else --解散房间如果没有开局直接退出不显示结算界面over=2
if room.curren_round > 0 then
2025-08-21 21:35:24 +08:00
mainCtr.selectedIndex = 1
2025-04-21 18:55:46 +08:00
_overCtr.selectedIndex = 1
showBtnTypeCtr.selectedIndex = 1
self:fillResult1(room, peopleNum, total_result)
else
ViewManager.ChangeView(ViewManager.View_Family)
end
end
2025-04-01 10:48:36 +08:00
end
2025-04-21 18:55:46 +08:00
function M:fillResult0(room, peopleNum, result)
local config = ExtendManager.GetExtendConfig(room.game_id)
local mode = config:GetGameInfo()
2025-08-23 22:23:17 +08:00
local gamePlay = mode:LoadConfigToDetail(json.encode(room.room_config.config), json.encode(room.room_config.hpData))
2025-04-21 18:55:46 +08:00
self._view:GetChild("Label_GamePlay").title = string.format("第%s/%s局,%s", room.curren_round,
room.room_config.round, gamePlay)
2025-07-18 19:26:03 +08:00
self.list_lastCard.numItems = #result.cardList
self._view:GetChild('n147').text = string.format("剩余%d张未显示", #result.cardList)
2025-04-21 18:55:46 +08:00
for i = 1, peopleNum do
local playerInfoComp = self._view:GetChild(string.format("Comp_Player%d", i))
local allCardsList = playerInfoComp:GetChild("list_allCards")
local huCardBtn = playerInfoComp:GetChild("Btn_Card_Hu")
local jiangMaList = playerInfoComp:GetChild("list_JiangMa")
local ziMoCtr = playerInfoComp:GetController("isZiMo")
local dianPaoCtr = playerInfoComp:GetController("isPao")
local isMeCtr = playerInfoComp:GetController("IsMe")
local isZhuang = playerInfoComp:GetController("zhuang")
local infoList = result.info_list[i]
2025-04-22 16:24:35 +08:00
local infoJiangma = result.niao
2025-04-21 18:55:46 +08:00
local playInfo = room:GetPlayerBySeat(infoList.seat)
local fzCardInfo = playInfo.fz_list
local fzInfoNum = #fzCardInfo
local handInfoNum = #infoList.hand_card
self:fillHead(playInfo.self_user.head_url, playerInfoComp)
infoList.jing_score = infoList.jing_score or 0
infoList.gang_score = infoList.gang_score or 0
infoList.hu_score = infoList.hu_score or 0
infoList.round_score = infoList.round_score or 0
playerInfoComp:GetChild("Text_BoJing").visible = false
2025-04-21 18:55:46 +08:00
playerInfoComp:GetChild("text_name").text = playInfo.self_user.nick_name
playerInfoComp:GetChild("Text_BoJing").text = infoList.jing_score >= 0 and
string.format("+%d", infoList.jing_score) or infoList.jing_score
playerInfoComp:GetChild("Text_Gang").text = infoList.gang_score >= 0 and
string.format("+%d", infoList.gang_score) or infoList.gang_score
playerInfoComp:GetChild("Text_Hu").text = infoList.hu_score >= 0 and string.format("+%d", infoList.hu_score) or
infoList.hu_score
playerInfoComp:GetChild("Text_Tatal").text = infoList.round_score >= 0 and
string.format("+%d", infoList.round_score) or infoList.round_score
for j = 1, fzInfoNum do
if fzCardInfo[j].type == FZType.Peng then
local item = allCardsList:AddItemFromPool("ui://Main_Majiang/Comp_Clearing_FZ_3")
for l = 1, 3 do
local card = item:GetChild(string.format("Btn_Card%d", l))
card.icon = string.format("ui://Main_Majiang/%s202_%d", self:GetPrefix(), fzCardInfo[j].card)
print("===============================FZType.Peng", room.jing, fzCardInfo[j].card)
if room.jing == fzCardInfo[j].card then
card:GetController('jing').selectedIndex = 1
2025-09-12 17:10:34 +08:00
else
card:GetController('jing').selectedIndex = 0
2025-04-21 18:55:46 +08:00
end
end
elseif fzCardInfo[j].type == FZType.Chi then
local item = allCardsList:AddItemFromPool("ui://Main_Majiang/Comp_Clearing_FZ_3")
for l = 1, 3 do
local card = item:GetChild(string.format("Btn_Card%d", l))
card.icon = string.format("ui://Main_Majiang/%s202_%d", self:GetPrefix(), fzCardInfo[j].opcard
[l])
print("===============================FZType.Chi", room.jing, fzCardInfo[j].opcard[l])
if room.jing == fzCardInfo[j].opcard[l] then
card:GetController('jing').selectedIndex = 1
2025-09-12 17:10:34 +08:00
else
card:GetController('jing').selectedIndex = 0
2025-04-21 18:55:46 +08:00
end
end
elseif fzCardInfo[j].type == FZType.Gang or fzCardInfo[j].type == FZType.Gang_An or fzCardInfo[j].type == FZType.Gang_Peng then
local item = allCardsList:AddItemFromPool("ui://Main_Majiang/Comp_Clearing_FZ_4")
for l = 1, 4 do
local card = item:GetChild(string.format("Btn_Card%d", l))
if fzCardInfo[j].type == FZType.Gang_An and j == 4 then
2025-07-16 15:07:29 +08:00
card.icon = "ui://Main_Majiang/b202_00"
2025-04-21 18:55:46 +08:00
else
card.icon = string.format("ui://Main_Majiang/%s202_%d", self:GetPrefix(), fzCardInfo[j].card)
print("===============================FZType.Gang", room.jing, fzCardInfo[j].card)
if room.jing == fzCardInfo[j].card then
card:GetController('jing').selectedIndex = 1
2025-09-12 17:10:34 +08:00
else
card:GetController('jing').selectedIndex = 0
2025-04-21 18:55:46 +08:00
end
end
end
end
end
2025-04-21 18:55:46 +08:00
local handCardItem = allCardsList:AddItemFromPool("ui://Main_Majiang/Comp_HandCard")
local handCardList = handCardItem:GetChild("list")
2025-05-07 17:19:35 +08:00
--手牌排序
2025-05-13 10:30:27 +08:00
table.sort(infoList.hand_card, self.HandCardSortAndJing)
2025-04-21 18:55:46 +08:00
handCardList:SetVirtual()
handCardList.itemRenderer = function(index, obj)
2025-07-18 18:58:58 +08:00
obj.icon = string.format("ui://Main_Majiang/%s202_%d", self:GetPrefix(), infoList.hand_card[index + 1])
2025-04-21 18:55:46 +08:00
if room.jing == infoList.hand_card[index + 1] then
obj:GetController('jing').selectedIndex = 1
2025-09-12 17:10:34 +08:00
else
obj:GetController('jing').selectedIndex = 0
2025-04-21 18:55:46 +08:00
end
end
handCardList.numItems = handInfoNum
--拿取实际的子项大小
local handCard = 78
local hangColumGrap = -4
local fzCard = 234
local fzColumGrap = 36
handCard = handCardList:GetChildAt(handInfoNum - 1).width
hangColumGrap = handCard + handCardList.columnGap
if fzInfoNum > 0 then
fzCard = allCardsList:GetChildAt(0).width
fzColumGrap = allCardsList.columnGap
end
allCardsList.width = fzCard * fzInfoNum + handCard + (handInfoNum - 1) * hangColumGrap +
fzColumGrap * (fzInfoNum)
2025-04-21 18:55:46 +08:00
if infoList.seat == room.self_player.seat then
isMeCtr.selectedIndex = 1
end
if infoList.seat == room.self_player.seat then
isMeCtr.selectedIndex = 1
end
2025-04-21 18:55:46 +08:00
if infoList.seat == room.banker_seat then
isZhuang.selectedIndex = 1
end
if infoList.is_win then
local winInfo = ""
for j = 1, #infoList.win_list do
winInfo = string.format("%s,%s", winInfo, Hu_Type_Name[infoList.win_list[j].type])
end
winInfo = string.sub(winInfo, 2, -1)
playerInfoComp:GetChild("text_huShow").text = winInfo
if room.isZiMoHu then
ziMoCtr.selectedIndex = 1
end
2025-07-16 15:07:29 +08:00
huCardBtn.icon = string.format("ui://Main_Majiang/b202_%d", infoList.win_card)
2025-09-09 21:06:16 +08:00
if room.jing == infoList.win_card then
huCardBtn:GetController('jing').selectedIndex = 1
2025-09-12 17:10:34 +08:00
else
huCardBtn:GetController('jing').selectedIndex = 0
2025-09-09 21:06:16 +08:00
end
2025-04-21 18:55:46 +08:00
huCardBtn.visible = true
2025-04-22 16:24:35 +08:00
jiangMaList.visible = true
jiangMaList:SetVirtual()
jiangMaList.itemRenderer = function(index, obj)
2025-07-16 15:07:29 +08:00
obj.icon = string.format("ui://Main_Majiang/b202_%d", infoJiangma[index + 1].card)
2025-04-22 16:24:35 +08:00
obj:GetController('bg').selectedIndex = infoJiangma[index + 1].score
obj:GetController('jing').selectedIndex = infoJiangma[index + 1].card == room.jing and 1 or 0
end
jiangMaList.numItems = #infoJiangma
2025-09-27 17:59:31 +08:00
-- jiangMaList.columnCount = #infoJiangma / 2
2025-04-21 18:55:46 +08:00
else
playerInfoComp:GetChild("text_huShow").text = ""
if not room.isZiMoHu and playInfo.self_user.account_id == result.active_player then
dianPaoCtr.selectedIndex = 1
end
huCardBtn.visible = false
jiangMaList.visible = false
end
end
2025-04-01 10:48:36 +08:00
end
2025-04-21 18:55:46 +08:00
function M:fillResult1(room, peopleNum, total_result)
local gameNameAndRoomIDText = self._view:GetChild("Text_GameNameAndRoomID")
local familyIDText = self._view:GetChild("Text_FamilyID")
2025-07-18 18:58:58 +08:00
print("lingmeng fillResult1")
pt(room)
2025-09-08 20:54:23 +08:00
--初始化大赢家和最佳炮手
local bigWin = { seat = -1, score = 0 }
local bestPao = { seat = -1, times = 0 }
--循环数据得出分数最大的大赢家,以及点炮次数最多的最佳炮手
for i = 1, #total_result.info_list do
if total_result.info_list[i].total_score > bigWin.score then
bigWin = { seat = total_result.info_list[i].seat, score = total_result.info_list[i].total_score }
end
if total_result.info_list[i].settle_log.fangpao and total_result.info_list[i].settle_log.fangpao > bestPao.times then
bestPao = { seat = total_result.info_list[i].seat, times = total_result.info_list[i].settle_log.fangpao }
end
end
2025-07-18 18:58:58 +08:00
for i, v in pairs(DataManager.SelfUser.games) do
2025-04-21 18:55:46 +08:00
if v.game_id == room.game_id then
gameNameAndRoomIDText.text = string.format("%s 房号:%s", v.name, room.room_id)
end
2025-04-01 10:48:36 +08:00
end
2025-04-21 18:55:46 +08:00
if #gameNameAndRoomIDText.text <= 0 then
gameNameAndRoomIDText.text = string.format("房号:%s", room.room_id)
2025-04-01 10:48:36 +08:00
end
if room.group_id ~= 0 then
2025-04-21 18:55:46 +08:00
familyIDText.text = string.format("俱乐部:%s", room.group_id)
else
familyIDText.visible = false
2025-10-14 20:44:57 +08:00
self._view:GetChild('n148').visible = false
2025-04-21 18:55:46 +08:00
end
self._view:GetChild("Text_RoundNum").text = string.format("局数:%s/%s", room.curren_round, room.room_config.round)
self._view:GetChild("Text_Time").text = os.date("%Y-%m-%d %H:%M:%S", os.time())
for i = 1, peopleNum do
local resultInfoComp = self._view:GetChild(string.format("Comp_ResultInfo%d", i))
local totalInfoList = total_result.info_list[i]
local playInfo = room:GetPlayerBySeat(totalInfoList.seat)
self:fillHead(playInfo.self_user.head_url, resultInfoComp)
resultInfoComp:GetChild('Text_Name').text = playInfo.self_user.nick_name
resultInfoComp:GetChild('Text_ID').text = string.format("ID:%s", playInfo.self_user.account_id)
resultInfoComp:GetChild('Text_TotalScore').text = totalInfoList.total_score >= 0 and
string.format("+%s", totalInfoList.total_score) or totalInfoList.total_score
resultInfoComp:GetChild('Text_ZiMo').text = string.format("自摸 %d次", totalInfoList.settle_log.zimo or 0)
resultInfoComp:GetChild('Text_JiePao').text = string.format("接炮 %d次", totalInfoList.settle_log.jiepao or 0)
resultInfoComp:GetChild('Text_FangPao').text = string.format("放炮 %d次", totalInfoList.settle_log.fangpao or 0)
resultInfoComp:GetChild('Text_AnGang').text = string.format("暗杠 %d次", totalInfoList.settle_log.an_kong or 0)
resultInfoComp:GetChild('Text_MingGang').text = string.format("明杠 %d次",
totalInfoList.settle_log.ming_kong or 0)
resultInfoComp:GetChild('Text_FangGang').text = string.format("放杠 %d次",
totalInfoList.settle_log.fanggang or 0)
resultInfoComp:GetController("win").selectedIndex = totalInfoList.total_score >= 0 and 1 or 0
2025-09-08 20:54:23 +08:00
if totalInfoList.seat == bigWin.seat then
resultInfoComp:GetController("bigWin").selectedIndex = 1
-- else
-- resultInfoComp:GetController("bigWin").selectedIndex = 0
end
if totalInfoList.seat == bestPao.seat then
resultInfoComp:GetController("fangPao").selectedIndex = 1
-- else
-- resultInfoComp:GetController("fangPao").selectedIndex = 0
end
2025-04-01 10:48:36 +08:00
end
end
2025-04-21 18:55:46 +08:00
function M:fillHead(url, view)
ImageLoad.Load(url, view:GetChild("Btn_Head")._iconObject)
2025-04-01 10:48:36 +08:00
end
2025-07-18 18:58:58 +08:00
function M:RemindCardRender(data, obj)
local room = DataManager.CurrenRoom
obj.icon = string.format("ui://Main_Majiang/%s202_%d", self:GetPrefix(), data)
if room.jing == data then
obj:GetController('jing').selectedIndex = 1
2025-09-12 17:10:34 +08:00
else
obj:GetController('jing').selectedIndex = 0
2025-07-18 18:58:58 +08:00
end
end
2025-05-13 10:30:27 +08:00
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
2025-04-01 10:48:36 +08:00
local prefix
function M:GetPrefix()
2025-04-21 18:55:46 +08:00
-- if not prefix then
prefix = get_majiang_prefix(10)
2025-04-01 10:48:36 +08:00
-- end
2025-04-21 18:55:46 +08:00
return prefix
2025-04-01 10:48:36 +08:00
end
2025-09-27 17:59:31 +08:00
function M:SetJiangMaCallback(fct)
self._callback_jiangma = fct
end
2025-04-21 18:55:46 +08:00
function M:DestroyWithCallback()
if self._callback then
self._callback()
end
self:Destroy()
2025-04-01 10:48:36 +08:00
end
2025-04-21 18:55:46 +08:00
return M