2009-04-15 17:03:31 +03:00
|
|
|
/*
|
2015-12-08 08:53:14 +02:00
|
|
|
* CConfigHandler.h, part of VCMI engine
|
2009-04-15 17:03:31 +03:00
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
2009-04-16 14:14:13 +03:00
|
|
|
*/
|
2017-07-13 10:26:03 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../lib/JsonNode.h"
|
|
|
|
|
2012-01-12 18:23:00 +03:00
|
|
|
class Settings;
|
|
|
|
class SettingsListener;
|
|
|
|
|
|
|
|
/// Main storage of game settings
|
2012-09-29 13:59:43 +03:00
|
|
|
class DLL_LINKAGE SettingsStorage
|
2009-04-16 14:14:13 +03:00
|
|
|
{
|
2012-01-12 18:23:00 +03:00
|
|
|
//Helper struct to access specific node either via chain of operator[] or with one operator() (vector)
|
|
|
|
template<typename Accessor>
|
2012-09-29 13:59:43 +03:00
|
|
|
struct DLL_LINKAGE NodeAccessor
|
2009-04-16 14:14:13 +03:00
|
|
|
{
|
2012-01-12 18:23:00 +03:00
|
|
|
SettingsStorage & parent;
|
|
|
|
std::vector<std::string> path;
|
|
|
|
|
|
|
|
NodeAccessor(SettingsStorage & _parent, std::vector<std::string> _path);
|
|
|
|
NodeAccessor<Accessor> operator [] (std::string nextNode) const;
|
|
|
|
NodeAccessor<Accessor> operator () (std::vector<std::string> _path);
|
|
|
|
operator Accessor() const;
|
2009-04-16 14:14:13 +03:00
|
|
|
};
|
2012-01-12 18:23:00 +03:00
|
|
|
|
|
|
|
std::set<SettingsListener*> listeners;
|
|
|
|
JsonNode config;
|
|
|
|
JsonNode & getNode(std::vector<std::string> path);
|
|
|
|
|
|
|
|
// Calls all required listeners
|
|
|
|
void invalidateNode(const std::vector<std::string> &changedPath);
|
|
|
|
|
|
|
|
Settings get(std::vector<std::string> path);
|
|
|
|
public:
|
|
|
|
// Initialize config structure
|
|
|
|
SettingsStorage();
|
|
|
|
void init();
|
2011-02-22 13:52:36 +02:00
|
|
|
|
2012-01-12 18:23:00 +03:00
|
|
|
// Get write access to config node at path
|
|
|
|
const NodeAccessor<Settings> write;
|
|
|
|
|
|
|
|
// Get access to listener at path
|
|
|
|
const NodeAccessor<SettingsListener> listen;
|
|
|
|
|
|
|
|
//Read access, see JsonNode::operator[]
|
|
|
|
const JsonNode& operator [](std::string value);
|
|
|
|
|
|
|
|
friend class SettingsListener;
|
|
|
|
friend class Settings;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Class for listening changes in specific part of configuration (e.g. change of music volume)
|
2012-09-29 13:59:43 +03:00
|
|
|
class DLL_LINKAGE SettingsListener
|
2012-01-12 18:23:00 +03:00
|
|
|
{
|
|
|
|
SettingsStorage &parent;
|
|
|
|
// Path to this node
|
|
|
|
std::vector<std::string> path;
|
|
|
|
// Callback
|
2013-06-26 14:18:27 +03:00
|
|
|
std::function<void(const JsonNode&)> callback;
|
2012-01-12 18:23:00 +03:00
|
|
|
|
|
|
|
SettingsListener(SettingsStorage &_parent, const std::vector<std::string> &_path);
|
|
|
|
|
|
|
|
// Executes callback if changedpath begins with path
|
2012-09-26 16:13:39 +03:00
|
|
|
void nodeInvalidated(const std::vector<std::string> & changedPath);
|
2012-01-12 18:23:00 +03:00
|
|
|
|
|
|
|
public:
|
2012-09-06 13:26:18 +03:00
|
|
|
SettingsListener(const SettingsListener &sl);
|
2012-01-12 18:23:00 +03:00
|
|
|
~SettingsListener();
|
|
|
|
|
|
|
|
// assign callback function
|
2013-06-26 14:18:27 +03:00
|
|
|
void operator()(std::function<void(const JsonNode&)> _callback);
|
2012-01-12 18:23:00 +03:00
|
|
|
|
|
|
|
friend class SettingsStorage;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// System options, provides write access to config tree with auto-saving on change
|
2012-09-29 13:59:43 +03:00
|
|
|
class DLL_LINKAGE Settings
|
2012-01-12 18:23:00 +03:00
|
|
|
{
|
|
|
|
SettingsStorage &parent;
|
|
|
|
//path to this node
|
|
|
|
std::vector<std::string> path;
|
|
|
|
JsonNode &node;
|
|
|
|
JsonNode copy;
|
|
|
|
|
|
|
|
//Get access to node pointed by path
|
|
|
|
Settings(SettingsStorage &_parent, const std::vector<std::string> &_path);
|
|
|
|
|
|
|
|
public:
|
|
|
|
//Saves config if it was modified
|
|
|
|
~Settings();
|
|
|
|
|
|
|
|
//Returns node selected during construction
|
|
|
|
JsonNode* operator ->();
|
|
|
|
const JsonNode* operator ->() const;
|
|
|
|
|
|
|
|
//Helper, replaces JsonNode::operator[]
|
|
|
|
JsonNode& operator [](std::string value);
|
|
|
|
const JsonNode& operator [](std::string value) const;
|
|
|
|
|
|
|
|
friend class SettingsStorage;
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace config
|
|
|
|
{
|
2012-09-29 13:59:43 +03:00
|
|
|
struct DLL_LINKAGE ButtonInfo
|
2009-04-16 14:14:13 +03:00
|
|
|
{
|
|
|
|
std::string defName;
|
|
|
|
std::vector<std::string> additionalDefs;
|
|
|
|
int x, y; //position on the screen
|
|
|
|
bool playerColoured; //if true button will be colored to main player's color (works properly only for appropriate 8bpp graphics)
|
|
|
|
};
|
2011-02-22 13:52:36 +02:00
|
|
|
/// Struct which holds data about position of several GUI elements at the adventure map screen
|
2012-09-29 13:59:43 +03:00
|
|
|
struct DLL_LINKAGE AdventureMapConfig
|
2009-04-16 14:14:13 +03:00
|
|
|
{
|
|
|
|
//minimap properties
|
|
|
|
int minimapX, minimapY, minimapW, minimapH;
|
|
|
|
//statusbar
|
|
|
|
int statusbarX, statusbarY; //pos
|
|
|
|
std::string statusbarG; //graphic name
|
|
|
|
//resdatabar
|
|
|
|
int resdatabarX, resdatabarY, resDist, resDateDist, resOffsetX, resOffsetY; //pos
|
|
|
|
std::string resdatabarG; //graphic name
|
|
|
|
//infobox
|
|
|
|
int infoboxX, infoboxY;
|
|
|
|
//advmap
|
2009-06-14 18:10:59 +03:00
|
|
|
int advmapX, advmapY, advmapW, advmapH;
|
2009-04-16 14:14:13 +03:00
|
|
|
bool smoothMove;
|
2009-08-31 18:57:15 +03:00
|
|
|
bool puzzleSepia;
|
2015-02-02 20:38:30 +02:00
|
|
|
bool screenFading;
|
|
|
|
bool objectFading;
|
2009-04-16 14:14:13 +03:00
|
|
|
//general properties
|
|
|
|
std::string mainGraphic;
|
2015-01-13 21:57:41 +02:00
|
|
|
std::string worldViewGraphic;
|
2009-04-16 14:14:13 +03:00
|
|
|
//buttons
|
|
|
|
ButtonInfo kingOverview, underground, questlog, sleepWake, moveHero, spellbook, advOptions,
|
|
|
|
sysOptions, nextHero, endTurn;
|
|
|
|
//hero list
|
|
|
|
int hlistX, hlistY, hlistSize;
|
|
|
|
std::string hlistMB, hlistMN, hlistAU, hlistAD;
|
|
|
|
//town list
|
|
|
|
int tlistX, tlistY, tlistSize;
|
|
|
|
std::string tlistAU, tlistAD;
|
|
|
|
//gems
|
|
|
|
int gemX[4], gemY[4];
|
|
|
|
std::vector<std::string> gemG;
|
2009-10-18 17:39:53 +03:00
|
|
|
//in-game console
|
2010-01-31 20:41:22 +02:00
|
|
|
int inputLineLength, outputLineLength;
|
2010-01-30 21:08:26 +02:00
|
|
|
//kingdom overview
|
|
|
|
int overviewPics, overviewSize; //pic count in def and count of visible slots
|
|
|
|
std::string overviewBg; //background name
|
2009-04-16 14:14:13 +03:00
|
|
|
};
|
2012-09-29 13:59:43 +03:00
|
|
|
struct DLL_LINKAGE GUIOptions
|
2009-04-16 14:14:13 +03:00
|
|
|
{
|
|
|
|
AdventureMapConfig ac;
|
|
|
|
};
|
2011-02-22 13:52:36 +02:00
|
|
|
/// Handles adventure map screen settings
|
2012-09-29 13:59:43 +03:00
|
|
|
class DLL_LINKAGE CConfigHandler
|
2009-04-16 14:14:13 +03:00
|
|
|
{
|
2011-08-24 07:13:45 +03:00
|
|
|
GUIOptions *current; // pointer to current gui options
|
|
|
|
|
2009-04-16 14:14:13 +03:00
|
|
|
public:
|
2012-01-12 18:23:00 +03:00
|
|
|
typedef std::map<std::pair<int,int>, GUIOptions > GuiOptionsMap;
|
|
|
|
GuiOptionsMap guiOptions;
|
2009-04-16 14:14:13 +03:00
|
|
|
void init();
|
2009-05-07 20:20:41 +03:00
|
|
|
CConfigHandler(void); //c-tor
|
|
|
|
~CConfigHandler(void); //d-tor
|
2011-08-24 07:13:45 +03:00
|
|
|
|
|
|
|
GUIOptions *go() { return current; };
|
2014-09-18 14:20:53 +03:00
|
|
|
void SetResolution(int x, int y)
|
|
|
|
{
|
|
|
|
std::pair<int,int> index(x, y);
|
|
|
|
if (guiOptions.count(index) == 0)
|
|
|
|
current = nullptr;
|
|
|
|
else
|
|
|
|
current = &guiOptions.at(index);
|
2011-08-24 07:13:45 +03:00
|
|
|
}
|
2009-04-16 14:14:13 +03:00
|
|
|
};
|
|
|
|
}
|
2012-01-12 18:23:00 +03:00
|
|
|
|
2012-09-29 13:59:43 +03:00
|
|
|
extern DLL_LINKAGE SettingsStorage settings;
|
|
|
|
extern DLL_LINKAGE config::CConfigHandler conf;
|