194 lines
5.1 KiB
Lua
194 lines
5.1 KiB
Lua
|
|
require "Game.View.init"
|
||
|
|
|
||
|
|
---
|
||
|
|
-- a net ViewManager
|
||
|
|
ViewManager = {
|
||
|
|
|
||
|
|
-- View_Login = 1,
|
||
|
|
View_LoginNew = 1,
|
||
|
|
|
||
|
|
View_Lobby = 2,
|
||
|
|
|
||
|
|
-- View_Main = 3,
|
||
|
|
View_MainNew = 3,
|
||
|
|
|
||
|
|
View_PlayBack = 4,
|
||
|
|
|
||
|
|
View_Game = 5,
|
||
|
|
|
||
|
|
View_CreateCardGame = 6,
|
||
|
|
|
||
|
|
View_CreateUnitView = 7,
|
||
|
|
|
||
|
|
View_GameGroup = 8,
|
||
|
|
|
||
|
|
View_Match = 9,
|
||
|
|
View_Filter = 10,
|
||
|
|
View_Shop = 11,
|
||
|
|
View_Wallet = 12,
|
||
|
|
View_Other = 13
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
local _viewClassMap = {}
|
||
|
|
local _currenView = nil
|
||
|
|
local _viewMap = {}
|
||
|
|
|
||
|
|
local _curren_msg
|
||
|
|
local function __NetTip(txt_msg)
|
||
|
|
if _curren_msg then
|
||
|
|
_curren_msg:Destroy()
|
||
|
|
_curren_msg = nil
|
||
|
|
end
|
||
|
|
-- 断网时关闭托管
|
||
|
|
if _currenView.UnmarkSelfTuoguan then
|
||
|
|
_currenView:UnmarkSelfTuoguan()
|
||
|
|
end
|
||
|
|
_curren_msg = BaseWindow.new("ui://Common/Win_ConnectTip", _currenView._root_view)
|
||
|
|
local view = _curren_msg._view
|
||
|
|
view:GetChild("tex_message").text = txt_msg
|
||
|
|
view:GetChild("btn_connect").onClick:Set(function()
|
||
|
|
_curren_msg:Destroy()
|
||
|
|
_curren_msg = nil
|
||
|
|
NetResetConnectWindow.ShowNetReset()
|
||
|
|
ControllerManager.reset_join_room = 0
|
||
|
|
ControllerManager.ResetJionRoom()
|
||
|
|
end)
|
||
|
|
view:GetChild("btn_back").onClick:Set(function()
|
||
|
|
_curren_msg:Destroy()
|
||
|
|
_curren_msg = nil
|
||
|
|
NetResetConnectWindow.CloseNetReset()
|
||
|
|
ControllerManager.ChangeController(LoddyController)
|
||
|
|
ViewManager.ChangeView(ViewManager.View_Lobby)
|
||
|
|
end)
|
||
|
|
_curren_msg._close_zone = false
|
||
|
|
_curren_msg._animation = false
|
||
|
|
_curren_msg:Show()
|
||
|
|
end
|
||
|
|
|
||
|
|
local function __OnGameConnectAction(state)
|
||
|
|
--print("state:"..state)
|
||
|
|
NetResetConnectWindow.CloseNetReset()
|
||
|
|
if state == SocketCode.Connect then
|
||
|
|
ViewManager.ChangeView(ViewManager.View_Main, DataManager.CurrenRoom.game_id)
|
||
|
|
return
|
||
|
|
elseif state == SocketCode.DisconnectByServer then
|
||
|
|
__NetTip("网络断开连接!")
|
||
|
|
elseif state == SocketCode.ExceptionOnConnect or state == SocketCode.NetworkException then
|
||
|
|
__NetTip("请检查您的网络环境!")
|
||
|
|
elseif state == SocketCode.Disconnect then
|
||
|
|
ControllerManager.ChangeController(LoddyController)
|
||
|
|
ViewManager.ChangeView(ViewManager.View_Lobby)
|
||
|
|
else
|
||
|
|
NetResetConnectWindow.ShowNetReset()
|
||
|
|
end
|
||
|
|
ViewUtil.CloseModalWait()
|
||
|
|
end
|
||
|
|
|
||
|
|
function ViewManager.Init()
|
||
|
|
-- _viewClassMap[ViewManager.View_Login] = LoginView
|
||
|
|
-- _viewClassMap[ViewManager.View_Lobby] = LobbyView
|
||
|
|
_viewClassMap[ViewManager.View_LoginNew] = LoginViewNew
|
||
|
|
_viewClassMap[ViewManager.View_MainNew] = MainViewNew
|
||
|
|
_viewClassMap[ViewManager.View_Game] = GameView
|
||
|
|
_viewClassMap[ViewManager.View_CreateCardGame] = CreateCardGameView
|
||
|
|
_viewClassMap[ViewManager.View_CreateUnitView] = CreateUnitView
|
||
|
|
_viewClassMap[ViewManager.View_GameGroup] = GameGroupView
|
||
|
|
_viewClassMap[ViewManager.View_Match] = MatchView
|
||
|
|
_viewClassMap[ViewManager.View_Filter] = FilterView
|
||
|
|
_viewClassMap[ViewManager.View_Shop] = ShopView
|
||
|
|
_viewClassMap[ViewManager.View_Wallet] = WalletView
|
||
|
|
_viewClassMap[ViewManager.View_Other] = OtherView
|
||
|
|
|
||
|
|
ControllerManager.OnGameConnect = __OnGameConnectAction
|
||
|
|
|
||
|
|
ControllerManager.WebClient.holdCallback = function(response)
|
||
|
|
if response.ReturnCode == Table_Error_code.ERR_LOGOUT then
|
||
|
|
PlayerPrefs.DeleteKey("session_id")
|
||
|
|
PlayerPrefs.Save()
|
||
|
|
end
|
||
|
|
if response.ReturnCode == -1 or response.ReturnCode == Table_Error_code.ERR_LOGOUT then
|
||
|
|
ViewUtil.CloseModalWait()
|
||
|
|
NetResetConnectWindow.CloseNetReset()
|
||
|
|
RestartGame()
|
||
|
|
return true
|
||
|
|
end
|
||
|
|
return false
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
function ViewManager.GetCurrenView()
|
||
|
|
return _currenView
|
||
|
|
end
|
||
|
|
|
||
|
|
function ViewManager.ChangeViewByClass(dview_class, callback)
|
||
|
|
if (_currenView ~= nil) then
|
||
|
|
if _currenView._close_destroy then
|
||
|
|
_currenView:Destroy()
|
||
|
|
_viewMap[_currenView.dview_class] = nil
|
||
|
|
else
|
||
|
|
_currenView:Close()
|
||
|
|
end
|
||
|
|
if _currenView._s_callback then
|
||
|
|
_currenView._s_callback()
|
||
|
|
end
|
||
|
|
end
|
||
|
|
local tem = _viewMap[dview_class]
|
||
|
|
if not tem then
|
||
|
|
tem = dview_class.new()
|
||
|
|
tem._s_callback = callback
|
||
|
|
_viewMap[dview_class] = tem
|
||
|
|
end
|
||
|
|
tem.Id = id
|
||
|
|
tem.dview_class = dview_class
|
||
|
|
tem:Show()
|
||
|
|
_currenView = tem
|
||
|
|
return tem
|
||
|
|
end
|
||
|
|
|
||
|
|
local last_game_id = 0
|
||
|
|
function ViewManager.ChangeView(id, game_id, callback)
|
||
|
|
local dview_class = _viewClassMap[id]
|
||
|
|
if not dview_class then
|
||
|
|
if last_game_id ~= 0 and last_game_id ~= game_id then
|
||
|
|
ExtendManager.GetExtendConfig(last_game_id):UnAssets()
|
||
|
|
end
|
||
|
|
local exconfig = ExtendManager.GetExtendConfig(game_id)
|
||
|
|
dview_class = exconfig:GetView(id)
|
||
|
|
last_game_id = game_id
|
||
|
|
end
|
||
|
|
if not dview_class then
|
||
|
|
return
|
||
|
|
end
|
||
|
|
return ViewManager.ChangeViewByClass(dview_class, callback)
|
||
|
|
end
|
||
|
|
|
||
|
|
function ViewManager.OnApplicationPause()
|
||
|
|
-- print("game pause")
|
||
|
|
if (_currenView ~= nil) then
|
||
|
|
_currenView:OnApplicationPause()
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
function ViewManager.OnApplicationActive()
|
||
|
|
-- print("game active")
|
||
|
|
if (_currenView ~= nil) then
|
||
|
|
_currenView:OnApplicationActive()
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
function ViewManager.refreshGameView()
|
||
|
|
NetResetConnectWindow.ShowNetReset()
|
||
|
|
|
||
|
|
if DataManager.CurrenRoom then
|
||
|
|
ControllerManager.reset_join_room = 0
|
||
|
|
|
||
|
|
ControllerManager.ResetJionRoom()
|
||
|
|
else
|
||
|
|
NetResetConnectWindow.CloseNetReset()
|
||
|
|
ControllerManager.ChangeController(LoddyController)
|
||
|
|
ViewManager.ChangeView(ViewManager.View_Lobby)
|
||
|
|
end
|
||
|
|
end
|