diff --git a/sources.cmake b/sources.cmake index 2acf0d601..4a2f26fff 100644 --- a/sources.cmake +++ b/sources.cmake @@ -51,6 +51,7 @@ src/graphics/stars.cpp src/guiengine/abstract_state_manager.cpp src/guiengine/abstract_top_level_container.cpp src/guiengine/CGUISpriteBank.cpp +src/guiengine/dialog_queue.cpp src/guiengine/engine.cpp src/guiengine/event_handler.cpp src/guiengine/layout_manager.cpp @@ -347,6 +348,7 @@ src/graphics/slip_stream.hpp src/graphics/stars.hpp src/guiengine/abstract_state_manager.hpp src/guiengine/abstract_top_level_container.hpp +src/guiengine/dialog_queue.hpp src/guiengine/engine.hpp src/guiengine/event_handler.hpp src/guiengine/layout_manager.hpp diff --git a/src/guiengine/dialog_queue.cpp b/src/guiengine/dialog_queue.cpp new file mode 100644 index 000000000..89b5c8979 --- /dev/null +++ b/src/guiengine/dialog_queue.cpp @@ -0,0 +1,74 @@ +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2013 Glenn De Jonghe +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include "guiengine/dialog_queue.hpp" +#include "assert.h" + +using namespace GUIEngine; + +namespace GUIEngine +{ + static DialogQueue* dialog_queue_singleton(NULL); + + DialogQueue* DialogQueue::get() + { + if (dialog_queue_singleton == NULL) + dialog_queue_singleton = new DialogQueue(); + return dialog_queue_singleton; + } + + void DialogQueue::deallocate() + { + delete dialog_queue_singleton; + dialog_queue_singleton = NULL; + } // deallocate + + + // ---------------------------------------------------------------------------- + + DialogQueue::DialogQueue() + { + } + + // ---------------------------------------------------------------------------- + + void DialogQueue::pushDialog(ModalDialog * dialog, bool closes_any_dialog) + { + assert(!dialog->isInited()); + m_queue.push( new Entry(dialog, closes_any_dialog)); } + } + + // ---------------------------------------------------------------------------- + + void DialogQueue::update() + { + + if(!m_queue.empty()) + { + Entry * entry = m_queue.front(); + if(entry->closes() || !ModalDialog::isADialogActive()) + { + ModalDialog::dismiss(); + entry->get()->doInit(); + m_queue.pop(); + delete entry; + } + } + + +} + diff --git a/src/guiengine/dialog_queue.hpp b/src/guiengine/dialog_queue.hpp new file mode 100644 index 000000000..08c3c87f4 --- /dev/null +++ b/src/guiengine/dialog_queue.hpp @@ -0,0 +1,55 @@ +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2013 Glenn De Jonghe +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#ifndef HEADER_DIALOG_QUEUE_HPP +#define HEADER_DIALOG_QUEUE_HPP + +#include +#include "guiengine/modaldialog.hpp" + +/** + * \ingroup guiengine + */ +namespace GUIEngine +{ + + class DialogQueue + { + private : + + class Entry + { + ModalDialog * m_dialog; + bool m_closes_any_dialog; + public : + Entry(ModalDialog * dialog, bool closes_any_dialog) : m_dialog(dialog), m_closes_any_dialog(closes_any_dialog) {} + bool closes() { return m_closes_any_dialog; } + ModalDialog* get() { return m_dialog; } + }; + std::queue m_queue; + DialogQueue(); + public : + /**Singleton */ + static DialogQueue * get(); + static void deallocate(); + void pushDialog(ModalDialog * dialog, bool closes_any_dialog); + void update(); + + }; + +} +#endif diff --git a/src/guiengine/engine.cpp b/src/guiengine/engine.cpp index 83235ad63..826d127f6 100644 --- a/src/guiengine/engine.cpp +++ b/src/guiengine/engine.cpp @@ -657,6 +657,7 @@ namespace GUIEngine #include "guiengine/screen.hpp" #include "guiengine/skin.hpp" #include "guiengine/widget.hpp" +#include "guiengine/dialog_queue.hpp" #include "modes/demo_world.hpp" #include "modes/world.hpp" #include "states_screens/race_gui_base.hpp" @@ -835,6 +836,7 @@ namespace GUIEngine { widget->update(dt); } + DialogQueue::get()->update(); } } diff --git a/src/guiengine/modaldialog.cpp b/src/guiengine/modaldialog.cpp index 35dc19fbe..8f9b98b04 100644 --- a/src/guiengine/modaldialog.cpp +++ b/src/guiengine/modaldialog.cpp @@ -47,11 +47,12 @@ using namespace GUIEngine; // ---------------------------------------------------------------------------- -ModalDialog::ModalDialog(const float percentWidth, const float percentHeight, - ModalDialogLocation location) +ModalDialog::ModalDialog(const float percentWidth, const float percentHeight, bool do_init, ModalDialogLocation location) { m_dialog_location = location; - doInit(percentWidth, percentHeight); + m_init = false; + if(do_init) + doInit(); } // ---------------------------------------------------------------------------- @@ -82,15 +83,16 @@ void ModalDialog::loadFromFile(const char* xmlFile) // ---------------------------------------------------------------------------- -void ModalDialog::doInit(const float percentWidth, const float percentHeight) +void ModalDialog::doInit() { + m_init = true; pointer_was_shown = irr_driver->isPointerShown(); irr_driver->showPointer(); const core::dimension2d& frame_size = GUIEngine::getDriver()->getCurrentRenderTargetSize(); - const int w = (int)(frame_size.Width*percentWidth); - const int h = (int)(frame_size.Height*percentHeight); + const int w = (int)(frame_size.Width* m_percent_width); + const int h = (int)(frame_size.Height* m_percent_height); assert(frame_size.Width > 0); assert(frame_size.Height > 0); diff --git a/src/guiengine/modaldialog.hpp b/src/guiengine/modaldialog.hpp index dfdf3fd8e..47c628ce8 100644 --- a/src/guiengine/modaldialog.hpp +++ b/src/guiengine/modaldialog.hpp @@ -55,11 +55,12 @@ namespace GUIEngine class ModalDialog : public SkinWidgetContainer, public AbstractTopLevelContainer { private: - /** Because C++ doesn't support constructor delegation... */ - void doInit(const float percentWidth, const float percentHeight); ModalDialogLocation m_dialog_location; + float m_percent_width, m_percent_height; + bool m_init; + protected: irr::gui::IGUIWindow* m_irrlicht_window; @@ -70,7 +71,7 @@ namespace GUIEngine /** * \brief Creates a modal dialog with given percentage of screen width and height */ - ModalDialog(const float percentWidth, const float percentHeight, + ModalDialog(const float percentWidth, const float percentHeight, bool do_init = true, ModalDialogLocation location = MODAL_DIALOG_LOCATION_CENTER); /** \brief Load a XML file to create the dialog from @@ -89,6 +90,10 @@ namespace GUIEngine public: LEAK_CHECK() + /** Because C++ doesn't support constructor delegation... */ + void doInit(); + bool isInited() {return m_init;} + virtual ~ModalDialog(); /** Returns whether to block event propagation (usually, you will want to block events you processed) */