hengyang_client/lua_probject/base_project/Game/View/FamilyView.lua

1184 lines
38 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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 FamilyMsgDiamond = import(".Family.FamilyMsgDiamond")
---无窗口
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")
local FamilyChatRoom = import(".Family.FamilyChatRoom")
local FamilyMsgRecord = import(".Family.FamilyMsgRecord")
local PlayEditView = import(".Family.PlayEditView")
---
FamilyView = {}
local M = FamilyView
local function FamilyOnline(groupId, self)
self._mgr_ctr:FG_Get_Online_Member(groupId, function(res)
end)
end
local function FamilyOffline(groupId, self)
self._mgr_ctr:FG_Get_Offline_Member(groupId, function(res)
end)
end
-- 刷新申请的红点
local function ReflashJoinsRedPoint(self)
if self._group == nil then
return
end
local btn_myfamily = self._view:GetChild("btn_myfamily")
local btn_myfamilycRedPoint = btn_myfamily:GetController("cRedPoint")
local btn_myfamilyRedPointText = btn_myfamily:GetChild("tex_redPoint")
local _joins = 0
for _, group in pairs(DataManager.groups.groupList) do
local player = group.memberMap[DataManager.SelfUser.account_id]
--[[
if player.lev ~= 3 then
_joins = _joins + group.joins
return
end
]]
_joins = _joins + group.joins
end
btn_myfamilycRedPoint.selectedIndex = 0
if _joins > 0 then
btn_myfamilycRedPoint.selectedIndex = 1
end
local RpTex = _joins
if _joins > 99 then
RpTex = "99+"
end
btn_myfamilyRedPointText.text = RpTex
self:ChangeOther()
end
local function SortMembers(Members)
local re = {}
local online = {}
local playing = {}
local offline = {}
for _, player in pairs(Members) do
-- 在线 绿色状态
if player.online == 1 and player.playing ~= "startPlaying" then
online[#online + 1] = player
end
-- 在线游戏中 红色状态
if player.online == 1 and player.playing == "startPlaying" then
playing[#playing + 1] = player
end
-- 离线
if player.online == 0 then
offline[#offline + 1] = player
end
end
for _, player in pairs(online) do
re[#re + 1] = player
end
for _, player in pairs(playing) do
re[#re + 1] = player
end
for _, player in pairs(offline) do
re[#re + 1] = player
end
return re
end
function FamilyView.new()
--print("刘海屏Rect position:%s, height:%s, width:%s", Screen.safeArea.position, Screen.safeArea.height,Screen.safeArea.width)
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._close_destroy = false
self._full_offset = false
local view = self._view
self.lastTime = os.time()
--self.n393 = self._view:GetChild("n393")
--self.n393.text = "无信息"
--self.n393.text = string.format("刘海屏Rect position:%s, height:%s, width:%s", Screen.safeArea.position, Screen.safeArea.height, Screen.safeArea.width)
--self._child_familyAuditNumber = FamilyAuditNumber.new(self)
self.com_FamilyChatRoom = FamilyChatRoom:Init(view:GetChild('com_chatRoom'), self)
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.btn_chatRoom = view:GetChild("btn_chatRoom")
self.list_family = view:GetChild("list_family")
self.cChatRoomRedPoint = self.btn_chatRoom:GetController("cRedPoint")
self:InitCloseClick()
--[[
fgCtr:FG_GroupList(function(res)
print("获取所有圈信息")
pt(res)
local groups = res.Data.groups
if #groups > 0 then
self.familyType.selectedIndex = 1
self:ConnetFamily(1, groups, true)
else
self:JoinFamily(true)
self.btn_chatRoom.visible = false
end
end)
]]
-------绑定成员战绩按钮
view:GetChild('btn_family_record').onClick:Set(function()
self._child_familyNumberRecord = FamilyNumberRecord.New(self, 1)
self.lastType = 1
end)
view:GetChild('btn_person_record').onClick:Set(function()
self._child_familyNumberRecord = FamilyNumberRecord.New(self, 2)
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)
self.btn_chatRoom.onClick:Set(function()
--local view = FamilyChatRoom.New()
--view:Show()
--FamilyChatRoom:Show(self.ChatRoomData)
self.com_FamilyChatRoom:Show()
end)
self.list_family.itemRenderer = function(i, obj)
local j = i + 1
local group = DataManager.groups.groupList[j]
obj:GetChild("title").emojies = EmojiDitc.EmojiesDitc
obj.text = Utils.TextOmit(group.name, 6, "...")
obj.onClick:Add(function()
if self._group ~= nil and group.id == self._group.id then
--ViewUtil.ShowBannerOnScreenCenter("已在家族中")
return
end
self.curGroupIndex = j
self:ConnetFamily(j, DataManager.groups.groupList)
end)
end
self.familyType.selectedIndex = 1
end
function M:Reflash()
local fgCtr = ControllerManager.GetController(NewGroupController)
fgCtr:FG_GroupList(function(res)
print("获取所有圈信息")
pt(res)
if res.ReturnCode ~= 0 then
ViewUtil.ErrorTip(res.ReturnCode)
end
local groups = res.Data.groups
if #groups > 0 then
--self:ConnetFamily(1, groups)
self.list_family.numItems = #DataManager.groups.groupList
local chooseIndex = 1
local lastID = Utils.LoadLocalFile("Family_lastID" .. DataManager.SelfUser.account_id)
if lastID then
lastID = tonumber(lastID)
for i = 1, #DataManager.groups.groupList do
if lastID == DataManager.groups.groupList[i].id then
chooseIndex = i
end
end
end
local btn = self.list_family:GetChildAt(chooseIndex - 1)
btn.onClick:Call()
else
self:JoinFamily(true)
self.btn_chatRoom.visible = false
end
end)
end
function M:InitCloseClick()
self.btn_close.onClick:Set(function()
print("lingmeng InitCloseClick", self.lastType, self.familyType.selectedIndex)
if not self.lastType or self.familyType.selectedIndex == 1 then
if self._group then
FamilyOffline(self._group.id, self)
end
self._mgr_ctr:disconnect()
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:MsgView()
local view = FamilyMsgRecord.New()
view:Show(self._group.id)
end
function M:MsgDiamondView()
local view = FamilyMsgDiamond.New({ groupId = self._group.id })
view:Show()
end
function M:SetIsOpenChatRoom()
local mgr_ctr = ControllerManager.GetController(GroupMgrController)
if self._group.isOpenChatRoom == 1 then
mgr_ctr:FG_CLOSE_ISOPEN_CHATROOM(self._group.id, function(res)
print("不允许成员可以查看聊天室")
pt(res)
if res.ReturnCode ~= 0 then
ViewUtil.ErrorTip(res.ReturnCode)
return
end
self._group.isOpenChatRoom = 0
self:RefalshMoreBtn()
end)
elseif self._group.isOpenChatRoom == 0 then
mgr_ctr:FG_OPEN_ISOPEN_CHATROOM(self._group.id, function(res)
print("允许成员可以查看聊天室")
pt(res)
if res.ReturnCode ~= 0 then
ViewUtil.ErrorTip(res.ReturnCode)
return
end
self._group.isOpenChatRoom = 1
self:RefalshMoreBtn()
end)
end
end
function M:SetCanWatch()
local value = 1
if self._group.isWatch == 1 then
value = 0
elseif self._group.isWatch == 0 then
value = 1
end
local fgCtr = ControllerManager.GetController(NewGroupController)
fgCtr:SetCanWatch(self._group.id, value, function(res)
print("设置是否观战")
pt(res)
if res.ReturnCode ~= 0 then
ViewUtil.ErrorTip(res.ReturnCode)
return
end
self._group.isWatch = value
self:RefalshMoreBtn()
--
local fgCtr = ControllerManager.GetController(NewGroupController)
self:UpdateFamilyRoom(fgCtr, self._group.id)
end)
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 type(frist) ~= "boolean" or 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 type(frist) ~= "boolean" or 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
local view = PlayEditView.New()
view:Show(self._group.id)
end
function M:OpenMyFamily(groupId)
FamilyMyFamily:TryShow(groupId, self)
end
function M:AllNumber()
local view = FamilyAllNumbers.new()
view:Show(self._group)
end
function M:AuditNumber()
local view = FamilyAuditNumber.new(self)
view:Show(self._group)
--self.lastType = 1
--self._child_familyAuditNumber:Show()
--self._child_familyAuditNumber = FamilyAuditNumber.new(self)
end
function M:UpdataRedPointAuditNumber(obj)
if self._group.joins == nil or self._group.joins <= 0 then
obj:GetController("cRedPoint").selectedIndex = 0
return
end
local redPointNum = self._group.joins
if redPointNum > 99 then
redPointNum = "99+"
end
obj:GetController("cRedPoint").selectedIndex = 1
obj:GetChild("tex_redPoint").text = redPointNum
end
function M:ShowShop()
--self._child_familyLobbyShopView = LobbyShopView.new(self, self._group.id)
--self._child_familyLobbyShopView:Show()
FamilyRoomCard:TryShow(self._group.id)
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)
local view = FamilyAllNumbers.new()
view:Show(group)
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()
self:RefalshMoreBtn()
end
function M:BanFamily()
local fgCtr = ControllerManager.GetController(NewGroupController)
local data = {
id = self._group.id,
ban = not self._group.ban
}
fgCtr:FG_UpdateGroupInfo(data,
function(res)
if res.ReturnCode ~= 0 then
ViewUtil.ErrorTip(res.ReturnCode, "一键打样失败")
else
self:ReflashBan()
self:RefalshMoreBtn()
end
end)
end
function M:ReflashBan()
self._view:GetController('familyBan').selectedIndex = self._group.ban and 1 or 0
end
function M:BanDeskmate()
self.FamilyBanDesk = FamilyBanDesk:TryShow(self)
end
function M:ReflashMember()
self.members = SortMembers(self._group.members)
local list_familyNumber = self._view:GetChild('list_familyNumber')
if list_familyNumber.itemRenderer == nil then
return
end
if list_familyNumber.numItems == #self._group.members then
list_familyNumber:RefreshVirtualList()
else
list_familyNumber.numItems = #self._group.members
end
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)
self.members = SortMembers(self._group.members) --local members = self._group.members
print("FG_GroupMembers12")
pt(self._group.members)
--ViewUtil:CloseModalWait()
if res.ReturnCode ~= 0 then
ViewUtil.ErrorTip(res.ReturnCode, "获取成员列表失败")
else
list_familyNumber.itemRenderer = function(index, obj)
local player = self.members[index + 1]
obj:GetChild('title').emojies = EmojiDitc.EmojiesDitc
obj:GetChild('title').text = Utils.TextOmit(player.nick, 5, "...")
local state = 0
if player.online == 1 and player.playing == "startPlaying" then
state = 2
elseif player.online == 1 and player.playing ~= "startPlaying" then
state = 1
elseif player.online == 0 then
state = 0
end
obj:GetController('type').selectedIndex = state
local loader_icon = obj:GetChild("btn_head"):GetChild("icon")
ImageLoad.Load(player.portrait, loader_icon)
end
--list_familyNumber.numItems = #self._group.members
list_familyNumber.numItems = #self.members
self:ChangeOther()
return 1
end
end)
return 0
end
function M:EnterGroup(fgCtr, id)
fgCtr:FG_EnterGroup(id, function(res)
ViewUtil:CloseModalWait()
if res.ReturnCode ~= 0 then
ViewUtil.ErrorTip(res.ReturnCode, "获取房间列表列表失败")
else
self:OnEnterGroupCallBack()
return 1
end
end)
return 0
end
function M:OnEnterGroupCallBack()
local fgCtr = ControllerManager.GetController(NewGroupController)
self._view:GetController('familyBan').selectedIndex = self._group.ban and 1 or 0
FamilyOnline(self._group.id, self)
ViewUtil.ShowModalWait(self._root_view, "正在加载成员列表中......")
self:ChangeNumber(fgCtr, self._group.id, 0, self._group.total_member_num, false, 1)
ViewUtil.ShowModalWait(self._root_view, "正在加载房间列表中......")
self:UpdateFamilyRoom(fgCtr, self._group.id)
--ViewUtil.ShowModalWait(self._root_view, "正在加载亲友圈权限中......")
--self:ChangeOther()
ViewUtil.CloseModalWait()
self:ReflashChatRoomRedPoint()
ReflashJoinsRedPoint(self)
self:ReflashChatRoomBtn()
fgCtr:FG_Get_Online_Member(self._group.id, function(res)
end)
fgCtr:FG_Get_Apply_Count(function(res)
print("收到获得申请列表的数量")
pt(res)
if res.ReturnCode ~= 0 then
return
end
self:ChangeOther()
end)
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()
local playList = self._group.playList
local roomList = self._group.rooms
self._view:GetChild('n364').text = string.format("已开启%s桌游戏", #roomList)
local roomCtr = ControllerManager.GetController(RoomController)
--先对房间进行一波分类
local readyRoom = {}
local startRoom = {}
for k, v in pairs(roomList) do
table.insert(v.status == 0 and readyRoom or startRoom, v)
end
local all_num = #playList + #roomList
list_room.itemRenderer = function(index, obj)
if index < #readyRoom then
local newIndex = index + 1
local playInfo = self._group:getPlay(roomList[newIndex].pid)
self:FillSameRoomInfo(obj, 1, playInfo)
local plist = readyRoom[newIndex].plist
local insertName = ""
for i = 1, 4 do
if i <= #plist then
ImageLoad.Load(plist[i].portrait, obj:GetChild(string.format("player%d", i))._iconObject)
insertName = string.format("%s、%s", plist[i].nick, insertName)
else
local btn = obj:GetChild(string.format("player%d", i))
btn:GetChild("icon").url = "ui://Family/btn_mainGameNumberHead"
end
end
obj:GetChild('Label_joinPlayers').text = insertName
obj:GetChild('text_playerNum').text = string.format("%s/%s", #plist, playInfo.maxPlayers)
obj:GetChild('btn_joinGame').onClick:Set(function()
roomCtr:PublicJoinRoom(
Protocol.WEB_FG_JOIN_ROOM,
readyRoom[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
if response.ReturnCode == 10 then
self:EnterWitnesss(id, roomList[newIndex].id, playInfo.gameId, roomList[newIndex].pid)
return
end
ViewUtil.ErrorMsg(self._root_view, response.ReturnCode, '进入房间失败')
-- ViewManager.ChangeView(ViewManager.View_Lobby)
else
UpdateBeat:Remove(self.OnUpdate, self)
FamilyView.lastId = self._group.id
ViewManager.ChangeView(ViewManager.View_Main, playInfo.gameId, { _flag_showTip = true })
end
end,
id,
readyRoom[newIndex].pid
)
end)
obj:GetChild('btn_watch').onClick:Set(function()
self:EnterWitnesss(id, readyRoom[newIndex].id, playInfo.gameId, readyRoom[newIndex].pid)
end)
obj:GetChild('btn_jiesan').onClick:Set(function()
self:JieSanRomm(id, readyRoom[newIndex].id)
end)
elseif index >= all_num - #startRoom then
local newIndex = index - #readyRoom - #playList + 1
local playInfo = self._group:getPlay(startRoom[newIndex].pid)
self:FillSameRoomInfo(obj, 2, playInfo)
local plist = startRoom[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('text_playerNum').text = string.format("%s/%s", playInfo.maxPlayers, playInfo.maxPlayers)
obj:GetChild('text_roundNum').text = string.format("%s/%s", startRoom[newIndex].round,
startRoom[newIndex].times)
obj:GetChild('btn_joinGame').onClick:Clear()
obj:GetChild('btn_watch').onClick:Set(function()
self:EnterWitnesss(id, startRoom[newIndex].id, playInfo.gameId, startRoom[newIndex].pid)
end)
obj:GetChild('btn_jiesan').onClick:Set(function()
self:JieSanRomm(id, startRoom[newIndex].id)
end)
else
local newIndex = index - #readyRoom + 1
local playInfo = playList[newIndex]
self:FillSameRoomInfo(obj, 0, playInfo)
obj:GetChild('Label_joinPlayers').text = ""
for i = 1, 4 do
local btn = obj:GetChild(string.format("player%d", i))
btn:GetChild("icon").url = "ui://Family/btn_mainGameNumberHead"
--ImageLoad.Load("ui://Family/btn_mainGameNumberHead", obj:GetChild(string.format("player%d", i))._iconObject)
end
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)
FamilyView.lastId = self._group.id
ViewManager.ChangeView(ViewManager.View_Main, playList[newIndex].gameId,
{ _flag_showTip = true })
end
end,
id,
playList[newIndex].id
)
end)
obj:GetChild('btn_watch').onClick:Clear()
obj:GetChild('btn_jiesan').onClick:Clear()
end
end
-- print("=================================================list_room", list_room, list_room.numItems, all_num)
print("游戏中的房间")
pt(roomList)
--list_room.numItems = all_num
if list_room.numItems == all_num then
list_room:RefreshVirtualList()
else
list_room.numItems = all_num
end
end
--房间渲染
function M:FillSameRoomInfo(obj, type, playInfo)
local gameId = playInfo.gameId
local config = ExtendManager.GetExtendConfig(gameId)
local mode = config:GetGameInfo()
local gamePlay = mode:LoadConfigToDetail(playInfo.config, playInfo.hpData)
obj:GetChild('Label_gameRule').title = gamePlay
local roomName = playInfo.name
roomName = Utils.TextOmit(roomName, 6, "")
obj:GetChild('game_type').emojies = EmojiDitc.EmojiesDitc
obj:GetChild('game_type').text = string.format("%s%s", playInfo.game_name, roomName)
obj:GetChild('btn_joinGame'):GetController('type').selectedIndex = type
obj:GetChild('btn_watch').visible = self._group.isWatch and self._group.isWatch == 1
obj:GetChild('btn_jiesan').visible = self._group.lev < 3
obj:GetController('type').selectedIndex = type
obj:GetController('num').selectedIndex = playInfo.maxPlayers - 2
end
--点击进入观战
function M:EnterWitnesss(groupId, roomId, gameId, pid)
local roomCtr = ControllerManager.GetController(RoomController)
roomCtr:PublicWitnessRoom(
Protocol.WEB_FG_Witness_ROOM,
roomId,
groupId,
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)
FamilyView.lastId = self._group.id
ViewManager.ChangeView(ViewManager.View_Witness, gameId)
end
end,
gameId,
pid
)
end
--点击解散房间
function M:JieSanRomm(groupId, roomId)
local _curren_msg =
MsgWindow.new(
self._root_view,
'确定要解散该房间吗?',
MsgWindow.MsgMode.OkAndCancel
)
_curren_msg.onOk:Add(
function()
ViewUtil.ShowModalWait(self._root_view)
local fgCtr = ControllerManager.GetController(NewGroupController)
fgCtr:FG_RemoveRoom(
groupId,
roomId,
function(res)
if self._is_destroy then
return
end
ViewUtil.CloseModalWait()
if res.ReturnCode ~= 0 then
ViewUtil.ErrorTip(res.ReturnCode, '删除房间失败!')
return
end
end
)
end
)
_curren_msg:Show()
end
function M:ReflashFamilyList()
local list_family = self._view:GetChild('list_family')
list_family.numItems = #DataManager.groups.groupList
end
function M:ConnetFamily(index, groups)
if self._group then
FamilyOffline(self._group.id, self)
end
UpdateBeat:Remove(self.OnUpdate, self)
ViewUtil:CloseModalWait()
self._group = DataManager.groups:get(groups[index].id)
DataManager.CurrenGroup = self._group
self._view:GetChild('text_familyId').text = self._group.id
self._view:GetController('lev').selectedIndex = self._group.lev - 1
print("===================================self._group")
pt(self._group)
self._roomNum = self._group.room_num
local fgCtr = ControllerManager.GetController(NewGroupController)
ViewUtil.ShowModalWait(self._root_view, "正在进入亲友圈......")
Utils.SaveLocalFile("Family_lastID" .. DataManager.SelfUser.account_id, self._group.id)
self:EnterGroup(fgCtr, self._group.id)
--[[
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:EnterGroup(fgCtr, self._group.id)
]]
UpdateBeat:Add(self.OnUpdate, self)
if self._group.isOpenChatRoom == 1 then
self.btn_chatRoom.visible = true
else
self.btn_chatRoom.visible = false
end
end
-- function M:Destroy()
-- UpdateBeat:Remove(self.OnUpdate, self)
-- BaseView:Destroy()
-- end
function M:OnUpdate()
local fgCtr = ControllerManager.GetController(NewGroupController)
local newTime = 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
local HeartbeatTime = 10
if newTime - self.lastTime > HeartbeatTime then
fgCtr:FG_SetFamilyHeartbeat(self._group.id, DataManager.SelfUser.account_id, function(res)
print(res)
end)
self.lastTime = newTime
if self._view:GetChild('list_familyNumber').itemRenderer then
self.members = SortMembers(self._group.members) --local members = self._group.members
self._view:GetChild('list_familyNumber').numItems = #self.members
end
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,
redPointFct = M.UpdataRedPointAuditNumber --开启红点
},
{
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,
redPointFct = M.UpdataRedPointAuditNumber --开启红点
},
{
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.MsgView
},
{
name = "房卡记录",
Fct = M.MsgDiamondView
},
{
name = "禁止同桌",
Fct = M.BanDeskmate
},
{
name = "关闭聊天室",
Fct = M.SetIsOpenChatRoom
},
{
name = "关闭旁观",
Fct = M.SetCanWatch
},
}
function M:ChangeOther()
local i = tonumber(self._group.lev) + 1
local otherList = IDENTITY_LIST[i].otherList
local list_other = self._view:GetChild('list_other')
self._lev = i
self._view:GetController('lev').selectedIndex = self._group.lev - 1
list_other:SetVirtual()
list_other.itemRenderer = function(index, obj)
local cfg = otherList[index + 1]
obj:GetChild('title').text = cfg.name
obj.onClick:Set(handler(self, cfg.Fct))
--print("cfg.redPointFct", cfg.redPointFct)
if cfg.redPointFct then
cfg.redPointFct(self, obj)
end
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)
local cfg = moreList[index + 1]
obj:GetChild('title').text = cfg.name
obj.onClick:Set(handler(self, cfg.Fct))
obj.onClick:Add(function()
self._view:GetController('moreBtn').selectedIndex = 0
end)
--print("cfg.redPointFct", cfg.redPointFct)
if cfg.redPointFct then
cfg.redPointFct(self, obj)
end
end
list_other.numItems = #moreList
end
function M:RefalshMoreBtn()
-- 有空优化吧
local tex = ""
if self._group.isOpenChatRoom == 1 then
tex = "关闭聊天室"
elseif self._group.isOpenChatRoom == 0 then
tex = "打开聊天室"
end
MORE_LIST[5].name = tex
local tex = ""
if self._group.isWatch == 1 then
tex = "关闭观战"
elseif self._group.isWatch == 0 then
tex = "打开观战"
end
MORE_LIST[6].name = tex
local tex = ""
if self._group.ban then
tex = "一键开启"
else
tex = "一键打烊"
end
MORE_LIST[1].name = tex
self:ChangeMore()
end
function M:ReflashChatRoomRedPoint()
self.cChatRoomRedPoint.selectedIndex = 0
if self._group.messageCount > 0 then
self.cChatRoomRedPoint.selectedIndex = 1
end
local tex = self._group.messageCount
if self._group.messageCount > 99 then
tex = "99+"
end
local tex_redPoint = self.btn_chatRoom:GetChild("tex_redPoint")
tex_redPoint.text = tex
end
function M:Show()
Broadcast.AddListener(BroadcastEvent.OnJoinsChange, ReflashJoinsRedPoint, self)
Broadcast.AddListener(BroadcastEvent.OnMemberChange, self.ReflashMember, self)
Broadcast.AddListener(BroadcastEvent.OnOutFamily, self.Reflash, self)
self._familyEventView:AddListener()
self:Reflash()
BaseView.Show(self)
end
function M:Close()
Broadcast.RemoveListener(BroadcastEvent.OnJoinsChange, ReflashJoinsRedPoint)
Broadcast.RemoveListener(BroadcastEvent.OnMemberChange, self.ReflashMember)
Broadcast.RemoveListener(BroadcastEvent.OnOutFamily, self.Reflash)
print("家族界面退出")
self._familyEventView:RemoveAll()
BaseView.Close(self)
end
function M:ReflashChatRoomBtn()
self.btn_chatRoom.visible = true
if self._group.lev == 3 and self._group.isOpenChatRoom == 0 then
self.btn_chatRoom.visible = false
end
end
return M