| 1 |
#pragma once |
| 2 |
|
| 3 |
#include <map> |
| 4 |
#include <list> |
| 5 |
#include <string> |
| 6 |
#include "ResponseEffect.h" |
| 7 |
#include "wxutil/dataview/TreeModel.h" |
| 8 |
|
| 9 |
namespace |
| 10 |
{ |
| 11 |
const char* const GKEY_STIM_RESPONSE_PREFIX = |
| 12 |
"/stimResponseSystem/stimResponsePrefix"; |
| 13 |
} |
| 14 |
|
| 15 |
struct SRKey |
| 16 |
{ |
| 17 |
// The key name |
| 18 |
std::string key; |
| 19 |
|
| 20 |
// A string defining the classes this applies for |
| 21 |
// e.g. "R" for responses only, "SR" for both |
| 22 |
std::string classes; |
| 23 |
}; |
| 24 |
|
| 25 |
/** greebo: A simple stim/response representation structure |
| 26 |
* (a SREntity can hold a bunch of these) |
| 27 |
*/ |
| 28 |
class StimResponse |
| 29 |
{ |
| 30 |
public: |
| 31 |
// The effect map |
| 32 |
typedef std::map<unsigned int, ResponseEffect> EffectMap; |
| 33 |
|
| 34 |
// Tree model definition for a Stim/Response list |
| 35 |
struct Columns : |
| 36 |
public wxutil::TreeModel::ColumnRecord |
| 37 |
{ |
| 38 |
Columns() : |
| 39 |
index(add(wxutil::TreeModel::Column::Integer)), |
| 40 |
caption(add(wxutil::TreeModel::Column::String)), |
| 41 |
arguments(add(wxutil::TreeModel::Column::String)) |
| 42 |
{} |
| 43 |
|
| 44 |
wxutil::TreeModel::Column index; // ID |
| 45 |
wxutil::TreeModel::Column caption; // Caption String |
| 46 |
wxutil::TreeModel::Column arguments; // Argument |
| 47 |
}; |
| 48 |
|
| 49 |
private: |
| 50 |
struct Property |
| 51 |
{ |
| 52 |
// The actual value (this is used for write-accesses) |
| 53 |
std::string value; |
| 54 |
|
| 55 |
// The "original" value (this is considered read-only) |
| 56 |
// Is used for inherited values to check if they were |
| 57 |
// "overruled" by non-inherited values (on the target entity) |
| 58 |
std::string origValue; |
| 59 |
}; |
| 60 |
|
| 61 |
// The key/value mapping |
| 62 |
typedef std::map<std::string, Property> PropertyMap; |
| 63 |
|
| 64 |
// TRUE, if this stems from an inherited eclass. Makes this object read-only |
| 65 |
bool _inherited; |
| 66 |
|
| 67 |
// The list of named properties |
| 68 |
PropertyMap _properties; |
| 69 |
|
| 70 |
/** greebo: The index of this object. The StimResponse objects themselves |
| 71 |
* are already mapped by the SREntity class, although it's |
| 72 |
* useful to set an index of this object by hand to allow |
| 73 |
* it to override an inherited stim. |
| 74 |
*/ |
| 75 |
int _index; |
| 76 |
|
| 77 |
// The list of ResponseEffects for this response (does not apply for stims) |
| 78 |
EffectMap _effects; |
| 79 |
|
| 80 |
// The treemodel for packing this info into a treeview |
| 81 |
wxutil::TreeModel::Ptr _effectStore; |
| 82 |
|
| 83 |
public: |
| 84 |
StimResponse(); |
| 85 |
|
| 86 |
// Copy constructor |
| 87 |
StimResponse(const StimResponse& other); |
| 88 |
|
| 89 |
/** greebo: Returns / sets the "inherited" flag |
| 90 |
*/ |
| 91 |
bool inherited() const; |
| 92 |
void setInherited(bool inherited); |
| 93 |
|
| 94 |
/** greebo: Gets/Sets the index of this object (only for non-inherited) |
| 95 |
*/ |
| 96 |
int getIndex() const; |
| 97 |
void setIndex(int index); |
| 98 |
|
| 99 |
/** greebo: Gets the property value string or "" if not defined/empty |
| 100 |
*/ |
| 101 |
std::string get(const std::string& key); |
| 102 |
|
| 103 |
/** greebo: Sets the given <key> to <value>. |
| 104 |
* |
| 105 |
* @load: This is indicating the origin of this value and can be used |
| 106 |
* to determine whether this is an "override" operation or just |
| 107 |
* an ordinary property population (during parsing the entityclass). |
| 108 |
*/ |
| 109 |
void set(const std::string& key, const std::string& value, bool inherited = false); |
| 110 |
|
| 111 |
/** greebo: Returns TRUE, if the given key has been overridden. |
| 112 |
*/ |
| 113 |
bool isOverridden(const std::string& key); |
| 114 |
|
| 115 |
/** greebo: Retrieves the response effect with the given id. |
| 116 |
* This creates the response effect if it doesn't exist yet. |
| 117 |
*/ |
| 118 |
ResponseEffect& getResponseEffect(const unsigned int index); |
| 119 |
|
| 120 |
/** greebo: Returns the reference to the interally stored map |
| 121 |
*/ |
| 122 |
EffectMap& getEffects(); |
| 123 |
|
| 124 |
/** greebo: Re-indexes the effects to avoid gaps in the numbering. |
| 125 |
* Should be called right before saving the effects to the |
| 126 |
* spawnargs. |
| 127 |
*/ |
| 128 |
void sortEffects(); |
| 129 |
|
| 130 |
/** greebo: Returns the highest used effect index. |
| 131 |
*/ |
| 132 |
unsigned int highestEffectIndex(); |
| 133 |
|
| 134 |
/** greebo: Swaps the two effects with the specified indices. |
| 135 |
*/ |
| 136 |
void moveEffect(const unsigned int fromIndex, const unsigned int toIndex); |
| 137 |
|
| 138 |
/** greebo: Removes the effect with the given index. |
| 139 |
* This re-sorts the items after deletion. |
| 140 |
*/ |
| 141 |
void deleteEffect(const unsigned int index); |
| 142 |
|
| 143 |
/** greebo: Adds a new effect before the given index. |
| 144 |
* |
| 145 |
* @index: the index of the effect the new one should be |
| 146 |
* inserted before. If this is negative, the item |
| 147 |
* is appended at the end of the list. |
| 148 |
*/ |
| 149 |
void addEffect(const unsigned int index); |
| 150 |
|
| 151 |
/** |
| 152 |
* greebo: Constructs the treemodel using the effects stored in this |
| 153 |
* response. The model is delivered with a refcount of 1. |
| 154 |
*/ |
| 155 |
wxutil::TreeModel::Ptr createEffectsStore(); |
| 156 |
|
| 157 |
static const Columns& getColumns(); |
| 158 |
}; |