/
SREntity.h
182 lines (149 loc) · 5.21 KB
/
SREntity.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#pragma once
#include <vector>
#include <list>
#include <string>
#include "wxutil/TreeModel.h"
#include <memory>
#include "StimResponse.h"
#include "StimTypes.h"
// Forward declaration
class Entity;
namespace
{
const std::string ICON_STIM = "sr_stim";
const std::string ICON_RESPONSE = "sr_response";
const std::string ICON_CUSTOM_STIM = "sr_icon_custom.png";
const std::string SUFFIX_INHERITED = "_inherited";
const std::string SUFFIX_INACTIVE = "_inactive";
const std::string SUFFIX_EXTENSION = ".png";
}
// Tree model definition for a Stim/Response list
struct SRListColumns :
public wxutil::TreeModel::ColumnRecord
{
SRListColumns() :
index(add(wxutil::TreeModel::Column::Integer)),
srClass(add(wxutil::TreeModel::Column::Icon)),
caption(add(wxutil::TreeModel::Column::IconText)),
inherited(add(wxutil::TreeModel::Column::Boolean)),
id(add(wxutil::TreeModel::Column::Integer))
{
}
wxutil::TreeModel::Column index; // S/R index
wxutil::TreeModel::Column srClass; // Type icon
wxutil::TreeModel::Column caption; // Caption String
wxutil::TreeModel::Column inherited; // Inheritance flag
wxutil::TreeModel::Column id; // ID (unique)
};
/**
* greebo: This is the representation of an entity holding S/R keys.
* Use the load() and save() methods to load/save the spawnargs.
*
* The getStimStore() and getResponseStore() methods are available
* to retrieve the TreeModel for association with a TreeView.
* The liststore is maintained automatically when the set() method is
* used to manipulate the data. The SREntity class will hold a reference
* of the liststore, so client code should not DecRef() it.
*/
class SREntity
{
public:
// These are the possible key names
typedef std::vector<SRKey> KeyList;
// These are the int-indexed Stims/Responses belonging to an entity
typedef std::map<int, StimResponse> StimResponseMap;
private:
// The local lists of S/R and possible keys
StimResponseMap _list;
KeyList _keys;
// The liststore representation
wxutil::TreeModel::Ptr _stimStore;
wxutil::TreeModel::Ptr _responseStore;
// A collection of warnings regarding the parsing of the spawnargs
std::string _warnings;
// The helper class managing the various stim types
StimTypes& _stimTypes;
// An empty stim
StimResponse _emptyStimResponse;
public:
SREntity(Entity* source, StimTypes& stimTypes);
void load(Entity* source);
void save(Entity* target);
/** greebo: Removes all the stim/response-relevant spawnargs
* from the <target> entity.
*/
void cleanEntity(Entity* target);
/** greebo: Retrieves the reference to the StimResponse object
* having the given integer <id>.
*
* @returns: The ref to the StimResponse or an empty StimResponse object,
* if the id was not found.
*/
StimResponse& get(int id);
/** greebo: Adds a new StimResponse and returns the id of the new object.
* The ListStore is NOT updated with this call to allow setting of
* the properties before refreshing the treeview.
*/
int add();
/** greebo: Removes the StimResponse object with the given id.
* This triggers a refresh of the liststores.
*/
void remove(int id);
/** greebo: Duplicates the stim/response with the given id.
*
* @fromId: The ID of the SR to copy from.
* @returns: the ID of the new duplicate.
*/
int duplicate(int fromId);
/** greebo: Overrides the "state" property of an inherited stim.
* As inherited spawnargs can't be altered, a sr_state_N
* key/value pair is added to the entity, overriding
* the inherited one.
*/
void setInheritedState(int id, bool enabled);
/** greebo: Returns TRUE if the inherited stim/response is enabled,
* FALSE, if the inherited item is overridden.
*/
bool getInheritedState(int id);
// Static column definition
static const SRListColumns& getColumns();
/**
* greebo: Returns the list store containing the stim/response data.
* Use this to add the data to a treeview or a combobox.
* Don't call DecRef() on this model, just associate it to a TreeView.
*/
wxutil::TreeModel::Ptr getStimStore();
wxutil::TreeModel::Ptr getResponseStore();
/** greebo: Sets the <key> of the SR with the given <id> to <value>
*/
void setProperty(int id, const std::string& key, const std::string& value);
/** greebo: Updates the ListStore according to the
* values of the current StimResponseMap <_list>
*/
void updateListStores();
/** greebo: Helper to load the possible key names
* from the registry into the _keys list.
*/
void loadKeys();
/**
* greebo: Returns the treeIter pointing to the row containing the
* StimResponse with the given <id>
*
* @targetStore: The liststore where the iter should be searched
*/
wxDataViewItem getIterForId(wxutil::TreeModel& targetStore, int id);
private:
/** greebo: Write the values of the passed StimResponse to the
* TreeModel using the passed Row.
* The ID stays untouched.
*
* @row: The row where the data should be inserted to
* @sr: the StimResponse object containing the source data
*/
void writeToListRow(wxutil::TreeModel::Row& row, StimResponse& sr);
// Returns the highest currently assigned id
int getHighestId();
// Returns the highest Stim/Response index number
int getHighestIndex();
};
typedef std::shared_ptr<SREntity> SREntityPtr;