use of org.terasology.nui.widgets.UIButton in project Terasology by MovingBlocks.
the class InputSettingsScreen method initialise.
@Override
public void initialise() {
setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
ColumnLayout mainLayout = find("main", ColumnLayout.class);
UIButton azerty = find("azerty", UIButton.class);
if (azerty != null) {
azerty.subscribe(event -> {
BindCommands.AZERTY.forEach(this::setPrimaryBind);
bindsManager.registerBinds();
});
}
UIButton dvorak = find("dvorak", UIButton.class);
if (dvorak != null) {
dvorak.subscribe(event -> {
BindCommands.DVORAK.forEach(this::setPrimaryBind);
bindsManager.registerBinds();
});
}
UIButton neo = find("neo", UIButton.class);
if (neo != null) {
neo.subscribe(event -> {
BindCommands.NEO.forEach(this::setPrimaryBind);
bindsManager.registerBinds();
});
}
UISlider mouseSensitivity = new UISlider("mouseSensitivity");
mouseSensitivity.bindValue(BindHelper.bindBeanProperty("mouseSensitivity", inputDeviceConfiguration, Float.TYPE));
mouseSensitivity.setIncrement(0.025f);
mouseSensitivity.setPrecision(3);
UICheckbox mouseInverted = new UICheckbox("mouseYAxisInverted");
mouseInverted.bindChecked(BindHelper.bindBeanProperty("mouseYAxisInverted", inputDeviceConfiguration, Boolean.TYPE));
if (mainLayout != null) {
mainLayout.addWidget(new UILabel("mouseLabel", "subheading", translationSystem.translate("${engine:menu" + "#category-mouse}")));
mainLayout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#mouse" + "-sensitivity}") + ":"), mouseSensitivity).setColumnRatios(0.4f).setHorizontalSpacing(horizontalSpacing));
mainLayout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#invert-mouse}") + ":"), mouseInverted).setColumnRatios(0.4f).setHorizontalSpacing(horizontalSpacing));
}
Map<String, InputCategory> inputCategories = Maps.newHashMap();
Map<SimpleUri, RegisterBindButton> inputsById = Maps.newHashMap();
DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
for (Name moduleId : moduleManager.getRegistry().getModuleIds()) {
Module module = moduleManager.getRegistry().getLatestModuleVersion(moduleId);
ResolutionResult result = resolver.resolve(moduleId);
if (result.isSuccess()) {
try (ModuleEnvironment environment = moduleManager.loadEnvironment(result.getModules(), false)) {
for (Class<?> holdingType : environment.getTypesAnnotatedWith(InputCategory.class, new FromModule(environment, moduleId))) {
InputCategory inputCategory = holdingType.getAnnotation(InputCategory.class);
inputCategories.put(module.getId() + ":" + inputCategory.id(), inputCategory);
}
for (Class<?> bindEvent : environment.getTypesAnnotatedWith(RegisterBindButton.class, new FromModule(environment, moduleId))) {
if (BindButtonEvent.class.isAssignableFrom(bindEvent)) {
RegisterBindButton bindRegister = bindEvent.getAnnotation(RegisterBindButton.class);
inputsById.put(new SimpleUri(module.getId(), bindRegister.id()), bindRegister);
}
}
}
}
}
if (mainLayout != null) {
addInputSection(inputCategories.remove("engine:movement"), mainLayout, inputsById);
addInputSection(inputCategories.remove("engine:interaction"), mainLayout, inputsById);
addInputSection(inputCategories.remove("engine:inventory"), mainLayout, inputsById);
addInputSection(inputCategories.remove("engine:general"), mainLayout, inputsById);
for (InputCategory category : inputCategories.values()) {
addInputSection(category, mainLayout, inputsById);
}
mainLayout.addWidget(new UISpace(new Vector2i(1, 16)));
List<String> controllers = inputSystem.getControllerDevice().getControllers();
for (String name : controllers) {
ControllerInfo cfg = inputDeviceConfiguration.getController(name);
addInputSection(mainLayout, name, cfg);
}
}
WidgetUtil.trySubscribe(this, "reset", button -> {
inputDeviceConfiguration.reset();
bindsManager.getBindsConfig().setBinds(bindsManager.getDefaultBindsConfig());
});
WidgetUtil.trySubscribe(this, "back", button -> triggerBackAnimation());
}
use of org.terasology.nui.widgets.UIButton in project Terasology by MovingBlocks.
the class NUIEditorScreen method initialise.
@Override
public void initialise() {
// Retrieve the widgets based on their identifiers.
UIDropdownScrollable<String> availableAssetDropdown = find(AVAILABLE_ASSETS_ID, UIDropdownScrollable.class);
JsonEditorTreeView editor = find(EDITOR_TREE_VIEW_ID, JsonEditorTreeView.class);
selectedScreenBox = find(SELECTED_SCREEN_ID, UIBox.class);
super.setEditorSystem(nuiEditorSystem);
super.setEditor(editor);
// Populate the list of screens.
List<String> availableAssetList = Lists.newArrayList();
availableAssetList.add(CREATE_NEW_SCREEN);
availableAssetList.addAll(assetManager.getAvailableAssets(UIElement.class).stream().map(Object::toString).collect(Collectors.toList()));
Collections.sort(availableAssetList);
if (availableAssetDropdown != null) {
availableAssetDropdown.setOptions(availableAssetList);
availableAssetDropdown.bindSelection(new Binding<String>() {
@Override
public String get() {
return selectedAsset;
}
@Override
public void set(String value) {
// Construct a new screen tree (or de-serialize from an existing asset)
selectedAssetPending = value;
if (CREATE_NEW_SCREEN.equals(value)) {
selectedAssetPath = null;
resetState(NUIEditorNodeUtils.createNewScreen());
} else {
selectAsset(new ResourceUrn(value));
}
}
});
}
if (editor != null) {
editor.subscribeTreeViewUpdate(() -> {
getEditor().addToHistory();
resetPreviewWidget();
updateConfig();
setUnsavedChangesPresent(true);
updateAutosave();
});
editor.setContextMenuTreeProducer(node -> {
NUIEditorMenuTreeBuilder nuiEditorMenuTreeBuilder = new NUIEditorMenuTreeBuilder();
nuiEditorMenuTreeBuilder.setManager(getManager());
nuiEditorMenuTreeBuilder.putConsumer(NUIEditorMenuTreeBuilder.OPTION_COPY, getEditor()::copyNode);
nuiEditorMenuTreeBuilder.putConsumer(NUIEditorMenuTreeBuilder.OPTION_PASTE, getEditor()::pasteNode);
nuiEditorMenuTreeBuilder.putConsumer(NUIEditorMenuTreeBuilder.OPTION_EDIT, this::editNode);
nuiEditorMenuTreeBuilder.putConsumer(NUIEditorMenuTreeBuilder.OPTION_DELETE, getEditor()::deleteNode);
nuiEditorMenuTreeBuilder.putConsumer(NUIEditorMenuTreeBuilder.OPTION_ADD_WIDGET, this::addWidget);
nuiEditorMenuTreeBuilder.subscribeAddContextMenu(n -> {
getEditor().fireUpdateListeners();
// Automatically edit a node that's been added.
if (n.getValue().getType() == JsonTreeValue.Type.KEY_VALUE_PAIR) {
getEditor().getModel().getNode(getEditor().getSelectedIndex()).setExpanded(true);
getEditor().getModel().resetNodes();
getEditor().setSelectedIndex(getEditor().getModel().indexOf(n));
editNode(n);
}
});
return nuiEditorMenuTreeBuilder.createPrimaryContextMenu(node);
});
editor.setEditor(this::editNode, getManager());
}
UIButton save = find("save", UIButton.class);
save.bindEnabled(new ReadOnlyBinding<Boolean>() {
@Override
public Boolean get() {
return CREATE_NEW_SCREEN.equals(selectedAsset) || areUnsavedChangesPresent();
}
});
save.subscribe(button -> {
// Save the current look and feel.
LookAndFeel currentLookAndFeel = UIManager.getLookAndFeel();
// (Temporarily) set the look and feel to the system default.
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException | UnsupportedLookAndFeelException ignored) {
}
// Configure the file chooser.
JFileChooser fileChooser = new JFileChooser() {
@Override
protected JDialog createDialog(Component parent) {
JDialog dialog = super.createDialog(parent);
dialog.setLocationByPlatform(true);
dialog.setAlwaysOnTop(true);
return dialog;
}
};
fileChooser.setSelectedFile(new File(CREATE_NEW_SCREEN.equals(selectedAsset) ? "untitled.ui" : selectedAsset.split(":")[1] + ".ui"));
fileChooser.setFileFilter(new FileNameExtensionFilter("UI asset file (*.ui)", "ui"));
if (fileChooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
saveToFile(fileChooser.getSelectedFile());
deleteAutosave();
}
// Reload the look and feel.
try {
UIManager.setLookAndFeel(currentLookAndFeel);
} catch (UnsupportedLookAndFeelException ignored) {
}
});
UIButton override = find("override", UIButton.class);
override.bindEnabled(new ReadOnlyBinding<Boolean>() {
@Override
public Boolean get() {
return selectedAssetPath != null && areUnsavedChangesPresent();
}
});
override.subscribe(button -> {
saveToFile(selectedAssetPath);
deleteAutosave();
});
// Set the handlers for the editor buttons.
WidgetUtil.trySubscribe(this, "settings", button -> getManager().pushScreen(NUIEditorSettingsScreen.ASSET_URI, NUIEditorSettingsScreen.class));
WidgetUtil.trySubscribe(this, "copy", button -> copyJson());
WidgetUtil.trySubscribe(this, "paste", button -> pasteJson());
WidgetUtil.trySubscribe(this, "undo", button -> undo());
WidgetUtil.trySubscribe(this, "redo", button -> redo());
WidgetUtil.trySubscribe(this, "close", button -> nuiEditorSystem.toggleEditor());
updateConfig();
}
use of org.terasology.nui.widgets.UIButton in project Terasology by MovingBlocks.
the class ConfirmUrlPopup method setRightButton.
public void setRightButton(String text, Runnable action) {
UIButton rightButton = find("rightButton", UIButton.class);
if (rightButton != null) {
rightButton.setText(text);
}
rightAction = action;
}
use of org.terasology.nui.widgets.UIButton in project Terasology by MovingBlocks.
the class NUISkinEditorScreen method initialise.
@Override
public void initialise() {
// Retrieve the widgets based on their identifiers.
availableAssetDropdown = find(AVAILABLE_ASSETS_ID, UIDropdownScrollable.class);
UIDropdownScrollable<ResourceUrn> availableScreenDropdown = find(AVAILABLE_SCREENS_ID, UIDropdownScrollable.class);
JsonEditorTreeView editor = find(EDITOR_TREE_VIEW_ID, JsonEditorTreeView.class);
selectedScreenBox = find(SELECTED_SCREEN_ID, UIBox.class);
super.setEditorSystem(nuiSkinEditorSystem);
super.setEditor(editor);
// Populate the list of screens.
List<String> availableAssetList = Lists.newArrayList();
availableAssetList.add(CREATE_NEW_SKIN);
availableAssetList.addAll(assetManager.getAvailableAssets(UISkinAsset.class).stream().map(Object::toString).collect(Collectors.toList()));
Collections.sort(availableAssetList);
if (availableAssetDropdown != null) {
availableAssetDropdown.setOptions(availableAssetList);
availableAssetDropdown.bindSelection(new Binding<String>() {
@Override
public String get() {
return selectedAsset;
}
@Override
public void set(String value) {
// Construct a new skin tree (or de-serialize from an existing asset)
selectedAssetPending = value;
if (CREATE_NEW_SKIN.equals(value)) {
selectedAssetPath = null;
resetState(NUIEditorNodeUtils.createNewSkin());
} else {
selectAsset(new ResourceUrn(value));
}
}
});
}
if (availableScreenDropdown != null) {
List<ResourceUrn> availableScreenList = Lists.newArrayList(assetManager.getAvailableAssets(UIElement.class));
Collections.sort(availableScreenList);
availableScreenDropdown.setOptions(availableScreenList);
availableScreenDropdown.bindEnabled(new ReadOnlyBinding<Boolean>() {
@Override
public Boolean get() {
return selectedAsset != null;
}
});
availableScreenDropdown.bindSelection(new Binding<ResourceUrn>() {
@Override
public ResourceUrn get() {
return selectedScreen;
}
@Override
public void set(ResourceUrn value) {
selectedScreen = value;
resetPreviewWidget();
}
});
}
if (editor != null) {
editor.setContextMenuTreeProducer(node -> {
NUIEditorMenuTreeBuilder nuiEditorMenuTreeBuilder = new NUIEditorMenuTreeBuilder();
nuiEditorMenuTreeBuilder.setManager(getManager());
nuiEditorMenuTreeBuilder.putConsumer(NUIEditorMenuTreeBuilder.OPTION_COPY, getEditor()::copyNode);
nuiEditorMenuTreeBuilder.putConsumer(NUIEditorMenuTreeBuilder.OPTION_PASTE, getEditor()::pasteNode);
nuiEditorMenuTreeBuilder.putConsumer(NUIEditorMenuTreeBuilder.OPTION_EDIT, this::editNode);
nuiEditorMenuTreeBuilder.putConsumer(NUIEditorMenuTreeBuilder.OPTION_DELETE, getEditor()::deleteNode);
nuiEditorMenuTreeBuilder.putConsumer(NUIEditorMenuTreeBuilder.OPTION_ADD_WIDGET, this::addWidget);
nuiEditorMenuTreeBuilder.subscribeAddContextMenu(n -> {
getEditor().fireUpdateListeners();
// Automatically edit a node that's been added.
if (n.getValue().getType() == JsonTreeValue.Type.KEY_VALUE_PAIR) {
getEditor().getModel().getNode(getEditor().getSelectedIndex()).setExpanded(true);
getEditor().getModel().resetNodes();
getEditor().setSelectedIndex(getEditor().getModel().indexOf(n));
editNode(n);
}
});
return nuiEditorMenuTreeBuilder.createPrimarySkinContextMenu(node);
});
editor.setEditor(this::editNode, getManager());
editor.subscribeTreeViewUpdate(() -> {
getEditor().addToHistory();
resetPreviewWidget();
updateConfig();
setUnsavedChangesPresent(true);
updateAutosave();
});
}
UIButton save = find("save", UIButton.class);
save.bindEnabled(new ReadOnlyBinding<Boolean>() {
@Override
public Boolean get() {
return CREATE_NEW_SKIN.equals(selectedAsset) || areUnsavedChangesPresent();
}
});
save.subscribe(button -> {
// Save the current look and feel.
LookAndFeel currentLookAndFeel = UIManager.getLookAndFeel();
// (Temporarily) set the look and feel to the system default.
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException | UnsupportedLookAndFeelException ignored) {
}
// Configure the file chooser.
JFileChooser fileChooser = new JFileChooser() {
@Override
protected JDialog createDialog(Component parent) {
JDialog dialog = super.createDialog(parent);
dialog.setLocationByPlatform(true);
dialog.setAlwaysOnTop(true);
return dialog;
}
};
fileChooser.setSelectedFile(new File(CREATE_NEW_SKIN.equals(selectedAsset) ? "untitled.skin" : selectedAsset.split(":")[1] + ".skin"));
fileChooser.setFileFilter(new FileNameExtensionFilter("Skin asset file (*.skin)", "skin"));
if (fileChooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
saveToFile(fileChooser.getSelectedFile());
deleteAutosave();
}
// Reload the look and feel.
try {
UIManager.setLookAndFeel(currentLookAndFeel);
} catch (UnsupportedLookAndFeelException ignored) {
}
});
UIButton override = find("override", UIButton.class);
override.bindEnabled(new ReadOnlyBinding<Boolean>() {
@Override
public Boolean get() {
return selectedAssetPath != null && areUnsavedChangesPresent();
}
});
override.subscribe(button -> {
saveToFile(selectedAssetPath);
deleteAutosave();
});
// Set the handlers for the editor buttons.
WidgetUtil.trySubscribe(this, "settings", button -> getManager().pushScreen(NUIEditorSettingsScreen.ASSET_URI, NUIEditorSettingsScreen.class));
WidgetUtil.trySubscribe(this, "copy", button -> copyJson());
WidgetUtil.trySubscribe(this, "paste", button -> pasteJson());
WidgetUtil.trySubscribe(this, "undo", button -> undo());
WidgetUtil.trySubscribe(this, "redo", button -> redo());
WidgetUtil.trySubscribe(this, "close", button -> nuiSkinEditorSystem.toggleEditor());
updateConfig();
}
use of org.terasology.nui.widgets.UIButton in project Terasology by MovingBlocks.
the class AdvancedGameSetupScreen method initialise.
@Override
public void initialise() {
setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
remoteModuleRegistryUpdater = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat(new TargetLengthBasedClassNameAbbreviator(36).abbreviate(getClass().getName()) + "-%d").setDaemon(true).build()).submit(moduleManager.getInstallManager().updateRemoteRegistry());
final UIText seed = find("seed", UIText.class);
if (seed != null) {
seed.setText(new FastRandom().nextString(32));
}
// skip loading module configs, limit shown modules to locally present ones
selectModulesConfig = new SelectModulesConfig();
selectModulesConfig.getSelectedStandardModuleExtensions().forEach(selectModulesConfig::unselectStandardModuleExtension);
selectModulesConfig.toggleIsLocalOnlySelected();
dependencyResolver = new DependencyResolver(moduleManager.getRegistry());
modulesLookup = Maps.newHashMap();
sortedModules = Lists.newArrayList();
for (Name moduleId : moduleManager.getRegistry().getModuleIds()) {
Module latestVersion = moduleManager.getRegistry().getLatestModuleVersion(moduleId);
ModuleSelectionInfo info = ModuleSelectionInfo.local(latestVersion);
modulesLookup.put(info.getMetadata().getId(), info);
sortedModules.add(info);
}
sortedModules.sort(moduleInfoComparator);
allSortedModules = new ArrayList<>(sortedModules);
final UIList<ModuleSelectionInfo> moduleList = find("moduleList", UIList.class);
if (moduleList != null) {
moduleList.setList(sortedModules);
moduleList.setItemRenderer(new AbstractItemRenderer<ModuleSelectionInfo>() {
String getString(ModuleSelectionInfo value) {
return value.getMetadata().getDisplayName().toString();
}
@Override
public void draw(ModuleSelectionInfo value, Canvas canvas) {
if (isSelectedGameplayModule(value) && value.isValidToSelect()) {
canvas.setMode("gameplay");
} else if (value.isSelected() && value.isExplicitSelection()) {
canvas.setMode("enabled");
} else if (value.isSelected()) {
canvas.setMode("dependency");
} else if (!value.isPresent()) {
canvas.setMode("disabled");
} else if (!value.isValidToSelect()) {
canvas.setMode("invalid");
} else {
canvas.setMode("available");
}
canvas.drawText(getString(value), canvas.getRegion());
}
@Override
public Vector2i getPreferredSize(ModuleSelectionInfo value, Canvas canvas) {
String text = getString(value);
return new Vector2i(canvas.getCurrentStyle().getFont().getWidth(text), canvas.getCurrentStyle().getFont().getLineHeight());
}
});
// ItemActivateEventListener is triggered by double clicking
moduleList.subscribe((widget, item) -> {
if (item.isSelected() && moduleList.getSelection().isExplicitSelection()) {
deselect(item);
} else if (item.isValidToSelect()) {
select(item);
}
});
moduleSearch = find("moduleSearch", ResettableUIText.class);
if (moduleSearch != null) {
moduleSearch.subscribe((TextChangeEventListener) (oldText, newText) -> filterModules());
}
final Binding<ModuleMetadata> moduleInfoBinding = new ReadOnlyBinding<ModuleMetadata>() {
@Override
public ModuleMetadata get() {
if (moduleList.getSelection() != null) {
return moduleList.getSelection().getMetadata();
}
return null;
}
};
UILabel name = find("name", UILabel.class);
if (name != null) {
name.bindText(new ReadOnlyBinding<String>() {
@Override
public String get() {
if (moduleInfoBinding.get() != null) {
return moduleInfoBinding.get().getDisplayName().toString();
}
return "";
}
});
}
UILabel installedVersion = find("installedVersion", UILabel.class);
if (installedVersion != null) {
installedVersion.bindText(new ReadOnlyBinding<String>() {
@Override
public String get() {
ModuleSelectionInfo sel = moduleList.getSelection();
if (sel == null) {
return "";
}
return sel.isPresent() ? sel.getMetadata().getVersion().toString() : translationSystem.translate("${engine:menu#module-version-installed-none}");
}
});
}
UILabel onlineVersion = find("onlineVersion", UILabel.class);
if (onlineVersion != null) {
onlineVersion.bindText(new ReadOnlyBinding<String>() {
@Override
public String get() {
ModuleSelectionInfo sel = moduleList.getSelection();
if (sel == null) {
return "";
}
return (sel.getOnlineVersion() != null) ? sel.getOnlineVersion().getVersion().toString() : "none";
}
});
}
UILabel description = find("description", UILabel.class);
if (description != null) {
description.bindText(new ReadOnlyBinding<String>() {
@Override
public String get() {
ModuleMetadata moduleMetadata = moduleInfoBinding.get();
if (moduleMetadata != null) {
StringBuilder dependenciesNames;
List<DependencyInfo> dependencies = moduleMetadata.getDependencies();
if (dependencies != null && !dependencies.isEmpty()) {
dependenciesNames = new StringBuilder(translationSystem.translate("${engine:menu#module-dependencies-exist}") + ":" + '\n');
for (DependencyInfo dependency : dependencies) {
dependenciesNames.append(" ").append(dependency.getId().toString()).append('\n');
}
} else {
dependenciesNames = new StringBuilder(translationSystem.translate("${engine:menu#module-dependencies-empty}") + ".");
}
return moduleMetadata.getDescription().toString() + '\n' + '\n' + dependenciesNames;
}
return "";
}
});
}
UILabel status = find("status", UILabel.class);
if (status != null) {
status.bindText(new ReadOnlyBinding<String>() {
@Override
public String get() {
ModuleSelectionInfo info = moduleList.getSelection();
if (info != null) {
if (isSelectedGameplayModule(info)) {
return translationSystem.translate("${engine:menu#module-status-activegameplay}");
} else if (info.isSelected() && info.isExplicitSelection()) {
return translationSystem.translate("${engine:menu#module-status-activated}");
} else if (info.isSelected()) {
return translationSystem.translate("${engine:menu#module-status-dependency}");
} else if (!info.isPresent()) {
return translationSystem.translate("${engine:menu#module-status-notpresent}");
} else if (info.isValidToSelect()) {
return translationSystem.translate("${engine:menu#module-status-available}");
} else {
return translationSystem.translate("${engine:menu#module-status-error}");
}
}
return "";
}
});
}
UIButton toggleActivate = find("toggleActivation", UIButton.class);
if (toggleActivate != null) {
toggleActivate.subscribe(button -> {
ModuleSelectionInfo info = moduleList.getSelection();
if (info != null) {
// Toggle
if (info.isSelected() && info.isExplicitSelection()) {
deselect(info);
} else if (info.isValidToSelect()) {
select(info);
}
}
});
toggleActivate.bindEnabled(new ReadOnlyBinding<Boolean>() {
@Override
public Boolean get() {
ModuleSelectionInfo info = moduleList.getSelection();
return info != null && info.isPresent() && !isSelectedGameplayModule(info) && (info.isSelected() || info.isValidToSelect());
}
});
toggleActivate.bindText(new ReadOnlyBinding<String>() {
@Override
public String get() {
if (moduleList.getSelection() != null) {
if (moduleList.getSelection().isExplicitSelection()) {
return translationSystem.translate("${engine:menu#deactivate-module}");
} else {
return translationSystem.translate("${engine:menu#activate-module}");
}
}
// button should be disabled
return translationSystem.translate("${engine:menu#activate-module}");
}
});
}
UIButton downloadButton = find("download", UIButton.class);
if (downloadButton != null) {
downloadButton.subscribe(button -> {
if (moduleList.getSelection() != null) {
ModuleSelectionInfo info = moduleList.getSelection();
startDownloadingNewestModulesRequiredFor(info);
}
});
downloadButton.bindEnabled(new ReadOnlyBinding<Boolean>() {
@Override
public Boolean get() {
ModuleSelectionInfo selection = moduleList.getSelection();
if (null == selection) {
return false;
}
return selection.getOnlineVersion() != null;
}
});
downloadButton.bindText(new ReadOnlyBinding<String>() {
@Override
public String get() {
ModuleSelectionInfo info = moduleList.getSelection();
if (info != null && !info.isPresent()) {
return translationSystem.translate("${engine:menu#download-module}");
} else {
return translationSystem.translate("${engine:menu#update-module}");
}
}
});
}
UIButton disableAll = find("disableAll", UIButton.class);
if (disableAll != null) {
disableAll.subscribe(button -> sortedModules.stream().filter(info -> info.isSelected() && info.isExplicitSelection()).forEach(this::deselect));
}
for (CheckboxAssociationEnum checkboxAssociation : CheckboxAssociationEnum.values()) {
String checkboxName = checkboxAssociation.getCheckboxName();
StandardModuleExtension standardModuleExtension = checkboxAssociation.getStandardModuleExtension();
UICheckbox checkBox = find(checkboxName, UICheckbox.class);
if (null != checkBox) {
checkBox.setChecked(selectModulesConfig.isStandardModuleExtensionSelected(standardModuleExtension));
checkBox.subscribe(e -> {
selectModulesConfig.toggleStandardModuleExtensionSelected(standardModuleExtension);
checkBox.setChecked(selectModulesConfig.isStandardModuleExtensionSelected(standardModuleExtension));
filterModules();
});
} else {
logger.error("Unable to find checkbox named " + checkboxName + " in " + ASSET_URI.toString());
selectModulesConfig.unselectStandardModuleExtension(standardModuleExtension);
}
}
UICheckbox localOnlyCheckbox = find("localOnlyCheckbox", UICheckbox.class);
localOnlyCheckbox.setChecked(selectModulesConfig.isLocalOnlySelected());
localOnlyCheckbox.subscribe(e -> {
selectModulesConfig.toggleIsLocalOnlySelected();
localOnlyCheckbox.setChecked(selectModulesConfig.isLocalOnlySelected());
filterModules();
});
UICheckbox uncategorizedCheckbox = find("uncategorizedCheckbox", UICheckbox.class);
uncategorizedCheckbox.setChecked(selectModulesConfig.isUncategorizedSelected());
uncategorizedCheckbox.subscribe(e -> {
selectModulesConfig.toggleUncategorizedSelected();
boolean isUncategorizedSelected = selectModulesConfig.isUncategorizedSelected();
uncategorizedCheckbox.setChecked(isUncategorizedSelected);
for (CheckboxAssociationEnum checkboxAssociation : CheckboxAssociationEnum.values()) {
final String checkboxName = checkboxAssociation.getCheckboxName();
UICheckbox checkbox = find(checkboxName, UICheckbox.class);
if (null != checkbox) {
checkbox.setEnabled(!isUncategorizedSelected);
}
}
filterModules();
});
UIButton resetAdvancedFilters = find("resetFilters", UIButton.class);
if (resetAdvancedFilters != null) {
// on clicking 'reset category filters' button, uncheck all advanced filters
localOnlyCheckbox.setChecked(selectModulesConfig.isLocalOnlySelected());
uncategorizedCheckbox.setChecked(selectModulesConfig.isUncategorizedSelected());
resetAdvancedFilters.subscribe(button -> {
if (selectModulesConfig.isLocalOnlySelected()) {
selectModulesConfig.toggleIsLocalOnlySelected();
localOnlyCheckbox.setChecked(selectModulesConfig.isLocalOnlySelected());
}
if (selectModulesConfig.isUncategorizedSelected()) {
selectModulesConfig.toggleUncategorizedSelected();
uncategorizedCheckbox.setChecked(selectModulesConfig.isUncategorizedSelected());
}
filterModules();
});
for (CheckboxAssociationEnum checkboxAssociation : CheckboxAssociationEnum.values()) {
StandardModuleExtension standardModuleExtension = checkboxAssociation.getStandardModuleExtension();
String checkboxName = checkboxAssociation.getCheckboxName();
UICheckbox checkbox = find(checkboxName, UICheckbox.class);
if (null != checkbox) {
checkbox.setChecked(selectModulesConfig.isStandardModuleExtensionSelected(standardModuleExtension));
resetAdvancedFilters.subscribe(button -> {
checkbox.setEnabled(!selectModulesConfig.isUncategorizedSelected());
if (selectModulesConfig.isStandardModuleExtensionSelected(standardModuleExtension)) {
selectModulesConfig.toggleStandardModuleExtensionSelected(standardModuleExtension);
checkbox.setChecked(selectModulesConfig.isStandardModuleExtensionSelected(standardModuleExtension));
}
filterModules();
});
}
}
final UIButton moduleDetails = find("moduleDetails", UIButton.class);
if (moduleDetails != null) {
moduleDetails.bindEnabled(new ReadOnlyBinding<Boolean>() {
@Override
public Boolean get() {
return moduleInfoBinding.get() != null;
}
});
moduleDetails.subscribe(b -> {
final ModuleDetailsScreen moduleDetailsScreen = getManager().createScreen(ModuleDetailsScreen.ASSET_URI, ModuleDetailsScreen.class);
final Collection<Module> modules = sortedModules.stream().map(ModuleSelectionInfo::getMetadata).filter(Objects::nonNull).map(meta -> moduleManager.getRegistry().getLatestModuleVersion(meta.getId())).filter(Objects::nonNull).collect(Collectors.toList());
moduleDetailsScreen.setModules(modules);
moduleDetailsScreen.setSelectedModule(modules.stream().filter(module -> module.getId().equals(moduleInfoBinding.get().getId())).findFirst().orElse(null));
getManager().pushScreen(moduleDetailsScreen);
});
}
}
}
WidgetUtil.trySubscribe(this, "createWorld", button -> {
final UniverseSetupScreen universeSetupScreen = getManager().createScreen(UniverseSetupScreen.ASSET_URI, UniverseSetupScreen.class);
universeWrapper.setSeed(seed.getText());
saveConfiguration();
universeSetupScreen.setEnvironment(universeWrapper);
triggerForwardAnimation(universeSetupScreen);
});
WidgetUtil.trySubscribe(this, "play", button -> {
if (StringUtils.isBlank(seed.getText())) {
getManager().createScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Error", "Game seed cannot be empty!");
} else {
universeWrapper.setSeed(seed.getText());
saveConfiguration();
final GameManifest gameManifest = GameManifestProvider.createGameManifest(universeWrapper, moduleManager, config);
if (gameManifest != null) {
gameEngine.changeState(new StateLoading(gameManifest, (universeWrapper.getLoadingAsServer()) ? NetworkMode.DEDICATED_SERVER : NetworkMode.NONE));
} else {
getManager().createScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Error", "Can't create new game!");
}
}
});
WidgetUtil.trySubscribe(this, "return", button -> triggerBackAnimation());
WidgetUtil.trySubscribe(this, "mainMenu", button -> {
getManager().pushScreen("engine:mainMenuScreen");
});
}
Aggregations