diff --git a/data/modules/mainmenu/entergamewindow.yml b/data/modules/mainmenu/entergamewindow.yml index 5e3d7abd..708b3cbc 100644 --- a/data/modules/mainmenu/entergamewindow.yml +++ b/data/modules/mainmenu/entergamewindow.yml @@ -3,6 +3,8 @@ window#enterGameWindow: size: [236, 178] anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter + onLoad: mainMenu:lock(self) + onDestroy: mainMenu:unlock() label#accountNameLabel: text: Account name @@ -49,9 +51,7 @@ window#enterGameWindow: anchors.bottom: parent.bottom margin.bottom: 10 margin.right: 13 - onClick: | - self:getParent():destroy() - self:getParent():getParent():unlock() + onClick: self:getParent():destroy() textEdit#accountNameTextEdit: anchors.right: parent.right diff --git a/data/modules/mainmenu/infowindow.yml b/data/modules/mainmenu/infowindow.yml index de909b93..1c05ac40 100644 --- a/data/modules/mainmenu/infowindow.yml +++ b/data/modules/mainmenu/infowindow.yml @@ -3,6 +3,8 @@ window#infoWindow: size: [244, 221] anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter + onLoad: mainMenu:lock(self) + onDestroy: mainMenu:unlock() panel#infoPanel: skin: flatPanel @@ -57,6 +59,4 @@ window#infoWindow: anchors.left: parent.left anchors.top: parent.top margin.top: 191 - margin.left: 188 - onClick: | - self:getParent():destroy() \ No newline at end of file + margin.left: 188 \ No newline at end of file diff --git a/data/modules/mainmenu/mainmenu.lua b/data/modules/mainmenu/mainmenu.lua deleted file mode 100644 index d1355ffa..00000000 --- a/data/modules/mainmenu/mainmenu.lua +++ /dev/null @@ -1,25 +0,0 @@ --- main menu methods -function MainMenu_create() - mainMenu = loadUI("modules/mainmenu/mainmenu.yml") -end - -function MainMenu_destroy() - mainMenu:destroy() -end - -function MainMenu_enterGameClicked() - enterGameWindow = loadUI("modules/mainmenu/entergamewindow.yml") - button = enterGameWindow:getChildByID("okButton") -end - -function MainMenu_optionsClicked() - optionsWindow = loadUI("modules/mainmenu/optionswindow.yml") -end - -function MainMenu_infoClicked() - infoWindow = loadUI("modules/mainmenu/infowindow.yml") -end - -function MainMenu_exitClicked() - onApplicationClose() -end diff --git a/data/modules/mainmenu/mainmenu.yml b/data/modules/mainmenu/mainmenu.yml index 6ee69152..cc651ea3 100644 --- a/data/modules/mainmenu/mainmenu.yml +++ b/data/modules/mainmenu/mainmenu.yml @@ -21,7 +21,7 @@ panel#background: anchors.top: parent.top anchors.horizontalCenter: parent.horizontalCenter margin.top: 16 - onClick: MainMenu_enterGameClicked() + onClick: loadUI("modules/mainmenu/entergamewindow.yml") button#accessAccountButton: text: Access Account @@ -34,18 +34,18 @@ panel#background: anchors.top: parent.top anchors.horizontalCenter: parent.horizontalCenter margin.top: 76 - onClick: MainMenu_optionsClicked() + onClick: loadUI("modules/mainmenu/optionswindow.yml") button#infoButton: text: Info anchors.top: parent.top anchors.horizontalCenter: parent.horizontalCenter margin.top: 106 - onClick: MainMenu_infoClicked() + onClick: loadUI("modules/mainmenu/infowindow.yml") button#exitGameButton: text: Exit anchors.top: parent.top anchors.horizontalCenter: parent.horizontalCenter margin.top: 136 - onClick: MainMenu_exitClicked() \ No newline at end of file + onClick: exitGame() \ No newline at end of file diff --git a/data/modules/mainmenu/menustate.lua b/data/modules/mainmenu/menustate.lua index 7def30b1..de0ddd6d 100644 --- a/data/modules/mainmenu/menustate.lua +++ b/data/modules/mainmenu/menustate.lua @@ -1,10 +1,10 @@ -- menu state function onEnterMenuState() - MainMenu_create() + mainMenu = loadUI("modules/mainmenu/mainmenu.yml") end function onLeaveMenuState() - MainMenu_destroy() + mainMenu:destroy() end function onApplicationClose() diff --git a/data/modules/mainmenu/optionswindow.yml b/data/modules/mainmenu/optionswindow.yml index acc0327c..c3d40945 100644 --- a/data/modules/mainmenu/optionswindow.yml +++ b/data/modules/mainmenu/optionswindow.yml @@ -3,6 +3,8 @@ window#optionsWindow: size: [286, 262] anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter + onLoad: mainMenu:lock(self) + onDestroy: mainMenu:unlock() # general button#generalButton: @@ -109,5 +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() \ No newline at end of file diff --git a/src/framework/platform/win32platform.cpp b/src/framework/platform/win32platform.cpp index 4e438523..2bfaf684 100644 --- a/src/framework/platform/win32platform.cpp +++ b/src/framework/platform/win32platform.cpp @@ -502,7 +502,7 @@ std::string Platform::getAppUserDir() std::stringstream sdir; sdir << PHYSFS_getUserDir() << "/." << win32.appName << "/"; if((mkdir(sdir.str().c_str()) != 0) && (errno != EEXIST)) - logError("ERROR: Couldn't create directory for saving configuration file. (%s)", sdir.str().c_str()); + flogError("ERROR: Couldn't create directory for saving configuration file. (%s)", sdir.str().c_str()); return sdir.str(); } diff --git a/src/framework/script/luascript.h b/src/framework/script/luascript.h index fe54b99e..58aa9622 100644 --- a/src/framework/script/luascript.h +++ b/src/framework/script/luascript.h @@ -85,7 +85,6 @@ public: void registerFunctions(); int lua_UIButton_setOnClick(); - int lua_UIElement_getParent(); int lua_UIElement_destroy(); diff --git a/src/framework/ui/uielement.cpp b/src/framework/ui/uielement.cpp index 659f8124..1663bca6 100644 --- a/src/framework/ui/uielement.cpp +++ b/src/framework/ui/uielement.cpp @@ -45,6 +45,7 @@ void UIElement::destroy() setVisible(false); setEnabled(false); + g_dispatcher.addTask(boost::bind(&UIContainer::removeChild, getParent(), asUIElement())); if(getParent()) { // schedule removal from parent g_dispatcher.addTask(boost::bind(&UIContainer::removeChild, getParent(), asUIElement())); diff --git a/src/framework/ui/uielement.h b/src/framework/ui/uielement.h index c752bf5f..1efcf302 100644 --- a/src/framework/ui/uielement.h +++ b/src/framework/ui/uielement.h @@ -86,6 +86,7 @@ public: virtual UIContainerPtr asUIContainer() { return UIContainerPtr(); } virtual const char *getScriptableName() const { return "UIElement"; } + void setOnDestroy( friend class UIContainer; private: diff --git a/src/main.cpp b/src/main.cpp index 6048d221..ec60e671 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -100,7 +100,7 @@ int main(int argc, const char *argv[]) if(!g_configs.load("config.yml")) logInfo("Could not read configuration file, default configurations will be used."); - logInfo("OTClient 0.1.0"); + logInfo("OTClient 0.2.0"); // create the window Platform::createWindow(g_configs.getInteger("window x"), g_configs.getInteger("window y"),