diff options
Diffstat (limited to 'src/configuration.h')
-rw-r--r-- | src/configuration.h | 262 |
1 files changed, 131 insertions, 131 deletions
diff --git a/src/configuration.h b/src/configuration.h index c6c115f6..69a211be 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -1,7 +1,7 @@ /* * The Mana Client * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2012 The Mana Developers + * Copyright (C) 2009-2024 The Mana Developers * * This file is part of The Mana Client. * @@ -22,51 +22,20 @@ #ifndef CONFIGURATION_H #define CONFIGURATION_H +#include "being.h" #include "defaults.h" +#include "playerrelations.h" +#include "video.h" -#include "utils/stringutils.h" #include "utils/xml.h" +#include "net/serverinfo.h" + #include <cassert> -#include <list> #include <map> +#include <optional> #include <string> - -class ConfigurationObject; - -/** - * Configuration list manager interface; responsible for - * serializing/deserializing configuration choices in containers. - * - * \param T Type of the container elements to serialise - * \param CONT Type of the container we (de)serialise - */ -template <class T, class CONT> -class ConfigurationListManager -{ - public: - /** - * Writes a value into a configuration object - * - * \param value The value to write out - * \param obj The configuation object to write to - * \return obj, or otherwise NULL to indicate that this option should - * be skipped - */ - virtual ConfigurationObject *writeConfigItem(const T &value, - ConfigurationObject *obj) = 0; - - /** - * Reads a value from a configuration object - * - * \param obj The configuration object to read from - * \param container The container to insert the object to - */ - virtual CONT readConfigItem(ConfigurationObject *obj, - CONT container) = 0; - - virtual ~ConfigurationListManager() = default; -}; +#include <vector> /** * Configuration object, mapping values to names and possibly containing @@ -87,8 +56,7 @@ class ConfigurationObject * \param key Option identifier. * \param value Value. */ - virtual void setValue(const std::string &key, - const std::string &value); + void setValue(const std::string &key, const std::string &value); /** * Gets a value as string. @@ -110,74 +78,10 @@ class ConfigurationObject */ void clear(); - /** - * Serialises a container into a list of configuration options - * - * \tparam IT Iterator type over CONT - * \tparam T Elements that IT iterates over - * \tparam CONT The associated container type - * - * \param name Name of the list the elements should be stored under - * \param begin Iterator start - * \param end Iterator end - * \param manager An object capable of serialising T items - */ - template <class IT, class T, class CONT> - void setList(const std::string &name, IT begin, IT end, - ConfigurationListManager<T, CONT> &manager) - { - auto *nextobj = new ConfigurationObject; - std::list<ConfigurationObject *> &list = mContainerOptions[name]; - deleteList(list); - - for (IT it = begin; it != end; it++) - { - ConfigurationObject *wrobj = manager.writeConfigItem(*it, nextobj); - if (wrobj) - { // wrote something - assert (wrobj == nextobj); - nextobj = new ConfigurationObject; - list.push_back(wrobj); - } - else - { - nextobj->clear(); // you never know... - } - } - - delete nextobj; - } - - /** - * Serialises a container into a list of configuration options - * - * \tparam IT Iterator type over CONT - * \tparam T Elements that IT iterates over - * \tparam CONT The associated container type - * - * \param name Name of the list the elements should be read from under - * \param empty Initial (empty) container to write to - * \param manager An object capable of deserialising items into CONT - */ - template<class T, class CONT> - CONT getList(const std::string &name, CONT empty, ConfigurationListManager<T, CONT> &manager) - { - CONT container = empty; - - for (auto obj : mContainerOptions[name]) - container = manager.readConfigItem(obj, container); - - return container; - } - protected: void initFromXML(XML::Node node); - void writeToXML(XML::Writer &writer) const; - - void deleteList(std::list<ConfigurationObject *> &list); std::map<std::string, std::string> mOptions; - std::map<std::string, std::list<ConfigurationObject *>> mContainerOptions; }; /** @@ -208,31 +112,6 @@ class Configuration : public ConfigurationObject void setDefaultValues(DefaultsData *defaultsData); /** - * Writes the current settings back to the config file. - */ - void write(); - - void setValue(const std::string &key, const std::string &value) override; - - void setValue(const std::string &key, const char *value) - { setValue(key, std::string(value)); } - - void setValue(const std::string &key, float value) - { setValue(key, toString(value)); } - - void setValue(const std::string &key, double value) - { setValue(key, toString(value)); } - - void setValue(const std::string &key, int value) - { setValue(key, toString(value)); } - - void setValue(const std::string &key, unsigned value) - { setValue(key, toString(value)); } - - void setValue(const std::string &key, bool value) - { setValue(key, value ? "1" : "0"); } - - /** * returns a value corresponding to the given key. * The default value returned in based on fallbacks registry. * @see defaults.h @@ -257,8 +136,129 @@ class Configuration : public ConfigurationObject DefaultsData *mDefaultsData = nullptr; /**< Defaults of value for a given key */ }; +struct ItemShortcutEntry +{ + int index; + int itemId; +}; + +struct EmoteShortcutEntry +{ + int index; + int emoteId; +}; + +struct Outfit +{ + int index; + std::string items; + bool unequip; +}; + +struct UserColor +{ + std::string color; + int gradient; + std::optional<int> delay; +}; + +struct WindowState +{ + std::optional<int> x; + std::optional<int> y; + std::optional<int> width; + std::optional<int> height; + std::optional<bool> visible; + std::optional<bool> sticky; +}; + +struct Config +{ + int overlayDetail = 2; + std::string speechBubblecolor = "000000"; + float speechBubbleAlpha = 1.0f; + Being::Speech speech = Being::TEXT_OVERHEAD; + bool visibleNames = true; + bool showGender = false; + bool showMonstersTakedDamage = false; + bool showWarps = true; + int particleMaxCount = 3000; + int particleFastPhysics = 0; + int particleEmitterSkip = 1; + bool particleEffects = true; + bool logToStandardOut = false; + bool opengl = false; + bool vsync = true; + WindowMode windowMode = WindowMode::Windowed; + int screenWidth = defaultScreenWidth; + int screenHeight = defaultScreenHeight; + int scale = 0; + bool sound = true; + int sfxVolume = 100; + int notificationsVolume = 100; + int musicVolume = 60; + int fpsLimit = 0; + + bool remember = true; + std::string username; + std::string lastCharacter; + std::string updatehost; + std::string afkMessage; + std::string screenshotDirectory; + std::string screenshotDirectorySuffix; + bool useScreenshotDirectorySuffix = true; + + bool enableSync = false; + + bool joystickEnabled = false; + int upTolerance = 100; + int downTolerance = 100; + int leftTolerance = 100; + int rightTolerance = 100; + + bool logNpcInGui = true; + bool downloadMusic = false; + float guiAlpha = 0.8f; + int chatLogLength = 128; + bool enableChatLog = false; + bool whisperTab = true; + bool customCursor = true; + bool showOwnName = false; + bool showPickupParticle = true; + bool showPickupChat = false; + bool showMinimap = true; + int fontSize = 12; + bool returnTogglesChat = false; + int scrollLaziness = 16; + int scrollRadius = 0; + int scrollCenterOffsetX = 0; + int scrollCenterOffsetY = 0; + std::string onlineServerList; + std::string theme; + bool disableTransparency = false; + + bool persistentPlayerList = true; + std::string playerIgnoreStrategy = DEFAULT_IGNORE_STRATEGY; + unsigned defaultPlayerPermissions = PlayerPermissions::DEFAULT; + + std::map<std::string, std::string> keys; + std::vector<ItemShortcutEntry> itemShortcuts; + std::vector<EmoteShortcutEntry> emoteShortcuts; + std::vector<Outfit> outfits; + std::map<std::string, UserColor> colors; + std::map<std::string, WindowState> windows; + std::map<std::string, PlayerRelation> players; + ServerInfos servers; + + // For compatibility with old configuration files or different clients + std::map<std::string, std::string> unknownOptions; +}; + +void serialize(XML::Writer &writer, const Config &config); +void deserialize(XML::Node node, Config &config); + +extern Config config; extern Configuration branding; -extern Configuration config; extern Configuration paths; #endif |