diff --git a/.gitmodules b/.gitmodules index 55bc079e..524ca5c2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "modules/tibiafiles"] - path = modules/tibiafiles +[submodule "modules/client_tibiafiles"] + path = modules/client_tibiafiles url = git://github.com/Baxnie/otclient-tibiafiles.git diff --git a/CMakeLists.txt b/CMakeLists.txt index dfa45666..1561590c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ INCLUDE(src/otclient/CMakeLists.txt) OPTION(USE_PCH "Use precompiled header (speed up compile)" ON) -SET(EXECUTABLE_SOURCES src/main.cpp) +SET(executable_SOURCES src/main.cpp) # add executable icon for win32 platforms IF(WIN32) @@ -15,14 +15,14 @@ IF(WIN32) -I${CMAKE_CURRENT_SOURCE_DIR}/src -i${CMAKE_CURRENT_SOURCE_DIR}/src/otcicon.rc -o ${CMAKE_CURRENT_BINARY_DIR}/otcicon.o) - SET(${EXECUTABLE_SOURCES} ${EXECUTABLE_SOURCES} otcicon.o) + SET(executable_SOURCES ${executable_SOURCES} otcicon.o) ENDIF(WIN32) # add otclient executable -ADD_EXECUTABLE(otclient ${FRAMEWORK_SOURCES} ${OTCLIENT_SOURCES} ${EXECUTABLE_SOURCES}) +ADD_EXECUTABLE(otclient ${framework_SOURCES} ${otclient_SOURCES} ${executable_SOURCES}) # target link libraries -TARGET_LINK_LIBRARIES(otclient ${FRAMEWORK_LIBRARIES}) +TARGET_LINK_LIBRARIES(otclient ${framework_LIBRARIES}) IF(USE_PCH) FIND_PACKAGE(PCHSupport REQUIRED) diff --git a/TODO b/TODO index 0398e081..e78600a8 100644 --- a/TODO +++ b/TODO @@ -29,3 +29,4 @@ bind every global lua function in a static class use metatable for Point,Rect,Color,Size lua classes lua binder generator restore win32 platform +set special types for g_configs like lists/point/size \ No newline at end of file diff --git a/modules/console/console.lua b/modules/addon_console/console.lua similarity index 100% rename from modules/console/console.lua rename to modules/addon_console/console.lua diff --git a/modules/console/console.otmod b/modules/addon_console/console.otmod similarity index 82% rename from modules/console/console.otmod rename to modules/addon_console/console.otmod index 5f38397d..bc6972b1 100644 --- a/modules/console/console.otmod +++ b/modules/addon_console/console.otmod @@ -3,7 +3,11 @@ Module description: Console for executing lua functions author: OTClient team website: https://github.com/edubart/otclient + + // console can be loaded after core autoLoad: true + autoLoadPriority: 20 + dependencies: - core diff --git a/modules/console/console.otui b/modules/addon_console/console.otui similarity index 100% rename from modules/console/console.otui rename to modules/addon_console/console.otui diff --git a/modules/addon_playground/playground.lua b/modules/addon_playground/playground.lua new file mode 100644 index 00000000..805983c3 --- /dev/null +++ b/modules/addon_playground/playground.lua @@ -0,0 +1 @@ +-- place any code for testing purposes here \ No newline at end of file diff --git a/modules/playground/playground.otmod b/modules/addon_playground/playground.otmod similarity index 77% rename from modules/playground/playground.otmod rename to modules/addon_playground/playground.otmod index 5e95db40..1ef3d48f 100644 --- a/modules/playground/playground.otmod +++ b/modules/addon_playground/playground.otmod @@ -1,9 +1,6 @@ Module name: playground autoLoad: true - dependencies: - - core - onLoad: | require 'playground' return true diff --git a/modules/otclient/otclient.lua b/modules/client/client.lua similarity index 62% rename from modules/otclient/otclient.lua rename to modules/client/client.lua index ac801b10..99ae68a5 100644 --- a/modules/otclient/otclient.lua +++ b/modules/client/client.lua @@ -1,13 +1,13 @@ -OTClient = { } +Client = { } -- TODO: load and save configurations -function OTClient.init() +function Client.init() g_window.move({ x=220, y=220 }) g_window.resize({ width=800, height=600 }) g_window.setTitle('OTClient') - g_window.setIcon('otcicon.png') + g_window.setIcon('clienticon.png') return true end -function OTClient.terminate() +function Client.terminate() end diff --git a/modules/client/client.otmod b/modules/client/client.otmod new file mode 100644 index 00000000..1c6c7ef0 --- /dev/null +++ b/modules/client/client.otmod @@ -0,0 +1,22 @@ +Module + name: client + description: Load all other otclient dependecies + author: OTClient team + website: https://github.com/edubart/otclient + + // NOTE: order does matter + dependencies: + - client_background + - client_topmenu + - client_tibiafiles + - client_about + - client_options + - client_entergame + - game + + onLoad: | + require 'client' + return Client.init() + + onUnload: | + Client.terminate() diff --git a/modules/otclient/otcicon.png b/modules/client/clienticon.png similarity index 100% rename from modules/otclient/otcicon.png rename to modules/client/clienticon.png diff --git a/modules/about/about.lua b/modules/client_about/about.lua similarity index 61% rename from modules/about/about.lua rename to modules/client_about/about.lua index 8e6032d5..64b92909 100644 --- a/modules/about/about.lua +++ b/modules/client_about/about.lua @@ -1,16 +1,16 @@ About = {} -- private variables -local about +local aboutWindow -- public functions function About.create() - about = UI.display('about.otui', { locked = true }) + aboutWindow = UI.display('about.otui', { locked = true }) end function About.destroy() - about:destroy() - about = nil + aboutWindow:destroy() + aboutWindow = nil end function About.openWebpage() diff --git a/modules/about/about.otmod b/modules/client_about/about.otmod similarity index 80% rename from modules/about/about.otmod rename to modules/client_about/about.otmod index 353895a8..5dd5c9db 100644 --- a/modules/about/about.otmod +++ b/modules/client_about/about.otmod @@ -1,10 +1,8 @@ Module - name: about + name: client_about description: Create the about window author: OTClient team website: https://github.com/edubart/otclient - dependencies: - - core onLoad: | require 'about' diff --git a/modules/about/about.otui b/modules/client_about/about.otui similarity index 100% rename from modules/about/about.otui rename to modules/client_about/about.otui diff --git a/modules/background/background.lua b/modules/client_background/background.lua similarity index 100% rename from modules/background/background.lua rename to modules/client_background/background.lua diff --git a/modules/background/background.otmod b/modules/client_background/background.otmod similarity index 84% rename from modules/background/background.otmod rename to modules/client_background/background.otmod index 750d33a5..4b3dc707 100644 --- a/modules/background/background.otmod +++ b/modules/client_background/background.otmod @@ -1,10 +1,8 @@ Module - name: background + name: client_background description: Handles the background of the login screen author: OTClient team website: https://github.com/edubart/otclient - dependencies: - - core onLoad: | require 'background' diff --git a/modules/background/background.otui b/modules/client_background/background.otui similarity index 83% rename from modules/background/background.otui rename to modules/client_background/background.otui index a2d9dadd..c88b9b87 100644 --- a/modules/background/background.otui +++ b/modules/client_background/background.otui @@ -1,7 +1,7 @@ Panel id: background image: - source: /background/background.png + source: /client_background/background.png smooth: true fixed ratio: true anchors.top: topMenu.bottom diff --git a/modules/background/background.png b/modules/client_background/background.png similarity index 100% rename from modules/background/background.png rename to modules/client_background/background.png diff --git a/modules/entergame/characterlist.lua b/modules/client_entergame/characterlist.lua similarity index 100% rename from modules/entergame/characterlist.lua rename to modules/client_entergame/characterlist.lua diff --git a/modules/entergame/characterlist.otui b/modules/client_entergame/characterlist.otui similarity index 100% rename from modules/entergame/characterlist.otui rename to modules/client_entergame/characterlist.otui diff --git a/modules/entergame/entergame.lua b/modules/client_entergame/entergame.lua similarity index 100% rename from modules/entergame/entergame.lua rename to modules/client_entergame/entergame.lua diff --git a/modules/entergame/entergame.otmod b/modules/client_entergame/entergame.otmod similarity index 91% rename from modules/entergame/entergame.otmod rename to modules/client_entergame/entergame.otmod index 7b9bfa7d..e1241bcf 100644 --- a/modules/entergame/entergame.otmod +++ b/modules/client_entergame/entergame.otmod @@ -1,8 +1,9 @@ Module - name: entergame + name: client_entergame description: Manages enter game and character list windows author: OTClient team website: https://github.com/edubart/otclient + onLoad: | require 'entergame' require 'characterlist' diff --git a/modules/entergame/entergame.otui b/modules/client_entergame/entergame.otui similarity index 100% rename from modules/entergame/entergame.otui rename to modules/client_entergame/entergame.otui diff --git a/modules/options/options.lua b/modules/client_options/options.lua similarity index 100% rename from modules/options/options.lua rename to modules/client_options/options.lua diff --git a/modules/options/options.otmod b/modules/client_options/options.otmod similarity index 87% rename from modules/options/options.otmod rename to modules/client_options/options.otmod index 97d72044..4722e368 100644 --- a/modules/options/options.otmod +++ b/modules/client_options/options.otmod @@ -1,8 +1,9 @@ Module - name: options + name: client_options description: Create the options window author: OTClient team website: https://github.com/edubart/otclient + onLoad: | require 'options' return true diff --git a/modules/options/options.otui b/modules/client_options/options.otui similarity index 100% rename from modules/options/options.otui rename to modules/client_options/options.otui diff --git a/modules/client_tibiafiles b/modules/client_tibiafiles new file mode 160000 index 00000000..e76fa278 --- /dev/null +++ b/modules/client_tibiafiles @@ -0,0 +1 @@ +Subproject commit e76fa2786e2a194375a110b700b7e2daa769f960 diff --git a/modules/topmenu/topmenu.lua b/modules/client_topmenu/topmenu.lua similarity index 98% rename from modules/topmenu/topmenu.lua rename to modules/client_topmenu/topmenu.lua index 28874b2a..fb1662c1 100644 --- a/modules/topmenu/topmenu.lua +++ b/modules/client_topmenu/topmenu.lua @@ -15,4 +15,4 @@ end function TopMenu.getButton(id) return topMenu:getChildById(id) -end \ No newline at end of file +end diff --git a/modules/topmenu/topmenu.otmod b/modules/client_topmenu/topmenu.otmod similarity index 72% rename from modules/topmenu/topmenu.otmod rename to modules/client_topmenu/topmenu.otmod index 84bcca62..4a102ac2 100644 --- a/modules/topmenu/topmenu.otmod +++ b/modules/client_topmenu/topmenu.otmod @@ -1,13 +1,8 @@ Module - name: topmenu + name: client_topmenu description: Create the top menu author: OTClient team website: https://github.com/edubart/otclient - dependencies: - - core - - entergame - - options - - about onLoad: | require 'topmenu' @@ -16,4 +11,3 @@ Module onUnload: | TopMenu.destroy() - diff --git a/modules/topmenu/topmenu.otui b/modules/client_topmenu/topmenu.otui similarity index 100% rename from modules/topmenu/topmenu.otui rename to modules/client_topmenu/topmenu.otui diff --git a/modules/core/core.otmod b/modules/core/core.otmod index b4886d92..88849485 100644 --- a/modules/core/core.otmod +++ b/modules/core/core.otmod @@ -3,19 +3,15 @@ Module description: Contains lua classes, functions and constants used by other modules author: OTClient team website: https://github.com/edubart/otclient + + // core must be loaded before other modules autoLoad: true + autoLoadPriority: 10 + + // NOTE: order does matter dependencies: - core_fonts - core_styles - - onLoad: | - require 'ext/table' - require 'ext/string' - require 'constants' - require 'util' - require 'dispatcher' - require 'widget' - require 'ui' - require 'gfx' - return true + - core_scripts + - core_widgets diff --git a/modules/core_fonts/sans-11px-antialised.png b/modules/core_fonts/sans-11px-antialised.png deleted file mode 100644 index 2178d684..00000000 Binary files a/modules/core_fonts/sans-11px-antialised.png and /dev/null differ diff --git a/modules/core/constants.lua b/modules/core_scripts/constants.lua similarity index 100% rename from modules/core/constants.lua rename to modules/core_scripts/constants.lua diff --git a/modules/core_scripts/core_scripts.otmod b/modules/core_scripts/core_scripts.otmod new file mode 100644 index 00000000..8c52ba30 --- /dev/null +++ b/modules/core_scripts/core_scripts.otmod @@ -0,0 +1,16 @@ +Module + name: core_scripts + description: Contains core lua classes, functions and constants used by other modules + author: OTClient team + website: https://github.com/edubart/otclient + + onLoad: | + require 'ext/table' + require 'ext/string' + require 'constants' + require 'util' + require 'dispatcher' + require 'widget' + require 'ui' + require 'gfx' + return true diff --git a/modules/core/dispatcher.lua b/modules/core_scripts/dispatcher.lua similarity index 100% rename from modules/core/dispatcher.lua rename to modules/core_scripts/dispatcher.lua diff --git a/modules/core/ext/color.lua b/modules/core_scripts/ext/color.lua similarity index 100% rename from modules/core/ext/color.lua rename to modules/core_scripts/ext/color.lua diff --git a/modules/core/ext/point.lua b/modules/core_scripts/ext/point.lua similarity index 100% rename from modules/core/ext/point.lua rename to modules/core_scripts/ext/point.lua diff --git a/modules/core/ext/rect.lua b/modules/core_scripts/ext/rect.lua similarity index 100% rename from modules/core/ext/rect.lua rename to modules/core_scripts/ext/rect.lua diff --git a/modules/core/ext/size.lua b/modules/core_scripts/ext/size.lua similarity index 100% rename from modules/core/ext/size.lua rename to modules/core_scripts/ext/size.lua diff --git a/modules/core/ext/string.lua b/modules/core_scripts/ext/string.lua similarity index 100% rename from modules/core/ext/string.lua rename to modules/core_scripts/ext/string.lua diff --git a/modules/core/ext/table.lua b/modules/core_scripts/ext/table.lua similarity index 100% rename from modules/core/ext/table.lua rename to modules/core_scripts/ext/table.lua diff --git a/modules/core/gfx.lua b/modules/core_scripts/gfx.lua similarity index 100% rename from modules/core/gfx.lua rename to modules/core_scripts/gfx.lua diff --git a/modules/core/ui.lua b/modules/core_scripts/ui.lua similarity index 100% rename from modules/core/ui.lua rename to modules/core_scripts/ui.lua diff --git a/modules/core/util.lua b/modules/core_scripts/util.lua similarity index 84% rename from modules/core/util.lua rename to modules/core_scripts/util.lua index ac26a4ae..9bf33688 100644 --- a/modules/core/util.lua +++ b/modules/core_scripts/util.lua @@ -12,14 +12,18 @@ function createEnvironment() return env end -function connect(object, signalsAndSlots) +function connect(object, signalsAndSlots, pushFront) for signal,slot in pairs(signalsAndSlots) do if not object[signal] then object[signal] = slot elseif type(object[signal]) == 'function' then object[signal] = { object[signal], slot } elseif type(object[signal]) == 'table' then - table.insert(object[signal], #object[signal]+1, slot) + if pushFront then + table.insert(object[signal], 1, slot) + else + table.insert(object[signal], #object[signal]+1, slot) + end end end end diff --git a/modules/core/widget.lua b/modules/core_scripts/widget.lua similarity index 100% rename from modules/core/widget.lua rename to modules/core_scripts/widget.lua diff --git a/modules/core_styles/core_styles.otmod b/modules/core_styles/core_styles.otmod index 93ce19d8..cdf885e1 100644 --- a/modules/core_styles/core_styles.otmod +++ b/modules/core_styles/core_styles.otmod @@ -3,8 +3,7 @@ Module description: Contains ui styles used by other modules author: OTClient team website: https://github.com/edubart/otclient - dependencies: - - core_fonts + onLoad: | importStyles 'styles/buttons.otui' importStyles 'styles/labels.otui' @@ -17,4 +16,3 @@ Module importStyles 'styles/items.otui' importStyles 'styles/creatures.otui' return true - diff --git a/modules/core_widgets/core_widgets.otmod b/modules/core_widgets/core_widgets.otmod new file mode 100644 index 00000000..6b228a62 --- /dev/null +++ b/modules/core_widgets/core_widgets.otmod @@ -0,0 +1,10 @@ +Module + name: core_widgets + description: Contains widgets used by other modules + author: OTClient team + website: https://github.com/edubart/otclient + + onLoad: | + require 'tooltip/tooltip' + require 'messagebox/messagebox' + return true \ No newline at end of file diff --git a/modules/messagebox/messagebox.lua b/modules/core_widgets/messagebox/messagebox.lua similarity index 100% rename from modules/messagebox/messagebox.lua rename to modules/core_widgets/messagebox/messagebox.lua diff --git a/modules/messagebox/messagebox.otui b/modules/core_widgets/messagebox/messagebox.otui similarity index 100% rename from modules/messagebox/messagebox.otui rename to modules/core_widgets/messagebox/messagebox.otui diff --git a/modules/tooltip/tooltip.lua b/modules/core_widgets/tooltip/tooltip.lua similarity index 100% rename from modules/tooltip/tooltip.lua rename to modules/core_widgets/tooltip/tooltip.lua diff --git a/modules/tooltip/tooltip.otui b/modules/core_widgets/tooltip/tooltip.otui similarity index 100% rename from modules/tooltip/tooltip.otui rename to modules/core_widgets/tooltip/tooltip.otui diff --git a/modules/game/game.lua b/modules/game/game.lua index b389bb1b..81b8d6ab 100644 --- a/modules/game/game.lua +++ b/modules/game/game.lua @@ -16,7 +16,7 @@ end function Game.createInterface() Background.hide() CharacterList.destroyLoadBox() - Game.gameUi = UI.display('/game/game.otui') + Game.gameUi = UI.display('game.otui') UI.root:moveChildToIndex(Game.gameUi, 1) Game.gameMapPanel = Game.gameUi:getChildById('mapPanel') Game.gameRightPanel = Game.gameUi:getChildById('rightPanel') @@ -56,5 +56,5 @@ function Game.onConnectionError(message) errorBox.onOk = CharacterList.show end -connect(Game, { onLogin = Game.createInterface, - onLogout = Game.destroyInterface }) +connect(Game, { onLogin = Game.createInterface }, true) +connect(Game, { onLogout = Game.destroyInterface }) diff --git a/modules/game/game.otmod b/modules/game/game.otmod index 4f941688..240e67da 100644 --- a/modules/game/game.otmod +++ b/modules/game/game.otmod @@ -3,6 +3,16 @@ Module description: Create the game interface, where the ingame stuff starts author: OTClient team website: https://github.com/edubart/otclient + + dependencies: + - game_healthbar + - game_inventory + - game_skills + - game_textmessage + - game_viplist + - game_chat + - game_outfit + onLoad: | require 'game' - return true + return true \ No newline at end of file diff --git a/modules/chat/chat.lua b/modules/game_chat/chat.lua similarity index 100% rename from modules/chat/chat.lua rename to modules/game_chat/chat.lua diff --git a/modules/chat/chat.otmod b/modules/game_chat/chat.otmod similarity index 89% rename from modules/chat/chat.otmod rename to modules/game_chat/chat.otmod index 6ce771d6..549c8d32 100644 --- a/modules/chat/chat.otmod +++ b/modules/game_chat/chat.otmod @@ -1,5 +1,5 @@ Module - name: chat + name: game_chat description: Manage chat window author: OTClient team website: https://github.com/edubart/otclient diff --git a/modules/chat/chat.otui b/modules/game_chat/chat.otui similarity index 100% rename from modules/chat/chat.otui rename to modules/game_chat/chat.otui diff --git a/modules/health_mana/health_mana.lua b/modules/game_healthbar/healthbar.lua similarity index 85% rename from modules/health_mana/health_mana.lua rename to modules/game_healthbar/healthbar.lua index e8fe8f1a..237296b4 100644 --- a/modules/health_mana/health_mana.lua +++ b/modules/game_healthbar/healthbar.lua @@ -1,11 +1,11 @@ -HealthMana = {} +HealthBar = {} -- private variables local healthManaPanel = nil -- public functions -function HealthMana.create() - healthManaPanel = UI.display('health_mana.otui', { parent = Game.gameRightPanel }) +function HealthBar.create() + healthManaPanel = UI.display('healthbar.otui', { parent = Game.gameRightPanel }) local healthBar = UIProgressBar.create() healthManaPanel:addChild(healthBar) @@ -32,7 +32,7 @@ function HealthMana.create() healthManaPanel:setHeight(healthBar:getHeight() + manaBar:getHeight() + 4) end -function HealthMana.destroy() +function HealthBar.destroy() healthManaPanel:destroy() healthManaPanel = nil end @@ -61,5 +61,5 @@ function Game.onManaChange(mana, maxMana) manaBar:setPercent(percent) end -connect(Game, { onLogin = HealthMana.create, - onLogout = HealthMana.destroy }) +connect(Game, { onLogin = HealthBar.create, + onLogout = HealthBar.destroy }) diff --git a/modules/health_mana/health_mana.otmod b/modules/game_healthbar/healthbar.otmod similarity index 76% rename from modules/health_mana/health_mana.otmod rename to modules/game_healthbar/healthbar.otmod index c62bf9b3..4dee07e3 100644 --- a/modules/health_mana/health_mana.otmod +++ b/modules/game_healthbar/healthbar.otmod @@ -1,10 +1,10 @@ Module - name: health_mana + name: game_healthbar description: Displays health and mana points author: OTClient team website: https://github.com/edubart/otclient onLoad: | - require 'health_mana' + require 'healthbar' return true diff --git a/modules/health_mana/health_mana.otui b/modules/game_healthbar/healthbar.otui similarity index 100% rename from modules/health_mana/health_mana.otui rename to modules/game_healthbar/healthbar.otui diff --git a/modules/inventory/inventory.lua b/modules/game_inventory/inventory.lua similarity index 100% rename from modules/inventory/inventory.lua rename to modules/game_inventory/inventory.lua diff --git a/modules/inventory/inventory.otmod b/modules/game_inventory/inventory.otmod similarity index 88% rename from modules/inventory/inventory.otmod rename to modules/game_inventory/inventory.otmod index 1ce10ed3..2d44fa1d 100644 --- a/modules/inventory/inventory.otmod +++ b/modules/game_inventory/inventory.otmod @@ -1,5 +1,5 @@ Module - name: inventory + name: game_inventory description: View local player equipments window author: OTClient team website: https://github.com/edubart/otclient diff --git a/modules/inventory/inventory.otui b/modules/game_inventory/inventory.otui similarity index 100% rename from modules/inventory/inventory.otui rename to modules/game_inventory/inventory.otui diff --git a/modules/inventory/itempopupmenu.otui b/modules/game_inventory/itempopupmenu.otui similarity index 100% rename from modules/inventory/itempopupmenu.otui rename to modules/game_inventory/itempopupmenu.otui diff --git a/modules/outfit/outfit.lua b/modules/game_outfit/outfit.lua similarity index 100% rename from modules/outfit/outfit.lua rename to modules/game_outfit/outfit.lua diff --git a/modules/outfit/outfit.otmod b/modules/game_outfit/outfit.otmod similarity index 89% rename from modules/outfit/outfit.otmod rename to modules/game_outfit/outfit.otmod index e43042e5..e31feea7 100644 --- a/modules/outfit/outfit.otmod +++ b/modules/game_outfit/outfit.otmod @@ -1,5 +1,5 @@ Module - name: outfit + name: game_outfit description: Change local player outfit author: OTClient team website: https://github.com/edubart/otclient diff --git a/modules/outfit/outfit.otui b/modules/game_outfit/outfit.otui similarity index 100% rename from modules/outfit/outfit.otui rename to modules/game_outfit/outfit.otui diff --git a/modules/skills/skills.lua b/modules/game_skills/skills.lua similarity index 100% rename from modules/skills/skills.lua rename to modules/game_skills/skills.lua diff --git a/modules/skills/skills.otmod b/modules/game_skills/skills.otmod similarity index 89% rename from modules/skills/skills.otmod rename to modules/game_skills/skills.otmod index b895f8a2..1b6f7c99 100644 --- a/modules/skills/skills.otmod +++ b/modules/game_skills/skills.otmod @@ -1,5 +1,5 @@ Module - name: skills + name: game_skills description: Manage skills window author: OTClient team website: https://github.com/edubart/otclient diff --git a/modules/skills/skills.otui b/modules/game_skills/skills.otui similarity index 100% rename from modules/skills/skills.otui rename to modules/game_skills/skills.otui diff --git a/modules/textmessage/textmessage.lua b/modules/game_textmessage/textmessage.lua similarity index 96% rename from modules/textmessage/textmessage.lua rename to modules/game_textmessage/textmessage.lua index 748e7b3b..81a46d9c 100644 --- a/modules/textmessage/textmessage.lua +++ b/modules/game_textmessage/textmessage.lua @@ -1,7 +1,7 @@ TextMessage = {} -- require styles -importStyles '/textmessage/textmessage.otui' +importStyles 'textmessage.otui' -- private variables local bottomLabelWidget, centerLabelWidget diff --git a/modules/textmessage/textmessage.otmod b/modules/game_textmessage/textmessage.otmod similarity index 87% rename from modules/textmessage/textmessage.otmod rename to modules/game_textmessage/textmessage.otmod index 534a2fe0..cdb15547 100644 --- a/modules/textmessage/textmessage.otmod +++ b/modules/game_textmessage/textmessage.otmod @@ -1,5 +1,5 @@ Module - name: textmessage + name: game_textmessage description: Manage game text messages author: OTClient team website: https://github.com/edubart/otclient diff --git a/modules/textmessage/textmessage.otui b/modules/game_textmessage/textmessage.otui similarity index 100% rename from modules/textmessage/textmessage.otui rename to modules/game_textmessage/textmessage.otui diff --git a/modules/viplist/viplist.lua b/modules/game_viplist/viplist.lua similarity index 100% rename from modules/viplist/viplist.lua rename to modules/game_viplist/viplist.lua diff --git a/modules/viplist/viplist.otmod b/modules/game_viplist/viplist.otmod similarity index 88% rename from modules/viplist/viplist.otmod rename to modules/game_viplist/viplist.otmod index 40b14260..8ff16013 100644 --- a/modules/viplist/viplist.otmod +++ b/modules/game_viplist/viplist.otmod @@ -1,5 +1,5 @@ Module - name: viplist + name: game_viplist description: Manage vip list window author: OTClient team website: https://github.com/edubart/otclient diff --git a/modules/viplist/viplist.otui b/modules/game_viplist/viplist.otui similarity index 100% rename from modules/viplist/viplist.otui rename to modules/game_viplist/viplist.otui diff --git a/modules/messagebox/messagebox.otmod b/modules/messagebox/messagebox.otmod deleted file mode 100644 index 23da5c55..00000000 --- a/modules/messagebox/messagebox.otmod +++ /dev/null @@ -1,12 +0,0 @@ -Module - name: messagebox - description: Manages message boxes - author: OTClient team - website: https://github.com/edubart/otclient - autoLoad: true - dependencies: - - core - - onLoad: | - require 'messagebox' - return true diff --git a/modules/otclient/otclient.otmod b/modules/otclient/otclient.otmod deleted file mode 100644 index c041c1c5..00000000 --- a/modules/otclient/otclient.otmod +++ /dev/null @@ -1,27 +0,0 @@ -Module - name: otclient - description: Load all other otclient modules - author: OTClient team - website: https://github.com/edubart/otclient - autoLoad: true - autoLoadPriority: 10 - dependencies: - - core - - background - - topmenu - - game - - health_mana - - inventory - - skills - - viplist - - textmessage - - chat - - outfit - - tibiafiles - - onLoad: | - require 'otclient' - return OTClient.init() - - onUnload: | - OTClient.terminate() diff --git a/modules/playground/playground.lua b/modules/playground/playground.lua deleted file mode 100644 index 2f3d65e1..00000000 --- a/modules/playground/playground.lua +++ /dev/null @@ -1,24 +0,0 @@ --- place any code for testing purposes here - -function UIItem.onMouseRelease(self, mousePos, mouseButton) - if mouseButton ~= MouseRightButton then return end - local top = self:getY() - local bottom = self:getY() + self:getHeight() - local left = self:getX() - local right = self:getX() + self:getWidth() - if not (mousePos.y >= top and mousePos.y <= bottom and mousePos.x >= left and mousePos.x <= right) then return end - - local menuFile = self:getStyle()['popup menu'] - if not menuFile then return end - - local popupMenu = UI.display(menuFile) - if not popupMenu then return end - - popupMenu:moveTo(mousePos) - popupMenu.onMouseRelease = function(self) self:destroy() end -end - -local function init() -end - -addEvent(init) \ No newline at end of file diff --git a/modules/tibiafiles b/modules/tibiafiles deleted file mode 160000 index 8bb3b7d6..00000000 --- a/modules/tibiafiles +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8bb3b7d6d86e561be4622fbe7dbef208446a0319 diff --git a/modules/tooltip/tooltip.otmod b/modules/tooltip/tooltip.otmod deleted file mode 100644 index 6c3b3efa..00000000 --- a/modules/tooltip/tooltip.otmod +++ /dev/null @@ -1,13 +0,0 @@ -Module - name: tooltip - description: Enable tooltips on any button - author: OTClient team - website: https://github.com/edubart/otclient - autoLoad: true - autoLoadPriority: 2 - dependencies: - - core - - onLoad: | - require 'tooltip' - return true diff --git a/src/framework/CMakeLists.txt b/src/framework/CMakeLists.txt index ebcecc15..659fc10a 100644 --- a/src/framework/CMakeLists.txt +++ b/src/framework/CMakeLists.txt @@ -62,7 +62,7 @@ ENDIF(HANDLE_EXCEPTIONS) IF(WIN32) - SET(FRAMEWORK_SOURCES ${FRAMEWORK_SOURCES} ${CMAKE_CURRENT_LIST_DIR}/platform/win32window.cpp) + SET(framework_SOURCES ${framework_SOURCES} ${CMAKE_CURRENT_LIST_DIR}/platform/win32window.cpp) SET(ADDITIONAL_LIBRARIES ws2_32 mswsock) IF(CMAKE_COMPILER_IS_GNUCXX) @@ -80,7 +80,7 @@ IF(WIN32) ELSE(WIN32) SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -rdynamic") SET(ADDITIONAL_LIBRARIES pthread) - SET(FRAMEWORK_SOURCES ${FRAMEWORK_SOURCES} ${CMAKE_CURRENT_LIST_DIR}/platform/x11window.cpp) + SET(framework_SOURCES ${framework_SOURCES} ${CMAKE_CURRENT_LIST_DIR}/platform/x11window.cpp) ENDIF(WIN32) @@ -94,7 +94,7 @@ INCLUDE_DIRECTORIES( "${CMAKE_CURRENT_LIST_DIR}/.." ) -SET(FRAMEWORK_LIBRARIES +SET(framework_LIBRARIES ${Boost_LIBRARIES} ${OPENGL_LIBRARIES} ${LUA_LIBRARIES} @@ -105,7 +105,7 @@ SET(FRAMEWORK_LIBRARIES ) -SET(FRAMEWORK_SOURCES ${FRAMEWORK_SOURCES} +SET(framework_SOURCES ${framework_SOURCES} # framework ${CMAKE_CURRENT_LIST_DIR}/application.cpp ${CMAKE_CURRENT_LIST_DIR}/luafunctions.cpp diff --git a/src/framework/application.cpp b/src/framework/application.cpp index ad2fde85..25542cc3 100644 --- a/src/framework/application.cpp +++ b/src/framework/application.cpp @@ -103,33 +103,12 @@ void Application::init(const std::vector& args, int appFlags) resize(g_window.getSize()); } - if(m_appFlags & Fw::AppEnableModules) { - // search for modules directory - std::string baseDir = g_resources.getBaseDir(); - std::string possibleDirs[] = { "modules", - baseDir + "modules", - baseDir + "../modules", - baseDir + "../share/" + m_appName + "/modules", - "" }; - bool found = false; - for(const std::string& dir : possibleDirs) { - // try to add module directory - if(g_resources.addToSearchPath(dir)) { - logInfo("Using modules directory '", dir.c_str(), "'"); - found = true; - break; - } - } - - if(!found) - logFatal("Could not find modules directory"); - - g_modules.discoverAndLoadModules(); - } - // finally show the window if(m_appFlags & Fw::AppEnableGraphics) g_window.show(); + + if(m_appFlags & Fw::AppEnableModules) + g_modules.discoverModulesPath(); } diff --git a/src/framework/application.h b/src/framework/application.h index b456765f..b09f2942 100644 --- a/src/framework/application.h +++ b/src/framework/application.h @@ -54,7 +54,6 @@ protected: virtual void resize(const Size& size); virtual void inputEvent(const InputEvent& event); -private: std::string m_appName; int m_appFlags; int m_pollCycleDelay; diff --git a/src/framework/core/modulemanager.cpp b/src/framework/core/modulemanager.cpp index d74ebb19..817016be 100644 --- a/src/framework/core/modulemanager.cpp +++ b/src/framework/core/modulemanager.cpp @@ -24,13 +24,12 @@ #include "resourcemanager.h" #include +#include ModuleManager g_modules; -void ModuleManager::discoverAndLoadModules() +void ModuleManager::discoverModules() { - std::multimap m_autoLoadModules; - auto moduleDirs = g_resources.listDirectoryFiles("/"); for(const std::string& moduleDir : moduleDirs) { auto moduleFiles = g_resources.listDirectoryFiles("/" + moduleDir); @@ -42,14 +41,42 @@ void ModuleManager::discoverAndLoadModules() } } } +} +void ModuleManager::autoLoadModules(int maxPriority) +{ for(auto& pair : m_autoLoadModules) { + int priority = pair.first; + if(priority > maxPriority) + break; ModulePtr module = pair.second; if(!module->isLoaded() && !module->load()) logFatal("A required module has failed to load, cannot continue to run."); } } +void ModuleManager::discoverModulesPath() +{ + // search for modules directory + std::string possibleDirs[] = { "modules", + g_resources.getBaseDir() + "modules", + g_resources.getBaseDir() + "../modules", + g_resources.getBaseDir() + "../share/" + g_app->getAppName() + "/modules", + "" }; + bool found = false; + for(const std::string& dir : possibleDirs) { + // try to add module directory + if(g_resources.addToSearchPath(dir)) { + logInfo("Using modules directory '", dir.c_str(), "'"); + found = true; + break; + } + } + + if(!found) + logFatal("Could not find modules directory"); +} + ModulePtr ModuleManager::discoverModule(const std::string& moduleFile) { ModulePtr module; @@ -70,6 +97,13 @@ ModulePtr ModuleManager::discoverModule(const std::string& moduleFile) return module; } +void ModuleManager::ensureModuleLoaded(const std::string& moduleName) +{ + ModulePtr module = g_modules.getModule(moduleName); + if(!module || !module->load()) + logFatal("Unable to load '", moduleName, "' module"); +} + void ModuleManager::unloadModules() { for(const ModulePtr& module : m_modules) diff --git a/src/framework/core/modulemanager.h b/src/framework/core/modulemanager.h index 9ce06bcd..3d49106d 100644 --- a/src/framework/core/modulemanager.h +++ b/src/framework/core/modulemanager.h @@ -28,14 +28,18 @@ class ModuleManager { public: - void discoverAndLoadModules(); + void discoverModulesPath(); + void discoverModules(); + void autoLoadModules(int maxPriority); ModulePtr discoverModule(const std::string& moduleFile); + void ensureModuleLoaded(const std::string& moduleName); void unloadModules(); ModulePtr getModule(const std::string& moduleName); private: std::vector m_modules; + std::multimap m_autoLoadModules; }; extern ModuleManager g_modules; diff --git a/src/framework/graphics/font.cpp b/src/framework/graphics/font.cpp index 20d2fa20..29a4246c 100644 --- a/src/framework/graphics/font.cpp +++ b/src/framework/graphics/font.cpp @@ -76,7 +76,7 @@ void Font::renderText(const std::string& text, const Color& color) { // prevent glitches from invalid rects - if(!screenCoords.isValid()) + if(!screenCoords.isValid() || !m_texture) return; int textLenght = text.length(); diff --git a/src/framework/graphics/fontmanager.cpp b/src/framework/graphics/fontmanager.cpp index 9137b2c6..c15a6721 100644 --- a/src/framework/graphics/fontmanager.cpp +++ b/src/framework/graphics/fontmanager.cpp @@ -27,6 +27,11 @@ FontManager g_fonts; +FontManager::FontManager() +{ + m_defaultFont = FontPtr(new Font("emptyfont")); +} + void FontManager::releaseFonts() { m_defaultFont.reset(); diff --git a/src/framework/graphics/fontmanager.h b/src/framework/graphics/fontmanager.h index 0444f672..586a79bd 100644 --- a/src/framework/graphics/fontmanager.h +++ b/src/framework/graphics/fontmanager.h @@ -28,6 +28,8 @@ class FontManager { public: + FontManager(); + /// Release fonts references, thus making possible to destruct them void releaseFonts(); diff --git a/src/otclient/CMakeLists.txt b/src/otclient/CMakeLists.txt index 242787f2..738a489b 100644 --- a/src/otclient/CMakeLists.txt +++ b/src/otclient/CMakeLists.txt @@ -8,7 +8,7 @@ ELSE(FORBIDDEN_FUNCTIONS) MESSAGE(STATUS "Lua forbidden functions: OFF") ENDIF(FORBIDDEN_FUNCTIONS) -SET(OTCLIENT_SOURCES ${OTCLIENT_SOURCES} +SET(otclient_SOURCES ${otclient_SOURCES} # otclient ${CMAKE_CURRENT_LIST_DIR}/otclient.cpp ${CMAKE_CURRENT_LIST_DIR}/luafunctions.cpp diff --git a/src/otclient/otclient.cpp b/src/otclient/otclient.cpp index 314d7c50..ef2c282a 100644 --- a/src/otclient/otclient.cpp +++ b/src/otclient/otclient.cpp @@ -21,6 +21,7 @@ */ #include "otclient.h" +#include OTClient::OTClient() : Application(Otc::AppCompactName) { @@ -31,4 +32,10 @@ void OTClient::init(const std::vector& args) { logInfo(Otc::AppName, " ", Otc::AppVersion); Application::init(args, Fw::AppEnableAll); + + g_modules.discoverModules(); + g_modules.autoLoadModules(100); + g_modules.ensureModuleLoaded("client"); + g_modules.ensureModuleLoaded("game"); + g_modules.autoLoadModules(1000); }