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));
}
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);
}
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);
}
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();
}
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;
}
Aggregations