Mana
Loading...
Searching...
No Matches
configuration.h
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2024 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include "being.h"
25#include "defaults.h"
26#include "playerrelations.h"
27#include "video.h"
28
29#include "utils/xml.h"
30
31#include "net/serverinfo.h"
32
33#include <cassert>
34#include <map>
35#include <optional>
36#include <string>
37#include <vector>
38
46{
47 friend class Configuration;
48
49 public:
50 virtual ~ConfigurationObject();
51
58 void setValue(const std::string &key, const std::string &value);
59
66 std::string getValue(const std::string &key,
67 const std::string &deflt) const;
68
69 int getValue(const std::string &key, int deflt) const;
70
71 unsigned getValue(const std::string &key, unsigned deflt) const;
72
73 double getValue(const std::string &key, double deflt) const;
74
78 void clear();
79
80 protected:
81 void initFromXML(XML::Node node);
82
83 std::map<std::string, std::string> mOptions;
84};
85
92{
93 public:
94 Configuration() = default;
95
96 ~Configuration() override;
97
104 void init(const std::string &filename, bool useResManager = false);
105
111 void setDefaultValues(DefaultsData *defaultsData);
112
118 int getIntValue(const std::string &key) const;
119
120 float getFloatValue(const std::string &key) const;
121
122 std::string getStringValue(const std::string &key) const;
123
124 bool getBoolValue(const std::string &key) const;
125
126 VariableData *getDefault(const std::string &key,
127 VariableData::DataType type) const;
128 private:
132 void cleanDefaults();
133
134 std::string mConfigPath;
136};
137
139{
140 int index;
142};
143
145{
146 int index;
148};
149
150struct Outfit
151{
152 int index;
153 std::string items;
155};
156
158{
159 std::string color;
161 std::optional<int> delay;
162};
163
165{
166 std::optional<int> x;
167 std::optional<int> y;
168 std::optional<int> width;
169 std::optional<int> height;
170 std::optional<bool> visible;
171 std::optional<bool> sticky;
172};
173
174struct Config
175{
177 std::string speechBubblecolor = "000000";
178 float speechBubbleAlpha = 1.0f;
180 bool visibleNames = true;
181 bool showGender = false;
183 bool showWarps = true;
188 bool particleEffects = true;
189 bool logToStandardOut = false;
190 bool opengl = false;
191 bool vsync = true;
193 int screenWidth = defaultScreenWidth;
194 int screenHeight = defaultScreenHeight;
195 int scale = 0;
196 bool sound = true;
197 int sfxVolume = 100;
199 int musicVolume = 60;
200 int fpsLimit = 0;
201
202 bool remember = true;
203 std::string username;
204 std::string lastCharacter;
205 std::string updatehost;
206 std::string afkMessage;
210
211 bool enableSync = false;
212
213 bool joystickEnabled = false;
214 int upTolerance = 100;
215 int downTolerance = 100;
216 int leftTolerance = 100;
217 int rightTolerance = 100;
218
219 bool logNpcInGui = true;
220 bool downloadMusic = false;
221 float guiAlpha = 0.9f;
222 int chatLogLength = 256;
223 bool enableChatLog = false;
224 bool whisperTab = true;
225 bool customCursor = true;
226 bool showOwnName = false;
228 bool showPickupChat = true;
229 bool showMinimap = true;
230 int fontSize = 12;
231 bool returnTogglesChat = false;
236 std::string onlineServerList;
237 std::string theme = "jewelry";
239
241 std::string playerIgnoreStrategy = DEFAULT_IGNORE_STRATEGY;
243
244 std::map<std::string, std::string> keys;
245 std::vector<ItemShortcutEntry> itemShortcuts;
246 std::vector<EmoteShortcutEntry> emoteShortcuts;
247 std::vector<Outfit> outfits;
248 std::map<std::string, UserColor> colors;
249 std::map<std::string, WindowState> windows;
250 std::map<std::string, PlayerRelation> players;
252
253 // For compatibility with old configuration files or different clients
254 std::map<std::string, std::string> unknownOptions;
255};
256
257void serialize(XML::Writer &writer, const Config &config);
259
260extern Config config;
262extern Configuration paths;
263
267template<typename T>
268void setConfigValue(T Config::*member, const T &value)
269{
270 if (config.*member == value)
271 return;
272
273 config.*member = value;
275}
Speech
Definition being.h:83
@ TEXT_OVERHEAD
Definition being.h:85
Configuration object, mapping values to names and possibly containing lists of further configuration ...
std::string getValue(const std::string &key, const std::string &deflt) const
Gets a value as string.
std::map< std::string, std::string > mOptions
void clear()
Re-sets all data in the configuration.
void initFromXML(XML::Node node)
virtual ~ConfigurationObject()
void setValue(const std::string &key, const std::string &value)
Sets an option using a string value.
Configuration handler for reading (and writing).
bool getBoolValue(const std::string &key) const
std::string getStringValue(const std::string &key) const
VariableData * getDefault(const std::string &key, VariableData::DataType type) const
float getFloatValue(const std::string &key) const
DefaultsData * mDefaultsData
Defaults of value for a given key.
std::string mConfigPath
Location of config file.
void setDefaultValues(DefaultsData *defaultsData)
Set the default values for each keys.
Configuration()=default
~Configuration() override
void cleanDefaults()
Clean up the default values member.
int getIntValue(const std::string &key) const
returns a value corresponding to the given key.
void init(const std::string &filename, bool useResManager=false)
Reads config file and parse all options into memory.
Definition event.h:42
@ ConfigOptionChanged
Definition event.h:68
void trigger(Channel channel) const
Sends this event to all classes listening to the given channel.
Definition event.h:275
@ ConfigChannel
Definition event.h:51
Helper class for writing out XML data.
Definition xml.h:229
void serialize(XML::Writer &writer, const Config &config)
Config config
Global settings (config.xml)
Definition client.cpp:97
Configuration paths
XML default paths information reader.
Definition client.cpp:99
void deserialize(XML::Node node, Config &config)
void setConfigValue(T Config::*member, const T &value)
Sets the given Config member and sends a change event.
Configuration branding
XML branding information reader.
Definition client.cpp:98
std::map< std::string, VariableData * > DefaultsData
Definition defaults.h:27
std::deque< ServerInfo > ServerInfos
Definition serverinfo.h:109
float guiAlpha
bool showPickupChat
bool logToStandardOut
std::vector< Outfit > outfits
bool persistentPlayerList
int downTolerance
std::map< std::string, PlayerRelation > players
std::map< std::string, WindowState > windows
bool opengl
bool joystickEnabled
int screenWidth
bool customCursor
bool showMinimap
std::vector< ItemShortcutEntry > itemShortcuts
int overlayDetail
std::map< std::string, std::string > unknownOptions
bool returnTogglesChat
ServerInfos servers
bool visibleNames
int scrollCenterOffsetX
int scrollLaziness
std::map< std::string, UserColor > colors
bool enableChatLog
bool enableSync
std::string playerIgnoreStrategy
std::string lastCharacter
Being::Speech speech
bool whisperTab
bool particleEffects
std::string speechBubblecolor
bool logNpcInGui
std::string updatehost
bool showWarps
int particleFastPhysics
WindowMode windowMode
int screenHeight
int sfxVolume
int notificationsVolume
bool showOwnName
int scrollRadius
float speechBubbleAlpha
int chatLogLength
bool disableTransparency
std::map< std::string, std::string > keys
std::vector< EmoteShortcutEntry > emoteShortcuts
bool useScreenshotDirectorySuffix
bool showPickupParticle
int particleEmitterSkip
bool hideCompletedQuests
std::string onlineServerList
std::string theme
bool showGender
int leftTolerance
bool showMonstersTakedDamage
int particleMaxCount
int musicVolume
bool downloadMusic
unsigned defaultPlayerPermissions
int rightTolerance
std::string screenshotDirectory
std::string username
int upTolerance
std::string screenshotDirectorySuffix
bool remember
int scrollCenterOffsetY
std::string afkMessage
bool unequip
std::string items
std::string color
std::optional< int > delay
std::optional< int > height
std::optional< bool > visible
std::optional< int > x
std::optional< int > y
std::optional< bool > sticky
std::optional< int > width
WindowMode
Definition video.h:33