handle close event in lua
This commit is contained in:
parent
806fb5995f
commit
a3721b3a11
2
TODO
2
TODO
|
@ -2,7 +2,6 @@
|
||||||
[bart] a class for binding hotkeys
|
[bart] a class for binding hotkeys
|
||||||
[bart] review directories loading search
|
[bart] review directories loading search
|
||||||
[bart] load modules from zip packages
|
[bart] load modules from zip packages
|
||||||
[bart] capture close application events in lua (old setOnClose)
|
|
||||||
[bart] create a class for reading binary files
|
[bart] create a class for reading binary files
|
||||||
[bart] rework lua/c++ logger
|
[bart] rework lua/c++ logger
|
||||||
[bart] save lists on config manager
|
[bart] save lists on config manager
|
||||||
|
@ -67,6 +66,7 @@
|
||||||
[bart] chat with tabs
|
[bart] chat with tabs
|
||||||
[bart] limit FPS in options
|
[bart] limit FPS in options
|
||||||
[baxnie] display 'You are dead.' message
|
[baxnie] display 'You are dead.' message
|
||||||
|
[baxnie] display exit box when exiting from game
|
||||||
[baxnie] do lua game event calls from Game instead from GameProtocol
|
[baxnie] do lua game event calls from Game instead from GameProtocol
|
||||||
[baxnie] classic control
|
[baxnie] classic control
|
||||||
[baxnie] trade window
|
[baxnie] trade window
|
||||||
|
|
|
@ -10,6 +10,14 @@ function fatal(msg)
|
||||||
Logger.log(LogFatal, msg)
|
Logger.log(LogFatal, msg)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function setonclose(func)
|
||||||
|
g_app.onClose = func
|
||||||
|
end
|
||||||
|
|
||||||
|
function exit()
|
||||||
|
g_app.exit()
|
||||||
|
end
|
||||||
|
|
||||||
function connect(object, signalsAndSlots, pushFront)
|
function connect(object, signalsAndSlots, pushFront)
|
||||||
for signal,slot in pairs(signalsAndSlots) do
|
for signal,slot in pairs(signalsAndSlots) do
|
||||||
if not object[signal] then
|
if not object[signal] then
|
||||||
|
|
|
@ -60,5 +60,15 @@ function Game.onDeath()
|
||||||
print('dead')
|
print('dead')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function onApplicationClose()
|
||||||
|
print('close app')
|
||||||
|
if Game.isOnline() then
|
||||||
|
Game.logout(false)
|
||||||
|
else
|
||||||
|
exit()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
setonclose(onApplicationClose)
|
||||||
connect(Game, { onLogin = Game.createInterface }, true)
|
connect(Game, { onLogin = Game.createInterface }, true)
|
||||||
connect(Game, { onLogout = Game.destroyInterface })
|
connect(Game, { onLogout = Game.destroyInterface })
|
||||||
|
|
|
@ -212,6 +212,15 @@ void Application::poll()
|
||||||
g_dispatcher.poll();
|
g_dispatcher.poll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Application::close()
|
||||||
|
{
|
||||||
|
g_lua.getGlobalField("g_app", "onClose");
|
||||||
|
if(!g_lua.isNil())
|
||||||
|
g_lua.protectedCall();
|
||||||
|
else
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
void Application::render()
|
void Application::render()
|
||||||
{
|
{
|
||||||
// everything is rendered by UI components
|
// everything is rendered by UI components
|
||||||
|
|
|
@ -41,7 +41,7 @@ public:
|
||||||
virtual void run();
|
virtual void run();
|
||||||
virtual void exit();
|
virtual void exit();
|
||||||
virtual void poll();
|
virtual void poll();
|
||||||
virtual void close() { exit(); }
|
virtual void close();
|
||||||
|
|
||||||
void setPollCycleDelay(int delay) { m_pollCycleDelay = delay; }
|
void setPollCycleDelay(int delay) { m_pollCycleDelay = delay; }
|
||||||
|
|
||||||
|
|
|
@ -234,6 +234,10 @@ void Application::registerLuaFunctions()
|
||||||
// Protocol
|
// Protocol
|
||||||
g_lua.registerClass<Protocol>();
|
g_lua.registerClass<Protocol>();
|
||||||
|
|
||||||
|
// Application
|
||||||
|
g_lua.registerStaticClass("g_app");
|
||||||
|
g_lua.bindClassStaticFunction("g_app", "exit", std::bind(&Application::exit, g_app));
|
||||||
|
|
||||||
// ConfigManager
|
// ConfigManager
|
||||||
g_lua.registerStaticClass("g_configs");
|
g_lua.registerStaticClass("g_configs");
|
||||||
g_lua.bindClassStaticFunction("g_configs", "set", std::bind(&ConfigManager::set, &g_configs, _1, _2));
|
g_lua.bindClassStaticFunction("g_configs", "set", std::bind(&ConfigManager::set, &g_configs, _1, _2));
|
||||||
|
@ -241,7 +245,7 @@ void Application::registerLuaFunctions()
|
||||||
g_lua.bindClassStaticFunction("g_configs", "exists", std::bind(&ConfigManager::exists, &g_configs, _1));
|
g_lua.bindClassStaticFunction("g_configs", "exists", std::bind(&ConfigManager::exists, &g_configs, _1));
|
||||||
g_lua.bindClassStaticFunction("g_configs", "remove", std::bind(&ConfigManager::remove, &g_configs, _1));
|
g_lua.bindClassStaticFunction("g_configs", "remove", std::bind(&ConfigManager::remove, &g_configs, _1));
|
||||||
|
|
||||||
|
// PlatformWindow
|
||||||
g_lua.registerStaticClass("g_window");
|
g_lua.registerStaticClass("g_window");
|
||||||
g_lua.bindClassStaticFunction("g_window", "move", std::bind(&PlatformWindow::move, &g_window, _1));
|
g_lua.bindClassStaticFunction("g_window", "move", std::bind(&PlatformWindow::move, &g_window, _1));
|
||||||
g_lua.bindClassStaticFunction("g_window", "resize", std::bind(&PlatformWindow::resize, &g_window, _1));
|
g_lua.bindClassStaticFunction("g_window", "resize", std::bind(&PlatformWindow::resize, &g_window, _1));
|
||||||
|
|
|
@ -54,7 +54,6 @@ void OTClient::registerLuaFunctions()
|
||||||
g_lua.bindClassStaticFunction("g_sprites", "isLoaded", std::bind(&SpriteManager::isLoaded, &g_sprites));
|
g_lua.bindClassStaticFunction("g_sprites", "isLoaded", std::bind(&SpriteManager::isLoaded, &g_sprites));
|
||||||
g_lua.bindClassStaticFunction("g_sprites", "getSignature", std::bind(&SpriteManager::getSignature, &g_sprites));
|
g_lua.bindClassStaticFunction("g_sprites", "getSignature", std::bind(&SpriteManager::getSignature, &g_sprites));
|
||||||
|
|
||||||
g_lua.bindGlobalFunction("exit", std::bind(&Application::exit, g_app));
|
|
||||||
g_lua.bindGlobalFunction("getOufitColor", Outfit::getColor);
|
g_lua.bindGlobalFunction("getOufitColor", Outfit::getColor);
|
||||||
|
|
||||||
g_lua.registerClass<ProtocolLogin, Protocol>();
|
g_lua.registerClass<ProtocolLogin, Protocol>();
|
||||||
|
|
|
@ -39,10 +39,3 @@ void OTClient::init(const std::vector<std::string>& args)
|
||||||
g_modules.ensureModuleLoaded("client");
|
g_modules.ensureModuleLoaded("client");
|
||||||
g_modules.autoLoadModules(1000);
|
g_modules.autoLoadModules(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OTClient::close()
|
|
||||||
{
|
|
||||||
if(g_game.isOnline())
|
|
||||||
g_game.logout(true);
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
|
|
|
@ -31,7 +31,6 @@ class OTClient : public Application
|
||||||
public:
|
public:
|
||||||
OTClient();
|
OTClient();
|
||||||
void init(const std::vector<std::string>& args);
|
void init(const std::vector<std::string>& args);
|
||||||
void close();
|
|
||||||
void registerLuaFunctions();
|
void registerLuaFunctions();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue