From ef0c625c4176810307f401cc2a262705d89b062b Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Sat, 7 Jan 2012 19:10:06 -0200 Subject: [PATCH] add option custom user script, otclientrc.lua --- modules/core_lib/.hotkeys.lua.swp | Bin 12288 -> 0 bytes modules/core_lib/util.lua | 18 +++++++++++++++--- modules/core_styles/styles/panels.otui | 2 +- modules/game/game.otui | 2 +- modules/otclientrc.lua | 12 ++++++++++++ src/framework/luafunctions.cpp | 4 ++++ src/otclient/core/game.cpp | 5 +++++ src/otclient/core/game.h | 1 + src/otclient/luafunctions.cpp | 7 +++---- src/otclient/otclient.cpp | 10 ++++++++++ src/otclient/ui/uigame.cpp | 2 +- 11 files changed, 53 insertions(+), 10 deletions(-) delete mode 100644 modules/core_lib/.hotkeys.lua.swp create mode 100644 modules/otclientrc.lua diff --git a/modules/core_lib/.hotkeys.lua.swp b/modules/core_lib/.hotkeys.lua.swp deleted file mode 100644 index 32e3325d4a3478dd3c708b142056d72bbf7e6d2f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2O>7la6vw9;rJ^9}#z-{7hqh=-zi9yrwy&=rw6A^bYiap*-n`qsq4Q=QGxMNL zEyN9yU>C*>EJ#e;kfFa6?enx^N>HB{3TRbMBopEr_s%Op{;d{{QF9 zojYglop+nQeB<7MjNZPrMZ?cJO*?$HdSq;RwN`vV)AEKFg!a9D49_eUgg<+)ypv&v z4Q0dtF%+N znMc$OomR)H+m1>mhok~Y1(FIR6-X+OR3NE9Qh}rbNd=M$Bo#<1kW}CStbkF_w9}7j z+Lw=E@c93K^!NYGr#0;c_zC<7J_GN8CGajd3WmWRFaSEhi=YbpyjIh`2cLuU;B7Di zGN27S1O8frJa83!3NCsrt8R?Gu`lL-f^c$pbVAB2g;Twhbe;2l&zqadWnRmQjrtX{;!D6z&NPO zu%o-Q&}SH--}ogjao23R^n)JdQh2T#Oj?B*5!C4my6X&z`K%{=U+;t%Ly(QdEt)1A zyz*_=H0;}=wI@^``0iE8Er>cDjd3xDUeULC}dc zbu}l|AjhnkVvwqM_IwnHYSC?Yk@c2J9um_la~D*g&ohp5*KaCw!YSZ!h2N~Beva@! zQidmjsPDte2h!~s=4>20q+;E0ecSMhbkac#Uj@Pe-FD6a71~d^`}v~#Nbh4kMS6<$ zB*^Y0_!dJ*0bBr%0z*ca!dB-9@@9)Cqhb@sGuC~~& zjqI+n>j$1&F3NR&u!aMrGF||9CsX&YL^f`~#CLDWd^s|ET-#PJoXwFpTq)&+$J1m} zdJbBvxMjgMOF zhfk60u)%JRdqO_#u)*#`nKCEJ>|~7@!MTxG5mo1ev1R9_)hxh~v-{nWd^BN$-K=Lh z0q#|(>9DHaRlj_`;L-Et?!kJJG9!TI`RBpyJ7z$RvLz z7hQK&6m)SM>&Tb;DqZe{u+#Am&{hYna1@SZYtt3S43~!9ufE-0aq^Z^kXs_;@s27w nab*|Sui1Hg1mD@uieBpUC=vbf_-XSM?gtkZ@u#S~zEuAL^0dYR 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) {