Debian Codegraph @

plugins/dm.difficulty/DifficultyEditor.h

raw
1 #pragma once
2
3 #include <string>
4 #include <memory>
5
6 #include "DifficultySettings.h"
7 #include "wxutil/XmlResourceBasedWidget.h"
8
9 class wxPanel;
10 class wxTextCtrl;
11 class wxChoice;
12 class wxButton;
13 class wxStaticText;
14 class wxComboBox;
15
16 namespace wxutil { class TreeView; }
17
18 namespace ui
19 {
20
21 /**
22 * greebo: A Difficulty Editor provides the front-end for editing a
23 * set of Difficulty Settings (e.g. "Easy" setting). The actual
24 * data is stored in a DifficultySettings instance.
25 */
26 class DifficultyEditor :
27 public wxEvtHandler,
28 private wxutil::XmlResourceBasedWidget
29 {
30 // The actual settings we're working with
31 difficulty::DifficultySettingsPtr _settings;
32
33 // GtkNotebook-related widgets
34 wxPanel* _editor = nullptr;
35
36 wxutil::TreeView* _settingsView = nullptr;
37
38 // The classname dropdown entry field
39 wxTextCtrl* _classEntry = nullptr;
40 wxTextCtrl* _spawnArgEntry = nullptr;
41 wxTextCtrl* _argumentEntry = nullptr;
42 wxChoice* _appTypeCombo = nullptr;
43
44 wxButton* _saveSettingButton = nullptr;
45 wxButton* _deleteSettingButton = nullptr;
46 wxButton* _createSettingButton = nullptr;
47 wxButton* _refreshButton = nullptr;
48
49 // A label containing notes to the user
50 wxStaticText* _noteText = nullptr;
51
52 // Mutex for avoiding loopbacks
53 bool _updateActive = false;
54
55 public:
56 /**
57 * greebo: Pass the label string and the difficulty settings object to the
58 * constructor. The DifficultySettings should be populated first.
59 */
60 DifficultyEditor(wxWindow* parent,
61 const difficulty::DifficultySettingsPtr& settings);
62
63 // Returns the actual editor widget (contains all controls and views)
64 wxWindow* getWidget();
65
66 private:
67 // Creates the widgets
68 void populateWindow();
69
70 // Returns the ID of the selected setting (or -1) if no valid setting is selected
71 int getSelectedSettingId();
72
73 // Loads the data from the treeview selection into the editor widgets
74 void updateEditorWidgets();
75
76 // Prepares the widgets for addition of a new setting
77 void createSetting();
78
79 // Saves the setting data from the widgets to the DifficultySettings object
80 void saveSetting();
81
82 // Removes the setting selected in the treeview
83 void deleteSetting();
84
85 // Highlights the setting (according to the given <id>) in the treeview
86 void selectSettingById(int id);
87
88 // Callback for treeview selection changes
89 void onSettingSelectionChange(wxDataViewEvent& ev);
90
91 void onSettingCreate(wxCommandEvent& ev);
92 void onSettingSave(wxCommandEvent& ev);
93 void onSettingDelete(wxCommandEvent& ev);
94 void onRefresh(wxCommandEvent& ev);
95 void chooseEntityClass();
96
97 void onAppTypeChange(wxCommandEvent& ev);
98 };
99 typedef std::shared_ptr<DifficultyEditor> DifficultyEditorPtr;
100
101 } // namespace ui