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

449 lines
18 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.

require("Game.View.ResultView")
local Hu_Type_Name = import(".CS_Win_Type")
local EXClearingView = {}
local M = EXClearingView
function EXClearingView.new(root, data)
setmetatable(M, { __index = ResultView })
local self = setmetatable({}, { __index = M })
self._full = true
ResultView.init(self, "ui://Main_Majiang/clearing")
self._root_view:GetChild("win_mode").visible = false
self._currenIndex = 0
self._root = root
self._close_zone = false
if data then
self.flag_back = data.flag_back
end
-- self:InitMaPai()
return self
end
-- function M:InitMaPai()
-- self.maPaiCtr = self._view:GetController("mapai")
-- self.maPaiCtr.selectedIndex = 0
-- self.maPaiList = {}
-- for i = 1, 8 do
-- local tempMP = self._view:GetChild("niao" .. i)
-- table.insert(self.maPaiList, tempMP)
-- end
-- end
function M:InitData(over, room, result, total_result, callback, isWitness, witnessCallbak)
-- print("===============================InitData===========================", over, room, result, total_result)
-- pt(room)
-- pt(result)
-- Pt(total_result)
self._callback = callback
self._witnessCallbak = witnessCallbak
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")
--回放不需要显示还剩下多少牌
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
end
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
local peopleNum = room.room_config.people_num
playerNum.selectedIndex = peopleNum - 2
showClearMainBtn.onClick:Set(function()
mainCtr.selectedIndex = 1
end)
nextRoundBtn.onClick:Set(function()
if self._callback_jiangma then
self._callback_jiangma()
end
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
end
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()
if self._callback_jiangma then
self._callback_jiangma()
end
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
end)
elseif over == 1 then
self:fillResult1(room, peopleNum, total_result)
if result then
_overCtr.selectedIndex = 0
self:fillResult0(room, peopleNum, result)
nextRoundBtn2.onClick:Set(function()
_overCtr.selectedIndex = 1
end)
else
showBtnTypeCtr.selectedIndex = 1
_overCtr.selectedIndex = 1
end
else --解散房间如果没有开局直接退出不显示结算界面over=2
if room.curren_round > 0 then
mainCtr.selectedIndex = 1
_overCtr.selectedIndex = 1
showBtnTypeCtr.selectedIndex = 1
self:fillResult1(room, peopleNum, total_result)
else
ViewManager.ChangeView(ViewManager.View_Family)
end
end
end
function M:fillResult0(room, peopleNum, result)
local config = ExtendManager.GetExtendConfig(room.game_id)
local mode = config:GetGameInfo()
local gamePlay = mode:LoadConfigToDetail(json.encode(room.room_config.config), json.encode(room.room_config.hpData))
self._view:GetChild("Label_GamePlay").title = string.format("第%s/%s局,%s", room.curren_round,
room.room_config.round, gamePlay)
self.list_lastCard.numItems = #result.cardList
self._view:GetChild('n147').text = string.format("剩余%d张未显示", #result.cardList)
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]
local infoJiangma = result.niao
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_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
else
card:GetController('jing').selectedIndex = 0
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
else
card:GetController('jing').selectedIndex = 0
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
card.icon = "ui://Main_Majiang/b202_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
else
card:GetController('jing').selectedIndex = 0
end
end
end
end
end
local handCardItem = allCardsList:AddItemFromPool("ui://Main_Majiang/Comp_HandCard")
local handCardList = handCardItem:GetChild("list")
--手牌排序
table.sort(infoList.hand_card, self.HandCardSortAndJing)
handCardList:SetVirtual()
handCardList.itemRenderer = function(index, obj)
obj.icon = string.format("ui://Main_Majiang/%s202_%d", self:GetPrefix(), infoList.hand_card[index + 1])
if room.jing == infoList.hand_card[index + 1] then
obj:GetController('jing').selectedIndex = 1
else
obj:GetController('jing').selectedIndex = 0
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)
if infoList.seat == room.self_player.seat then
isMeCtr.selectedIndex = 1
end
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
huCardBtn.icon = string.format("ui://Main_Majiang/b202_%d", infoList.win_card)
if room.jing == infoList.win_card then
huCardBtn:GetController('jing').selectedIndex = 1
else
huCardBtn:GetController('jing').selectedIndex = 0
end
huCardBtn.visible = true
jiangMaList.visible = true
jiangMaList:SetVirtual()
jiangMaList.itemRenderer = function(index, obj)
obj.icon = string.format("ui://Main_Majiang/b202_%d", infoJiangma[index + 1].card)
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
-- jiangMaList.columnCount = #infoJiangma / 2
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
end
function M:fillResult1(room, peopleNum, total_result)
local gameNameAndRoomIDText = self._view:GetChild("Text_GameNameAndRoomID")
local familyIDText = self._view:GetChild("Text_FamilyID")
print("lingmeng fillResult1")
pt(room)
--初始化大赢家和最佳炮手
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
for i, v in pairs(DataManager.SelfUser.games) do
if v.game_id == room.game_id then
gameNameAndRoomIDText.text = string.format("%s 房号:%s", v.name, room.room_id)
end
end
if #gameNameAndRoomIDText.text <= 0 then
gameNameAndRoomIDText.text = string.format("房号:%s", room.room_id)
end
if room.group_id ~= 0 then
familyIDText.text = string.format("俱乐部:%s", room.group_id)
else
familyIDText.visible = false
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
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
end
end
function M:fillHead(url, view)
ImageLoad.Load(url, view:GetChild("Btn_Head")._iconObject)
end
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
else
obj:GetController('jing').selectedIndex = 0
end
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
local prefix
function M:GetPrefix()
-- if not prefix then
prefix = get_majiang_prefix(10)
-- end
return prefix
end
function M:SetJiangMaCallback(fct)
self._callback_jiangma = fct
end
function M:DestroyWithCallback()
if self._callback then
self._callback()
end
self:Destroy()
end
return M