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

542 lines
18 KiB
Lua
Raw Normal View History

2025-04-01 10:48:36 +08:00
local FamilyInviteFamilyView = import('.Family.FamilyInviteFamilyView')
local CreatePlayView = import('.Family.CreatePlayView')
local GroupMngGameListView = import(".NewGroup.MngView/GroupMngGameListView")
--设置窗口对象
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.list_room = self._view:GetChild('list_room')
local createOrJoin = view:GetController('createOrJoin')
self.familyType = view:GetController('familyType')
local btn_close = view:GetChild('btn_close')
btn_close.onClick:Set(function()
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
createOrJoin.selectedIndex = (createOrJoin.selectedIndex + 1) % 2
end
end
end)
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.familyType.selectedIndex = 3
end
end)
--------初始化创建和加入亲友圈界面---------------
self._currenIndex = 0
self.tex_num = view:GetChild('text_inputNum')
view:GetChild('btn_joinFamily').onClick:Add(function()
createOrJoin.selectedIndex = 1
self.lastType = 3
end)
view:GetChild('btn_createFamily').onClick:Add(function()
createOrJoin.selectedIndex = 0
self.lastType = 3
end)
view:GetChild('list_num').onClickItem:Set(handler(self, self.OnNumButtonAction))
local input_name = view:GetChild('input_name')
local input_wxId = view:GetChild('input_wxId')
input_name.onChanged:Set(function()
input_name.alpha = 1
end)
input_name.onFocusOut:Set(function()
if #input_name.text > 0 then
input_name.alpha = 1
else
input_name.alpha = 0.5
end
end)
input_wxId.onChanged:Set(function()
input_wxId.alpha = 1
end)
input_wxId.onFocusOut:Set(function()
if #input_wxId.text > 0 then
input_wxId.alpha = 1
else
input_wxId.alpha = 0.5
end
end)
view:GetChild('btn_create').onClick:Add(function()
fgCtr:FG_GroupList(function(res)
local groups = res.Data.groups
if #groups > 0 then
for i = 1, #groups do
if groups[i].name == input_name.text then
fgCtr:FG_RemoveGroup(groups[i].id, function(res)
2025-04-01 16:47:54 +08:00
fgCtr:FG_CreateGroup(input_name.text, 1, 2, function(res)
2025-04-01 10:48:36 +08:00
if res.ReturnCode == 0 then
self.familyType.selectedIndex = 1
self:ConnetFamily(1, groups, true)
end
end)
end)
end
end
else
2025-04-01 16:47:54 +08:00
fgCtr:FG_CreateGroup(input_name.text, 1, 2, function(res)
2025-04-01 10:48:36 +08:00
if res.ReturnCode == 0 then
self.familyType.selectedIndex = 1
self:ConnetFamily(1, groups, true)
end
end)
end
end)
end)
end
function ShareWx(view)
local familyInviteFamilyView = FamilyInviteFamilyView.new()
familyInviteFamilyView:Show()
end
function CreateFamily(view)
view.familyType.selectedIndex = 3
view.lastType = 1
view._view:GetController('createOrJoin').selectedIndex = 0
end
function JoinFamily(view)
view.familyType.selectedIndex = 3
view.lastType = 1
view._view:GetController('createOrJoin').selectedIndex = 1
end
function PlayEdit(view)
view.familyType.selectedIndex = 2
view.lastType = 1
end
local IDENTITY_LIST = {
{
level = 0, --圈主
},
{
level = 1, --副圈主
otherList = {
{
name = "邀请朋友",
Fct = ShareWx
},
{
name = "游戏记录",
Fct = ShareWx
},
{
name = "玩法管理",
Fct = PlayEdit
},
{
name = "充值房卡",
Fct = ShareWx
},
{
name = "申请消息",
Fct = ShareWx
},
{
name = "查看成员",
Fct = ShareWx
},
{
name = "创建亲友圈",
Fct = CreateFamily
},
{
name = "高级选项",
Fct = CreateFamily
},
{
name = "添加助理",
Fct = CreateFamily
},
{
name = "加入亲友圈",
Fct = JoinFamily
},
}
},
{
level = 2, --管理员
otherList = {
{
name = "邀请朋友",
Fct = ShareWx
},
{
name = "游戏记录",
Fct = ShareWx
},
{
name = "玩法管理",
Fct = PlayEdit
},
{
name = "充值房卡",
Fct = ShareWx
},
{
name = "申请消息",
Fct = ShareWx
},
{
name = "查看成员",
Fct = ShareWx
},
{
name = "创建亲友圈",
Fct = CreateFamily
},
{
name = "高级选项",
Fct = CreateFamily
},
{
name = "添加助理",
Fct = CreateFamily
},
{
name = "加入亲友圈",
Fct = JoinFamily
},
}
},
{
level = 3, --成员
otherList = {
{
name = "邀请朋友",
Fct = ShareWx
},
{
name = "创建亲友圈",
Fct = CreateFamily
},
{
name = "加入亲友圈",
Fct = JoinFamily
},
}
},
}
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('text').text = otherList[index + 1].name
obj.onClick:Add(handler(self, otherList[index + 1].Fct))
end
list_other.numItems = #otherList
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_GroupMembers(group_id, limit, num, minus_only, sort_type, function(res)
local members = res.Data.members
print("==========================res.Data.members")
pt(res.Data.members)
ViewUtil:CloseModalWait()
if res.ReturnCode ~= 0 then
ViewUtil.ErrorTip(res.ReturnCode, "获取成员列表失败")
else
list_familyNumber.itemRenderer = function(index, obj)
obj:GetChild('text_name').text = members[index + 1].nick
if self._lev ~= 3 then
if members[index + 1].hp < 777777 then
fgCtr:FG_ChangeFag(group_id, members[index + 1].uid, members[index + 1].hp + 777777,
function(res)
if res.ReturnCode == 0 then
else
ViewUtil.CloseModalWait('join_room')
ViewUtil.ErrorMsg(self._root_view, res.ReturnCode, '默认分配积分失败')
end
end)
end
end
end
list_familyNumber.numItems = res.Data.member_num
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)
return 1
end
end)
return 0
end
function M:UpdateFamilyRoom(fgCtr, id)
local list_room = self.list_room
list_room:SetVirtual()
local list_gamePlay = self._view:GetChild('list_gamePlay')
list_gamePlay:SetVirtual()
2025-04-01 13:56:18 +08:00
local playList = self._group.playList
local roomList = self._group.rooms
print("=========================playList,rooms")
pt(playList)
pt(roomList)
2025-04-01 10:48:36 +08:00
list_room.itemRenderer = function(index, obj)
if index < #roomList then
2025-04-01 17:21:53 +08:00
local newIndex = index + 1
2025-04-01 10:48:36 +08:00
-- local config = ExtendManager.GetExtendConfig(roomList[index + 1].pid)
-- local mode = config:GetGameInfo()
-- local gamePlay = mode:LoadConfigToDetail("这是房间")
-- obj:GetChild('Label_gameRule').title = gamePlay
2025-04-01 17:21:53 +08:00
obj:GetChild('game_type').text = string.format("房间-%s", roomList[newIndex].id)
2025-04-01 10:48:36 +08:00
obj:GetChild('btn_joinGame'):GetController('type').selectedIndex = 1
2025-04-01 13:56:18 +08:00
obj:GetChild('btn_joinGame').onClick:Set(function()
2025-04-01 10:48:36 +08:00
ViewUtil.ShowModalWait(self._root_view, "匹配房间中", 'join_room')
local roomCtr = ControllerManager.GetController(RoomController)
roomCtr:PublicJoinRoom(
2025-04-01 13:56:18 +08:00
Protocol.WEB_FG_JOIN_ROOM,
2025-04-01 17:21:53 +08:00
roomList[newIndex].id,
2025-04-01 13:56:18 +08:00
false,
2025-04-01 10:48:36 +08:00
function(response)
ViewUtil.CloseModalWait('join_room')
if (response.ReturnCode == -1) then
-- RestartGame()
return
end
if response.ReturnCode ~= 0 then
ViewUtil.ErrorMsg(self._root_view, response.ReturnCode, '进入房间失败')
-- ViewManager.ChangeView(ViewManager.View_Lobby)
return
else
ViewManager.ChangeView(ViewManager.View_Main, playList[index + 1].gameId)
end
end,
id,
2025-04-01 17:21:53 +08:00
roomList[newIndex].pid
2025-04-01 10:48:36 +08:00
)
end)
else
2025-04-01 17:21:53 +08:00
local newIndex = index - #roomList + 1
2025-04-01 10:48:36 +08:00
-- local config = ExtendManager.GetExtendConfig(playList[index - #roomList + 1].gameId)
-- local mode = config:GetGameInfo()
-- local gamePlay = mode:LoadConfigToDetail("随便甜点")
-- obj:GetChild('Label_gameRule').title = gamePlay
2025-04-01 17:21:53 +08:00
obj:GetChild('game_type').text = playList[newIndex].name
2025-04-01 10:48:36 +08:00
obj:GetChild('btn_joinGame'):GetController('type').selectedIndex = 0
2025-04-01 13:56:18 +08:00
obj:GetChild('btn_joinGame').onClick:Set(function()
2025-04-01 10:48:36 +08:00
ViewUtil.ShowModalWait(self._root_view, "匹配房间中", 'join_room')
local roomCtr = ControllerManager.GetController(RoomController)
fgCtr:FG_ChangeFag(id, DataManager.SelfUser.acc, 777777, function()
roomCtr:PublicJoinRoom(
Protocol.WEB_FG_MATCH_ROOM,
"",
true,
function(response)
ViewUtil.CloseModalWait('join_room')
if (response.ReturnCode == -1) then
-- RestartGame()
return
end
if response.ReturnCode ~= 0 then
ViewUtil.ErrorMsg(self._root_view, response.ReturnCode, '进入房间失败')
-- ViewManager.ChangeView(ViewManager.View_Lobby)
return
else
2025-04-01 17:21:53 +08:00
ViewManager.ChangeView(ViewManager.View_Main, playList[newIndex].gameId)
2025-04-01 10:48:36 +08:00
end
end,
id,
2025-04-01 17:21:53 +08:00
playList[newIndex].id
2025-04-01 10:48:36 +08:00
)
end)
end)
end
end
list_gamePlay.itemRenderer = function(index, obj)
if index == 0 then
obj:GetChild('num').text = string.format("%d/7", #playList)
obj:GetChild('btn_addPlay').onClick:Add(function()
local gl_view = GroupMngGameListView.new(id)
gl_view:Show()
gl_view:CreateCallBack(function()
self:UpdateFamilyRoom(fgCtr, id)
end)
end)
return
end
obj:GetChild('text_title').text = playList[index].game_name
obj:GetChild('Label_details'):GetChild('title').text = playList[index].config
obj:GetController('type').selectedIndex = 1
obj:GetChild('btn_del').onClick:Add(function()
fgCtr:FG_DelPlay(id, playList[index].id, function()
ViewUtil.ShowBannerOnScreenCenter("删除成功")
self:UpdateFamilyRoom(fgCtr, id)
end)
end)
end
2025-04-01 13:56:18 +08:00
print("=======================why", list_room.numItems, #playList, #roomList)
2025-04-01 10:48:36 +08:00
list_room.numItems = #playList + #roomList
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')
self._group = DataManager.groups:get(groups[index].id)
self._roomNum = self._group.room_num
if isCreate then
for i = 1, #groups do
local j = i
local child = UIPackage.CreateObjectFromURL('ui://Family/btn_familyName')
child:GetChild('name').text = groups[i].name
child.onClick:Add(function()
self:ConnetFamily(j, groups, false)
end)
if i == index then
child:GetController('button').selectedIndex = 1
end
list_family:AddChild(child)
end
end
local fgCtr = ControllerManager.GetController(NewGroupController)
ViewUtil.ShowModalWait(self._root_view, "正在加载亲友圈权限中......")
self:ChangeOther(tonumber(groups[index].lev) + 1)
allLoad = 1
ViewUtil.ShowModalWait(self._root_view, "正在加载成员列表中......")
allLoad = allLoad +
self:ChangeNumber(fgCtr, groups[index].id, 0, groups[index].total_member_num or groups[index].member_num, false,
1)
ViewUtil.ShowModalWait(self._root_view, "正在加载房间列表中......")
allLoad = allLoad + self:ConnetFamilyRoom(fgCtr, groups[index].id)
UpdateBeat:Add(self.OnUpdate, self)
end
----------创建和加入---------------------
function M:OnNumButtonAction(context)
local item = context.data
local index = self._view:GetChild('list_num'):GetChildIndex(item)
if index < 9 or index == 10 then
if (self._currenIndex < 6) then
self._currenIndex = self._currenIndex + 1
self.tex_num.text = self.tex_num.text .. (index < 9 and index + 1 or index - 9)
if (self._currenIndex == 6) then
self:JoinRoom(self.tex_num.text)
end
end
elseif index == 9 then
self:ClearNumTex()
else
if (self._currenIndex > 0) then
self._currenIndex = self._currenIndex - 1
self.tex_num.text = string.sub(self.tex_num.text, 0, self._currenIndex)
end
end
end
function M:ClearNumTex()
self.tex_num.text = ""
self._currenIndex = 0
end
function M:JoinRoom(roomId)
local fgCtr = ControllerManager.GetController(NewGroupController)
--后端似乎还未调通
-- fgCtr:FG_JoinGroup(roomId, function(res)
-- ViewUtil.ShowBannerOnScreenCenter("加入房间回调")
-- end)
--先换成邀请玩家
fgCtr:FG_AddMember(self._group.id, tonumber(roomId), function()
self:ChangeNumber(fgCtr, self._group.id, 0, (self._group.total_member_num or self._group.member_num) + 1, false,
1)
end)
end
function M:OnUpdate()
-- --12001事件
if self._group.update_room then
local fgCtr = ControllerManager.GetController(NewGroupController)
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
2025-04-01 16:56:04 +08:00
self._group.update_room = false
2025-04-01 17:21:53 +08:00
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
)
2025-04-01 10:48:36 +08:00
end
end
else
self._group.update_room = false
end
if self._fristRoom then
self._group.update_room = false
self._fristRoom = true
end
self:UpdateFamilyRoom(fgCtr, self._group.id)
end
end
return M