Search in sources :

Example 1 with NUIManager

use of org.terasology.rendering.nui.NUIManager in project Terasology by MovingBlocks.

the class StateHeadlessSetup method init.

@Override
public void init(GameEngine gameEngine) {
    context = gameEngine.createChildContext();
    CoreRegistry.setContext(context);
    // let's get the entity event system running
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    entityManager = context.get(EngineEntityManager.class);
    eventSystem = context.get(EventSystem.class);
    context.put(Console.class, new ConsoleImpl(context));
    NUIManager nuiManager = new NUIManagerInternal(context.get(CanvasRenderer.class), context);
    context.put(NUIManager.class, nuiManager);
    componentSystemManager = new ComponentSystemManager(context);
    context.put(ComponentSystemManager.class, componentSystemManager);
    componentSystemManager.register(new ConsoleSystem(), "engine:ConsoleSystem");
    componentSystemManager.register(new CoreCommands(), "engine:CoreCommands");
    componentSystemManager.register(context.get(InputSystem.class), "engine:InputSystem");
    EntityRef localPlayerEntity = entityManager.create(new ClientComponent());
    LocalPlayer localPlayer = new LocalPlayer();
    context.put(LocalPlayer.class, localPlayer);
    localPlayer.setClientEntity(localPlayerEntity);
    componentSystemManager.initialise();
    GameManifest gameManifest = null;
    List<GameInfo> savedGames = GameProvider.getSavedGames();
    if (savedGames.size() > 0) {
        gameManifest = savedGames.get(0).getManifest();
    } else {
        gameManifest = createGameManifest();
    }
    gameEngine.changeState(new StateLoading(gameManifest, NetworkMode.LISTEN_SERVER));
}
Also used : EngineEntityManager(org.terasology.entitySystem.entity.internal.EngineEntityManager) GameInfo(org.terasology.rendering.nui.layers.mainMenu.savedGames.GameInfo) StateLoading(org.terasology.engine.modes.StateLoading) ConsoleImpl(org.terasology.logic.console.ConsoleImpl) CanvasRenderer(org.terasology.rendering.nui.internal.CanvasRenderer) LocalPlayer(org.terasology.logic.players.LocalPlayer) InputSystem(org.terasology.input.InputSystem) CoreCommands(org.terasology.logic.console.commands.CoreCommands) ClientComponent(org.terasology.network.ClientComponent) NUIManagerInternal(org.terasology.rendering.nui.internal.NUIManagerInternal) ComponentSystemManager(org.terasology.engine.ComponentSystemManager) ConsoleSystem(org.terasology.logic.console.ConsoleSystem) GameManifest(org.terasology.game.GameManifest) EventSystem(org.terasology.entitySystem.event.internal.EventSystem) NUIManager(org.terasology.rendering.nui.NUIManager) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 2 with NUIManager

use of org.terasology.rendering.nui.NUIManager 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 3 with NUIManager

use of org.terasology.rendering.nui.NUIManager in project Terasology by MovingBlocks.

the class PreviewWorldScreen method updatePreview.

private void updatePreview() {
    final NUIManager manager = context.get(NUIManager.class);
    final WaitPopup<TextureData> popup = manager.pushScreen(WaitPopup.ASSET_URI, WaitPopup.class);
    popup.setMessage("Updating Preview", "Please wait ...");
    ProgressListener progressListener = progress -> popup.setMessage("Updating Preview", String.format("Please wait ... %d%%", (int) (progress * 100f)));
    Callable<TextureData> operation = () -> {
        if (seed != null) {
            worldGenerator.setWorldSeed(seed.getText());
        }
        int zoom = TeraMath.floorToInt(zoomSlider.getValue());
        TextureData data = texture.getData();
        if (zoneSelector.isVisible()) {
            previewGen = zoneSelector.getSelection().preview(worldGenerator);
        }
        previewGen.render(data, zoom, progressListener);
        return data;
    };
    popup.onSuccess(texture::reload);
    popup.startOperation(operation, true);
}
Also used : CoreScreenLayer(org.terasology.rendering.nui.CoreScreenLayer) Zone(org.terasology.world.zones.Zone) ContextImpl(org.terasology.context.internal.ContextImpl) DependencyResolver(org.terasology.module.DependencyResolver) UISlider(org.terasology.rendering.nui.widgets.UISlider) LoggerFactory(org.slf4j.LoggerFactory) Config(org.terasology.config.Config) Property(org.terasology.rendering.nui.properties.Property) ByteBuffer(java.nio.ByteBuffer) WorldConfigurator(org.terasology.world.generator.WorldConfigurator) Map(java.util.Map) PropertyLayout(org.terasology.rendering.nui.layouts.PropertyLayout) SimpleUri(org.terasology.engine.SimpleUri) TeraMath(org.terasology.math.TeraMath) Context(org.terasology.context.Context) ModuleAwareAssetTypeManager(org.terasology.assets.module.ModuleAwareAssetTypeManager) WidgetUtil(org.terasology.rendering.nui.WidgetUtil) ModuleEnvironment(org.terasology.module.ModuleEnvironment) ComponentLibrary(org.terasology.entitySystem.metadata.ComponentLibrary) Collectors(java.util.stream.Collectors) PropertyProvider(org.terasology.rendering.nui.properties.PropertyProvider) UIImage(org.terasology.rendering.nui.widgets.UIImage) Objects(java.util.Objects) List(java.util.List) UnresolvedDependencyException(org.terasology.module.exceptions.UnresolvedDependencyException) CoreRegistry(org.terasology.registry.CoreRegistry) TextureData(org.terasology.rendering.assets.texture.TextureData) ResourceUrn(org.terasology.assets.ResourceUrn) In(org.terasology.registry.In) MenuAnimationSystems(org.terasology.rendering.nui.animation.MenuAnimationSystems) Texture(org.terasology.rendering.assets.texture.Texture) Callable(java.util.concurrent.Callable) FacetLayerPreview(org.terasology.rendering.nui.layers.mainMenu.preview.FacetLayerPreview) Lists(com.google.common.collect.Lists) WorldGeneratorPluginLibrary(org.terasology.world.generator.plugin.WorldGeneratorPluginLibrary) ResolutionResult(org.terasology.module.ResolutionResult) NUIManager(org.terasology.rendering.nui.NUIManager) ModuleManager(org.terasology.engine.module.ModuleManager) Assets(org.terasology.utilities.Assets) Logger(org.slf4j.Logger) FieldMetadata(org.terasology.reflection.metadata.FieldMetadata) TempWorldGeneratorPluginLibrary(org.terasology.world.generator.plugin.TempWorldGeneratorPluginLibrary) UIText(org.terasology.rendering.nui.widgets.UIText) WorldGeneratorManager(org.terasology.world.generator.internal.WorldGeneratorManager) UIDropdown(org.terasology.rendering.nui.widgets.UIDropdown) WorldGenerator(org.terasology.world.generator.WorldGenerator) Binding(org.terasology.rendering.nui.databinding.Binding) PreviewGenerator(org.terasology.rendering.nui.layers.mainMenu.preview.PreviewGenerator) Component(org.terasology.entitySystem.Component) EnvironmentSwitchHandler(org.terasology.engine.bootstrap.EnvironmentSwitchHandler) UIButton(org.terasology.rendering.nui.widgets.UIButton) PropertyOrdering(org.terasology.rendering.nui.properties.PropertyOrdering) TextureData(org.terasology.rendering.assets.texture.TextureData) NUIManager(org.terasology.rendering.nui.NUIManager)

Example 4 with NUIManager

use of org.terasology.rendering.nui.NUIManager in project Terasology by MovingBlocks.

the class StateMainMenu method init.

@Override
public void init(GameEngine gameEngine) {
    context = gameEngine.createChildContext();
    CoreRegistry.setContext(context);
    // let's get the entity event system running
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    entityManager = context.get(EngineEntityManager.class);
    eventSystem = context.get(EventSystem.class);
    console = new ConsoleImpl(context);
    context.put(Console.class, console);
    nuiManager = new NUIManagerInternal(context.get(CanvasRenderer.class), context);
    context.put(NUIManager.class, nuiManager);
    eventSystem.registerEventHandler(nuiManager);
    componentSystemManager = new ComponentSystemManager(context);
    context.put(ComponentSystemManager.class, componentSystemManager);
    // TODO: Reduce coupling between Input system and CameraTargetSystem,
    // TODO: potentially eliminating the following lines. See Issue #1126
    CameraTargetSystem cameraTargetSystem = new CameraTargetSystem();
    context.put(CameraTargetSystem.class, cameraTargetSystem);
    componentSystemManager.register(cameraTargetSystem, "engine:CameraTargetSystem");
    componentSystemManager.register(new ConsoleSystem(), "engine:ConsoleSystem");
    componentSystemManager.register(new CoreCommands(), "engine:CoreCommands");
    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);
    // TODO: REMOVE this and handle refreshing of core game state at the engine level - see Issue #1127
    new RegisterInputSystem(context).step();
    EntityRef localPlayerEntity = entityManager.create(new ClientComponent());
    LocalPlayer localPlayer = new LocalPlayer();
    context.put(LocalPlayer.class, localPlayer);
    localPlayer.setClientEntity(localPlayerEntity);
    componentSystemManager.initialise();
    storageServiceWorker = context.get(StorageServiceWorker.class);
    playBackgroundMusic();
    // guiManager.openWindow("main");
    context.get(NUIManager.class).pushScreen("engine:mainMenuScreen");
    if (!messageOnLoad.isEmpty()) {
        nuiManager.pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Error", messageOnLoad);
    }
// TODO: enable it when exposing the telemetry to users
// pushLaunchPopup();
}
Also used : EngineEntityManager(org.terasology.entitySystem.entity.internal.EngineEntityManager) NUIEditorSystem(org.terasology.rendering.nui.editor.systems.NUIEditorSystem) ConsoleImpl(org.terasology.logic.console.ConsoleImpl) LocalPlayer(org.terasology.logic.players.LocalPlayer) MessagePopup(org.terasology.rendering.nui.layers.mainMenu.MessagePopup) NUISkinEditorSystem(org.terasology.rendering.nui.editor.systems.NUISkinEditorSystem) RegisterInputSystem(org.terasology.engine.modes.loadProcesses.RegisterInputSystem) RegisterInputSystem(org.terasology.engine.modes.loadProcesses.RegisterInputSystem) InputSystem(org.terasology.input.InputSystem) CoreCommands(org.terasology.logic.console.commands.CoreCommands) ClientComponent(org.terasology.network.ClientComponent) NUIManagerInternal(org.terasology.rendering.nui.internal.NUIManagerInternal) ComponentSystemManager(org.terasology.engine.ComponentSystemManager) ConsoleSystem(org.terasology.logic.console.ConsoleSystem) EventSystem(org.terasology.entitySystem.event.internal.EventSystem) NUIManager(org.terasology.rendering.nui.NUIManager) EntityRef(org.terasology.entitySystem.entity.EntityRef) StorageServiceWorker(org.terasology.identity.storageServiceClient.StorageServiceWorker) CameraTargetSystem(org.terasology.input.cameraTarget.CameraTargetSystem)

Example 5 with NUIManager

use of org.terasology.rendering.nui.NUIManager in project Terasology by MovingBlocks.

the class InitialiseGraphics method step.

@Override
public boolean step() {
    // Refresh widget library after modules got laoded:
    NUIManager nuiManager = context.get(NUIManager.class);
    ((NUIManagerInternal) nuiManager).refreshWidgetsLibrary();
    // TODO: This should be elsewhere
    // Create gelatinousCubeMesh
    Tessellator tessellator = new Tessellator();
    TessellatorHelper.addBlockMesh(tessellator, new Vector4f(1.0f, 1.0f, 1.0f, 1.0f), 0.8f, 0.8f, 0.6f, 0f, 0f, 0f);
    TessellatorHelper.addBlockMesh(tessellator, new Vector4f(1.0f, 1.0f, 1.0f, 0.6f), 1.0f, 1.0f, 0.8f, 0f, 0f, 0f);
    tessellator.generateMesh(new ResourceUrn(TerasologyConstants.ENGINE_MODULE, new Name("gelatinousCube")));
    return true;
}
Also used : Tessellator(org.terasology.rendering.primitives.Tessellator) Vector4f(org.terasology.math.geom.Vector4f) NUIManager(org.terasology.rendering.nui.NUIManager) ResourceUrn(org.terasology.assets.ResourceUrn) NUIManagerInternal(org.terasology.rendering.nui.internal.NUIManagerInternal) Name(org.terasology.naming.Name)

Aggregations

NUIManager (org.terasology.rendering.nui.NUIManager)5 NUIManagerInternal (org.terasology.rendering.nui.internal.NUIManagerInternal)3 ResourceUrn (org.terasology.assets.ResourceUrn)2 ComponentSystemManager (org.terasology.engine.ComponentSystemManager)2 EntityRef (org.terasology.entitySystem.entity.EntityRef)2 EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)2 EventSystem (org.terasology.entitySystem.event.internal.EventSystem)2 InputSystem (org.terasology.input.InputSystem)2 ConsoleImpl (org.terasology.logic.console.ConsoleImpl)2 ConsoleSystem (org.terasology.logic.console.ConsoleSystem)2 CoreCommands (org.terasology.logic.console.commands.CoreCommands)2 LocalPlayer (org.terasology.logic.players.LocalPlayer)2 Lists (com.google.common.collect.Lists)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 ByteBuffer (java.nio.ByteBuffer)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Callable (java.util.concurrent.Callable)1