diff --git a/modules/core_lib/.hotkeys.lua.swp b/modules/core_lib/.hotkeys.lua.swp deleted file mode 100644 index 32e3325d..00000000 Binary files a/modules/core_lib/.hotkeys.lua.swp and /dev/null differ diff --git a/modules/core_lib/util.lua b/modules/core_lib/util.lua index 0d7c2e68..e4455bd8 100644 --- a/modules/core_lib/util.lua +++ b/modules/core_lib/util.lua @@ -70,10 +70,18 @@ end function resolvepath(filePath, depth) depth = depth or 1 - if filePath:sub(0, 1) ~= '/' then - return getfsrcpath(depth+1) .. '/' .. filePath + if filePath then + if filePath:sub(0, 1) ~= '/' then + local basepath = getfsrcpath(depth+1) + if basepath:sub(#basepath) ~= '/' then basepath = basepath .. '/' end + return basepath .. filePath + else + return filePath + end else - return filePath + local basepath = getfsrcpath(depth+1) + if basepath:sub(#basepath) ~= '/' then basepath = basepath .. '/' end + return basepath end end @@ -90,3 +98,7 @@ function tonumber(v) if v == nil then return 0 end return oldtonumber(v) end + +function runscript(file) + g_lua.runScript(resolvepath(file, 2)) +end \ No newline at end of file diff --git a/modules/core_styles/styles/panels.otui b/modules/core_styles/styles/panels.otui index 5386fc0e..dadc2d01 100644 --- a/modules/core_styles/styles/panels.otui +++ b/modules/core_styles/styles/panels.otui @@ -27,7 +27,7 @@ InterfacePanel2 < Panel source: /core_styles/images/interface_panel2.png border: 4 -MapPanel < UIMap +Map< UIMap map margin: 4 border-image: source: /core_styles/images/map_panel.png diff --git a/modules/game/game.otui b/modules/game/game.otui index 45395e49..84d44bb9 100644 --- a/modules/game/game.otui +++ b/modules/game/game.otui @@ -18,7 +18,7 @@ UIGame anchors.right: rightPanel.left anchors.bottom: parent.bottom - MapPanel + Map id: mapPanel anchors.left: parent.left anchors.right: rightPanel.left diff --git a/modules/otclientrc.lua b/modules/otclientrc.lua new file mode 100644 index 00000000..292cc828 --- /dev/null +++ b/modules/otclientrc.lua @@ -0,0 +1,12 @@ +-- this file use loaded after everything is loaded and initialized +-- you can place any custom user code here + +Hotkeys.bind('F1', function() Game.talk('exura gran') end) +Hotkeys.bind('F2', function() Game.talk('exori flam') end) +Hotkeys.bind('F3', function() Game.talk('exevo flam hur') end) +Hotkeys.bind('Ctrl+R', function() runscript('otclientrc.lua') end) + +if rcloaded then + print('otclient.rc lua reloaded') +end +rcloaded = true \ No newline at end of file diff --git a/src/framework/luafunctions.cpp b/src/framework/luafunctions.cpp index 07149f4d..577e6f91 100644 --- a/src/framework/luafunctions.cpp +++ b/src/framework/luafunctions.cpp @@ -286,6 +286,10 @@ void Application::registerLuaFunctions() g_lua.bindClassStaticFunction("fireOldMessages", std::bind(&Logger::fireOldMessages, &g_logger)); g_lua.bindClassStaticFunction("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)); diff --git a/src/otclient/core/game.cpp b/src/otclient/core/game.cpp index 0884ffec..4e652a55 100644 --- a/src/otclient/core/game.cpp +++ b/src/otclient/core/game.cpp @@ -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()) diff --git a/src/otclient/core/game.h b/src/otclient/core/game.h index fd642c37..dcda5f77 100644 --- a/src/otclient/core/game.h +++ b/src/otclient/core/game.h @@ -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); diff --git a/src/otclient/luafunctions.cpp b/src/otclient/luafunctions.cpp index b74d2813..84a2cfa7 100644 --- a/src/otclient/luafunctions.cpp +++ b/src/otclient/luafunctions.cpp @@ -108,6 +108,9 @@ void OTClient::registerLuaFunctions() g_lua.bindClassStaticFunction("removeVip", std::bind(&Game::removeVip, &g_game, _1)); g_lua.bindClassStaticFunction("getAttackingCreature", std::bind(&Game::getAttackingCreature, &g_game)); g_lua.bindClassStaticFunction("getFollowingCreature", std::bind(&Game::getFollowingCreature, &g_game)); + g_lua.bindClassStaticFunction("talk", std::bind(&Game::talk, &g_game, _1)); + g_lua.bindClassStaticFunction("talkChannel", std::bind(&Game::talkChannel, &g_game, _1, _2, _3)); + g_lua.bindClassStaticFunction("talkPrivate", std::bind(&Game::talkPrivate, &g_game, _1, _2, _3)); g_lua.registerClass(); g_lua.bindClassStaticFunction("create", []{ return UIItemPtr(new UIItem); } ); @@ -125,8 +128,4 @@ void OTClient::registerLuaFunctions() g_lua.registerClass(); g_lua.bindClassStaticFunction("create", []{ return UIGamePtr(new UIGame); } ); -#ifdef FORBIDDEN_FUNCTIONS - g_lua.bindClassStaticFunction("talkChannel", std::bind(&Game::talkChannel, &g_game, _1, _2, _3)); - g_lua.bindClassStaticFunction("talkPrivate", std::bind(&Game::talkPrivate, &g_game, _1, _2, _3)); -#endif } diff --git a/src/otclient/otclient.cpp b/src/otclient/otclient.cpp index d3b643aa..56e91a0a 100644 --- a/src/otclient/otclient.cpp +++ b/src/otclient/otclient.cpp @@ -23,6 +23,7 @@ #include "otclient.h" #include #include "core/game.h" +#include OTClient::OTClient() : Application(Otc::AppCompactName) { @@ -38,4 +39,13 @@ void OTClient::init(const std::vector& 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()); + } + } } diff --git a/src/otclient/ui/uigame.cpp b/src/otclient/ui/uigame.cpp index dd375945..08837a75 100644 --- a/src/otclient/ui/uigame.cpp +++ b/src/otclient/ui/uigame.cpp @@ -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) {