Browse Source

reorganize some stuff

Eduardo Bart 9 years ago
parent
commit
30ce5e2ba9
69 changed files with 143 additions and 129 deletions
  1. 1
    1
      modules/addon_console/console.lua
  2. 0
    1
      modules/addon_console/console.otmod
  3. 0
    1
      modules/addon_playground/playground.otmod
  4. 7
    3
      modules/client/client.lua
  5. 1
    1
      modules/client/client.otmod
  6. 0
    2
      modules/client_about/about.otmod
  7. 0
    1
      modules/client_background/background.otmod
  8. 0
    1
      modules/client_entergame/entergame.otmod
  9. 0
    2
      modules/client_options/options.otmod
  10. 1
    1
      modules/client_tibiafiles
  11. 0
    1
      modules/client_topmenu/topmenu.otmod
  12. 1
    1
      modules/core/core.otmod
  13. 5
    6
      modules/core_fonts/core_fonts.otmod
  14. 0
    0
      modules/core_lib/const.lua
  15. 6
    7
      modules/core_lib/core_lib.otmod
  16. 0
    0
      modules/core_lib/dispatcher.lua
  17. 0
    0
      modules/core_lib/effects.lua
  18. 0
    0
      modules/core_lib/ext/string.lua
  19. 0
    0
      modules/core_lib/ext/table.lua
  20. 10
    2
      modules/core_lib/globals.lua
  21. 0
    0
      modules/core_lib/hotkeys.lua
  22. 0
    0
      modules/core_lib/math/color.lua
  23. 0
    0
      modules/core_lib/math/point.lua
  24. 0
    0
      modules/core_lib/math/rect.lua
  25. 0
    0
      modules/core_lib/math/size.lua
  26. 17
    18
      modules/core_lib/util.lua
  27. 0
    0
      modules/core_lib/widget.lua
  28. 0
    1
      modules/core_styles/core_styles.otmod
  29. 1
    2
      modules/core_widgets/core_widgets.otmod
  30. 8
    0
      modules/core_widgets/uicheckbox.lua
  31. 0
    1
      modules/game/game.otmod
  32. 0
    3
      modules/game_chat/chat.otmod
  33. 0
    3
      modules/game_healthbar/healthbar.otmod
  34. 0
    3
      modules/game_inventory/inventory.otmod
  35. 0
    3
      modules/game_outfit/outfit.otmod
  36. 0
    1
      modules/game_skills/skills.otmod
  37. 0
    2
      modules/game_textmessage/textmessage.otmod
  38. 0
    3
      modules/game_viplist/viplist.otmod
  39. 1
    1
      src/framework/application.cpp
  40. 3
    5
      src/framework/core/module.cpp
  41. 1
    1
      src/framework/core/module.h
  42. 13
    9
      src/framework/core/resourcemanager.cpp
  43. 1
    1
      src/framework/core/resourcemanager.h
  44. 5
    5
      src/framework/global.h
  45. 3
    2
      src/framework/graphics/font.cpp
  46. 0
    1
      src/framework/graphics/particleaffector.h
  47. 0
    1
      src/framework/graphics/particleemitter.h
  48. 0
    1
      src/framework/graphics/particlesystem.h
  49. 2
    12
      src/framework/luafunctions.cpp
  50. 8
    3
      src/framework/luascript/luainterface.cpp
  51. 2
    2
      src/framework/math/color.h
  52. 0
    0
      src/framework/math/matrix.h
  53. 1
    1
      src/framework/math/point.h
  54. 1
    1
      src/framework/math/rect.h
  55. 0
    0
      src/framework/math/size.h
  56. 1
    1
      src/framework/otml/otmldocument.cpp
  57. 2
    0
      src/framework/ui/uimanager.cpp
  58. 3
    0
      src/framework/ui/uimanager.h
  59. 3
    2
      src/framework/ui/uiwidget.h
  60. 15
    3
      src/framework/util/tools.h
  61. 1
    1
      src/otclient/const.h
  62. 1
    1
      src/otclient/core/outfit.h
  63. 1
    0
      src/otclient/core/spritemanager.cpp
  64. 2
    0
      src/otclient/core/spritemanager.h
  65. 1
    0
      src/otclient/core/thingstype.cpp
  66. 2
    1
      src/otclient/core/thingstype.h
  67. 8
    2
      src/otclient/luafunctions.cpp
  68. 1
    1
      src/otclient/util/position.h
  69. 3
    0
      tools/katepart-syntax/lua.xml

+ 1
- 1
modules/addon_console/console.lua View File

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

+ 0
- 1
modules/addon_console/console.otmod View File

@@ -12,7 +12,6 @@ Module
12 12
     require 'console'
13 13
     require 'commands'
14 14
     Console.init()
15
-    return true
16 15
 
17 16
   onUnload: |
18 17
     Console.terminate()

+ 0
- 1
modules/addon_playground/playground.otmod View File

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

+ 7
- 3
modules/client/client.lua View File

@@ -1,8 +1,9 @@
1
-Client = { }
1
+Client = {}
2 2
 
3 3
 -- TODO: load and save configurations
4 4
 function Client.init()
5 5
   g_window.show()
6
+  g_window.setMinimumSize({ width = 550, height = 450 })
6 7
 
7 8
   -- initialize in fullscreen mode on mobile devices
8 9
   if g_window.getPlatformType() == "X11-EGL" then
@@ -19,8 +20,11 @@ function Client.init()
19 20
   end
20 21
 
21 22
   g_window.setTitle('OTClient')
22
-  g_window.setIcon('clienticon.png')
23
-  return true
23
+  g_window.setIcon(resolvepath('clienticon.png'))
24
+
25
+  if not g_sprites.isLoaded() or not g_thingsType.isLoaded() then
26
+    fatal("spr and dat files are not loaded, did you loaded them?")
27
+  end
24 28
 end
25 29
 
26 30
 function Client.terminate()

+ 1
- 1
modules/client/client.otmod View File

@@ -16,7 +16,7 @@ Module
16 16
 
17 17
   onLoad: |
18 18
     require 'client'
19
-    return Client.init()
19
+    Client.init()
20 20
 
21 21
   onUnload: |
22 22
     Client.terminate()

+ 0
- 2
modules/client_about/about.otmod View File

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

+ 0
- 1
modules/client_background/background.otmod View File

@@ -7,7 +7,6 @@ Module
7 7
   onLoad: |
8 8
     require 'background'
9 9
     Background.create()
10
-    return true
11 10
 
12 11
   onUnload:
13 12
     Background.destroy()

+ 0
- 1
modules/client_entergame/entergame.otmod View File

@@ -8,7 +8,6 @@ Module
8 8
     require 'entergame'
9 9
     require 'characterlist'
10 10
     EnterGame.create()
11
-    return true
12 11
 
13 12
   onUnload:
14 13
     EnterGame.destroy()

+ 0
- 2
modules/client_options/options.otmod View File

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

+ 1
- 1
modules/client_tibiafiles

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

+ 0
- 1
modules/client_topmenu/topmenu.otmod View File

@@ -7,7 +7,6 @@ Module
7 7
   onLoad: |
8 8
     require 'topmenu'
9 9
     TopMenu.create()
10
-    return true
11 10
 
12 11
   onUnload: |
13 12
     TopMenu.destroy()

+ 1
- 1
modules/core/core.otmod View File

@@ -10,7 +10,7 @@ Module
10 10
 
11 11
   // NOTE: order does matter
12 12
   dependencies:
13
-    - core_scripts
13
+    - core_lib
14 14
     - core_fonts
15 15
     - core_styles
16 16
     - core_widgets

+ 5
- 6
modules/core_fonts/core_fonts.otmod View File

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

modules/core_scripts/const.lua → modules/core_lib/const.lua View File


modules/core_scripts/core_scripts.otmod → modules/core_lib/core_lib.otmod View File

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

modules/core_scripts/dispatcher.lua → modules/core_lib/dispatcher.lua View File


modules/core_scripts/effects.lua → modules/core_lib/effects.lua View File


modules/core_scripts/ext/string.lua → modules/core_lib/ext/string.lua View File


modules/core_scripts/ext/table.lua → modules/core_lib/ext/table.lua View File


modules/core_scripts/ui.lua → modules/core_lib/globals.lua View File

@@ -1,9 +1,15 @@
1 1
 rootWidget = g_ui.getRootWidget()
2 2
 
3 3
 function importStyle(otui)
4
-  g_ui.importStyle(resolveFileFullPath(otui, 2))
4
+  g_ui.importStyle(resolvepath(otui, 2))
5
+end
6
+
7
+function importFont(otfont)
8
+  g_fonts.importFont(resolvepath(otfont, 2))
9
+end
10
+
11
+function setDefaultFont(font)
12
+  g_fonts.setDefaultFont(font)
5 13
 end
6 14
 
7 15
 function displayUI(arg1, options)
@@ -14,7 +20,7 @@ function displayUI(arg1, options)
14 20
 
15 21
   -- display otui files
16 22
   if type(arg1) == 'string' then
17
-    local otuiFilePath = resolveFileFullPath(arg1, 2)
23
+    local otuiFilePath = resolvepath(arg1, 2)
18 24
     widget = g_ui.loadUI(otuiFilePath, parent)
19 25
   -- display already loaded widgets
20 26
   else

modules/core_scripts/hotkeys.lua → modules/core_lib/hotkeys.lua View File


modules/core_scripts/util/color.lua → modules/core_lib/math/color.lua View File


modules/core_scripts/util/point.lua → modules/core_lib/math/point.lua View File


modules/core_scripts/util/rect.lua → modules/core_lib/math/rect.lua View File


modules/core_scripts/util/size.lua → modules/core_lib/math/size.lua View File


modules/core_scripts/util.lua → modules/core_lib/util.lua View File

@@ -26,13 +26,26 @@ function connect(object, signalsAndSlots, pushFront)
26 26
   end
27 27
 end
28 28
 
29
-function createEnvironment()
29
+function extends(base)
30
+  local derived = {}
31
+  function derived.internalCreate()
32
+    local instance = base.create()
33
+    for k,v in pairs(derived) do
34
+      instance[k] = v
35
+    end
36
+    return instance
37
+  end
38
+  derived.create = derived.internalCreate
39
+  return derived
40
+end
41
+
42
+function newenv()
30 43
   local env = { }
31 44
   setmetatable(env, { __index = _G} )
32 45
   return env
33 46
 end
34 47
 
35
-function getCallingScriptSourcePath(depth)
48
+function getfsrcpath(depth)
36 49
   depth = depth or 2
37 50
   local info = debug.getinfo(1+depth, "Sn")
38 51
   local path
@@ -47,25 +60,11 @@ function getCallingScriptSourcePath(depth)
47 60
   return path
48 61
 end
49 62
 
50
-function resolveFileFullPath(filePath, depth)
63
+function resolvepath(filePath, depth)
51 64
   depth = depth or 1
52 65
   if filePath:sub(0, 1) ~= '/' then
53
-    return getCallingScriptSourcePath(depth+1) .. '/' .. filePath
66
+    return getfsrcpath(depth+1) .. '/' .. filePath
54 67
   else
55 68
     return filePath
56 69
   end
57 70
 end
58
-
59
-function extends(base)
60
-  local derived = {}
61
-  function derived.internalCreate()
62
-    local instance = base.create()
63
-    for k,v in pairs(derived) do
64
-      instance[k] = v
65
-    end
66
-    return instance
67
-  end
68
-  derived.create = derived.internalCreate
69
-  return derived
70
-end
71
-

modules/core_scripts/widget.lua → modules/core_lib/widget.lua View File


+ 0
- 1
modules/core_styles/core_styles.otmod View File

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

+ 1
- 2
modules/core_widgets/core_widgets.otmod View File

@@ -10,5 +10,4 @@ Module
10 10
     require 'uibutton'
11 11
     require 'uilabel'
12 12
     require 'uicombobox'
13
-    require 'uipopupmenu'
14
-    return true
13
+    require 'uipopupmenu'

+ 8
- 0
modules/core_widgets/uicheckbox.lua View File

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

+ 0
- 1
modules/game/game.otmod View File

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

+ 0
- 3
modules/game_chat/chat.otmod View File

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

+ 0
- 3
modules/game_healthbar/healthbar.otmod View File

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

+ 0
- 3
modules/game_inventory/inventory.otmod View File

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

+ 0
- 3
modules/game_outfit/outfit.otmod View File

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

+ 0
- 1
modules/game_skills/skills.otmod View File

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

+ 0
- 2
modules/game_textmessage/textmessage.otmod View File

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

+ 0
- 3
modules/game_viplist/viplist.otmod View File

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

+ 1
- 1
src/framework/application.cpp View File

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

+ 3
- 5
src/framework/core/module.cpp View File

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

+ 1
- 1
src/framework/core/module.h View File

@@ -55,7 +55,7 @@ private:
55 55
     std::string m_author;
56 56
     std::string m_website;
57 57
     std::string m_version;
58
-    BooleanCallback m_loadCallback;
58
+    SimpleCallback m_loadCallback;
59 59
     SimpleCallback m_unloadCallback;
60 60
     std::list<std::string> m_dependencies;
61 61
 };

+ 13
- 9
src/framework/core/resourcemanager.cpp View File

@@ -67,7 +67,7 @@ bool ResourceManager::addToSearchPath(const std::string& path, bool insertInFron
67 67
 
68 68
 void ResourceManager::searchAndAddPackages(const std::string& packagesDir, const std::string& packageExt, bool append)
69 69
 {
70
-    auto files = listDirectoryFiles(resolvePath(packagesDir));
70
+    auto files = listDirectoryFiles(checkPath(packagesDir));
71 71
     for(const std::string& file : files) {
72 72
         if(boost::ends_with(file, packageExt))
73 73
             addToSearchPath(packagesDir + "/" + file, !append);
@@ -76,17 +76,17 @@ void ResourceManager::searchAndAddPackages(const std::string& packagesDir, const
76 76
 
77 77
 bool ResourceManager::fileExists(const std::string& fileName)
78 78
 {
79
-    return (PHYSFS_exists(resolvePath(fileName).c_str()) && !PHYSFS_isDirectory(resolvePath(fileName).c_str()));
79
+    return (PHYSFS_exists(checkPath(fileName).c_str()) && !PHYSFS_isDirectory(checkPath(fileName).c_str()));
80 80
 }
81 81
 
82 82
 bool ResourceManager::directoryExists(const std::string& directoryName)
83 83
 {
84
-    return (PHYSFS_isDirectory(resolvePath(directoryName).c_str()));
84
+    return (PHYSFS_isDirectory(checkPath(directoryName).c_str()));
85 85
 }
86 86
 
87 87
 void ResourceManager::loadFile(const std::string& fileName, std::iostream& out)
88 88
 {
89
-    std::string fullPath = resolvePath(fileName);
89
+    std::string fullPath = checkPath(fileName);
90 90
     out.clear(std::ios::goodbit);
91 91
     PHYSFS_file* file = PHYSFS_openRead(fullPath.c_str());
92 92
     if(!file) {
@@ -114,7 +114,7 @@ std::string ResourceManager::loadFile(const std::string& fileName)
114 114
 
115 115
 bool ResourceManager::saveFile(const std::string& fileName, const uchar* data, uint size)
116 116
 {
117
-    PHYSFS_file* file = PHYSFS_openWrite(resolvePath(fileName).c_str());
117
+    PHYSFS_file* file = PHYSFS_openWrite(checkPath(fileName).c_str());
118 118
     if(!file)
119 119
         return false;
120 120
 
@@ -143,13 +143,13 @@ bool ResourceManager::saveFile(const std::string& fileName, const std::string& d
143 143
 
144 144
 bool ResourceManager::deleteFile(const std::string& fileName)
145 145
 {
146
-    return PHYSFS_delete(resolvePath(fileName).c_str()) != 0;
146
+    return PHYSFS_delete(checkPath(fileName).c_str()) != 0;
147 147
 }
148 148
 
149 149
 std::list<std::string> ResourceManager::listDirectoryFiles(const std::string& directoryPath)
150 150
 {
151 151
     std::list<std::string> files;
152
-    auto rc = PHYSFS_enumerateFiles(resolvePath(directoryPath).c_str());
152
+    auto rc = PHYSFS_enumerateFiles(checkPath(directoryPath).c_str());
153 153
 
154 154
     for(int i = 0; rc[i] != NULL; i++)
155 155
         files.push_back(rc[i]);
@@ -158,8 +158,9 @@ std::list<std::string> ResourceManager::listDirectoryFiles(const std::string& di
158 158
     return files;
159 159
 }
160 160
 
161
-std::string ResourceManager::resolvePath(const std::string& path)
161
+std::string ResourceManager::checkPath(const std::string& path)
162 162
 {
163
+    /*
163 164
     std::string fullPath;
164 165
     if(boost::starts_with(path, "/"))
165 166
         fullPath = path;
@@ -169,7 +170,10 @@ std::string ResourceManager::resolvePath(const std::string& path)
169 170
             fullPath += scriptPath + "/";
170 171
         fullPath += path;
171 172
     }
172
-    return fullPath;
173
+    */
174
+    if(!(boost::starts_with(path, "/")))
175
+        logTraceWarning("the following file path is not fully resolved: ", path);
176
+    return path;
173 177
 }
174 178
 
175 179
 std::string ResourceManager::getBaseDir()

+ 1
- 1
src/framework/core/resourcemanager.h View File

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

+ 5
- 5
src/framework/global.h View File

@@ -32,11 +32,11 @@
32 32
 // additional utilities
33 33
 #include "util/types.h"
34 34
 #include "util/tools.h"
35
-#include "util/point.h"
36
-#include "util/color.h"
37
-#include "util/rect.h"
38
-#include "util/size.h"
39
-#include "util/matrix.h"
35
+#include "math/point.h"
36
+#include "math/color.h"
37
+#include "math/rect.h"
38
+#include "math/size.h"
39
+#include "math/matrix.h"
40 40
 
41 41
 // logger
42 42
 #include "core/logger.h"

+ 3
- 2
src/framework/graphics/font.cpp View File

@@ -28,7 +28,8 @@
28 28
 
29 29
 void Font::load(const OTMLNodePtr& fontNode)
30 30
 {
31
-    std::string textureName = fontNode->valueAt("texture");
31
+    OTMLNodePtr textureNode = fontNode->at("texture");
32
+    std::string textureFile = Fw::resolvePath(textureNode->value(), textureNode->source());
32 33
     Size glyphSize = fontNode->valueAt<Size>("glyph-size");
33 34
     m_glyphHeight = fontNode->valueAt<int>("height");
34 35
     m_yOffset = fontNode->valueAt("y-offset", 0);
@@ -36,7 +37,7 @@ void Font::load(const OTMLNodePtr& fontNode)
36 37
     m_glyphSpacing = fontNode->valueAt("spacing", Size(0,0));
37 38
 
38 39
     // load font texture
39
-    m_texture = g_textures.getTexture(textureName);
40
+    m_texture = g_textures.getTexture(textureFile);
40 41
 
41 42
     if(OTMLNodePtr node = fontNode->get("fixed-glyph-width")) {
42 43
         for(int glyph = m_firstGlyph; glyph < 256; ++glyph)

+ 0
- 1
src/framework/graphics/particleaffector.h View File

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

+ 0
- 1
src/framework/graphics/particleemitter.h View File

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

+ 0
- 1
src/framework/graphics/particlesystem.h View File

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

+ 2
- 12
src/framework/luafunctions.cpp View File

@@ -37,9 +37,6 @@ void Application::registerLuaFunctions()
37 37
     g_lua.registerClass<UIWidget>();
38 38
     g_lua.bindClassStaticFunction<UIWidget>("create", &UIWidget::create<UIWidget>);
39 39
     g_lua.bindClassMemberFunction<UIWidget>("destroy", &UIWidget::destroy);
40
-    g_lua.bindClassMemberFunction<UIWidget>("render", &UIWidget::render);
41
-    g_lua.bindClassMemberFunction<UIWidget>("renderSelf", &UIWidget::renderSelf);
42
-    g_lua.bindClassMemberFunction<UIWidget>("renderChildren", &UIWidget::renderChildren);
43 40
     g_lua.bindClassMemberFunction<UIWidget>("setVisible", &UIWidget::setVisible);
44 41
     g_lua.bindClassMemberFunction<UIWidget>("setEnabled", &UIWidget::setEnabled);
45 42
     g_lua.bindClassMemberFunction<UIWidget>("setPressed", &UIWidget::setPressed);
@@ -237,6 +234,7 @@ void Application::registerLuaFunctions()
237 234
     g_lua.bindClassStaticFunction("g_window", "hide", std::bind(&PlatformWindow::hide, &g_window));
238 235
     g_lua.bindClassStaticFunction("g_window", "move", std::bind(&PlatformWindow::move, &g_window, _1));
239 236
     g_lua.bindClassStaticFunction("g_window", "resize", std::bind(&PlatformWindow::resize, &g_window, _1));
237
+    g_lua.bindClassStaticFunction("g_window", "setMinimumSize", std::bind(&PlatformWindow::setMinimumSize, &g_window, _1));
240 238
     g_lua.bindClassStaticFunction("g_window", "setVerticalSync", std::bind(&PlatformWindow::setVerticalSync, &g_window, _1));
241 239
     g_lua.bindClassStaticFunction("g_window", "setFullscreen", std::bind(&PlatformWindow::setFullscreen, &g_window, _1));
242 240
     g_lua.bindClassStaticFunction("g_window", "setTitle", std::bind(&PlatformWindow::setTitle, &g_window, _1));
@@ -260,22 +258,14 @@ void Application::registerLuaFunctions()
260 258
     g_lua.bindClassStaticFunction("g_ui", "loadUI", std::bind(&UIManager::loadUI, &g_ui, _1, _2));
261 259
     g_lua.bindClassStaticFunction("g_ui", "getRootWidget", std::bind(&UIManager::getRootWidget, &g_ui));
262 260
 
263
-    /*
264 261
     // FontManager
265 262
     g_lua.registerStaticClass("g_fonts");
266
-    g_lua.bindClassStaticFunction("g_fonts", "releaseFonts", std::bind(&FontManager::releaseFonts, &g_fonts));
267 263
     g_lua.bindClassStaticFunction("g_fonts", "importFont", std::bind(&FontManager::importFont, &g_fonts, _1));
268 264
     g_lua.bindClassStaticFunction("g_fonts", "fontExists", std::bind(&FontManager::fontExists, &g_fonts, _1));
269
-    g_lua.bindClassStaticFunction("g_fonts", "getFont", std::bind(&FontManager::getFont, &g_fonts, _1));
270
-    g_lua.bindClassStaticFunction("g_fonts", "getDefaultFont", std::bind(&FontManager::getDefaultFont, &g_fonts));
271 265
     g_lua.bindClassStaticFunction("g_fonts", "setDefaultFont", std::bind(&FontManager::setDefaultFont, &g_fonts, _1));
272
-    */
273 266
 
267
+    // EventDispatcher
274 268
     g_lua.registerStaticClass("g_dispatcher");
275 269
     g_lua.bindClassStaticFunction("g_dispatcher", "addEvent", std::bind(&EventDispatcher::addEvent, &g_dispatcher, _1, _2));
276 270
     g_lua.bindClassStaticFunction("g_dispatcher", "scheduleEvent", std::bind(&EventDispatcher::scheduleEvent, &g_dispatcher, _1, _2));
277
-
278
-    // global functions
279
-    g_lua.bindGlobalFunction("importFont", std::bind(&FontManager::importFont, &g_fonts, _1));
280
-    g_lua.bindGlobalFunction("setDefaultFont", std::bind(&FontManager::setDefaultFont, &g_fonts, _1));
281 271
 }

+ 8
- 3
src/framework/luascript/luainterface.cpp View File

@@ -290,9 +290,14 @@ void LuaInterface::runBuffer(const std::string& buffer, const std::string& sourc
290 290
 
291 291
 void LuaInterface::loadScript(const std::string& fileName)
292 292
 {
293
-    std::string buffer = g_resources.loadFile(fileName);
294
-    std::string source = "@" + g_resources.resolvePath(fileName);
295
-    loadBuffer(g_resources.loadFile(fileName), "@" + g_resources.resolvePath(fileName));
293
+    // resolve file full path
294
+    std::string filePath = fileName;
295
+    if(!boost::starts_with(fileName, "/"))
296
+        filePath = getCurrentSourcePath() + "/" + filePath;
297
+
298
+    std::string buffer = g_resources.loadFile(filePath);
299
+    std::string source = "@" + filePath;
300
+    loadBuffer(buffer, source);
296 301
 }
297 302
 
298 303
 void LuaInterface::loadFunction(const std::string& buffer, const std::string& source)

src/framework/util/color.h → src/framework/math/color.h View File

@@ -23,8 +23,8 @@
23 23
 #ifndef COLOR_H
24 24
 #define COLOR_H
25 25
 
26
-#include "types.h"
27
-#include "tools.h"
26
+#include "../util/types.h"
27
+#include "../util/tools.h"
28 28
 #include "../const.h"
29 29
 
30 30
 class Color

src/framework/util/matrix.h → src/framework/math/matrix.h View File


src/framework/util/point.h → src/framework/math/point.h View File

@@ -23,7 +23,7 @@
23 23
 #ifndef POINT_H
24 24
 #define POINT_H
25 25
 
26
-#include "types.h"
26
+#include "../util/types.h"
27 27
 #include <sstream>
28 28
 #include <cmath>
29 29
 

src/framework/util/rect.h → src/framework/math/rect.h View File

@@ -23,7 +23,7 @@
23 23
 #ifndef RECT_H
24 24
 #define RECT_H
25 25
 
26
-#include "types.h"
26
+#include "../util/types.h"
27 27
 #include <sstream>
28 28
 
29 29
 template<class T>

src/framework/util/size.h → src/framework/math/size.h View File


+ 1
- 1
src/framework/otml/otmldocument.cpp View File

@@ -37,7 +37,7 @@ OTMLDocumentPtr OTMLDocument::parse(const std::string& fileName)
37 37
 {
38 38
     std::stringstream fin;
39 39
     g_resources.loadFile(fileName, fin);
40
-    return parse(fin, g_resources.resolvePath(fileName));
40
+    return parse(fin, fileName);
41 41
 }
42 42
 
43 43
 OTMLDocumentPtr OTMLDocument::parse(std::istream& in, const std::string& source)

+ 2
- 0
src/framework/ui/uimanager.cpp View File

@@ -57,6 +57,7 @@ void UIManager::resize(const Size& size)
57 57
 
58 58
 void UIManager::inputEvent(const InputEvent& event)
59 59
 {
60
+    m_isOnInputEvent = true;
60 61
     switch(event.type) {
61 62
         case Fw::KeyPressInputEvent:
62 63
             m_keyboardReceiver->onKeyPress(event.keyCode, event.keyText, event.keyboardModifiers);
@@ -78,6 +79,7 @@ void UIManager::inputEvent(const InputEvent& event)
78 79
             m_mouseReceiver->onMouseWheel(event.mousePos, event.wheelDirection);
79 80
             break;
80 81
     };
82
+    m_isOnInputEvent = false;
81 83
 }
82 84
 
83 85
 bool UIManager::importStyle(const std::string& file)

+ 3
- 0
src/framework/ui/uimanager.h View File

@@ -54,10 +54,13 @@ public:
54 54
 
55 55
     UIWidgetPtr getRootWidget() { return m_rootWidget; }
56 56
 
57
+    bool isOnInputEvent() { return m_isOnInputEvent; }
58
+
57 59
 private:
58 60
     UIWidgetPtr m_rootWidget;
59 61
     UIWidgetPtr m_mouseReceiver;
60 62
     UIWidgetPtr m_keyboardReceiver;
63
+    bool m_isOnInputEvent;
61 64
     std::map<std::string, OTMLNodePtr> m_styles;
62 65
 };
63 66
 

+ 3
- 2
src/framework/ui/uiwidget.h View File

@@ -40,11 +40,13 @@ public:
40 40
 
41 41
     void destroy();
42 42
 
43
+protected:
43 44
     virtual void render();
44 45
     virtual void renderSelf();
45 46
     virtual void renderChildren();
46 47
 
47
-protected:
48
+    friend class UIManager;
49
+
48 50
     void drawBackground(const Rect& screenCoords);
49 51
     void drawBorder(const Rect& screenCoords);
50 52
     void drawImage(const Rect& screenCoords);
@@ -206,7 +208,6 @@ protected:
206 208
     virtual void onMouseRelease(const Point& mousePos, Fw::MouseButton button);
207 209
     virtual bool onMouseMove(const Point& mousePos, const Point& mouseMoved);
208 210
     virtual bool onMouseWheel(const Point& mousePos, Fw::MouseWheelDirection direction);
209
-    friend class UIManager;
210 211
 
211 212
 protected:
212 213
     std::string m_id;

+ 15
- 3
src/framework/util/tools.h View File

@@ -76,6 +76,11 @@ std::string mkstr(const T&... args) {
76 76
     return buf.str();
77 77
 }
78 78
 
79
+template<typename... T>
80
+void throwException(const T&... args) {
81
+    throw Exception(Fw::mkstr(args...));
82
+}
83
+
79 84
 // used by dumper
80 85
 struct dump_util {
81 86
     ~dump_util() { std::cout << std::endl; }
@@ -270,9 +275,16 @@ std::vector<T> split(const std::string& str, const std::string& separators = " "
270 275
     return results;
271 276
 }
272 277
 
273
-template<typename... T>
274
-void throwException(const T&... args) {
275
-    throw Exception(Fw::mkstr(args...));
278
+inline std::string resolvePath(const std::string& file, std::string sourcePath) {
279
+    if(boost::starts_with(file, "/"))
280
+        return file;
281
+    if(!boost::ends_with(sourcePath, "/")) {
282
+        std::size_t slashPos = sourcePath.find_last_of("/");
283
+        if(slashPos == std::string::npos)
284
+            throwException("invalid source path '", sourcePath, "' for file '", file, "'");
285
+        sourcePath = sourcePath.substr(0, slashPos + 1);
286
+    }
287
+    return sourcePath + file;
276 288
 }
277 289
 
278 290
 template<typename T>

+ 1
- 1
src/otclient/const.h View File

@@ -23,7 +23,7 @@
23 23
 #ifndef OTCLIENT_CONST_H
24 24
 #define OTCLIENT_CONST_H
25 25
 
26
-#include <framework/util/color.h>
26
+#include <framework/math/color.h>
27 27
 
28 28
 namespace Otc
29 29
 {

+ 1
- 1
src/otclient/core/outfit.h View File

@@ -23,7 +23,7 @@
23 23
 #ifndef OUTFIT_H
24 24
 #define OUTFIT_H
25 25
 
26
-#include <framework/util/color.h>
26
+#include <framework/math/color.h>
27 27
 
28 28
 class Outfit
29 29
 {

+ 1
- 0
src/otclient/core/spritemanager.cpp View File

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

+ 2
- 0
src/otclient/core/spritemanager.h View File

@@ -38,10 +38,12 @@ public:
38 38
     int getSpritesCount() { return m_spritesCount; }
39 39
 
40 40
     TexturePtr getSpriteTexture(int id);
41
+    bool isLoaded() { return m_loaded; }
41 42
 
42 43
 private:
43 44
     TexturePtr loadSpriteTexture(int id);
44 45
 
46
+    Boolean<false> m_loaded;
45 47
     uint32 m_signature;
46 48
     uint16 m_spritesCount;
47 49
     std::stringstream m_fin;

+ 1
- 0
src/otclient/core/thingstype.cpp View File

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

+ 2
- 1
src/otclient/core/thingstype.h View File

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

+ 8
- 2
src/otclient/luafunctions.cpp View File

@@ -22,9 +22,15 @@ void OTClient::registerLuaFunctions()
22 22
 {
23 23
     Application::registerLuaFunctions();
24 24
 
25
+    g_lua.registerStaticClass("g_thingsType");
26
+    g_lua.bindClassStaticFunction("g_thingsType", "load", std::bind(&ThingsType::load, &g_thingsType, _1));
27
+    g_lua.bindClassStaticFunction("g_thingsType", "isLoaded", std::bind(&ThingsType::isLoaded, &g_thingsType));
28
+
29
+    g_lua.registerStaticClass("g_sprites");
30
+    g_lua.bindClassStaticFunction("g_sprites", "load", std::bind(&SpriteManager::load, &g_sprites, _1));
31
+    g_lua.bindClassStaticFunction("g_sprites", "isLoaded", std::bind(&SpriteManager::isLoaded, &g_sprites));
32
+
25 33
     g_lua.bindGlobalFunction("exit", std::bind(&Application::exit, g_app));
26
-    g_lua.bindGlobalFunction("importDat", std::bind(&ThingsType::load, &g_thingsType, _1));
27
-    g_lua.bindGlobalFunction("importSpr", std::bind(&SpriteManager::load, &g_sprites, _1));
28 34
     g_lua.bindGlobalFunction("getOufitColor", Outfit::getColor);
29 35
 
30 36
     g_lua.registerClass<ProtocolLogin, Protocol>();

+ 1
- 1
src/otclient/util/position.h View File

@@ -25,7 +25,7 @@
25 25
 
26 26
 #include <otclient/const.h>
27 27
 #include <framework/util/types.h>
28
-#include <framework/util/point.h>
28
+#include <framework/math/point.h>
29 29
 
30 30
 class Position
31 31
 {

+ 3
- 0
tools/katepart-syntax/lua.xml View File

@@ -128,6 +128,9 @@
128 128
       <item> extends </item>
129 129
       <item> print </item>
130 130
       <item> fatal </item>
131
+      <item> newenv </item>
132
+      <item> getfsrcpath </item>
133
+      <item> resolvepath </item>
131 134
 
132 135
       <item> scheduleEvent </item>
133 136
       <item> addEvent </item>

Loading…
Cancel
Save