local FamilyInviteFamilyView = import('.Family.FamilyInviteFamilyView') local CreatePlayView = import('.Family.CreatePlayView') local GroupGameSettingView = import(".NewGroup.MngView.GroupGameSettingView_jaingxi") local LobbyShopView = import(".Lobby.LobbyShopView") local FamilAllRank = import(".Family.FamilAllRank") local FamilyNumberRecord = import(".Family.FamilyNumberRecord") local FamilyRecord = import(".Family.FamilyRecord") ---无窗口 local FamilyAllNumbers = import(".Family.FamilyAllNumbers") local FamilyAuditNumber = import(".Family.FamilyAuditNumber") local FamilyJoinAndCreate = import(".Family.FamilyJoinAndCreate") local FamilyEventView = import(".Family.FamilyEventView") local FamilyBanDesk = import(".Family.FamilyBanDesk") local FamilyMyFamily = import(".Family.FamilyMyFamily") local FamilyRoomCard = import(".Family.FamilyRoomCard") local FamilyMyfamilyList = import(".Family.FamilyMyfamilyList") --- FamilyView = {} local M = FamilyView function FamilyView.new() UIPackage.AddPackage("base/Family/ui/Family") setmetatable(M, { __index = BaseView }) local self = setmetatable({}, { __index = M }) self.class = 'FamilyMainView' self._full = true self._close_destroy = false self._fristRoom = true self:init('ui://Family/Main') return self end function M:init(url) BaseView.InitView(self, url) self._full_offset = false local view = self._view local fgCtr = ControllerManager.GetController(NewGroupController) self.familyType = view:GetController('familyType') self.btn_close = view:GetChild('btn_close') self.btn_myFamilyList = view:GetChild("btn_myFamilyList") self.btn_creatFamily = view:GetChild("btn_creatFamily") self.btn_joinFamily = view:GetChild("btn_joinFamily") self._mgr_ctr = ControllerManager.GetController(GroupMgrController) self.cMyfamilyList = view:GetController("cMyfamilyList") self.btn_quitMyfamilyTab = view:GetChild("btn_quitMyfamilyTab") self:InitCloseClick() fgCtr:FG_GroupList(function(res) local groups = res.Data.groups if #groups > 0 then self.familyType.selectedIndex = 1 self:ConnetFamily(1, groups, true) else self:JoinFamily(true) end end) -------绑定成员战绩按钮 view:GetChild('btn_family_record').onClick:Set(function() self._child_familyNumberRecord = FamilyNumberRecord.New(self) self.lastType = 1 end) if FamilyEventView then self._familyEventView = FamilyEventView.new(self) self._familyEventView:_evtAddPlay() end -------绑定我的亲友圈按钮 view:GetChild('btn_myfamily').onClick:Set(function() self.cMyfamilyList.selectedIndex = 1 end) self.btn_myFamilyList.onClick:Set(function() self.cMyfamilyList.selectedIndex = 0 --FamilyMyFamily:TryShow(self) FamilyMyfamilyList:TryShow(self) end) self.btn_creatFamily.onClick:Set(function() self.cMyfamilyList.selectedIndex = 0 self:CreateFamily() end) self.btn_joinFamily.onClick:Set(function() self.cMyfamilyList.selectedIndex = 0 self:CreateFamily() end) self.btn_quitMyfamilyTab.onClick:Set(function() self.cMyfamilyList.selectedIndex = 0 end) end function M:InitCloseClick() self.btn_close.onClick:Set(function() print("lingmengfamily", self.lastType, self.familyType.selectedIndex) if not self.lastType or self.familyType.selectedIndex == 1 then ControllerManager.ChangeController(LoddyController) ViewManager.ChangeView(ViewManager.View_Lobby) else self.familyType.selectedIndex = self.lastType if self.lastType == 3 then self.lastType = 1 end end end) end function M:ShareWx() local familyInviteFamilyView = FamilyInviteFamilyView.new() familyInviteFamilyView:Show() end function M:FamilyRecord() if not self._ViewChild_Record or not self._ViewChild_Record.ShouRanks then self._ViewChild_Record = FamilyRecord.New(self, self._group.id) return end self._ViewChild_Record:ShouRanks() end function M:CreateFamily(frist) self.familyType.selectedIndex = 3 if not frist then self.lastType = 1 end self._view:GetController('createOrJoin').selectedIndex = 0 self._child_familyJoinAndCreate = FamilyJoinAndCreate:init(self) end function M:JoinFamily(frist) self.familyType.selectedIndex = 3 if not frist then self.lastType = 1 end self._view:GetController('createOrJoin').selectedIndex = 1 self._child_familyJoinAndCreate = FamilyJoinAndCreate:init(self) end function M:PlayEdit() self.familyType.selectedIndex = 2 self.lastType = 1 end function M:OpenMyFamily(groupId) FamilyMyFamily:TryShow(groupId, self) end function M:AllNumber() self.lastType = 1 self._child_familyAllNumbers = FamilyAllNumbers.new(self._group, self) end function M:AuditNumber() self.lastType = 1 self._child_familyAuditNumber = FamilyAuditNumber.new(self) end function M:ShowShop() --self._child_familyLobbyShopView = LobbyShopView.new(self, self._group.id) --self._child_familyLobbyShopView:Show() FamilyRoomCard:TryShow() end function M:ShowAllRank() if not self._ViewChild_AllRank or not self._ViewChild_AllRank.ShouRanks then self._ViewChild_AllRank = FamilAllRank.New(self, self._group.id) return end self._ViewChild_AllRank:ShouRanks() end function M:OpenAllNumber(group) self.lastType = 1 self._child_familyAllNumbers = FamilyAllNumbers.new(group, self) end function M:MoreBtn() local ctr_more = self._view:GetController('moreBtn') self._view:GetChild('bg_moreBtnBack').onClick:Set(function() ctr_more.selectedIndex = 0 end) ctr_more.selectedIndex = 1 self:ChangeMore() end function M:BanFamily() local fgCtr = ControllerManager.GetController(NewGroupController) fgCtr:FG_UpdateGroupInfo(self._group.id, self._group.name, "", not self._group.ban, self._group.dissolve_opt, self._group.kick_opt, self._group.apply, self._group.ban_chat1, self._group.ban_chat2, self._group.option, 0, function(res) if res.ReturnCode ~= 0 then ViewUtil.ErrorTip(res.ReturnCode, "一键打样失败") else self._view:GetController('familyBan').selectedIndex = self._group.ban and 1 or 0 end end) end function M:BanDeskmate() self.FamilyBanDesk = FamilyBanDesk:TryShow(self) end function M:ChangeNumber(fgCtr, group_id, limit, num, minus_only, sort_type) local list_familyNumber = self._view:GetChild('list_familyNumber') list_familyNumber:SetVirtual() fgCtr:FG_GroupMembers12(group_id, limit, num, 2, 2, function(res) local members = self._group.members -- print("==========================res.Data.members") pt(self._group.members) ViewUtil:CloseModalWait() if res.ReturnCode ~= 0 then ViewUtil.ErrorTip(res.ReturnCode, "获取成员列表失败") else list_familyNumber.itemRenderer = function(index, obj) obj:GetChild('title').text = members[index + 1].nick obj:GetController('type').selectedIndex = members[index + 1].online and members[index + 1].online or 0 end list_familyNumber.numItems = #self._group.members return 1 end end) return 0 end function M:ConnetFamilyRoom(fgCtr, id) fgCtr:FG_EnterGroup(id, function(res) ViewUtil:CloseModalWait() if res.ReturnCode ~= 0 then ViewUtil.ErrorTip(res.ReturnCode, "获取房间列表列表失败") else self:UpdateFamilyRoom(fgCtr, id) self._view:GetController('familyBan').selectedIndex = self._group.ban and 1 or 0 return 1 end end) return 0 end function M:UpdateFamilyRoom(fgCtr, id) local list_room = self._view:GetChild('list_room') list_room:SetVirtual() local list_gamePlay = self._view:GetChild('list_gamePlay') list_gamePlay:SetVirtual() self._view:GetChild('n364').text = string.format("已开启%s桌游戏", self._group.room_num) local playList = self._group.playList --初始化玩法列表,用于房间使用 local playGameInfoTable = {} for i = 1, #playList do playGameInfoTable[playList[i].id] = { gameId = playList[i].gameId, config = playList[i].config, name = playList[i].name, gameName = playList[i].game_name, } end local roomList = self._group.rooms print("lingmengroomList") pt(roomList) pt(playList) local roomCtr = ControllerManager.GetController(RoomController) list_room.itemRenderer = function(index, obj) if index < #roomList then local newIndex = index + 1 local gameId = playGameInfoTable[roomList[newIndex].pid].gameId local config = ExtendManager.GetExtendConfig(gameId) local mode = config:GetGameInfo() local gamePlay = mode:LoadConfigToDetail(playGameInfoTable[roomList[newIndex].pid].config) obj:GetChild('Label_gameRule').title = gamePlay obj:GetChild('game_type').text = string.format("(%s)%s", playGameInfoTable[roomList[newIndex].pid].gameName, playGameInfoTable[roomList[newIndex].pid].name, roomList[newIndex].id) obj:GetChild('btn_joinGame'):GetController('type').selectedIndex = 1 obj:GetController('num').selectedIndex = roomList[newIndex].maxPlayers - 2 obj:GetController('type').selectedIndex = 1 local plist = roomList[newIndex].plist local insertName = "" for i = 1, #plist do ImageLoad.Load(plist[i].portrait, obj:GetChild(string.format("player%d", i))._iconObject) insertName = string.format("%s、%s", plist[i].nick, insertName) end obj:GetChild('Label_joinPlayers').text = insertName obj:GetChild('btn_joinGame').onClick:Set(function() roomCtr:PublicJoinRoom( Protocol.WEB_FG_JOIN_ROOM, roomList[newIndex].id, id, function(response) if (response.ReturnCode == -1) then ViewUtil.ErrorMsg(self._root_view, response.ReturnCode, 'response.ReturnCode == -1') -- RestartGame() return end if response.ReturnCode ~= 0 then ViewUtil.ErrorMsg(self._root_view, response.ReturnCode, '进入房间失败') -- ViewManager.ChangeView(ViewManager.View_Lobby) return else UpdateBeat:Remove(self.OnUpdate, self) ViewManager.ChangeView(ViewManager.View_Main, gameId) end end, id, roomList[newIndex].pid ) end) obj:GetChild('btn_watch').onClick:Set(function() roomCtr:PublicWitnessRoom( Protocol.WEB_FG_Witness_ROOM, roomList[newIndex].id, id, function(response) if (response.ReturnCode == -1) then ViewUtil.ErrorMsg(self._root_view, response.ReturnCode, 'response.ReturnCode == -1') -- RestartGame() return end if response.ReturnCode ~= 0 then ViewUtil.ErrorMsg(self._root_view, response.ReturnCode, '进入房间失败') -- ViewManager.ChangeView(ViewManager.View_Lobby) return else UpdateBeat:Remove(self.OnUpdate, self) ViewManager.ChangeView(ViewManager.View_Witness, gameId) end end, gameId, roomList[newIndex].pid ) -- self._gamectr = ControllerManager.GetController(GameController) -- self._gamectr:WitnessGame(DataManager.SelfUser.account_id, id, roomList[newIndex].id) end) else local newIndex = index - #roomList + 1 local config = ExtendManager.GetExtendConfig(playList[newIndex].gameId) local mode = config:GetGameInfo() local gamePlay = mode:LoadConfigToDetail(playList[newIndex].config) obj:GetChild('Label_gameRule').title = gamePlay obj:GetChild('game_type').text = string.format("(%s)%s", playList[newIndex].game_name, playList[newIndex] .name) obj:GetChild('btn_joinGame'):GetController('type').selectedIndex = 0 obj:GetController('num').selectedIndex = playList[newIndex].maxPlayers - 2 obj:GetChild('btn_joinGame').onClick:Set(function() roomCtr:PublicJoinRoom( Protocol.WEB_FG_MATCH_ROOM, "", true, function(response) if (response.ReturnCode == -1) then ViewUtil.ErrorMsg(self._root_view, response.ReturnCode, 'response.ReturnCode == -1') -- RestartGame() return end if response.ReturnCode ~= 0 then ViewUtil.ErrorMsg(self._root_view, response.ReturnCode, '进入房间失败') -- ViewManager.ChangeView(ViewManager.View_Lobby) return else UpdateBeat:Remove(self.OnUpdate, self) ViewManager.ChangeView(ViewManager.View_Main, playList[newIndex].gameId) end end, id, playList[newIndex].id ) end) end end list_gamePlay.itemRenderer = function(index, obj) if index == 0 then obj:GetController('type').selectedIndex = 0 obj:GetChild('num').text = string.format("%d/7", #playList) obj:GetChild('btn_addPlay').onClick:Set(function() local tem = GroupGameSettingView.new(self.blur_view, id, 0, nil, function(play) local group = DataManager.groups:get(id) group:addPlay(play) -- self:FillView() self:UpdateFamilyRoom(fgCtr, id) printlog("刷新玩法===>>>>") group.update_play = true end) tem:Show() end) return end obj:GetChild('text_title').text = playList[index].game_name local mode = ExtendManager.GetExtendConfig(playList[index].gameId):GetGameInfo() obj:GetChild('Label_details'):GetChild('title').text = mode:LoadConfigToDetail(playList[index].config) obj:GetChild('text_playName').text = playList[index].name obj:GetController('type').selectedIndex = 1 obj:GetChild('btn_del').onClick:Set(function() ViewUtil.ShowTwoChooose("是否要删除该玩法", function() fgCtr:FG_DelPlay(id, playList[index].id, function() self:UpdateFamilyRoom(fgCtr, id) end) end) end) end local all_num = #playList + #roomList -- print("=================================================list_room", list_room, list_room.numItems, all_num) pt(list_room) list_room.numItems = all_num list_gamePlay.numItems = #playList + 1 end function M:ConnetFamily(index, groups, isCreate) UpdateBeat:Remove(self.OnUpdate, self) ViewUtil:CloseModalWait() local list_family = self._view:GetChild('list_family') list_family:SetVirtual() self._group = DataManager.groups:get(groups[index].id) self._view:GetChild('text_familyId').text = self._group.id print("===================================self._group") pt(self._group) self._roomNum = self._group.room_num if isCreate then list_family.itemRenderer = function(i, obj) local j = i + 1 obj.text = groups[j].name obj.onClick:Add(function() self:ConnetFamily(j, DataManager.groups.groupList, false) end) end list_family.numItems = #groups if list_family.selectedIndex == -1 then list_family.selectedIndex = 0 end end local fgCtr = ControllerManager.GetController(NewGroupController) ViewUtil.ShowModalWait(self._root_view, "正在加载亲友圈权限中......") self:ChangeOther(tonumber(self._group.lev) + 1) allLoad = 1 ViewUtil.ShowModalWait(self._root_view, "正在加载成员列表中......") allLoad = allLoad + self:ChangeNumber(fgCtr, self._group.id, 0, self._group.total_member_num, false, 1) ViewUtil.ShowModalWait(self._root_view, "正在加载房间列表中......") allLoad = allLoad + self:ConnetFamilyRoom(fgCtr, self._group.id) UpdateBeat:Add(self.OnUpdate, self) end -- function M:Destroy() -- UpdateBeat:Remove(self.OnUpdate, self) -- BaseView:Destroy() -- end function M:OnUpdate() local fgCtr = ControllerManager.GetController(NewGroupController) local heatTime = os.time() -- --12001事件 local func = self._mgr_ctr:PopEvent() if (func ~= nil) then local success, result = pcall(func) if success then else print("witness error") print(result) -- self._gamectr = ControllerManager.GetController(GameController) -- if self._gamectr then -- self._gamectr:ResetConnect() -- end end --func() end if self._group.update_room then -- if self._roomNum == self._group.room_num then -- for i = 1, self._group.room_num do -- if self._group.rooms[i] and #self._group.rooms[i].plist == 0 then -- self._group.update_room = false -- fgCtr:FG_RemoveRoom( -- self._group.id, -- self._group.rooms[i].id, -- function(res) -- if res.ReturnCode ~= 0 then -- ViewUtil.ErrorTip(res.ReturnCode, string.format('删除房间-%s失败!', self._group.rooms[i].id)) -- else -- self._roomNum = #self._group.rooms -- end -- end -- ) -- end -- end -- else -- self._group.update_room = false -- -- self._group.update_room = false -- end -- if self._fristRoom then self._group.update_room = false -- self._fristRoom = true -- end -- -- print("====================================UpdateFamilyRoom", fgCtr, self._group.id) self:UpdateFamilyRoom(fgCtr, self._group.id) end if not self.lastTime or self.lastTime - heatTime > 30 then fgCtr:FG_SetFamilyHeartbeat(self._group.id, DataManager.SelfUser.account_id, function(res) self:ChangeNumber(fgCtr, self._group.id, 0, self._group.total_member_num, false, 1) pt(res) end) self.lastTime = heatTime end end local IDENTITY_LIST = { { level = 0, --圈主 }, { level = 1, --副圈主 otherList = { { name = "邀请朋友", Fct = M.ShareWx }, { name = "游戏记录", Fct = M.FamilyRecord }, { name = "玩法管理", Fct = M.PlayEdit }, { name = "充值房卡", Fct = M.ShowShop }, { name = "申请消息", Fct = M.AuditNumber }, { name = "查看成员", Fct = M.AllNumber }, { name = "创建亲友圈", Fct = M.CreateFamily }, { name = "高级选项", Fct = M.MoreBtn }, { name = "亲友圈排行榜", Fct = M.ShowAllRank } } }, { level = 2, --管理员 otherList = { { name = "邀请朋友", Fct = M.ShareWx }, { name = "游戏记录", Fct = M.FamilyRecord }, { name = "玩法管理", Fct = M.PlayEdit }, { name = "充值房卡", Fct = M.ShowShop }, { name = "申请消息", Fct = M.AuditNumber }, { name = "查看成员", Fct = M.AllNumber }, { name = "创建亲友圈", Fct = M.CreateFamily }, { name = "高级选项", Fct = M.MoreBtn }, { name = "亲友圈排行榜", Fct = M.ShowAllRank } } }, { level = 3, --成员 otherList = { { name = "邀请朋友", Fct = M.ShareWx }, { name = "创建亲友圈", Fct = M.CreateFamily }, { name = "加入亲友圈", Fct = M.JoinFamily }, } }, } local MORE_LIST = { { name = "一键打样", Fct = M.BanFamily }, { name = "消息记录", Fct = M.ShareWx }, { name = "禁止同桌", Fct = M.BanDeskmate }, { name = "关闭聊天室", Fct = M.ShareWx }, } function M:ChangeOther(i) local otherList = IDENTITY_LIST[i].otherList local list_other = self._view:GetChild('list_other') self._lev = i list_other:SetVirtual() list_other.itemRenderer = function(index, obj) obj:GetChild('title').text = otherList[index + 1].name obj.onClick:Set(handler(self, otherList[index + 1].Fct)) end list_other.numItems = #otherList end function M:ChangeMore() local moreList = MORE_LIST local list_other = self._view:GetChild('list_more') list_other:SetVirtual() list_other.itemRenderer = function(index, obj) obj:GetChild('title').text = moreList[index + 1].name obj.onClick:Set(handler(self, moreList[index + 1].Fct)) obj.onClick:Add(function() self._view:GetController('moreBtn').selectedIndex = 0 end) end list_other.numItems = #moreList end return M