1
0
Fork 0

Change: Add fonts document to help window

pull/13437/head
merni-ns 2025-01-14 01:10:35 +05:30 committed by rubidium42
parent 20d1420d66
commit 2ab714b32e
5 changed files with 24 additions and 14 deletions

View File

@ -53,6 +53,7 @@ static const char * const _subdirs[] = {
"game" PATHSEP "library" PATHSEP, "game" PATHSEP "library" PATHSEP,
"screenshot" PATHSEP, "screenshot" PATHSEP,
"social_integration" PATHSEP, "social_integration" PATHSEP,
"docs" PATHSEP,
}; };
static_assert(lengthof(_subdirs) == NUM_SUBDIRS); static_assert(lengthof(_subdirs) == NUM_SUBDIRS);

View File

@ -129,6 +129,7 @@ enum Subdirectory : uint8_t {
GAME_LIBRARY_DIR, ///< Subdirectory for all GS libraries GAME_LIBRARY_DIR, ///< Subdirectory for all GS libraries
SCREENSHOT_DIR, ///< Subdirectory for all screenshots SCREENSHOT_DIR, ///< Subdirectory for all screenshots
SOCIAL_INTEGRATION_DIR, ///< Subdirectory for all social integration plugins SOCIAL_INTEGRATION_DIR, ///< Subdirectory for all social integration plugins
DOCS_DIR, ///< Subdirectory for documentation
NUM_SUBDIRS, ///< Number of subdirectories NUM_SUBDIRS, ///< Number of subdirectories
NO_DIRECTORY, ///< A path without any base directory NO_DIRECTORY, ///< A path without any base directory
}; };

View File

@ -26,6 +26,7 @@ static const std::string README_FILENAME = "README.md";
static const std::string CHANGELOG_FILENAME = "changelog.md"; static const std::string CHANGELOG_FILENAME = "changelog.md";
static const std::string KNOWN_BUGS_FILENAME = "known-bugs.md"; static const std::string KNOWN_BUGS_FILENAME = "known-bugs.md";
static const std::string LICENSE_FILENAME = "COPYING.md"; static const std::string LICENSE_FILENAME = "COPYING.md";
static const std::string FONTS_FILENAME = "fonts.md";
static const std::string WEBSITE_LINK = "https://www.openttd.org/"; static const std::string WEBSITE_LINK = "https://www.openttd.org/";
static const std::string WIKI_LINK = "https://wiki.openttd.org/"; static const std::string WIKI_LINK = "https://wiki.openttd.org/";
@ -41,14 +42,14 @@ static constexpr size_t CHANGELOG_VERSIONS_LIMIT = 20;
* @param filename The filename to find. * @param filename The filename to find.
* @return std::string The path to the filename if found. * @return std::string The path to the filename if found.
*/ */
static std::optional<std::string> FindGameManualFilePath(std::string_view filename) static std::optional<std::string> FindGameManualFilePath(std::string_view filename, Subdirectory subdir)
{ {
static const Searchpath searchpaths[] = { static const Searchpath searchpaths[] = {
SP_APPLICATION_BUNDLE_DIR, SP_INSTALLATION_DIR, SP_SHARED_DIR, SP_BINARY_DIR, SP_WORKING_DIR SP_APPLICATION_BUNDLE_DIR, SP_INSTALLATION_DIR, SP_SHARED_DIR, SP_BINARY_DIR, SP_WORKING_DIR
}; };
for (Searchpath sp : searchpaths) { for (Searchpath sp : searchpaths) {
auto file_path = FioGetDirectory(sp, BASE_DIR) + filename.data(); auto file_path = FioGetDirectory(sp, subdir) + filename.data();
if (FioCheckFileExists(file_path, NO_DIRECTORY)) return file_path; if (FioCheckFileExists(file_path, NO_DIRECTORY)) return file_path;
} }
@ -57,14 +58,14 @@ static std::optional<std::string> FindGameManualFilePath(std::string_view filena
/** Window class displaying the game manual textfile viewer. */ /** Window class displaying the game manual textfile viewer. */
struct GameManualTextfileWindow : public TextfileWindow { struct GameManualTextfileWindow : public TextfileWindow {
GameManualTextfileWindow(std::string_view filename) : TextfileWindow(TFT_GAME_MANUAL) GameManualTextfileWindow(std::string_view filename, Subdirectory subdir) : TextfileWindow(TFT_GAME_MANUAL)
{ {
this->ConstructWindow(); this->ConstructWindow();
/* Mark the content of these files as trusted. */ /* Mark the content of these files as trusted. */
this->trusted = true; this->trusted = true;
auto filepath = FindGameManualFilePath(filename); auto filepath = FindGameManualFilePath(filename, subdir);
/* The user could, in theory, have moved the file. So just show an empty window if that is the case. */ /* The user could, in theory, have moved the file. So just show an empty window if that is the case. */
if (!filepath.has_value()) { if (!filepath.has_value()) {
return; return;
@ -122,26 +123,30 @@ struct HelpWindow : public Window {
{ {
this->InitNested(number); this->InitNested(number);
this->EnableTextfileButton(README_FILENAME, WID_HW_README); this->EnableTextfileButton(README_FILENAME, BASE_DIR, WID_HW_README);
this->EnableTextfileButton(CHANGELOG_FILENAME, WID_HW_CHANGELOG); this->EnableTextfileButton(CHANGELOG_FILENAME, BASE_DIR, WID_HW_CHANGELOG);
this->EnableTextfileButton(KNOWN_BUGS_FILENAME, WID_HW_KNOWN_BUGS); this->EnableTextfileButton(KNOWN_BUGS_FILENAME, BASE_DIR, WID_HW_KNOWN_BUGS);
this->EnableTextfileButton(LICENSE_FILENAME, WID_HW_LICENSE); this->EnableTextfileButton(LICENSE_FILENAME, BASE_DIR, WID_HW_LICENSE);
this->EnableTextfileButton(FONTS_FILENAME, DOCS_DIR, WID_HW_FONTS);
} }
void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
{ {
switch (widget) { switch (widget) {
case WID_HW_README: case WID_HW_README:
new GameManualTextfileWindow(README_FILENAME); new GameManualTextfileWindow(README_FILENAME, BASE_DIR);
break; break;
case WID_HW_CHANGELOG: case WID_HW_CHANGELOG:
new GameManualTextfileWindow(CHANGELOG_FILENAME); new GameManualTextfileWindow(CHANGELOG_FILENAME, BASE_DIR);
break; break;
case WID_HW_KNOWN_BUGS: case WID_HW_KNOWN_BUGS:
new GameManualTextfileWindow(KNOWN_BUGS_FILENAME); new GameManualTextfileWindow(KNOWN_BUGS_FILENAME, BASE_DIR);
break; break;
case WID_HW_LICENSE: case WID_HW_LICENSE:
new GameManualTextfileWindow(LICENSE_FILENAME); new GameManualTextfileWindow(LICENSE_FILENAME, BASE_DIR);
break;
case WID_HW_FONTS:
new GameManualTextfileWindow(FONTS_FILENAME, DOCS_DIR);
break; break;
case WID_HW_WEBSITE: case WID_HW_WEBSITE:
OpenBrowser(WEBSITE_LINK); OpenBrowser(WEBSITE_LINK);
@ -159,9 +164,9 @@ struct HelpWindow : public Window {
} }
private: private:
void EnableTextfileButton(std::string_view filename, WidgetID button_widget) void EnableTextfileButton(std::string_view filename, Subdirectory subdir, WidgetID button_widget)
{ {
this->GetWidget<NWidgetLeaf>(button_widget)->SetDisabled(!FindGameManualFilePath(filename).has_value()); this->GetWidget<NWidgetLeaf>(button_widget)->SetDisabled(!FindGameManualFilePath(filename, subdir).has_value());
} }
}; };
@ -185,6 +190,7 @@ static constexpr NWidgetPart _nested_helpwin_widgets[] = {
NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_HW_CHANGELOG), SetStringTip(STR_HELP_WINDOW_CHANGELOG), SetMinimalSize(128, 12), SetFill(1, 0), NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_HW_CHANGELOG), SetStringTip(STR_HELP_WINDOW_CHANGELOG), SetMinimalSize(128, 12), SetFill(1, 0),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_HW_KNOWN_BUGS),SetStringTip(STR_HELP_WINDOW_KNOWN_BUGS), SetMinimalSize(128, 12), SetFill(1, 0), NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_HW_KNOWN_BUGS),SetStringTip(STR_HELP_WINDOW_KNOWN_BUGS), SetMinimalSize(128, 12), SetFill(1, 0),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_HW_LICENSE), SetStringTip(STR_HELP_WINDOW_LICENSE), SetMinimalSize(128, 12), SetFill(1, 0), NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_HW_LICENSE), SetStringTip(STR_HELP_WINDOW_LICENSE), SetMinimalSize(128, 12), SetFill(1, 0),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_HW_FONTS), SetStringTip(STR_HELP_WINDOW_FONTS), SetMinimalSize(128, 12), SetFill(1, 0),
EndContainer(), EndContainer(),
EndContainer(), EndContainer(),
EndContainer(), EndContainer(),

View File

@ -2248,6 +2248,7 @@ STR_HELP_WINDOW_README :{BLACK}Readme
STR_HELP_WINDOW_CHANGELOG :{BLACK}Changelog STR_HELP_WINDOW_CHANGELOG :{BLACK}Changelog
STR_HELP_WINDOW_KNOWN_BUGS :{BLACK}Known Bugs STR_HELP_WINDOW_KNOWN_BUGS :{BLACK}Known Bugs
STR_HELP_WINDOW_LICENSE :{BLACK}License STR_HELP_WINDOW_LICENSE :{BLACK}License
STR_HELP_WINDOW_FONTS :{BLACK}Fonts
STR_HELP_WINDOW_MAIN_WEBSITE :{BLACK}OpenTTD STR_HELP_WINDOW_MAIN_WEBSITE :{BLACK}OpenTTD
STR_HELP_WINDOW_MANUAL_WIKI :{BLACK}Manual / Wiki STR_HELP_WINDOW_MANUAL_WIKI :{BLACK}Manual / Wiki
STR_HELP_WINDOW_BUGTRACKER :{BLACK}Report a Bug STR_HELP_WINDOW_BUGTRACKER :{BLACK}Report a Bug

View File

@ -16,6 +16,7 @@ enum HelpWindowWidgets : WidgetID {
WID_HW_CHANGELOG, WID_HW_CHANGELOG,
WID_HW_KNOWN_BUGS, WID_HW_KNOWN_BUGS,
WID_HW_LICENSE, WID_HW_LICENSE,
WID_HW_FONTS,
WID_HW_WEBSITE, WID_HW_WEBSITE,
WID_HW_WIKI, WID_HW_WIKI,
WID_HW_BUGTRACKER, WID_HW_BUGTRACKER,