changhong/lua_probject/base_project/Game/View/NewGroup/MngView/GroupMngRoomStatView.lua

397 lines
14 KiB
Lua
Raw Normal View History

2025-05-24 14:29:14 +08:00
-- 开桌统计
local GroupMngRoomStatView = {}
local M = GroupMngRoomStatView
function GroupMngRoomStatView.new(gid)
local self = M
self.class = "GroupMngRoomStatView"
self.group_id = gid
self:InitView()
return self
end
function M:initData()
self.lst_record.numItems = 0
self.record_data = {}
self.lst_player_record.numItems = 0
self.player_record_data = {}
self.qid = 0
self._view:GetController("search").selectedIndex = 0
self._view:GetController("record").selectedIndex = 0
self._view:GetChild("tex_id").text = ""
self:GetRecordData(0, self.qid)
end
function M:InitView()
self._view = UIPackage.CreateObjectFromURL("ui://NewGroup/View_GroupStat")
2025-06-21 22:58:29 +08:00
self.record_data = {} --回放数据
2025-05-24 14:29:14 +08:00
self.player_record_data = {} --指定玩家的回放数据
2025-06-21 22:58:29 +08:00
self.qid = 0 --查询玩家id
2025-05-24 14:29:14 +08:00
2025-06-21 22:58:29 +08:00
self.lst_record_find = self._view:GetChild("lst_record_find")
self.lst_record_find:SetVirtual()
2025-05-24 14:29:14 +08:00
self.lst_record_find.itemRenderer = function(index, obj)
self:OnRenderRecordItem1(index, obj)
end
self.lst_record = self._view:GetChild("lst_record")
2025-06-21 22:58:29 +08:00
self.lst_record:SetVirtual()
2025-05-24 14:29:14 +08:00
self.lst_record.itemRenderer = function(index, obj)
self:OnRenderRecordItem(index, obj)
end
self.lst_record.scrollPane.onPullUpRelease:Set(function()
2025-06-21 22:58:29 +08:00
self:GetRecordData(self.lst_record.numItems)
2025-05-24 14:29:14 +08:00
end)
self.lst_player_record = self._view:GetChild("lst_player_record")
2025-06-21 22:58:29 +08:00
self.lst_player_record:SetVirtual()
2025-05-24 14:29:14 +08:00
self.lst_player_record.itemRenderer = function(index, obj)
self:OnRenderPlayerRecordItem(index, obj)
end
self.lst_player_record.scrollPane.onPullUpRelease:Set(function()
2025-06-21 22:58:29 +08:00
self:GetRecordData(self.lst_player_record.numItems, self.qid)
2025-05-24 14:29:14 +08:00
end)
self._view:GetChild("btn_search").onClick:Set(function()
local qid = self._view:GetChild("tex_id").text
local rtype = self._view:GetChild("cb_type").value
if (qid == "" and rtype == "1") or (string.len(qid) < 6 and rtype == "2") then
ViewUtil.ErrorTip(nil, "请输入正确的ID")
return
end
if rtype == "1" then
self.lst_player_record.numItems = 0
self.player_record_data = {}
self.qid = tonumber(qid)
self:GetRecordData(0, self.qid)
else
self:GetRecordByRoomid()
end
end)
self._view:GetChild("btn_search_back").onClick:Set(function()
self.qid = 0
self.player_record_data = {}
self.lst_player_record.numItems = 0
2025-06-21 22:58:29 +08:00
self.isFindCode = false
2025-05-24 14:29:14 +08:00
end)
end
function M:GetRecordData(index, qid)
qid = qid or 0
ViewUtil.ShowModalWait()
local fgCtr = ControllerManager.GetController(NewGroupController)
fgCtr:FG_GetGroupRecord(self.group_id, GetPlatform(), qid, index, 6, function(res)
printlog("ccccccccccccccccccccccccccccccccccccc")
pt(res)
if self._is_destroy then
return
end
ViewUtil.CloseModalWait()
2025-06-21 22:58:29 +08:00
if res.ReturnCode ~= 0 then
2025-05-24 14:29:14 +08:00
ViewUtil.ErrorTip(res.ReturnCode, "获取回放数据失败")
else
local ctr_search = self._view:GetController("search")
local records = res.Data.records
if qid == 0 then
for i = 1, #records do
self.record_data[#self.record_data + 1] = records[i]
end
self.lst_record.numItems = #self.record_data
if ctr_search.selectedIndex ~= 0 then
ctr_search.selectedIndex = 0
end
else
for i = 1, #records do
self.player_record_data[#self.player_record_data + 1] = records[i]
end
self.lst_player_record.numItems = #self.player_record_data
ctr_search.selectedIndex = 2
end
end
end)
end
function M:FillRecordItem(data, obj)
local game_id = data.game_id
local room_id = data.room_id
local create_time = data.create_time
local room_type_str = data.game_info.name
2025-06-21 22:58:29 +08:00
local time = tonumber(create_time)
2025-05-24 14:29:14 +08:00
local room_time_str = os.date("%Y-%m-%d %H:%M:%S", time)
local totalScore = json.decode(data.totalScore)
local hpOnOff = data.hpOnOff
local hpType = data.game_info.hpType
local player_list = {}
for i = 1, #totalScore do
local p = totalScore[i]
player_list[i] = {}
player_list[i].id = p.accId
local score = p.score
if hpOnOff == 1 and hpType > 1 then
score = score / 10
end
player_list[i].score = score
player_list[i].house = 0
player_list[i].nick = p.nick
end
2025-06-21 22:58:29 +08:00
local play_name = DataManager.groups:get(self.group_id):getPlayName(data.groupPid)
2025-05-24 14:29:14 +08:00
obj:GetChild("tex_time").text = room_time_str
2025-06-21 22:58:29 +08:00
obj:GetChild("tex_roomid").text = room_id
obj:GetChild("tex_times").text = d2ad(data.hp_times) .. ""
2025-05-24 14:29:14 +08:00
obj:GetChild("tex_game").text = play_name
local lst_total = obj:GetChild("lst_total")
lst_total:RemoveChildrenToPool()
local ids = {}
2025-06-21 22:58:29 +08:00
for j = 1, #totalScore do
2025-05-24 14:29:14 +08:00
local titem = lst_total:AddItemFromPool()
local trdata = totalScore[j]
titem:GetChild("tex_name").text = ViewUtil.stringEllipsis(trdata.nick)
2025-06-21 22:58:29 +08:00
titem:GetChild("tex_id").text = trdata.accId and ("ID:" .. trdata.accId) or ""
table.insert(ids, trdata.accId)
2025-05-24 14:29:14 +08:00
local score = trdata.score
if trdata.hp == nil then
if hpOnOff == 1 and hpType > 1 then
score = score / 10
end
else
score = d2ad(trdata.hp)
end
2025-06-21 22:58:29 +08:00
2025-05-24 14:29:14 +08:00
titem:GetChild("tex_score").text = score
if score >= 0 then
titem:GetController("num_color").selectedIndex = 0
else
titem:GetController("num_color").selectedIndex = 1
end
end
if #totalScore >= 6 then
obj:GetController("person_num").selectedIndex = 1
else
obj:GetController("person_num").selectedIndex = 0
end
obj:GetChild("btn_screenshot").onClick:Set(function()
self:OnShareScreenShot(room_id, room_type_str, room_time_str, totalScore, hpOnOff, hpType)
2025-06-21 22:58:29 +08:00
end)
2025-05-24 14:29:14 +08:00
obj:GetChild("btn_share").onClick:Set(function()
ShareChatRoom(room_id, tostring(os.time()), data.round, room_type_str, self.group_id, player_list)
2025-06-21 22:58:29 +08:00
end)
2025-05-24 14:29:14 +08:00
obj.onClick:Set(function()
2025-06-21 22:58:29 +08:00
self:OnShowRecordInfo(data, ids)
end)
2025-05-24 14:29:14 +08:00
end
function M:OnRenderRecordItem(index, obj)
2025-06-21 22:58:29 +08:00
local data = self.record_data[index + 1]
data.seat = 2 - (index + 1) % 2
self:FillRecordItem(data, obj)
2025-05-24 14:29:14 +08:00
end
function M:OnRenderRecordItem1(index, obj)
2025-06-21 22:58:29 +08:00
local data = self.tempRec[index + 1]
self:FillRecordItem(data, obj)
2025-05-24 14:29:14 +08:00
end
function M:OnRenderPlayerRecordItem(index, obj)
local data = self.player_record_data[index + 1]
self:FillRecordItem(data, obj)
end
function M:GetRecordByRoomid()
local qid = self._view:GetChild("tex_id").text
ViewUtil.ShowModalWait()
local fgCtr = ControllerManager.GetController(NewGroupController)
fgCtr:FG_GetRecordByRoomid(self.group_id, qid, GetPlatform(), function(res)
if self._is_destroy then
return
end
ViewUtil.CloseModalWait()
2025-06-21 22:58:29 +08:00
if res.ReturnCode ~= 0 then
2025-05-24 14:29:14 +08:00
ViewUtil.ErrorTip(res.ReturnCode, "获取回放数据失败")
else
if not res.Data.is_rec then
ViewUtil.ErrorTip(nil, "没有找到回放")
return
end
2025-06-21 22:58:29 +08:00
self.tempRec = res.Data.rec
self.lst_record_find.numItems = #res.Data.rec
2025-05-24 14:29:14 +08:00
self._view:GetController("search").selectedIndex = 1
end
end)
end
2025-06-21 22:58:29 +08:00
function M:OnShareScreenShot(room_id, room_type_str, room_time_str, totalScore, hpOnOff, hpType)
2025-05-24 14:29:14 +08:00
ViewUtil.ShowModalWait(self._view, "正在分享...")
UIPackage.AddPackage("base/rank/ui/Rank")
local result_view = UIPackage.CreateObjectFromURL("ui://Rank/ResultView")
result_view.visible = false
self._view:AddChild(result_view)
result_view.x = -308
result_view.y = -47
result_view:GetChild("tex_roomnum").text = "房间号:" .. room_id .. " " .. room_type_str
result_view:GetChild("tex_data").text = room_time_str
result_view:GetChild("btn_confirm").onClick:Set(function() result_view:Dispose() end)
local lst_p = result_view:GetChild("list_result")
local load_head_num = #totalScore
for j = 1, #totalScore do
local p = totalScore[j]
local item = lst_p:AddItemFromPool()
item:GetChild("name").text = p.nick
local score = p.score
if hpOnOff == 1 and hpType > 1 then
score = score / 10
end
item:GetChild("score").text = score
if score < 0 then item:GetController("di").selectedIndex = 1 end
2025-06-21 22:58:29 +08:00
if p.portrait and p.portrait ~= "" then
ImageLoad.Load(p.portrait, item:GetChild("n9")._iconObject, self.class, function(...)
load_head_num = load_head_num - 1
end)
2025-05-24 14:29:14 +08:00
else
load_head_num = load_head_num - 1
end
end
2025-06-21 22:58:29 +08:00
coroutine.start(function(...)
2025-05-24 14:29:14 +08:00
local left_time = 4
while (true) do
if load_head_num == 0 or left_time == 0 then
result_view.visible = true
coroutine.wait(0.2)
ShareScreenShotWithOption(function()
result_view:Dispose()
end)
ViewUtil.CloseModalWait()
break
end
coroutine.wait(1)
left_time = left_time - 1
end
end)
end
2025-06-21 22:58:29 +08:00
function M:OnShowRecordInfo(rdata, ids)
2025-05-24 14:29:14 +08:00
local ctr_record = self._view:GetController("record")
ctr_record.selectedIndex = 1
local lst_recordInfo = self._view:GetChild("lst_recordInfo")
lst_recordInfo:RemoveChildrenToPool()
-- lst_recordInfo.scrollPane.currentPageX = 0
local round_count = tonumber(rdata.round)
local game_id = rdata.game_info.game_id
local playback_id = rdata.military_id
local hpOnOff = rdata.hpOnOff
local hpType = rdata.game_info.hpType
local play_name = DataManager.groups:get(self.group_id):getPlayName(rdata.groupPid)
2025-06-21 22:58:29 +08:00
for i = 1, round_count do
2025-05-24 14:29:14 +08:00
local item = lst_recordInfo:AddItemFromPool()
item:GetChild("tex_num").text = tostring(i)
item:GetChild("tex_game").text = play_name
2025-06-21 22:58:29 +08:00
item:GetChild("tex_times").text = d2ad(rdata.hp_times) .. ""
item:GetChild("tex_roomid").text = rdata.room_id
local round_score_str = rdata["round_" .. i]
2025-05-24 14:29:14 +08:00
local round_score_item = json.decode(round_score_str)
local lst_total = item:GetChild("lst_total")
lst_total:RemoveChildrenToPool()
2025-06-21 22:58:29 +08:00
for k = 1, #round_score_item do
2025-05-24 14:29:14 +08:00
local titem = lst_total:AddItemFromPool()
local trdata = round_score_item[k]
titem:GetChild("tex_name").text = ViewUtil.stringEllipsis(trdata.nick)
2025-06-21 22:58:29 +08:00
titem:GetChild("tex_id").text = "ID:" .. ids[k]
2025-05-24 14:29:14 +08:00
local score = trdata.score
if trdata.hp == nil then
if hpOnOff == 1 and hpType > 1 then
score = score / 10
end
else
score = d2ad(trdata.hp)
end
2025-06-21 22:58:29 +08:00
2025-05-24 14:29:14 +08:00
titem:GetChild("tex_score").text = score
end
if #round_score_item >= 6 then
item:GetController("person_num").selectedIndex = 1
else
item:GetController("person_num").selectedIndex = 0
end
2025-06-21 22:58:29 +08:00
local btn_play = item:GetChild("btn_play")
2025-05-24 14:29:14 +08:00
btn_play.onClick:Set(function()
local group = DataManager.groups:get(self.group_id)
if DataManager.SelfUser.playback[playback_id] ~= nil and DataManager.SelfUser.playback[playback_id][i] ~= nil then
2025-06-21 22:58:29 +08:00
local room = ExtendManager.GetExtendConfig(game_id):NewRoom()
2025-05-24 14:29:14 +08:00
DataManager.CurrenRoom = room
room.lev = group.lev
room.game_id = game_id
local extend = ExtendManager.GetExtendConfig(game_id)
extend:FillPlayBackData(DataManager.SelfUser.playback[playback_id][i])
if not room.self_player then
2025-06-21 22:58:29 +08:00
room.self_player = room:GetPlayerBySeat(rdata.seat)
2025-05-24 14:29:14 +08:00
end
local main = self:GenaratePlayBack(ViewManager.View_PlayBack, game_id)
main._currentId = playback_id
main._currentRound = i
main._totalRound = tonumber(rdata.round)
main:FillRoomData(DataManager.SelfUser.playback[playback_id][i])
else
ViewUtil.ShowModalWait(self._view)
local _data = {}
_data["military_id"] = playback_id
_data["round"] = tostring(i)
local loddyCtr1 = ControllerManager.GetController(LoddyController)
2025-06-21 22:58:29 +08:00
loddyCtr1:RequestPlayBack(_data, function(code, data)
2025-05-24 14:29:14 +08:00
ViewUtil.CloseModalWait()
if code == 0 then
2025-06-21 22:58:29 +08:00
if group.lev == 1 then
DataManager.CurrenRoom.self_player = DataManager.CurrenRoom:GetPlayerBySeat(rdata.seat)
2025-05-24 14:29:14 +08:00
end
2025-06-21 22:58:29 +08:00
-- if DataManager.SelfUser.playback[playback_id] ~= nil then
-- DataManager.SelfUser.playback[playback_id][i] = data
-- else
-- local playback_data = {}
-- playback_data[i] = data
-- DataManager.SelfUser.playback[playback_id] = playback_data
-- end
2025-05-24 14:29:14 +08:00
local main = self:GenaratePlayBack(ViewManager.View_PlayBack, game_id)
main._currentId = playback_id
main._currentRound = i
main._totalRound = tonumber(rdata.round)
main:FillRoomData(data)
main._room.lev = group.lev
elseif code == 25 then
ViewUtil.ErrorTip(-1, "回放未找到!")
-- btn_play_back.grayed = true
end
end, rdata.game_info)
end
end)
end
end
function M:GenaratePlayBack(id, game_id, ...)
2025-06-21 22:58:29 +08:00
local tem = nil
2025-05-24 14:29:14 +08:00
local dview_class = nil
if not dview_class then
local exconfig = ExtendManager.GetExtendConfig(game_id)
dview_class = exconfig:GetView(id)
end
if not dview_class then
return
end
2025-06-21 22:58:29 +08:00
local arg = { ... }
2025-05-24 14:29:14 +08:00
tem = dview_class.new(...)
tem.Id = id
tem:Show()
return tem
end
2025-06-21 22:58:29 +08:00
return M