diff --git a/libraries/ZWidget/include/zwidget/core/resourcedata.h b/libraries/ZWidget/include/zwidget/core/resourcedata.h index 17627dabe9..f29ab261e5 100644 --- a/libraries/ZWidget/include/zwidget/core/resourcedata.h +++ b/libraries/ZWidget/include/zwidget/core/resourcedata.h @@ -11,4 +11,4 @@ struct SingleFontData }; std::vector LoadWidgetFontData(const std::string& name); -std::vector LoadWidgetImageData(const std::string& name); +std::vector LoadWidgetData(const std::string& name); diff --git a/libraries/ZWidget/include/zwidget/widgets/listview/listview.h b/libraries/ZWidget/include/zwidget/widgets/listview/listview.h index c7caca8d44..879bda114d 100644 --- a/libraries/ZWidget/include/zwidget/widgets/listview/listview.h +++ b/libraries/ZWidget/include/zwidget/widgets/listview/listview.h @@ -19,6 +19,7 @@ public: void Activate(); + std::function OnChanged; std::function OnActivated; protected: diff --git a/libraries/ZWidget/src/core/canvas.cpp b/libraries/ZWidget/src/core/canvas.cpp index d952191e5a..76c7a16e79 100644 --- a/libraries/ZWidget/src/core/canvas.cpp +++ b/libraries/ZWidget/src/core/canvas.cpp @@ -249,7 +249,7 @@ BitmapCanvas::BitmapCanvas(DisplayWindow* window) : window(window) uiscale = window->GetDpiScale(); uint32_t white = 0xffffffff; whiteTexture = createTexture(1, 1, &white); - font = std::make_unique("NotoSans", 15.0 * uiscale); + font = std::make_unique("NotoSans", 13.0 * uiscale); } BitmapCanvas::~BitmapCanvas() diff --git a/libraries/ZWidget/src/core/image.cpp b/libraries/ZWidget/src/core/image.cpp index 91e201a47f..3998d78e81 100644 --- a/libraries/ZWidget/src/core/image.cpp +++ b/libraries/ZWidget/src/core/image.cpp @@ -62,7 +62,7 @@ std::shared_ptr Image::LoadResource(const std::string& resourcename, doub if (extension == "png") { - auto filedata = LoadWidgetImageData(resourcename); + auto filedata = LoadWidgetData(resourcename); std::vector pixels; unsigned long width = 0, height = 0; @@ -74,7 +74,7 @@ std::shared_ptr Image::LoadResource(const std::string& resourcename, doub } else if (extension == "svg") { - auto filedata = LoadWidgetImageData(resourcename); + auto filedata = LoadWidgetData(resourcename); filedata.push_back(0); NSVGimage* svgimage = nsvgParse((char*)filedata.data(), "px", (float)(96.0 * dpiscale)); diff --git a/libraries/ZWidget/src/widgets/listview/listview.cpp b/libraries/ZWidget/src/widgets/listview/listview.cpp index 43212771fe..680b41d143 100644 --- a/libraries/ZWidget/src/widgets/listview/listview.cpp +++ b/libraries/ZWidget/src/widgets/listview/listview.cpp @@ -27,6 +27,7 @@ void ListView::SetSelectedItem(int index) if (selectedItem != index && index >= 0 && index < items.size()) { selectedItem = index; + if (OnChanged) OnChanged(selectedItem); Update(); } } diff --git a/src/common/widgets/widgetresourcedata.cpp b/src/common/widgets/widgetresourcedata.cpp index 1b04e66fc8..73adb14e04 100644 --- a/src/common/widgets/widgetresourcedata.cpp +++ b/src/common/widgets/widgetresourcedata.cpp @@ -81,7 +81,7 @@ std::vector LoadWidgetFontData(const std::string& name) return returnv; } -std::vector LoadWidgetImageData(const std::string& name) +std::vector LoadWidgetData(const std::string& name) { return LoadFile(name.c_str()); } diff --git a/src/launcher/launcherwindow.cpp b/src/launcher/launcherwindow.cpp index 87bbd2b1f1..48d1e5b7d9 100644 --- a/src/launcher/launcherwindow.cpp +++ b/src/launcher/launcherwindow.cpp @@ -3,6 +3,7 @@ #include "version.h" #include "i_interface.h" #include "gstrings.h" +#include #include #include #include @@ -17,13 +18,14 @@ EXTERN_CVAR(Int, vid_preferbackend); #endif +EXTERN_CVAR(String, language) EXTERN_CVAR(Bool, queryiwad); int LauncherWindow::ExecModal(WadStuff* wads, int numwads, int defaultiwad, int* autoloadflags) { Size screenSize = GetScreenSize(); double windowWidth = 615.0; - double windowHeight = 668.0; + double windowHeight = 700.0; auto launcher = std::make_unique(wads, numwads, defaultiwad, autoloadflags); launcher->SetFrameGeometry((screenSize.width - windowWidth) * 0.5, (screenSize.height - windowHeight) * 0.5, windowWidth, windowHeight); @@ -34,36 +36,9 @@ int LauncherWindow::ExecModal(WadStuff* wads, int numwads, int defaultiwad, int* return launcher->ExecResult; } -LauncherWindow::LauncherWindow(WadStuff* wads, int numwads, int defaultiwad, int* autoloadflags) : Widget(nullptr, WidgetType::Window), AutoloadFlags(autoloadflags) +void LauncherWindow::UpdateLanguage() { - SetWindowBackground(Colorf::fromRgba8(51, 51, 51)); - SetWindowBorderColor(Colorf::fromRgba8(51, 51, 51)); - SetWindowCaptionColor(Colorf::fromRgba8(33, 33, 33)); - SetWindowCaptionTextColor(Colorf::fromRgba8(226, 223, 219)); - SetWindowTitle(GAMENAME); - - Logo = new ImageBox(this); - WelcomeLabel = new TextLabel(this); - VersionLabel = new TextLabel(this); - SelectLabel = new TextLabel(this); - GeneralLabel = new TextLabel(this); - ExtrasLabel = new TextLabel(this); - ParametersLabel = new TextLabel(this); - FullscreenCheckbox = new CheckboxLabel(this); - DisableAutoloadCheckbox = new CheckboxLabel(this); - DontAskAgainCheckbox = new CheckboxLabel(this); - LightsCheckbox = new CheckboxLabel(this); - BrightmapsCheckbox = new CheckboxLabel(this); - WidescreenCheckbox = new CheckboxLabel(this); - PlayButton = new PushButton(this); - ExitButton = new PushButton(this); - GamesList = new ListView(this); - ParametersEdit = new LineEdit(this); - - PlayButton->OnClick = [=]() { OnPlayButtonClicked(); }; - ExitButton->OnClick = [=]() { OnExitButtonClicked(); }; - GamesList->OnActivated = [=]() { OnGamesListActivated(); }; - + LangLabel->SetText(GStrings("OPTMNU_LANGUAGE")); SelectLabel->SetText(GStrings("PICKER_SELECT")); PlayButton->SetText(GStrings("PICKER_PLAY")); ExitButton->SetText(GStrings("PICKER_EXIT")); @@ -79,11 +54,7 @@ LauncherWindow::LauncherWindow(WadStuff* wads, int numwads, int defaultiwad, int ParametersLabel->SetText(GStrings("PICKER_ADDPARM")); #ifdef RENDER_BACKENDS - BackendLabel = new TextLabel(this); - VulkanCheckbox = new CheckboxLabel(this); - OpenGLCheckbox = new CheckboxLabel(this); - GLESCheckbox = new CheckboxLabel(this); - BackendLabel->SetText(GStrings("VIDMNU_PREFERBACKEND")); + BackendLabel->SetText(GStrings("PICKER_PREFERBACKEND")); VulkanCheckbox->SetText(GStrings("OPTVAL_VULKAN")); OpenGLCheckbox->SetText(GStrings("OPTVAL_OPENGL")); GLESCheckbox->SetText(GStrings("OPTVAL_OPENGLES")); @@ -95,6 +66,48 @@ LauncherWindow::LauncherWindow(WadStuff* wads, int numwads, int defaultiwad, int versionText.Substitute("%s", GetVersionString()); WelcomeLabel->SetText(welcomeText.GetChars()); VersionLabel->SetText(versionText.GetChars()); +} + +LauncherWindow::LauncherWindow(WadStuff* wads, int numwads, int defaultiwad, int* autoloadflags) : Widget(nullptr, WidgetType::Window), AutoloadFlags(autoloadflags) +{ + SetWindowBackground(Colorf::fromRgba8(51, 51, 51)); + SetWindowBorderColor(Colorf::fromRgba8(51, 51, 51)); + SetWindowCaptionColor(Colorf::fromRgba8(33, 33, 33)); + SetWindowCaptionTextColor(Colorf::fromRgba8(226, 223, 219)); + SetWindowTitle(GAMENAME); + + Logo = new ImageBox(this); + WelcomeLabel = new TextLabel(this); + VersionLabel = new TextLabel(this); + LangLabel = new TextLabel(this); + SelectLabel = new TextLabel(this); + GeneralLabel = new TextLabel(this); + ExtrasLabel = new TextLabel(this); + ParametersLabel = new TextLabel(this); + FullscreenCheckbox = new CheckboxLabel(this); + DisableAutoloadCheckbox = new CheckboxLabel(this); + DontAskAgainCheckbox = new CheckboxLabel(this); + LightsCheckbox = new CheckboxLabel(this); + BrightmapsCheckbox = new CheckboxLabel(this); + WidescreenCheckbox = new CheckboxLabel(this); + PlayButton = new PushButton(this); + ExitButton = new PushButton(this); + LangList = new ListView(this); + GamesList = new ListView(this); + ParametersEdit = new LineEdit(this); + +#ifdef RENDER_BACKENDS + BackendLabel = new TextLabel(this); + VulkanCheckbox = new CheckboxLabel(this); + OpenGLCheckbox = new CheckboxLabel(this); + GLESCheckbox = new CheckboxLabel(this); +#endif + + PlayButton->OnClick = [=]() { OnPlayButtonClicked(); }; + ExitButton->OnClick = [=]() { OnExitButtonClicked(); }; + GamesList->OnActivated = [=]() { OnGamesListActivated(); }; + + UpdateLanguage(); FullscreenCheckbox->SetChecked(vid_fullscreen); DontAskAgainCheckbox->SetChecked(!queryiwad); @@ -126,6 +139,45 @@ LauncherWindow::LauncherWindow(WadStuff* wads, int numwads, int defaultiwad, int } #endif + + try + { + auto data = LoadWidgetData("menudef.txt"); + FScanner sc; + sc.OpenMem("menudef.txt", data); + while (sc.GetString()) + { + if (sc.Compare("OptionString")) + { + sc.MustGetString(); + if (sc.Compare("LanguageOptions")) + { + sc.MustGetStringName("{"); + while (!sc.CheckString("}")) + { + sc.MustGetString(); + FString iso = sc.String; + sc.MustGetStringName(","); + sc.MustGetString(); + if(iso.CompareNoCase("auto")) + languages.push_back(std::make_pair(iso, FString(sc.String))); + } + } + } + } + } + catch (const std::exception& ex) + { + hideLanguage = true; + } + int i = 0; + for (auto& l : languages) + { + LangList->AddItem(l.second.GetChars()); + if (!l.first.CompareNoCase(::language)) + LangList->SetSelectedItem(i); + i++; + } for (int i = 0; i < numwads; i++) { const char* filepart = strrchr(wads[i].Path.GetChars(), '/'); @@ -150,6 +202,14 @@ LauncherWindow::LauncherWindow(WadStuff* wads, int numwads, int defaultiwad, int Logo->SetImage(Image::LoadResource("widgets/banner.png")); GamesList->SetFocus(); + + LangList->OnChanged = [this](int i) + { + ::language = languages[i].first.GetChars(); + GStrings.UpdateLanguage(::language); // CVAR callbacks are not active yet. + UpdateLanguage(); + Update(); + }; } void LauncherWindow::OnClose() @@ -215,10 +275,19 @@ void LauncherWindow::OnGeometryChanged() y += 10.0; + if (!hideLanguage) + { + LangLabel->SetFrameGeometry(20.0, y, GetWidth() - 40.0, SelectLabel->GetPreferredHeight()); + y += LangLabel->GetPreferredHeight(); + LangList->SetFrameGeometry(20.0, y, GetWidth() - 40.0, 61); + y += 64.0; + } + + SelectLabel->SetFrameGeometry(20.0, y, GetWidth() - 40.0, SelectLabel->GetPreferredHeight()); y += SelectLabel->GetPreferredHeight(); - double listViewTop = y + 10.0; + double listViewTop = y; y = GetHeight() - 15.0 - PlayButton->GetPreferredHeight(); PlayButton->SetFrameGeometry(20.0, y, 120.0, PlayButton->GetPreferredHeight()); diff --git a/src/launcher/launcherwindow.h b/src/launcher/launcherwindow.h index 6f48a05254..d54f77464a 100644 --- a/src/launcher/launcherwindow.h +++ b/src/launcher/launcherwindow.h @@ -1,6 +1,8 @@ #pragma once #include +#include "tarray.h" +#include "zstring.h" #define RENDER_BACKENDS @@ -27,10 +29,12 @@ private: void OnClose() override; void OnGeometryChanged() override; + void UpdateLanguage(); ImageBox* Logo = nullptr; TextLabel* WelcomeLabel = nullptr; TextLabel* VersionLabel = nullptr; + TextLabel* LangLabel = nullptr; TextLabel* SelectLabel = nullptr; TextLabel* GeneralLabel = nullptr; TextLabel* ExtrasLabel = nullptr; @@ -50,8 +54,11 @@ private: PushButton* PlayButton = nullptr; PushButton* ExitButton = nullptr; ListView* GamesList = nullptr; + ListView* LangList = nullptr; LineEdit* ParametersEdit = nullptr; int* AutoloadFlags = nullptr; int ExecResult = -1; + bool hideLanguage = false; + TArray> languages; }; diff --git a/wadsrc/static/language.0 b/wadsrc/static/language.0 index 1beaedfa02..b43bba5a38 100644 --- a/wadsrc/static/language.0 +++ b/wadsrc/static/language.0 @@ -859,17 +859,18 @@ Sprite Options,OPTMNU_SPRITE,,,,Sprity,Sprite-indstillinger,Spriteoptionen,,Agor Coronas,GLPREFMNU_CORONAS,,,,Záře,Coronas,,,Lum-ampoloj,Focos de luz,,,,,,光冠,,Corona's,Koronaer,Korony,,,,Короны,,Koronor,Koronalar,Корони, Appearance,DSPLYMNU_APPEARANCE,,,,Vzhled,Udseende,Spieldarstellung,,Aspekto,Apariencia,,,,,,アピアランス,,Uiterlijk,Utseende,Wygląd,Aparência,,,Внешность,,Utseende,Görünüş,Зовнішній вигляд, Advanced Display Options,DSPLYMNU_ADVANCED,,,,Grafika (pokročilé),Avancerede visningsindstillinger,Erweiterte Anzeigeoptionen,,Altnivelaj ekran-agordoj,Opciones avanzadas de visualización,,,,,,高度なディスプレイオプション,,Geavanceerde Weergave Opties,Avanserte visningsalternativer,Zaawansowane Opcje Wyświetlania,Opções de vídeo avançadas,,,Расширенные настройки экрана,,Avancerade visningsalternativ,Gelişmiş Görüntüleme Seçenekleri,Додаткові параметри відображення, -Select which game file to run.,PICKER_SELECT,,,,,,,,,,,,,,,,,,,,,,,,,,,, -Play Game,PICKER_PLAY,,,,,,,,,,,,,,,,,,,,,,,,,,,, -Exit,PICKER_EXIT,,,,,,,,,,,,,,,,,,,,,,,,,,,, -General,PICKER_GENERAL,,,,,,,,,,,,,,,,,,,,,,,,,,,, -Extra Graphics,PICKER_EXTRA,,,,,,,,,,,,,,,,,,,,,,,,,,,, -Fullscreen,PICKER_FULLSCREEN,,,,,,,,,,,,,,,,,,,,,,,,,,,, -Disable autoload,PICKER_NOAUTOLOAD,,,,,,,,,,,,,,,,,,,,,,,,,,,, -Don't ask me again,PICKER_DONTASK,,,,,,,,,,,,,,,,,,,,,,,,,,,, -Lights,PICKER_LIGHTS,,,,,,,,,,,,,,,,,,,,,,,,,,,, -Brightmaps,PICKER_BRIGHTMAPS,,,,,,,,,,,,,,,,,,,,,,,,,,,, -Widescreen,PICKER_WIDESCREEN,,,,,,,,,,,,,,,,,,,,,,,,,,,, -Additional Parameters:,PICKER_ADDPARM,,,,,,,,,,,,,,,,,,,,,,,,,,,, -Welcome to %s!,PICKER_WELCOME,,,,,,,,,,,,,,,,,,,,,,,,,,,, -Version %s,PICKER_VERSION,,,,,,,,,,,,,,,,,,,,,,,,,,,, \ No newline at end of file +Select which game file to run.,PICKER_SELECT,,,,,,Bitte wähle ein Spiel aus.,,,,,,,,,,,,,,,,,Выбор файла игры для запуска.,,,,, +Play Game,PICKER_PLAY,,,,,,Spielen,,,,,,,,,,,,,,,,,Играть,,,,, +Exit,PICKER_EXIT,,,,,,Verlassen,,,,,,,,,,,,,,,,,Выход,,,,, +General,PICKER_GENERAL,,,,,,Allgemein,,,,,,,,,,,,,,,,,Общее,,,,, +Extra Graphics,PICKER_EXTRA,,,,,,Extragrafiken,,,,,,,,,,,,,,,,,Доп. графика,,,,, +Fullscreen,PICKER_FULLSCREEN,,,,,,Vollbild,,,,,,,,,,,,,,,,,Полный экран,,,,, +Disable autoload,PICKER_NOAUTOLOAD,,,,,,Autoload deaktivieren,,,,,,,,,,,,,,,,,Отключить автозагрузку,,,,, +Don't ask me again,PICKER_DONTASK,,,,,,Nicht nochmal fragen,,,,,,,,,,,,,,,,,Не спрашивать снова,,,,, +Lights,PICKER_LIGHTS,,,,,,Lichter,,,,,,,,,,,,,,,,,Освещение,,,,, +Brightmaps,PICKER_BRIGHTMAPS,,,,,,,,,,,,,,,,,,,,,,,Карты освещения,,,,, +Widescreen,PICKER_WIDESCREEN,,,,,,Breitbildunterstützung,,,,,,,,,,,,,,,,,Широкий экран,,,,, +Additional Parameters:,PICKER_ADDPARM,,,,,,Zusätzliche Parameter,,,,,,,,,,,,,,,,,Доп. параметры:,,,,, +Welcome to %s!,PICKER_WELCOME,,,,,,Willkommen bei %s!,,,,,,,,,,,,,,,,,Добро пожаловать в %s!,,,,, +Version %s,PICKER_VERSION,,,,,,,,,,,,,,,,,,,,,,,Версия %s,,,,, +Rendering API,PICKER_PREFERBACKEND,,,,API vykreslování,,Render API,,Preferita bildigado de API,API de renderizado,,Renderöinti API,API de rendu,Renderelő API,API di rendering,優先レンダリングAPI,기본적인 API 랜더링,,,API renderowania,API de renderização,,API Video Preferat,API для рендеринга,АПИ приказивања,API för rendering,,API для візуалізації, \ No newline at end of file