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

263 lines
8.4 KiB
Lua

local FamilyCreateView = import(".FamilyZuo.FamilyCreateView")
local FamilyJoinView = import(".FamilyZuo.FamilyJoinView")
local FamilyManagerView = import(".FamilyZuo.FamilyManagerView")
local FamilyPlayListView = import(".FamilyZuo.FamilyPlayListView")
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('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({})
end)
--新玩法管理
view:GetChild('btn_showPlayEdit').onClick:Set(function()
FamilyPlayListView.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
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
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, tmp, roomInfo)
end)
end
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)
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
self._viewList_familyList.selectedIndex = index_family - 1
self:UpdateRoom()
end
end)
end
--房间处理方法
function M:UpdateRoom()
local group = self._group
local playList = self._group.playList
local roomList = self._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:ClickJoinRoom(context, playinfo, 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, playinfo.gameId, { _flag_showTip = true })
ViewUtil.CloseModalWait2()
end
end,
group.id,
room.pid
)
end
-----------------
function M:FillData()
local groups = DataManager.groups.groupList
self._viewList_familyList.numItems = #groups
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