diff --git a/src/framework/ui/uielement.cpp b/src/framework/ui/uielement.cpp index afb01d57..052ee849 100644 --- a/src/framework/ui/uielement.cpp +++ b/src/framework/ui/uielement.cpp @@ -29,6 +29,7 @@ UIElement::UIElement(UI::EElementType type) : AnchorLayout(), m_type(type), + m_skin(NULL), m_visible(true), m_enabled(true) { diff --git a/src/framework/ui/uielementskin.cpp b/src/framework/ui/uielementskin.cpp index ee83b858..f5b5928b 100644 --- a/src/framework/ui/uielementskin.cpp +++ b/src/framework/ui/uielementskin.cpp @@ -76,15 +76,15 @@ ImagePtr UIElementSkin::loadImage(const YAML::Node& node) } image = ImagePtr(new BorderedImage(texture, - left, - right, - top, - bottom, - topLeft, - topRight, - bottomLeft, - bottomRight, - center)); + left, + right, + top, + bottom, + topLeft, + topRight, + bottomLeft, + bottomRight, + center)); } return image; } diff --git a/src/framework/ui/uielementskin.h b/src/framework/ui/uielementskin.h index 05b402e3..cd24f39a 100644 --- a/src/framework/ui/uielementskin.h +++ b/src/framework/ui/uielementskin.h @@ -38,6 +38,7 @@ public: UIElementSkin(const std::string& name, UI::EElementType elementType) : m_name(name), m_elementType(elementType) { } + virtual ~UIElementSkin() { } virtual void load(const YAML::Node& node); virtual void draw(UIElement *element); diff --git a/src/framework/ui/uiskins.cpp b/src/framework/ui/uiskins.cpp index 62b72b4b..ee296b0d 100644 --- a/src/framework/ui/uiskins.cpp +++ b/src/framework/ui/uiskins.cpp @@ -32,10 +32,18 @@ UISkins g_uiSkins; -UISkins::~UISkins() +void UISkins::init() +{ + // load default skin + g_uiSkins.load("skins/tibiaskin.yml"); + +} + +void UISkins::terminate() { for(auto it = m_elementSkins.begin(); it != m_elementSkins.end(); ++it) delete (*it); + m_elementSkins.clear(); } bool UISkins::load(const std::string& file) diff --git a/src/framework/ui/uiskins.h b/src/framework/ui/uiskins.h index 3d41740c..d240e133 100644 --- a/src/framework/ui/uiskins.h +++ b/src/framework/ui/uiskins.h @@ -35,7 +35,9 @@ class UISkins { public: UISkins() { } - ~UISkins(); + + void init(); + void terminate(); bool load(const std::string& file); diff --git a/src/main.cpp b/src/main.cpp index 8a383f13..0badcbe1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -109,8 +109,7 @@ int main(int argc, const char *argv[]) // init engine g_engine.init(); - // load UI skin - g_uiSkins.load("skins/tibiaskin.yml"); + g_uiSkins.init(); // state scope { @@ -129,6 +128,8 @@ int main(int argc, const char *argv[]) // terminate stuff g_engine.terminate(); + + g_uiSkins.terminate(); } // save configurations before exiting diff --git a/src/menustate.cpp b/src/menustate.cpp index 15f87328..a89373d0 100644 --- a/src/menustate.cpp +++ b/src/menustate.cpp @@ -127,6 +127,7 @@ void MenuState::createMainMenu() // login window UIWindowPtr window(new UIWindow("Enter Game")); + UIElementWeakPtr weakWindow(window); window->setSize(Size(236, 178)); window->anchorHorizontalCenter(g_ui->horizontalCenter()); window->anchorVerticalCenter(g_ui->verticalCenter()); @@ -162,7 +163,11 @@ void MenuState::createMainMenu() button->anchorRight(window->right()); button->anchorBottom(window->bottom()); button->setMargin(0, 0, 10, 66); - button->onClick([window]{ window->setVisible(false); }); + button->onClick([weakWindow]{ + UIElementPtr window = weakWindow.lock(); + if(window) + window->setVisible(false); + }); window->addChild(button); button = UIButtonPtr(new UIButton("Cancel")); @@ -170,7 +175,11 @@ void MenuState::createMainMenu() button->anchorRight(window->right()); button->anchorBottom(window->bottom()); button->setMargin(0, 0, 10, 13); - button->onClick([window]{ window->setVisible(false); }); + button->onClick([weakWindow]{ + UIElementPtr window = weakWindow.lock(); + if(window) + window->setVisible(false); + }); window->addChild(button); UITextEditPtr textEdit(new UITextEdit); @@ -185,5 +194,9 @@ void MenuState::createMainMenu() textEdit->setMargin(61, 0, 0, 18); window->addChild(textEdit); - enterGameButton->onClick([window] { window->setVisible(true); }); + enterGameButton->onClick([weakWindow]{ + UIElementPtr window = weakWindow.lock(); + if(window) + window->setVisible(true); + }); }