hengyang_client/lua_probject/base_project/Game/View/Lobby/CreateRoomView.lua

89 lines
2.7 KiB
Lua
Raw Normal View History

2025-04-01 10:48:36 +08:00
---创建房间View对象
local GameListView = import(".GameListView")
local CreateRoomView = {}
local M = CreateRoomView
function CreateRoomView.new(index)
setmetatable(M, { __index = BaseWindow })
local self = setmetatable({}, { __index = M })
self.class = "CreateRoomView"
self._animation = false
self._full = true
self._full_offset = false
self._modeMap = {}
self.selectedIndex = index
self._close_destroy = true
self._put_map = false
self._new_hide = false
self._queue = false
-- self:init("ui://Lobby/Win_CreateRoom")
self:init("ui://Lobby/CreatePlay")
return self
end
function M:init(url)
BaseWindow.init(self, url)
self.gl_view = GameListView.new(self._view, self.selectedIndex, nil, function(mode_data)
self:OnCreateRoom(mode_data)
end, true)
--self.gl_view.IsHallGame=true
end
function M:OnCreateRoom(mode_data)
if mode_data.type == 0 then
local mode = mode_data.data
--点击建房按钮后保存当前游戏的config
local _data = mode:SelectedConfigData()
2025-04-11 12:49:08 +08:00
---- print("OnCreateRoom================")
2025-04-01 10:48:36 +08:00
--pt(_data)
if not _data["stamina"] then _data["stamina"] = 0 end
local user_id = DataManager.SelfUser.account_id
local config_data = {}
local game_id = mode.game_data.game_id
config_data["game_id"] = game_id
config_data["version"] = mode.game_data.version
config_data["config"] = _data
Utils.SaveLocalFile(user_id, json.encode(config_data))
local loddyCtr = ControllerManager.GetController(LoddyController)
-- 对强制开启gps的玩法进行判断
if not DataManager.SelfUser.location then
DataManager.SelfUser.location = Location.new()
end
if _data["GPSDetection"] and _data["GPSDetection"] > 0 and DataManager.SelfUser.location:Location2String() == "" then
-- if DataManager.SelfUser.location:Location2String() == "" then
ViewUtil.ErrorTip(nil, "正在获取GPS定位请稍候重试。")
get_gps()
return
end
ViewUtil.ShowModalWait(self._root_view, "正在创建房间...")
loddyCtr:CreateRoom(game_id, _data, function(res)
self:__OnCreateRoomAction(res)
end)
end
end
function M:__OnCreateRoomAction(response)
ViewUtil.CloseModalWait()
if (response.ReturnCode == -2) then
return
end
if (response.ReturnCode ~= 0) then
ViewUtil.ErrorTip(response.ReturnCode, "创建房间失败")
return
end
self:Destroy()
if self.onCeateRoom then self.onCeateRoom() end
end
function M:Destroy()
self.gl_view:Destroy()
BaseWindow.Destroy(self)
end
return M