diff --git a/plugins/dm.difficulty/DifficultyDialog.cpp b/plugins/dm.difficulty/DifficultyDialog.cpp index 9f4f1708be..d044842d01 100644 --- a/plugins/dm.difficulty/DifficultyDialog.cpp +++ b/plugins/dm.difficulty/DifficultyDialog.cpp @@ -44,29 +44,21 @@ void DifficultyDialog::createDifficultyEditors() { // Acquire the settings object difficulty::DifficultySettingsPtr settings = _settingsManager.getSettings(i); - - if (settings != NULL) + if (settings) { - _editors.push_back( - DifficultyEditorPtr(new DifficultyEditor( - _notebook, _settingsManager.getDifficultyName(i), settings) - ) - ); + // Construct the editor for this difficulty level and add it to our + // internal list of editors + std::string diffName = _settingsManager.getDifficultyName(i); + auto editor = std::make_shared(_notebook, + settings); + _editors.push_back(editor); + + // Insert the editor's widget as a new page in the choicebook + wxWindow* editorWidget = editor->getWidget(); + editorWidget->Reparent(_notebook); + _notebook->AddPage(editorWidget, diffName, false); } } - - // Pack the editors into the notebook - for (std::size_t i = 0; i < _editors.size(); i++) - { - DifficultyEditor& editor = *_editors[i]; - - wxWindow* editorWidget = editor.getEditor(); - - // Reparent the DifficultyEditor's widget to the book control and then - // add it as a new page. - editorWidget->Reparent(_notebook); - _notebook->AddPage(editorWidget, editor.getNotebookLabel(), false); - } } void DifficultyDialog::populateWindow() diff --git a/plugins/dm.difficulty/DifficultyEditor.cpp b/plugins/dm.difficulty/DifficultyEditor.cpp index 8d8cae26bb..7047492c88 100644 --- a/plugins/dm.difficulty/DifficultyEditor.cpp +++ b/plugins/dm.difficulty/DifficultyEditor.cpp @@ -19,21 +19,20 @@ namespace ui { -DifficultyEditor::DifficultyEditor(wxWindow* parent, const std::string& label, - const difficulty::DifficultySettingsPtr& settings) : - _settings(settings), - _label(label), - _settingsView(nullptr), - _classCombo(nullptr), - _spawnArgEntry(nullptr), - _argumentEntry(nullptr), - _appTypeCombo(nullptr), - _saveSettingButton(nullptr), - _deleteSettingButton(nullptr), - _createSettingButton(nullptr), - _refreshButton(nullptr), - _noteText(nullptr), - _updateActive(false) +DifficultyEditor::DifficultyEditor(wxWindow* parent, + const difficulty::DifficultySettingsPtr& settings) +: _settings(settings), + _settingsView(nullptr), + _classCombo(nullptr), + _spawnArgEntry(nullptr), + _argumentEntry(nullptr), + _appTypeCombo(nullptr), + _saveSettingButton(nullptr), + _deleteSettingButton(nullptr), + _createSettingButton(nullptr), + _refreshButton(nullptr), + _noteText(nullptr), + _updateActive(false) { // The actual editor pane _editor = loadNamedPanel(parent, "DifficultyEditorMainPanel"); @@ -44,16 +43,11 @@ DifficultyEditor::DifficultyEditor(wxWindow* parent, const std::string& label, updateEditorWidgets(); } -wxWindow* DifficultyEditor::getEditor() +wxWindow* DifficultyEditor::getWidget() { return _editor; } -std::string DifficultyEditor::getNotebookLabel() -{ - return _label; -} - void DifficultyEditor::populateWindow() { wxPanel* viewPanel = findNamedObject(_editor, "DifficultyEditorTreeViewPanel"); diff --git a/plugins/dm.difficulty/DifficultyEditor.h b/plugins/dm.difficulty/DifficultyEditor.h index 3e582e729f..6f6d7a3cf6 100644 --- a/plugins/dm.difficulty/DifficultyEditor.h +++ b/plugins/dm.difficulty/DifficultyEditor.h @@ -24,80 +24,76 @@ namespace ui * data is stored in a DifficultySettings instance. */ class DifficultyEditor : - public wxEvtHandler, - private wxutil::XmlResourceBasedWidget + public wxEvtHandler, + private wxutil::XmlResourceBasedWidget { -private: - // The actual settings we're working with - difficulty::DifficultySettingsPtr _settings; + // The actual settings we're working with + difficulty::DifficultySettingsPtr _settings; - // GtkNotebook-related widgets - wxPanel* _editor; - std::string _label; // the actual label + // GtkNotebook-related widgets + wxPanel* _editor; - wxutil::TreeView* _settingsView; + wxutil::TreeView* _settingsView; - // The classname dropdown entry field - wxComboBox* _classCombo; - wxTextCtrl* _spawnArgEntry; - wxTextCtrl* _argumentEntry; - wxChoice* _appTypeCombo; + // The classname dropdown entry field + wxComboBox* _classCombo; + wxTextCtrl* _spawnArgEntry; + wxTextCtrl* _argumentEntry; + wxChoice* _appTypeCombo; - wxButton* _saveSettingButton; - wxButton* _deleteSettingButton; - wxButton* _createSettingButton; - wxButton* _refreshButton; + wxButton* _saveSettingButton; + wxButton* _deleteSettingButton; + wxButton* _createSettingButton; + wxButton* _refreshButton; - // A label containing notes to the user - wxStaticText* _noteText; + // A label containing notes to the user + wxStaticText* _noteText; - // Mutex for avoiding loopbacks - bool _updateActive; + // Mutex for avoiding loopbacks + bool _updateActive; public: - /** - * greebo: Pass the label string and the difficulty settings object to the - * constructor. The DifficultySettings should be populated first. - */ - DifficultyEditor(wxWindow* parent, const std::string& label, const difficulty::DifficultySettingsPtr& settings); - - // Returns the actual editor widget (contains all controls and views) - wxWindow* getEditor(); + /** + * greebo: Pass the label string and the difficulty settings object to the + * constructor. The DifficultySettings should be populated first. + */ + DifficultyEditor(wxWindow* parent, + const difficulty::DifficultySettingsPtr& settings); - // Returns the label for packing into a GtkNotebook tab. - std::string getNotebookLabel(); + // Returns the actual editor widget (contains all controls and views) + wxWindow* getWidget(); private: - // Creates the widgets - void populateWindow(); + // Creates the widgets + void populateWindow(); - // Returns the ID of the selected setting (or -1) if no valid setting is selected - int getSelectedSettingId(); + // Returns the ID of the selected setting (or -1) if no valid setting is selected + int getSelectedSettingId(); - // Loads the data from the treeview selection into the editor widgets - void updateEditorWidgets(); + // Loads the data from the treeview selection into the editor widgets + void updateEditorWidgets(); - // Prepares the widgets for addition of a new setting - void createSetting(); + // Prepares the widgets for addition of a new setting + void createSetting(); - // Saves the setting data from the widgets to the DifficultySettings object - void saveSetting(); + // Saves the setting data from the widgets to the DifficultySettings object + void saveSetting(); - // Removes the setting selected in the treeview - void deleteSetting(); + // Removes the setting selected in the treeview + void deleteSetting(); - // Highlights the setting (according to the given ) in the treeview - void selectSettingById(int id); + // Highlights the setting (according to the given ) in the treeview + void selectSettingById(int id); - // Callback for treeview selection changes - void onSettingSelectionChange(wxDataViewEvent& ev); + // Callback for treeview selection changes + void onSettingSelectionChange(wxDataViewEvent& ev); - void onSettingCreate(wxCommandEvent& ev); - void onSettingSave(wxCommandEvent& ev); - void onSettingDelete(wxCommandEvent& ev); - void onRefresh(wxCommandEvent& ev); + void onSettingCreate(wxCommandEvent& ev); + void onSettingSave(wxCommandEvent& ev); + void onSettingDelete(wxCommandEvent& ev); + void onRefresh(wxCommandEvent& ev); - void onAppTypeChange(wxCommandEvent& ev); + void onAppTypeChange(wxCommandEvent& ev); }; typedef std::shared_ptr DifficultyEditorPtr;