SuperTuxKart
message_dialog.hpp
1 // SuperTuxKart - a fun racing game with go-kart
2 // Copyright (C) 2010-2015 Marianne Gagnon
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 3
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 
18 
19 #ifndef HEADER_CONFIRM_DIALOG_HPP
20 #define HEADER_CONFIRM_DIALOG_HPP
21 
22 #include "guiengine/modaldialog.hpp"
23 #include "utils/cpp2011.hpp"
24 #include "utils/leak_check.hpp"
25 
31 {
32 public:
33 
39  {
40  public:
41 
42  LEAK_CHECK()
43 
45  virtual ~IConfirmDialogListener() {}
46 
51  virtual void onConfirm() { ModalDialog::dismiss(); };
52 
57  virtual void onCancel() { ModalDialog::dismiss(); };
58 
62  virtual void onDialogUpdate(float dt) {}
63  };
64 
65  enum MessageDialogType { MESSAGE_DIALOG_OK, MESSAGE_DIALOG_CONFIRM,
66  MESSAGE_DIALOG_OK_CANCEL, MESSAGE_DIALOG_YESNO };
67 
68  MessageDialogType m_type;
69 
70 private:
71 
72  IConfirmDialogListener* m_listener;
73  bool m_own_listener;
74  irr::core::stringw m_msg;
75  void doInit(bool from_queue);
76 
80 
81 public:
82 
89  MessageDialog(const irr::core::stringw &msg, MessageDialogType type,
90  IConfirmDialogListener* listener, bool delete_listener,
91  bool from_queue = false, float width = 0.6f, float height = 0.6f);
92 
97  MessageDialog(const irr::core::stringw &msg, bool from_queue = false);
98 
99  ~MessageDialog();
100 
101  virtual void onEnterPressedInternal() OVERRIDE;
102  virtual void onUpdate(float dt) OVERRIDE;
103  virtual void load() OVERRIDE;
104 
105  GUIEngine::EventPropagation processEvent(const std::string& eventSource) OVERRIDE;
106 
107  virtual void loadedFromFile() OVERRIDE;
108 
112 };
113 
114 
115 #endif
Generic dialog to ask the user to confirm something, or to show a simple message box.
Definition: message_dialog.hpp:30
Contains all GUI engine related classes and functions.
Definition: abstract_state_manager.hpp:31
virtual void onUpdate(float dt) OVERRIDE
Override to be notified of updates.
Definition: message_dialog.cpp:190
virtual void onCancel()
Implement to be notified of dialog cancelled.
Definition: message_dialog.hpp:57
void setFocusCancel()
Calling this will make sure that the focus is set on the 'cancel' or 'no'.
Definition: message_dialog.hpp:111
void doInit(bool from_queue)
If necessary schedules a pause, and loads the xml file if necessary.
Definition: message_dialog.cpp:85
virtual void loadedFromFile() OVERRIDE
Callback invoked when the dialog was loaded from the XML file (if the constructor that takes a XML fi...
Definition: message_dialog.cpp:110
virtual void onDialogUpdate(float dt)
Optional callback.
Definition: message_dialog.hpp:62
GUIEngine::EventPropagation processEvent(const std::string &eventSource) OVERRIDE
Returns whether to block event propagation (usually, you will want to block events you processed)
Definition: message_dialog.cpp:154
virtual void load() OVERRIDE
Called from the DialogQueue, used to load the actual xml file and init the dialog.
Definition: message_dialog.cpp:75
virtual void onConfirm()
Implement to be notified of dialog confirmed.
Definition: message_dialog.hpp:51
MessageDialog(const irr::core::stringw &msg, MessageDialogType type, IConfirmDialogListener *listener, bool delete_listener, bool from_queue=false, float width=0.6f, float height=0.6f)
Complete constructor, which allows setting of listener, type etc.
Definition: message_dialog.cpp:39
bool m_focus_on_cancel
If set this will set the focus on 'cancel'/'no' instead of "yes"/"ok".
Definition: message_dialog.hpp:79
Listener interface to get notified of whether the user chose to confirm or cancel.
Definition: message_dialog.hpp:38
Abstract base class representing a modal dialog.
Definition: modaldialog.hpp:55