add option custom user script, otclientrc.lua

This commit is contained in:
Eduardo Bart
2012-01-07 19:10:06 -02:00
parent 060d8740f5
commit ef0c625c41
11 changed files with 53 additions and 10 deletions

View File

@@ -286,6 +286,10 @@ void Application::registerLuaFunctions()
g_lua.bindClassStaticFunction<Logger>("fireOldMessages", std::bind(&Logger::fireOldMessages, &g_logger));
g_lua.bindClassStaticFunction<Logger>("setOnLog", std::bind(&Logger::setOnLog, &g_logger, _1));
// Lua
g_lua.registerStaticClass("g_lua");
g_lua.bindClassStaticFunction("g_lua", "runScript", std::bind(&LuaInterface::runScript, &g_lua, _1));
// UI
g_lua.registerStaticClass("g_ui");
g_lua.bindClassStaticFunction("g_ui", "importStyle", std::bind(&UIManager::importStyle, &g_ui, _1));

View File

@@ -268,6 +268,11 @@ int Game::getThingStackpos(const ThingPtr& thing)
return 0;
}
void Game::talk(const std::string& message)
{
talkChannel(1, 0, message);
}
void Game::talkChannel(int channelType, int channelId, const std::string& message)
{
if(!m_online || !checkBotProtection())

View File

@@ -58,6 +58,7 @@ public:
void follow(const CreaturePtr& creature);
void cancelFollow();
void rotate(const ThingPtr& thing);
void talk(const std::string& message);
void talkChannel(int channelType, int channelId, const std::string& message);
void talkPrivate(int channelType, const std::string& receiver, const std::string& message);
void inviteToParty(int creatureId);

View File

@@ -108,6 +108,9 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassStaticFunction<Game>("removeVip", std::bind(&Game::removeVip, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("getAttackingCreature", std::bind(&Game::getAttackingCreature, &g_game));
g_lua.bindClassStaticFunction<Game>("getFollowingCreature", std::bind(&Game::getFollowingCreature, &g_game));
g_lua.bindClassStaticFunction<Game>("talk", std::bind(&Game::talk, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("talkChannel", std::bind(&Game::talkChannel, &g_game, _1, _2, _3));
g_lua.bindClassStaticFunction<Game>("talkPrivate", std::bind(&Game::talkPrivate, &g_game, _1, _2, _3));
g_lua.registerClass<UIItem, UIWidget>();
g_lua.bindClassStaticFunction<UIItem>("create", []{ return UIItemPtr(new UIItem); } );
@@ -125,8 +128,4 @@ void OTClient::registerLuaFunctions()
g_lua.registerClass<UIGame, UIWidget>();
g_lua.bindClassStaticFunction<UIGame>("create", []{ return UIGamePtr(new UIGame); } );
#ifdef FORBIDDEN_FUNCTIONS
g_lua.bindClassStaticFunction<Game>("talkChannel", std::bind(&Game::talkChannel, &g_game, _1, _2, _3));
g_lua.bindClassStaticFunction<Game>("talkPrivate", std::bind(&Game::talkPrivate, &g_game, _1, _2, _3));
#endif
}

View File

@@ -23,6 +23,7 @@
#include "otclient.h"
#include <framework/core/modulemanager.h>
#include "core/game.h"
#include <framework/core/resourcemanager.h>
OTClient::OTClient() : Application(Otc::AppCompactName)
{
@@ -38,4 +39,13 @@ void OTClient::init(const std::vector<std::string>& args)
g_modules.autoLoadModules(100);
g_modules.ensureModuleLoaded("client");
g_modules.autoLoadModules(1000);
// load otclientrc.lua
if(g_resources.fileExists("/otclientrc.lua")) {
try {
g_lua.runScript("/otclientrc.lua");
} catch(LuaException& e) {
logError("failed to load otclientrc.lua: ", e.what());
}
}
}

View File

@@ -55,7 +55,7 @@ bool UIGame::onKeyPress(uchar keyCode, std::string keyText, int keyboardModifier
g_game.walk(Otc::NorthWest);
return true;
} else if(keyCode == Fw::KeyReturn || keyCode == Fw::KeyEnter) {
g_game.talkChannel(1, 0, chatLineEdit->getText());
g_game.talk(chatLineEdit->getText());
chatLineEdit->clearText();
return true;
} else if(keyCode == Fw::KeyDelete) {