reorganize some stuff
This commit is contained in:
parent
a92af44eb6
commit
30ce5e2ba9
|
@ -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 = { }
|
||||
|
|
|
@ -12,7 +12,6 @@ Module
|
|||
require 'console'
|
||||
require 'commands'
|
||||
Console.init()
|
||||
return true
|
||||
|
||||
onUnload: |
|
||||
Console.terminate()
|
||||
|
|
|
@ -3,5 +3,4 @@ Module
|
|||
autoLoad: true
|
||||
onLoad: |
|
||||
require 'playground'
|
||||
return true
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -16,7 +16,7 @@ Module
|
|||
|
||||
onLoad: |
|
||||
require 'client'
|
||||
return Client.init()
|
||||
Client.init()
|
||||
|
||||
onUnload: |
|
||||
Client.terminate()
|
||||
|
|
|
@ -6,5 +6,3 @@ Module
|
|||
|
||||
onLoad: |
|
||||
require 'about'
|
||||
return true
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ Module
|
|||
onLoad: |
|
||||
require 'background'
|
||||
Background.create()
|
||||
return true
|
||||
|
||||
onUnload:
|
||||
Background.destroy()
|
||||
|
|
|
@ -8,7 +8,6 @@ Module
|
|||
require 'entergame'
|
||||
require 'characterlist'
|
||||
EnterGame.create()
|
||||
return true
|
||||
|
||||
onUnload:
|
||||
EnterGame.destroy()
|
||||
|
|
|
@ -6,5 +6,3 @@ Module
|
|||
|
||||
onLoad: |
|
||||
require 'options'
|
||||
return true
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit e76fa2786e2a194375a110b700b7e2daa769f960
|
||||
Subproject commit 81e6ef44c73edc5037512cdee3b2f75a23331521
|
|
@ -7,7 +7,6 @@ Module
|
|||
onLoad: |
|
||||
require 'topmenu'
|
||||
TopMenu.create()
|
||||
return true
|
||||
|
||||
onUnload: |
|
||||
TopMenu.destroy()
|
||||
|
|
|
@ -10,7 +10,7 @@ Module
|
|||
|
||||
// NOTE: order does matter
|
||||
dependencies:
|
||||
- core_scripts
|
||||
- core_lib
|
||||
- core_fonts
|
||||
- core_styles
|
||||
- core_widgets
|
||||
|
|
|
@ -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'
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
||||
|
|
@ -17,4 +17,3 @@ Module
|
|||
importStyle 'styles/creatures.otui'
|
||||
importStyle 'styles/popupmenus.otui'
|
||||
importStyle 'styles/comboboxes.otui'
|
||||
return true
|
||||
|
|
|
@ -11,4 +11,3 @@ Module
|
|||
require 'uilabel'
|
||||
require 'uicombobox'
|
||||
require 'uipopupmenu'
|
||||
return true
|
|
@ -0,0 +1,8 @@
|
|||
UICheckBox = extends(UIWidget)
|
||||
|
||||
function UICheckBox.create()
|
||||
local checkbox = UICheckBox.internalCreate()
|
||||
checkbox:setFocusable(false)
|
||||
checkbox:setAlign(AlignLeft)
|
||||
return checkbox
|
||||
end
|
|
@ -16,4 +16,3 @@ Module
|
|||
onLoad: |
|
||||
require 'game'
|
||||
require 'thing'
|
||||
return true
|
||||
|
|
|
@ -5,6 +5,3 @@ Module
|
|||
website: https://github.com/edubart/otclient
|
||||
onLoad: |
|
||||
require 'chat'
|
||||
return true
|
||||
|
||||
|
||||
|
|
|
@ -5,6 +5,3 @@ Module
|
|||
website: https://github.com/edubart/otclient
|
||||
onLoad: |
|
||||
require 'healthbar'
|
||||
return true
|
||||
|
||||
|
||||
|
|
|
@ -5,6 +5,3 @@ Module
|
|||
website: https://github.com/edubart/otclient
|
||||
onLoad: |
|
||||
require 'inventory'
|
||||
return true
|
||||
|
||||
|
||||
|
|
|
@ -5,6 +5,3 @@ Module
|
|||
website: https://github.com/edubart/otclient
|
||||
onLoad: |
|
||||
require 'outfit'
|
||||
return true
|
||||
|
||||
|
||||
|
|
|
@ -5,4 +5,3 @@ Module
|
|||
website: https://github.com/edubart/otclient
|
||||
onLoad: |
|
||||
require 'skills'
|
||||
return true
|
||||
|
|
|
@ -5,5 +5,3 @@ Module
|
|||
website: https://github.com/edubart/otclient
|
||||
onLoad: |
|
||||
require 'textmessage'
|
||||
return true
|
||||
|
||||
|
|
|
@ -5,6 +5,3 @@ Module
|
|||
website: https://github.com/edubart/otclient
|
||||
onLoad: |
|
||||
require 'viplist'
|
||||
return true
|
||||
|
||||
|
||||
|
|
|
@ -90,7 +90,7 @@ void Application::init(const std::vector<std::string>& 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.");
|
||||
}
|
||||
|
||||
|
|
|
@ -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<BooleanCallback>();
|
||||
m_loadCallback = g_lua.polymorphicPop<SimpleCallback>();
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
|
|
@ -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<std::string> m_dependencies;
|
||||
};
|
||||
|
|
|
@ -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<std::string> ResourceManager::listDirectoryFiles(const std::string& directoryPath)
|
||||
{
|
||||
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++)
|
||||
files.push_back(rc[i]);
|
||||
|
@ -158,8 +158,9 @@ std::list<std::string> 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()
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
|
||||
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();
|
||||
};
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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<Size>("glyph-size");
|
||||
m_glyphHeight = fontNode->valueAt<int>("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)
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
class ParticleAffector {
|
||||
public:
|
||||
ParticleAffector();
|
||||
virtual ~ParticleAffector() { dump << "ParticleAffector deleted"; }
|
||||
|
||||
void update(double elapsedTime);
|
||||
virtual bool load(const OTMLNodePtr& node);
|
||||
|
|
|
@ -33,7 +33,6 @@ class ParticleEmitter {
|
|||
public:
|
||||
|
||||
ParticleEmitter(const ParticleSystemPtr& parent);
|
||||
~ParticleEmitter() { dump << "ParticleEmitter deleted"; }
|
||||
|
||||
bool load(const OTMLNodePtr& node);
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
class ParticleSystem : public std::enable_shared_from_this<ParticleSystem> {
|
||||
public:
|
||||
ParticleSystem();
|
||||
~ParticleSystem() { dump << "ParticleSystem deleted"; }
|
||||
|
||||
bool load(const OTMLNodePtr& node);
|
||||
|
||||
|
|
|
@ -37,9 +37,6 @@ void Application::registerLuaFunctions()
|
|||
g_lua.registerClass<UIWidget>();
|
||||
g_lua.bindClassStaticFunction<UIWidget>("create", &UIWidget::create<UIWidget>);
|
||||
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>("setEnabled", &UIWidget::setEnabled);
|
||||
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", "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));
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
|
@ -23,7 +23,7 @@
|
|||
#ifndef POINT_H
|
||||
#define POINT_H
|
||||
|
||||
#include "types.h"
|
||||
#include "../util/types.h"
|
||||
#include <sstream>
|
||||
#include <cmath>
|
||||
|
|
@ -23,7 +23,7 @@
|
|||
#ifndef RECT_H
|
||||
#define RECT_H
|
||||
|
||||
#include "types.h"
|
||||
#include "../util/types.h"
|
||||
#include <sstream>
|
||||
|
||||
template<class T>
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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<std::string, OTMLNodePtr> m_styles;
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -76,6 +76,11 @@ std::string mkstr(const T&... args) {
|
|||
return buf.str();
|
||||
}
|
||||
|
||||
template<typename... T>
|
||||
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<T> split(const std::string& str, const std::string& separators = " "
|
|||
return results;
|
||||
}
|
||||
|
||||
template<typename... T>
|
||||
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<typename T>
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#ifndef OTCLIENT_CONST_H
|
||||
#define OTCLIENT_CONST_H
|
||||
|
||||
#include <framework/util/color.h>
|
||||
#include <framework/math/color.h>
|
||||
|
||||
namespace Otc
|
||||
{
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#ifndef OUTFIT_H
|
||||
#define OUTFIT_H
|
||||
|
||||
#include <framework/util/color.h>
|
||||
#include <framework/math/color.h>
|
||||
|
||||
class Outfit
|
||||
{
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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<false> m_loaded;
|
||||
uint32 m_signature;
|
||||
uint16 m_spritesCount;
|
||||
std::stringstream m_fin;
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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<false> m_loaded;
|
||||
ThingTypeList m_things[LastCategory];
|
||||
static ThingType m_emptyThingType;
|
||||
};
|
||||
|
|
|
@ -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<ProtocolLogin, Protocol>();
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
#include <otclient/const.h>
|
||||
#include <framework/util/types.h>
|
||||
#include <framework/util/point.h>
|
||||
#include <framework/math/point.h>
|
||||
|
||||
class Position
|
||||
{
|
||||
|
|
|
@ -128,6 +128,9 @@
|
|||
<item> extends </item>
|
||||
<item> print </item>
|
||||
<item> fatal </item>
|
||||
<item> newenv </item>
|
||||
<item> getfsrcpath </item>
|
||||
<item> resolvepath </item>
|
||||
|
||||
<item> scheduleEvent </item>
|
||||
<item> addEvent </item>
|
||||
|
|
Loading…
Reference in New Issue