diff --git a/modules/addon_console/console.lua b/modules/addon_console/console.lua index d6c17a03..bac13f7f 100644 --- a/modules/addon_console/console.lua +++ b/modules/addon_console/console.lua @@ -10,7 +10,7 @@ local LabelHeight = 16 -- private variables local consoleWidget local logLocked = false -local commandEnv = createEnvironment() +local commandEnv = newenv() local commandLineEdit local consoleBuffer local commandHistory = { } diff --git a/modules/addon_console/console.otmod b/modules/addon_console/console.otmod index 2a1634be..628e0e97 100644 --- a/modules/addon_console/console.otmod +++ b/modules/addon_console/console.otmod @@ -12,7 +12,6 @@ Module require 'console' require 'commands' Console.init() - return true onUnload: | Console.terminate() diff --git a/modules/addon_playground/playground.otmod b/modules/addon_playground/playground.otmod index 1ef3d48f..6fe92c90 100644 --- a/modules/addon_playground/playground.otmod +++ b/modules/addon_playground/playground.otmod @@ -3,5 +3,4 @@ Module autoLoad: true onLoad: | require 'playground' - return true diff --git a/modules/client/client.lua b/modules/client/client.lua index ca1c151b..c6577c83 100644 --- a/modules/client/client.lua +++ b/modules/client/client.lua @@ -1,8 +1,9 @@ -Client = { } +Client = {} -- TODO: load and save configurations function Client.init() g_window.show() + g_window.setMinimumSize({ width = 550, height = 450 }) -- initialize in fullscreen mode on mobile devices if g_window.getPlatformType() == "X11-EGL" then @@ -19,8 +20,11 @@ function Client.init() end g_window.setTitle('OTClient') - g_window.setIcon('clienticon.png') - return true + g_window.setIcon(resolvepath('clienticon.png')) + + if not g_sprites.isLoaded() or not g_thingsType.isLoaded() then + fatal("spr and dat files are not loaded, did you loaded them?") + end end function Client.terminate() diff --git a/modules/client/client.otmod b/modules/client/client.otmod index 1c6c7ef0..fa8555bb 100644 --- a/modules/client/client.otmod +++ b/modules/client/client.otmod @@ -16,7 +16,7 @@ Module onLoad: | require 'client' - return Client.init() + Client.init() onUnload: | Client.terminate() diff --git a/modules/client_about/about.otmod b/modules/client_about/about.otmod index 5dd5c9db..d6bc8b49 100644 --- a/modules/client_about/about.otmod +++ b/modules/client_about/about.otmod @@ -6,5 +6,3 @@ Module onLoad: | require 'about' - return true - diff --git a/modules/client_background/background.otmod b/modules/client_background/background.otmod index 4b3dc707..e9de49b3 100644 --- a/modules/client_background/background.otmod +++ b/modules/client_background/background.otmod @@ -7,7 +7,6 @@ Module onLoad: | require 'background' Background.create() - return true onUnload: Background.destroy() diff --git a/modules/client_entergame/entergame.otmod b/modules/client_entergame/entergame.otmod index e1241bcf..8da4d8a2 100644 --- a/modules/client_entergame/entergame.otmod +++ b/modules/client_entergame/entergame.otmod @@ -8,7 +8,6 @@ Module require 'entergame' require 'characterlist' EnterGame.create() - return true onUnload: EnterGame.destroy() diff --git a/modules/client_options/options.otmod b/modules/client_options/options.otmod index 4722e368..7e434931 100644 --- a/modules/client_options/options.otmod +++ b/modules/client_options/options.otmod @@ -6,5 +6,3 @@ Module onLoad: | require 'options' - return true - diff --git a/modules/client_tibiafiles b/modules/client_tibiafiles index e76fa278..81e6ef44 160000 --- a/modules/client_tibiafiles +++ b/modules/client_tibiafiles @@ -1 +1 @@ -Subproject commit e76fa2786e2a194375a110b700b7e2daa769f960 +Subproject commit 81e6ef44c73edc5037512cdee3b2f75a23331521 diff --git a/modules/client_topmenu/topmenu.otmod b/modules/client_topmenu/topmenu.otmod index 4a102ac2..3a902a7f 100644 --- a/modules/client_topmenu/topmenu.otmod +++ b/modules/client_topmenu/topmenu.otmod @@ -7,7 +7,6 @@ Module onLoad: | require 'topmenu' TopMenu.create() - return true onUnload: | TopMenu.destroy() diff --git a/modules/core/core.otmod b/modules/core/core.otmod index 31460779..5dd9ec92 100644 --- a/modules/core/core.otmod +++ b/modules/core/core.otmod @@ -10,7 +10,7 @@ Module // NOTE: order does matter dependencies: - - core_scripts + - core_lib - core_fonts - core_styles - core_widgets diff --git a/modules/core_fonts/core_fonts.otmod b/modules/core_fonts/core_fonts.otmod index 42b7db29..8d870754 100644 --- a/modules/core_fonts/core_fonts.otmod +++ b/modules/core_fonts/core_fonts.otmod @@ -4,10 +4,9 @@ Module author: OTClient team website: https://github.com/edubart/otclient onLoad: | - importFont('verdana-11px-antialised') - importFont('verdana-11px-monochrome') - importFont('verdana-11px-rounded') - importFont('terminus-14px-bold') - setDefaultFont('verdana-11px-antialised') - return true + importFont 'verdana-11px-antialised' + importFont 'verdana-11px-monochrome' + importFont 'verdana-11px-rounded' + importFont 'terminus-14px-bold' + setDefaultFont 'verdana-11px-antialised' diff --git a/modules/core_scripts/const.lua b/modules/core_lib/const.lua similarity index 100% rename from modules/core_scripts/const.lua rename to modules/core_lib/const.lua diff --git a/modules/core_scripts/core_scripts.otmod b/modules/core_lib/core_lib.otmod similarity index 68% rename from modules/core_scripts/core_scripts.otmod rename to modules/core_lib/core_lib.otmod index a4478608..0107de4e 100644 --- a/modules/core_scripts/core_scripts.otmod +++ b/modules/core_lib/core_lib.otmod @@ -1,5 +1,5 @@ Module - name: core_scripts + name: core_lib description: Contains core lua classes, functions and constants used by other modules author: OTClient team website: https://github.com/edubart/otclient @@ -7,14 +7,13 @@ Module onLoad: | require 'ext/table' require 'ext/string' - require 'util/point' - require 'util/size' - require 'util/color' - require 'util/rect' + require 'math/point' + require 'math/size' + require 'math/color' + require 'math/rect' require 'const' require 'util' + require 'globals' require 'dispatcher' require 'widget' - require 'ui' require 'effects' - return true diff --git a/modules/core_scripts/dispatcher.lua b/modules/core_lib/dispatcher.lua similarity index 100% rename from modules/core_scripts/dispatcher.lua rename to modules/core_lib/dispatcher.lua diff --git a/modules/core_scripts/effects.lua b/modules/core_lib/effects.lua similarity index 100% rename from modules/core_scripts/effects.lua rename to modules/core_lib/effects.lua diff --git a/modules/core_scripts/ext/string.lua b/modules/core_lib/ext/string.lua similarity index 100% rename from modules/core_scripts/ext/string.lua rename to modules/core_lib/ext/string.lua diff --git a/modules/core_scripts/ext/table.lua b/modules/core_lib/ext/table.lua similarity index 100% rename from modules/core_scripts/ext/table.lua rename to modules/core_lib/ext/table.lua diff --git a/modules/core_scripts/ui.lua b/modules/core_lib/globals.lua similarity index 85% rename from modules/core_scripts/ui.lua rename to modules/core_lib/globals.lua index 6cff1d4b..603699d2 100644 --- a/modules/core_scripts/ui.lua +++ b/modules/core_lib/globals.lua @@ -1,9 +1,15 @@ --- globals rootWidget = g_ui.getRootWidget() --- public functions function importStyle(otui) - g_ui.importStyle(resolveFileFullPath(otui, 2)) + g_ui.importStyle(resolvepath(otui, 2)) +end + +function importFont(otfont) + g_fonts.importFont(resolvepath(otfont, 2)) +end + +function setDefaultFont(font) + g_fonts.setDefaultFont(font) end function displayUI(arg1, options) @@ -14,7 +20,7 @@ function displayUI(arg1, options) -- display otui files if type(arg1) == 'string' then - local otuiFilePath = resolveFileFullPath(arg1, 2) + local otuiFilePath = resolvepath(arg1, 2) widget = g_ui.loadUI(otuiFilePath, parent) -- display already loaded widgets else diff --git a/modules/core_scripts/hotkeys.lua b/modules/core_lib/hotkeys.lua similarity index 100% rename from modules/core_scripts/hotkeys.lua rename to modules/core_lib/hotkeys.lua diff --git a/modules/core_scripts/util/color.lua b/modules/core_lib/math/color.lua similarity index 100% rename from modules/core_scripts/util/color.lua rename to modules/core_lib/math/color.lua diff --git a/modules/core_scripts/util/point.lua b/modules/core_lib/math/point.lua similarity index 100% rename from modules/core_scripts/util/point.lua rename to modules/core_lib/math/point.lua diff --git a/modules/core_scripts/util/rect.lua b/modules/core_lib/math/rect.lua similarity index 100% rename from modules/core_scripts/util/rect.lua rename to modules/core_lib/math/rect.lua diff --git a/modules/core_scripts/util/size.lua b/modules/core_lib/math/size.lua similarity index 100% rename from modules/core_scripts/util/size.lua rename to modules/core_lib/math/size.lua diff --git a/modules/core_scripts/util.lua b/modules/core_lib/util.lua similarity index 88% rename from modules/core_scripts/util.lua rename to modules/core_lib/util.lua index b7173229..a2787709 100644 --- a/modules/core_scripts/util.lua +++ b/modules/core_lib/util.lua @@ -26,13 +26,26 @@ function connect(object, signalsAndSlots, pushFront) end end -function createEnvironment() +function extends(base) + local derived = {} + function derived.internalCreate() + local instance = base.create() + for k,v in pairs(derived) do + instance[k] = v + end + return instance + end + derived.create = derived.internalCreate + return derived +end + +function newenv() local env = { } setmetatable(env, { __index = _G} ) return env end -function getCallingScriptSourcePath(depth) +function getfsrcpath(depth) depth = depth or 2 local info = debug.getinfo(1+depth, "Sn") local path @@ -47,25 +60,11 @@ function getCallingScriptSourcePath(depth) return path end -function resolveFileFullPath(filePath, depth) +function resolvepath(filePath, depth) depth = depth or 1 if filePath:sub(0, 1) ~= '/' then - return getCallingScriptSourcePath(depth+1) .. '/' .. filePath + return getfsrcpath(depth+1) .. '/' .. filePath else return filePath end end - -function extends(base) - local derived = {} - function derived.internalCreate() - local instance = base.create() - for k,v in pairs(derived) do - instance[k] = v - end - return instance - end - derived.create = derived.internalCreate - return derived -end - diff --git a/modules/core_scripts/widget.lua b/modules/core_lib/widget.lua similarity index 100% rename from modules/core_scripts/widget.lua rename to modules/core_lib/widget.lua diff --git a/modules/core_styles/core_styles.otmod b/modules/core_styles/core_styles.otmod index ff41dbaf..64707446 100644 --- a/modules/core_styles/core_styles.otmod +++ b/modules/core_styles/core_styles.otmod @@ -17,4 +17,3 @@ Module importStyle 'styles/creatures.otui' importStyle 'styles/popupmenus.otui' importStyle 'styles/comboboxes.otui' - return true diff --git a/modules/core_widgets/core_widgets.otmod b/modules/core_widgets/core_widgets.otmod index 1a096d49..6f1dc31d 100644 --- a/modules/core_widgets/core_widgets.otmod +++ b/modules/core_widgets/core_widgets.otmod @@ -10,5 +10,4 @@ Module require 'uibutton' require 'uilabel' require 'uicombobox' - require 'uipopupmenu' - return true \ No newline at end of file + require 'uipopupmenu' \ No newline at end of file diff --git a/modules/core_widgets/uicheckbox.lua b/modules/core_widgets/uicheckbox.lua new file mode 100644 index 00000000..bc010691 --- /dev/null +++ b/modules/core_widgets/uicheckbox.lua @@ -0,0 +1,8 @@ +UICheckBox = extends(UIWidget) + +function UICheckBox.create() + local checkbox = UICheckBox.internalCreate() + checkbox:setFocusable(false) + checkbox:setAlign(AlignLeft) + return checkbox +end diff --git a/modules/game/game.otmod b/modules/game/game.otmod index e1a954f5..0d8184c3 100644 --- a/modules/game/game.otmod +++ b/modules/game/game.otmod @@ -16,4 +16,3 @@ Module onLoad: | require 'game' require 'thing' - return true diff --git a/modules/game_chat/chat.otmod b/modules/game_chat/chat.otmod index 549c8d32..43ee0ee5 100644 --- a/modules/game_chat/chat.otmod +++ b/modules/game_chat/chat.otmod @@ -5,6 +5,3 @@ Module website: https://github.com/edubart/otclient onLoad: | require 'chat' - return true - - diff --git a/modules/game_healthbar/healthbar.otmod b/modules/game_healthbar/healthbar.otmod index 4dee07e3..5f8e9974 100644 --- a/modules/game_healthbar/healthbar.otmod +++ b/modules/game_healthbar/healthbar.otmod @@ -5,6 +5,3 @@ Module website: https://github.com/edubart/otclient onLoad: | require 'healthbar' - return true - - diff --git a/modules/game_inventory/inventory.otmod b/modules/game_inventory/inventory.otmod index 2d44fa1d..e724a5e5 100644 --- a/modules/game_inventory/inventory.otmod +++ b/modules/game_inventory/inventory.otmod @@ -5,6 +5,3 @@ Module website: https://github.com/edubart/otclient onLoad: | require 'inventory' - return true - - diff --git a/modules/game_outfit/outfit.otmod b/modules/game_outfit/outfit.otmod index e31feea7..cbf3bfe8 100644 --- a/modules/game_outfit/outfit.otmod +++ b/modules/game_outfit/outfit.otmod @@ -5,6 +5,3 @@ Module website: https://github.com/edubart/otclient onLoad: | require 'outfit' - return true - - diff --git a/modules/game_skills/skills.otmod b/modules/game_skills/skills.otmod index 1b6f7c99..440357d0 100644 --- a/modules/game_skills/skills.otmod +++ b/modules/game_skills/skills.otmod @@ -5,4 +5,3 @@ Module website: https://github.com/edubart/otclient onLoad: | require 'skills' - return true diff --git a/modules/game_textmessage/textmessage.otmod b/modules/game_textmessage/textmessage.otmod index cdb15547..6cc75030 100644 --- a/modules/game_textmessage/textmessage.otmod +++ b/modules/game_textmessage/textmessage.otmod @@ -5,5 +5,3 @@ Module website: https://github.com/edubart/otclient onLoad: | require 'textmessage' - return true - diff --git a/modules/game_viplist/viplist.otmod b/modules/game_viplist/viplist.otmod index 8ff16013..d1ffb40f 100644 --- a/modules/game_viplist/viplist.otmod +++ b/modules/game_viplist/viplist.otmod @@ -5,6 +5,3 @@ Module website: https://github.com/edubart/otclient onLoad: | require 'viplist' - return true - - diff --git a/src/framework/application.cpp b/src/framework/application.cpp index af006ca5..7d8fccc4 100644 --- a/src/framework/application.cpp +++ b/src/framework/application.cpp @@ -90,7 +90,7 @@ void Application::init(const std::vector& args, int appFlags) logError("Could not setup write directory"); // load configs - if(!g_configs.load("config.otml")) + if(!g_configs.load("/config.otml")) logInfo("Using default configurations."); } diff --git a/src/framework/core/module.cpp b/src/framework/core/module.cpp index f44c5254..160e3f89 100644 --- a/src/framework/core/module.cpp +++ b/src/framework/core/module.cpp @@ -50,7 +50,7 @@ void Module::discover(const OTMLNodePtr& moduleNode) if(OTMLNodePtr node = moduleNode->get("onLoad")) { g_lua.loadFunction(node->value(), "@" + node->source() + "[" + node->tag() + "]"); g_lua.useValue(); - m_loadCallback = g_lua.polymorphicPop(); + m_loadCallback = g_lua.polymorphicPop(); } // set onUnload callback @@ -79,10 +79,8 @@ bool Module::load() } } - if(m_loadCallback && !m_loadCallback()) { - logError("Unable to load module '", m_name, "' because its onLoad event returned false"); - return false; - } + if(m_loadCallback) + m_loadCallback(); logInfo("Loaded module '", m_name, "'"); m_loaded = true; diff --git a/src/framework/core/module.h b/src/framework/core/module.h index 1bb75055..6a4650bc 100644 --- a/src/framework/core/module.h +++ b/src/framework/core/module.h @@ -55,7 +55,7 @@ private: std::string m_author; std::string m_website; std::string m_version; - BooleanCallback m_loadCallback; + SimpleCallback m_loadCallback; SimpleCallback m_unloadCallback; std::list m_dependencies; }; diff --git a/src/framework/core/resourcemanager.cpp b/src/framework/core/resourcemanager.cpp index 62594cc8..a0debf80 100644 --- a/src/framework/core/resourcemanager.cpp +++ b/src/framework/core/resourcemanager.cpp @@ -67,7 +67,7 @@ bool ResourceManager::addToSearchPath(const std::string& path, bool insertInFron void ResourceManager::searchAndAddPackages(const std::string& packagesDir, const std::string& packageExt, bool append) { - auto files = listDirectoryFiles(resolvePath(packagesDir)); + auto files = listDirectoryFiles(checkPath(packagesDir)); for(const std::string& file : files) { if(boost::ends_with(file, packageExt)) addToSearchPath(packagesDir + "/" + file, !append); @@ -76,17 +76,17 @@ void ResourceManager::searchAndAddPackages(const std::string& packagesDir, const bool ResourceManager::fileExists(const std::string& fileName) { - return (PHYSFS_exists(resolvePath(fileName).c_str()) && !PHYSFS_isDirectory(resolvePath(fileName).c_str())); + return (PHYSFS_exists(checkPath(fileName).c_str()) && !PHYSFS_isDirectory(checkPath(fileName).c_str())); } bool ResourceManager::directoryExists(const std::string& directoryName) { - return (PHYSFS_isDirectory(resolvePath(directoryName).c_str())); + return (PHYSFS_isDirectory(checkPath(directoryName).c_str())); } void ResourceManager::loadFile(const std::string& fileName, std::iostream& out) { - std::string fullPath = resolvePath(fileName); + std::string fullPath = checkPath(fileName); out.clear(std::ios::goodbit); PHYSFS_file* file = PHYSFS_openRead(fullPath.c_str()); if(!file) { @@ -114,7 +114,7 @@ std::string ResourceManager::loadFile(const std::string& fileName) bool ResourceManager::saveFile(const std::string& fileName, const uchar* data, uint size) { - PHYSFS_file* file = PHYSFS_openWrite(resolvePath(fileName).c_str()); + PHYSFS_file* file = PHYSFS_openWrite(checkPath(fileName).c_str()); if(!file) return false; @@ -143,13 +143,13 @@ bool ResourceManager::saveFile(const std::string& fileName, const std::string& d bool ResourceManager::deleteFile(const std::string& fileName) { - return PHYSFS_delete(resolvePath(fileName).c_str()) != 0; + return PHYSFS_delete(checkPath(fileName).c_str()) != 0; } std::list ResourceManager::listDirectoryFiles(const std::string& directoryPath) { std::list files; - auto rc = PHYSFS_enumerateFiles(resolvePath(directoryPath).c_str()); + auto rc = PHYSFS_enumerateFiles(checkPath(directoryPath).c_str()); for(int i = 0; rc[i] != NULL; i++) files.push_back(rc[i]); @@ -158,8 +158,9 @@ std::list ResourceManager::listDirectoryFiles(const std::string& di return files; } -std::string ResourceManager::resolvePath(const std::string& path) +std::string ResourceManager::checkPath(const std::string& path) { + /* std::string fullPath; if(boost::starts_with(path, "/")) fullPath = path; @@ -169,7 +170,10 @@ std::string ResourceManager::resolvePath(const std::string& path) fullPath += scriptPath + "/"; fullPath += path; } - return fullPath; + */ + if(!(boost::starts_with(path, "/"))) + logTraceWarning("the following file path is not fully resolved: ", path); + return path; } std::string ResourceManager::getBaseDir() diff --git a/src/framework/core/resourcemanager.h b/src/framework/core/resourcemanager.h index 9360f59a..54920e5f 100644 --- a/src/framework/core/resourcemanager.h +++ b/src/framework/core/resourcemanager.h @@ -50,7 +50,7 @@ public: std::list listDirectoryFiles(const std::string& directoryPath = ""); - std::string resolvePath(const std::string& path); + std::string checkPath(const std::string& path); std::string getBaseDir(); }; diff --git a/src/framework/global.h b/src/framework/global.h index 30ef2160..0ae020e8 100644 --- a/src/framework/global.h +++ b/src/framework/global.h @@ -32,11 +32,11 @@ // additional utilities #include "util/types.h" #include "util/tools.h" -#include "util/point.h" -#include "util/color.h" -#include "util/rect.h" -#include "util/size.h" -#include "util/matrix.h" +#include "math/point.h" +#include "math/color.h" +#include "math/rect.h" +#include "math/size.h" +#include "math/matrix.h" // logger #include "core/logger.h" diff --git a/src/framework/graphics/font.cpp b/src/framework/graphics/font.cpp index c0c100ff..a0bebd12 100644 --- a/src/framework/graphics/font.cpp +++ b/src/framework/graphics/font.cpp @@ -28,7 +28,8 @@ void Font::load(const OTMLNodePtr& fontNode) { - std::string textureName = fontNode->valueAt("texture"); + OTMLNodePtr textureNode = fontNode->at("texture"); + std::string textureFile = Fw::resolvePath(textureNode->value(), textureNode->source()); Size glyphSize = fontNode->valueAt("glyph-size"); m_glyphHeight = fontNode->valueAt("height"); m_yOffset = fontNode->valueAt("y-offset", 0); @@ -36,7 +37,7 @@ void Font::load(const OTMLNodePtr& fontNode) m_glyphSpacing = fontNode->valueAt("spacing", Size(0,0)); // load font texture - m_texture = g_textures.getTexture(textureName); + m_texture = g_textures.getTexture(textureFile); if(OTMLNodePtr node = fontNode->get("fixed-glyph-width")) { for(int glyph = m_firstGlyph; glyph < 256; ++glyph) diff --git a/src/framework/graphics/particleaffector.h b/src/framework/graphics/particleaffector.h index d785f522..dbfd2f2c 100644 --- a/src/framework/graphics/particleaffector.h +++ b/src/framework/graphics/particleaffector.h @@ -29,7 +29,6 @@ class ParticleAffector { public: ParticleAffector(); - virtual ~ParticleAffector() { dump << "ParticleAffector deleted"; } void update(double elapsedTime); virtual bool load(const OTMLNodePtr& node); diff --git a/src/framework/graphics/particleemitter.h b/src/framework/graphics/particleemitter.h index 8ddb1f04..402a96e4 100644 --- a/src/framework/graphics/particleemitter.h +++ b/src/framework/graphics/particleemitter.h @@ -33,7 +33,6 @@ class ParticleEmitter { public: ParticleEmitter(const ParticleSystemPtr& parent); - ~ParticleEmitter() { dump << "ParticleEmitter deleted"; } bool load(const OTMLNodePtr& node); diff --git a/src/framework/graphics/particlesystem.h b/src/framework/graphics/particlesystem.h index 1ba250ad..a24d4948 100644 --- a/src/framework/graphics/particlesystem.h +++ b/src/framework/graphics/particlesystem.h @@ -30,7 +30,6 @@ class ParticleSystem : public std::enable_shared_from_this { public: ParticleSystem(); - ~ParticleSystem() { dump << "ParticleSystem deleted"; } bool load(const OTMLNodePtr& node); diff --git a/src/framework/luafunctions.cpp b/src/framework/luafunctions.cpp index 6dda9f67..559c9007 100644 --- a/src/framework/luafunctions.cpp +++ b/src/framework/luafunctions.cpp @@ -37,9 +37,6 @@ void Application::registerLuaFunctions() g_lua.registerClass(); g_lua.bindClassStaticFunction("create", &UIWidget::create); g_lua.bindClassMemberFunction("destroy", &UIWidget::destroy); - g_lua.bindClassMemberFunction("render", &UIWidget::render); - g_lua.bindClassMemberFunction("renderSelf", &UIWidget::renderSelf); - g_lua.bindClassMemberFunction("renderChildren", &UIWidget::renderChildren); g_lua.bindClassMemberFunction("setVisible", &UIWidget::setVisible); g_lua.bindClassMemberFunction("setEnabled", &UIWidget::setEnabled); g_lua.bindClassMemberFunction("setPressed", &UIWidget::setPressed); @@ -237,6 +234,7 @@ void Application::registerLuaFunctions() g_lua.bindClassStaticFunction("g_window", "hide", std::bind(&PlatformWindow::hide, &g_window)); 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", "setMinimumSize", std::bind(&PlatformWindow::setMinimumSize, &g_window, _1)); g_lua.bindClassStaticFunction("g_window", "setVerticalSync", std::bind(&PlatformWindow::setVerticalSync, &g_window, _1)); g_lua.bindClassStaticFunction("g_window", "setFullscreen", std::bind(&PlatformWindow::setFullscreen, &g_window, _1)); g_lua.bindClassStaticFunction("g_window", "setTitle", std::bind(&PlatformWindow::setTitle, &g_window, _1)); @@ -260,22 +258,14 @@ void Application::registerLuaFunctions() g_lua.bindClassStaticFunction("g_ui", "loadUI", std::bind(&UIManager::loadUI, &g_ui, _1, _2)); g_lua.bindClassStaticFunction("g_ui", "getRootWidget", std::bind(&UIManager::getRootWidget, &g_ui)); - /* // FontManager g_lua.registerStaticClass("g_fonts"); - g_lua.bindClassStaticFunction("g_fonts", "releaseFonts", std::bind(&FontManager::releaseFonts, &g_fonts)); g_lua.bindClassStaticFunction("g_fonts", "importFont", std::bind(&FontManager::importFont, &g_fonts, _1)); g_lua.bindClassStaticFunction("g_fonts", "fontExists", std::bind(&FontManager::fontExists, &g_fonts, _1)); - g_lua.bindClassStaticFunction("g_fonts", "getFont", std::bind(&FontManager::getFont, &g_fonts, _1)); - g_lua.bindClassStaticFunction("g_fonts", "getDefaultFont", std::bind(&FontManager::getDefaultFont, &g_fonts)); g_lua.bindClassStaticFunction("g_fonts", "setDefaultFont", std::bind(&FontManager::setDefaultFont, &g_fonts, _1)); - */ + // EventDispatcher g_lua.registerStaticClass("g_dispatcher"); g_lua.bindClassStaticFunction("g_dispatcher", "addEvent", std::bind(&EventDispatcher::addEvent, &g_dispatcher, _1, _2)); g_lua.bindClassStaticFunction("g_dispatcher", "scheduleEvent", std::bind(&EventDispatcher::scheduleEvent, &g_dispatcher, _1, _2)); - - // global functions - g_lua.bindGlobalFunction("importFont", std::bind(&FontManager::importFont, &g_fonts, _1)); - g_lua.bindGlobalFunction("setDefaultFont", std::bind(&FontManager::setDefaultFont, &g_fonts, _1)); } diff --git a/src/framework/luascript/luainterface.cpp b/src/framework/luascript/luainterface.cpp index 642b1f63..c4e62c95 100644 --- a/src/framework/luascript/luainterface.cpp +++ b/src/framework/luascript/luainterface.cpp @@ -290,9 +290,14 @@ void LuaInterface::runBuffer(const std::string& buffer, const std::string& sourc void LuaInterface::loadScript(const std::string& fileName) { - std::string buffer = g_resources.loadFile(fileName); - std::string source = "@" + g_resources.resolvePath(fileName); - loadBuffer(g_resources.loadFile(fileName), "@" + g_resources.resolvePath(fileName)); + // resolve file full path + std::string filePath = fileName; + if(!boost::starts_with(fileName, "/")) + filePath = getCurrentSourcePath() + "/" + filePath; + + std::string buffer = g_resources.loadFile(filePath); + std::string source = "@" + filePath; + loadBuffer(buffer, source); } void LuaInterface::loadFunction(const std::string& buffer, const std::string& source) diff --git a/src/framework/util/color.h b/src/framework/math/color.h similarity index 99% rename from src/framework/util/color.h rename to src/framework/math/color.h index fbcad05b..529cdd4d 100644 --- a/src/framework/util/color.h +++ b/src/framework/math/color.h @@ -23,8 +23,8 @@ #ifndef COLOR_H #define COLOR_H -#include "types.h" -#include "tools.h" +#include "../util/types.h" +#include "../util/tools.h" #include "../const.h" class Color diff --git a/src/framework/util/matrix.h b/src/framework/math/matrix.h similarity index 100% rename from src/framework/util/matrix.h rename to src/framework/math/matrix.h diff --git a/src/framework/util/point.h b/src/framework/math/point.h similarity index 99% rename from src/framework/util/point.h rename to src/framework/math/point.h index ef616044..c17bd598 100644 --- a/src/framework/util/point.h +++ b/src/framework/math/point.h @@ -23,7 +23,7 @@ #ifndef POINT_H #define POINT_H -#include "types.h" +#include "../util/types.h" #include #include diff --git a/src/framework/util/rect.h b/src/framework/math/rect.h similarity index 99% rename from src/framework/util/rect.h rename to src/framework/math/rect.h index 0ca01c5e..38c91626 100644 --- a/src/framework/util/rect.h +++ b/src/framework/math/rect.h @@ -23,7 +23,7 @@ #ifndef RECT_H #define RECT_H -#include "types.h" +#include "../util/types.h" #include template diff --git a/src/framework/util/size.h b/src/framework/math/size.h similarity index 100% rename from src/framework/util/size.h rename to src/framework/math/size.h diff --git a/src/framework/otml/otmldocument.cpp b/src/framework/otml/otmldocument.cpp index 82462fa2..3abe8a2a 100644 --- a/src/framework/otml/otmldocument.cpp +++ b/src/framework/otml/otmldocument.cpp @@ -37,7 +37,7 @@ OTMLDocumentPtr OTMLDocument::parse(const std::string& fileName) { std::stringstream fin; g_resources.loadFile(fileName, fin); - return parse(fin, g_resources.resolvePath(fileName)); + return parse(fin, fileName); } OTMLDocumentPtr OTMLDocument::parse(std::istream& in, const std::string& source) diff --git a/src/framework/ui/uimanager.cpp b/src/framework/ui/uimanager.cpp index 406eccc0..5205eaf5 100644 --- a/src/framework/ui/uimanager.cpp +++ b/src/framework/ui/uimanager.cpp @@ -57,6 +57,7 @@ void UIManager::resize(const Size& size) void UIManager::inputEvent(const InputEvent& event) { + m_isOnInputEvent = true; switch(event.type) { case Fw::KeyPressInputEvent: m_keyboardReceiver->onKeyPress(event.keyCode, event.keyText, event.keyboardModifiers); @@ -78,6 +79,7 @@ void UIManager::inputEvent(const InputEvent& event) m_mouseReceiver->onMouseWheel(event.mousePos, event.wheelDirection); break; }; + m_isOnInputEvent = false; } bool UIManager::importStyle(const std::string& file) diff --git a/src/framework/ui/uimanager.h b/src/framework/ui/uimanager.h index 5d351a4b..9cbe14a1 100644 --- a/src/framework/ui/uimanager.h +++ b/src/framework/ui/uimanager.h @@ -54,10 +54,13 @@ public: UIWidgetPtr getRootWidget() { return m_rootWidget; } + bool isOnInputEvent() { return m_isOnInputEvent; } + private: UIWidgetPtr m_rootWidget; UIWidgetPtr m_mouseReceiver; UIWidgetPtr m_keyboardReceiver; + bool m_isOnInputEvent; std::map m_styles; }; diff --git a/src/framework/ui/uiwidget.h b/src/framework/ui/uiwidget.h index ab3d4071..73384acd 100644 --- a/src/framework/ui/uiwidget.h +++ b/src/framework/ui/uiwidget.h @@ -40,11 +40,13 @@ public: void destroy(); +protected: virtual void render(); virtual void renderSelf(); virtual void renderChildren(); -protected: + friend class UIManager; + void drawBackground(const Rect& screenCoords); void drawBorder(const Rect& screenCoords); void drawImage(const Rect& screenCoords); @@ -206,7 +208,6 @@ protected: virtual void onMouseRelease(const Point& mousePos, Fw::MouseButton button); virtual bool onMouseMove(const Point& mousePos, const Point& mouseMoved); virtual bool onMouseWheel(const Point& mousePos, Fw::MouseWheelDirection direction); - friend class UIManager; protected: std::string m_id; diff --git a/src/framework/util/tools.h b/src/framework/util/tools.h index dbb3df45..68ff79fe 100644 --- a/src/framework/util/tools.h +++ b/src/framework/util/tools.h @@ -76,6 +76,11 @@ std::string mkstr(const T&... args) { return buf.str(); } +template +void throwException(const T&... args) { + throw Exception(Fw::mkstr(args...)); +} + // used by dumper struct dump_util { ~dump_util() { std::cout << std::endl; } @@ -270,9 +275,16 @@ std::vector split(const std::string& str, const std::string& separators = " " return results; } -template -void throwException(const T&... args) { - throw Exception(Fw::mkstr(args...)); +inline std::string resolvePath(const std::string& file, std::string sourcePath) { + if(boost::starts_with(file, "/")) + return file; + if(!boost::ends_with(sourcePath, "/")) { + std::size_t slashPos = sourcePath.find_last_of("/"); + if(slashPos == std::string::npos) + throwException("invalid source path '", sourcePath, "' for file '", file, "'"); + sourcePath = sourcePath.substr(0, slashPos + 1); + } + return sourcePath + file; } template diff --git a/src/otclient/const.h b/src/otclient/const.h index ebb43139..5f5b6dd2 100644 --- a/src/otclient/const.h +++ b/src/otclient/const.h @@ -23,7 +23,7 @@ #ifndef OTCLIENT_CONST_H #define OTCLIENT_CONST_H -#include +#include namespace Otc { diff --git a/src/otclient/core/outfit.h b/src/otclient/core/outfit.h index 2dc2f30a..63edb687 100644 --- a/src/otclient/core/outfit.h +++ b/src/otclient/core/outfit.h @@ -23,7 +23,7 @@ #ifndef OUTFIT_H #define OUTFIT_H -#include +#include class Outfit { diff --git a/src/otclient/core/spritemanager.cpp b/src/otclient/core/spritemanager.cpp index 60826acf..7c3ecd1a 100644 --- a/src/otclient/core/spritemanager.cpp +++ b/src/otclient/core/spritemanager.cpp @@ -39,6 +39,7 @@ bool SpriteManager::load(const std::string& file) m_signature = Fw::getU32(m_fin); m_spritesCount = Fw::getU16(m_fin); m_sprites.resize(m_spritesCount); + m_loaded = true; return true; } catch(Exception& e) { logError("Failed to load sprites from '", file, "': ", e.what()); diff --git a/src/otclient/core/spritemanager.h b/src/otclient/core/spritemanager.h index 38c49416..130254de 100644 --- a/src/otclient/core/spritemanager.h +++ b/src/otclient/core/spritemanager.h @@ -38,10 +38,12 @@ public: int getSpritesCount() { return m_spritesCount; } TexturePtr getSpriteTexture(int id); + bool isLoaded() { return m_loaded; } private: TexturePtr loadSpriteTexture(int id); + Boolean m_loaded; uint32 m_signature; uint16 m_spritesCount; std::stringstream m_fin; diff --git a/src/otclient/core/thingstype.cpp b/src/otclient/core/thingstype.cpp index 5b50a6ca..cc48a30f 100644 --- a/src/otclient/core/thingstype.cpp +++ b/src/otclient/core/thingstype.cpp @@ -48,6 +48,7 @@ bool ThingsType::load(const std::string& file) parseThingType(fin, m_things[i][id]); } + m_loaded = true; return true; } catch(Exception& e) { logError("Failed to load dat from '", file, "': ", e.what()); diff --git a/src/otclient/core/thingstype.h b/src/otclient/core/thingstype.h index 5691295d..2c8264db 100644 --- a/src/otclient/core/thingstype.h +++ b/src/otclient/core/thingstype.h @@ -47,10 +47,11 @@ public: ThingType *getThingType(uint16 id, Categories category); uint32 getSignature() { return m_signature; } + bool isLoaded() { return m_loaded; } private: uint32 m_signature; - + Boolean m_loaded; ThingTypeList m_things[LastCategory]; static ThingType m_emptyThingType; }; diff --git a/src/otclient/luafunctions.cpp b/src/otclient/luafunctions.cpp index 7b260238..4a96e5af 100644 --- a/src/otclient/luafunctions.cpp +++ b/src/otclient/luafunctions.cpp @@ -22,9 +22,15 @@ void OTClient::registerLuaFunctions() { Application::registerLuaFunctions(); + g_lua.registerStaticClass("g_thingsType"); + g_lua.bindClassStaticFunction("g_thingsType", "load", std::bind(&ThingsType::load, &g_thingsType, _1)); + g_lua.bindClassStaticFunction("g_thingsType", "isLoaded", std::bind(&ThingsType::isLoaded, &g_thingsType)); + + g_lua.registerStaticClass("g_sprites"); + g_lua.bindClassStaticFunction("g_sprites", "load", std::bind(&SpriteManager::load, &g_sprites, _1)); + g_lua.bindClassStaticFunction("g_sprites", "isLoaded", std::bind(&SpriteManager::isLoaded, &g_sprites)); + g_lua.bindGlobalFunction("exit", std::bind(&Application::exit, g_app)); - g_lua.bindGlobalFunction("importDat", std::bind(&ThingsType::load, &g_thingsType, _1)); - g_lua.bindGlobalFunction("importSpr", std::bind(&SpriteManager::load, &g_sprites, _1)); g_lua.bindGlobalFunction("getOufitColor", Outfit::getColor); g_lua.registerClass(); diff --git a/src/otclient/util/position.h b/src/otclient/util/position.h index 2e63df10..41667ade 100644 --- a/src/otclient/util/position.h +++ b/src/otclient/util/position.h @@ -25,7 +25,7 @@ #include #include -#include +#include class Position { diff --git a/tools/katepart-syntax/lua.xml b/tools/katepart-syntax/lua.xml index 66415ca3..9a12ec14 100644 --- a/tools/katepart-syntax/lua.xml +++ b/tools/katepart-syntax/lua.xml @@ -128,6 +128,9 @@ extends print fatal + newenv + getfsrcpath + resolvepath scheduleEvent addEvent