mirror of https://github.com/OpenTTD/OpenTTD
Codechange: use the shortname as unique id to identify the base graphics in openttd.cfg.
parent
97df27e41f
commit
0b7ecf6102
|
@ -188,7 +188,9 @@ public:
|
||||||
|
|
||||||
static Tbase_set *GetAvailableSets();
|
static Tbase_set *GetAvailableSets();
|
||||||
|
|
||||||
static bool SetSet(const std::string &name);
|
static bool SetSet(const Tbase_set *set);
|
||||||
|
static bool SetSetByName(const std::string &name);
|
||||||
|
static bool SetSetByShortname(uint32_t shortname);
|
||||||
static void GetSetsList(std::back_insert_iterator<std::string> &output_iterator);
|
static void GetSetsList(std::back_insert_iterator<std::string> &output_iterator);
|
||||||
static int GetNumSets();
|
static int GetNumSets();
|
||||||
static int GetIndexOfUsedSet();
|
static int GetIndexOfUsedSet();
|
||||||
|
@ -251,6 +253,7 @@ public:
|
||||||
/** Values loaded from config file. */
|
/** Values loaded from config file. */
|
||||||
struct Ini {
|
struct Ini {
|
||||||
std::string name;
|
std::string name;
|
||||||
|
uint32_t shortname; ///< unique key for base set
|
||||||
};
|
};
|
||||||
static inline Ini ini_data;
|
static inline Ini ini_data;
|
||||||
|
|
||||||
|
|
|
@ -226,25 +226,58 @@ bool BaseMedia<Tbase_set>::AddFile(const std::string &filename, size_t basepath_
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the set to be used.
|
||||||
|
* @param set the set to use
|
||||||
|
* @return true if it could be loaded
|
||||||
|
*/
|
||||||
|
template <class Tbase_set>
|
||||||
|
/* static */ bool BaseMedia<Tbase_set>::SetSet(const Tbase_set *set)
|
||||||
|
{
|
||||||
|
if (set == nullptr) {
|
||||||
|
if (!BaseMedia<Tbase_set>::DetermineBestSet()) return false;
|
||||||
|
} else {
|
||||||
|
BaseMedia<Tbase_set>::used_set = set;
|
||||||
|
}
|
||||||
|
CheckExternalFiles();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the set to be used.
|
* Set the set to be used.
|
||||||
* @param name of the set to use
|
* @param name of the set to use
|
||||||
* @return true if it could be loaded
|
* @return true if it could be loaded
|
||||||
*/
|
*/
|
||||||
template <class Tbase_set>
|
template <class Tbase_set>
|
||||||
/* static */ bool BaseMedia<Tbase_set>::SetSet(const std::string &name)
|
/* static */ bool BaseMedia<Tbase_set>::SetSetByName(const std::string &name)
|
||||||
{
|
{
|
||||||
if (name.empty()) {
|
if (name.empty()) {
|
||||||
if (!BaseMedia<Tbase_set>::DetermineBestSet()) return false;
|
return SetSet(nullptr);
|
||||||
CheckExternalFiles();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const Tbase_set *s = BaseMedia<Tbase_set>::available_sets; s != nullptr; s = s->next) {
|
for (const Tbase_set *s = BaseMedia<Tbase_set>::available_sets; s != nullptr; s = s->next) {
|
||||||
if (name == s->name) {
|
if (name == s->name) {
|
||||||
BaseMedia<Tbase_set>::used_set = s;
|
return SetSet(s);
|
||||||
CheckExternalFiles();
|
}
|
||||||
return true;
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the set to be used.
|
||||||
|
* @param shortname of the set to use
|
||||||
|
* @return true if it could be loaded
|
||||||
|
*/
|
||||||
|
template <class Tbase_set>
|
||||||
|
/* static */ bool BaseMedia<Tbase_set>::SetSetByShortname(uint32_t shortname)
|
||||||
|
{
|
||||||
|
if (shortname == 0) {
|
||||||
|
return SetSet(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const Tbase_set *s = BaseMedia<Tbase_set>::available_sets; s != nullptr; s = s->next) {
|
||||||
|
if (shortname == s->shortname) {
|
||||||
|
return SetSet(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -376,7 +409,9 @@ template <class Tbase_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); \
|
||||||
template bool repl_type::SetSet(const std::string &name); \
|
template bool repl_type::SetSet(const set_type *set); \
|
||||||
|
template bool repl_type::SetSetByName(const std::string &name); \
|
||||||
|
template bool repl_type::SetSetByShortname(uint32_t shortname); \
|
||||||
template void repl_type::GetSetsList(std::back_insert_iterator<std::string> &output_iterator); \
|
template void repl_type::GetSetsList(std::back_insert_iterator<std::string> &output_iterator); \
|
||||||
template int repl_type::GetNumSets(); \
|
template int repl_type::GetNumSets(); \
|
||||||
template int repl_type::GetIndexOfUsedSet(); \
|
template int repl_type::GetIndexOfUsedSet(); \
|
||||||
|
|
|
@ -173,7 +173,7 @@ void MusicSystem::ChangePlaylist(PlaylistChoices pl)
|
||||||
*/
|
*/
|
||||||
void MusicSystem::ChangeMusicSet(const std::string &set_name)
|
void MusicSystem::ChangeMusicSet(const std::string &set_name)
|
||||||
{
|
{
|
||||||
BaseMusic::SetSet(set_name);
|
BaseMusic::SetSetByName(set_name);
|
||||||
BaseMusic::ini_set = set_name;
|
BaseMusic::ini_set = set_name;
|
||||||
|
|
||||||
this->BuildPlaylists();
|
this->BuildPlaylists();
|
||||||
|
|
|
@ -702,10 +702,13 @@ int openttd_main(int argc, char *argv[])
|
||||||
BaseGraphics::FindSets();
|
BaseGraphics::FindSets();
|
||||||
bool valid_graphics_set;
|
bool valid_graphics_set;
|
||||||
if (!graphics_set.empty()) {
|
if (!graphics_set.empty()) {
|
||||||
valid_graphics_set = BaseGraphics::SetSet(graphics_set);
|
valid_graphics_set = BaseGraphics::SetSetByName(graphics_set);
|
||||||
|
} else if (BaseGraphics::ini_data.shortname != 0) {
|
||||||
|
graphics_set = BaseGraphics::ini_data.name;
|
||||||
|
valid_graphics_set = BaseGraphics::SetSetByShortname(BaseGraphics::ini_data.shortname);
|
||||||
} else if (!BaseGraphics::ini_data.name.empty()) {
|
} else if (!BaseGraphics::ini_data.name.empty()) {
|
||||||
graphics_set = BaseGraphics::ini_data.name;
|
graphics_set = BaseGraphics::ini_data.name;
|
||||||
valid_graphics_set = BaseGraphics::SetSet(BaseGraphics::ini_data.name);
|
valid_graphics_set = BaseGraphics::SetSetByName(BaseGraphics::ini_data.name);
|
||||||
} else {
|
} else {
|
||||||
valid_graphics_set = true;
|
valid_graphics_set = true;
|
||||||
BaseGraphics::SetSet(nullptr); // ignore error, continue to bootstrap GUI
|
BaseGraphics::SetSet(nullptr); // ignore error, continue to bootstrap GUI
|
||||||
|
@ -769,7 +772,7 @@ int openttd_main(int argc, char *argv[])
|
||||||
|
|
||||||
BaseSounds::FindSets();
|
BaseSounds::FindSets();
|
||||||
if (sounds_set.empty() && !BaseSounds::ini_set.empty()) sounds_set = BaseSounds::ini_set;
|
if (sounds_set.empty() && !BaseSounds::ini_set.empty()) sounds_set = BaseSounds::ini_set;
|
||||||
if (!BaseSounds::SetSet(sounds_set)) {
|
if (!BaseSounds::SetSetByName(sounds_set)) {
|
||||||
if (sounds_set.empty() || !BaseSounds::SetSet({})) {
|
if (sounds_set.empty() || !BaseSounds::SetSet({})) {
|
||||||
UserError("Failed to find a sounds set. Please acquire a sounds set for OpenTTD. See section 1.4 of README.md.");
|
UserError("Failed to find a sounds set. Please acquire a sounds set for OpenTTD. See section 1.4 of README.md.");
|
||||||
} else {
|
} else {
|
||||||
|
@ -781,7 +784,7 @@ int openttd_main(int argc, char *argv[])
|
||||||
|
|
||||||
BaseMusic::FindSets();
|
BaseMusic::FindSets();
|
||||||
if (music_set.empty() && !BaseMusic::ini_set.empty()) music_set = BaseMusic::ini_set;
|
if (music_set.empty() && !BaseMusic::ini_set.empty()) music_set = BaseMusic::ini_set;
|
||||||
if (!BaseMusic::SetSet(music_set)) {
|
if (!BaseMusic::SetSetByName(music_set)) {
|
||||||
if (music_set.empty() || !BaseMusic::SetSet({})) {
|
if (music_set.empty() || !BaseMusic::SetSet({})) {
|
||||||
UserError("Failed to find a music set. Please acquire a music set for OpenTTD. See section 1.4 of README.md.");
|
UserError("Failed to find a music set. Please acquire a music set for OpenTTD. See section 1.4 of README.md.");
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -995,6 +995,10 @@ static void GraphicsSetLoadConfig(IniFile &ini)
|
||||||
if (const IniGroup *group = ini.GetGroup("graphicsset"); group != nullptr) {
|
if (const IniGroup *group = ini.GetGroup("graphicsset"); group != nullptr) {
|
||||||
/* Load new settings. */
|
/* Load new settings. */
|
||||||
if (const IniItem *item = group->GetItem("name"); item != nullptr && item->value) BaseGraphics::ini_data.name = *item->value;
|
if (const IniItem *item = group->GetItem("name"); item != nullptr && item->value) BaseGraphics::ini_data.name = *item->value;
|
||||||
|
|
||||||
|
if (const IniItem *item = group->GetItem("shortname"); item != nullptr && item->value && item->value->size() == 8) {
|
||||||
|
BaseGraphics::ini_data.shortname = BSWAP32(std::strtoul(item->value->c_str(), nullptr, 16));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1182,6 +1186,7 @@ static void GraphicsSetSaveConfig(IniFile &ini)
|
||||||
group.Clear();
|
group.Clear();
|
||||||
|
|
||||||
group.GetOrCreateItem("name").SetValue(used_set->name);
|
group.GetOrCreateItem("name").SetValue(used_set->name);
|
||||||
|
group.GetOrCreateItem("shortname").SetValue(fmt::format("{:08X}", BSWAP32(used_set->shortname)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Save a GRF configuration to the given group name */
|
/* Save a GRF configuration to the given group name */
|
||||||
|
|
|
@ -693,7 +693,7 @@ struct GameOptionsWindow : Window {
|
||||||
case WID_GO_BASE_GRF_DROPDOWN:
|
case WID_GO_BASE_GRF_DROPDOWN:
|
||||||
if (_game_mode == GM_MENU) {
|
if (_game_mode == GM_MENU) {
|
||||||
auto* set = BaseGraphics::GetSet(index);
|
auto* set = BaseGraphics::GetSet(index);
|
||||||
BaseGraphics::SetSet(set->name);
|
BaseGraphics::SetSet(set);
|
||||||
this->reload = true;
|
this->reload = true;
|
||||||
this->InvalidateData();
|
this->InvalidateData();
|
||||||
}
|
}
|
||||||
|
@ -703,7 +703,7 @@ struct GameOptionsWindow : Window {
|
||||||
if (_game_mode == GM_MENU) {
|
if (_game_mode == GM_MENU) {
|
||||||
auto* set = BaseSounds::GetSet(index);
|
auto* set = BaseSounds::GetSet(index);
|
||||||
BaseSounds::ini_set = set->name;
|
BaseSounds::ini_set = set->name;
|
||||||
BaseSounds::SetSet(set->name);
|
BaseSounds::SetSet(set);
|
||||||
this->reload = true;
|
this->reload = true;
|
||||||
this->InvalidateData();
|
this->InvalidateData();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue