Merge branch 'locale_menu' into 'master'

Add a way to configure locale settings in-game

See merge request OpenMW/openmw!2179
check_span
psi29a 2 years ago
commit c54822acf9

@ -23,7 +23,7 @@ namespace
{
auto* processor = MWBase::Environment::get().getWorld()->getPostProcessor();
std::ostringstream chain;
std::vector<std::string> chain;
for (size_t i = 1; i < processor->getTechniques().size(); ++i)
{
@ -32,13 +32,10 @@ namespace
if (!technique || technique->getDynamic())
continue;
chain << technique->getName();
if (i < processor-> getTechniques().size() - 1)
chain << ",";
chain.push_back(technique->getName());
}
Settings::Manager::setString("chain", "Post Processing", chain.str());
Settings::Manager::setStringArray("chain", "Post Processing", chain);
}
}

@ -5,6 +5,8 @@
#include <numeric>
#include <array>
#include <unicode/locid.h>
#include <MyGUI_ScrollBar.h>
#include <MyGUI_Window.h>
#include <MyGUI_ComboBox.h>
@ -18,12 +20,14 @@
#include <components/debug/debuglog.hpp>
#include <components/misc/stringops.hpp>
#include <components/misc/constants.hpp>
#include <components/misc/pathhelpers.hpp>
#include <components/widgets/sharedstatebutton.hpp>
#include <components/settings/settings.hpp>
#include <components/resource/resourcesystem.hpp>
#include <components/resource/scenemanager.hpp>
#include <components/sceneutil/lightmanager.hpp>
#include <components/lua_ui/scriptsettings.hpp>
#include <components/vfs/manager.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
@ -254,6 +258,8 @@ namespace MWGui
getWidget(mWaterTextureSize, "WaterTextureSize");
getWidget(mWaterReflectionDetail, "WaterReflectionDetail");
getWidget(mWaterRainRippleDetail, "WaterRainRippleDetail");
getWidget(mPrimaryLanguage, "PrimaryLanguage");
getWidget(mSecondaryLanguage, "SecondaryLanguage");
getWidget(mLightingMethodButton, "LightingMethodButton");
getWidget(mLightsResetButton, "LightsResetButton");
getWidget(mMaxLights, "MaxLights");
@ -297,6 +303,9 @@ namespace MWGui
mKeyboardSwitch->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onKeyboardSwitchClicked);
mControllerSwitch->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onControllerSwitchClicked);
mPrimaryLanguage->eventComboChangePosition += MyGUI::newDelegate(this, &SettingsWindow::onPrimaryLanguageChanged);
mSecondaryLanguage->eventComboChangePosition += MyGUI::newDelegate(this, &SettingsWindow::onSecondaryLanguageChanged);
computeMinimumWindowSize();
center();
@ -353,6 +362,54 @@ namespace MWGui
mScriptFilter->eventEditTextChange += MyGUI::newDelegate(this, &SettingsWindow::onScriptFilterChange);
mScriptList->eventListMouseItemActivate += MyGUI::newDelegate(this, &SettingsWindow::onScriptListSelection);
std::vector<std::string> availableLanguages;
const VFS::Manager* vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
for (const auto& path : vfs->getRecursiveDirectoryIterator("l10n/"))
{
if (Misc::getFileExtension(path) == "yaml")
{
std::string localeName(Misc::stemFile(path));
if (std::find(availableLanguages.begin(), availableLanguages.end(), localeName) == availableLanguages.end())
availableLanguages.push_back(localeName);
}
}
std::sort (availableLanguages.begin(), availableLanguages.end());
std::vector<std::string> currentLocales = Settings::Manager::getStringArray("preferred locales", "General");
if (currentLocales.empty())
currentLocales.push_back("en");
icu::Locale primaryLocale(currentLocales[0].c_str());
mPrimaryLanguage->removeAllItems();
mPrimaryLanguage->setIndexSelected(MyGUI::ITEM_NONE);
mSecondaryLanguage->removeAllItems();
mSecondaryLanguage->addItem(MyGUI::LanguageManager::getInstance().replaceTags("#{sNone}"), std::string());
mSecondaryLanguage->setIndexSelected(0);
size_t i = 0;
for (const auto& language : availableLanguages)
{
icu::Locale locale(language.c_str());
icu::UnicodeString str(language.c_str());
locale.getDisplayName(primaryLocale, str);
std::string localeString;
str.toUTF8String(localeString);
mPrimaryLanguage->addItem(localeString, language);
mSecondaryLanguage->addItem(localeString, language);
if (language == currentLocales[0])
mPrimaryLanguage->setIndexSelected(i);
if (currentLocales.size() > 1 && language == currentLocales[1])
mSecondaryLanguage->setIndexSelected(i + 1);
i++;
}
}
void SettingsWindow::onTabChanged(MyGUI::TabControl* /*_sender*/, size_t /*index*/)
@ -447,13 +504,36 @@ namespace MWGui
if (pos == MyGUI::ITEM_NONE)
return;
_sender->setCaptionWithReplacing(_sender->getItemNameAt(_sender->getIndexSelected()));
MWBase::Environment::get().getWindowManager()->interactiveMessageBox("#{SettingsMenu:ChangeRequiresRestart}", {"#{sOK}"}, true);
const auto settingsNames = _sender->getUserData<std::vector<std::string>>();
Settings::Manager::setString("lighting method", "Shaders", settingsNames->at(pos));
Settings::Manager::setString("lighting method", "Shaders", *_sender->getItemDataAt<std::string>(pos));
apply();
}
void SettingsWindow::onLanguageChanged(size_t langPriority, MyGUI::ComboBox* _sender, size_t pos)
{
if (pos == MyGUI::ITEM_NONE)
return;
_sender->setCaptionWithReplacing(_sender->getItemNameAt(_sender->getIndexSelected()));
MWBase::Environment::get().getWindowManager()->interactiveMessageBox("#{SettingsMenu:ChangeRequiresRestart}", {"#{sOK}"}, true);
std::vector<std::string> currentLocales = Settings::Manager::getStringArray("preferred locales", "General");
if (currentLocales.size() <= langPriority)
currentLocales.resize(langPriority + 1, "en");
const auto& languageCode = *_sender->getItemDataAt<std::string>(pos);
if (!languageCode.empty())
currentLocales[langPriority] = languageCode;
else
currentLocales.resize(1);
Settings::Manager::setStringArray("preferred locales", "General", currentLocales);
}
void SettingsWindow::onWindowModeChanged(MyGUI::ComboBox* _sender, size_t pos)
{
if (pos == MyGUI::ITEM_NONE)
@ -668,17 +748,13 @@ namespace MWGui
SceneUtil::LightingMethod::SingleUBO,
};
std::vector<std::string> userData;
for (const auto& method : methods)
{
if (!MWBase::Environment::get().getResourceSystem()->getSceneManager()->isSupportedLightingMethod(method))
continue;
mLightingMethodButton->addItem(lightingMethodToStr(method));
userData.emplace_back(SceneUtil::LightManager::getLightingMethodString(method));
mLightingMethodButton->addItem(lightingMethodToStr(method), SceneUtil::LightManager::getLightingMethodString(method));
}
mLightingMethodButton->setUserData(userData);
mLightingMethodButton->setIndexSelected(mLightingMethodButton->findItemIndexWith(lightingMethodStr));
}

@ -40,6 +40,9 @@ namespace MWGui
MyGUI::ComboBox* mLightingMethodButton;
MyGUI::Button* mLightsResetButton;
MyGUI::ComboBox* mPrimaryLanguage;
MyGUI::ComboBox* mSecondaryLanguage;
// controls
MyGUI::ScrollView* mControlsBox;
MyGUI::Button* mResetControlsButton;
@ -72,6 +75,10 @@ namespace MWGui
void onLightsResetButtonClicked(MyGUI::Widget* _sender);
void onMaxLightsChanged(MyGUI::ComboBox* _sender, size_t pos);
void onPrimaryLanguageChanged(MyGUI::ComboBox* _sender, size_t pos) { onLanguageChanged(0, _sender, pos); }
void onSecondaryLanguageChanged(MyGUI::ComboBox* _sender, size_t pos) { onLanguageChanged(1, _sender, pos); }
void onLanguageChanged(size_t langPriority, MyGUI::ComboBox* _sender, size_t pos);
void onWindowModeChanged(MyGUI::ComboBox* _sender, size_t pos);
void onRebindAction(MyGUI::Widget* _sender);

@ -58,9 +58,7 @@ namespace MWLua
void LuaManager::initL10n()
{
mL10n.init();
std::vector<std::string> preferredLocales;
Misc::StringUtils::split(Settings::Manager::getString("preferred locales", "General"), preferredLocales, ", ");
mL10n.setPreferredLocales(preferredLocales);
mL10n.setPreferredLocales(Settings::Manager::getStringArray("preferred locales", "General"));
}
void LuaManager::init()

@ -830,8 +830,7 @@ namespace MWRender
mTechniques.clear();
std::vector<std::string> techniqueStrings;
Misc::StringUtils::split(Settings::Manager::getString("chain", "Post Processing"), techniqueStrings, ",");
std::vector<std::string> techniqueStrings = Settings::Manager::getStringArray("chain", "Post Processing");
const std::string mainIdentifier = "main";
@ -844,8 +843,6 @@ namespace MWRender
for (auto& techniqueName : techniqueStrings)
{
Misc::StringUtils::trim(techniqueName);
if (techniqueName.empty() || Misc::StringUtils::ciEqual(techniqueName, mainIdentifier))
continue;

@ -88,6 +88,22 @@ std::string Manager::getString(std::string_view setting, std::string_view catego
throw std::runtime_error(error);
}
std::vector<std::string> Manager::getStringArray(std::string_view setting, std::string_view category)
{
// TODO: it is unclear how to handle empty value -
// there is no difference between empty serialized array
// and a serialized array which has one empty value
std::vector<std::string> values;
const std::string& value = getString(setting, category);
if (value.empty())
return values;
Misc::StringUtils::split(value, values, ",");
for (auto& item : values)
Misc::StringUtils::trim(item);
return values;
}
float Manager::getFloat(std::string_view setting, std::string_view category)
{
const std::string& value = getString(setting, category);
@ -168,6 +184,24 @@ void Manager::setString(std::string_view setting, std::string_view category, con
mChangedSettings.insert(std::move(key));
}
void Manager::setStringArray(std::string_view setting, std::string_view category, const std::vector<std::string> &value)
{
std::stringstream stream;
// TODO: escape delimeters, new line characters, etc.
for (size_t i = 0; i < value.size(); ++i)
{
std::string item = value[i];
Misc::StringUtils::trim(item);
stream << item;
if (i < value.size() - 1)
stream << ",";
}
setString(setting, category, stream.str());
}
void Manager::setInt(std::string_view setting, std::string_view category, const int value)
{
std::ostringstream stream;

@ -7,6 +7,7 @@
#include <map>
#include <string>
#include <string_view>
#include <vector>
#include <osg/Vec2f>
#include <osg/Vec3f>
@ -63,6 +64,7 @@ namespace Settings
static float getFloat(std::string_view setting, std::string_view category);
static double getDouble(std::string_view setting, std::string_view category);
static std::string getString(std::string_view setting, std::string_view category);
static std::vector<std::string> getStringArray(std::string_view setting, std::string_view category);
static bool getBool(std::string_view setting, std::string_view category);
static osg::Vec2f getVector2(std::string_view setting, std::string_view category);
static osg::Vec3f getVector3(std::string_view setting, std::string_view category);
@ -72,6 +74,7 @@ namespace Settings
static void setFloat(std::string_view setting, std::string_view category, float value);
static void setDouble(std::string_view setting, std::string_view category, double value);
static void setString(std::string_view setting, std::string_view category, const std::string& value);
static void setStringArray(std::string_view setting, std::string_view category, const std::vector<std::string> &value);
static void setBool(std::string_view setting, std::string_view category, bool value);
static void setVector2(std::string_view setting, std::string_view category, osg::Vec2f value);
static void setVector3(std::string_view setting, std::string_view category, osg::Vec3f value);

@ -85,7 +85,7 @@ will match "en"), so is recommended that you include the country codes where pos
since if the country code isn't specified the generic language-code only locale might
refer to any of the country-specific variants.
This setting can only be configured by editing the settings configuration file.
Two highest priority locales may be assigned via the Localization tab of the in-game options.
log buffer size
---------------

@ -8,6 +8,8 @@ Controller: "Controller"
FieldOfView: "Field of View"
FrameRateHint: "Hint: press F3 to show\nthe current frame rate."
InvertXAxis: "Invert X Axis"
Language: "Language"
LanguageNote: "Note: these settings do not affect strings from ESM files."
LightingMethod: "Lighting Method"
LightingMethodLegacy: "Legacy"
LightingMethodShaders: "Shaders"
@ -27,6 +29,8 @@ MaxLightsTooltip: "Default: 8\nMaximum number of lights per object.\n\nA low num
MouseAndKeyboard: "Mouse/Keyboard"
PostProcessing: "Post Processing"
PostProcessingTooltip: "Tweaked via Post Processor HUD, see input bindings."
PrimaryLanguage: "Primary Language"
PrimaryLanguageTooltip: "Localization files for this language have the highest priority."
RainRippleDetail: "Rain ripple detail"
RainRippleDetailDense: "Dense"
RainRippleDetailSimple: "Simple"
@ -41,6 +45,8 @@ ReflectionShaderDetailWorld: "World"
Refraction: "Refraction"
Screenshot: "Screenshot"
Scripts: "Scripts"
SecondaryLanguage: "Secondary Language"
SecondaryLanguageTooltip: "Localization files for this language may be used if the primary language files lack the necessary lines."
TextureFiltering: "Texture Filtering"
TextureFilteringBilinear: "Bilinear"
TextureFilteringDisabled: "None"

@ -8,6 +8,8 @@ Controller: "Геймпад"
FieldOfView: "Поле зрения"
FrameRateHint: "Подсказка: нажмите F3, чтобы показать\nтекущую частоту смены кадров."
InvertXAxis: "Инвертировать ось X"
Language: "Язык"
LanguageNote: "Примечание: эти настройки не затрагивают строки из ESM-файлов."
LightingMethod: "Способ освещения"
LightingMethodLegacy: "Устаревший"
LightingMethodShaders: "Шейдеры"
@ -27,6 +29,8 @@ MaxLightsTooltip: "Значение по умолчанию: 8\nМаксимал
MouseAndKeyboard: "Мышь/Клавиатура"
PostProcessing: "Постобработка"
PostProcessingTooltip: "Настраивается через меню настроек постобработки, см. привязки клавиш."
PrimaryLanguage: "Основной язык"
PrimaryLanguageTooltip: "Язык, строки на котором будут использоваться в первую очередь."
RainRippleDetail: "Капли дождя на воде"
RainRippleDetailDense: "Плотные"
RainRippleDetailSimple: "Упрощенные"
@ -41,6 +45,8 @@ ReflectionShaderDetailWorld: "Мир"
Refraction: "Рефракция"
Screenshot: "Снимок экрана"
Scripts: "Скрипты"
SecondaryLanguage: "Дополнительный язык"
SecondaryLanguageTooltip: "Язык, строки на котором будут использоваться, если соответствующие строки на основном языке не найдены."
TextureFiltering: "Фильтрация текстур"
TextureFilteringBilinear: "Билинейная"
TextureFilteringDisabled: "Отключена"

@ -670,6 +670,28 @@
</Widget>
</Widget>
<Widget type="TabItem">
<Property key="Caption" value=" #{SettingsMenu:Language} "/>
<Widget type="AutoSizedTextBox" skin="SandText" position="4 4 300 32" align="Left Top">
<Property key="Caption" value="#{SettingsMenu:LanguageNote}"/>
</Widget>
<!-- Primary Language -->
<Widget type="TextBox" skin="NormalText" position="4 28 250 18" align="Left Top">
<Property key="Caption" value="#{SettingsMenu:PrimaryLanguage}"/>
<UserString key="ToolTipType" value="Layout"/>
<UserString key="ToolTipLayout" value="TextToolTip"/>
<UserString key="Caption_Text" value="#{SettingsMenu:PrimaryLanguageTooltip}"/>
</Widget>
<Widget type="ComboBox" skin="MW_ComboBox" position="4 52 250 24" align="Left Top" name="PrimaryLanguage" />
<!-- Secondary Language -->
<Widget type="TextBox" skin="NormalText" position="262 28 250 18" align="Left Top">
<Property key="Caption" value="#{SettingsMenu:SecondaryLanguage}"/>
<UserString key="ToolTipType" value="Layout"/>
<UserString key="ToolTipLayout" value="TextToolTip"/>
<UserString key="Caption_Text" value="#{SettingsMenu:SecondaryLanguageTooltip}"/>
</Widget>
<Widget type="ComboBox" skin="MW_ComboBox" position="262 52 250 24" align="Left Top" name="SecondaryLanguage" />
</Widget>
</Widget>
<Widget type="AutoSizedButton" skin="MW_Button" position="320 420 56 24" align="Right Bottom" name="OkButton">
<Property key="ExpandDirection" value="Left"/>

Loading…
Cancel
Save