hengyang_client/lua_probject/base_project/Game/View/NewGroup/GroupSetDefaultGameView.lua

110 lines
2.8 KiB
Lua
Raw Permalink Normal View History

2025-04-01 10:48:36 +08:00
-- 牌友圈默认玩法设置界面
local GroupSetDefaultGameView = {}
local M = GroupSetDefaultGameView
2025-11-06 17:37:53 +08:00
function GroupSetDefaultGameView.new(gid, blur_view, callback)
setmetatable(M, { __index = BaseWindow })
local self = setmetatable({}, { __index = M })
self.class = "GroupSetDefaultGameView"
self._close_destroy = true
2025-04-01 10:48:36 +08:00
self.group_id = gid
2025-11-06 17:37:53 +08:00
self._blur_view = blur_view
self._callback = callback
local url = "ui://NewGroup/Win_SetDefaultGame"
self:init(url)
return self
2025-04-01 10:48:36 +08:00
end
function M:init(url)
2025-11-06 17:37:53 +08:00
BaseWindow.init(self, url)
2025-04-01 10:48:36 +08:00
end
2025-11-06 17:37:53 +08:00
function M:FillData(list, index, callbackFill)
self.callbackFill = callbackFill
self._index = index
local lst_game = self._view:GetChild("lst_game")
lst_game:RemoveChildrenToPool()
local playName = "playfaconfig" .. self.group_id
2025-04-01 10:48:36 +08:00
local json_data = Utils.LoadLocalFile(playName)
2025-11-06 17:37:53 +08:00
local localDataPlay = nil
if json_data then
2025-04-01 10:48:36 +08:00
localDataPlay = json.decode(json_data)
end
2025-11-06 17:37:53 +08:00
for i = 1, #list do
local tem = list[i]
local item = lst_game:AddItemFromPool()
item.title = tem.name
item.selected = index == i
2025-04-01 10:48:36 +08:00
local group = DataManager.groups:get(self.group_id)
2025-11-06 17:37:53 +08:00
local MarkSelect = item:GetChild("btn_select")
2025-04-01 10:48:36 +08:00
--if group.lev==1 then
-- MarkSelect.visible=true
--else
-- MarkSelect.visible=false
--end
2025-11-06 17:37:53 +08:00
MarkSelect.visible = true
if localDataPlay and localDataPlay[tostring(tem.id)] then
MarkSelect.selected = localDataPlay[tostring(tem.id)]
2025-04-01 10:48:36 +08:00
else
2025-11-06 17:37:53 +08:00
MarkSelect.selected = false
2025-04-01 10:48:36 +08:00
end
2025-11-06 17:37:53 +08:00
2025-04-01 10:48:36 +08:00
MarkSelect.onClick:Set(function()
2025-11-06 17:37:53 +08:00
self:MarkPlay(MarkSelect, tem.id, MarkSelect.selected)
2025-04-01 10:48:36 +08:00
end)
2025-11-06 17:37:53 +08:00
end
local btn_confirm = self._view:GetChild("btn_confirm")
btn_confirm.onClick:Set(function()
if self._callback then
self._callback(lst_game.selectedIndex + 1)
end
self:Destroy()
end)
2025-04-01 10:48:36 +08:00
end
2025-11-06 17:37:53 +08:00
function M:MarkPlay(markS, pid, isMark)
2025-04-01 10:48:36 +08:00
--[[local fgCtr = ControllerManager.GetController(NewGroupController)
2025-11-06 17:37:53 +08:00
ViewUtil.ShowModalWait2()
2025-04-01 10:48:36 +08:00
fgCtr:FG_MarkPlay(self.group_id, pid, isMark, function(res)
if self._is_destroy then
return
end
2025-11-06 17:37:53 +08:00
ViewUtil.CloseModalWait2()
2025-04-01 10:48:36 +08:00
if res.ReturnCode == 0 then
local group = DataManager.groups:get(self.group_id)
group:markPlay(pid, isMark)
if self.callbackFill then
self.callbackFill()
end
else
markS.selected=not isMark
ViewUtil.ErrorTip(res.ReturnCode,"设置失败,或已达设置上限")
end
end)--]]
2025-11-06 17:37:53 +08:00
if DataManager.SelfUser.PlayLocalList == nil then
DataManager.SelfUser.PlayLocalList = {}
2025-04-01 10:48:36 +08:00
end
2025-11-06 17:37:53 +08:00
DataManager.SelfUser.PlayLocalList[tostring(pid)] = isMark
2025-04-01 10:48:36 +08:00
--printlog("111111111122222222222223333333333333")
--pt(DataManager.SelfUser.PlayLocalList)
2025-11-06 17:37:53 +08:00
local playName = "playfaconfig" .. self.group_id
Utils.SaveLocalFile(playName, json.encode(DataManager.SelfUser.PlayLocalList))
2025-04-01 10:48:36 +08:00
if self.callbackFill then
self.callbackFill()
end
end
2025-11-06 17:37:53 +08:00
return M