Search in sources :

Example 1 with TranslationSystem

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

the class UIFormat method load.

public UIData load(JsonElement element, Locale otherLocale) throws IOException {
    NUIManager nuiManager = CoreRegistry.get(NUIManager.class);
    TranslationSystem translationSystem = CoreRegistry.get(TranslationSystem.class);
    TypeSerializationLibrary library = new TypeSerializationLibrary(CoreRegistry.get(TypeSerializationLibrary.class));
    library.add(UISkin.class, new AssetTypeHandler<>(UISkin.class));
    library.add(Border.class, new BorderTypeHandler());
    GsonBuilder gsonBuilder = new GsonBuilder().registerTypeAdapterFactory(new CaseInsensitiveEnumTypeAdapterFactory()).registerTypeAdapter(UIData.class, new UIDataTypeAdapter()).registerTypeHierarchyAdapter(UIWidget.class, new UIWidgetTypeAdapter(nuiManager));
    for (Class<?> handledType : library.getCoreTypes()) {
        gsonBuilder.registerTypeAdapter(handledType, new JsonTypeHandlerAdapter<>(library.getHandlerFor(handledType)));
    }
    // override the String TypeAdapter from the serialization library
    gsonBuilder.registerTypeAdapter(String.class, new I18nStringTypeAdapter(translationSystem, otherLocale));
    Gson gson = gsonBuilder.create();
    return gson.fromJson(element, UIData.class);
}
Also used : TranslationSystem(org.terasology.i18n.TranslationSystem) GsonBuilder(com.google.gson.GsonBuilder) UISkin(org.terasology.rendering.nui.skin.UISkin) Gson(com.google.gson.Gson) CaseInsensitiveEnumTypeAdapterFactory(org.terasology.utilities.gson.CaseInsensitiveEnumTypeAdapterFactory) BorderTypeHandler(org.terasology.persistence.typeHandling.mathTypes.BorderTypeHandler) TypeSerializationLibrary(org.terasology.persistence.typeHandling.TypeSerializationLibrary) NUIManager(org.terasology.rendering.nui.NUIManager)

Example 2 with TranslationSystem

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

the class StateMainMenu method pushLaunchPopup.

private void pushLaunchPopup() {
    Config config = context.get(Config.class);
    TelemetryConfig telemetryConfig = config.getTelemetryConfig();
    TranslationSystem translationSystem = context.get(TranslationSystem.class);
    TelemetryLogstashAppender appender = TelemetryUtils.fetchTelemetryLogstashAppender();
    if (!telemetryConfig.isLaunchPopupDisabled()) {
        String telemetryTitle = translationSystem.translate("${engine:menu#telemetry-launch-popup-title}");
        String telemetryMessage = translationSystem.translate("${engine:menu#telemetry-launch-popup-text}");
        LaunchPopup telemetryConfirmPopup = nuiManager.pushScreen(LaunchPopup.ASSET_URI, LaunchPopup.class);
        telemetryConfirmPopup.setMessage(telemetryTitle, telemetryMessage);
        telemetryConfirmPopup.setYesHandler(() -> {
            telemetryConfig.setTelemetryAndErrorReportingEnable(true);
            // Enable error reporting
            appender.start();
        });
        telemetryConfirmPopup.setNoHandler(() -> {
            telemetryConfig.setTelemetryAndErrorReportingEnable(false);
            // Disable error reporting
            appender.stop();
        });
        telemetryConfirmPopup.setOptionButtonText(translationSystem.translate("${engine:menu#telemetry-button}"));
        telemetryConfirmPopup.setOptionHandler(() -> {
            nuiManager.pushScreen(TelemetryScreen.ASSET_URI, TelemetryScreen.class);
        });
    }
}
Also used : TranslationSystem(org.terasology.i18n.TranslationSystem) LaunchPopup(org.terasology.rendering.nui.layers.mainMenu.LaunchPopup) Config(org.terasology.config.Config) TelemetryConfig(org.terasology.config.TelemetryConfig) TelemetryLogstashAppender(org.terasology.telemetry.logstash.TelemetryLogstashAppender) TelemetryConfig(org.terasology.config.TelemetryConfig)

Aggregations

TranslationSystem (org.terasology.i18n.TranslationSystem)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 Config (org.terasology.config.Config)1 TelemetryConfig (org.terasology.config.TelemetryConfig)1 TypeSerializationLibrary (org.terasology.persistence.typeHandling.TypeSerializationLibrary)1 BorderTypeHandler (org.terasology.persistence.typeHandling.mathTypes.BorderTypeHandler)1 NUIManager (org.terasology.rendering.nui.NUIManager)1 LaunchPopup (org.terasology.rendering.nui.layers.mainMenu.LaunchPopup)1 UISkin (org.terasology.rendering.nui.skin.UISkin)1 TelemetryLogstashAppender (org.terasology.telemetry.logstash.TelemetryLogstashAppender)1 CaseInsensitiveEnumTypeAdapterFactory (org.terasology.utilities.gson.CaseInsensitiveEnumTypeAdapterFactory)1