hengyang_client/lua_probject/base_project/Game/View/Family/CreatePlayView.lua

112 lines
3.6 KiB
Lua
Raw Permalink Normal View History

2025-04-01 10:48:36 +08:00
--设置窗口对象
local CreatePlayView = {}
local M = CreatePlayView
setmetatable(M, { __index = BaseWindow })
local PlayInfo = {
{
gameName = "麻将",
playListInfo = {
},
playList = {
}
}
}
function CreatePlayView.new()
UIPackage.AddPackage("base/Family/ui/Family")
local self = setmetatable({}, { __index = M })
self.class = 'CreatePlayView'
self._close_destroy = true
self:initePlayInfo()
self:init('ui://Family/CreatePlay')
return self
end
function M:init(url)
BaseWindow.init(self, url)
local view = self._view
-----设置游戏类型------------
self.gameNameCtl = view:GetController('gameName')
local list_gameName = view:GetChild('list_gameName')
list_gameName:SetVirtual()
list_gameName.itemRenderer = function(index, obj)
obj:GetChild('title').text = PlayInfo[index + 1].gameName
end
-- list_gameName.onClickItem:Add()
list_gameName.numItems = #PlayInfo
list_gameName:GetChildAt(0):GetController('button').selectedIndex = 1
-----------设置游戏名称-------------------
self.playNameCtr = view:GetController('playName')
local list_playName = view:GetChild('list_playName')
list_playName:SetVirtual()
list_playName.itemRenderer = function(index, obj)
obj:GetChild('title').text = PlayInfo[1].playList[index + 1].playName
end
list_playName.onClickItem:Add(function()
self.showView.visible = false
local index = PlayInfo[1].playList[self.playNameCtr.selectedIndex + 1].playeId
2025-04-11 12:49:08 +08:00
local playDetail = view:GetChild(string.format("Label_Detail_%d", index))
2025-04-01 10:48:36 +08:00
local playView
if not playDetail then
2025-04-11 12:49:08 +08:00
playDetail = UIPackage.CreateObjectFromURL(string.format("ui//Family/Label_Detail_%d", index))
2025-04-01 10:48:36 +08:00
if playDetail then
playView = view:AddChild(playDetail)
2025-04-11 12:49:08 +08:00
playView.name = string.format("Label_Detail_%d", index)
2025-04-01 10:48:36 +08:00
end
end
if not playDetail then
view:GetChild('buttom').visible = false
else
view:GetChild('buttom').visible = true
self.showView = playView and playView or playDetail
self.showView.visible = true
end
end)
list_playName.numItems = #PlayInfo[1].playList
list_playName:GetChildAt(0):GetController('button').selectedIndex = 1
self.showView = view:GetChild(string.format("Label_Detail_%d",
PlayInfo[1].playList[self.playNameCtr.selectedIndex + 1].playeId))
-----------创建玩法----------
2025-04-11 12:49:08 +08:00
view:GetChild('btn_Create').onClick:Add(function()
self:CreatePlay()
end)
2025-04-01 10:48:36 +08:00
end
function M:CreatePlay()
2025-04-11 12:49:08 +08:00
ViewUtil.ShowModalWait(self._root_view, "正在创建房间...")
2025-04-01 10:48:36 +08:00
local loddyCtr = ControllerManager.GetController(LoddyController)
2025-04-11 12:49:08 +08:00
local gameId = PlayInfo[1].playList[self.playNameCtr.selectedIndex + 1].playeId
2025-04-01 10:48:36 +08:00
local config = ExtendManager.GetExtendConfig(gameId)
2025-04-11 12:49:08 +08:00
-- print("==============================config")
2025-04-01 10:48:36 +08:00
pt(config)
local mode = config:GetGameInfo()
2025-04-11 12:49:08 +08:00
-- print("==============================mode")
2025-04-01 10:48:36 +08:00
pt(mode)
local _data = mode:SelectedConfigData()
2025-04-11 12:49:08 +08:00
-- print("==============================_data")
2025-04-01 10:48:36 +08:00
pt(_data)
-- loddyCtr:CreateRoom(gameId,_data, function (res)
-- self:__OnCreateRoomAction(res)
-- end)
2025-11-06 17:37:53 +08:00
ViewUtil.CloseModalWait2()
2025-04-01 10:48:36 +08:00
end
function M:initePlayInfo()
local games = DataManager.SelfUser.games
for i = 1, #games do
if PlayInfo[1].playListInfo[games[i].game_id] then
2025-04-11 12:49:08 +08:00
table.insert(PlayInfo[1].playList, PlayInfo[1].playListInfo[games[i].game_id])
2025-04-01 10:48:36 +08:00
end
end
pt(PlayInfo)
end
return M