Search in sources :

Example 1 with LocaleRenderer

use of org.terasology.engine.rendering.nui.layers.mainMenu.settings.LocaleRenderer in project Terasology by MovingBlocks.

the class LocaleConstraintWidgetFactory method buildWidget.

@Override
protected Optional<UIWidget> buildWidget() {
    Setting<Locale> setting = getSetting();
    Binding<Locale> binding = new Binding<Locale>() {

        @Override
        public Locale get() {
            return setting.get();
        }

        @Override
        public void set(Locale value) {
            setting.set(value);
        }
    };
    UIDropdownScrollable<Locale> dropdownScrollable = new UIDropdownScrollable<>();
    ResourceUrn menuUrn = new ResourceUrn("engine:menu");
    TranslationProject menuProject = translationSystem.getProject(menuUrn);
    List<Locale> locales = new ArrayList<>(menuProject.getAvailableLocales());
    for (Locale languageExcluded : languagesExcluded) {
        locales.remove(languageExcluded);
    }
    Collections.sort(locales, (Comparator.comparing((Function<Object, String>) Object::toString)));
    dropdownScrollable.setOptions(Lists.newArrayList(locales));
    // Set maximum number of options visible for scrolling
    dropdownScrollable.setVisibleOptions(5);
    dropdownScrollable.bindSelection(binding);
    dropdownScrollable.setOptionRenderer(new LocaleRenderer(translationSystem));
    return Optional.of(dropdownScrollable);
}
Also used : Locale(java.util.Locale) Binding(org.terasology.nui.databinding.Binding) LocaleRenderer(org.terasology.engine.rendering.nui.layers.mainMenu.settings.LocaleRenderer) UIDropdownScrollable(org.terasology.nui.widgets.UIDropdownScrollable) ArrayList(java.util.ArrayList) TranslationProject(org.terasology.engine.i18n.TranslationProject) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn)

Example 2 with LocaleRenderer

use of org.terasology.engine.rendering.nui.layers.mainMenu.settings.LocaleRenderer in project Terasology by MovingBlocks.

the class NUIEditorSettingsScreen method initialise.

@Override
public void initialise() {
    WidgetUtil.tryBindCheckbox(this, "disableAutosave", BindHelper.bindBeanProperty("disableAutosave", config.getNuiEditor(), Boolean.TYPE));
    WidgetUtil.tryBindCheckbox(this, "disableIcons", BindHelper.bindBeanProperty("disableIcons", config.getNuiEditor(), Boolean.TYPE));
    WidgetUtil.trySubscribe(this, "close", button -> getManager().closeScreen(ASSET_URI));
    alternativeLocale = find("alternativeLocale", UIDropdownScrollable.class);
    if (alternativeLocale != null) {
        // Build the list of available locales and set the dropdown's options to them.
        TranslationProject menuProject = translationSystem.getProject(new ResourceUrn("engine:menu"));
        List<Locale> locales = new ArrayList<>(menuProject.getAvailableLocales());
        Collections.sort(locales, ((Object o1, Object o2) -> (o1.toString().compareTo(o2.toString()))));
        alternativeLocale.setOptions(Lists.newArrayList(locales));
        alternativeLocale.setVisibleOptions(5);
        alternativeLocale.setOptionRenderer(new LocaleRenderer(translationSystem));
        // If an alternative locale has been previously selected, select it; otherwise select the system locale.
        if (config.getNuiEditor().getAlternativeLocale() != null) {
            alternativeLocale.setSelection(config.getNuiEditor().getAlternativeLocale());
        } else {
            alternativeLocale.setSelection(systemConfig.locale.get());
        }
    }
}
Also used : Locale(java.util.Locale) LocaleRenderer(org.terasology.engine.rendering.nui.layers.mainMenu.settings.LocaleRenderer) TranslationProject(org.terasology.engine.i18n.TranslationProject) UIDropdownScrollable(org.terasology.nui.widgets.UIDropdownScrollable) ArrayList(java.util.ArrayList) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn)

Aggregations

ArrayList (java.util.ArrayList)2 Locale (java.util.Locale)2 TranslationProject (org.terasology.engine.i18n.TranslationProject)2 LocaleRenderer (org.terasology.engine.rendering.nui.layers.mainMenu.settings.LocaleRenderer)2 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)2 UIDropdownScrollable (org.terasology.nui.widgets.UIDropdownScrollable)2 Binding (org.terasology.nui.databinding.Binding)1