393 lines
13 KiB
Lua
393 lines
13 KiB
Lua
local JoinGroupView = import('.JoinGroupView')
|
||
local GroupSettingView = import('.GroupSettingView')
|
||
local CreateGroupView = import('.CreateGroupView')
|
||
local GroupInfoView = import('.GroupInfoView')
|
||
local PhoneBindView = import("Game.View.Lobby.PhoneBindView")
|
||
|
||
local GroupMainView = {}
|
||
|
||
local M = GroupMainView
|
||
|
||
function GroupMainView.new(main_view, root_view,par_veiw)
|
||
--print(debug.traceback())
|
||
local self = setmetatable({}, {__index = M})
|
||
self.class = 'GroupMainView'
|
||
UIPackage.AddPackage('base/newgroup/ui/NewGroup')
|
||
self._view = main_view
|
||
self._root_view = root_view
|
||
self._par_veiw = par_veiw
|
||
|
||
self:InitView()
|
||
return self
|
||
end
|
||
|
||
function M:InitView(url)
|
||
|
||
--print(url)
|
||
-- BlurView(self._view:GetChild("bg"),true)
|
||
if DataManager.SelfUser.agent > 0 then
|
||
self._view:GetController('agent').selectedIndex = 1
|
||
end
|
||
-- local btn_close = self._view:GetChild("btn_close")
|
||
-- btn_close.onClick:Set(function()
|
||
-- self:Destroy()
|
||
-- end)
|
||
local fgCtr = ControllerManager.GetController(NewGroupController)
|
||
local btn_creategroup = self._view:GetChild('btn_creategroup')
|
||
btn_creategroup.onClick:Set(function()
|
||
local cgv = CreateGroupView.new(self._root_view)
|
||
cgv:Show()
|
||
cgv:SetCallback(function(name, pay_type, fg_type)
|
||
ViewUtil.ShowModalWait(cgv._root_view)
|
||
fgCtr:FG_CreateGroup(name,pay_type,fg_type,function(res)
|
||
ViewUtil.CloseModalWait()
|
||
if self._is_destroy then
|
||
return
|
||
end
|
||
if res.ReturnCode == 0 then
|
||
cgv:Destroy()
|
||
self:FillData()
|
||
else
|
||
ViewUtil.ErrorTip(res.ReturnCode, '创建大联盟失败!')
|
||
end
|
||
end)
|
||
end)
|
||
end)
|
||
|
||
self.btn_joingroup = self._par_veiw:GetChild('btn_join_group')
|
||
self.btn_joingroup.displayObject.gameObject:SetActive(false)
|
||
--[[self.btn_joingroup.onClick:Set(function()
|
||
local groups = DataManager.groups.groupList
|
||
if #groups == 0 then
|
||
local jgv = JoinGroupView.new(self._root_view)
|
||
jgv:Show()
|
||
else
|
||
local info = GroupInfoView.new(groups[1], self.fg_info)
|
||
self._groupInfoView = info
|
||
info:SetCallBack(function()
|
||
self._groupInfoView = nil
|
||
self:Show()
|
||
self._view.visible = true
|
||
end)
|
||
info:Show()
|
||
self._view.visible = false
|
||
end
|
||
if not DataManager.SelfUser.phone then
|
||
--local phone_view = PhoneBindView.new()
|
||
--phone_view:Show()
|
||
-- return
|
||
end
|
||
end)--]]
|
||
|
||
-- local btn_setting = self._view:GetChild('btn_setting')
|
||
-- btn_setting.onClick:Set(
|
||
-- function()
|
||
-- local gsv = GroupSettingView.new(self._root_view)
|
||
-- gsv:FillData()
|
||
-- gsv:SetCallback(
|
||
-- function()
|
||
-- self:FillData()
|
||
-- end
|
||
-- )
|
||
-- gsv:Show()
|
||
-- end
|
||
-- )
|
||
|
||
local btn_refresh = self._view:GetChild('btn_refresh')
|
||
btn_refresh.onClick:Set(function()
|
||
ViewUtil.ShowModalWait(self._root_view)
|
||
fgCtr:FG_GroupList(function(res)
|
||
ViewUtil.CloseModalWait()
|
||
if self._is_destroy then
|
||
return
|
||
end
|
||
if res.ReturnCode == 0 then
|
||
-- self:__fillTopGroups(res.Data.groups,res.Data.stickGroups)
|
||
self:FillData(res.Data.groups)
|
||
end
|
||
end)
|
||
end)
|
||
|
||
-- btn_jiaru按钮:打开圈子列表页,类似btn_more_group的功能
|
||
local btn_jiaru = self._view:GetChild('btn_jiaru')
|
||
if btn_jiaru then
|
||
btn_jiaru.visible = true
|
||
btn_jiaru.onClick:Set(function()
|
||
ViewUtil.ShowModalWait(self._root_view, "请稍等,获取牌友圈中...")
|
||
fgCtr:FG_GroupList(function(res)
|
||
ViewUtil.CloseModalWait()
|
||
if self._is_destroy then
|
||
return
|
||
end
|
||
if res.ReturnCode == 0 then
|
||
local groups = DataManager.groups.groupList
|
||
if #groups == 0 then
|
||
-- 如果没有圈子,显示列表页让用户创建或加入
|
||
self._view.visible = true
|
||
self:Show()
|
||
else
|
||
-- 有圈子,显示第一个圈子的详情页
|
||
local curGroup = groups[1]
|
||
-- 读取牌友圈信息
|
||
local filename = 'fginfo_' .. DataManager.SelfUser.account_id
|
||
local json_data = Utils.LoadLocalFile(filename)
|
||
local fg_info = not json_data and {} or json.decode(json_data)
|
||
|
||
-- 创建GroupInfoView,传入根视图和列表页容器
|
||
-- GroupMainView会被嵌入到GroupInfoView的lnfo_group组件中,显示所有圈子列表
|
||
local info = GroupInfoView.new(curGroup, fg_info, self._root_view, self)
|
||
info:SetCallBack(function()
|
||
-- 关闭回调:恢复列表页到原位置
|
||
if self and self._view and not self._view.isDisposed then
|
||
-- 将列表页移回原容器
|
||
if self._originalParent then
|
||
self._originalParent:AddChild(self._view)
|
||
self._originalParent = nil
|
||
end
|
||
self._view.visible = false
|
||
end
|
||
end)
|
||
info:Show()
|
||
end
|
||
else
|
||
ViewUtil.ErrorTip(10000000, '获取牌友圈失败,请检查网络设置!')
|
||
end
|
||
end)
|
||
end)
|
||
end
|
||
|
||
local lst_group = self._view:GetChild('lst_group')
|
||
lst_group.onClickItem:Add(function(context)
|
||
local curGroup = context.data.data
|
||
|
||
-- 判断当前GroupMainView是否被嵌入到GroupInfoView中
|
||
if self._parentInfoView then
|
||
-- 如果被嵌入,调用父视图的切换方法
|
||
--printlog("GroupMainView被嵌入,切换到圈子:", curGroup.id, curGroup.name)
|
||
self._parentInfoView:SwitchToGroup(curGroup)
|
||
return
|
||
end
|
||
|
||
-- 正常模式:创建并显示GroupInfoView
|
||
local info = GroupInfoView.new(curGroup, self.fg_info)
|
||
self._groupInfoView = info
|
||
info:SetCallBack(function()
|
||
self._groupInfoView = nil
|
||
-- 关闭详情页后刷新列表
|
||
ViewUtil.ShowModalWait(self._root_view, "刷新中...")
|
||
local fgCtr = ControllerManager.GetController(NewGroupController)
|
||
fgCtr:FG_GroupList(function(res)
|
||
ViewUtil.CloseModalWait()
|
||
if self._is_destroy then
|
||
return
|
||
end
|
||
if res.ReturnCode == 0 then
|
||
-- 刷新列表数据
|
||
self:FillData()
|
||
self._view.visible = true
|
||
else
|
||
ViewUtil.ErrorTip(res.ReturnCode, '刷新列表失败!')
|
||
end
|
||
end)
|
||
end)
|
||
--info:Show()
|
||
--self._view.visible = false
|
||
end)
|
||
|
||
local ctr_empty_group = self._view:GetController('empty_group')
|
||
ctr_empty_group.selectedIndex = 1
|
||
|
||
local btn_close = self._view:GetChild("btn_close")
|
||
btn_close.onClick:Set(function()
|
||
self._view.visible = false
|
||
end)
|
||
end
|
||
|
||
function M:DEnterGroup()
|
||
local groups = DataManager.groups.groupList
|
||
if #groups == 0 then
|
||
--local jgv = JoinGroupView.new(self._root_view)
|
||
--jgv:Show()
|
||
else
|
||
local info = GroupInfoView.new(groups[1], self.fg_info)
|
||
self._groupInfoView = info
|
||
info:SetCallBack(function()
|
||
self._groupInfoView = nil
|
||
self:Show()
|
||
self._view.visible = true
|
||
end)
|
||
--info:Show()
|
||
--self._view.visible = false
|
||
end
|
||
end
|
||
|
||
|
||
local function SortGroups(a, b)
|
||
local sort_a = 0
|
||
local sort_b = 0
|
||
sort_a = a.top and 2000 or 0
|
||
sort_b = b.top and 2000 or 0
|
||
|
||
return sort_a > sort_b
|
||
end
|
||
|
||
function M:__fill_item(item,group)
|
||
item:GetChild('tex_name').text = group.name
|
||
item:GetChild('tex_id').text = "ID:".. group.id
|
||
local p_num = group.total_member_num
|
||
item:GetChild('tex_p_num').text = p_num > 99 and '99+' or p_num
|
||
|
||
if group.lev < 3 then
|
||
if group.lev == 1 then
|
||
item:GetChild('tex_room_num').text = group.room_num
|
||
else
|
||
item:GetChild('tex_room_num').text = group.room_num > 99 and '99+' or group.room_num
|
||
end
|
||
else
|
||
if group.show_num > 0 and group.room_num > group.show_num then
|
||
item:GetChild('tex_room_num').text = group.show_num > 99 and '99+' or group.show_num--group.show_num
|
||
else
|
||
item:GetChild('tex_room_num').text = group.room_num > 99 and '99+' or group.room_num
|
||
end
|
||
end
|
||
|
||
local btn_head = item:GetChild('btn_head')
|
||
btn_head.icon = 'ui://Common/Head0'
|
||
ImageLoad.Load(group.o_portrait, btn_head._iconObject, self.class)
|
||
end
|
||
|
||
function M:FillData()
|
||
local groups = DataManager.groups.groupList
|
||
-- 读取牌友圈信息
|
||
local filename = 'fginfo_' .. DataManager.SelfUser.account_id
|
||
local json_data = Utils.LoadLocalFile(filename)
|
||
local fg_info = not json_data and {} or json.decode(json_data)
|
||
local fg_info_changed = not json_data and true or (table.nums(fg_info) ~= #groups and true or false)
|
||
local new_info = {}
|
||
for i = 1, #groups do
|
||
local key = tostring(groups[i].id)
|
||
local key1 = tostring(groups[i].id).."vip"
|
||
if not fg_info[key] then
|
||
new_info[key] = 0
|
||
if not fg_info_changed then
|
||
fg_info_changed = true
|
||
end
|
||
else
|
||
new_info[key] = fg_info[key]
|
||
end
|
||
if not fg_info[key1] then
|
||
new_info[key1] = 0
|
||
else
|
||
new_info[key1] = fg_info[key1]
|
||
end
|
||
end
|
||
self.fg_info = new_info
|
||
if fg_info_changed and table.nums(new_info) > 0 then
|
||
Utils.SaveLocalFile(filename, json.encode(new_info))
|
||
end
|
||
|
||
local ctr_empty_group = self._view:GetController('empty_group')
|
||
if #groups == 0 then
|
||
self.btn_joingroup:GetController("info").selectedIndex = 0
|
||
ctr_empty_group.selectedIndex = 1
|
||
return
|
||
else
|
||
self.btn_joingroup:GetController("info").selectedIndex = 1
|
||
ctr_empty_group.selectedIndex = 0
|
||
self:__fill_item(self.btn_joingroup,groups[1])
|
||
end
|
||
|
||
local lst_group = self._view:GetChild('lst_group')
|
||
-- 使用pcall保护池操作,防止空引用异常
|
||
pcall(function()
|
||
lst_group:RemoveChildrenToPool()
|
||
end)
|
||
|
||
for i = 1, #groups do
|
||
local group = groups[i]
|
||
|
||
local item = lst_group:AddItemFromPool()
|
||
item.data = group
|
||
self:__fill_item(item,group)
|
||
|
||
local btn_top = item:GetChild('btn_top')
|
||
local ctr_select = btn_top:GetController('select')
|
||
ctr_select.selectedIndex = group.top_time > 0 and 1 or 0
|
||
-- item:GetController('select_index').selectedIndex = group.top_time > 0 and 1 or 0
|
||
btn_top.onClick:Set(function(context)
|
||
context:StopPropagation()
|
||
local fgCtr = ControllerManager.GetController(NewGroupController)
|
||
ViewUtil.ShowModalWait(self._root_view)
|
||
fgCtr:FG_TopGroup(group.id,ctr_select.selectedIndex == 0,function(res)
|
||
ViewUtil.CloseModalWait()
|
||
if self._is_destroy then
|
||
return
|
||
end
|
||
if res.ReturnCode == 0 then
|
||
ctr_select.selectedIndex = group.top_time > 0 and 1 or 0
|
||
self:FillData()
|
||
else
|
||
ViewUtil.ErrorTip(res.ReturnCode, '置顶大联盟失败!')
|
||
end
|
||
end)
|
||
end)
|
||
end
|
||
-- end
|
||
end
|
||
|
||
function M:OnFGChanged(callback)
|
||
self._onFGChange = callback
|
||
end
|
||
|
||
function M:EnterGroup(fg_id)
|
||
local curGroup = DataManager.groups:get(fg_id)
|
||
local info = GroupInfoView.new(curGroup, self.fg_info)
|
||
self._groupInfoView = info
|
||
info:SetCallBack(function()
|
||
self._groupInfoView = nil
|
||
self:FillData()
|
||
self._view.visible = true
|
||
end)
|
||
info:Show()
|
||
--self._view.visible = false
|
||
end
|
||
|
||
function M:Show(fg_id,callback)
|
||
local fgCtr1 = ControllerManager.GetController(NewGroupController)
|
||
fgCtr1:FG_GroupList(function(res)
|
||
if self._is_destroy then
|
||
return
|
||
end
|
||
if res.ReturnCode == 0 then
|
||
self:FillData()
|
||
if fg_id then
|
||
self:EnterGroup(fg_id)
|
||
else
|
||
if callback then
|
||
callback(0)
|
||
end
|
||
end
|
||
else
|
||
if callback then
|
||
callback(-1)
|
||
end
|
||
end
|
||
|
||
end)
|
||
end
|
||
|
||
function M:Destroy()
|
||
if self._onFGChange then
|
||
self._onFGChange()
|
||
end
|
||
ImageLoad.Clear(self.class)
|
||
UIPackage.RemovePackage('base/newgroup/ui/NewGroup')
|
||
local num = PlayerPrefs.GetInt('fgroup_bg')
|
||
if num == 0 then
|
||
num = 1
|
||
end
|
||
ResourcesManager.UnLoadGroup('base/newgroup/bg/bg0' .. num)
|
||
end
|
||
|
||
return M
|