use of org.terasology.nui.widgets.UIDropdownScrollable in project Terasology by MovingBlocks.
the class ObjectLayoutBuilder method populateNullLayout.
private void populateNullLayout(Binding<T> binding, ColumnLayout layout, UILabel nameWidget) {
// TODO: Translate
if (MODIFY_LABEL.equals(nameWidget.getText())) {
nameWidget.setText(NULL_LABEL);
}
List<Constructor<T>> constructors = Arrays.stream(type.getRawType().getConstructors()).map(constructor -> (Constructor<T>) constructor).collect(Collectors.toList());
if (constructors.isEmpty()) {
// TODO: Translate
UIBox box = buildErrorWidget("No accessible constructors found");
layout.addWidget(box);
return;
}
ColumnLayout parameterLayout = createDefaultLayout();
UIButton createInstanceButton = new UIButton();
// TODO: Translate
createInstanceButton.setText("Create Instance");
UIDropdownScrollable<Constructor<T>> constructorSelection = new UIDropdownScrollable<>();
Binding<Constructor<T>> selectedConstructor = new NotifyingBinding<Constructor<T>>(constructors.get(0)) {
@Override
protected void onSet() {
populateConstructorParameters(binding, parameterLayout, createInstanceButton, this);
}
};
constructorSelection.setOptions(constructors);
constructorSelection.bindSelection(selectedConstructor);
constructorSelection.setOptionRenderer(new StringTextRenderer<Constructor<T>>() {
@Override
public String getString(Constructor<T> value) {
return ReflectionUtil.resolvedMethodToString(type.getType(), value, true);
}
});
// TODO: Translate
constructorSelection.setTooltip("Select the constructor to use to create the new object");
layout.addWidget(constructorSelection);
layout.addWidget(parameterLayout);
layout.addWidget(createInstanceButton);
}
use of org.terasology.nui.widgets.UIDropdownScrollable in project Terasology by MovingBlocks.
the class LocaleConstraintWidgetFactory method buildWidget.
@Override
protected Optional<UIWidget> buildWidget() {
Setting<Locale> setting = getSetting();
Binding<Locale> binding = new Binding<Locale>() {
@Override
public Locale get() {
return setting.get();
}
@Override
public void set(Locale value) {
setting.set(value);
}
};
UIDropdownScrollable<Locale> dropdownScrollable = new UIDropdownScrollable<>();
ResourceUrn menuUrn = new ResourceUrn("engine:menu");
TranslationProject menuProject = translationSystem.getProject(menuUrn);
List<Locale> locales = new ArrayList<>(menuProject.getAvailableLocales());
for (Locale languageExcluded : languagesExcluded) {
locales.remove(languageExcluded);
}
Collections.sort(locales, (Comparator.comparing((Function<Object, String>) Object::toString)));
dropdownScrollable.setOptions(Lists.newArrayList(locales));
// Set maximum number of options visible for scrolling
dropdownScrollable.setVisibleOptions(5);
dropdownScrollable.bindSelection(binding);
dropdownScrollable.setOptionRenderer(new LocaleRenderer(translationSystem));
return Optional.of(dropdownScrollable);
}
use of org.terasology.nui.widgets.UIDropdownScrollable in project Terasology by MovingBlocks.
the class WorldPreGenerationScreen method setEnvironment.
/**
* A function called before the screen comes to the forefront to setup the environment
* and extract necessary objects from the new Context.
*
* @param subContext The new environment created in {@link UniverseSetupScreen}
* @throws UnresolvedWorldGeneratorException The creation of a world generator can throw this Exception
*/
public void setEnvironment(Context subContext) throws UnresolvedWorldGeneratorException {
context = subContext;
environment = context.get(ModuleEnvironment.class);
context.put(WorldGeneratorPluginLibrary.class, new TempWorldGeneratorPluginLibrary(environment, context));
worldList = context.get(UniverseSetupScreen.class).getWorldsList();
selectedWorld = context.get(UniverseSetupScreen.class).getSelectedWorld();
worldNames = context.get(UniverseSetupScreen.class).worldNames();
setWorldGenerators();
worldGenerator = findWorldByName(selectedWorld).getWorldGenerator();
final UIDropdownScrollable worldsDropdown = find("worlds", UIDropdownScrollable.class);
worldsDropdown.setOptions(worldNames);
genTexture();
List<Zone> previewZones = Lists.newArrayList(worldGenerator.getZones()).stream().filter(z -> !z.getPreviewLayers().isEmpty()).collect(Collectors.toList());
if (previewZones.isEmpty()) {
previewGen = new FacetLayerPreview(environment, worldGenerator);
}
}
use of org.terasology.nui.widgets.UIDropdownScrollable in project Terasology by MovingBlocks.
the class WorldPreGenerationScreen method initialise.
@Override
public void initialise() {
setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
zoomSlider = find("zoomSlider", UISlider.class);
if (zoomSlider != null) {
zoomSlider.setValue(2f);
zoomSlider.setUiSliderOnChangeTriggeredListener(this);
}
final UIDropdownScrollable worldsDropdown = find("worlds", UIDropdownScrollable.class);
worldsDropdown.bindSelection(new Binding<String>() {
@Override
public String get() {
return selectedWorld;
}
@Override
public void set(String value) {
selectedWorld = value;
try {
if (findWorldByName(selectedWorld).getWorldGenerator() == null) {
worldGenerator = WorldGeneratorManager.createWorldGenerator(findWorldByName(selectedWorld).getWorldGeneratorInfo().getUri(), context, environment);
findWorldByName(selectedWorld).setWorldGenerator(worldGenerator);
} else {
worldGenerator = findWorldByName(selectedWorld).getWorldGenerator();
}
if (worldGenerator.getWorldSeed() == null) {
worldGenerator.setWorldSeed(createSeed(selectedWorld));
}
previewGen = new FacetLayerPreview(environment, worldGenerator);
updatePreview();
} catch (UnresolvedWorldGeneratorException e) {
e.printStackTrace();
}
}
});
WidgetUtil.trySubscribe(this, "reRoll", button -> {
worldGenerator.setWorldSeed(createSeed(selectedWorld));
updatePreview();
});
StartPlayingScreen startPlayingScreen = getManager().createScreen(StartPlayingScreen.ASSET_URI, StartPlayingScreen.class);
WidgetUtil.trySubscribe(this, "continue", button -> {
startPlayingScreen.setTargetWorld(worldList, findWorldByName(selectedWorld), texture, context);
triggerForwardAnimation(startPlayingScreen);
});
WorldSetupScreen worldSetupScreen = getManager().createScreen(WorldSetupScreen.ASSET_URI, WorldSetupScreen.class);
WidgetUtil.trySubscribe(this, "config", button -> {
try {
if (!selectedWorld.isEmpty()) {
worldSetupScreen.setWorld(context, findWorldByName(selectedWorld), worldsDropdown);
triggerForwardAnimation(worldSetupScreen);
} else {
getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Worlds List Empty!", "No world found to configure.");
}
} catch (UnresolvedWorldGeneratorException e) {
e.printStackTrace();
}
});
WidgetUtil.trySubscribe(this, "close", button -> {
final UniverseSetupScreen universeSetupScreen = getManager().createScreen(UniverseSetupScreen.ASSET_URI, UniverseSetupScreen.class);
UIDropdownScrollable worldsDropdownOfUniverse = universeSetupScreen.find("worlds", UIDropdownScrollable.class);
universeSetupScreen.refreshWorldDropdown(worldsDropdownOfUniverse);
triggerBackAnimation();
});
WidgetUtil.trySubscribe(this, "mainMenu", button -> {
getManager().pushScreen("engine:mainMenuScreen");
});
}
use of org.terasology.nui.widgets.UIDropdownScrollable 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();
}
Aggregations