add option custom user script, otclientrc.lua
This commit is contained in:
parent
060d8740f5
commit
ef0c625c41
Binary file not shown.
|
@ -70,11 +70,19 @@ end
|
||||||
|
|
||||||
function resolvepath(filePath, depth)
|
function resolvepath(filePath, depth)
|
||||||
depth = depth or 1
|
depth = depth or 1
|
||||||
|
if filePath then
|
||||||
if filePath:sub(0, 1) ~= '/' then
|
if filePath:sub(0, 1) ~= '/' then
|
||||||
return getfsrcpath(depth+1) .. '/' .. filePath
|
local basepath = getfsrcpath(depth+1)
|
||||||
|
if basepath:sub(#basepath) ~= '/' then basepath = basepath .. '/' end
|
||||||
|
return basepath .. filePath
|
||||||
else
|
else
|
||||||
return filePath
|
return filePath
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
local basepath = getfsrcpath(depth+1)
|
||||||
|
if basepath:sub(#basepath) ~= '/' then basepath = basepath .. '/' end
|
||||||
|
return basepath
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function toboolean(str)
|
function toboolean(str)
|
||||||
|
@ -90,3 +98,7 @@ function tonumber(v)
|
||||||
if v == nil then return 0 end
|
if v == nil then return 0 end
|
||||||
return oldtonumber(v)
|
return oldtonumber(v)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function runscript(file)
|
||||||
|
g_lua.runScript(resolvepath(file, 2))
|
||||||
|
end
|
|
@ -27,7 +27,7 @@ InterfacePanel2 < Panel
|
||||||
source: /core_styles/images/interface_panel2.png
|
source: /core_styles/images/interface_panel2.png
|
||||||
border: 4
|
border: 4
|
||||||
|
|
||||||
MapPanel < UIMap
|
Map< UIMap
|
||||||
map margin: 4
|
map margin: 4
|
||||||
border-image:
|
border-image:
|
||||||
source: /core_styles/images/map_panel.png
|
source: /core_styles/images/map_panel.png
|
||||||
|
|
|
@ -18,7 +18,7 @@ UIGame
|
||||||
anchors.right: rightPanel.left
|
anchors.right: rightPanel.left
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
|
|
||||||
MapPanel
|
Map
|
||||||
id: mapPanel
|
id: mapPanel
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: rightPanel.left
|
anchors.right: rightPanel.left
|
||||||
|
|
|
@ -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
|
|
@ -286,6 +286,10 @@ void Application::registerLuaFunctions()
|
||||||
g_lua.bindClassStaticFunction<Logger>("fireOldMessages", std::bind(&Logger::fireOldMessages, &g_logger));
|
g_lua.bindClassStaticFunction<Logger>("fireOldMessages", std::bind(&Logger::fireOldMessages, &g_logger));
|
||||||
g_lua.bindClassStaticFunction<Logger>("setOnLog", std::bind(&Logger::setOnLog, &g_logger, _1));
|
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
|
// UI
|
||||||
g_lua.registerStaticClass("g_ui");
|
g_lua.registerStaticClass("g_ui");
|
||||||
g_lua.bindClassStaticFunction("g_ui", "importStyle", std::bind(&UIManager::importStyle, &g_ui, _1));
|
g_lua.bindClassStaticFunction("g_ui", "importStyle", std::bind(&UIManager::importStyle, &g_ui, _1));
|
||||||
|
|
|
@ -268,6 +268,11 @@ int Game::getThingStackpos(const ThingPtr& thing)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Game::talk(const std::string& message)
|
||||||
|
{
|
||||||
|
talkChannel(1, 0, message);
|
||||||
|
}
|
||||||
|
|
||||||
void Game::talkChannel(int channelType, int channelId, const std::string& message)
|
void Game::talkChannel(int channelType, int channelId, const std::string& message)
|
||||||
{
|
{
|
||||||
if(!m_online || !checkBotProtection())
|
if(!m_online || !checkBotProtection())
|
||||||
|
|
|
@ -58,6 +58,7 @@ public:
|
||||||
void follow(const CreaturePtr& creature);
|
void follow(const CreaturePtr& creature);
|
||||||
void cancelFollow();
|
void cancelFollow();
|
||||||
void rotate(const ThingPtr& thing);
|
void rotate(const ThingPtr& thing);
|
||||||
|
void talk(const std::string& message);
|
||||||
void talkChannel(int channelType, int channelId, 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 talkPrivate(int channelType, const std::string& receiver, const std::string& message);
|
||||||
void inviteToParty(int creatureId);
|
void inviteToParty(int creatureId);
|
||||||
|
|
|
@ -108,6 +108,9 @@ void OTClient::registerLuaFunctions()
|
||||||
g_lua.bindClassStaticFunction<Game>("removeVip", std::bind(&Game::removeVip, &g_game, _1));
|
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>("getAttackingCreature", std::bind(&Game::getAttackingCreature, &g_game));
|
||||||
g_lua.bindClassStaticFunction<Game>("getFollowingCreature", std::bind(&Game::getFollowingCreature, &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.registerClass<UIItem, UIWidget>();
|
||||||
g_lua.bindClassStaticFunction<UIItem>("create", []{ return UIItemPtr(new UIItem); } );
|
g_lua.bindClassStaticFunction<UIItem>("create", []{ return UIItemPtr(new UIItem); } );
|
||||||
|
@ -125,8 +128,4 @@ void OTClient::registerLuaFunctions()
|
||||||
g_lua.registerClass<UIGame, UIWidget>();
|
g_lua.registerClass<UIGame, UIWidget>();
|
||||||
g_lua.bindClassStaticFunction<UIGame>("create", []{ return UIGamePtr(new UIGame); } );
|
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
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "otclient.h"
|
#include "otclient.h"
|
||||||
#include <framework/core/modulemanager.h>
|
#include <framework/core/modulemanager.h>
|
||||||
#include "core/game.h"
|
#include "core/game.h"
|
||||||
|
#include <framework/core/resourcemanager.h>
|
||||||
|
|
||||||
OTClient::OTClient() : Application(Otc::AppCompactName)
|
OTClient::OTClient() : Application(Otc::AppCompactName)
|
||||||
{
|
{
|
||||||
|
@ -38,4 +39,13 @@ void OTClient::init(const std::vector<std::string>& args)
|
||||||
g_modules.autoLoadModules(100);
|
g_modules.autoLoadModules(100);
|
||||||
g_modules.ensureModuleLoaded("client");
|
g_modules.ensureModuleLoaded("client");
|
||||||
g_modules.autoLoadModules(1000);
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ bool UIGame::onKeyPress(uchar keyCode, std::string keyText, int keyboardModifier
|
||||||
g_game.walk(Otc::NorthWest);
|
g_game.walk(Otc::NorthWest);
|
||||||
return true;
|
return true;
|
||||||
} else if(keyCode == Fw::KeyReturn || keyCode == Fw::KeyEnter) {
|
} else if(keyCode == Fw::KeyReturn || keyCode == Fw::KeyEnter) {
|
||||||
g_game.talkChannel(1, 0, chatLineEdit->getText());
|
g_game.talk(chatLineEdit->getText());
|
||||||
chatLineEdit->clearText();
|
chatLineEdit->clearText();
|
||||||
return true;
|
return true;
|
||||||
} else if(keyCode == Fw::KeyDelete) {
|
} else if(keyCode == Fw::KeyDelete) {
|
||||||
|
|
Loading…
Reference in New Issue