use of org.terasology.engine.config.ServerInfo in project Terasology by MovingBlocks.
the class JoinGameScreen method refresh.
public void refresh() {
ServerInfo i = visibleList.getSelection();
visibleList.setSelection(null);
extInfo.clear();
visibleList.setSelection(i);
}
use of org.terasology.engine.config.ServerInfo in project Terasology by MovingBlocks.
the class AddServerPopup method initialise.
@Override
public void initialise() {
nameText = find("name", UIText.class);
ownerText = find("owner", UIText.class);
addressText = find("address", UIText.class);
portText = find("port", UIText.class);
okButton = find("ok", UIButton.class);
cancelButton = find("cancel", UIButton.class);
tip = find("tip", UILabel.class);
okButton.subscribe(button -> {
String name = nameText.getText();
String owner = ownerText.getText();
String address = addressText.getText();
Integer portBoxed = Ints.tryParse(portText.getText().trim());
int port = (portBoxed != null) ? portBoxed : TerasologyConstants.DEFAULT_PORT;
if (serverInfo == null) {
// create new
serverInfo = new ServerInfo(name, address, port);
serverInfo.setOwner(owner);
} else {
// update existing
serverInfo.setName(name);
serverInfo.setAddress(address);
serverInfo.setPort(port);
serverInfo.setOwner(owner);
}
if (successFunc != null) {
successFunc.accept(serverInfo);
}
getManager().popScreen();
});
okButton.bindEnabled(new ReadOnlyBinding<Boolean>() {
@Override
public Boolean get() {
return !nameText.getText().isEmpty() && !addressText.getText().isEmpty() && Ints.tryParse(portText.getText().trim()) != null;
}
});
cancelButton.subscribe(button -> getManager().popScreen());
// copy name to address on ENTER if address is empty
nameText.subscribe(widget -> {
if (addressText.getText().isEmpty()) {
addressText.setText(nameText.getText());
addressText.setCursorPosition(addressText.getText().length());
}
getManager().setFocus(addressText);
});
// simulate tabbing behavior
// TODO: replace with NUI tabbing, once available
addressText.subscribe(widget -> {
getManager().setFocus(portText);
});
}
use of org.terasology.engine.config.ServerInfo in project Terasology by MovingBlocks.
the class TelemetryScreen method pushAddServerPopupAndStartEmitter.
private void pushAddServerPopupAndStartEmitter() {
AddServerPopup addServerPopup = nuiManager.pushScreen(AddServerPopup.ASSET_URI, AddServerPopup.class);
addServerPopup.removeTip();
ServerInfo serverInfo;
TelemetryConfig telemetryConfig = config.getTelemetryConfig();
String telemetryDestination = telemetryConfig.getTelemetryDestination();
if (telemetryDestination != null) {
try {
URL url = new URL(telemetryDestination);
String address = url.getHost();
int port = url.getPort();
serverInfo = new ServerInfo(telemetryConfig.getTelemetryServerName(), address, port);
serverInfo.setOwner(telemetryConfig.getTelemetryServerOwner());
} catch (Exception e) {
logger.error("Exception when get telemetry server information", e);
serverInfo = new ServerInfo(TelemetryEmitter.DEFAULT_COLLECTOR_NAME, TelemetryEmitter.DEFAULT_COLLECTOR_HOST, TelemetryEmitter.DEFAULT_COLLECTOR_PORT);
serverInfo.setOwner(TelemetryEmitter.DEFAULT_COLLECTOR_OWNER);
}
} else {
serverInfo = new ServerInfo(TelemetryEmitter.DEFAULT_COLLECTOR_NAME, TelemetryEmitter.DEFAULT_COLLECTOR_HOST, TelemetryEmitter.DEFAULT_COLLECTOR_PORT);
serverInfo.setOwner(TelemetryEmitter.DEFAULT_COLLECTOR_OWNER);
}
addServerPopup.setServerInfo(serverInfo);
addServerPopup.onSuccess((item) -> {
TelemetryEmitter telemetryEmitter = (TelemetryEmitter) emitter;
Optional<URL> optionalURL = item.getURL("http");
if (optionalURL.isPresent()) {
telemetryEmitter.changeUrl(optionalURL.get());
// Save the telemetry destination
telemetryConfig.setTelemetryDestination(optionalURL.get().toString());
telemetryConfig.setTelemetryServerName(item.getName());
telemetryConfig.setTelemetryServerOwner(item.getOwner());
}
});
addServerPopup.onCancel((button) -> config.getTelemetryConfig().setTelemetryEnabled(false));
}
Aggregations