319 lines
10 KiB
Lua
319 lines
10 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)
|
|
|
|
local lst_group = self._view:GetChild('lst_group')
|
|
lst_group.onClickItem:Add(function(context)
|
|
local curGroup = context.data.data
|
|
--点击进入亲友圈的时候清空亲友圈快捷玩法
|
|
print("lingmeng selectplay", string.format("selectplay%d", DataManager.SelfUser.account_id))
|
|
Utils.SaveLocalFile(string.format("selectplay%d", DataManager.SelfUser.account_id), "")
|
|
Utils.SaveLocalFile(string.format("selectplayname%d", DataManager.SelfUser.account_id), "")
|
|
local info = GroupInfoView.new(curGroup, 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)
|
|
|
|
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')
|
|
lst_group:RemoveChildrenToPool()
|
|
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
|
|
ViewUtil.ShowBannerOnScreenCenter("亲友圈热更问题有问题")
|
|
ViewUtil.CloseModalWait()
|
|
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(res.ReturnCode)
|
|
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
|