From 32a8ed3871b1c637507906cffa412ae4c40e6be8 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Sun, 1 May 2011 15:47:35 -0300 Subject: [PATCH] scripting and UI improvements --- CMakeLists.txt | 2 +- data/modules/mainmenu/entergamewindow.yml | 13 +- data/modules/mainmenu/infowindow.yml | 16 +- data/modules/mainmenu/mainmenu.yml | 12 +- data/modules/mainmenu/menustate.lua | 6 +- data/modules/mainmenu/optionswindow.yml | 20 +- data/modules/messagebox/messagebox.lua | 14 +- data/modules/messagebox/messagebox.yml | 2 +- data/skins/tibiaskin.yml | 11 +- src/framework/core/engine.cpp | 17 +- src/framework/graphics/graphics.cpp | 2 +- src/framework/prerequisites.h | 1 + src/framework/script/luafunctions.cpp | 265 +++++++++++++--------- src/framework/script/luafunctions.h | 62 +++++ src/framework/script/luascript.cpp | 30 ++- src/framework/script/luascript.h | 26 +-- src/framework/ui/uicontainer.cpp | 148 ++++++------ src/framework/ui/uicontainer.h | 5 +- src/framework/ui/uielement.cpp | 30 ++- src/framework/ui/uielement.h | 7 +- src/framework/ui/uiloader.cpp | 9 +- src/framework/ui/uiloader.h | 2 +- src/main.cpp | 11 +- 23 files changed, 421 insertions(+), 290 deletions(-) create mode 100644 src/framework/script/luafunctions.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b3cb730..5098d910 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}") # find needed packages SET(Boost_USE_STATIC_LIBS ON) -SET(Boost_USE_MULTITHREADED ON) +SET(Boost_USE_MULTITHREADED OFF) FIND_PACKAGE(Boost COMPONENTS system signals REQUIRED) FIND_PACKAGE(OpenGL REQUIRED) FIND_PACKAGE(Lua51 REQUIRED) diff --git a/data/modules/mainmenu/entergamewindow.yml b/data/modules/mainmenu/entergamewindow.yml index 0f068884..57ab400d 100644 --- a/data/modules/mainmenu/entergamewindow.yml +++ b/data/modules/mainmenu/entergamewindow.yml @@ -4,22 +4,22 @@ window#enterGameWindow: anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter onLoad: self:getParent():lock(self) - onDestroy: self:getParent():unlock() - + onDestroy: self:getParent():unlock(self) + label#accountNameLabel: text: Account name anchors.left: parent.left anchors.top: parent.top margin.left: 18 margin.top: 33 - + label#passwordLabel: text: "Password:" anchors.left: parent.left anchors.top: parent.top margin.left: 18 margin.top: 62 - + label#createAccountLabel: text: | If you don't have @@ -35,6 +35,7 @@ window#enterGameWindow: anchors.top: parent.top margin.top: 94 margin.left: 132 + onClick: messageBox("Error", "Not implemented yet") button#okButton: text: Ok @@ -52,7 +53,7 @@ window#enterGameWindow: margin.bottom: 10 margin.right: 13 onClick: self:getParent():destroy() - + textEdit#accountNameTextEdit: anchors.right: parent.right anchors.top: parent.top @@ -63,4 +64,4 @@ window#enterGameWindow: anchors.right: parent.right anchors.top: parent.top margin.top: 61 - margin.right: 18 \ No newline at end of file + margin.right: 18 diff --git a/data/modules/mainmenu/infowindow.yml b/data/modules/mainmenu/infowindow.yml index fc93346c..b1ecd471 100644 --- a/data/modules/mainmenu/infowindow.yml +++ b/data/modules/mainmenu/infowindow.yml @@ -4,8 +4,8 @@ window#infoWindow: anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter onLoad: self:getParent():lock(self) - onDestroy: self:getParent():unlock() - + onDestroy: self:getParent():unlock(self) + panel#infoPanel: skin: flatPanel size: [208, 129] @@ -13,7 +13,7 @@ window#infoWindow: anchors.top: parent.top margin.top: 32 margin.left: 18 - + label#infoLabel: align: center text: |- @@ -30,21 +30,21 @@ window#infoWindow: anchors.top: parent.top margin.top: 83 margin.left: 9 - + label#websiteLabel: text: Official Website anchors.left: parent.left anchors.bottom: parent.bottom margin.bottom: 14 margin.left: 9 - + button#websiteButton: text: Github Page anchors.right: parent.right anchors.bottom: parent.bottom margin.bottom: 9 margin.right: 9 - + lineDecoration#bottomSeparator: anchors.left: parent.left anchors.right: parent.right @@ -52,7 +52,7 @@ window#infoWindow: margin.bottom: 40 margin.left: 13 margin.right: 13 - + button#okButton: text: Ok size: [43, 20] @@ -60,4 +60,4 @@ window#infoWindow: anchors.top: parent.top margin.top: 191 margin.left: 188 - onClick: self:getParent():destroy() \ No newline at end of file + onClick: self:getParent():destroy() diff --git a/data/modules/mainmenu/mainmenu.yml b/data/modules/mainmenu/mainmenu.yml index ea230339..1b568c51 100644 --- a/data/modules/mainmenu/mainmenu.yml +++ b/data/modules/mainmenu/mainmenu.yml @@ -7,7 +7,7 @@ panel#background: anchors.right: parent.right anchors.top: parent.top anchors.bottom: parent.bottom - + panel#mainMenu: skin: roundedGridPanel size: [117, 171] @@ -15,13 +15,13 @@ panel#background: anchors.bottom: parent.bottom margin.left: 60 margin.bottom: 70 - + button#enterGameButton: text: Enter Game anchors.top: parent.top anchors.horizontalCenter: parent.horizontalCenter margin.top: 16 - onClick: loadUI("modules/mainmenu/entergamewindow.yml") + onClick: UI.load("modules/mainmenu/entergamewindow.yml") button#accessAccountButton: text: Access Account @@ -35,18 +35,18 @@ panel#background: anchors.top: parent.top anchors.horizontalCenter: parent.horizontalCenter margin.top: 76 - onClick: loadUI("modules/mainmenu/optionswindow.yml") + onClick: UI.load("modules/mainmenu/optionswindow.yml") button#infoButton: text: Info anchors.top: parent.top anchors.horizontalCenter: parent.horizontalCenter margin.top: 106 - onClick: loadUI("modules/mainmenu/infowindow.yml") + onClick: UI.load("modules/mainmenu/infowindow.yml") button#exitGameButton: text: Exit anchors.top: parent.top anchors.horizontalCenter: parent.horizontalCenter margin.top: 136 - onClick: exitGame() \ No newline at end of file + onClick: App.exit() diff --git a/data/modules/mainmenu/menustate.lua b/data/modules/mainmenu/menustate.lua index de0ddd6d..061bd831 100644 --- a/data/modules/mainmenu/menustate.lua +++ b/data/modules/mainmenu/menustate.lua @@ -1,6 +1,6 @@ -- menu state function onEnterMenuState() - mainMenu = loadUI("modules/mainmenu/mainmenu.yml") + mainMenu = UI.load("modules/mainmenu/mainmenu.yml") end function onLeaveMenuState() @@ -15,6 +15,6 @@ end -- here is where everything starts if not initialStateLoaded then onEnterMenuState() - setOnApplicationClose(onApplicationClose) + App.setOnClose(onApplicationClose) initialStateLoaded = true -end \ No newline at end of file +end diff --git a/data/modules/mainmenu/optionswindow.yml b/data/modules/mainmenu/optionswindow.yml index a807abe1..45aa789b 100644 --- a/data/modules/mainmenu/optionswindow.yml +++ b/data/modules/mainmenu/optionswindow.yml @@ -4,8 +4,8 @@ window#optionsWindow: anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter onLoad: self:getParent():lock(self) - onDestroy: self:getParent():unlock() - + onDestroy: self:getParent():unlock(self) + # general button#generalButton: text: General @@ -22,7 +22,7 @@ window#optionsWindow: anchors.top: parent.top margin.left: 117 margin.top: 29 - + # graphics button#graphicsButton: text: Graphics @@ -39,7 +39,7 @@ window#optionsWindow: anchors.top: parent.top margin.left: 117 margin.top: 62 - + # console button#consoleButton: text: Console @@ -54,7 +54,7 @@ window#optionsWindow: anchors.top: parent.top margin.left: 117 margin.top: 95 - + # hotkeys button#hotkeysButton: text: Hotkeys @@ -69,7 +69,7 @@ window#optionsWindow: anchors.top: parent.top margin.left: 117 margin.top: 128 - + lineDecoration#middleSeparator: anchors.left: parent.left anchors.right: parent.right @@ -77,7 +77,7 @@ window#optionsWindow: margin.bottom: 97 margin.left: 18 margin.right: 18 - + # motd button#motdButton: text: Motd @@ -94,7 +94,7 @@ window#optionsWindow: anchors.bottom: parent.bottom margin.left: 117 margin.bottom: 56 - + lineDecoration#bottomSeparator: anchors.left: parent.left anchors.right: parent.right @@ -102,7 +102,7 @@ window#optionsWindow: margin.bottom: 40 margin.left: 13 margin.right: 13 - + # ok button button#okButton: text: Ok @@ -111,4 +111,4 @@ window#optionsWindow: anchors.bottom: parent.bottom margin.right: 10 margin.bottom: 13 - onClick: self:getParent():destroy() \ No newline at end of file + onClick: self:getParent():destroy() diff --git a/data/modules/messagebox/messagebox.lua b/data/modules/messagebox/messagebox.lua index a8e48ce1..a4a3ee7c 100644 --- a/data/modules/messagebox/messagebox.lua +++ b/data/modules/messagebox/messagebox.lua @@ -1,12 +1,12 @@ function messageBox(title, text) - local messageBoxWindow = loadUI("modules/messagebox/messagebox.yml") + local messageBoxWindow = UI.load("modules/messagebox/messagebox.yml") local messageBoxLabel = messageBoxWindow:getChildByID("messageBoxLabel") local messageBoxOkButton = messageBoxWindow:getChildByID("messageBoxOkButton") - local uiRoot = messageBoxWindow:getParent() - uiRoot:lock(messageBox) - messageBoxWindow:setTitle(text) + local uiRoot = UI.getRootContainer() + uiRoot:lock(messageBoxWindow) + messageBoxWindow:setTitle(title) messageBoxLabel:setText(text) - messageBoxWindow:setSize(messageBoxLabel:getSize() + Size{20, 20}) - messageBox:setOnDestroy(function() uiRoot:unlock() end) + --messageBoxWindow:setSize(messageBoxLabel:getSize() + Size{20, 20}) + messageBoxWindow:setOnDestroy(function() uiRoot:unlock(self) end) messageBoxOkButton:setOnClick(function() messageBoxWindow:destroy() end) -end \ No newline at end of file +end diff --git a/data/modules/messagebox/messagebox.yml b/data/modules/messagebox/messagebox.yml index 072a402f..dc8776b0 100644 --- a/data/modules/messagebox/messagebox.yml +++ b/data/modules/messagebox/messagebox.yml @@ -3,7 +3,7 @@ window#messageBoxWindow: anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter - + label#messageBoxLabel: anchors.horizontalCenter: parent.horizontalCenter anchors.top: parent.top diff --git a/data/skins/tibiaskin.yml b/data/skins/tibiaskin.yml index ccfa41a8..f95511e3 100644 --- a/data/skins/tibiaskin.yml +++ b/data/skins/tibiaskin.yml @@ -16,7 +16,7 @@ buttons: bottom left corner: [45,157,1,1] bottom right corner: [130,157,1,1] center: [46,139,84,18] - + down state: text translate: [1, 1] bordered image: @@ -45,7 +45,7 @@ panels: bottom left corner: [43,230,5,5] bottom right corner: [48,231,5,5] center: [11,214,32,32] - + flatPanel: bordered image: left border: [275,0,1,96] @@ -57,7 +57,7 @@ panels: bottom left corner: [2,210,1,1] bottom right corner: [276,95,1,1] center: [0, 0, 96, 96] - + labels: default: font: tibia-10px-antialised @@ -87,7 +87,7 @@ windows: bottom left corner: [98,193,4,4] bottom right corner: [102,193,4,4] center: [0, 0, 96, 96] - + text edits: default: default size: [86, 16] @@ -103,9 +103,8 @@ text edits: bottom left corner: [308,107,1,1] bottom right corner: [319,107,1,1] center: [309,97,10,10] - + line decorations: default: bordered image: top border: [2,210,96,2] - \ No newline at end of file diff --git a/src/framework/core/engine.cpp b/src/framework/core/engine.cpp index 0fdc7c03..0befc46d 100644 --- a/src/framework/core/engine.cpp +++ b/src/framework/core/engine.cpp @@ -61,6 +61,11 @@ void Engine::poll() void Engine::run() { + // check if root container has elements + const UIContainerPtr& rootContainer = UIContainer::getRoot(); + if(rootContainer->getChildCount() == 0) + logFatal("FATAL ERROR: no ui loaded at all, no reason to continue running"); + std::string fpsText; Size fpsTextSize; Font *defaultFont = g_fonts.getDefaultFont(); @@ -95,7 +100,7 @@ void Engine::run() // render g_graphics.beginRender(); - UIContainer::getRootContainer()->render(); + rootContainer->render(); // render fps if(m_calculateFps) @@ -110,6 +115,12 @@ void Engine::run() m_stopping = false; m_running = false; + + // destroy root ui + rootContainer->destroy(); + + // poll remaning ui events + g_engine.poll(); } void Engine::stop() @@ -126,10 +137,10 @@ void Engine::onClose() void Engine::onResize(const Size& size) { g_graphics.resize(size); - UIContainer::getRootContainer()->setSize(size); + UIContainer::getRoot()->setSize(size); } void Engine::onInputEvent(const InputEvent& event) { - UIContainer::getRootContainer()->onInputEvent(event); + UIContainer::getRoot()->onInputEvent(event); } diff --git a/src/framework/graphics/graphics.cpp b/src/framework/graphics/graphics.cpp index bf066c6b..eb374de3 100644 --- a/src/framework/graphics/graphics.cpp +++ b/src/framework/graphics/graphics.cpp @@ -49,7 +49,7 @@ void Graphics::init() void Graphics::terminate() { - m_bindedTexture = TexturePtr(); + m_bindedTexture.reset(); } bool Graphics::isExtensionSupported(const char *extension) diff --git a/src/framework/prerequisites.h b/src/framework/prerequisites.h index 738e5042..a260822d 100644 --- a/src/framework/prerequisites.h +++ b/src/framework/prerequisites.h @@ -59,6 +59,7 @@ typedef int8_t int8; #include #include #include +#include // boost utilities #include diff --git a/src/framework/script/luafunctions.cpp b/src/framework/script/luafunctions.cpp index 34b12ab9..773a9c42 100644 --- a/src/framework/script/luafunctions.cpp +++ b/src/framework/script/luafunctions.cpp @@ -23,182 +23,237 @@ #include +#include