use of org.terasology.nui.widgets.UILabel in project Terasology by MovingBlocks.
the class NUIEditorScreen method resetPreviewWidget.
/**
* {@inheritDoc}
*/
@Override
public void resetPreviewWidget() {
try {
// Serialize the editor's contents and update the widget.
JsonElement element = JsonTreeConverter.deserialize(getEditor().getRoot());
UIWidget widget = new UIFormat().load(element, alternativeLocale).getRootWidget();
selectedScreenBox.setContent(widget);
} catch (Throwable t) {
String truncatedStackTrace = Joiner.on(System.lineSeparator()).join(Arrays.copyOfRange(ExceptionUtils.getStackFrames(t), 0, 10));
selectedScreenBox.setContent(new UILabel(truncatedStackTrace));
}
}
use of org.terasology.nui.widgets.UILabel in project Terasology by MovingBlocks.
the class JoinGameScreen method refreshPing.
private void refreshPing() {
String address = visibleList.getSelection().getAddress();
int port = visibleList.getSelection().getPort();
String name = visibleList.getSelection().getName();
UILabel ping = find("ping", UILabel.class);
ping.setText("Requested");
Thread getPing = new Thread(() -> {
PingService pingService = new PingService(address, port);
// we're not on the game thread, so we cannot modify GUI elements directly
try {
long responseTime = pingService.call();
if (visibleList.getSelection().getAddress().equals(address)) {
GameThread.asynch(() -> ping.setText(responseTime + " ms."));
}
} catch (IOException e) {
String text = translationSystem.translate("${engine:menu#connection-failed}");
// Check if selection name is same as earlier when response is received before updating ping field
if (name.equals(visibleList.getSelection().getName())) {
GameThread.asynch(() -> ping.setText(FontColor.getColored(text, Color.RED)));
}
}
});
// TODO: once the common thread pool is in place this could be posted there and the
// returned Future could be kept and cancelled as soon the selected menu entry changes
getPing.start();
}
use of org.terasology.nui.widgets.UILabel in project Terasology by MovingBlocks.
the class JoinGameScreen method bindCustomButtons.
private void bindCustomButtons() {
UIList<?> customServerList = find("customServerList", UIList.class);
ReadOnlyBinding<Boolean> localSelectedServerOnly = new ReadOnlyBinding<Boolean>() {
@Override
public Boolean get() {
return customServerList.getSelection() != null;
}
};
UIButton add = find("add", UIButton.class);
if (add != null) {
add.subscribe(button -> {
AddServerPopup popup = getManager().pushScreen(AddServerPopup.ASSET_URI, AddServerPopup.class);
// select the entry if added successfully
popup.onSuccess(item -> {
config.getNetwork().addServerInfo(item);
visibleList.setSelection(item);
});
});
}
UIButton edit = find("edit", UIButton.class);
if (edit != null) {
edit.bindEnabled(localSelectedServerOnly);
edit.subscribe(button -> {
AddServerPopup popup = getManager().pushScreen(AddServerPopup.ASSET_URI, AddServerPopup.class);
ServerInfo info = visibleList.getSelection();
popup.setServerInfo(info);
// editing invalidates the currently known info, so query it again
popup.onSuccess(item -> extInfo.put(item, infoService.requestInfo(item.getAddress(), item.getPort())));
});
}
UIButton removeButton = find("remove", UIButton.class);
if (removeButton != null) {
removeButton.bindEnabled(localSelectedServerOnly);
removeButton.subscribe(button -> {
ServerInfo info = visibleList.getSelection();
if (info != null) {
config.getNetwork().removeServerInfo(info);
extInfo.remove(info);
visibleList.setSelection(null);
}
});
}
UILabel downloadLabel = find("download", UILabel.class);
if (downloadLabel != null) {
downloadLabel.bindText(new ReadOnlyBinding<String>() {
@Override
public String get() {
return translationSystem.translate(downloader.getStatus());
}
});
}
}
use of org.terasology.nui.widgets.UILabel in project Terasology by MovingBlocks.
the class MainMenuScreen method initialise.
@Override
public void initialise() {
setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
UILabel versionLabel = find("version", UILabel.class);
versionLabel.setText(TerasologyVersion.getInstance().getHumanVersion());
UILabel jvmWarningLabel = find("nonNativeJvmWarning", UILabel.class);
jvmWarningLabel.setVisible(NonNativeJVMDetector.JVM_ARCH_IS_NONNATIVE);
SelectGameScreen selectScreen = getManager().createScreen(SelectGameScreen.ASSET_URI, SelectGameScreen.class);
UniverseWrapper universeWrapper = new UniverseWrapper();
WidgetUtil.trySubscribe(this, "singleplayer", button -> {
universeWrapper.setLoadingAsServer(false);
selectScreen.setUniverseWrapper(universeWrapper);
triggerForwardAnimation(selectScreen);
});
WidgetUtil.trySubscribe(this, "multiplayer", button -> {
universeWrapper.setLoadingAsServer(true);
selectScreen.setUniverseWrapper(universeWrapper);
triggerForwardAnimation(selectScreen);
});
WidgetUtil.trySubscribe(this, "join", button -> {
if (storageService.getStatus() == StorageServiceWorkerStatus.WORKING) {
ConfirmPopup confirmPopup = getManager().pushScreen(ConfirmPopup.ASSET_URI, ConfirmPopup.class);
confirmPopup.setMessage(translationSystem.translate("${engine:menu#warning}"), translationSystem.translate("${engine:menu#storage-service-working}"));
confirmPopup.setOkHandler(() -> triggerForwardAnimation(JoinGameScreen.ASSET_URI));
} else {
triggerForwardAnimation(JoinGameScreen.ASSET_URI);
}
});
WidgetUtil.trySubscribe(this, "settings", button -> triggerForwardAnimation(SettingsMenuScreen.ASSET_URI));
WidgetUtil.trySubscribe(this, "extras", button -> triggerForwardAnimation(ExtrasMenuScreen.ASSET_URI));
WidgetUtil.trySubscribe(this, "exit", button -> engine.shutdown());
WidgetUtil.trySubscribe(this, "storageServiceAction", widget -> triggerForwardAnimation(PlayerSettingsScreen.ASSET_URI));
}
use of org.terasology.nui.widgets.UILabel in project Terasology by MovingBlocks.
the class MessagePopup method setMessage.
public void setMessage(String title, String message) {
UILabel titleLabel = find("title", UILabel.class);
if (titleLabel != null) {
titleLabel.setText(title);
}
UILabel messageLabel = find("message", UILabel.class);
if (messageLabel != null) {
messageLabel.setText(message);
}
}
Aggregations