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

343 lines
12 KiB
Lua
Raw Normal View History

2025-05-24 14:29:14 +08:00
local TimeSettingPanel = import(".TimeSettingPanel")
-- 开桌统计
local GroupMngPersonStatView = {}
local M = GroupMngPersonStatView
function GroupMngPersonStatView.new(gid)
local self = M
self.class = "GroupMngPersonStatView"
self.group_id = gid
self:InitView()
return self
end
function M:initData()
self.lst_record.numItems = 0
self.record_data = {}
self._view:GetController("record").selectedIndex = 0
self:GetRecordData(0)
end
function M:InitView()
self._view = UIPackage.CreateObjectFromURL("ui://NewGroup/View_GroupPersonStat")
self.lst_record = self._view:GetChild("lst_record")
self.lst_record:SetVirtual()
self.lst_record.itemRenderer = function(index, obj)
self:OnRenderRecordItem(index, obj)
end
self.lst_record.scrollPane.onPullUpRelease:Set(function()
self:GetRecordData(self.lst_record.numItems)
end)
self.time_panel = TimeSettingPanel.new(self._view, self._view:GetChild("btn_date1"), self._view:GetChild("btn_date2"), -308, 0)
self.begin_time, self.end_time = self.time_panel:GetDate()
local ctr_page = self._view:GetController("type")
ctr_page.onChanged:Set(function()
self.record_data = {}
self.lst_record.numItems = 0
self.begin_time = nil
self.end_time = nil
self:GetRecordData(0)
end)
self._view:GetChild("btn_search").onClick:Set(function()
self.record_data = {}
self.lst_record.numItems = 0
self.begin_time, self.end_time = self.time_panel:GetDate()
self:GetRecordData(0)
end)
end
function M:GetRecordData(index)
ViewUtil.ShowModalWait()
local time_type = self._view:GetController("type").selectedIndex
if self.begin_time ~= nil and self.end_time ~= nil then
time_type = 3
end
local fgCtr = ControllerManager.GetController(NewGroupController)
fgCtr:FG_GetGroupPersonRecord(self.group_id, GetPlatform(), DataManager.SelfUser.account_id, time_type, self.begin_time, self.end_time, index, 6, function(res)
if self._is_destroy then
return
end
ViewUtil.CloseModalWait()
if res.ReturnCode ~= 0 then
ViewUtil.ErrorTip(res.ReturnCode, "获取回放数据失败")
else
local records = res.Data.records
for i = 1, #records do
self.record_data[#self.record_data + 1] = records[i]
end
self.lst_record.numItems = #self.record_data
printlog("ccccccccccccccccccccccccccccccccccc2222223333333333333333333333333333333",res.Data.total_round," ",res.Data.valid_round)
pt(res.Data)
if index == 0 then
--self._view:GetChild("tex_num1").text = ""..res.Data.total
--self._view:GetChild("tex_num3").text = ""..d2ad(res.Data.consume)
self._view:GetChild("tex_winner_count").text = res.Data.total_round
self._view:GetChild("tex_valid_count").text = res.Data.valid_round / 100
self._view:GetChild("tex_total_proportion").text = d2ad(res.Data.total_win)
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
local time =tonumber(create_time)
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
local play_name = DataManager.groups:get(self.group_id):getPlayName(data.groupPid)
obj:GetChild("tex_time").text = room_time_str
obj:GetChild("tex_roomid").text = room_id
obj:GetChild("tex_times").text = d2ad(data.hp_times)..""
obj:GetChild("tex_game").text = play_name
local lst_total = obj:GetChild("lst_total")
lst_total:RemoveChildrenToPool()
local ids = {}
for j=1,#totalScore do
local titem = lst_total:AddItemFromPool()
local trdata = totalScore[j]
titem:GetChild("tex_name").text = ViewUtil.stringEllipsis(trdata.nick)
titem:GetChild("tex_id").text = "ID:"..trdata.accId
table.insert( ids, trdata.accId )
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
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)
end)
obj:GetChild("btn_share").onClick:Set(function()
ShareChatRoom(room_id, tostring(os.time()), data.round, room_type_str, self.group_id, player_list)
end)
obj.onClick:Set(function()
self:OnShowRecordInfo(data,ids)
end)
end
function M:OnRenderRecordItem(index, obj)
local data = self.record_data[index + 1]
self:FillRecordItem(data, obj)
end
function M:OnShareScreenShot(room_id, room_type_str, room_time_str, totalScore, hpOnOff, hpType)
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 = ViewUtil.stringEllipsis(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
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)
else
load_head_num = load_head_num - 1
end
end
coroutine.start(function ( ... )
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
function M:OnShowRecordInfo(rdata,ids)
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
for i = 1,round_count do
local item = lst_recordInfo:AddItemFromPool()
item:GetChild("tex_num").text = tostring(i)
local play_name = DataManager.groups:get(self.group_id):getPlayName(rdata.groupPid)
item:GetChild("tex_game").text = play_name
item:GetChild("tex_roomid").text = rdata.room_id
item:GetChild("tex_times").text = d2ad(rdata.hp_times)..""
local round_score_str = rdata["round_"..i]
local round_score_item = json.decode(round_score_str)
local lst_total = item:GetChild("lst_total")
lst_total:RemoveChildrenToPool()
for k=1,#round_score_item do
local titem = lst_total:AddItemFromPool()
local trdata = round_score_item[k]
titem:GetChild("tex_name").text = ViewUtil.stringEllipsis(trdata.nick)
titem:GetChild("tex_id").text = "ID:".. ids[k]
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
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
local btn_play =item:GetChild("btn_play")
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
local room = ExtendManager.GetExtendConfig(game_id):NewRoom()
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
room.self_player = room:GetPlayerBySeat(1)
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)
loddyCtr1:RequestPlayBack(_data,function(code,data)
ViewUtil.CloseModalWait()
if code == 0 then
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
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, ...)
local tem =nil
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
local arg = {...}
tem = dview_class.new(...)
tem.Id = id
tem:Show()
return tem
end
return M