use of org.terasology.rendering.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();
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}");
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.rendering.nui.widgets.UILabel in project Terasology by MovingBlocks.
the class JoinGameScreen method bindInfoLabels.
private void bindInfoLabels() {
final ReadOnlyBinding<ServerInfo> infoBinding = new ReadOnlyBinding<ServerInfo>() {
@Override
public ServerInfo get() {
return visibleList.getSelection();
}
};
UILabel name = find("name", UILabel.class);
if (name != null) {
name.bindText(BindHelper.bindBoundBeanProperty("name", infoBinding, ServerInfo.class, String.class));
}
UILabel owner = find("owner", UILabel.class);
if (owner != null) {
owner.bindText(BindHelper.bindBoundBeanProperty("owner", infoBinding, ServerInfo.class, String.class));
}
UILabel address = find("address", UILabel.class);
if (address != null) {
address.bindText(BindHelper.bindBoundBeanProperty("address", infoBinding, ServerInfo.class, String.class));
}
UILabel port = find("port", UILabel.class);
if (port != null) {
port.bindText(new IntToStringBinding(BindHelper.bindBoundBeanProperty("port", infoBinding, ServerInfo.class, int.class)));
}
UILabel onlinePlayers = find("onlinePlayers", UILabel.class);
onlinePlayers.bindText(new ReadOnlyBinding<String>() {
@Override
public String get() {
Future<ServerInfoMessage> info = extInfo.get(visibleList.getSelection());
if (info != null) {
if (info.isDone()) {
return getOnlinePlayersText(info);
} else {
return translationSystem.translate("${engine:menu#join-server-requested}");
}
}
return null;
}
});
UILabel modules = find("modules", UILabel.class);
modules.bindText(new ReadOnlyBinding<String>() {
@Override
public String get() {
Future<ServerInfoMessage> info = extInfo.get(visibleList.getSelection());
if (info != null) {
if (info.isDone()) {
return getModulesText(info);
} else {
return translationSystem.translate("${engine:menu#join-server-requested}");
}
}
return null;
}
});
UILabel worlds = find("worlds", UILabel.class);
worlds.bindText(new ReadOnlyBinding<String>() {
@Override
public String get() {
Future<ServerInfoMessage> info = extInfo.get(visibleList.getSelection());
if (info != null) {
if (info.isDone()) {
return getWorldText(info);
} else {
return translationSystem.translate("${engine:menu#join-server-requested}");
}
}
return null;
}
});
UIButton joinButton = find("join", UIButton.class);
if (joinButton != null) {
joinButton.bindEnabled(new ReadOnlyBinding<Boolean>() {
@Override
public Boolean get() {
return infoBinding.get() != null;
}
});
joinButton.subscribe(button -> {
config.save();
ServerInfo item = infoBinding.get();
if (item != null) {
join(item.getAddress(), item.getPort());
}
});
}
UIButton refreshButton = find("refresh", UIButton.class);
if (refreshButton != null) {
refreshButton.bindEnabled(new ReadOnlyBinding<Boolean>() {
@Override
public Boolean get() {
return visibleList.getSelection() != null;
}
});
refreshButton.subscribe(button -> {
refresh();
});
}
}
use of org.terasology.rendering.nui.widgets.UILabel in project Terasology by MovingBlocks.
the class LaunchPopup 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);
}
}
use of org.terasology.rendering.nui.widgets.UILabel in project Terasology by MovingBlocks.
the class SelectGameScreen method initialise.
@Override
public void initialise() {
setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
UILabel gameTypeTitle = find("gameTypeTitle", UILabel.class);
if (gameTypeTitle != null) {
gameTypeTitle.bindText(new ReadOnlyBinding<String>() {
@Override
public String get() {
if (loadingAsServer) {
return translationSystem.translate("${engine:menu#select-multiplayer-game-sub-title}");
} else {
return translationSystem.translate("${engine:menu#select-singleplayer-game-sub-title}");
}
}
});
}
final UILabel saveGamePath = find("saveGamePath", UILabel.class);
if (saveGamePath != null) {
saveGamePath.setText(translationSystem.translate("${engine:menu#save-game-path} ") + PathManager.getInstance().getSavesPath().toAbsolutePath().toString());
}
final UIList<GameInfo> gameList = find("gameList", UIList.class);
refreshList(gameList);
gameList.select(0);
gameList.subscribe((widget, item) -> loadGame(item));
CreateGameScreen screen = getManager().createScreen(CreateGameScreen.ASSET_URI, CreateGameScreen.class);
WidgetUtil.trySubscribe(this, "create", button -> {
screen.setLoadingAsServer(loadingAsServer);
triggerForwardAnimation(screen);
});
WidgetUtil.trySubscribe(this, "load", button -> {
GameInfo gameInfo = gameList.getSelection();
if (gameInfo != null) {
loadGame(gameInfo);
}
});
WidgetUtil.trySubscribe(this, "delete", button -> {
GameInfo gameInfo = gameList.getSelection();
if (gameInfo != null) {
Path world = PathManager.getInstance().getSavePath(gameInfo.getManifest().getTitle());
try {
FilesUtil.recursiveDelete(world);
gameList.getList().remove(gameInfo);
gameList.setSelection(null);
} catch (Exception e) {
logger.error("Failed to delete saved game", e);
getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Error Deleting Game", e.getMessage());
}
}
});
WidgetUtil.trySubscribe(this, "close", button -> triggerBackAnimation());
}
use of org.terasology.rendering.nui.widgets.UILabel in project Terasology by MovingBlocks.
the class InputSettingsScreen method addInputSection.
private void addInputSection(InputCategory category, ColumnLayout layout, Map<SimpleUri, RegisterBindButton> inputsById) {
if (category != null) {
layout.addWidget(new UISpace(new Vector2i(0, 16)));
UILabel categoryHeader = new UILabel(translationSystem.translate(category.displayName()));
categoryHeader.setFamily("subheading");
layout.addWidget(categoryHeader);
Set<SimpleUri> processedBinds = Sets.newHashSet();
for (String bindId : category.ordering()) {
SimpleUri bindUri = new SimpleUri(bindId);
if (bindUri.isValid()) {
RegisterBindButton bind = inputsById.get(new SimpleUri(bindId));
if (bind != null) {
addInputBindRow(bindUri, bind, layout);
processedBinds.add(bindUri);
}
}
}
List<ExtensionBind> extensionBindList = Lists.newArrayList();
for (Map.Entry<SimpleUri, RegisterBindButton> bind : inputsById.entrySet()) {
if (bind.getValue().category().equals(category.id()) && !processedBinds.contains(bind.getKey())) {
extensionBindList.add(new ExtensionBind(bind.getKey(), bind.getValue()));
}
}
Collections.sort(extensionBindList);
for (ExtensionBind extension : extensionBindList) {
addInputBindRow(extension.uri, extension.bind, layout);
}
}
}
Aggregations