diff --git a/.gitmodules b/.gitmodules index 1b1349e6..f2a9c9e6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "data/tibiafiles"] - path = data/tibiafiles +[submodule "modules/tibiafiles"] + path = modules/tibiafiles url = https://github.com/Baxnie/otclient-tibiafiles.git diff --git a/CMakeLists.txt b/CMakeLists.txt index dfee198c..cd227920 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,8 @@ PROJECT(otclient) # setup custom cmake modules path SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}") +OPTION(USE_PCH "Use precompiled header" ON) + # find needed packages SET(Boost_USE_STATIC_LIBS ON) SET(Boost_USE_MULTITHREADED OFF) @@ -13,21 +15,24 @@ FIND_PACKAGE(Lua REQUIRED) FIND_PACKAGE(PhysFS REQUIRED) FIND_PACKAGE(GMP REQUIRED) FIND_PACKAGE(ZLIB REQUIRED) +FIND_PACKAGE(PCHSupport REQUIRED) # choose a default build type if not specified IF(NOT CMAKE_BUILD_TYPE) - SET(CMAKE_BUILD_TYPE RelWithDebInfo) + SET(CMAKE_BUILD_TYPE Debug) ENDIF(NOT CMAKE_BUILD_TYPE) MESSAGE(STATUS "BUILD TYPE: " ${CMAKE_BUILD_TYPE}) # setup compiler options IF(CMAKE_COMPILER_IS_GNUCXX) - SET(CMAKE_CXX_FLAGS "-Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-unused-result -std=gnu++0x") - SET(CMAKE_CXX_FLAGS_DEBUG "-O1 -g -ggdb -fno-inline") - SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -Wl,-s") - SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g") + SET(CXX_WARNS "-Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-unused-result") + SET(CMAKE_CXX_FLAGS "-std=c++0x -pipe ${CXX_WARNS}") + SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -ggdb3 -fno-inline") + SET(CMAKE_CXX_FLAGS_RELEASE "-O2") + SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O1 -g -fno-inline") ENDIF(CMAKE_COMPILER_IS_GNUCXX) + INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIRS} ${OPENGL_INCLUDE_DIR} @@ -35,106 +40,91 @@ INCLUDE_DIRECTORIES( ${PHYSFS_INCLUDE_DIR} ${GMP_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} - "${CMAKE_CURRENT_SOURCE_DIR}/src/framework") - -# setup definitions -ADD_DEFINITIONS(-D_REENTRANT) + "${CMAKE_CURRENT_SOURCE_DIR}/src/framework" +) IF(CMAKE_BUILD_TYPE STREQUAL "Debug") ADD_DEFINITIONS(-D_DEBUG) ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug") SET(SOURCES -# game sources src/main.cpp + src/otclient.cpp + src/otclientluafunctions.cpp -# game files - src/tibiadat.cpp - src/tibiaspr.cpp - -# game contents src/game.cpp src/map.cpp - src/tile.cpp - src/thing.cpp - src/item.cpp - -# game net src/protocollogin.cpp src/protocolgame.cpp - src/protocolgameparse.cpp src/protocolgamesend.cpp + src/protocolgameparse.cpp + src/tibiadat.cpp + src/tibiaspr.cpp + src/item.cpp + src/tile.cpp + src/thing.cpp -# framework core - src/framework/core/dispatcher.cpp - src/framework/core/configs.cpp - src/framework/core/resources.cpp - src/framework/core/engine.cpp - src/framework/core/packages.cpp + # framework third party + src/framework/thirdparty/apngloader.cpp -# framework otml - src/framework/otml/otmlemitter.cpp - src/framework/otml/otmlparser.cpp - src/framework/otml/otmlnode.cpp - -# framework script - src/framework/script/luastate.cpp - src/framework/script/luavalue.cpp - src/framework/script/luaobject.cpp - src/framework/script/luainterface.cpp - src/framework/script/luafunctions.cpp - src/framework/script/luaexception.cpp - src/framework/script/luavaluecasts.cpp - -# framework utilities - src/framework/util/color.cpp - src/framework/util/translator.cpp - src/framework/util/convert.cpp - src/framework/util/logger.cpp - src/framework/util/apngloader.cpp - src/framework/util/allocator.cpp - -# framework graphics - src/framework/graphics/image.cpp - src/framework/graphics/borderedimage.cpp - src/framework/graphics/framebuffer.cpp - src/framework/graphics/font.cpp - src/framework/graphics/fonts.cpp - src/framework/graphics/textureloader.cpp - src/framework/graphics/texture.cpp - src/framework/graphics/animatedtexture.cpp - src/framework/graphics/textures.cpp - src/framework/graphics/graphics.cpp - src/framework/graphics/textarea.cpp - -# framework ui - src/framework/ui/uianchorlayout.cpp - src/framework/ui/uielement.cpp - src/framework/ui/uielementskin.cpp - src/framework/ui/uibuttonskin.cpp - src/framework/ui/uilabelskin.cpp - src/framework/ui/uicontainer.cpp - src/framework/ui/uiskins.cpp - src/framework/ui/uiloader.cpp - src/framework/ui/uibutton.cpp - src/framework/ui/uilabel.cpp - src/framework/ui/uiwindow.cpp - src/framework/ui/uiwindowskin.cpp - src/framework/ui/uitextedit.cpp - src/framework/ui/uitexteditskin.cpp - src/framework/ui/uicheckboxskin.cpp - src/framework/ui/uicheckbox.cpp - -# framework net + # framework net src/framework/net/connection.cpp - src/framework/net/protocol.cpp src/framework/net/inputmessage.cpp src/framework/net/outputmessage.cpp + src/framework/net/protocol.cpp src/framework/net/rsa.cpp + + # framework util + src/framework/util/logger.cpp + src/framework/util/color.cpp + src/framework/util/translator.cpp + + # framework core + src/framework/core/configmanager.cpp + src/framework/core/resourcemanager.cpp + src/framework/core/eventdispatcher.cpp + src/framework/core/modulemanager.cpp + src/framework/core/module.cpp + + # framework graphics + src/framework/graphics/font.cpp + src/framework/graphics/fontmanager.cpp + src/framework/graphics/graphics.cpp + src/framework/graphics/texture.cpp + src/framework/graphics/framebuffer.cpp + src/framework/graphics/animatedtexture.cpp + src/framework/graphics/framebuffer.cpp + src/framework/graphics/texturemanager.cpp + src/framework/graphics/borderimage.cpp + src/framework/graphics/image.cpp + src/framework/graphics/textarea.cpp + + # framework otml + src/framework/otml/otmldocument.cpp + src/framework/otml/otmlemitter.cpp + src/framework/otml/otmlexception.cpp + src/framework/otml/otmlnode.cpp + src/framework/otml/otmlparser.cpp + + # framework luascript + src/framework/luascript/luainterface.cpp + src/framework/luascript/luaobject.cpp + src/framework/luascript/luaexception.cpp + src/framework/luascript/luafunctions.cpp + + # framework ui + src/framework/ui/uimanager.cpp + src/framework/ui/uiwidget.cpp + src/framework/ui/uilabel.cpp + src/framework/ui/uibutton.cpp + src/framework/ui/uilineedit.cpp + src/framework/ui/uiwindow.cpp + src/framework/ui/uianchorlayout.cpp + src/framework/ui/uianchor.cpp ) IF(WIN32) - SET(SOURCES ${SOURCES} src/framework/platform/win32platform.cpp) + SET(SOURCES ${SOURCES} src/framework/core/win32platform.cpp) SET(ADDITIONAL_LIBRARIES ws2_32) IF(CMAKE_COMPILER_IS_GNUCXX) SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -mwindows") @@ -142,25 +132,30 @@ IF(WIN32) ENDIF(CMAKE_COMPILER_IS_GNUCXX) ADD_DEFINITIONS(-DWIN32_NO_CONSOLE) ELSE(WIN32) - SET(SOURCES ${SOURCES} src/framework/platform/x11platform.cpp) - #ADD_DEFINITIONS(-D_DEBUG_MEMORY) - SET(ADDITIONAL_LIBRARIES pthread GLU) + SET(SOURCES ${SOURCES} src/framework/core/x11platform.cpp) ENDIF(WIN32) # target executable ADD_EXECUTABLE(otclient ${SOURCES}) # target link libraries -TARGET_LINK_LIBRARIES(otclient +TARGET_LINK_LIBRARIES( + otclient ${Boost_LIBRARIES} ${OPENGL_LIBRARIES} ${LUA_LIBRARIES} ${PHYSFS_LIBRARY} ${GMP_LIBRARY} ${ZLIB_LIBRARY} - ${ADDITIONAL_LIBRARIES}) + ${ADDITIONAL_LIBRARIES} +) + +IF(USE_PCH) + ADD_PRECOMPILED_HEADER(otclient ${CMAKE_CURRENT_SOURCE_DIR}/src/framework/pch.h) +ENDIF(USE_PCH) # installation SET(DATA_INSTALL_DIR share/otclient) INSTALL(TARGETS otclient RUNTIME DESTINATION bin) -INSTALL(DIRECTORY data DESTINATION ${DATA_INSTALL_DIR}) +INSTALL(DIRECTORY modules DESTINATION ${DATA_INSTALL_DIR}) + diff --git a/data/fonts/helvetica-11px-bold.otml b/data/fonts/helvetica-11px-bold.otml deleted file mode 100644 index e69e35cf..00000000 --- a/data/fonts/helvetica-11px-bold.otml +++ /dev/null @@ -1,10 +0,0 @@ -glyph-height: 14 -glyph-spacing: [1, 1] -top-margin: 2 -image: helvetica-11px-bold.png -image-glyph-size: [16, 16] - -glyph-widths: - 32: 4 - 65: 8 - diff --git a/data/fonts/helvetica-11px.otml b/data/fonts/helvetica-11px.otml deleted file mode 100644 index b4f04e1b..00000000 --- a/data/fonts/helvetica-11px.otml +++ /dev/null @@ -1,9 +0,0 @@ -glyph-height: 14 -glyph-spacing: [1, 1] -top-margin: 1 -image: helvetica-11px.png -image-glyph-size: [16, 16] - -glyph-widths: - 32: 4 - diff --git a/data/fonts/helvetica-12px-bold.otml b/data/fonts/helvetica-12px-bold.otml deleted file mode 100644 index 925e0826..00000000 --- a/data/fonts/helvetica-12px-bold.otml +++ /dev/null @@ -1,10 +0,0 @@ -glyph-height: 16 -glyph-spacing: [1, 1] -top-margin: 2 -image: helvetica-12px-bold.png -image-glyph-size: [18, 18] - -glyph-widths: - 32: 4 - 65: 9 - diff --git a/data/fonts/helvetica-12px.otml b/data/fonts/helvetica-12px.otml deleted file mode 100644 index 8ec0b6db..00000000 --- a/data/fonts/helvetica-12px.otml +++ /dev/null @@ -1,9 +0,0 @@ -glyph-height: 15 -glyph-spacing: [1, 1] -top-margin: 1 -image: helvetica-12px.png -image-glyph-size: [16, 16] - -glyph-widths: - 32: 4 - 65: 8 diff --git a/data/fonts/helvetica-14px-bold.otml b/data/fonts/helvetica-14px-bold.otml deleted file mode 100644 index 737ec8af..00000000 --- a/data/fonts/helvetica-14px-bold.otml +++ /dev/null @@ -1,10 +0,0 @@ -glyph-height: 16 -glyph-spacing: [1, 1] -top-margin: 2 -image: helvetica-14px-bold.png -image-glyph-size: [20, 20] - -glyph-widths: - 32: 4 - 65: 9 - diff --git a/data/modules/core/core.lua b/data/modules/core/core.lua deleted file mode 100644 index 06068672..00000000 --- a/data/modules/core/core.lua +++ /dev/null @@ -1,3 +0,0 @@ -require 'constants' -require 'util' -require 'messagebox' \ No newline at end of file diff --git a/data/modules/mainmenu/init.lua b/data/modules/mainmenu/init.lua deleted file mode 100644 index cfa4fee2..00000000 --- a/data/modules/mainmenu/init.lua +++ /dev/null @@ -1,16 +0,0 @@ -require 'entergame' - -function initializeApplication() - mainMenu = loadUI("ui/mainmenu", rootUI) -end - -function terminateApplication() - exit() -end - --- here is where everything starts -if not initialized then - initializeApplication() - onClose = terminateApplication - initialized = true -end diff --git a/data/skins/default.otml b/data/skins/default.otml deleted file mode 100644 index 0786421a..00000000 --- a/data/skins/default.otml +++ /dev/null @@ -1,80 +0,0 @@ -default font: helvetica-12px -default font color: [210, 210, 210, 255] - -buttons: - default: - font: helvetica-11px-bold - font color: [240, 173, 77, 255] - default size: [106, 24] - - bordered image: - source: button.png - border: 5 - - hover state: - bordered image: - source: button_hover.png - border: 5 - - down state: - text translate: [1, 1] - bordered image: - source: button_down.png - border: 5 -panels: - default: - # the default panel is empty - - mainMenuBackground: - image: background.png - antialised: true - - roundedGridPanel: - bordered image: - source: panel_rounded.png - border: 4 - - flatPanel: - bordered image: - source: panel_flat.png - border: 1 - -labels: - default: - - large: - font: helvetica-12px-bold - -windows: - default: - font: helvetica-11px-bold - font color: [240, 173, 77, 255] - head: - height: 20 - bordered image: - source: window.png - size: [256, 19] - border: 4 - bottom: 3 - - body: - bordered image: - source: window.png - size: [256, 237] - offset: [0, 19] - border: 4 - top: 0 - -text edits: - default: - default size: [86, 20] - text margin: 3 - bordered image: - source: panel_flat.png - border: 1 - -line decorations: - default: - bordered image: - source: horizontal_separator.png - top: 2 diff --git a/data/tibiafiles b/data/tibiafiles deleted file mode 160000 index a25c2389..00000000 --- a/data/tibiafiles +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a25c238959eb660a187e614eb5c794e0da302bac diff --git a/data/modules/core/constants.lua b/modules/core/constants.lua similarity index 100% rename from data/modules/core/constants.lua rename to modules/core/constants.lua diff --git a/modules/core/core.otmod b/modules/core/core.otmod new file mode 100644 index 00000000..27229214 --- /dev/null +++ b/modules/core/core.otmod @@ -0,0 +1,23 @@ +Module + name: core + description: Contains lua classes, functions and constants used by other modules + author: OTClient team + website: https://github.com/edubart/otclient + version: 0.2 + autoLoad: true + dependencies: + - core_fonts + - core_ui + + onLoad: | + require 'constants' + require 'util' + require 'widget' + require 'messagebox' + + rootWidget = getRootWidget() + return true + + onUnload: | + rootWidget = nil + diff --git a/data/modules/core/messagebox.lua b/modules/core/messagebox.lua similarity index 85% rename from data/modules/core/messagebox.lua rename to modules/core/messagebox.lua index a29c3e5f..3df5d88c 100644 --- a/data/modules/core/messagebox.lua +++ b/modules/core/messagebox.lua @@ -11,32 +11,32 @@ function MessageBox.create(title, text, flags) -- create messagebox window local window = UIWindow.create() - id = "messageBoxWindow" + window.id = "messageBoxWindow" window.title = title - window:centerIn(rootUI) - window:setLocked(true) - rootUI:addChild(window) + window:centerIn("parent") + --window:setLocked(true) + rootWidget:addChild(window) -- create messagebox label local label = UILabel.create() - id = "messageBoxLabel" + label.id = "messageBoxLabel" label.text = text label:addAnchor(AnchorHorizontalCenter, window.id, AnchorHorizontalCenter) label:addAnchor(AnchorTop, window.id, AnchorTop) - --label:setMargin(27, 0) + label:setMargin(27, 0) + label:resizeToText() window:addChild(label) -- set window size based on label size - window.width = label.width + 40 + window.width = label.width + 60 window.height = label.height + 64 -- setup messagebox first button - local buttonText - local button1 = UIButton.new() - id = "messageBoxButton1" + local button1 = UIButton.create() + button1.id = "messageBoxButton1" button1:addAnchor(AnchorBottom, window.id, AnchorBottom) button1:addAnchor(AnchorRight, window.id, AnchorRight) - --button1:setMargin(10) + button1:setMargin(10) button1.width = 64 window:addChild(button1) diff --git a/data/modules/core/util.lua b/modules/core/util.lua similarity index 100% rename from data/modules/core/util.lua rename to modules/core/util.lua diff --git a/modules/core/widget.lua b/modules/core/widget.lua new file mode 100644 index 00000000..afdebbac --- /dev/null +++ b/modules/core/widget.lua @@ -0,0 +1,19 @@ +function UIWidget:setMargin(...) + local params = {...} + if #params == 1 then + self.marginTop = params[1] + self.marginRight = params[1] + self.marginBottom = params[1] + self.marginLeft = params[1] + elseif #params == 2 then + self.marginTop = params[1] + self.marginRight = params[2] + self.marginBottom = params[1] + self.marginLeft = params[2] + elseif #params == 4 then + self.marginTop = params[1] + self.marginRight = params[2] + self.marginBottom = params[3] + self.marginLeft = params[4] + end +end \ No newline at end of file diff --git a/modules/core_fonts/core_fonts.otmod b/modules/core_fonts/core_fonts.otmod new file mode 100644 index 00000000..eac5071f --- /dev/null +++ b/modules/core_fonts/core_fonts.otmod @@ -0,0 +1,17 @@ +Module + name: core_fonts + description: Contains fonts used by core + author: OTClient team + website: https://github.com/edubart/otclient + version: 0.2 + autoLoad: true + onLoad: | + importFont('helvetica-11px-bold') + importFont('helvetica-11px') + importFont('helvetica-12px-bold') + importFont('helvetica-12px') + importFont('helvetica-14px-bold') + + setDefaultFont('helvetica-12px') + return true + diff --git a/modules/core_fonts/helvetica-11px-bold.otfont b/modules/core_fonts/helvetica-11px-bold.otfont new file mode 100644 index 00000000..32ee09e6 --- /dev/null +++ b/modules/core_fonts/helvetica-11px-bold.otfont @@ -0,0 +1,12 @@ +Font + name: helvetica-11px-bold + height: 14 + spacing: 1 1 + top margin: 2 + texture: helvetica-11px-bold.png + glyph size: 16 16 + + glyph widths: + 32: 4 + 65: 8 + diff --git a/data/fonts/helvetica-11px-bold.png b/modules/core_fonts/helvetica-11px-bold.png similarity index 100% rename from data/fonts/helvetica-11px-bold.png rename to modules/core_fonts/helvetica-11px-bold.png diff --git a/modules/core_fonts/helvetica-11px.otfont b/modules/core_fonts/helvetica-11px.otfont new file mode 100644 index 00000000..1f4be47c --- /dev/null +++ b/modules/core_fonts/helvetica-11px.otfont @@ -0,0 +1,11 @@ +Font + name: helvetica-11px + height: 14 + spacing: 1 1 + top margin: 1 + texture: helvetica-11px.png + glyph size: 16 16 + + glyph widths: + 32: 4 + diff --git a/data/fonts/helvetica-11px.png b/modules/core_fonts/helvetica-11px.png similarity index 100% rename from data/fonts/helvetica-11px.png rename to modules/core_fonts/helvetica-11px.png diff --git a/modules/core_fonts/helvetica-12px-bold.otfont b/modules/core_fonts/helvetica-12px-bold.otfont new file mode 100644 index 00000000..28512f4f --- /dev/null +++ b/modules/core_fonts/helvetica-12px-bold.otfont @@ -0,0 +1,12 @@ +Font + name: helvetica-12px-bold + height: 16 + spacing: 1 1 + top margin: 2 + texture: helvetica-12px-bold.png + glyph size: 18 18 + + glyph widths: + 32: 4 + 65: 9 + diff --git a/data/fonts/helvetica-12px-bold.png b/modules/core_fonts/helvetica-12px-bold.png similarity index 100% rename from data/fonts/helvetica-12px-bold.png rename to modules/core_fonts/helvetica-12px-bold.png diff --git a/modules/core_fonts/helvetica-12px.otfont b/modules/core_fonts/helvetica-12px.otfont new file mode 100644 index 00000000..2d32cf6e --- /dev/null +++ b/modules/core_fonts/helvetica-12px.otfont @@ -0,0 +1,11 @@ +Font + name: helvetica-12px + height: 15 + spacing: 1 1 + top margin: 1 + texture: helvetica-12px.png + glyph size: 16 16 + + glyph widths: + 32: 4 + 65: 8 diff --git a/data/fonts/helvetica-12px.png b/modules/core_fonts/helvetica-12px.png similarity index 100% rename from data/fonts/helvetica-12px.png rename to modules/core_fonts/helvetica-12px.png diff --git a/modules/core_fonts/helvetica-14px-bold.otfont b/modules/core_fonts/helvetica-14px-bold.otfont new file mode 100644 index 00000000..2a91bed0 --- /dev/null +++ b/modules/core_fonts/helvetica-14px-bold.otfont @@ -0,0 +1,12 @@ +Font + name: helvetica-14px-bold + height: 16 + spacing: 1 1 + top margin: 2 + texture: helvetica-14px-bold.png + glyph size: 20 20 + + glyph widths: + 32: 4 + 65: 9 + diff --git a/data/fonts/helvetica-14px-bold.png b/modules/core_fonts/helvetica-14px-bold.png similarity index 100% rename from data/fonts/helvetica-14px-bold.png rename to modules/core_fonts/helvetica-14px-bold.png diff --git a/modules/core_ui/buttons.otui b/modules/core_ui/buttons.otui new file mode 100644 index 00000000..c71f04b6 --- /dev/null +++ b/modules/core_ui/buttons.otui @@ -0,0 +1,19 @@ +Button < UIButton + font: helvetica-11px-bold + color: 240 173 77 255 + size: 106 24 + border-image: + source: /core_ui/images/button.png + border: 5 + + state.hover: + border-image: + source: /core_ui/images/button_hover.png + border: 5 + + state.down: + text-translate: 1 1 + border-image: + source: /core_ui/images/button_down.png + border: 5 + diff --git a/modules/core_ui/core_ui.otmod b/modules/core_ui/core_ui.otmod new file mode 100644 index 00000000..818c8c32 --- /dev/null +++ b/modules/core_ui/core_ui.otmod @@ -0,0 +1,18 @@ +Module + name: core_ui + description: Contains ui styles used by other modules + author: OTClient team + website: https://github.com/edubart/otclient + version: 0.2 + autoLoad: true + dependencies: + - core_fonts + onLoad: | + importStyles('buttons.otui') + importStyles('labels.otui') + importStyles('panels.otui') + importStyles('separators.otui') + importStyles('lineedits.otui') + importStyles('windows.otui') + return true + diff --git a/data/skins/button.png b/modules/core_ui/images/button.png similarity index 100% rename from data/skins/button.png rename to modules/core_ui/images/button.png diff --git a/data/skins/button_down.png b/modules/core_ui/images/button_down.png similarity index 100% rename from data/skins/button_down.png rename to modules/core_ui/images/button_down.png diff --git a/data/skins/button_hover.png b/modules/core_ui/images/button_hover.png similarity index 100% rename from data/skins/button_hover.png rename to modules/core_ui/images/button_hover.png diff --git a/data/skins/container_bg.png b/modules/core_ui/images/container_bg.png similarity index 100% rename from data/skins/container_bg.png rename to modules/core_ui/images/container_bg.png diff --git a/data/skins/horizontal_separator.png b/modules/core_ui/images/horizontal_separator.png similarity index 100% rename from data/skins/horizontal_separator.png rename to modules/core_ui/images/horizontal_separator.png diff --git a/data/skins/horizotal_separator.png b/modules/core_ui/images/horizotal_separator.png similarity index 100% rename from data/skins/horizotal_separator.png rename to modules/core_ui/images/horizotal_separator.png diff --git a/data/skins/panel_flat.png b/modules/core_ui/images/panel_flat.png similarity index 100% rename from data/skins/panel_flat.png rename to modules/core_ui/images/panel_flat.png diff --git a/data/skins/panel_rounded.png b/modules/core_ui/images/panel_rounded.png similarity index 100% rename from data/skins/panel_rounded.png rename to modules/core_ui/images/panel_rounded.png diff --git a/data/skins/window.png b/modules/core_ui/images/window.png similarity index 100% rename from data/skins/window.png rename to modules/core_ui/images/window.png diff --git a/modules/core_ui/labels.otui b/modules/core_ui/labels.otui new file mode 100644 index 00000000..9444c45a --- /dev/null +++ b/modules/core_ui/labels.otui @@ -0,0 +1,5 @@ +Label < UILabel + +LargerLabel < Label + font: helvetica-12px-bold + diff --git a/modules/core_ui/lineedits.otui b/modules/core_ui/lineedits.otui new file mode 100644 index 00000000..e3caa9b3 --- /dev/null +++ b/modules/core_ui/lineedits.otui @@ -0,0 +1,7 @@ +LineEdit < UILineEdit + size: 86 20 + text-margin: 3 + border-image: + source: /core_ui/images/panel_flat.png + border: 1 + diff --git a/modules/core_ui/panels.otui b/modules/core_ui/panels.otui new file mode 100644 index 00000000..37cae238 --- /dev/null +++ b/modules/core_ui/panels.otui @@ -0,0 +1,11 @@ +Panel < UIWidget + +FlatPanel < Panel + border-image: + source: /core_ui/images/panel_flat.png + border: 4 + +RoundedGridPanel < Panel + border-image: + source: /core_ui/images/panel_rounded.png + border: 4 diff --git a/modules/core_ui/separators.otui b/modules/core_ui/separators.otui new file mode 100644 index 00000000..67e2d355 --- /dev/null +++ b/modules/core_ui/separators.otui @@ -0,0 +1,4 @@ +HorizontalSeparator < UIWidget + border-image: + source: /core_ui/images/horizontal_separator.png + border.top: 2 diff --git a/modules/core_ui/windows.otui b/modules/core_ui/windows.otui new file mode 100644 index 00000000..7c1b965a --- /dev/null +++ b/modules/core_ui/windows.otui @@ -0,0 +1,20 @@ +Window < UIWindow + size: 200 100 + head: + height: 20 + border-image: + source: /core_ui/images/window.png + size: 256 19 + border: 4 + border.bottom: 3 + + body: + border-image: + source: /core_ui/images/window.png + size: 256 237 + offset: 0 19 + border: 4 + border.top: 0 + +MainWindow < Window + anchors.centerIn: parent \ No newline at end of file diff --git a/data/modules/mainmenu/entergame.lua b/modules/mainmenu/entergame.lua similarity index 79% rename from data/modules/mainmenu/entergame.lua rename to modules/mainmenu/entergame.lua index dba2ae5a..0ef57768 100644 --- a/data/modules/mainmenu/entergame.lua +++ b/modules/mainmenu/entergame.lua @@ -4,7 +4,7 @@ function EnterGame_connectToLoginServer() -- used to recreate enter game window local recreateEnterGame = function() - loadUI("ui/entergamewindow") + loadUI("/mainmenu/ui/entergamewindow.otui") end -- display loading message box @@ -40,18 +40,16 @@ function EnterGame_connectToLoginServer() local motdText = string.sub(motd, string.find(motd, "\n") + 1, string.len(motd)) local motdBox = displayInfoBox("Message of the day", motdText) - -- cancel protocol and reacreate enter game window - protocol:cancel() - motdBox.onOk = recreateEnterGame + -- hide main menu + mainMenu.visible = false end -- get account and password then login - local enterGameWindow = rootUI:getChild("enterGameWindow") - local account = enterGameWindow:getChild("accountNameTextEdit").text - local password = enterGameWindow:getChild("passwordTextEdit").text + local enterGameWindow = rootWidget:getChild("enterGameWindow") + local account = enterGameWindow:getChild("accountNameLineEdit").text + local password = enterGameWindow:getChild("accountPasswordLineEdit").text protocolLogin:login(account, password) -- destroy enter game window enterGameWindow:destroy() end - diff --git a/modules/mainmenu/mainmenu.otmod b/modules/mainmenu/mainmenu.otmod new file mode 100644 index 00000000..95b79fd4 --- /dev/null +++ b/modules/mainmenu/mainmenu.otmod @@ -0,0 +1,26 @@ +Module + name: mainmenu + description: Create the game mainmenu, where everything starts + author: OTClient team + website: https://github.com/edubart/otclient + version: 0.2 + autoLoad: true + dependencies: + - core + + onLoad: | + require('entergame') + + if not initialized then + mainMenu = loadUI("/mainmenu/ui/mainmenu.otui") + getRootWidget():addChild(mainMenu) + initialized = true + end + + return true + + onUnload: | + mainMenu:destroy() + mainMenu = nil + initialized = false + diff --git a/data/skins/background.png b/modules/mainmenu/ui/background.png similarity index 100% rename from data/skins/background.png rename to modules/mainmenu/ui/background.png diff --git a/data/modules/mainmenu/ui/entergamewindow.otml b/modules/mainmenu/ui/entergamewindow.otui similarity index 68% rename from data/modules/mainmenu/ui/entergamewindow.otml rename to modules/mainmenu/ui/entergamewindow.otui index e4c58684..54e101d7 100644 --- a/data/modules/mainmenu/ui/entergamewindow.otml +++ b/modules/mainmenu/ui/entergamewindow.otui @@ -1,18 +1,17 @@ -%window#enterGameWindow +MainWindow + id: enterGameWindow title: Enter Game - size: [236, 160] - anchors.horizontalCenter: parent.horizontalCenter - anchors.verticalCenter: parent.verticalCenter + size: 236 160 - %label#accountNameLabel - skin: large + LargerLabel text: Account name anchors.left: parent.left anchors.top: parent.top margin.left: 18 margin.top: 28 - %textEdit#accountNameTextEdit + LineEdit + id: accountNameLineEdit text: otclient0 anchors.left: parent.left anchors.right: parent.right @@ -20,14 +19,14 @@ margin.left: 18 margin.right: 18 - %label#passwordLabel - skin: large + LargerLabel text: Password anchors.left: prev.left anchors.top: prev.bottom margin.top: 8 - %textEdit#passwordTextEdit + LineEdit + id: accountPasswordLineEdit text: 123456 anchors.left: parent.left anchors.right: parent.right @@ -35,7 +34,7 @@ margin.left: 18 margin.right: 18 - %button#okButton + Button text: Ok width: 64 anchors.right: next.left @@ -44,11 +43,11 @@ margin.right: 16 onClick: EnterGame_connectToLoginServer() - %button#cancelButton + Button text: Cancel width: 64 anchors.right: parent.right anchors.bottom: parent.bottom margin.bottom: 16 margin.right: 16 - onClick: function(self) rootUI:getChild("enterGameWindow"):destroy() end + onClick: function(self) self.parent:destroy() end diff --git a/data/modules/mainmenu/ui/infowindow.otml b/modules/mainmenu/ui/infowindow.otui similarity index 69% rename from data/modules/mainmenu/ui/infowindow.otml rename to modules/mainmenu/ui/infowindow.otui index afdd7bf7..9315fe4c 100644 --- a/data/modules/mainmenu/ui/infowindow.otml +++ b/modules/mainmenu/ui/infowindow.otui @@ -1,19 +1,16 @@ -%window#infoWindow +MainWindow + id: infoWindow title: Info - size: [244, 221] - anchors.horizontalCenter: parent.horizontalCenter - anchors.verticalCenter: parent.verticalCenter - onLoad: function(self) self:setLocked() end + size: 244 221 - %panel#infoPanel - skin: flatPanel - size: [208, 129] + FlatPanel + size: 208 129 anchors.left: parent.left anchors.top: parent.top margin.top: 32 margin.left: 18 - %label#infoLabel + Label align: center text: |- OTClient @@ -23,29 +20,29 @@ anchors.top: parent.top margin.top: 20 - %lineDecoration#bottomSeparator - size: [190, 2] + HorizontalSeparator + size: 190 2 anchors.left: parent.left anchors.top: parent.top margin.top: 83 margin.left: 9 - %label#websiteLabel + Label text: Official Website anchors.left: parent.left anchors.bottom: parent.bottom margin.bottom: 14 margin.left: 9 - %button#websiteButton + Button text: Github Page - size: [88, 24] + size: 88 24 anchors.right: parent.right anchors.bottom: parent.bottom margin.bottom: 9 margin.right: 9 - %lineDecoration#bottomSeparator + HorizontalSeparator anchors.left: parent.left anchors.right: parent.right anchors.bottom: parent.bottom @@ -53,9 +50,9 @@ margin.left: 13 margin.right: 13 - %button#okButton + Button text: Ok - size: [46, 24] + size: 46 24 anchors.left: parent.left anchors.top: parent.top margin.top: 191 diff --git a/data/modules/mainmenu/ui/mainmenu.otml b/modules/mainmenu/ui/mainmenu.otml similarity index 66% rename from data/modules/mainmenu/ui/mainmenu.otml rename to modules/mainmenu/ui/mainmenu.otml index d01103b8..83287130 100644 --- a/data/modules/mainmenu/ui/mainmenu.otml +++ b/modules/mainmenu/ui/mainmenu.otml @@ -1,42 +1,47 @@ -%panel#background +Panel skin: mainMenuBackground anchors.left: parent.left anchors.right: parent.right anchors.top: parent.top anchors.bottom: parent.bottom - %panel#mainMenu + Panel + id: mainMenu skin: roundedGridPanel - size: [144, 162] + size: 144 162 anchors.left: parent.left anchors.bottom: parent.bottom margin.left: 60 margin.bottom: 70 - %button#enterGameButton + Button + id: enterGameButton text: Enter Game anchors.top: parent.top anchors.horizontalCenter: parent.horizontalCenter margin.top: 18 - onClick: loadUI("entergamewindow", rootUI) + onClick: rootWidget:addChild(loadUI("entergamewindow")) - %button#optionsButton + Button + id: optionsButton text: Options anchors.top: prev.bottom anchors.horizontalCenter: parent.horizontalCenter margin.top: 10 - onClick: loadUI("optionswindow", rootUI) + onClick: rootWidget:addChild(loadUI("optionswindow")) - %button#infoButton + Button + id: infoButton text: Info anchors.top: prev.bottom anchors.horizontalCenter: parent.horizontalCenter margin.top: 10 - onClick: loadUI("infowindow", rootUI) + onClick: rootWidget:addChild(loadUI("infowindow")) - %button#exitGameButton + Button + id: exitGameButton text: Exit anchors.top: prev.bottom anchors.horizontalCenter: parent.horizontalCenter margin.top: 10 - onClick: terminateApplication() + onClick: exit() diff --git a/modules/mainmenu/ui/mainmenu.otui b/modules/mainmenu/ui/mainmenu.otui new file mode 100644 index 00000000..17eba56c --- /dev/null +++ b/modules/mainmenu/ui/mainmenu.otui @@ -0,0 +1,38 @@ +MenuButton < Button + anchors.top: prev.bottom + anchors.horizontalCenter: parent.horizontalCenter + margin.top: 10 + +Panel + id: mainMenuBackground + image: + source: /mainmenu/ui/background.png + smooth: true + anchors.fill: parent + + RoundedGridPanel + id: mainMenu + size: 144 162 + anchors.left: parent.left + anchors.bottom: parent.bottom + margin.left: 60 + margin.bottom: 70 + + MenuButton + text: Enter Game + anchors.top: parent.top + anchors.horizontalCenter: parent.horizontalCenter + margin.top: 18 + onClick: rootWidget:addChild(loadUI("/mainmenu/ui/entergamewindow.otui")) + + MenuButton + text: Options + onClick: rootWidget:addChild(loadUI("/mainmenu/ui/optionswindow.otui")) + + MenuButton + text: Info + onClick: rootWidget:addChild(loadUI("/mainmenu/ui/infowindow.otui")) + + MenuButton + text: Exit + onClick: exit() diff --git a/data/modules/mainmenu/ui/optionswindow.otml b/modules/mainmenu/ui/optionswindow.otui similarity index 75% rename from data/modules/mainmenu/ui/optionswindow.otml rename to modules/mainmenu/ui/optionswindow.otui index c8df9049..752a1aa3 100644 --- a/data/modules/mainmenu/ui/optionswindow.otml +++ b/modules/mainmenu/ui/optionswindow.otui @@ -1,19 +1,18 @@ -%window#optionsWindow +MainWindow + id: optionsWindow title: Options - size: [286, 262] - anchors.horizontalCenter: parent.horizontalCenter - anchors.verticalCenter: parent.verticalCenter - onLoad: function(self) self:setLocked(true) end + size: 286 262 - # general - %button#generalButton + // general + Button text: General anchors.left: parent.left anchors.top: parent.top margin.left: 18 margin.top: 32 + onClick: displayErrorBox("Error", "Not implemented yet") - %label#generalLabel + Label text: |- Change general game options @@ -22,15 +21,15 @@ margin.left: 10 margin.top: -2 - # graphics - %button#graphicsButton + // graphics + Button text: Graphics anchors.left: parent.left anchors.top: parent.top margin.left: 18 margin.top: 65 - %label#graphicsLabel + Label text: |- Change graphics and performance settings @@ -39,37 +38,37 @@ margin.left: 10 margin.top: -2 - # console - %button#consoleButton + // console + Button text: Console anchors.left: parent.left anchors.top: parent.top margin.left: 18 margin.top: 98 - %label#consoleLabel + Label text: Customise the console anchors.left: prev.right anchors.top: prev.top margin.left: 10 margin.top: -2 - # hotkeys - %button#hotkeysButton + // hotkeys + Button text: Hotkeys anchors.left: parent.left anchors.top: parent.top margin.left: 18 margin.top: 131 - %label#hotkeysLabel + Label text: Edit your hotkey texts anchors.left: prev.right anchors.top: prev.top margin.left: 10 margin.top: -2 - %lineDecoration#middleSeparator + HorizontalSeparator anchors.left: parent.left anchors.right: parent.right anchors.bottom: parent.bottom @@ -77,15 +76,15 @@ margin.left: 18 margin.right: 18 - # motd - %button#motdButton + // motd + Button text: Motd anchors.left: parent.left anchors.bottom: parent.bottom margin.left: 18 margin.bottom: 60 - %label#motdLabel + Label text: | Show the most recent Message of the Day @@ -94,7 +93,7 @@ margin.left: 10 margin.top: -2 - %lineDecoration#bottomSeparator + HorizontalSeparator anchors.left: parent.left anchors.right: parent.right anchors.bottom: parent.bottom @@ -102,10 +101,10 @@ margin.left: 13 margin.right: 13 - # ok button - %button#okButton + // ok button + Button text: Ok - size: [43, 20] + size: 43 20 anchors.right: parent.right anchors.bottom: parent.bottom margin.right: 10 diff --git a/modules/tibiafiles b/modules/tibiafiles new file mode 160000 index 00000000..8bb3b7d6 --- /dev/null +++ b/modules/tibiafiles @@ -0,0 +1 @@ +Subproject commit 8bb3b7d6d86e561be4622fbe7dbef208446a0319 diff --git a/packages/core/constants.lua b/packages/core/constants.lua deleted file mode 100644 index 180925d1..00000000 --- a/packages/core/constants.lua +++ /dev/null @@ -1,11 +0,0 @@ -rootUI = App.getRootContainer() - --- AnchorPoint -AnchorNone = 0 -AnchorTop = 1 -AnchorBottom = 2 -AnchorLeft = 3 -AnchorRight = 4 -AnchorVerticalCenter = 5 -AnchorHorizontalCenter = 6 - diff --git a/packages/core/core.lua b/packages/core/core.lua deleted file mode 100644 index 33e5dda7..00000000 --- a/packages/core/core.lua +++ /dev/null @@ -1,3 +0,0 @@ -require 'constants' -require 'util' -require 'messagebox' diff --git a/packages/core/messagebox.lua b/packages/core/messagebox.lua deleted file mode 100644 index b4369a06..00000000 --- a/packages/core/messagebox.lua +++ /dev/null @@ -1,86 +0,0 @@ -MessageBox = {} -MessageBox.__index = MessageBox - --- messagebox flags -MessageBoxOk = 1 -MessageBoxCancel = 2 - -function MessageBox.create(title, text, flags) - local box = {} - setmetatable(box, MessageBox) - - -- create messagebox window - local window = UIWindow.new("messageBoxWindow", rootUI) - window.title = title - window:centerIn(rootUI) - window:setLocked() - - -- create messagebox label - local label = UILabel.new("messageBoxLabel", window) - label.text = text - label:addAnchor(AnchorHorizontalCenter, window, AnchorHorizontalCenter) - label:addAnchor(AnchorTop, window, AnchorTop) - label:setMargin(27, 0) - - -- set window size based on label size - window.width = label.width + 40 - window.height = label.height + 64 - - -- setup messagebox first button - local buttonText - local button1 = UIButton.new("messageBoxButton1", window) - button1:addAnchor(AnchorBottom, window, AnchorBottom) - button1:addAnchor(AnchorRight, window, AnchorRight) - button1:setMargin(10) - - if flags == MessageBoxOk then - buttonText = "Ok" - box.onOk = createEmptyFunction() - button1.onClick = function() - box.onOk() - box:destroy() - end - elseif flags == MessageBoxCancel then - buttonText = "Cancel" - box.onCancel = createEmptyFunction() - button1.onClick = function() - box.onCancel() - box:destroy() - end - end - button1.text = buttonText - - box.window = window - return box -end - -function MessageBox:destroy() - if self.onDestroy then - self.onDestroy() - self.onDestroy = nil - end - if self.window then - self.window:destroy() - self.window = nil - end - self.onOk = nil - self.onCancel = nil -end - --- shortcuts for creating message boxes -function displayMessageBox(title, text, flags) - return MessageBox.create(title, text, flags) -end - -function displayErrorBox(title, text) - return MessageBox.create(title, text, MessageBoxOk) -end - -function displayInfoBox(title, text) - return MessageBox.create(title, text, MessageBoxOk) -end - -function displayCancelBox(title, text) - return MessageBox.create(title, text, MessageBoxCancel) -end - diff --git a/packages/core/package.otml b/packages/core/package.otml deleted file mode 100644 index 64604cdc..00000000 --- a/packages/core/package.otml +++ /dev/null @@ -1,9 +0,0 @@ -title: Core -description: Core utilities used by other modules -author: otclient -version: 1 -website: https://github.com/edubart/otclient -enabled: true -dependencies: [core_fonts, core_styles] -script: core.lua - diff --git a/packages/core/util.lua b/packages/core/util.lua deleted file mode 100644 index 7e9c6c4f..00000000 --- a/packages/core/util.lua +++ /dev/null @@ -1,5 +0,0 @@ -function createEmptyFunction() - local emptyFunction = function() end - return emptyFunction -end - diff --git a/packages/core_fonts/fonts.lua b/packages/core_fonts/fonts.lua deleted file mode 100644 index ad2d430e..00000000 --- a/packages/core_fonts/fonts.lua +++ /dev/null @@ -1,4 +0,0 @@ --- load default fonts -App.loadFont("fonts/helvetica-11px") -App.loadFont("fonts/helvetica-11px-bold") - diff --git a/packages/core_fonts/fonts/helvetica-11px-bold.otml b/packages/core_fonts/fonts/helvetica-11px-bold.otml deleted file mode 100644 index 1c89fb7f..00000000 --- a/packages/core_fonts/fonts/helvetica-11px-bold.otml +++ /dev/null @@ -1,9 +0,0 @@ -glyph-height: 14 -glyph-spacing: 1 1 -top-margin: 2 -image: helvetica-11px-bold.png -image-glyph-size: 16 16 - -glyph-widths: - 32: 4 - diff --git a/packages/core_fonts/fonts/helvetica-11px-bold.png b/packages/core_fonts/fonts/helvetica-11px-bold.png deleted file mode 100644 index 3c334571..00000000 Binary files a/packages/core_fonts/fonts/helvetica-11px-bold.png and /dev/null differ diff --git a/packages/core_fonts/fonts/helvetica-11px.otml b/packages/core_fonts/fonts/helvetica-11px.otml deleted file mode 100644 index c5200e1c..00000000 --- a/packages/core_fonts/fonts/helvetica-11px.otml +++ /dev/null @@ -1,9 +0,0 @@ -glyph-height: 14 -glyph-spacing: 1 1 -top-margin: 1 -image: helvetica-11px.png -image-glyph-size: 16 16 - -glyph-widths: - 32: 4 - diff --git a/packages/core_fonts/fonts/helvetica-11px.png b/packages/core_fonts/fonts/helvetica-11px.png deleted file mode 100644 index 3f716a7f..00000000 Binary files a/packages/core_fonts/fonts/helvetica-11px.png and /dev/null differ diff --git a/packages/core_fonts/package.otml b/packages/core_fonts/package.otml deleted file mode 100644 index 6111c5db..00000000 --- a/packages/core_fonts/package.otml +++ /dev/null @@ -1,9 +0,0 @@ -title: Fonts -description: Fonts package -author: otclient -version: 1 -website: https://github.com/edubart/otclient -enabled: true -dependencies: [] -script: fonts.lua - diff --git a/packages/core_styles/package.otml b/packages/core_styles/package.otml deleted file mode 100644 index 3ed602e7..00000000 --- a/packages/core_styles/package.otml +++ /dev/null @@ -1,9 +0,0 @@ -title: Core styles -description: Core styles used by other modules -author: otclient -version: 1 -website: https://github.com/edubart/otclient -enabled: true -dependencies: [core_fonts] -script: styles.lua - diff --git a/packages/core_styles/styles.lua b/packages/core_styles/styles.lua deleted file mode 100644 index 97432480..00000000 --- a/packages/core_styles/styles.lua +++ /dev/null @@ -1,12 +0,0 @@ --- set default font -App.setDefaultFont("helvetica-11px") -App.setDefaultFontColor(Color("#f0ad4dff")) - --- load styles -App.loadStyle("styles/utilities") -App.loadStyle("styles/panels") -App.loadStyle("styles/buttons") -App.loadStyle("styles/labels") -App.loadStyle("styles/textedits") -App.loadStyle("styles/windows") -App.loadStyle("styles/linedecorations") diff --git a/packages/core_styles/styles/button_standard.png b/packages/core_styles/styles/button_standard.png deleted file mode 100644 index 70727e0b..00000000 Binary files a/packages/core_styles/styles/button_standard.png and /dev/null differ diff --git a/packages/core_styles/styles/button_standard_down.png b/packages/core_styles/styles/button_standard_down.png deleted file mode 100644 index 7808d00a..00000000 Binary files a/packages/core_styles/styles/button_standard_down.png and /dev/null differ diff --git a/packages/core_styles/styles/button_standard_hover.png b/packages/core_styles/styles/button_standard_hover.png deleted file mode 100644 index 509268b4..00000000 Binary files a/packages/core_styles/styles/button_standard_hover.png and /dev/null differ diff --git a/packages/core_styles/styles/buttons.otml b/packages/core_styles/styles/buttons.otml deleted file mode 100644 index fc9ea015..00000000 --- a/packages/core_styles/styles/buttons.otml +++ /dev/null @@ -1,25 +0,0 @@ -button - font: helvetica-11px-bold - font-color: #f0ad4dff - size: 106 24 - bordered-image: { source: button_standard.png; border: 5 } - -button:hover - bordered-image: { source: tibia_flash/button_standard_hover.png; border: 5 } - -button:down - text-translate: 1 1 - bordered-image: { source: tibia_flash/button_standard_down.png; border: 5 } - -button.small - width: 64 - -button.large - width: 144 - -button.notImplemented - onClick: displayErrorBox("Error", "Not implemented yet") - -button.closeParent - onClick: self.parent:destroy() - diff --git a/packages/core_styles/styles/linedecorations.otml b/packages/core_styles/styles/linedecorations.otml deleted file mode 100644 index e69de29b..00000000 diff --git a/packages/core_styles/styles/panels.otml b/packages/core_styles/styles/panels.otml deleted file mode 100644 index e69de29b..00000000 diff --git a/packages/core_styles/styles/textedits.otml b/packages/core_styles/styles/textedits.otml deleted file mode 100644 index e69de29b..00000000 diff --git a/packages/core_styles/styles/utilities.otml b/packages/core_styles/styles/utilities.otml deleted file mode 100644 index e69de29b..00000000 diff --git a/packages/core_styles/styles/windows.otml b/packages/core_styles/styles/windows.otml deleted file mode 100644 index e69de29b..00000000 diff --git a/packages/mainmenu/entergame.lua b/packages/mainmenu/entergame.lua deleted file mode 100644 index 26369bd4..00000000 --- a/packages/mainmenu/entergame.lua +++ /dev/null @@ -1,57 +0,0 @@ -function EnterGame_connectToLoginServer() - -- create login protocol - local protocolLogin = ProtocolLogin.new() - - -- used to recreate enter game window - local recreateEnterGame = function() - loadUI("ui/entergamewindow") - end - - -- display loading message box - local loadBox = displayCancelBox("Please wait", "Connecting..") - - -- cancel loading callback - loadBox.onCancel = function() - -- cancel protocol and reacreate enter game window - protocolLogin:cancel() - recreateEnterGame() - end - - -- error callback - protocolLogin.onError = function(error) - -- destroy loading message box - loadBox:destroy() - - -- display error message - local errorBox = displayErrorBox("Login Error", error) - - -- cancel protocol and reacreate enter game window - self.cancel() - errorBox.onOk = recreateEnterGame - end - - -- motd callback - protocolLogin.onMotd = function(motd) - -- destroy loading message box - loadBox:destroy() - - -- display motd - local motdNumber = string.sub(motd, 0, string.find(motd, "\n")) - local motdText = string.sub(motd, string.find(motd, "\n") + 1, string.len(motd)) - local motdBox = displayInfoBox("Message of the day", motdText) - - -- cancel protocol and reacreate enter game window - self.cancel() - motdBox.onOk = recreateEnterGame - end - - -- get account and password then login - local enterGameWindow = rootUI:child("enterGameWindow") - local account = enterGameWindow:child("accountNameTextEdit").text - local password = enterGameWindow:child("passwordTextEdit").text - protocolLogin:login(account, password) - - -- destroy enter game window - enterGameWindow:destroy() -end - diff --git a/packages/mainmenu/init.lua b/packages/mainmenu/init.lua deleted file mode 100644 index bce7aeb4..00000000 --- a/packages/mainmenu/init.lua +++ /dev/null @@ -1,16 +0,0 @@ -require 'entergame' - -function initializeApplication() - mainMenu = loadUI("ui/mainmenu") -end - -function terminateApplication() - App.exit() -end - --- here is where everything starts -if not initialized then - initializeApplication() - App.onClose = terminateApplication - initialized = true -end diff --git a/packages/mainmenu/package.otml b/packages/mainmenu/package.otml deleted file mode 100644 index 24d9a2c3..00000000 --- a/packages/mainmenu/package.otml +++ /dev/null @@ -1,9 +0,0 @@ -title: Main menu -description: Used to create the main menu -author: otclient -version: 1 -website: https://github.com/edubart/otclient -enabled: true -dependencies: [core] -script: init.lua - diff --git a/packages/mainmenu/ui/background.png b/packages/mainmenu/ui/background.png deleted file mode 100644 index 2c9c1041..00000000 Binary files a/packages/mainmenu/ui/background.png and /dev/null differ diff --git a/packages/mainmenu/ui/entergamewindow.otml b/packages/mainmenu/ui/entergamewindow.otml deleted file mode 100644 index 09a433da..00000000 --- a/packages/mainmenu/ui/entergamewindow.otml +++ /dev/null @@ -1,63 +0,0 @@ -Window - id: enterGameWindow - title: Enter Game - size: 236 178 - anchor.centerIn: parent - lockOnLoad: true - - Label - text: Account name - position: 18 33 - - Label - text: "Password:" - position: 18 62 - - Label - text: - [[If you don't have - an account yet]] - - anchors.top: parent.top - anchors.left: parent.left - margin: 87 18 - - Button - text: Create Account - anchors.top: parent.top - anchors.right: parent.right - margin: 94 18 - onClick: - function(self) - displayErrorBox("Error", "Not implemented yet") - self.parent:destroy() - end - - SmallButton - text: Ok - anchors.bottomRight: parent.bottomRight - margin: 10 66 - onClick: EnterGame_connectToLoginServer() - - SmallButton - text: Cancel - anchors.bottom: parent.bottom - anchors.right: parent.right - margin: 10 13 - onClick: displayErrorBox("Error", "Not implemented yet") - - TextEdit - id: accountNameTextEdit - text: tibialua0 - anchors.top: parent.top - anchors.right: parent.right - margin: 32 18 - - TextEdit - id: passwordTextEdit - text: lua123456 - text-hidden: true - anchors.top: parent.top - anchors.right: parent.right - margin: 61 18 - diff --git a/packages/mainmenu/ui/infowindow.otml b/packages/mainmenu/ui/infowindow.otml deleted file mode 100644 index 8acf138f..00000000 --- a/packages/mainmenu/ui/infowindow.otml +++ /dev/null @@ -1,54 +0,0 @@ -%window#infoWindow - title: Info - size: 244 221 - anchor.centerIn: parent - lockOnLoad: true - - %panel.flat - size: 208 129 - anchors.top: parent.top - anchors.left: parent.left - margin: 32 18 - - %label - align: center - text: |- - OTClient - Version 0.2.0 - Created by edubart - anchors.horizontalCenter: parent.horizontalCenter - anchors.top: parent.top - margin.top: 20 - - %element.bottomSeparator - size: 190 2 - anchors.top: parent.top - anchors.left: parent.left - margin: 83 9 - - %label - text: Official Website - anchors.bottom: parent.bottom - anchors.left: parent.left - margin: 14 9 - - %button - text: Github Page - size: 80 22 - anchors.bottom: parent.bottom - anchors.right: parent.right - margin: 9 - - %element.bottomSeparator - anchors.left: parent.left - anchors.right: parent.right - anchors.bottom: parent.bottom - margin: 40 13 - - %button.closeParent - text: Ok - size: 43 20 - anchors.top: parent.top - anchors.left: parent.left - margin: 191 188 - diff --git a/packages/mainmenu/ui/mainmenu.otml b/packages/mainmenu/ui/mainmenu.otml deleted file mode 100644 index df52045b..00000000 --- a/packages/mainmenu/ui/mainmenu.otml +++ /dev/null @@ -1,63 +0,0 @@ -@import "additional_elements" - -Panel - id: "mainBackground" - image: - source: "background.png" - antialised: true - anchor.fill: parent - - lista: - - valor1 - - valor2 - - valor3 - - FlatPanel - id: mainMenuPanel - size: {117, 171} - anchors.bottom: parent.bottom - anchors.left: parent.left - margin: {70, 60} - - // enter game button - Button - text: "Enter Game" - anchors.top: parent.top - anchors.horizontalCenter: parent.horizontalCenter - margin.top: 16 - onClick: | - function(self) - if not mainMenu:getChild("enterGameWindow") then - local enterGame = loadUI("entergamewindow") - enterGame:setLocked(true) - end - end - - Button - text: "Access Account" - anchors.top: prev.bottom - anchors.horizontalCenter: parent.horizontalCenter - margin.top: 6 - onClick: loadUI("entergamewindow") - - Button - text: "Options" - anchors.top: prev.bottom - anchors.horizontalCenter: parent.horizontalCenter - margin.top: 6 - onClick: loadUI("optionswindow") - - Button - text: "Info" - anchors.top: prev.bottom - anchors.horizontalCenter: parent.horizontalCenter - margin.top: 6 - onClick: loadUI("infowindow") - - Button - text: "Exit" - anchors.top: prev.bottom - anchors.horizontalCenter: parent.horizontalCenter - margin.top: 6 - onClick: terminateApplication() - diff --git a/packages/mainmenu/ui/optionswindow.otml b/packages/mainmenu/ui/optionswindow.otml deleted file mode 100644 index 66dae4dd..00000000 --- a/packages/mainmenu/ui/optionswindow.otml +++ /dev/null @@ -1,82 +0,0 @@ -%window#optionsWindow - title: Options - size: 286 262 - anchor.centerIn: parent - lockOnLoad: true - - panel - anchors.left: parent.left - anchors.right: parent.right - anchors.top: prev.bottom - margin.left: 18 - margin.top: 3 - height: 30 - - button - anchors.top: parent.top - anchors.left: parent.left - margin.top: 3 - onClick: displayErrorBox("Error", "Not implemented yet") - - label - anchors.top: parent.top - anchors.left: parent.left - margin.top: 99 - - %panel - anchors.top: parent.top - margin.top: 29 - - %button { text: General } - %label { text: "Change general\ngame options" } - - %panel - %button { text: Graphics } - %label { text: "Change graphics and\nperformance settings" } - - %panel - %button { text: Console } - %label { text: Customise the console } - - %panel - %button { text: Hotkeys } - %label { text: Edit your hotkey texts } - - %element.horizontalSeparator - anchors.left: parent.left - anchors.right: parent.right - anchors.bottom: parent.bottom - margin: 97 18 - - %panel - anchors.top: ~ - anchors.bottom: parent.bottom - margin.top: 29 - - %button - text: Motd - anchors.left: parent.left - anchors.bottom: parent.bottom - margin: 60 18 - - %label - text: | - Show the most recent - Message of the Day - anchors.left: parent.left - anchors.bottom: parent.bottom - margin: 56 117 - - %element.horizontalSeparator - anchors.left: parent.left - anchors.right: parent.right - anchors.bottom: parent.bottom - margin: 40 13 - - %button.closeParent - text: Ok - size: 43 20 - anchors.right: parent.right - anchors.bottom: parent.bottom - margin: 13 10 - diff --git a/src/framework/const.h b/src/framework/const.h index b5b21713..0ad86b6d 100644 --- a/src/framework/const.h +++ b/src/framework/const.h @@ -1,6 +1,8 @@ #ifndef CONST_H #define CONST_H +//namespace Fw { + enum AlignmentFlag { AlignLeft = 1, AlignRight = 2, @@ -19,4 +21,42 @@ enum AlignmentFlag { AlignCenter = AlignVerticalCenter | AlignHorizontalCenter }; -#endif // CONST_H +enum AnchorPoint { + AnchorNone = 0, + AnchorTop, + AnchorBottom, + AnchorLeft, + AnchorRight, + AnchorVerticalCenter, + AnchorHorizontalCenter, +}; + +enum MouseButton { + MouseNoButton = 0, + MouseLeftButton, + MouseRightButton, + MouseMidButton +}; + +enum MouseWheelDirection { + MouseNoWheel = 0, + MouseWheelUp, + MouseWheelDown +}; + +enum KeyboardModifier { + KeyboardNoModifier = 0, + KeyboardCtrlModifier = 1, + KeyboardAltModifier = 2, + KeyboardShiftModifier = 4 +}; + +enum ButtonState { + ButtonUp = 0, + ButtonDown, + ButtonHover +}; + +//} + +#endif diff --git a/src/framework/core/configmanager.cpp b/src/framework/core/configmanager.cpp new file mode 100644 index 00000000..6e792d2a --- /dev/null +++ b/src/framework/core/configmanager.cpp @@ -0,0 +1,35 @@ +#include "configmanager.h" +#include "resourcemanager.h" + +#include + +ConfigManager g_configs; + +bool ConfigManager::load(const std::string& fileName) +{ + m_fileName = fileName; + + if(!g_resources.fileExists(fileName)) + return false; + + try { + OTMLDocumentPtr doc = OTMLDocument::parse(fileName); + for(const OTMLNodePtr& child : doc->childNodes()) + m_confsMap[child->tag()] = child->value(); + } catch(std::exception& e) { + logError("ERROR: could not load configurations: ", e.what()); + return false; + } + + return true; +} + +bool ConfigManager::save() +{ + if(!m_fileName.empty()) { + OTMLDocumentPtr doc = OTMLDocument::create(); + doc->write(m_confsMap); + return doc->save(m_fileName); + } + return false; +} diff --git a/src/framework/core/configs.h b/src/framework/core/configmanager.h similarity index 50% rename from src/framework/core/configs.h rename to src/framework/core/configmanager.h index 49262a5c..89d78ed4 100644 --- a/src/framework/core/configs.h +++ b/src/framework/core/configmanager.h @@ -1,25 +1,25 @@ -#ifndef CONFIGS_H -#define CONFIGS_H +#ifndef CONFIGMANAGER_H +#define CONFIGMANAGER_H #include struct ConfigValueProxy { ConfigValueProxy(const std::string& v) : value(v) { } - operator std::string() const { return convert(value); } - operator float() const { return convert(value); } - operator int() const { return convert(value); } - operator bool() const { return convert(value); } + operator std::string() const { return aux::unsafe_cast(value); } + operator float() const { return aux::unsafe_cast(value); } + operator int() const { return aux::unsafe_cast(value); } + operator bool() const { return aux::unsafe_cast(value); } std::string value; }; -class Configs +class ConfigManager { public: bool load(const std::string& fileName); - void save(); + bool save(); template - void set(const std::string& key, const T& value) { m_confsMap[key] = convert(value); } + void set(const std::string& key, const T& value) { m_confsMap[key] = aux::unsafe_cast(value); } ConfigValueProxy get(const std::string& key) { return ConfigValueProxy(m_confsMap[key]); } @@ -28,6 +28,6 @@ private: std::map m_confsMap; }; -extern Configs g_configs; +extern ConfigManager g_configs; -#endif // CONFIGS_H +#endif diff --git a/src/framework/core/configs.cpp b/src/framework/core/configs.cpp deleted file mode 100644 index 2c929042..00000000 --- a/src/framework/core/configs.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include "configs.h" -#include "resources.h" - -#include - -Configs g_configs; - -bool Configs::load(const std::string& fileName) -{ - m_fileName = fileName; - - if(!g_resources.fileExists(fileName)) - return false; - - std::stringstream fin; - if(!g_resources.loadFile(fileName, fin)) - return false; - - try { - OTMLParser parser(fin, fileName); - parser.getDocument()->read(&m_confsMap); - } catch(OTMLException e) { - logError("ERROR: Malformed config file: ", e.what()); - return false; - } - - return true; -} - -void Configs::save() -{ - if(!m_fileName.empty()) { - OTMLEmitter emitter; - emitter.createDocument()->write(m_confsMap); - g_resources.saveFile(m_fileName, emitter.emitDocument()); - } -} diff --git a/src/framework/core/dispatcher.cpp b/src/framework/core/dispatcher.cpp deleted file mode 100644 index a7c5e6b6..00000000 --- a/src/framework/core/dispatcher.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include "dispatcher.h" -#include "engine.h" - -Dispatcher g_dispatcher; - -void Dispatcher::cleanup() -{ - while(!m_scheduledTaskList.empty()) { - ScheduledTask *task = m_scheduledTaskList.top(); - m_scheduledTaskList.pop(); - delete task; - } -} - -void Dispatcher::poll() -{ - while(!m_taskList.empty()) { - m_taskList.front()(); - m_taskList.pop_front(); - } - - while(!m_scheduledTaskList.empty()) { - ScheduledTask *task = m_scheduledTaskList.top(); - if(g_engine.getCurrentFrameTicks() < task->ticks) - break; - m_scheduledTaskList.pop(); - task->callback(); - delete task; - } -} - -void Dispatcher::scheduleTask(const std::function& callback, int delay) -{ - m_scheduledTaskList.push(new ScheduledTask(g_engine.getCurrentFrameTicks() + delay, callback)); -} - -void Dispatcher::addTask(const std::function& callback, bool pushFront) -{ - if(pushFront) - m_taskList.push_front(callback); - else - m_taskList.push_back(callback); -} diff --git a/src/framework/core/dispatcher.h b/src/framework/core/dispatcher.h deleted file mode 100644 index 5617465d..00000000 --- a/src/framework/core/dispatcher.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef DISPATCHER_H -#define DISPATCHER_H - -#include -#include - -struct ScheduledTask { - ScheduledTask(const std::function& _callback) : ticks(0), callback(_callback) { } - ScheduledTask(int _ticks, const std::function& _callback) : ticks(_ticks), callback(_callback) { } - bool operator<(const ScheduledTask& other) const { return ticks > other.ticks; } - int ticks; - std::function callback; -}; - -struct lessScheduledTask : public std::binary_function { - bool operator()(ScheduledTask*& t1,ScheduledTask*& t2) { return (*t1) < (*t2); } -}; - -class Dispatcher -{ -public: - Dispatcher() { } - - /// Cleanup scheduled events - void cleanup(); - - /// Execute scheduled events - void poll(); - - /// Add an event - void addTask(const std::function& callback, bool pushFront = false); - - /// Schedula an event - void scheduleTask(const std::function& callback, int delay); - -private: - std::list> m_taskList; - std::priority_queue, lessScheduledTask> m_scheduledTaskList; -}; - -extern Dispatcher g_dispatcher; - -#endif // DISPATCHER_H diff --git a/src/framework/core/engine.cpp b/src/framework/core/engine.cpp deleted file mode 100644 index 115086d8..00000000 --- a/src/framework/core/engine.cpp +++ /dev/null @@ -1,155 +0,0 @@ -#include "engine.h" -#include "platform.h" -#include "dispatcher.h" -#include -#include -#include -#include -#include -#include