| 1 |
#pragma once |
| 2 |
|
| 3 |
#include "ieclass.h" |
| 4 |
#include "entitylib.h" |
| 5 |
#include <map> |
| 6 |
#include <memory> |
| 7 |
#include "wxutil/dataview/TreeModel.h" |
| 8 |
|
| 9 |
#include "DifficultyEntity.h" |
| 10 |
#include "Setting.h" |
| 11 |
|
| 12 |
namespace |
| 13 |
{ |
| 14 |
const std::string GKEY_DIFFICULTY_LEVELS("/difficulty/numLevels"); |
| 15 |
const std::string GKEY_DIFFICULTY_ENTITYDEF_DEFAULT("/difficulty/defaultSettingsEclass"); |
| 16 |
const std::string GKEY_DIFFICULTY_ENTITYDEF_MAP("/difficulty/mapSettingsEclass"); |
| 17 |
const std::string GKEY_DIFFICULTY_ENTITYDEF_MENU("/difficulty/difficultyMenuEclass"); |
| 18 |
} |
| 19 |
|
| 20 |
namespace difficulty { |
| 21 |
|
| 22 |
class DifficultySettings |
| 23 |
{ |
| 24 |
public: |
| 25 |
struct TreeModelColumns : |
| 26 |
public wxutil::TreeModel::ColumnRecord |
| 27 |
{ |
| 28 |
TreeModelColumns() : |
| 29 |
description(add(wxutil::TreeModel::Column::String)), |
| 30 |
classname(add(wxutil::TreeModel::Column::String)), |
| 31 |
settingId(add(wxutil::TreeModel::Column::Integer)), |
| 32 |
isOverridden(add(wxutil::TreeModel::Column::Boolean)) |
| 33 |
{} |
| 34 |
|
| 35 |
wxutil::TreeModel::Column description; |
| 36 |
wxutil::TreeModel::Column classname; |
| 37 |
wxutil::TreeModel::Column settingId; |
| 38 |
wxutil::TreeModel::Column isOverridden; |
| 39 |
}; |
| 40 |
|
| 41 |
private: |
| 42 |
// the difficulty level, these settings are referring to |
| 43 |
int _level; |
| 44 |
|
| 45 |
// The settings map associates classnames with spawnarg change records. |
| 46 |
// Multiple settings can be made for a single classname. |
| 47 |
typedef std::multimap<std::string, SettingPtr> SettingsMap; |
| 48 |
SettingsMap _settings; |
| 49 |
|
| 50 |
// A mapping between Setting ID and Setting (for faster lookup on GTK selection) |
| 51 |
typedef std::map<int, SettingPtr> SettingIdMap; |
| 52 |
SettingIdMap _settingIds; |
| 53 |
|
| 54 |
// This maps classnames to wxDataViewItems, for faster lookup |
| 55 |
typedef std::map<std::string, wxDataViewItem> TreeIterMap; |
| 56 |
TreeIterMap _iterMap; |
| 57 |
|
| 58 |
// The treemodel |
| 59 |
TreeModelColumns _columns; |
| 60 |
|
| 61 |
// This class holds a reference to the treemodel |
| 62 |
wxutil::TreeModel::Ptr _store; |
| 63 |
|
| 64 |
public: |
| 65 |
// Define the difficulty level in the constructor |
| 66 |
DifficultySettings(int level); |
| 67 |
|
| 68 |
~DifficultySettings(); |
| 69 |
|
| 70 |
const TreeModelColumns& getColumns() const; |
| 71 |
|
| 72 |
// Get the treestore pointer for packing into a treeview |
| 73 |
// Note that this class will keep a reference to the model |
| 74 |
wxutil::TreeModel::Ptr getTreeStore() const; |
| 75 |
|
| 76 |
// Returns the Setting associated with the given className |
| 77 |
// and carrying the given ID (returned pointer might be NULL) |
| 78 |
SettingPtr getSettingById(int id) const; |
| 79 |
|
| 80 |
// Returns the level these settings are referring to |
| 81 |
int getLevel() const; |
| 82 |
|
| 83 |
// Empties the internal structures |
| 84 |
void clear(); |
| 85 |
|
| 86 |
/** |
| 87 |
* greebo: Saves the given setting. The ID specifices the setting currently |
| 88 |
* highlighted in the editor (pass -1 if nothing is selected). |
| 89 |
* |
| 90 |
* @returns: the ID of the saved Setting, can be used to select it. |
| 91 |
*/ |
| 92 |
int save(int id, const SettingPtr& setting); |
| 93 |
|
| 94 |
// Removes the setting with the given ID |
| 95 |
void deleteSetting(int id); |
| 96 |
|
| 97 |
// Loads the data into the given treestore |
| 98 |
void updateTreeModel(); |
| 99 |
|
| 100 |
// Loads all settings (matching the internal _level) from the given entityDef. |
| 101 |
void parseFromEntityDef(const IEntityClassPtr& def); |
| 102 |
|
| 103 |
// Loads all settings (matching the internal _level) from the given entity. |
| 104 |
void parseFromMapEntity(Entity* entity); |
| 105 |
|
| 106 |
// Save the relevant settings to the given difficulty entity |
| 107 |
void saveToEntity(DifficultyEntity& target); |
| 108 |
|
| 109 |
// Returns true if the given setting is overridden by map-specific settings |
| 110 |
bool isOverridden(const SettingPtr& setting); |
| 111 |
|
| 112 |
// Clears and reloads the treemodel |
| 113 |
void refreshTreeModel(); |
| 114 |
|
| 115 |
private: |
| 116 |
// Clears the tree data |
| 117 |
void clearTreeModel(); |
| 118 |
|
| 119 |
// Get the inheritance key of the given classname (for sorting in the map) |
| 120 |
std::string getInheritanceKey(const std::string& className); |
| 121 |
|
| 122 |
// Creates a new setting (and updates the internal structures) |
| 123 |
// This needs the classname as argument (for the internal mapping) |
| 124 |
SettingPtr createSetting(const std::string& className); |
| 125 |
|
| 126 |
/** |
| 127 |
* greebo: Finds or creates a setting overruling the given <existing> one. |
| 128 |
*/ |
| 129 |
SettingPtr findOrCreateOverrule(const SettingPtr& existing); |
| 130 |
|
| 131 |
/** |
| 132 |
* greebo: Returns the TreeIter pointing to the tree element <className> in <store>. |
| 133 |
* If the item is not yet existing, it gets inserted into the tree, according |
| 134 |
* to its inheritance tree. |
| 135 |
*/ |
| 136 |
wxDataViewItem findOrInsertClassname(const std::string& className); |
| 137 |
|
| 138 |
/** |
| 139 |
* greebo: Inserts the given classname into the treestore, using the |
| 140 |
* given <parent> iter as insertion point. If <parent> is invalid, |
| 141 |
* the entry is inserted at root level. |
| 142 |
*/ |
| 143 |
wxDataViewItem insertClassName(const std::string& className, |
| 144 |
const wxDataViewItem& parent = wxDataViewItem()); |
| 145 |
|
| 146 |
// returns the parent eclass name for the given <className> or "" if no parent |
| 147 |
std::string getParentClass(const std::string& className); |
| 148 |
}; |
| 149 |
typedef std::shared_ptr<DifficultySettings> DifficultySettingsPtr; |
| 150 |
|
| 151 |
} // namespace difficulty |