local FamilyCreateView = import(".FamilyZuo.FamilyCreateView") local FamilyJoinView = import(".FamilyZuo.FamilyJoinView") local FamilyManagerView = import(".FamilyZuo.FamilyManagerView") local FamilyPlayListView = import(".FamilyZuo.FamilyPlayListView") local FamilyRoomCardView = import(".FamilyZuo.FamilyRoomCardView") FamilyViewZuo = {} local M = FamilyViewZuo function FamilyViewZuo.new() UIPackage.AddPackage("base/Family/ui/Family") setmetatable(M, { __index = BaseView }) local self = setmetatable({}, { __index = M }) self.class = 'FamilyMainZuoView' self._full = true self._full_offset = false self._fristRoom = true self:init('ui://Family/Main_zuo') return self end function M:init(url) BaseView.InitView(self, url) local view = self._view --退出按钮 view:GetChild('btn_exit').onClick:Set(function() ViewManager.ChangeView(ViewManager.View_Lobby) end) --亲友圈列表 self._viewList_familyList = view:GetChild('familyList') self._viewList_familyList.itemRenderer = handler(self, self.FamilyListRenderer) view:GetController('showList').onChanged:Set(function(context) if context.sender.selectedIndex == 0 then view:GetTransition('familyListExit'):Play(1, 0, function() view:GetChild('showList').visible = false end) else view:GetChild('showList').visible = true view:GetTransition('familyLisrShow'):Play(1, 0, function() end) end end) --房间列表 self._viewList_tableList = view:GetChild('list_roomTable') self._viewList_tableList.itemRenderer = handler(self, self.FamilyTableRenderer) view:GetChild('click_closePlayDetail').onClick:Set(function() view:GetController('showPlayDetail').selectedIndex = 0 end) --创建亲友圈和加入亲友圈 view:GetChild('btn_createFamily').onClick:Set(function() FamilyCreateView.new({}, function() self._viewList_familyList.numItems = #DataManager.groups end) end) view:GetChild('btn_joinFamily').onClick:Set(function() FamilyJoinView.new() end) --管理页面 view:GetChild('btn_manager').onClick:Set(function() FamilyManagerView.new({pageType=1}) end) --成员页面 view:GetChild('btn_menber').onClick:Set(function() FamilyManagerView.new({pageType=2}) end) --新玩法管理 view:GetChild('btn_showPlayEdit').onClick:Set(function() FamilyPlayListView.new({}) end) --充值房卡 view:GetChild('btn_chongFangka').onClick:Set(function() FamilyRoomCardView.new({}) end) end --列表渲染类函数-- function M:FamilyListRenderer(index, obj) local groupList = DataManager.groups.groupList obj:GetChild('text_name').text = groupList[index + 1].name obj:GetChild('text_num').text = string.format("在线:1") end function M:FamilyTableRenderer(index, obj) self._group = DataManager.CurrenGroup local playList = self._group.playList local roomList = self._group.rooms local tmp local showDeatilFct = function() end if index < #playList then -- 默认玩法,开桌子之类的 tmp = playList[index + 1] for i = 1, tmp.maxPlayers do local head = obj:GetChild(string.format("head%s", i)) head:GetChild('btn_head').icon = "" head.onClick:Set(function(context) self:ClickMachRoom(context, tmp) end) end obj:GetChild('icon').onClick:Set(function(context) self:ClickTableShowDetail({ type = 1, info = tmp, index = index }) end) if self._view:GetController('showPlayDetail').selectedIndex == 1 then self:ClickTableShowDetail({ type = 1, info = tmp, index = index }) end elseif index - #playList < #roomList then --存在的桌子 local roomInfo = roomList[index - #playList + 1] tmp = self._group:getPlay(roomInfo.pid) local plist = roomInfo.plist for i = 1, 4 do if i <= #plist then local btn = obj:GetChild(string.format("head%s", i)) btn:GetController('zuo').selectedIndex = 1 btn:GetChild('text_name').text = plist[i].nick ImageLoad.Load(plist[i].portrait, btn:GetChild('btn_head')._iconObject) else local btn = obj:GetChild(string.format("head%s", i)) btn:GetController('zuo').selectedIndex = 0 btn:GetChild("btn_head").icon = "ui://Family/icon_luozuo" btn.onClick:Set(function(context) self:ClickJoinRoom(context, roomInfo) end) end end obj:GetChild('icon').onClick:Set(function(context) self:ClickTableShowDetail({ type = 2, info = roomInfo, index = index }) end) if self._view:GetController('showPlayDetail').selectedIndex == 1 then self:ClickTableShowDetail({ type = 2, info = roomInfo, index = index }) end end obj:GetController('playerNum').selectedIndex = tmp.maxPlayers - 2 obj:GetChild('text_playName').text = tmp.name obj:GetChild('text_roundNum').text = string.format("(0/%s)", ExtendManager.GetExtendConfig(tmp.gameId):GetGameInfo():LoadConfigOneInfo(tmp.config, tmp.hpData, "maxRound") or 0) obj.icon = string.format("ui://Family/icon_table%s", (self.localTextDesk[tmp.gameId] or 0) + 1) end --进入亲友圈 function M:EnterFamily(index_family, only) local groups = DataManager.groups.groupList index_family = index_family or 1 if index_family > #groups then return end local fgCtr = ControllerManager.GetController(NewGroupController) local familyId = groups[index_family].id fgCtr:FG_EnterGroup(familyId, function(res) if res.ReturnCode ~= 0 then if only then ViewUtil.ErrorTip(res.ReturnCode, "进入亲友圈失败") else self:EnterFamily(index_family + 1) end else DataManager.CurrenGroup = DataManager.groups:get(familyId) self._group = DataManager.CurrenGroup local view = self._view view:GetChild('text_familyName').text = self._group.name view:GetChild('text_familyid').text = self._group.id view:GetChild('text_fangka').text = self._group.groupDiamo self._viewList_familyList.selectedIndex = index_family - 1 self:UpdateRoom() end end) end --房间处理方法 function M:UpdateRoom() local group = self._group local playList = group.playList local roomList = group.rooms self._viewList_tableList.numItems = #playList + #roomList end --点击玩法创建桌子 function M:ClickMachRoom(context, playinfo) local group = DataManager.CurrenGroup local roomCtr = ControllerManager.GetController(RoomController) roomCtr:PublicJoinRoom( Protocol.WEB_FG_MATCH_ROOM, "", true, function(response) if (response.ReturnCode == -1) then ViewUtil.CloseModalWait2() ViewUtil.ErrorMsg(self._root_view, response.ReturnCode, 'response.ReturnCode == -1') -- RestartGame() return end if response.ReturnCode ~= 0 then ViewUtil.CloseModalWait2() ViewUtil.ErrorMsg(self._root_view, response.ReturnCode, '进入房间失败') -- ViewManager.ChangeView(ViewManager.View_Lobby) return else UpdateBeat:Remove(self.OnUpdate, self) FamilyView.lastId = group.id ViewManager.ChangeView(ViewManager.View_Main, playinfo.gameId, { _flag_showTip = true }) ViewUtil.CloseModalWait2() end end, group.id, playinfo.id ) end --点击桌子查看信息 function M:ClickTableShowDetail(data) local data = data or {} if data.type then self._view:GetController('showPlayDetail').selectedIndex = 1 local detailView = self._view:GetChild('comp_playDetail') local detailType = detailView:GetController('type') local tableIcon = self._viewList_tableList:GetChildAt(data.index):GetChild('icon') local gxy = tableIcon:LocalToGlobal(Vector2.New(tableIcon.width, tableIcon.height) / 2) detailView.xy = self._view:GlobalToLocal(gxy) - Vector2.New(detailView.width / 2, detailView.height) local playinfo = data.info detailView:GetChild('btn_createRoom').onClick:Set(function(context) self:ClickMachRoom(context, data.info) end) detailView:GetChild('btn_joinRoom').onClick:Set(function(context) self:ClickJoinRoom(context, data.info) end) detailView:GetChild('btn_inviteRoom').onClick:Set(function(context) ViewUtil:ErrorTip("暂时还未联通微信") end) detailView:GetChild('btn_delRoom').onClick:Set(function(context) self:JieSanRomm(self._group.id, data.info.id) end) if data.type == 1 then detailType.selectedIndex = 0 elseif data.type == 2 then local stype = 1 if self._group.lev and self._group.lev == 1 then stype = stype + 2 end if playinfo.plist and #playinfo.plist > 0 and playinfo.plist[1].aid == DataManager.SelfUser.account_id then stype = stype + 1 end playinfo = self._group:getPlay(playinfo.pid) detailType.selectedIndex = stype end detailView:GetChild('text_playDetail').text = ExtendManager.GetExtendConfig(playinfo.gameId):GetGameInfo() :LoadConfigToDetail(playinfo.config, playinfo.hpData) end end --点击解散房间 function M:JieSanRomm(groupId, roomId) local _curren_msg = MsgWindow.new( self._root_view, '确定要解散该房间吗?', MsgWindow.MsgMode.OkAndCancel ) _curren_msg.onOk:Add( function() ViewUtil.ShowModalWait2(self._root_view) local fgCtr = ControllerManager.GetController(NewGroupController) fgCtr:FG_RemoveRoom( groupId, roomId, function(res) ViewUtil.CloseModalWait2() if res.ReturnCode ~= 0 then ViewUtil.ErrorTip(res.ReturnCode, '删除房间失败!') return end end ) end ) _curren_msg:Show() end --点击桌子进入游戏 function M:ClickJoinRoom(context, room) local group = DataManager.CurrenGroup local roomCtr = ControllerManager.GetController(RoomController) roomCtr:PublicJoinRoom( Protocol.WEB_FG_JOIN_ROOM, room.id, true, function(response) if (response.ReturnCode == -1) then ViewUtil.CloseModalWait2() ViewUtil.ErrorMsg(self._root_view, response.ReturnCode, 'response.ReturnCode == -1') -- RestartGame() return end if response.ReturnCode ~= 0 then ViewUtil.CloseModalWait2() ViewUtil.ErrorMsg(self._root_view, response.ReturnCode, '进入房间失败') -- ViewManager.ChangeView(ViewManager.View_Lobby) else UpdateBeat:Remove(self.OnUpdate, self) FamilyView.lastId = group.id ViewManager.ChangeView(ViewManager.View_Main, self._group:getPlay(room.pid).gameId, { _flag_showTip = true }) ViewUtil.CloseModalWait2() end end, group.id, room.pid ) end ----------------- function M:FillData() local view = self._view local groups = DataManager.groups.groupList self._viewList_familyList.numItems = #groups self.localTextDesk = FamilyPlayListView:EncodeDeskType() self:EnterFamily() end function M:Close() getmetatable(M).__index.Close(self) -- UpdateBeat:Remove(self.OnUpdate, self) coroutine.stopAll() BaseWindow.DestroyAll() DSTweenManager.ClearTween() end function M:Destroy() getmetatable(M).__index.Destroy(self) -- UpdateBeat:Remove(self.OnUpdate, self) coroutine.stopAll() BaseWindow.DestroyAll() DSTweenManager.ClearTween() end function M:Show() ViewUtil.ShowModalWait2() self:FillData() ViewUtil.CloseModalWait2() BaseView.Show(self) -- UpdateBeat:Add(self.OnUpdate, self) end return M