| 1 |
#pragma once |
| 2 |
|
| 3 |
#include "ClassEditor.h" |
| 4 |
#include "wxutil/XmlResourceBasedWidget.h" |
| 5 |
#include "wxutil/dataview/TreeView.h" |
| 6 |
#include <memory> |
| 7 |
|
| 8 |
namespace ui |
| 9 |
{ |
| 10 |
|
| 11 |
class ResponseEditor : |
| 12 |
public ClassEditor, |
| 13 |
private wxutil::XmlResourceBasedWidget |
| 14 |
{ |
| 15 |
private: |
| 16 |
struct ListContextMenu |
| 17 |
{ |
| 18 |
std::unique_ptr<wxMenu> menu; |
| 19 |
wxMenuItem* remove; |
| 20 |
wxMenuItem* add; |
| 21 |
wxMenuItem* enable; |
| 22 |
wxMenuItem* disable; |
| 23 |
wxMenuItem* duplicate; |
| 24 |
} _contextMenu; |
| 25 |
|
| 26 |
struct EffectWidgets |
| 27 |
{ |
| 28 |
wxutil::TreeView* view; |
| 29 |
std::unique_ptr<wxMenu> contextMenu; |
| 30 |
wxMenuItem* deleteMenuItem; |
| 31 |
wxMenuItem* addMenuItem; |
| 32 |
wxMenuItem* editMenuItem; |
| 33 |
wxMenuItem* upMenuItem; |
| 34 |
wxMenuItem* downMenuItem; |
| 35 |
} _effectWidgets; |
| 36 |
|
| 37 |
struct PropertyWidgets |
| 38 |
{ |
| 39 |
wxCheckBox* active; |
| 40 |
wxCheckBox* chanceToggle; |
| 41 |
wxSpinCtrlDouble* chanceEntry; |
| 42 |
wxCheckBox* randomEffectsToggle; |
| 43 |
wxTextCtrl* randomEffectsEntry; |
| 44 |
} _propertyWidgets; |
| 45 |
|
| 46 |
wxWindow* _mainPanel; |
| 47 |
|
| 48 |
public: |
| 49 |
// Constructor is setting up the response edit controls |
| 50 |
ResponseEditor(wxWindow* mainPanel, StimTypes& stimTypes); |
| 51 |
|
| 52 |
/** greebo: Sets the new entity (updates the treeviews) |
| 53 |
*/ |
| 54 |
virtual void setEntity(const SREntityPtr& entity) override; |
| 55 |
|
| 56 |
/** greebo: Updates the widgets (e.g. after a selection change) |
| 57 |
*/ |
| 58 |
void update() override; |
| 59 |
|
| 60 |
void reloadStimTypes(); |
| 61 |
|
| 62 |
private: |
| 63 |
/** greebo: Updates the associated text fields when a check box |
| 64 |
* is toggled. |
| 65 |
*/ |
| 66 |
void checkBoxToggled(wxCheckBox* toggleButton) override; |
| 67 |
|
| 68 |
/** greebo: Adds a new response effect to the list. |
| 69 |
*/ |
| 70 |
void addEffect(); |
| 71 |
|
| 72 |
/** greebo: Removes the currently selected response effect |
| 73 |
*/ |
| 74 |
void removeEffect(); |
| 75 |
|
| 76 |
/** greebo: Edits the currently selected effect |
| 77 |
*/ |
| 78 |
void editEffect(); |
| 79 |
|
| 80 |
/** greebo: Moves the selected effect up or down (i.e. increasing |
| 81 |
* or decreasing its index). |
| 82 |
* |
| 83 |
* @direction: +1 for moving it down (increasing the index) |
| 84 |
* -1 for moving it up (decreasing the index) |
| 85 |
*/ |
| 86 |
void moveEffect(int direction); |
| 87 |
|
| 88 |
/** greebo: Updates the sensitivity of the effects context menu |
| 89 |
*/ |
| 90 |
void updateEffectContextMenu(); |
| 91 |
|
| 92 |
/** greebo: Selects the effect with the given index in the treeview. |
| 93 |
*/ |
| 94 |
void selectEffectIndex(const unsigned int index); |
| 95 |
|
| 96 |
/** greebo: Returns the ID of the currently selected response effect |
| 97 |
* |
| 98 |
* @returns: the index of the selected effect or -1 on failure |
| 99 |
*/ |
| 100 |
int getEffectIdFromSelection(); |
| 101 |
|
| 102 |
/** greebo: Adds a new default response to the entity |
| 103 |
*/ |
| 104 |
void addSR() override; |
| 105 |
|
| 106 |
// Widget creator helpers |
| 107 |
void createContextMenu(); |
| 108 |
void createEffectWidgets(); // Response effect list |
| 109 |
|
| 110 |
/** greebo: Gets called when the response selection gets changed |
| 111 |
*/ |
| 112 |
virtual void selectionChanged() override; |
| 113 |
|
| 114 |
void openSRListContextMenu() override; |
| 115 |
|
| 116 |
void setupPage(); |
| 117 |
|
| 118 |
// Context menu callbacks |
| 119 |
void onContextMenuAdd(wxCommandEvent& ev); |
| 120 |
void onContextMenuDelete(wxCommandEvent& ev); |
| 121 |
|
| 122 |
void onEffectMenuDelete(wxCommandEvent& ev); |
| 123 |
void onEffectMenuEdit(wxCommandEvent& ev); |
| 124 |
void onEffectMenuAdd(wxCommandEvent& ev); |
| 125 |
void onEffectMenuEffectUp(wxCommandEvent& ev); |
| 126 |
void onEffectMenuEffectDown(wxCommandEvent& ev); |
| 127 |
|
| 128 |
// To catch double-clicks in the response effect list |
| 129 |
void onEffectItemActivated(wxDataViewEvent& ev); |
| 130 |
|
| 131 |
// Context menu handler for effects view |
| 132 |
void onEffectItemContextMenu(wxDataViewEvent& ev); |
| 133 |
|
| 134 |
// Callback for Stim/Response and effect selection changes |
| 135 |
void onEffectSelectionChange(wxDataViewEvent& ev); |
| 136 |
}; |
| 137 |
|
| 138 |
} // namespace ui |