changhong_newclient/lua_probject/base_project/Game/View/NewGroup/GroupFastGamesView.lua

124 lines
3.4 KiB
Lua
Raw Normal View History

2025-06-30 08:39:00 +08:00
-- 能量包
local GroupFastGamesView = {}
local M = GroupFastGamesView
function GroupFastGamesView.new(gid, blur_view, playIdList)
setmetatable(M, { __index = BaseWindow })
local self = setmetatable({}, { __index = M })
2025-06-30 08:39:00 +08:00
self.class = "GroupFastGamesView"
self._close_destroy = true
self.group_id = gid
self.blur_view = blur_view
self.playIdList = playIdList
self.allplays_data = {}
self.uid = DataManager.SelfUser.account_id
self.showid = 0
self:init("ui://NewGroup/Win_SelectGames")
self:FillView()
return self
end
2025-06-30 08:39:00 +08:00
function M:FillView()
--lst_allplays
self.showid = Utils.LoadLocalFile("selectplay" .. self.uid)
self.lst_allplays = self._view:GetChild("lst_allplays")
2025-06-30 08:39:00 +08:00
self.lst_allplays:SetVirtual()
self.lst_allplays.itemRenderer = function(index, obj)
self:OnRenderAllPlaysItem(index, obj, self.showid)
2025-06-30 08:39:00 +08:00
end
self:GetFlagPlaysData(self.showid)
2025-06-30 08:39:00 +08:00
end
-- 获取快速开始设置数据
function M:GetFlagPlaysData(showid)
local allplays = self.playIdList
self.allplays_data = allplays
table.sort(self.allplays_data, handler(self, self.SortPlayList))
-- local tmp = {}
-- for i = 1, #allplays do
-- if showid == allplays[i].id .. "" then
-- tmp = self.allplays_data[1]
-- self.allplays_data[1] = self.allplays_data[i]
-- self.allplays_data[i] = tmp
-- end
-- end
self.lst_allplays.numItems = #self.allplays_data
2025-06-30 08:39:00 +08:00
end
function M:OnRenderAllPlaysItem(index, obj, showid)
local data = self.allplays_data[index + 1]
local exconfig = ExtendManager.GetExtendConfig(data.gameId)
local datajson = json.decode(data.config)
local r = {}
2025-06-30 08:39:00 +08:00
exconfig:FillRoomConfig(r, datajson)
local gameStr = ""
gameStr = string.gsub(r.room_config:GetDes(), "\r", "")
obj:GetChild("tex_name").text = data.name
obj:GetChild("tex_display").text = gameStr
if showid ~= nil then
if data.id .. "" == showid then
obj:GetChild("gxbtn").selected = true
else
obj:GetChild("gxbtn").selected = false
end
end
obj:GetChild("gxbtn").onClick:Set(function()
self:SelectPlaysItem(data.id, index + 1, data.name)
end)
--obj:GetChild("gxbtn").selected =
2025-06-30 08:39:00 +08:00
end
function M:SelectPlaysItem(id, index, gamename)
self.lst_allplays = self._view:GetChild("lst_allplays")
Utils.SaveLocalFile("selectplay" .. self.uid, id)
Utils.SaveLocalFile("selectplayname" .. self.uid, gamename)
for key, value in pairs(self.playIdList) do
if key == index then
self.playIdList[index].show = true
else
self.playIdList[key].show = false
end
end
self:FillView()
if self.callback then
self.callback()
end
self:Destroy()
2025-06-30 08:39:00 +08:00
end
function M:SetCallback(callback)
self.callback = callback
end
function M:SortPlayList(a, b)
local a_play = a
local b_play = b
if a_play.gameType == b_play.gameType then
if a_play.gameId == a_play.gameId then
return a_play.id > b_play.id
else
return a_play.gameId > b_play.gameId
end
else
return a_play.gameType > b_play.gameType
end
2025-06-30 08:39:00 +08:00
end
-- 销毁窗口
function M:Destroy(remove_map)
-- if self.callback then
-- self.callback()
-- end
BaseWindow.Destroy(self, remove_map)
ImageLoad.Clear(self.class)
2025-06-30 08:39:00 +08:00
end
return M