Search in sources :

Example 1 with TranslationSystem

use of org.terasology.engine.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.engine.i18n.TranslationSystem) LaunchPopup(org.terasology.engine.rendering.nui.layers.mainMenu.LaunchPopup) Config(org.terasology.engine.config.Config) TelemetryConfig(org.terasology.engine.config.TelemetryConfig) TelemetryLogstashAppender(org.terasology.engine.telemetry.logstash.TelemetryLogstashAppender) TelemetryConfig(org.terasology.engine.config.TelemetryConfig)

Example 2 with TranslationSystem

use of org.terasology.engine.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);
    TypeHandlerLibrary library = CoreRegistry.get(TypeHandlerLibrary.class).copy();
    library.addTypeHandler(UISkinAsset.class, new AssetTypeHandler<>(UISkinAsset.class));
    library.addTypeHandler(UISkin.class, new UISkinTypeHandler());
    // TODO: Rewrite to use TypeHandlerLibrary
    GsonBuilder gsonBuilder = new GsonBuilder().registerTypeAdapterFactory(new GsonTypeSerializationLibraryAdapterFactory(library)).registerTypeAdapterFactory(new CaseInsensitiveEnumTypeAdapterFactory()).registerTypeAdapter(UIData.class, new UIDataTypeAdapter()).registerTypeHierarchyAdapter(UIWidget.class, new UIWidgetTypeAdapter(nuiManager));
    // 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.engine.i18n.TranslationSystem) GsonTypeSerializationLibraryAdapterFactory(org.terasology.engine.persistence.typeHandling.gson.GsonTypeSerializationLibraryAdapterFactory) UISkinAsset(org.terasology.nui.skin.UISkinAsset) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) UISkinTypeHandler(org.terasology.engine.persistence.typeHandling.extensionTypes.UISkinTypeHandler) UIData(org.terasology.nui.asset.UIData) CaseInsensitiveEnumTypeAdapterFactory(org.terasology.engine.utilities.gson.CaseInsensitiveEnumTypeAdapterFactory) TypeHandlerLibrary(org.terasology.persistence.typeHandling.TypeHandlerLibrary) NUIManager(org.terasology.engine.rendering.nui.NUIManager)

Example 3 with TranslationSystem

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

the class StateMainMenu method init.

@Override
public void init(GameEngine gameEngine) {
    context = gameEngine.createChildContext();
    headless = context.get(DisplayDevice.class).isHeadless();
    initEntityAndComponentManagers(headless);
    createLocalPlayer(context);
    if (!headless) {
        // TODO: REMOVE this and handle refreshing of core game state at the engine level - see Issue #1127
        new RegisterInputSystem(context).step();
        nuiManager = context.get(NUIManager.class);
        eventSystem.registerEventHandler(nuiManager);
        NUIEditorSystem nuiEditorSystem = new NUIEditorSystem();
        context.put(NUIEditorSystem.class, nuiEditorSystem);
        componentSystemManager.register(nuiEditorSystem, "engine:NUIEditorSystem");
        NUISkinEditorSystem nuiSkinEditorSystem = new NUISkinEditorSystem();
        context.put(NUISkinEditorSystem.class, nuiSkinEditorSystem);
        componentSystemManager.register(nuiSkinEditorSystem, "engine:NUISkinEditorSystem");
        inputSystem = context.get(InputSystem.class);
    }
    componentSystemManager.initialise();
    console = context.get(Console.class);
    storageServiceWorker = context.get(StorageServiceWorker.class);
    playBackgroundMusic();
    if (!headless) {
        // guiManager.openWindow("main");
        context.get(NUIManager.class).pushScreen("engine:mainMenuScreen");
    }
    if (!messageOnLoad.isEmpty()) {
        TranslationSystem translationSystem = context.get(TranslationSystem.class);
        if (headless) {
            throw new RuntimeException(String.format("Game could not be started, server attempted to return to main menu: [%s]. See logs before", translationSystem.translate(messageOnLoad)));
        } else {
            MessagePopup popup = nuiManager.pushScreen(MessagePopup.ASSET_URI, MessagePopup.class);
            popup.setMessage("Error", translationSystem.translate(messageOnLoad));
        }
    }
// TODO: enable it when exposing the telemetry to users
// pushLaunchPopup();
}
Also used : NUIEditorSystem(org.terasology.engine.rendering.nui.editor.systems.NUIEditorSystem) TranslationSystem(org.terasology.engine.i18n.TranslationSystem) Console(org.terasology.engine.logic.console.Console) MessagePopup(org.terasology.engine.rendering.nui.layers.mainMenu.MessagePopup) RegisterInputSystem(org.terasology.engine.core.modes.loadProcesses.RegisterInputSystem) NUISkinEditorSystem(org.terasology.engine.rendering.nui.editor.systems.NUISkinEditorSystem) RegisterInputSystem(org.terasology.engine.core.modes.loadProcesses.RegisterInputSystem) InputSystem(org.terasology.engine.input.InputSystem) NUIManager(org.terasology.engine.rendering.nui.NUIManager) StorageServiceWorker(org.terasology.engine.identity.storageServiceClient.StorageServiceWorker)

Aggregations

TranslationSystem (org.terasology.engine.i18n.TranslationSystem)3 NUIManager (org.terasology.engine.rendering.nui.NUIManager)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 Config (org.terasology.engine.config.Config)1 TelemetryConfig (org.terasology.engine.config.TelemetryConfig)1 RegisterInputSystem (org.terasology.engine.core.modes.loadProcesses.RegisterInputSystem)1 StorageServiceWorker (org.terasology.engine.identity.storageServiceClient.StorageServiceWorker)1 InputSystem (org.terasology.engine.input.InputSystem)1 Console (org.terasology.engine.logic.console.Console)1 UISkinTypeHandler (org.terasology.engine.persistence.typeHandling.extensionTypes.UISkinTypeHandler)1 GsonTypeSerializationLibraryAdapterFactory (org.terasology.engine.persistence.typeHandling.gson.GsonTypeSerializationLibraryAdapterFactory)1 NUIEditorSystem (org.terasology.engine.rendering.nui.editor.systems.NUIEditorSystem)1 NUISkinEditorSystem (org.terasology.engine.rendering.nui.editor.systems.NUISkinEditorSystem)1 LaunchPopup (org.terasology.engine.rendering.nui.layers.mainMenu.LaunchPopup)1 MessagePopup (org.terasology.engine.rendering.nui.layers.mainMenu.MessagePopup)1 TelemetryLogstashAppender (org.terasology.engine.telemetry.logstash.TelemetryLogstashAppender)1 CaseInsensitiveEnumTypeAdapterFactory (org.terasology.engine.utilities.gson.CaseInsensitiveEnumTypeAdapterFactory)1 UIData (org.terasology.nui.asset.UIData)1 UISkinAsset (org.terasology.nui.skin.UISkinAsset)1