yunque9/lua_probject/base_project/Game/View/ResultView.lua

496 lines
17 KiB
Lua
Raw Normal View History

2025-05-24 14:29:14 +08:00
ResultView = {}
local M = ResultView
setmetatable(M, { __index = BaseWindow })
local self = setmetatable({}, { __index = M })
2025-05-24 14:29:14 +08:00
function M:InitView()
self:InitMaPai()
self:InitMaPaiShowPanel()
2025-05-24 14:29:14 +08:00
end
function M:InitMaPaiShowPanel()
self.mapaiTypeCtr = self._view:GetController("matype")
if self.mapaiTypeCtr then
self.mapaiTypeCtr.selectedIndex = 0
end
self.mapaiTypeBgShowCtr = self._view:GetController("matypebgshow")
if self.mapaiTypeBgShowCtr then
self.mapaiTypeBgShowCtr.selectedIndex = 0
end
self.mapaiTypeShowCtr = self._view:GetController("matypeshow")
if self.mapaiTypeShowCtr then
self.mapaiTypeShowCtr.selectedIndex = 0
end
2025-05-24 14:29:14 +08:00
end
function M:InitMaPai()
self.maPaiCtr = self._view:GetController("mapai")
if self.maPaiCtr then
self.maPaiCtr.selectedIndex = 0
end
2025-05-24 14:29:14 +08:00
self.maPaiList = {}
2025-05-24 14:29:14 +08:00
for i = 1, 8 do
local tempMP = self._view:GetChild("niao" .. i)
if tempMP then
table.insert(self.maPaiList, tempMP)
end
end
2025-05-24 14:29:14 +08:00
end
function M:IsMapaiShow(niao, isShow)
if niao then
niao.visible = isShow
end
2025-05-24 14:29:14 +08:00
end
function M:SetMaPaiValue(niao, value)
if niao then
niao.icon = 'ui://Main_Majiang/' .. get_majiang_prefix(DataManager.CurrenRoom.game_id) .. "201_" .. value
end
2025-05-24 14:29:14 +08:00
end
function M:SetMaPaiColor(niao, num)
niao:GetController("color").selectedIndex = num
end
2025-05-24 14:29:14 +08:00
function M:HideAllMapai()
for i = 1, #self.maPaiList do
self:IsMapaiShow(self.maPaiList[i], false)
self:SetMaPaiColor(self.maPaiList[i], 0)
end
end
2025-05-24 14:29:14 +08:00
function M:ShowSelectMaPai(niaoList)
if niaoList and #niaoList > 0 then
self.maPaiCtr.selectedIndex = 1
self:HideAllMapai()
for i = 1, #niaoList do
self:IsMapaiShow(self.maPaiList[i], true)
self:SetMaPaiValue(self.maPaiList[i], niaoList[i].card)
if niaoList[i].score > 0 then
self:SetMaPaiColor(self.maPaiList[i], 2)
end
end
else
self.maPaiCtr.selectedIndex = 0
end
2025-05-24 14:29:14 +08:00
end
function M:init(url, isBigFull)
2025-05-24 14:29:14 +08:00
BaseWindow.init(self, url)
self:InitView()
2025-05-24 14:29:14 +08:00
local btn_share = self._view:GetChild('btn_share')
if btn_share ~= nil then
btn_share.onClick:Set(
function()
ShareScreenShotWithOption()
end
)
end
local btn_share_str = self._view:GetChild('btn_share_str')
if btn_share_str then
btn_share_str.onClick:Set(
function()
self:__ShareResultStr()
end
)
end
local btn_shareInfo = self._view:GetChild('btn_chat_room')
if btn_shareInfo then
btn_shareInfo.onClick:Set(
function()
self:__ShareResultInfo()
end
)
end
local big_result = self._view:GetChild('big_result')
if big_result ~= nil then
if isBigFull then
else
self._full = true
big_result:AddRelation(self._view, RelationType.Size)
big_result.width = self._view.width
big_result.height = self._view.height
end
2025-05-24 14:29:14 +08:00
local btn_share_copy = big_result:GetChild('btn_share_copy')
btn_share_copy.onClick:Set(
function()
big_result:GetController('share').selectedIndex = 0
self:__ShareResultStr()
end
)
local btn_share_link = big_result:GetChild('btn_share_link')
btn_share_link.onClick:Set(
function()
big_result:GetController('share').selectedIndex = 0
self:__ShareResultInfo()
end
)
local btn_share_photo = big_result:GetChild('btn_share_photo')
btn_share_photo.onClick:Set(
function()
big_result:GetController('share').selectedIndex = 0
ShareScreenShotWithOption()
end
)
local btn_result_share = big_result:GetChild('btn_result_share')
btn_result_share.onClick:Set(
function()
big_result:GetController('share').selectedIndex = 1
end
)
local btn_result_confirm = big_result:GetChild('btn_result_confirm')
btn_result_confirm.onClick:Set(
function()
self:Destroy()
ViewManager.ChangeView(ViewManager.View_Lobby)
end
)
local btn_close = big_result:GetChild('btn_close')
btn_close.onClick:Set(
function()
self:Destroy()
ViewManager.ChangeView(ViewManager.View_Lobby)
end
)
local btn_close_share = big_result:GetChild('btn_close_share')
btn_close_share.onClick:Set(
function()
big_result:GetController('share').selectedIndex = 0
end
)
end
end
-- 分享数据至聊天室需在扩展填充数据GenerateRoomResultInfo()
function M:__ShareResultInfo()
local info = self._resultInfo
local room = info.room
local cur_group = DataManager.SelfUser.cur_group
local play_name
if room.play_id and cur_group then
play_name = cur_group.curGroup:getPlayName(room.play_id)
end
ShareChatRoom(
info.room_id,
info.share_time,
info.round,
info.game_name,
info.groupId,
info.player_list,
self._root_view,
play_name
)
end
-- 生成分享到聊天室的结算数据
-- round 回合数没有就填nil
-- game_name 游戏名,如长沙麻将,仅保留必要的地名,如湘乡告胡子就可以简称告胡子
-- room_id 房间号
-- create_time 房间创建时间
-- player_list 玩家列表内含所有玩家的id和总分,如:
-- {
-- 1 = {id = 11, score = 60, house = 0, nick = "test"},
-- 2 = {id = 12, score = 61, house = 1, nick = "test2"}
-- }
function M:GenerateRoomResultInfo(round, game_name, room_id, create_time, player_list)
local result_info = {}
result_info.share_time = tostring(os.time())
result_info.create_time = create_time
result_info.round = round
result_info.game_name = game_name
result_info.room_id = room_id
result_info.player_list = player_list
result_info.groupId = DataManager.CurrenRoom.group_id or 0
result_info.room = DataManager.CurrenRoom
self._resultInfo = result_info
end
-- 分享文字
function M:__ShareResultStr()
local str = ''
local sp = ' '
local result_info = self._resultInfo
str = str .. '房间号:' .. result_info.room_id .. ' ' .. result_info.game_name .. ' ' .. result_info.round .. '\r'
-- str = str .. "玩家" .. sp .. "ID" .. sp .. "积分" .. "\r"
for i = 1, #result_info.player_list do
local p = result_info.player_list[i]
str = str .. p.nick .. sp .. p.id .. '' .. p.score .. '\r'
end
GameApplication.Instance:CopyToClipboard(str)
ViewUtil.ShowBannerOnScreenCenter('已复制战绩')
end
function M:SetGSListlineGap(linespacing)
self._gameStatisticsLineSpacing = linespacing
end
function M:InitBigResult(room, fontsize)
local big_result = self._view:GetChild('big_result')
if big_result ~= nil then
local player_list = big_result:GetChild('player_list')
player_list:RemoveChildrenToPool()
big_result:GetChild('txt_room_id').text = '房号:' .. self._resultInfo.room_id
big_result:GetChild('txt_game_name').text = self._resultInfo.game_name
big_result:GetChild('txt_game_data').text = os.date('%Y-%m-%d %H:%M', os.time())
2025-05-29 15:23:52 +08:00
2025-05-24 14:29:14 +08:00
local str_roominfo = string.gsub(room.room_config:GetDes(), '\r', '')
big_result:GetChild('txt_play').text = str_roominfo
if room.hpOnOff == 1 and room.score_times ~= 1 then
big_result:GetChild('txt_time').text = '倍数:' .. tostring(room.score_times)
big_result:GetController('time').selectedIndex = 1
end
local maxScore = 0
local isWin = false
local flag_new = big_result:GetChild('flag_tempNew')
2025-05-24 14:29:14 +08:00
for i = 1, #self._resultInfo.player_list do
local player_info = self._resultInfo.player_list[i]
local total_score = room:GetTotalScore(player_info.score)
local hp_nonnegative = room:checkHpNonnegative()
player_info.total_score = 0
if hp_nonnegative then
local hp_info = player_info.hp_info
player_info.total_score = d2ad(hp_info.total_hp)
else
player_info.total_score = total_score
end
if player_info.score > maxScore then
maxScore = player_info.score
end
if player_info.id == room.self_player.self_user.account_id then
if player_info.total_score >= 0 then
isWin = true
end
end
end
if isWin then
big_result:GetController('result').selectedIndex = 1
else
big_result:GetController('result').selectedIndex = 0
end
for i = 1, #self._resultInfo.player_list do
local player_info = self._resultInfo.player_list[i]
local item2
if player_info.id == room.self_player.self_user.account_id then
if isWin then
item2 = big_result:GetChild('play_win')
else
item2 = big_result:GetChild('play_lose')
end
else
if not isWin then
item2 = big_result:GetChild('play_win')
else
item2 = big_result:GetChild('play_lose')
end
end
2025-05-24 14:29:14 +08:00
local item = player_list:AddItemFromPool()
item:GetChild('txt_name').text = player_info.nick
item2:GetChild('txt_name').text = player_info.nick
item2:GetChild('txt_id').text = player_info.id
2025-05-24 14:29:14 +08:00
local head = item:GetChild('head'):GetChild('n4')
ImageLoad.Load(player_info.head_url, head)
local head = item2:GetChild('head'):GetChild('n4')
ImageLoad.Load(player_info.head_url, head)
2025-05-24 14:29:14 +08:00
if player_info.entrust ~= nil and player_info.entrust == true then
item:GetController('entrust').selectedIndex = 1
else
item:GetController('entrust').selectedIndex = 0
end
if player_info.hp_info ~= nil and player_info.hp_info.cur_hp ~= nil then
item:GetChild('txt_reserve_hp').text = '积分:' .. tostring(d2ad(player_info.hp_info.cur_hp))
end
if player_info.total_score ~= nil then
if tostring(player_info.score) == tostring(maxScore) and player_info.score > 0 then
item:GetController('big_win').selectedIndex = 1
else
item:GetController('big_win').selectedIndex = 0
end
if player_info.total_score >= 0 then
item:GetController('pn').selectedIndex = 1
item:GetChild('txt_positive').text = '+' .. tostring(player_info.total_score)
item2:GetChild('txt_navigate').text = string.format("总战绩:+%s", player_info.total_score)
item2:GetChild('txt_daniao').text = string.format("打鸟 +%s", player_info.daniao)
item2:GetChild('text_zongjifen').text = player_info.total_score - player_info.daniao
2025-05-24 14:29:14 +08:00
else
item:GetController('pn').selectedIndex = 0
item:GetChild('txt_navigate').text = tostring(player_info.total_score)
item2:GetChild('txt_navigate').text = string.format("总战绩:%s", player_info.total_score)
item2:GetChild('txt_daniao').text = string.format("打鸟 %s", player_info.daniao)
item2:GetChild('text_zongjifen').text = player_info.total_score - player_info.daniao
2025-05-24 14:29:14 +08:00
end
end
player_info.score = room:GetTotalScore(player_info.score)
local list_param = item:GetChild('list_param')
list_param:RemoveChildrenToPool()
if self._gameStatisticsLineSpacing ~= nil then
list_param.lineGap = self._gameStatisticsLineSpacing
end
if player_info.param ~= nil then
local big = false
if #player_info.param <= 4 then
big = true
end
for i = 1, #player_info.param do
local pitem = list_param:AddItemFromPool()
pitem:GetChild('txt_key').text = player_info.param[i].key
pitem:GetChild('txt_value').text = player_info.param[i].value
if fontsize ~= nil and fontsize > 0 then
pitem:GetChild('txt_key').textFormat.size = fontsize
pitem:GetChild('txt_value').textFormat.size = fontsize
else
if big then
pitem:GetChild('txt_key').textFormat.size = 30
pitem:GetChild('txt_value').textFormat.size = 30
else
pitem:GetChild('txt_key').textFormat.size = 24
pitem:GetChild('txt_value').textFormat.size = 24
end
end
end
end
local list_param = item2:GetChild('list_param')
list_param:RemoveChildrenToPool()
if self._gameStatisticsLineSpacing ~= nil then
list_param.lineGap = self._gameStatisticsLineSpacing
end
if player_info.param ~= nil then
local big = false
if #player_info.param <= 4 then
big = true
end
for i = 1, #player_info.param do
local pitem = list_param:AddItemFromPool()
pitem:GetChild('txt_key').text = player_info.param[i].key
pitem:GetChild('txt_value').text = player_info.param[i].value
if fontsize ~= nil and fontsize > 0 then
pitem:GetChild('txt_key').textFormat.size = fontsize
pitem:GetChild('txt_value').textFormat.size = fontsize
else
if big then
pitem:GetChild('txt_key').textFormat.size = 30
pitem:GetChild('txt_value').textFormat.size = 30
2025-05-24 14:29:14 +08:00
else
pitem:GetChild('txt_key').textFormat.size = 24
pitem:GetChild('txt_value').textFormat.size = 24
2025-05-24 14:29:14 +08:00
end
end
end
end
local flag = item:GetChild('flag')
flag:RemoveChildrenToPool()
if player_info.flag ~= nil and #player_info.flag > 0 then
for i = 1, #player_info.flag do
local pitem = flag:AddItemFromPool()
pitem:GetChild('txt_name').text = player_info.flag[i]
end
item:GetController('have_flag').selectedIndex = 1
else
item:GetController('have_flag').selectedIndex = 0
end
if player_info.id == room.self_player.self_user.account_id then
item:GetController('self').selectedIndex = 1
else
item:GetController('self').selectedIndex = 0
end
end
local btn_continue_game = big_result:GetChild('btn_continue_game')
if btn_continue_game then
local gid = room.group_id
if gid ~= 0 then
btn_continue_game.visible = true
local pid = room.room_config.pid
local game_id = room.game_id
btn_continue_game.onClick:Set(
function()
self:ContinueGame(gid, pid, game_id)
end
)
end
end
end
end
-- 继续游戏
function M:ContinueGame(gid, pid, game_id)
ViewUtil.ShowModalWait(self._root_view, nil, 'join_room')
local roomCtr = ControllerManager.GetController(RoomController)
roomCtr:PublicJoinRoom(
Protocol.WEB_FG_MATCH_ROOM,
"",
false,
function(response)
if (response.ReturnCode == -1) then
ViewUtil.CloseModalWait('join_room')
RestartGame()
return
end
if response.ReturnCode ~= 0 then
ViewUtil.ErrorMsg(self._root_view, response.ReturnCode, '进入房间失败')
ViewUtil.CloseModalWait("join_room")
self:Destroy()
ViewManager.ChangeView(ViewManager.View_Lobby)
return
else
ViewManager.ChangeView(ViewManager.View_Main, game_id)
ViewUtil.CloseModalWait('join_room')
end
end,
gid,
pid
)
end