use of org.terasology.assets.ResourceUrn in project Terasology by MovingBlocks.
the class NUIManagerInternal method closeScreen.
@Override
public void closeScreen(UIScreenLayer screen) {
if (screens.remove(screen)) {
ResourceUrn screenUri = screenLookup.inverse().remove(screen);
onCloseScreen(screen, screenUri, true);
}
}
use of org.terasology.assets.ResourceUrn in project Terasology by MovingBlocks.
the class NUIManagerInternal method invalidate.
@Override
public void invalidate() {
assetManager.getLoadedAssets(UIElement.class).forEach(UIElement::dispose);
boolean hudVisible = isHUDVisible();
if (hudVisible) {
setHUDVisible(false);
}
Deque<ResourceUrn> reverseUrns = new LinkedList<>();
Map<UIScreenLayer, ResourceUrn> inverseLookup = screenLookup.inverse();
for (UIScreenLayer screen : screens) {
screen.onClosed();
reverseUrns.addFirst(inverseLookup.get(screen));
}
screens.clear();
screenLookup.clear();
reverseUrns.forEach(this::pushScreen);
if (hudVisible) {
setHUDVisible(true);
}
}
use of org.terasology.assets.ResourceUrn in project Terasology by MovingBlocks.
the class NUIManagerInternal method pushScreen.
@Override
public void pushScreen(UIScreenLayer screen) {
if (!screen.isLowerLayerVisible()) {
UIScreenLayer current = screens.peek();
if (current != null) {
current.onHide();
}
}
screens.push(screen);
screen.onOpened();
String id = screen.getId();
if (ResourceUrn.isValid(id)) {
ResourceUrn uri = new ResourceUrn(id);
screenLookup.put(uri, screen);
}
}
use of org.terasology.assets.ResourceUrn in project Terasology by MovingBlocks.
the class PreviewWorldScreen method genTexture.
private void genTexture() {
int imgWidth = 384;
int imgHeight = 384;
ByteBuffer buffer = ByteBuffer.allocateDirect(imgWidth * imgHeight * Integer.BYTES);
ByteBuffer[] data = new ByteBuffer[] { buffer };
ResourceUrn uri = new ResourceUrn("engine:terrainPreview");
TextureData texData = new TextureData(imgWidth, imgHeight, data, Texture.WrapMode.CLAMP, Texture.FilterMode.LINEAR);
texture = Assets.generateAsset(uri, texData, Texture.class);
previewImage = find("preview", UIImage.class);
previewImage.setImage(texture);
}
use of org.terasology.assets.ResourceUrn 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();
}
});
}
}
Aggregations