reorganize some stuff

This commit is contained in:
Eduardo Bart 2012-01-04 23:28:29 -02:00
parent a92af44eb6
commit 30ce5e2ba9
69 changed files with 143 additions and 131 deletions

View File

@ -10,7 +10,7 @@ local LabelHeight = 16
-- private variables -- private variables
local consoleWidget local consoleWidget
local logLocked = false local logLocked = false
local commandEnv = createEnvironment() local commandEnv = newenv()
local commandLineEdit local commandLineEdit
local consoleBuffer local consoleBuffer
local commandHistory = { } local commandHistory = { }

View File

@ -12,7 +12,6 @@ Module
require 'console' require 'console'
require 'commands' require 'commands'
Console.init() Console.init()
return true
onUnload: | onUnload: |
Console.terminate() Console.terminate()

View File

@ -3,5 +3,4 @@ Module
autoLoad: true autoLoad: true
onLoad: | onLoad: |
require 'playground' require 'playground'
return true

View File

@ -1,8 +1,9 @@
Client = { } Client = {}
-- TODO: load and save configurations -- TODO: load and save configurations
function Client.init() function Client.init()
g_window.show() g_window.show()
g_window.setMinimumSize({ width = 550, height = 450 })
-- initialize in fullscreen mode on mobile devices -- initialize in fullscreen mode on mobile devices
if g_window.getPlatformType() == "X11-EGL" then if g_window.getPlatformType() == "X11-EGL" then
@ -19,8 +20,11 @@ function Client.init()
end end
g_window.setTitle('OTClient') g_window.setTitle('OTClient')
g_window.setIcon('clienticon.png') g_window.setIcon(resolvepath('clienticon.png'))
return true
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 end
function Client.terminate() function Client.terminate()

View File

@ -16,7 +16,7 @@ Module
onLoad: | onLoad: |
require 'client' require 'client'
return Client.init() Client.init()
onUnload: | onUnload: |
Client.terminate() Client.terminate()

View File

@ -6,5 +6,3 @@ Module
onLoad: | onLoad: |
require 'about' require 'about'
return true

View File

@ -7,7 +7,6 @@ Module
onLoad: | onLoad: |
require 'background' require 'background'
Background.create() Background.create()
return true
onUnload: onUnload:
Background.destroy() Background.destroy()

View File

@ -8,7 +8,6 @@ Module
require 'entergame' require 'entergame'
require 'characterlist' require 'characterlist'
EnterGame.create() EnterGame.create()
return true
onUnload: onUnload:
EnterGame.destroy() EnterGame.destroy()

View File

@ -6,5 +6,3 @@ Module
onLoad: | onLoad: |
require 'options' require 'options'
return true

@ -1 +1 @@
Subproject commit e76fa2786e2a194375a110b700b7e2daa769f960 Subproject commit 81e6ef44c73edc5037512cdee3b2f75a23331521

View File

@ -7,7 +7,6 @@ Module
onLoad: | onLoad: |
require 'topmenu' require 'topmenu'
TopMenu.create() TopMenu.create()
return true
onUnload: | onUnload: |
TopMenu.destroy() TopMenu.destroy()

View File

@ -10,7 +10,7 @@ Module
// NOTE: order does matter // NOTE: order does matter
dependencies: dependencies:
- core_scripts - core_lib
- core_fonts - core_fonts
- core_styles - core_styles
- core_widgets - core_widgets

View File

@ -4,10 +4,9 @@ Module
author: OTClient team author: OTClient team
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
onLoad: | onLoad: |
importFont('verdana-11px-antialised') importFont 'verdana-11px-antialised'
importFont('verdana-11px-monochrome') importFont 'verdana-11px-monochrome'
importFont('verdana-11px-rounded') importFont 'verdana-11px-rounded'
importFont('terminus-14px-bold') importFont 'terminus-14px-bold'
setDefaultFont('verdana-11px-antialised') setDefaultFont 'verdana-11px-antialised'
return true

View File

@ -1,5 +1,5 @@
Module Module
name: core_scripts name: core_lib
description: Contains core lua classes, functions and constants used by other modules description: Contains core lua classes, functions and constants used by other modules
author: OTClient team author: OTClient team
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
@ -7,14 +7,13 @@ Module
onLoad: | onLoad: |
require 'ext/table' require 'ext/table'
require 'ext/string' require 'ext/string'
require 'util/point' require 'math/point'
require 'util/size' require 'math/size'
require 'util/color' require 'math/color'
require 'util/rect' require 'math/rect'
require 'const' require 'const'
require 'util' require 'util'
require 'globals'
require 'dispatcher' require 'dispatcher'
require 'widget' require 'widget'
require 'ui'
require 'effects' require 'effects'
return true

View File

@ -1,9 +1,15 @@
-- globals
rootWidget = g_ui.getRootWidget() rootWidget = g_ui.getRootWidget()
-- public functions
function importStyle(otui) 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 end
function displayUI(arg1, options) function displayUI(arg1, options)
@ -14,7 +20,7 @@ function displayUI(arg1, options)
-- display otui files -- display otui files
if type(arg1) == 'string' then if type(arg1) == 'string' then
local otuiFilePath = resolveFileFullPath(arg1, 2) local otuiFilePath = resolvepath(arg1, 2)
widget = g_ui.loadUI(otuiFilePath, parent) widget = g_ui.loadUI(otuiFilePath, parent)
-- display already loaded widgets -- display already loaded widgets
else else

View File

@ -26,13 +26,26 @@ function connect(object, signalsAndSlots, pushFront)
end end
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 = { } local env = { }
setmetatable(env, { __index = _G} ) setmetatable(env, { __index = _G} )
return env return env
end end
function getCallingScriptSourcePath(depth) function getfsrcpath(depth)
depth = depth or 2 depth = depth or 2
local info = debug.getinfo(1+depth, "Sn") local info = debug.getinfo(1+depth, "Sn")
local path local path
@ -47,25 +60,11 @@ function getCallingScriptSourcePath(depth)
return path return path
end end
function resolveFileFullPath(filePath, depth) function resolvepath(filePath, depth)
depth = depth or 1 depth = depth or 1
if filePath:sub(0, 1) ~= '/' then if filePath:sub(0, 1) ~= '/' then
return getCallingScriptSourcePath(depth+1) .. '/' .. filePath return getfsrcpath(depth+1) .. '/' .. filePath
else else
return filePath return filePath
end end
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

View File

@ -17,4 +17,3 @@ Module
importStyle 'styles/creatures.otui' importStyle 'styles/creatures.otui'
importStyle 'styles/popupmenus.otui' importStyle 'styles/popupmenus.otui'
importStyle 'styles/comboboxes.otui' importStyle 'styles/comboboxes.otui'
return true

View File

@ -11,4 +11,3 @@ Module
require 'uilabel' require 'uilabel'
require 'uicombobox' require 'uicombobox'
require 'uipopupmenu' require 'uipopupmenu'
return true

View File

@ -0,0 +1,8 @@
UICheckBox = extends(UIWidget)
function UICheckBox.create()
local checkbox = UICheckBox.internalCreate()
checkbox:setFocusable(false)
checkbox:setAlign(AlignLeft)
return checkbox
end

View File

@ -16,4 +16,3 @@ Module
onLoad: | onLoad: |
require 'game' require 'game'
require 'thing' require 'thing'
return true

View File

@ -5,6 +5,3 @@ Module
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
onLoad: | onLoad: |
require 'chat' require 'chat'
return true

View File

@ -5,6 +5,3 @@ Module
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
onLoad: | onLoad: |
require 'healthbar' require 'healthbar'
return true

View File

@ -5,6 +5,3 @@ Module
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
onLoad: | onLoad: |
require 'inventory' require 'inventory'
return true

View File

@ -5,6 +5,3 @@ Module
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
onLoad: | onLoad: |
require 'outfit' require 'outfit'
return true

View File

@ -5,4 +5,3 @@ Module
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
onLoad: | onLoad: |
require 'skills' require 'skills'
return true

View File

@ -5,5 +5,3 @@ Module
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
onLoad: | onLoad: |
require 'textmessage' require 'textmessage'
return true

View File

@ -5,6 +5,3 @@ Module
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
onLoad: | onLoad: |
require 'viplist' require 'viplist'
return true

View File

@ -90,7 +90,7 @@ void Application::init(const std::vector<std::string>& args, int appFlags)
logError("Could not setup write directory"); logError("Could not setup write directory");
// load configs // load configs
if(!g_configs.load("config.otml")) if(!g_configs.load("/config.otml"))
logInfo("Using default configurations."); logInfo("Using default configurations.");
} }

View File

@ -50,7 +50,7 @@ void Module::discover(const OTMLNodePtr& moduleNode)
if(OTMLNodePtr node = moduleNode->get("onLoad")) { if(OTMLNodePtr node = moduleNode->get("onLoad")) {
g_lua.loadFunction(node->value(), "@" + node->source() + "[" + node->tag() + "]"); g_lua.loadFunction(node->value(), "@" + node->source() + "[" + node->tag() + "]");
g_lua.useValue(); g_lua.useValue();
m_loadCallback = g_lua.polymorphicPop<BooleanCallback>(); m_loadCallback = g_lua.polymorphicPop<SimpleCallback>();
} }
// set onUnload callback // set onUnload callback
@ -79,10 +79,8 @@ bool Module::load()
} }
} }
if(m_loadCallback && !m_loadCallback()) { if(m_loadCallback)
logError("Unable to load module '", m_name, "' because its onLoad event returned false"); m_loadCallback();
return false;
}
logInfo("Loaded module '", m_name, "'"); logInfo("Loaded module '", m_name, "'");
m_loaded = true; m_loaded = true;

View File

@ -55,7 +55,7 @@ private:
std::string m_author; std::string m_author;
std::string m_website; std::string m_website;
std::string m_version; std::string m_version;
BooleanCallback m_loadCallback; SimpleCallback m_loadCallback;
SimpleCallback m_unloadCallback; SimpleCallback m_unloadCallback;
std::list<std::string> m_dependencies; std::list<std::string> m_dependencies;
}; };

View File

@ -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) 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) { for(const std::string& file : files) {
if(boost::ends_with(file, packageExt)) if(boost::ends_with(file, packageExt))
addToSearchPath(packagesDir + "/" + file, !append); addToSearchPath(packagesDir + "/" + file, !append);
@ -76,17 +76,17 @@ void ResourceManager::searchAndAddPackages(const std::string& packagesDir, const
bool ResourceManager::fileExists(const std::string& fileName) 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) 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) 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); out.clear(std::ios::goodbit);
PHYSFS_file* file = PHYSFS_openRead(fullPath.c_str()); PHYSFS_file* file = PHYSFS_openRead(fullPath.c_str());
if(!file) { 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) 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) if(!file)
return false; return false;
@ -143,13 +143,13 @@ bool ResourceManager::saveFile(const std::string& fileName, const std::string& d
bool ResourceManager::deleteFile(const std::string& fileName) 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<std::string> ResourceManager::listDirectoryFiles(const std::string& directoryPath) std::list<std::string> ResourceManager::listDirectoryFiles(const std::string& directoryPath)
{ {
std::list<std::string> files; std::list<std::string> 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++) for(int i = 0; rc[i] != NULL; i++)
files.push_back(rc[i]); files.push_back(rc[i]);
@ -158,8 +158,9 @@ std::list<std::string> ResourceManager::listDirectoryFiles(const std::string& di
return files; return files;
} }
std::string ResourceManager::resolvePath(const std::string& path) std::string ResourceManager::checkPath(const std::string& path)
{ {
/*
std::string fullPath; std::string fullPath;
if(boost::starts_with(path, "/")) if(boost::starts_with(path, "/"))
fullPath = path; fullPath = path;
@ -169,7 +170,10 @@ std::string ResourceManager::resolvePath(const std::string& path)
fullPath += scriptPath + "/"; fullPath += scriptPath + "/";
fullPath += path; 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() std::string ResourceManager::getBaseDir()

View File

@ -50,7 +50,7 @@ public:
std::list<std::string> listDirectoryFiles(const std::string& directoryPath = ""); std::list<std::string> listDirectoryFiles(const std::string& directoryPath = "");
std::string resolvePath(const std::string& path); std::string checkPath(const std::string& path);
std::string getBaseDir(); std::string getBaseDir();
}; };

View File

@ -32,11 +32,11 @@
// additional utilities // additional utilities
#include "util/types.h" #include "util/types.h"
#include "util/tools.h" #include "util/tools.h"
#include "util/point.h" #include "math/point.h"
#include "util/color.h" #include "math/color.h"
#include "util/rect.h" #include "math/rect.h"
#include "util/size.h" #include "math/size.h"
#include "util/matrix.h" #include "math/matrix.h"
// logger // logger
#include "core/logger.h" #include "core/logger.h"

View File

@ -28,7 +28,8 @@
void Font::load(const OTMLNodePtr& fontNode) 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<Size>("glyph-size"); Size glyphSize = fontNode->valueAt<Size>("glyph-size");
m_glyphHeight = fontNode->valueAt<int>("height"); m_glyphHeight = fontNode->valueAt<int>("height");
m_yOffset = fontNode->valueAt("y-offset", 0); 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)); m_glyphSpacing = fontNode->valueAt("spacing", Size(0,0));
// load font texture // load font texture
m_texture = g_textures.getTexture(textureName); m_texture = g_textures.getTexture(textureFile);
if(OTMLNodePtr node = fontNode->get("fixed-glyph-width")) { if(OTMLNodePtr node = fontNode->get("fixed-glyph-width")) {
for(int glyph = m_firstGlyph; glyph < 256; ++glyph) for(int glyph = m_firstGlyph; glyph < 256; ++glyph)

View File

@ -29,7 +29,6 @@
class ParticleAffector { class ParticleAffector {
public: public:
ParticleAffector(); ParticleAffector();
virtual ~ParticleAffector() { dump << "ParticleAffector deleted"; }
void update(double elapsedTime); void update(double elapsedTime);
virtual bool load(const OTMLNodePtr& node); virtual bool load(const OTMLNodePtr& node);

View File

@ -33,7 +33,6 @@ class ParticleEmitter {
public: public:
ParticleEmitter(const ParticleSystemPtr& parent); ParticleEmitter(const ParticleSystemPtr& parent);
~ParticleEmitter() { dump << "ParticleEmitter deleted"; }
bool load(const OTMLNodePtr& node); bool load(const OTMLNodePtr& node);

View File

@ -30,7 +30,6 @@
class ParticleSystem : public std::enable_shared_from_this<ParticleSystem> { class ParticleSystem : public std::enable_shared_from_this<ParticleSystem> {
public: public:
ParticleSystem(); ParticleSystem();
~ParticleSystem() { dump << "ParticleSystem deleted"; }
bool load(const OTMLNodePtr& node); bool load(const OTMLNodePtr& node);

View File

@ -37,9 +37,6 @@ void Application::registerLuaFunctions()
g_lua.registerClass<UIWidget>(); g_lua.registerClass<UIWidget>();
g_lua.bindClassStaticFunction<UIWidget>("create", &UIWidget::create<UIWidget>); g_lua.bindClassStaticFunction<UIWidget>("create", &UIWidget::create<UIWidget>);
g_lua.bindClassMemberFunction<UIWidget>("destroy", &UIWidget::destroy); g_lua.bindClassMemberFunction<UIWidget>("destroy", &UIWidget::destroy);
g_lua.bindClassMemberFunction<UIWidget>("render", &UIWidget::render);
g_lua.bindClassMemberFunction<UIWidget>("renderSelf", &UIWidget::renderSelf);
g_lua.bindClassMemberFunction<UIWidget>("renderChildren", &UIWidget::renderChildren);
g_lua.bindClassMemberFunction<UIWidget>("setVisible", &UIWidget::setVisible); g_lua.bindClassMemberFunction<UIWidget>("setVisible", &UIWidget::setVisible);
g_lua.bindClassMemberFunction<UIWidget>("setEnabled", &UIWidget::setEnabled); g_lua.bindClassMemberFunction<UIWidget>("setEnabled", &UIWidget::setEnabled);
g_lua.bindClassMemberFunction<UIWidget>("setPressed", &UIWidget::setPressed); g_lua.bindClassMemberFunction<UIWidget>("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", "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", "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", "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", "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", "setFullscreen", std::bind(&PlatformWindow::setFullscreen, &g_window, _1));
g_lua.bindClassStaticFunction("g_window", "setTitle", std::bind(&PlatformWindow::setTitle, &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", "loadUI", std::bind(&UIManager::loadUI, &g_ui, _1, _2));
g_lua.bindClassStaticFunction("g_ui", "getRootWidget", std::bind(&UIManager::getRootWidget, &g_ui)); g_lua.bindClassStaticFunction("g_ui", "getRootWidget", std::bind(&UIManager::getRootWidget, &g_ui));
/*
// FontManager // FontManager
g_lua.registerStaticClass("g_fonts"); 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", "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", "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)); g_lua.bindClassStaticFunction("g_fonts", "setDefaultFont", std::bind(&FontManager::setDefaultFont, &g_fonts, _1));
*/
// EventDispatcher
g_lua.registerStaticClass("g_dispatcher"); g_lua.registerStaticClass("g_dispatcher");
g_lua.bindClassStaticFunction("g_dispatcher", "addEvent", std::bind(&EventDispatcher::addEvent, &g_dispatcher, _1, _2)); 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)); 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));
} }

View File

@ -290,9 +290,14 @@ void LuaInterface::runBuffer(const std::string& buffer, const std::string& sourc
void LuaInterface::loadScript(const std::string& fileName) void LuaInterface::loadScript(const std::string& fileName)
{ {
std::string buffer = g_resources.loadFile(fileName); // resolve file full path
std::string source = "@" + g_resources.resolvePath(fileName); std::string filePath = fileName;
loadBuffer(g_resources.loadFile(fileName), "@" + g_resources.resolvePath(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) void LuaInterface::loadFunction(const std::string& buffer, const std::string& source)

View File

@ -23,8 +23,8 @@
#ifndef COLOR_H #ifndef COLOR_H
#define COLOR_H #define COLOR_H
#include "types.h" #include "../util/types.h"
#include "tools.h" #include "../util/tools.h"
#include "../const.h" #include "../const.h"
class Color class Color

View File

@ -23,7 +23,7 @@
#ifndef POINT_H #ifndef POINT_H
#define POINT_H #define POINT_H
#include "types.h" #include "../util/types.h"
#include <sstream> #include <sstream>
#include <cmath> #include <cmath>

View File

@ -23,7 +23,7 @@
#ifndef RECT_H #ifndef RECT_H
#define RECT_H #define RECT_H
#include "types.h" #include "../util/types.h"
#include <sstream> #include <sstream>
template<class T> template<class T>

View File

@ -37,7 +37,7 @@ OTMLDocumentPtr OTMLDocument::parse(const std::string& fileName)
{ {
std::stringstream fin; std::stringstream fin;
g_resources.loadFile(fileName, 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) OTMLDocumentPtr OTMLDocument::parse(std::istream& in, const std::string& source)

View File

@ -57,6 +57,7 @@ void UIManager::resize(const Size& size)
void UIManager::inputEvent(const InputEvent& event) void UIManager::inputEvent(const InputEvent& event)
{ {
m_isOnInputEvent = true;
switch(event.type) { switch(event.type) {
case Fw::KeyPressInputEvent: case Fw::KeyPressInputEvent:
m_keyboardReceiver->onKeyPress(event.keyCode, event.keyText, event.keyboardModifiers); 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); m_mouseReceiver->onMouseWheel(event.mousePos, event.wheelDirection);
break; break;
}; };
m_isOnInputEvent = false;
} }
bool UIManager::importStyle(const std::string& file) bool UIManager::importStyle(const std::string& file)

View File

@ -54,10 +54,13 @@ public:
UIWidgetPtr getRootWidget() { return m_rootWidget; } UIWidgetPtr getRootWidget() { return m_rootWidget; }
bool isOnInputEvent() { return m_isOnInputEvent; }
private: private:
UIWidgetPtr m_rootWidget; UIWidgetPtr m_rootWidget;
UIWidgetPtr m_mouseReceiver; UIWidgetPtr m_mouseReceiver;
UIWidgetPtr m_keyboardReceiver; UIWidgetPtr m_keyboardReceiver;
bool m_isOnInputEvent;
std::map<std::string, OTMLNodePtr> m_styles; std::map<std::string, OTMLNodePtr> m_styles;
}; };

View File

@ -40,11 +40,13 @@ public:
void destroy(); void destroy();
protected:
virtual void render(); virtual void render();
virtual void renderSelf(); virtual void renderSelf();
virtual void renderChildren(); virtual void renderChildren();
protected: friend class UIManager;
void drawBackground(const Rect& screenCoords); void drawBackground(const Rect& screenCoords);
void drawBorder(const Rect& screenCoords); void drawBorder(const Rect& screenCoords);
void drawImage(const Rect& screenCoords); void drawImage(const Rect& screenCoords);
@ -206,7 +208,6 @@ protected:
virtual void onMouseRelease(const Point& mousePos, Fw::MouseButton button); virtual void onMouseRelease(const Point& mousePos, Fw::MouseButton button);
virtual bool onMouseMove(const Point& mousePos, const Point& mouseMoved); virtual bool onMouseMove(const Point& mousePos, const Point& mouseMoved);
virtual bool onMouseWheel(const Point& mousePos, Fw::MouseWheelDirection direction); virtual bool onMouseWheel(const Point& mousePos, Fw::MouseWheelDirection direction);
friend class UIManager;
protected: protected:
std::string m_id; std::string m_id;

View File

@ -76,6 +76,11 @@ std::string mkstr(const T&... args) {
return buf.str(); return buf.str();
} }
template<typename... T>
void throwException(const T&... args) {
throw Exception(Fw::mkstr(args...));
}
// used by dumper // used by dumper
struct dump_util { struct dump_util {
~dump_util() { std::cout << std::endl; } ~dump_util() { std::cout << std::endl; }
@ -270,9 +275,16 @@ std::vector<T> split(const std::string& str, const std::string& separators = " "
return results; return results;
} }
template<typename... T> inline std::string resolvePath(const std::string& file, std::string sourcePath) {
void throwException(const T&... args) { if(boost::starts_with(file, "/"))
throw Exception(Fw::mkstr(args...)); 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<typename T> template<typename T>

View File

@ -23,7 +23,7 @@
#ifndef OTCLIENT_CONST_H #ifndef OTCLIENT_CONST_H
#define OTCLIENT_CONST_H #define OTCLIENT_CONST_H
#include <framework/util/color.h> #include <framework/math/color.h>
namespace Otc namespace Otc
{ {

View File

@ -23,7 +23,7 @@
#ifndef OUTFIT_H #ifndef OUTFIT_H
#define OUTFIT_H #define OUTFIT_H
#include <framework/util/color.h> #include <framework/math/color.h>
class Outfit class Outfit
{ {

View File

@ -39,6 +39,7 @@ bool SpriteManager::load(const std::string& file)
m_signature = Fw::getU32(m_fin); m_signature = Fw::getU32(m_fin);
m_spritesCount = Fw::getU16(m_fin); m_spritesCount = Fw::getU16(m_fin);
m_sprites.resize(m_spritesCount); m_sprites.resize(m_spritesCount);
m_loaded = true;
return true; return true;
} catch(Exception& e) { } catch(Exception& e) {
logError("Failed to load sprites from '", file, "': ", e.what()); logError("Failed to load sprites from '", file, "': ", e.what());

View File

@ -38,10 +38,12 @@ public:
int getSpritesCount() { return m_spritesCount; } int getSpritesCount() { return m_spritesCount; }
TexturePtr getSpriteTexture(int id); TexturePtr getSpriteTexture(int id);
bool isLoaded() { return m_loaded; }
private: private:
TexturePtr loadSpriteTexture(int id); TexturePtr loadSpriteTexture(int id);
Boolean<false> m_loaded;
uint32 m_signature; uint32 m_signature;
uint16 m_spritesCount; uint16 m_spritesCount;
std::stringstream m_fin; std::stringstream m_fin;

View File

@ -48,6 +48,7 @@ bool ThingsType::load(const std::string& file)
parseThingType(fin, m_things[i][id]); parseThingType(fin, m_things[i][id]);
} }
m_loaded = true;
return true; return true;
} catch(Exception& e) { } catch(Exception& e) {
logError("Failed to load dat from '", file, "': ", e.what()); logError("Failed to load dat from '", file, "': ", e.what());

View File

@ -47,10 +47,11 @@ public:
ThingType *getThingType(uint16 id, Categories category); ThingType *getThingType(uint16 id, Categories category);
uint32 getSignature() { return m_signature; } uint32 getSignature() { return m_signature; }
bool isLoaded() { return m_loaded; }
private: private:
uint32 m_signature; uint32 m_signature;
Boolean<false> m_loaded;
ThingTypeList m_things[LastCategory]; ThingTypeList m_things[LastCategory];
static ThingType m_emptyThingType; static ThingType m_emptyThingType;
}; };

View File

@ -22,9 +22,15 @@ void OTClient::registerLuaFunctions()
{ {
Application::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("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.bindGlobalFunction("getOufitColor", Outfit::getColor);
g_lua.registerClass<ProtocolLogin, Protocol>(); g_lua.registerClass<ProtocolLogin, Protocol>();

View File

@ -25,7 +25,7 @@
#include <otclient/const.h> #include <otclient/const.h>
#include <framework/util/types.h> #include <framework/util/types.h>
#include <framework/util/point.h> #include <framework/math/point.h>
class Position class Position
{ {

View File

@ -128,6 +128,9 @@
<item> extends </item> <item> extends </item>
<item> print </item> <item> print </item>
<item> fatal </item> <item> fatal </item>
<item> newenv </item>
<item> getfsrcpath </item>
<item> resolvepath </item>
<item> scheduleEvent </item> <item> scheduleEvent </item>
<item> addEvent </item> <item> addEvent </item>