1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2025-12-19 11:12:44 +01:00

Fix: File/directory titles not updated if language is changed. (#14542)

This commit is contained in:
Peter Nelson
2025-08-28 17:42:00 +01:00
committed by GitHub
parent 2978cfa5c9
commit e6323e6760
7 changed files with 23 additions and 20 deletions

View File

@@ -569,7 +569,7 @@ static bool ConListFiles(std::span<std::string_view> argv)
_console_file_list_savegame.ValidateFileList(true); _console_file_list_savegame.ValidateFileList(true);
for (uint i = 0; i < _console_file_list_savegame.size(); i++) { for (uint i = 0; i < _console_file_list_savegame.size(); i++) {
IConsolePrint(CC_DEFAULT, "{}) {}", i, _console_file_list_savegame[i].title); IConsolePrint(CC_DEFAULT, "{}) {}", i, _console_file_list_savegame[i].title.GetDecodedString());
} }
return true; return true;
@@ -585,7 +585,7 @@ static bool ConListScenarios(std::span<std::string_view> argv)
_console_file_list_scenario.ValidateFileList(true); _console_file_list_scenario.ValidateFileList(true);
for (uint i = 0; i < _console_file_list_scenario.size(); i++) { for (uint i = 0; i < _console_file_list_scenario.size(); i++) {
IConsolePrint(CC_DEFAULT, "{}) {}", i, _console_file_list_scenario[i].title); IConsolePrint(CC_DEFAULT, "{}) {}", i, _console_file_list_scenario[i].title.GetDecodedString());
} }
return true; return true;
@@ -601,7 +601,7 @@ static bool ConListHeightmaps(std::span<std::string_view> argv)
_console_file_list_heightmap.ValidateFileList(true); _console_file_list_heightmap.ValidateFileList(true);
for (uint i = 0; i < _console_file_list_heightmap.size(); i++) { for (uint i = 0; i < _console_file_list_heightmap.size(); i++) {
IConsolePrint(CC_DEFAULT, "{}) {}", i, _console_file_list_heightmap[i].title); IConsolePrint(CC_DEFAULT, "{}) {}", i, _console_file_list_heightmap[i].title.GetDecodedString());
} }
return true; return true;

View File

@@ -52,7 +52,7 @@ bool FiosItem::operator< (const FiosItem &other) const
if ((_savegame_sort_order & SORT_BY_NAME) == 0 && (*this).mtime != other.mtime) { if ((_savegame_sort_order & SORT_BY_NAME) == 0 && (*this).mtime != other.mtime) {
r = ClampTo<int32_t>(this->mtime - other.mtime); r = ClampTo<int32_t>(this->mtime - other.mtime);
} else { } else {
r = StrNaturalCompare((*this).title, other.title); r = StrNaturalCompare(this->title.GetDecodedString(), other.title.GetDecodedString());
} }
if (r == 0) return false; if (r == 0) return false;
return (_savegame_sort_order & SORT_DESCENDING) ? r > 0 : r < 0; return (_savegame_sort_order & SORT_DESCENDING) ? r > 0 : r < 0;
@@ -105,7 +105,7 @@ const FiosItem *FileList::FindItem(std::string_view file)
for (const auto &it : *this) { for (const auto &it : *this) {
const FiosItem *item = &it; const FiosItem *item = &it;
if (file == item->name) return item; if (file == item->name) return item;
if (file == item->title) return item; if (file == item->title.GetDecodedString()) return item;
} }
/* If no name matches, try to parse it as number */ /* If no name matches, try to parse it as number */
@@ -120,7 +120,7 @@ const FiosItem *FileList::FindItem(std::string_view file)
for (const auto &it : *this) { for (const auto &it : *this) {
const FiosItem *item = &it; const FiosItem *item = &it;
if (long_file == item->name) return item; if (long_file == item->name) return item;
if (long_file == item->title) return item; if (long_file == item->title.GetDecodedString()) return item;
} }
return nullptr; return nullptr;
@@ -145,7 +145,7 @@ bool FiosBrowseTo(const FiosItem *item)
case DFT_FIOS_DRIVE: case DFT_FIOS_DRIVE:
#if defined(_WIN32) #if defined(_WIN32)
assert(_fios_path != nullptr); assert(_fios_path != nullptr);
*_fios_path = std::string{ item->title, 0, 1 } + ":" PATHSEP; *_fios_path = std::string{ item->name, 0, 1 } + ":" PATHSEP;
#endif #endif
break; break;
@@ -297,9 +297,9 @@ bool FiosFileScanner::AddFile(const std::string &filename, size_t, const std::st
/* If the file doesn't have a title, use its filename */ /* If the file doesn't have a title, use its filename */
if (title.empty()) { if (title.empty()) {
auto ps = filename.rfind(PATHSEPCHAR); auto ps = filename.rfind(PATHSEPCHAR);
fios->title = StrMakeValid(filename.substr((ps == std::string::npos ? 0 : ps + 1))); fios->title = GetEncodedString(STR_JUST_RAW_STRING, StrMakeValid(filename.substr((ps == std::string::npos ? 0 : ps + 1))));
} else { } else {
fios->title = StrMakeValid(title); fios->title = GetEncodedString(STR_JUST_RAW_STRING, StrMakeValid(title));
}; };
return true; return true;
@@ -329,7 +329,7 @@ static void FiosGetFileList(SaveLoadOperation fop, bool show_dirs, FiosGetTypeAn
fios.type = FIOS_TYPE_PARENT; fios.type = FIOS_TYPE_PARENT;
fios.mtime = 0; fios.mtime = 0;
fios.name = ".."; fios.name = "..";
fios.title = GetString(STR_SAVELOAD_PARENT_DIRECTORY, ".."sv); fios.title = GetEncodedString(STR_SAVELOAD_PARENT_DIRECTORY, ".."sv);
sort_start = file_list.size(); sort_start = file_list.size();
} }
@@ -343,7 +343,7 @@ static void FiosGetFileList(SaveLoadOperation fop, bool show_dirs, FiosGetTypeAn
fios.type = FIOS_TYPE_DIR; fios.type = FIOS_TYPE_DIR;
fios.mtime = 0; fios.mtime = 0;
fios.name = FS2OTTD(dir_entry.path().filename().native()); fios.name = FS2OTTD(dir_entry.path().filename().native());
fios.title = GetString(STR_SAVELOAD_DIRECTORY, fios.name + PATHSEP); fios.title = GetEncodedString(STR_SAVELOAD_DIRECTORY, fios.name + PATHSEP);
} }
/* Sort the subdirs always by name, ascending, remember user-sorting order */ /* Sort the subdirs always by name, ascending, remember user-sorting order */
@@ -736,7 +736,7 @@ FiosNumberedSaveName::FiosNumberedSaveName(const std::string &prefix) : prefix(p
std::sort(list.begin(), list.end()); std::sort(list.begin(), list.end());
_savegame_sort_order = order; _savegame_sort_order = order;
std::string_view name = list.begin()->title; std::string name = list.begin()->title.GetDecodedString();
std::from_chars(name.data() + this->prefix.size(), name.data() + name.size(), this->number); std::from_chars(name.data() + this->prefix.size(), name.data() + name.size(), this->number);
} }
} }

View File

@@ -78,7 +78,7 @@ extern LoadCheckData _load_check_data;
struct FiosItem { struct FiosItem {
FiosType type; FiosType type;
int64_t mtime; int64_t mtime;
std::string title; EncodedString title;
std::string name; std::string name;
bool operator< (const FiosItem &other) const; bool operator< (const FiosItem &other) const;
}; };

View File

@@ -514,7 +514,7 @@ public:
} else if (item == this->highlighted) { } else if (item == this->highlighted) {
GfxFillRect(br.left, tr.top, br.right, tr.bottom, PC_VERY_DARK_BLUE); GfxFillRect(br.left, tr.top, br.right, tr.bottom, PC_VERY_DARK_BLUE);
} }
DrawString(tr, item->title, _fios_colours[item->type.detailed]); DrawString(tr, item->title.GetDecodedString(), _fios_colours[item->type.detailed]);
tr = tr.Translate(0, this->resize.step_height); tr = tr.Translate(0, this->resize.step_height);
} }
break; break;
@@ -728,7 +728,7 @@ public:
} }
if (this->fop == SLO_SAVE) { if (this->fop == SLO_SAVE) {
/* Copy clicked name to editbox */ /* Copy clicked name to editbox */
this->filename_editbox.text.Assign(file->title); this->filename_editbox.text.Assign(file->title.GetDecodedString());
this->SetWidgetDirty(WID_SL_SAVE_OSK_TITLE); this->SetWidgetDirty(WID_SL_SAVE_OSK_TITLE);
} }
} else if (!_load_check_data.HasErrors()) { } else if (!_load_check_data.HasErrors()) {
@@ -860,7 +860,7 @@ public:
} else { } else {
for (auto &it : this->fios_items) { for (auto &it : this->fios_items) {
this->string_filter.ResetState(); this->string_filter.ResetState();
this->string_filter.AddLine(it.title); this->string_filter.AddLine(it.title.GetDecodedString());
/* We set the vector to show this fios element as filtered depending on the result of the filter */ /* We set the vector to show this fios element as filtered depending on the result of the filter */
if (this->string_filter.GetState()) { if (this->string_filter.GetState()) {
this->display_list.push_back(&it); this->display_list.push_back(&it);

View File

@@ -391,7 +391,7 @@ struct GenerateLandscapeWindow : public Window {
WidgetID widget_id{}; WidgetID widget_id{};
uint x = 0; uint x = 0;
uint y = 0; uint y = 0;
std::string name{}; EncodedString name{};
GenerateLandscapeWindowMode mode{}; GenerateLandscapeWindowMode mode{};
GenerateLandscapeWindow(WindowDesc &desc, WindowNumber number = 0) : Window(desc) GenerateLandscapeWindow(WindowDesc &desc, WindowNumber number = 0) : Window(desc)
@@ -467,7 +467,7 @@ struct GenerateLandscapeWindow : public Window {
} }
return GetString(_sea_lakes[_settings_newgame.difficulty.quantity_sea_lakes]); return GetString(_sea_lakes[_settings_newgame.difficulty.quantity_sea_lakes]);
case WID_GL_HEIGHTMAP_NAME_TEXT: return this->name; case WID_GL_HEIGHTMAP_NAME_TEXT: return this->name.GetDecodedString();
case WID_GL_RIVER_PULLDOWN: return GetString(_rivers[_settings_newgame.game_creation.amount_of_rivers]); case WID_GL_RIVER_PULLDOWN: return GetString(_rivers[_settings_newgame.game_creation.amount_of_rivers]);
case WID_GL_SMOOTHNESS_PULLDOWN: return GetString(_smoothness[_settings_newgame.game_creation.tgen_smoothness]); case WID_GL_SMOOTHNESS_PULLDOWN: return GetString(_smoothness[_settings_newgame.game_creation.tgen_smoothness]);
case WID_GL_VARIETY_PULLDOWN: return GetString(_variety[_settings_newgame.game_creation.variety]); case WID_GL_VARIETY_PULLDOWN: return GetString(_variety[_settings_newgame.game_creation.variety]);

View File

@@ -10,6 +10,7 @@
#include "../../stdafx.h" #include "../../stdafx.h"
#include "../../debug.h" #include "../../debug.h"
#include "../../gfx_func.h" #include "../../gfx_func.h"
#include "../../strings_func.h"
#include "../../textbuf_gui.h" #include "../../textbuf_gui.h"
#include "../../fileio_func.h" #include "../../fileio_func.h"
#include <windows.h> #include <windows.h>
@@ -29,6 +30,8 @@
#include "../../thread.h" #include "../../thread.h"
#include "../../library_loader.h" #include "../../library_loader.h"
#include "table/strings.h"
#include "../../safeguards.h" #include "../../safeguards.h"
static bool _has_console; static bool _has_console;
@@ -75,7 +78,7 @@ void FiosGetDrives(FileList &file_list)
fios->mtime = 0; fios->mtime = 0;
fios->name += (char)(s[0] & 0xFF); fios->name += (char)(s[0] & 0xFF);
fios->name += ':'; fios->name += ':';
fios->title = fios->name; fios->title = GetEncodedString(STR_JUST_RAW_STRING, fios->name);
while (*s++ != '\0') { /* Nothing */ } while (*s++ != '\0') { /* Nothing */ }
} }
} }

View File

@@ -424,7 +424,7 @@ struct FileToSaveLoad {
SaveLoadOperation file_op; ///< File operation to perform. SaveLoadOperation file_op; ///< File operation to perform.
FiosType ftype; ///< File type. FiosType ftype; ///< File type.
std::string name; ///< Name of the file. std::string name; ///< Name of the file.
std::string title; ///< Internal name of the game. EncodedString title; ///< Internal name of the game.
void SetMode(const FiosType &ft, SaveLoadOperation fop = SLO_LOAD); void SetMode(const FiosType &ft, SaveLoadOperation fop = SLO_LOAD);
void Set(const FiosItem &item); void Set(const FiosItem &item);