| 1 |
#pragma once |
| 2 |
|
| 3 |
#include "imodule.h" |
| 4 |
#include <memory> |
| 5 |
|
| 6 |
class wxWindow; |
| 7 |
|
| 8 |
namespace ui |
| 9 |
{ |
| 10 |
|
| 11 |
class IDialog |
| 12 |
{ |
| 13 |
public: |
| 14 |
virtual ~IDialog() {} |
| 15 |
|
| 16 |
enum Result |
| 17 |
{ |
| 18 |
RESULT_CANCELLED = 0, |
| 19 |
RESULT_OK, |
| 20 |
RESULT_NO, |
| 21 |
RESULT_YES, |
| 22 |
}; |
| 23 |
|
| 24 |
/// Possible message types (used for IDialogManager::createMessageBox()) |
| 25 |
enum MessageType |
| 26 |
{ |
| 27 |
/// Just a plain message with an OK button |
| 28 |
MESSAGE_CONFIRM, |
| 29 |
|
| 30 |
// Queries Yes//No from the user |
| 31 |
MESSAGE_ASK, |
| 32 |
|
| 33 |
/// Displays a warning message |
| 34 |
MESSAGE_WARNING, |
| 35 |
|
| 36 |
/// Displays an error message |
| 37 |
MESSAGE_ERROR, |
| 38 |
|
| 39 |
/// Has three options: Yes, No or Cancel |
| 40 |
MESSAGE_YESNOCANCEL, |
| 41 |
|
| 42 |
/// Save confirmation as per HIG 2.32/3.4.6.1 |
| 43 |
MESSAGE_SAVECONFIRMATION |
| 44 |
}; |
| 45 |
|
| 46 |
// Sets the dialog title |
| 47 |
virtual void setTitle(const std::string& title) = 0; |
| 48 |
|
| 49 |
// A handle to access dialog elements after addition |
| 50 |
typedef std::size_t Handle; |
| 51 |
typedef std::vector<std::string> ComboBoxOptions; |
| 52 |
|
| 53 |
// ------------------- Elements ----------------------- |
| 54 |
|
| 55 |
/** |
| 56 |
* Adds a simple label at the current position in the dialog. |
| 57 |
* A unique handle is returned to allow for later value retrieval. |
| 58 |
* The elements are inserted in the order of calls, top to bottom. |
| 59 |
* In case of errors an invalid handle (==0) is returned. |
| 60 |
*/ |
| 61 |
virtual Handle addLabel(const std::string& text) = 0; |
| 62 |
virtual Handle addComboBox(const std::string& label, const ComboBoxOptions& options) = 0; |
| 63 |
virtual Handle addEntryBox(const std::string& label) = 0; |
| 64 |
virtual Handle addPathEntry(const std::string& label, bool foldersOnly = false) = 0; |
| 65 |
virtual Handle addSpinButton(const std::string& label, double min, double max, double step, unsigned int digits) = 0; |
| 66 |
virtual Handle addCheckbox(const std::string& label) = 0; |
| 67 |
|
| 68 |
// ----------------- Element Value -------------------- |
| 69 |
|
| 70 |
// Retrieve or set an element's value by string |
| 71 |
virtual void setElementValue(const Handle& handle, const std::string& value) = 0; |
| 72 |
virtual std::string getElementValue(const Handle& handle) = 0; |
| 73 |
|
| 74 |
// ---------------------------------------------------- |
| 75 |
|
| 76 |
/** |
| 77 |
* Run the dialog an enter the main loop (block the application). |
| 78 |
* Returns the Dialog::Result, corresponding to the user's action. |
| 79 |
*/ |
| 80 |
virtual Result run() = 0; |
| 81 |
}; |
| 82 |
typedef std::shared_ptr<IDialog> IDialogPtr; |
| 83 |
|
| 84 |
const IDialog::Handle INVALID_HANDLE = 0; |
| 85 |
|
| 86 |
class IFileChooser; |
| 87 |
typedef std::shared_ptr<IFileChooser> IFileChooserPtr; |
| 88 |
|
| 89 |
class IDirChooser; |
| 90 |
typedef std::shared_ptr<IDirChooser> IDirChooserPtr; |
| 91 |
|
| 92 |
class IResourceChooser; // defined in iresourcechooser.h |
| 93 |
class IAnimationChooser; // defined in ianimationchooser.h |
| 94 |
|
| 95 |
class IDialogManager : |
| 96 |
public RegisterableModule |
| 97 |
{ |
| 98 |
public: |
| 99 |
// Virtual destructor |
| 100 |
virtual ~IDialogManager() {} |
| 101 |
|
| 102 |
/** |
| 103 |
* Create a new dialog. Note that the DialogManager will hold a reference |
| 104 |
* to this dialog internally to allow scripts to reference the Dialog class |
| 105 |
* without holding the shared_ptr on their own or using wrapper classes doing so. |
| 106 |
* |
| 107 |
* Every dialog features an OK and a Cancel button by default. |
| 108 |
* |
| 109 |
* @title: The string displayed on the dialog's window bar. |
| 110 |
* @type: the dialog type to create, determines e.g. which buttons are shown. |
| 111 |
* @parent: optional top-level widget this dialog should be parented to, defaults to |
| 112 |
* GlobalMainFrame's toplevel window if left at NULL. |
| 113 |
*/ |
| 114 |
virtual IDialogPtr createDialog(const std::string& title, |
| 115 |
wxWindow* parent = nullptr) = 0; |
| 116 |
|
| 117 |
/** |
| 118 |
* Create a simple message box, which can either notify the user about something, |
| 119 |
* queries "Yes"/"No" or displays an error message. It usually features |
| 120 |
* an icon according to the the MessageType passed (exclamation mark, error sign). |
| 121 |
* |
| 122 |
* @title: The string displayed on the message box window bar. |
| 123 |
* @text: The text/question to be displayed. |
| 124 |
* @type: the message type this dialog represents. |
| 125 |
* @parent: optional top-level widget this dialog should be parented to, defaults to |
| 126 |
* GlobalMainFrame().getMainWindow(). |
| 127 |
*/ |
| 128 |
virtual IDialogPtr createMessageBox(const std::string& title, |
| 129 |
const std::string& text, |
| 130 |
IDialog::MessageType type, |
| 131 |
wxWindow* parent = nullptr) = 0; |
| 132 |
|
| 133 |
/** |
| 134 |
* Acquire a new filechooser instance with the given parameters. |
| 135 |
* |
| 136 |
* @title: The dialog title. |
| 137 |
* @open: if TRUE this is asking for "Open" files, FALSE generates a "Save" dialog. |
| 138 |
* @pattern: the type "map", "prefab", this determines the file extensions. |
| 139 |
* @defaultExt: The default extension appended when the user enters |
| 140 |
* filenames without extension. |
| 141 |
*/ |
| 142 |
virtual IFileChooserPtr createFileChooser(const std::string& title, |
| 143 |
bool open, |
| 144 |
const std::string& pattern = "", |
| 145 |
const std::string& defaultExt = "") = 0; |
| 146 |
|
| 147 |
/** |
| 148 |
* Acquire a new folder chooser instance with the given parameters. |
| 149 |
* |
| 150 |
* @title: The dialog title. |
| 151 |
*/ |
| 152 |
virtual IDirChooserPtr createDirChooser(const std::string& title) = 0; |
| 153 |
|
| 154 |
// Creates and returns a new Dialog class for selecting a sound shader. |
| 155 |
// It's the responsibility of the client code to call destroyDialog() on the returned object. |
| 156 |
// Optionally specify a parent window the dialog should be a child of. |
| 157 |
virtual IResourceChooser* createSoundShaderChooser(wxWindow* parent = nullptr) = 0; |
| 158 |
|
| 159 |
// Creates and returns a new Dialog class for selecting an MD5 anim. |
| 160 |
// It's the responsibility of the client code to call destroyDialog() on the returned object. |
| 161 |
// Optionally specify a parent window the dialog should be a child of. |
| 162 |
virtual IAnimationChooser* createAnimationChooser(wxWindow* parent = nullptr) = 0; |
| 163 |
}; |
| 164 |
|
| 165 |
} // namespace ui |
| 166 |
|
| 167 |
|
| 168 |
constexpr const char* const MODULE_DIALOGMANAGER = "DialogManager"; |
| 169 |
|
| 170 |
inline ui::IDialogManager& GlobalDialogManager() |
| 171 |
{ |
| 172 |
static module::InstanceReference<ui::IDialogManager> _reference(MODULE_DIALOGMANAGER); |
| 173 |
return _reference; |
| 174 |
} |