-- 牌友圈管理界面 local MngPageConfig = import(".MngView.MngPageConfig") local GroupManagerView = {} local M = GroupManagerView function GroupManagerView.new(blur_view, gid, btn_type, callback) setmetatable(M, { __index = BaseWindow }) local self = setmetatable({}, { __index = M }) self.class = "GroupManagerView" -- self._close_destroy = true self._put_map = false self._new_hide = false self._queue = false -- self._full = true -- self._full_offset = false self._animation = false self._blur_view = blur_view self.group_id = gid self.partnerList = {} self.callback = callback self:init("ui://NewGroup/Win_ManagerView", btn_type) return self end -- 获取界面配置 local function getPageConfig(id) --pt(MngPageConfig.PageList) for i = 1, #MngPageConfig.PageList do local tem = MngPageConfig.PageList[i] if tem.id == id then return tem end end end function M:init(url, btn_type) BaseWindow.init(self, url) self.titleTxt = self._view:GetChild("n79") -- if btn_type == 2 then -- self._view:GetChild("n0"):GetChild("icon").url = "ui://m7iejg46p41ohx8" -- elseif btn_type == 3 then -- self._view:GetChild("n0"):GetChild("icon").url = "ui://m7iejg46p41ohx7" -- elseif btn_type == 4 then -- self._view:GetChild("n0"):GetChild("icon").url = "ui://m7iejg46p41ohx9" -- end local lst_index = self._view:GetChild("lst_index") lst_index:RemoveChildrenToPool() local group = DataManager.groups:get(self.group_id) --根据玩家权限,加载不同的界面配置 local lev = group.lev if lev == 3 and group.partnerLev == 0 then lev = 4 end self.page_config = MngPageConfig.Config[btn_type][lev] -- 初始化标题列表 for i = 1, #self.page_config do -- print("page_config:"..self.page_config[i]) local page = getPageConfig(self.page_config[i]) --如果界面无show_key,或圈子中对应的key为true才显示界面 if not page.show_key or (page.show_key and group[page.show_key]) then --如果allicance为ture,则只有大联盟才显示界面 if (page.alliance and group.type == 2) or not page.alliance then local item = lst_index:AddItemFromPool() local title = page.title item:GetChild("title").text = title if i == 1 then item.selected = true end end end end -- coroutine.start(function() -- coroutine.wait(0) -- local anchor = self._view:GetChild("anchor") -- -- 初始界面 -- local first_page_config = getPageConfig(self.page_config[1]) -- local gmsv = first_page_config.view.new(self.group_id, self._root_view) -- self._view_map = {} -- self._view_map[1] = gmsv -- gmsv.id = first_page_config.id -- anchor:AddChild(gmsv._view) -- printlog("tttttttttttttttttttttt :" , gmsv._view.displayObject.gameObject.name," ",gmsv._view.parent.displayObject.gameObject.name) -- -- gmsv._view:AddRelation(anchor, RelationType.Size) -- local offset = get_offset(self._full_offset) -- gmsv._view.width = GRoot.inst.width -300 - 2 * offset -- gmsv._view.height = GRoot.inst.height -- gmsv._view.x = offset -- end) -- 所有子界面加载点 local anchor = self._view:GetChild("anchor") -- 初始界面 local first_page_config = getPageConfig(self.page_config[1]) local gmsv = first_page_config.view.new(self.group_id, self._root_view) self._view_map = {} self._view_map[1] = gmsv gmsv.id = first_page_config.id anchor:AddChild(gmsv._view) --printlog("tttttttttttttttttttttt :" , gmsv._view.displayObject.gameObject.name," ",gmsv._view.parent.displayObject.gameObject.name) --gmsv._view:AddRelation(anchor, RelationType.Size) local offset = get_offset(self._full_offset) gmsv._view.width = anchor.width gmsv._view.height = anchor.height gmsv._view.x = 0 --offset -- first_page_config = getPageConfig(self.page_config[2]) -- gmsv = first_page_config.view.new(self.group_id, self._root_view) -- self._view_map[2] = gmsv -- gmsv.id = first_page_config.id -- gmsv._view.visible = false -- anchor:AddChild(gmsv._view) -- gmsv._view:AddRelation(anchor, RelationType.Size) -- if first_page_config.refresh then gmsv:initData() end -- if #self.page_config == 1 then -- self._view:GetController("single").selectedIndex = 1 -- lst_index.visible = false -- self._view:GetChild("n0"):GetController("v_menu").selectedIndex = 1 -- end -- 切换界面 self.ctr_index = self._view:GetController("index") -- 监听左侧导航列表索引变化,实现子页面的切换 self.ctr_index.onChanged:Set(function(pas) local anchor = self._view:GetChild("anchor") -- 1. 清理容器:移除当前显示的所有子视图 -- 注意:这里只是从父节点移除,并没有销毁对象,以便后续复用 anchor:RemoveChildren() -- 2. 获取目标页面配置 local index = self.ctr_index.selectedIndex -- page_config 存储的是页面ID列表,需要根据索引获取对应的配置详情 local page_info = getPageConfig(self.page_config[index + 1]) -- 3. 视图懒加载与缓存机制 if not self._view_map[index + 1] then -- 【情况A:首次访问该页面】需要创建新的视图实例 -- 实例化对应的子视图类 (例如: GroupMngMemberListView1.new(...)) local tem = page_info.view.new(self.group_id, self._root_view) -- 将新创建的视图添加到锚点容器中显示 anchor:AddChild(tem._view) -- 【UI适配】强制设置子视图尺寸与容器一致 local offset = get_offset(self._full_offset) tem._view.width = anchor.width tem._view.height = anchor.height tem._view.x = 0 --offset (通常设为0以贴合左侧或居中,具体视UI布局而定) -- 记录页面唯一ID,用于后续查找 tem.id = page_info.id -- 【缓存】将创建好的视图实例存入映射表,避免重复创建 self._view_map[index + 1] = tem else -- 【情况B:再次访问该页面】直接从缓存中读取并重新挂载 -- 从映射表中取出之前创建过的视图实例,重新添加回容器 anchor:AddChild(self._view_map[index + 1]._view) end -- 4. 数据刷新 -- 如果配置中标记了 refresh=true,则每次切换到此页面时都重新加载数据 if page_info.refresh then self._view_map[index + 1]:initData() end -- 5. 更新顶部标题 self.titleTxt.text = page_info.title end) end function M:SetCurrentGroupInfoViewIns(groupInfoViewCallBack) self.groupInfoViewCallBack = groupInfoViewCallBack end -- 获取指定ID的页面 function M:GetPageByID(id) for i, v in pairs(self._view_map) do if v.id == id then return v end end return nil end -- 根据ID刷新页面 function M:RefreshPage(id) local page = self:GetPageByID(id) if not page then return end page:initData() end function M:Close() if self.callback then self.callback() end BaseWindow.Close(self) end function M:Destroy() for i = 1, #self.page_config do if self._view_map[i] then self._view_map[i]._view:Dispose() if self._view_map[i].clear_image then ImageLoad.Clear(self._view_map[i].class) end end end BaseWindow.Destroy(self) end -- quick_access_id 是快速访问标志,打开对应id的页面 function M:Show(quick_access_id) local index = self.ctr_index.selectedIndex if not quick_access_id then local page_info = getPageConfig(self.page_config[index + 1]) if page_info.refresh then self._view_map[index + 1]:initData() end self.titleTxt.text = page_info.title else -- 如果是 快速访问 for i, v in pairs(self.page_config) do if getPageConfig(v).id == quick_access_id then self.ctr_index.selectedIndex = i - 1 if not self._view_map[i] then local tem = page_info.view.new(self.group_id, self._root_view) self._view_map[i] = tem end local anchor = self._view:GetChild("anchor") anchor:AddChild(self._view_map[i]._view) self._view_map[i]:navigation() --self._view:AddRelation(anchor, RelationType.Size) break end end end BaseWindow.Show(self) end return M