Changeset - r28056:26f1b214d694
[Not reviewed]
master
0 6 0
frosch - 14 months ago 2023-10-02 11:29:32
frosch@openttd.org
Codechange: Store base graphics settings in a separate section in openttd.cfg.
6 files changed with 76 insertions and 41 deletions:
0 comments (0 inline, 0 general)
src/base_media_base.h
Show inline comments
 
@@ -170,9 +170,6 @@ protected:
 
	 */
 
	static const char *GetExtension();
 
public:
 
	/** The set as saved in the config file. */
 
	static std::string ini_set;
 

	
 
	/**
 
	 * Determine the graphics pack that has to be used.
 
	 * The one with the most correct files wins.
 
@@ -207,7 +204,6 @@ public:
 
	static bool HasSet(const ContentInfo *ci, bool md5sum);
 
};
 

	
 
template <class Tbase_set> /* static */ std::string BaseMedia<Tbase_set>::ini_set;
 
template <class Tbase_set> /* static */ const Tbase_set *BaseMedia<Tbase_set>::used_set;
 
template <class Tbase_set> /* static */ Tbase_set *BaseMedia<Tbase_set>::available_sets;
 
template <class Tbase_set> /* static */ Tbase_set *BaseMedia<Tbase_set>::duplicate_sets;
 
@@ -252,6 +248,12 @@ struct GraphicsSet : BaseSet<GraphicsSet
 
/** All data/functions related with replacing the base graphics. */
 
class BaseGraphics : public BaseMedia<GraphicsSet> {
 
public:
 
	/** Values loaded from config file. */
 
	struct Ini {
 
		std::string name;
 
	};
 
	static inline Ini ini_data;
 

	
 
};
 

	
 
/** All data of a sounds set. */
 
@@ -261,6 +263,9 @@ struct SoundsSet : BaseSet<SoundsSet, 1,
 
/** All data/functions related with replacing the base sounds */
 
class BaseSounds : public BaseMedia<SoundsSet> {
 
public:
 
	/** The set as saved in the config file. */
 
	static inline std::string ini_set;
 

	
 
};
 

	
 
/** Maximum number of songs in the 'class' playlists. */
 
@@ -307,6 +312,9 @@ struct MusicSet : BaseSet<MusicSet, NUM_
 
/** All data/functions related with replacing the base music */
 
class BaseMusic : public BaseMedia<MusicSet> {
 
public:
 
	/** The set as saved in the config file. */
 
	static inline std::string ini_set;
 

	
 
};
 

	
 
#endif /* BASE_MEDIA_BASE_H */
src/base_media_func.h
Show inline comments
 
@@ -373,7 +373,6 @@ template <class Tbase_set>
 
 * @param set_type  the type of the BaseSet to instantiate
 
 */
 
#define INSTANTIATE_BASE_MEDIA_METHODS(repl_type, set_type) \
 
	template std::string repl_type::ini_set; \
 
	template const char *repl_type::GetExtension(); \
 
	template bool repl_type::AddFile(const std::string &filename, size_t pathlength, const std::string &tar_filename); \
 
	template bool repl_type::HasSet(const struct ContentInfo *ci, bool md5sum); \
src/openttd.cpp
Show inline comments
 
@@ -700,15 +700,22 @@ int openttd_main(int argc, char *argv[])
 
	InitWindowSystem();
 

	
 
	BaseGraphics::FindSets();
 
	if (graphics_set.empty() && !BaseGraphics::ini_set.empty()) graphics_set = BaseGraphics::ini_set;
 
	if (!BaseGraphics::SetSet(graphics_set)) {
 
		if (!graphics_set.empty()) {
 
			BaseGraphics::SetSet({});
 
	bool valid_graphics_set;
 
	if (!graphics_set.empty()) {
 
		valid_graphics_set = BaseGraphics::SetSet(graphics_set);
 
	} else if (!BaseGraphics::ini_data.name.empty()) {
 
		graphics_set = BaseGraphics::ini_data.name;
 
		valid_graphics_set = BaseGraphics::SetSet(BaseGraphics::ini_data.name);
 
	} else {
 
		valid_graphics_set = true;
 
		BaseGraphics::SetSet(nullptr); // ignore error, continue to bootstrap GUI
 
	}
 
	if (!valid_graphics_set) {
 
		BaseGraphics::SetSet(nullptr);
 

	
 
			ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_BASE_GRAPHICS_NOT_FOUND);
 
			msg.SetDParamStr(0, graphics_set);
 
			ScheduleErrorMessage(msg);
 
		}
 
		ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_BASE_GRAPHICS_NOT_FOUND);
 
		msg.SetDParamStr(0, graphics_set);
 
		ScheduleErrorMessage(msg);
 
	}
 

	
 
	/* Initialize game palette */
src/settings.cpp
Show inline comments
 
@@ -42,6 +42,7 @@
 
#include "ai/ai_config.hpp"
 
#include "game/game_config.hpp"
 
#include "newgrf_config.h"
 
#include "base_media_base.h"
 
#include "fios.h"
 
#include "fileio_func.h"
 
#include "settings_cmd.h"
 
@@ -982,6 +983,22 @@ static bool DecodeHexText(const char *po
 
}
 

	
 
/**
 
 * Load BaseGraphics set selection and configuration.
 
 */
 
static void GraphicsSetLoadConfig(IniFile &ini)
 
{
 
	if (const IniGroup *group = ini.GetGroup("misc"); group != nullptr) {
 
		/* Load old setting first. */
 
		if (const IniItem *item = group->GetItem("graphicsset"); item != nullptr && item->value) BaseGraphics::ini_data.name = *item->value;
 
	}
 

	
 
	if (const IniGroup *group = ini.GetGroup("graphicsset"); group != nullptr) {
 
		/* Load new settings. */
 
		if (const IniItem *item = group->GetItem("name"); item != nullptr && item->value) BaseGraphics::ini_data.name = *item->value;
 
	}
 
}
 

	
 
/**
 
 * Load a GRF configuration
 
 * @param ini       The configuration to read from.
 
 * @param grpname   Group name containing the configuration of the GRF.
 
@@ -1153,6 +1170,20 @@ static void SaveVersionInConfig(IniFile 
 
	group.GetOrCreateItem("ini_version").SetValue(std::to_string(INIFILE_VERSION));
 
}
 

	
 
/**
 
 * Save BaseGraphics set selection and configuration.
 
 */
 
static void GraphicsSetSaveConfig(IniFile &ini)
 
{
 
	const GraphicsSet *used_set = BaseGraphics::GetUsedSet();
 
	if (used_set == nullptr) return;
 

	
 
	IniGroup &group = ini.GetOrCreateGroup("graphicsset");
 
	group.Clear();
 

	
 
	group.GetOrCreateItem("name").SetValue(used_set->name);
 
}
 

	
 
/* Save a GRF configuration to the given group name */
 
static void GRFSaveConfig(IniFile &ini, const char *grpname, const GRFConfig *list)
 
{
 
@@ -1285,6 +1316,10 @@ void LoadFromConfig(bool startup)
 

	
 
	IniFileVersion generic_version = LoadVersionFromConfig(generic_ini);
 

	
 
	if (startup) {
 
		GraphicsSetLoadConfig(generic_ini);
 
	}
 

	
 
	/* Before the split of private/secrets, we have to look in the generic for these settings. */
 
	if (generic_version < IFV_PRIVATE_SECRETS) {
 
		HandleSettingDescs(generic_ini, generic_ini, generic_ini, IniLoadSettings, IniLoadSettingList, startup);
 
@@ -1416,6 +1451,7 @@ void SaveToConfig()
 
	}
 

	
 
	HandleSettingDescs(generic_ini, private_ini, secrets_ini, IniSaveSettings, IniSaveSettingList);
 
	GraphicsSetSaveConfig(generic_ini);
 
	GRFSaveConfig(generic_ini, "newgrf", _grfconfig_newgame);
 
	GRFSaveConfig(generic_ini, "newgrf-static", _grfconfig_static);
 
	AISaveConfig(generic_ini, "ai_players");
src/settings_gui.cpp
Show inline comments
 
@@ -649,25 +649,6 @@ struct GameOptionsWindow : Window {
 
		}
 
	}
 

	
 
	/**
 
	 * Set the base media set.
 
	 * @param index the index of the media set
 
	 * @tparam T class of media set
 
	 */
 
	template <class T>
 
	void SetMediaSet(int index)
 
	{
 
		if (_game_mode == GM_MENU) {
 
			auto name = T::GetSet(index)->name;
 

	
 
			T::ini_set = name;
 

	
 
			T::SetSet(name);
 
			this->reload = true;
 
			this->InvalidateData();
 
		}
 
	}
 

	
 
	void OnDropdownSelect(int widget, int index) override
 
	{
 
		switch (widget) {
 
@@ -710,11 +691,22 @@ struct GameOptionsWindow : Window {
 
			}
 

	
 
			case WID_GO_BASE_GRF_DROPDOWN:
 
				this->SetMediaSet<BaseGraphics>(index);
 
				if (_game_mode == GM_MENU) {
 
					auto* set = BaseGraphics::GetSet(index);
 
					BaseGraphics::SetSet(set->name);
 
					this->reload = true;
 
					this->InvalidateData();
 
				}
 
				break;
 

	
 
			case WID_GO_BASE_SFX_DROPDOWN:
 
				this->SetMediaSet<BaseSounds>(index);
 
				if (_game_mode == GM_MENU) {
 
					auto* set = BaseSounds::GetSet(index);
 
					BaseSounds::ini_set = set->name;
 
					BaseSounds::SetSet(set->name);
 
					this->reload = true;
 
					this->InvalidateData();
 
				}
 
				break;
 

	
 
			case WID_GO_BASE_MUSIC_DROPDOWN:
src/table/settings/misc_settings.ini
Show inline comments
 
@@ -95,13 +95,6 @@ full     = _support8bppmodes
 
cat      = SC_BASIC
 

	
 
[SDTG_SSTR]
 
name     = ""graphicsset""
 
type     = SLE_STRQ
 
var      = BaseGraphics::ini_set
 
def      = nullptr
 
cat      = SC_BASIC
 

	
 
[SDTG_SSTR]
 
name     = ""soundsset""
 
type     = SLE_STRQ
 
var      = BaseSounds::ini_set
0 comments (0 inline, 0 general)