mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-08-29 17:39:09 +00:00
Fix: File/directory titles not updated if language is changed. (#14542)
This commit is contained in:
@@ -569,7 +569,7 @@ static bool ConListFiles(std::span<std::string_view> argv)
|
||||
|
||||
_console_file_list_savegame.ValidateFileList(true);
|
||||
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;
|
||||
@@ -585,7 +585,7 @@ static bool ConListScenarios(std::span<std::string_view> argv)
|
||||
|
||||
_console_file_list_scenario.ValidateFileList(true);
|
||||
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;
|
||||
@@ -601,7 +601,7 @@ static bool ConListHeightmaps(std::span<std::string_view> argv)
|
||||
|
||||
_console_file_list_heightmap.ValidateFileList(true);
|
||||
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;
|
||||
|
18
src/fios.cpp
18
src/fios.cpp
@@ -52,7 +52,7 @@ bool FiosItem::operator< (const FiosItem &other) const
|
||||
if ((_savegame_sort_order & SORT_BY_NAME) == 0 && (*this).mtime != other.mtime) {
|
||||
r = ClampTo<int32_t>(this->mtime - other.mtime);
|
||||
} else {
|
||||
r = StrNaturalCompare((*this).title, other.title);
|
||||
r = StrNaturalCompare(this->title.GetDecodedString(), other.title.GetDecodedString());
|
||||
}
|
||||
if (r == 0) return false;
|
||||
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) {
|
||||
const FiosItem *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 */
|
||||
@@ -120,7 +120,7 @@ const FiosItem *FileList::FindItem(std::string_view file)
|
||||
for (const auto &it : *this) {
|
||||
const FiosItem *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;
|
||||
@@ -145,7 +145,7 @@ bool FiosBrowseTo(const FiosItem *item)
|
||||
case DFT_FIOS_DRIVE:
|
||||
#if defined(_WIN32)
|
||||
assert(_fios_path != nullptr);
|
||||
*_fios_path = std::string{ item->title, 0, 1 } + ":" PATHSEP;
|
||||
*_fios_path = std::string{ item->name, 0, 1 } + ":" PATHSEP;
|
||||
#endif
|
||||
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 (title.empty()) {
|
||||
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 {
|
||||
fios->title = StrMakeValid(title);
|
||||
fios->title = GetEncodedString(STR_JUST_RAW_STRING, StrMakeValid(title));
|
||||
};
|
||||
|
||||
return true;
|
||||
@@ -329,7 +329,7 @@ static void FiosGetFileList(SaveLoadOperation fop, bool show_dirs, FiosGetTypeAn
|
||||
fios.type = FIOS_TYPE_PARENT;
|
||||
fios.mtime = 0;
|
||||
fios.name = "..";
|
||||
fios.title = GetString(STR_SAVELOAD_PARENT_DIRECTORY, ".."sv);
|
||||
fios.title = GetEncodedString(STR_SAVELOAD_PARENT_DIRECTORY, ".."sv);
|
||||
sort_start = file_list.size();
|
||||
}
|
||||
|
||||
@@ -343,7 +343,7 @@ static void FiosGetFileList(SaveLoadOperation fop, bool show_dirs, FiosGetTypeAn
|
||||
fios.type = FIOS_TYPE_DIR;
|
||||
fios.mtime = 0;
|
||||
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 */
|
||||
@@ -736,7 +736,7 @@ FiosNumberedSaveName::FiosNumberedSaveName(const std::string &prefix) : prefix(p
|
||||
std::sort(list.begin(), list.end());
|
||||
_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);
|
||||
}
|
||||
}
|
||||
|
@@ -78,7 +78,7 @@ extern LoadCheckData _load_check_data;
|
||||
struct FiosItem {
|
||||
FiosType type;
|
||||
int64_t mtime;
|
||||
std::string title;
|
||||
EncodedString title;
|
||||
std::string name;
|
||||
bool operator< (const FiosItem &other) const;
|
||||
};
|
||||
|
@@ -514,7 +514,7 @@ public:
|
||||
} else if (item == this->highlighted) {
|
||||
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);
|
||||
}
|
||||
break;
|
||||
@@ -728,7 +728,7 @@ public:
|
||||
}
|
||||
if (this->fop == SLO_SAVE) {
|
||||
/* 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);
|
||||
}
|
||||
} else if (!_load_check_data.HasErrors()) {
|
||||
@@ -860,7 +860,7 @@ public:
|
||||
} else {
|
||||
for (auto &it : this->fios_items) {
|
||||
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 */
|
||||
if (this->string_filter.GetState()) {
|
||||
this->display_list.push_back(&it);
|
||||
|
@@ -391,7 +391,7 @@ struct GenerateLandscapeWindow : public Window {
|
||||
WidgetID widget_id{};
|
||||
uint x = 0;
|
||||
uint y = 0;
|
||||
std::string name{};
|
||||
EncodedString name{};
|
||||
GenerateLandscapeWindowMode mode{};
|
||||
|
||||
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]);
|
||||
|
||||
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_SMOOTHNESS_PULLDOWN: return GetString(_smoothness[_settings_newgame.game_creation.tgen_smoothness]);
|
||||
case WID_GL_VARIETY_PULLDOWN: return GetString(_variety[_settings_newgame.game_creation.variety]);
|
||||
|
@@ -10,6 +10,7 @@
|
||||
#include "../../stdafx.h"
|
||||
#include "../../debug.h"
|
||||
#include "../../gfx_func.h"
|
||||
#include "../../strings_func.h"
|
||||
#include "../../textbuf_gui.h"
|
||||
#include "../../fileio_func.h"
|
||||
#include <windows.h>
|
||||
@@ -29,6 +30,8 @@
|
||||
#include "../../thread.h"
|
||||
#include "../../library_loader.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
static bool _has_console;
|
||||
@@ -75,7 +78,7 @@ void FiosGetDrives(FileList &file_list)
|
||||
fios->mtime = 0;
|
||||
fios->name += (char)(s[0] & 0xFF);
|
||||
fios->name += ':';
|
||||
fios->title = fios->name;
|
||||
fios->title = GetEncodedString(STR_JUST_RAW_STRING, fios->name);
|
||||
while (*s++ != '\0') { /* Nothing */ }
|
||||
}
|
||||
}
|
||||
|
@@ -424,7 +424,7 @@ struct FileToSaveLoad {
|
||||
SaveLoadOperation file_op; ///< File operation to perform.
|
||||
FiosType ftype; ///< File type.
|
||||
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 Set(const FiosItem &item);
|
||||
|
Reference in New Issue
Block a user