| 1 |
#pragma once |
| 2 |
|
| 3 |
#include <vector> |
| 4 |
#include <set> |
| 5 |
#include "imodule.h" |
| 6 |
#include <sigc++/signal.h> |
| 7 |
#include "ideclmanager.h" |
| 8 |
|
| 9 |
constexpr const char* const SKINS_FOLDER = "skins/"; |
| 10 |
constexpr const char* const SKIN_FILE_EXTENSION = ".skin"; |
| 11 |
|
| 12 |
namespace decl |
| 13 |
{ |
| 14 |
|
| 15 |
class ISkin : |
| 16 |
public IDeclaration |
| 17 |
{ |
| 18 |
public: |
| 19 |
using Ptr = std::shared_ptr<ISkin>; |
| 20 |
|
| 21 |
~ISkin() override {} |
| 22 |
|
| 23 |
struct Remapping |
| 24 |
{ |
| 25 |
// The original material name (can also be a wildcard "*") |
| 26 |
std::string Original; |
| 27 |
|
| 28 |
// The replacement material name |
| 29 |
std::string Replacement; |
| 30 |
}; |
| 31 |
|
| 32 |
/** |
| 33 |
* Get the mapped texture for the given query texture, using the mappings |
| 34 |
* in this skin. If there is no mapping for the given texture, return an |
| 35 |
* empty string. |
| 36 |
*/ |
| 37 |
virtual std::string getRemap(const std::string& name) = 0; |
| 38 |
|
| 39 |
// Returns the list of models this skin applies to |
| 40 |
virtual const std::set<std::string>& getModels() = 0; |
| 41 |
|
| 42 |
// Adds the given model to the set of associated models (does nothing if the model is already present) |
| 43 |
virtual void addModel(const std::string& model) = 0; |
| 44 |
|
| 45 |
// Removes the given model from the set of models (does nothing if the model is not listed) |
| 46 |
virtual void removeModel(const std::string& model) = 0; |
| 47 |
|
| 48 |
// The list of all remappings defined in this skin |
| 49 |
virtual const std::vector<Remapping>& getAllRemappings() = 0; |
| 50 |
|
| 51 |
// Adds the given remapping to this skin (doesn't check for redundancy) |
| 52 |
virtual void addRemapping(const Remapping& remapping) = 0; |
| 53 |
|
| 54 |
// Removes the remapping for the given (source) material |
| 55 |
virtual void removeRemapping(const std::string& material) = 0; |
| 56 |
|
| 57 |
// Removes all remappings from this skin |
| 58 |
virtual void clearRemappings() = 0; |
| 59 |
|
| 60 |
// Returns true if the skin has changed since it has been parsed |
| 61 |
virtual bool isModified() = 0; |
| 62 |
|
| 63 |
// Save any modifications, after this call isModified() will return false |
| 64 |
virtual void commitModifications() = 0; |
| 65 |
|
| 66 |
// Discard any modifications, reverting this to the state it had after parsing. |
| 67 |
// After this call isModified() will return false again. |
| 68 |
virtual void revertModifications() = 0; |
| 69 |
}; |
| 70 |
|
| 71 |
} // namespace |
| 72 |
|
| 73 |
class SkinnedModel |
| 74 |
{ |
| 75 |
public: |
| 76 |
using Ptr = std::shared_ptr<SkinnedModel>; |
| 77 |
|
| 78 |
virtual ~SkinnedModel() {} |
| 79 |
|
| 80 |
// greebo: Updates the model's surface remaps. Pass the new skin name (can be empty). |
| 81 |
virtual void skinChanged(const std::string& newSkinName) = 0; |
| 82 |
|
| 83 |
// Returns the name of the currently active skin |
| 84 |
// If no explicit skin has been defined through skinChanged, this returns the default skin |
| 85 |
virtual std::string getSkin() const = 0; |
| 86 |
|
| 87 |
// Define the skin that is active when an empty skin name is active |
| 88 |
// This is basically referring to the skin value in the modelDefs |
| 89 |
virtual void setDefaultSkin(const std::string& defaultSkin) = 0; |
| 90 |
}; |
| 91 |
|
| 92 |
// Model skinlist typedef |
| 93 |
using StringList = std::vector<std::string>; |
| 94 |
|
| 95 |
constexpr const char* const MODULE_MODELSKINCACHE("ModelSkinCache"); |
| 96 |
|
| 97 |
namespace decl |
| 98 |
{ |
| 99 |
|
| 100 |
/** |
| 101 |
* Interface class for the skin manager. |
| 102 |
*/ |
| 103 |
class IModelSkinCache : |
| 104 |
public RegisterableModule |
| 105 |
{ |
| 106 |
public: |
| 107 |
/** |
| 108 |
* Lookup a specific named skin and return the corresponding skin object. |
| 109 |
* Returns an empty reference if no declaration is matching the name. |
| 110 |
*/ |
| 111 |
virtual ISkin::Ptr findSkin(const std::string& name) = 0; |
| 112 |
|
| 113 |
/** |
| 114 |
* Copies the existing material and creates a new skin with the suggested name. |
| 115 |
* If the suggested name is already present, a non-conflicting name will be generated and used instead. |
| 116 |
* Returns the new skin reference - or an empty reference if the original skin is not existing |
| 117 |
* or if the suggested name is empty. |
| 118 |
*/ |
| 119 |
virtual ISkin::Ptr copySkin(const std::string& nameOfOriginal, const std::string& nameOfCopy) = 0; |
| 120 |
|
| 121 |
// Renames the skin named oldName to newName, and returns true if the operation was successful. |
| 122 |
// If the new name is already in use, this returns false too. |
| 123 |
virtual bool renameSkin(const std::string& oldName, const std::string& newName) = 0; |
| 124 |
|
| 125 |
/** |
| 126 |
* Return the skins associated with the given model. |
| 127 |
* |
| 128 |
* @param |
| 129 |
* The full pathname of the model, as given by the "model" key in the skin |
| 130 |
* definition. |
| 131 |
* |
| 132 |
* @returns |
| 133 |
* A vector of strings, each identifying the name of a skin which is |
| 134 |
* associated with the given model. The vector may be empty as a model does |
| 135 |
* not require any associated skins. |
| 136 |
*/ |
| 137 |
virtual const StringList& getSkinsForModel(const std::string& model) = 0; |
| 138 |
|
| 139 |
/** |
| 140 |
* Return the complete list of available skins. |
| 141 |
*/ |
| 142 |
virtual const StringList& getAllSkins() = 0; |
| 143 |
|
| 144 |
/** |
| 145 |
* A skin can be modified if it has been declared in a physical file, |
| 146 |
* i.e. outside a PAK file. |
| 147 |
*/ |
| 148 |
virtual bool skinCanBeModified(const std::string& name) = 0; |
| 149 |
|
| 150 |
/** |
| 151 |
* greebo: Reloads all skins from the definition files. |
| 152 |
*/ |
| 153 |
virtual void refresh() = 0; |
| 154 |
|
| 155 |
/// Signal emitted after skins are reloaded |
| 156 |
virtual sigc::signal<void> signal_skinsReloaded() = 0; |
| 157 |
}; |
| 158 |
|
| 159 |
} // namespace |
| 160 |
|
| 161 |
inline decl::IModelSkinCache& GlobalModelSkinCache() |
| 162 |
{ |
| 163 |
static module::InstanceReference<decl::IModelSkinCache> _reference(MODULE_MODELSKINCACHE); |
| 164 |
return _reference; |
| 165 |
} |