Search in sources :

Example 1 with TranslationProject

use of org.terasology.i18n.TranslationProject in project Terasology by MovingBlocks.

the class PlayerSettingsScreen method initialise.

@Override
public void initialise() {
    setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
    storageServiceStatus = find("storageServiceStatus", UILabel.class);
    storageServiceAction = find("storageServiceAction", UIButton.class);
    updateStorageServiceStatus();
    nametext = find("playername", UIText.class);
    if (nametext != null) {
        nametext.setTooltipDelay(0);
        nametext.bindTooltipString(new ReadOnlyBinding<String>() {

            @Override
            public String get() {
                return validateScreen();
            }
        });
    }
    img = find("image", UIImage.class);
    if (img != null) {
        ResourceUrn uri = TextureUtil.getTextureUriForColor(Color.WHITE);
        Texture tex = Assets.get(uri, Texture.class).get();
        img.setImage(tex);
    }
    slider = find("tone", UISlider.class);
    if (slider != null) {
        slider.setIncrement(0.01f);
        // ensure a certain width
        Function<Object, String> constant = Functions.constant("  ");
        slider.setLabelFunction(constant);
    }
    heightSlider = find("height", UISlider.class);
    if (heightSlider != null) {
        heightSlider.setMinimum(1.5f);
        heightSlider.setIncrement(0.1f);
        heightSlider.setRange(0.5f);
        heightSlider.setPrecision(1);
    }
    eyeHeightSlider = find("eye-height", UISlider.class);
    if (eyeHeightSlider != null) {
        eyeHeightSlider.setMinimum(0.5f);
        eyeHeightSlider.setIncrement(0.1f);
        eyeHeightSlider.setRange(1f);
        eyeHeightSlider.setPrecision(1);
    }
    language = find("language", UIDropdownScrollable.class);
    if (language != null) {
        SimpleUri menuUri = new SimpleUri("engine:menu");
        TranslationProject menuProject = translationSystem.getProject(menuUri);
        List<Locale> locales = new ArrayList<>(menuProject.getAvailableLocales());
        for (Locale languageExcluded : languagesExcluded) {
            locales.remove(languageExcluded);
        }
        Collections.sort(locales, ((Object o1, Object o2) -> (o1.toString().compareTo(o2.toString()))));
        language.setOptions(Lists.newArrayList(locales));
        // Set maximum number of options visible for scrolling
        language.setVisibleOptions(5);
        language.setOptionRenderer(new LocaleRenderer(translationSystem));
    }
    WidgetUtil.trySubscribe(this, "close", button -> triggerBackAnimation());
    IdentityIOHelper identityIOHelper = new IdentityIOHelper(context);
    WidgetUtil.trySubscribe(this, "importIdentities", button -> identityIOHelper.importIdentities());
    WidgetUtil.trySubscribe(this, "exportIdentities", button -> identityIOHelper.exportIdentities());
    WidgetUtil.trySubscribe(this, "storageServiceAction", widget -> {
        if (storageService.getStatus() == StorageServiceWorkerStatus.LOGGED_IN) {
            ThreeButtonPopup logoutPopup = getManager().pushScreen(ThreeButtonPopup.ASSET_URI, ThreeButtonPopup.class);
            logoutPopup.setMessage(translationSystem.translate("${engine:menu#storage-service-log-out}"), translationSystem.translate("${engine:menu#storage-service-log-out-popup}"));
            logoutPopup.setLeftButton(translationSystem.translate("${engine:menu#dialog-yes}"), () -> storageService.logout(true));
            logoutPopup.setCenterButton(translationSystem.translate("${engine:menu#dialog-no}"), () -> storageService.logout(false));
            logoutPopup.setRightButton(translationSystem.translate("${engine:menu#dialog-cancel}"), () -> {
            });
        } else if (storageService.getStatus() == StorageServiceWorkerStatus.LOGGED_OUT) {
            getManager().pushScreen(StorageServiceLoginPopup.ASSET_URI, StorageServiceLoginPopup.class);
        }
    });
    UIButton okButton = find("ok", UIButton.class);
    if (okButton != null) {
        okButton.subscribe(button -> {
            savePlayerSettings();
            triggerBackAnimation();
        });
        okButton.bindEnabled(new ReadOnlyBinding<Boolean>() {

            @Override
            public Boolean get() {
                return Strings.isNullOrEmpty(validateScreen());
            }
        });
        okButton.setTooltipDelay(0);
        okButton.bindTooltipString(new ReadOnlyBinding<String>() {

            @Override
            public String get() {
                return validateScreen();
            }
        });
    }
}
Also used : UILabel(org.terasology.rendering.nui.widgets.UILabel) Locale(java.util.Locale) UISlider(org.terasology.rendering.nui.widgets.UISlider) UIDropdownScrollable(org.terasology.rendering.nui.widgets.UIDropdownScrollable) SimpleUri(org.terasology.engine.SimpleUri) ArrayList(java.util.ArrayList) Texture(org.terasology.rendering.assets.texture.Texture) StorageServiceLoginPopup(org.terasology.rendering.nui.layers.mainMenu.StorageServiceLoginPopup) TranslationProject(org.terasology.i18n.TranslationProject) UIButton(org.terasology.rendering.nui.widgets.UIButton) UIText(org.terasology.rendering.nui.widgets.UIText) UIImage(org.terasology.rendering.nui.widgets.UIImage) ResourceUrn(org.terasology.assets.ResourceUrn) ThreeButtonPopup(org.terasology.rendering.nui.layers.mainMenu.ThreeButtonPopup)

Example 2 with TranslationProject

use of org.terasology.i18n.TranslationProject 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 SimpleUri("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(config.getSystem().getLocale());
        }
    }
}
Also used : Locale(java.util.Locale) LocaleRenderer(org.terasology.rendering.nui.layers.mainMenu.settings.LocaleRenderer) TranslationProject(org.terasology.i18n.TranslationProject) UIDropdownScrollable(org.terasology.rendering.nui.widgets.UIDropdownScrollable) SimpleUri(org.terasology.engine.SimpleUri) ArrayList(java.util.ArrayList)

Example 3 with TranslationProject

use of org.terasology.i18n.TranslationProject in project Terasology by MovingBlocks.

the class CoreCommands method setLanguage.

/**
 * Change the UI language
 * @param langTag String containing language code to change
 * @return String containing language or if not recognized error message
 */
@Command(shortDescription = "Changes the UI language")
public String setLanguage(@CommandParam("language-tag") String langTag) {
    Locale locale = Locale.forLanguageTag(langTag);
    TranslationProject proj = translationSystem.getProject(new SimpleUri("engine:menu"));
    // Try if language exists
    if (proj.getAvailableLocales().contains(locale)) {
        config.getSystem().setLocale(locale);
        nuiManager.invalidate();
        String nat = translationSystem.translate("${engine:menu#this-language-native}", locale);
        String eng = translationSystem.translate("${engine:menu#this-language-English}", locale);
        return String.format("Language set to %s (%s)", nat, eng);
    } else {
        return "Unrecognized locale! Try one of: " + proj.getAvailableLocales();
    }
}
Also used : Locale(java.util.Locale) TranslationProject(org.terasology.i18n.TranslationProject) SimpleUri(org.terasology.engine.SimpleUri) Command(org.terasology.logic.console.commandSystem.annotations.Command) ConsoleCommand(org.terasology.logic.console.commandSystem.ConsoleCommand)

Aggregations

Locale (java.util.Locale)3 SimpleUri (org.terasology.engine.SimpleUri)3 TranslationProject (org.terasology.i18n.TranslationProject)3 ArrayList (java.util.ArrayList)2 UIDropdownScrollable (org.terasology.rendering.nui.widgets.UIDropdownScrollable)2 ResourceUrn (org.terasology.assets.ResourceUrn)1 ConsoleCommand (org.terasology.logic.console.commandSystem.ConsoleCommand)1 Command (org.terasology.logic.console.commandSystem.annotations.Command)1 Texture (org.terasology.rendering.assets.texture.Texture)1 StorageServiceLoginPopup (org.terasology.rendering.nui.layers.mainMenu.StorageServiceLoginPopup)1 ThreeButtonPopup (org.terasology.rendering.nui.layers.mainMenu.ThreeButtonPopup)1 LocaleRenderer (org.terasology.rendering.nui.layers.mainMenu.settings.LocaleRenderer)1 UIButton (org.terasology.rendering.nui.widgets.UIButton)1 UIImage (org.terasology.rendering.nui.widgets.UIImage)1 UILabel (org.terasology.rendering.nui.widgets.UILabel)1 UISlider (org.terasology.rendering.nui.widgets.UISlider)1 UIText (org.terasology.rendering.nui.widgets.UIText)1