mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Store base graphics settings in a separate section in openttd.cfg.
parent
2d3fef3113
commit
97df27e41f
|
@ -170,9 +170,6 @@ protected:
|
||||||
*/
|
*/
|
||||||
static const char *GetExtension();
|
static const char *GetExtension();
|
||||||
public:
|
public:
|
||||||
/** The set as saved in the config file. */
|
|
||||||
static std::string ini_set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine the graphics pack that has to be used.
|
* Determine the graphics pack that has to be used.
|
||||||
* The one with the most correct files wins.
|
* The one with the most correct files wins.
|
||||||
|
@ -207,7 +204,6 @@ public:
|
||||||
static bool HasSet(const ContentInfo *ci, bool md5sum);
|
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 */ 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>::available_sets;
|
||||||
template <class Tbase_set> /* static */ Tbase_set *BaseMedia<Tbase_set>::duplicate_sets;
|
template <class Tbase_set> /* static */ Tbase_set *BaseMedia<Tbase_set>::duplicate_sets;
|
||||||
|
@ -252,6 +248,12 @@ struct GraphicsSet : BaseSet<GraphicsSet, MAX_GFT, true> {
|
||||||
/** All data/functions related with replacing the base graphics. */
|
/** All data/functions related with replacing the base graphics. */
|
||||||
class BaseGraphics : public BaseMedia<GraphicsSet> {
|
class BaseGraphics : public BaseMedia<GraphicsSet> {
|
||||||
public:
|
public:
|
||||||
|
/** Values loaded from config file. */
|
||||||
|
struct Ini {
|
||||||
|
std::string name;
|
||||||
|
};
|
||||||
|
static inline Ini ini_data;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** All data of a sounds set. */
|
/** All data of a sounds set. */
|
||||||
|
@ -261,6 +263,9 @@ struct SoundsSet : BaseSet<SoundsSet, 1, true> {
|
||||||
/** All data/functions related with replacing the base sounds */
|
/** All data/functions related with replacing the base sounds */
|
||||||
class BaseSounds : public BaseMedia<SoundsSet> {
|
class BaseSounds : public BaseMedia<SoundsSet> {
|
||||||
public:
|
public:
|
||||||
|
/** The set as saved in the config file. */
|
||||||
|
static inline std::string ini_set;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Maximum number of songs in the 'class' playlists. */
|
/** Maximum number of songs in the 'class' playlists. */
|
||||||
|
@ -307,6 +312,9 @@ struct MusicSet : BaseSet<MusicSet, NUM_SONGS_AVAILABLE, false> {
|
||||||
/** All data/functions related with replacing the base music */
|
/** All data/functions related with replacing the base music */
|
||||||
class BaseMusic : public BaseMedia<MusicSet> {
|
class BaseMusic : public BaseMedia<MusicSet> {
|
||||||
public:
|
public:
|
||||||
|
/** The set as saved in the config file. */
|
||||||
|
static inline std::string ini_set;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* BASE_MEDIA_BASE_H */
|
#endif /* BASE_MEDIA_BASE_H */
|
||||||
|
|
|
@ -373,7 +373,6 @@ template <class Tbase_set>
|
||||||
* @param set_type the type of the BaseSet to instantiate
|
* @param set_type the type of the BaseSet to instantiate
|
||||||
*/
|
*/
|
||||||
#define INSTANTIATE_BASE_MEDIA_METHODS(repl_type, set_type) \
|
#define INSTANTIATE_BASE_MEDIA_METHODS(repl_type, set_type) \
|
||||||
template std::string repl_type::ini_set; \
|
|
||||||
template const char *repl_type::GetExtension(); \
|
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::AddFile(const std::string &filename, size_t pathlength, const std::string &tar_filename); \
|
||||||
template bool repl_type::HasSet(const struct ContentInfo *ci, bool md5sum); \
|
template bool repl_type::HasSet(const struct ContentInfo *ci, bool md5sum); \
|
||||||
|
|
|
@ -700,15 +700,22 @@ int openttd_main(int argc, char *argv[])
|
||||||
InitWindowSystem();
|
InitWindowSystem();
|
||||||
|
|
||||||
BaseGraphics::FindSets();
|
BaseGraphics::FindSets();
|
||||||
if (graphics_set.empty() && !BaseGraphics::ini_set.empty()) graphics_set = BaseGraphics::ini_set;
|
bool valid_graphics_set;
|
||||||
if (!BaseGraphics::SetSet(graphics_set)) {
|
if (!graphics_set.empty()) {
|
||||||
if (!graphics_set.empty()) {
|
valid_graphics_set = BaseGraphics::SetSet(graphics_set);
|
||||||
BaseGraphics::SetSet({});
|
} 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);
|
ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_BASE_GRAPHICS_NOT_FOUND);
|
||||||
msg.SetDParamStr(0, graphics_set);
|
msg.SetDParamStr(0, graphics_set);
|
||||||
ScheduleErrorMessage(msg);
|
ScheduleErrorMessage(msg);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize game palette */
|
/* Initialize game palette */
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
#include "ai/ai_config.hpp"
|
#include "ai/ai_config.hpp"
|
||||||
#include "game/game_config.hpp"
|
#include "game/game_config.hpp"
|
||||||
#include "newgrf_config.h"
|
#include "newgrf_config.h"
|
||||||
|
#include "base_media_base.h"
|
||||||
#include "fios.h"
|
#include "fios.h"
|
||||||
#include "fileio_func.h"
|
#include "fileio_func.h"
|
||||||
#include "settings_cmd.h"
|
#include "settings_cmd.h"
|
||||||
|
@ -981,6 +982,22 @@ static bool DecodeHexText(const char *pos, uint8_t *dest, size_t dest_size)
|
||||||
return *pos == '|';
|
return *pos == '|';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* Load a GRF configuration
|
||||||
* @param ini The configuration to read from.
|
* @param ini The configuration to read from.
|
||||||
|
@ -1153,6 +1170,20 @@ static void SaveVersionInConfig(IniFile &ini)
|
||||||
group.GetOrCreateItem("ini_version").SetValue(std::to_string(INIFILE_VERSION));
|
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 */
|
/* Save a GRF configuration to the given group name */
|
||||||
static void GRFSaveConfig(IniFile &ini, const char *grpname, const GRFConfig *list)
|
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);
|
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. */
|
/* Before the split of private/secrets, we have to look in the generic for these settings. */
|
||||||
if (generic_version < IFV_PRIVATE_SECRETS) {
|
if (generic_version < IFV_PRIVATE_SECRETS) {
|
||||||
HandleSettingDescs(generic_ini, generic_ini, generic_ini, IniLoadSettings, IniLoadSettingList, startup);
|
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);
|
HandleSettingDescs(generic_ini, private_ini, secrets_ini, IniSaveSettings, IniSaveSettingList);
|
||||||
|
GraphicsSetSaveConfig(generic_ini);
|
||||||
GRFSaveConfig(generic_ini, "newgrf", _grfconfig_newgame);
|
GRFSaveConfig(generic_ini, "newgrf", _grfconfig_newgame);
|
||||||
GRFSaveConfig(generic_ini, "newgrf-static", _grfconfig_static);
|
GRFSaveConfig(generic_ini, "newgrf-static", _grfconfig_static);
|
||||||
AISaveConfig(generic_ini, "ai_players");
|
AISaveConfig(generic_ini, "ai_players");
|
||||||
|
|
|
@ -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
|
void OnDropdownSelect(int widget, int index) override
|
||||||
{
|
{
|
||||||
switch (widget) {
|
switch (widget) {
|
||||||
|
@ -710,11 +691,22 @@ struct GameOptionsWindow : Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
case WID_GO_BASE_GRF_DROPDOWN:
|
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;
|
break;
|
||||||
|
|
||||||
case WID_GO_BASE_SFX_DROPDOWN:
|
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;
|
break;
|
||||||
|
|
||||||
case WID_GO_BASE_MUSIC_DROPDOWN:
|
case WID_GO_BASE_MUSIC_DROPDOWN:
|
||||||
|
|
|
@ -94,13 +94,6 @@ max = 2
|
||||||
full = _support8bppmodes
|
full = _support8bppmodes
|
||||||
cat = SC_BASIC
|
cat = SC_BASIC
|
||||||
|
|
||||||
[SDTG_SSTR]
|
|
||||||
name = ""graphicsset""
|
|
||||||
type = SLE_STRQ
|
|
||||||
var = BaseGraphics::ini_set
|
|
||||||
def = nullptr
|
|
||||||
cat = SC_BASIC
|
|
||||||
|
|
||||||
[SDTG_SSTR]
|
[SDTG_SSTR]
|
||||||
name = ""soundsset""
|
name = ""soundsset""
|
||||||
type = SLE_STRQ
|
type = SLE_STRQ
|
||||||
|
|
Loading…
Reference in New Issue