new selection ui

bottom-bar
Ivory 2023-01-18 17:31:27 -05:00
parent f19cfccf1a
commit 7c0a3be105
2 changed files with 53 additions and 26 deletions

View File

@ -2,14 +2,16 @@ package xyz.valnet.hadean.gameobjects;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import xyz.valnet.engine.graphics.ImmediateUI; import xyz.valnet.engine.graphics.ImmediateUI;
import xyz.valnet.engine.math.Vector4f;
import xyz.valnet.engine.scenegraph.ITransient; import xyz.valnet.engine.scenegraph.ITransient;
import xyz.valnet.hadean.gameobjects.inputlayer.SelectionLayer; import xyz.valnet.hadean.gameobjects.inputlayer.SelectionLayer;
import xyz.valnet.hadean.interfaces.ISelectable; import xyz.valnet.hadean.interfaces.ISelectable;
import xyz.valnet.hadean.interfaces.ISelectionChangeListener; import xyz.valnet.hadean.interfaces.ISelectionChangeListener;
import xyz.valnet.hadean.util.Action;
import xyz.valnet.hadean.util.Layers; import xyz.valnet.hadean.util.Layers;
import xyz.valnet.hadean.util.detail.Detail; import xyz.valnet.hadean.util.detail.Detail;
@ -22,6 +24,7 @@ public class SelectionUI extends ImmediateUI implements ISelectionChangeListener
private String genericName; private String genericName;
private List<ISelectable> selected = new ArrayList<ISelectable>(); private List<ISelectable> selected = new ArrayList<ISelectable>();
private transient SelectedByType selectedByType = new SelectedByType(); private transient SelectedByType selectedByType = new SelectedByType();
private transient Set<Action> actions = new HashSet<Action>();
private SelectionLayer selectionManager; private SelectionLayer selectionManager;
@ -56,12 +59,17 @@ public class SelectionUI extends ImmediateUI implements ISelectionChangeListener
selected = newSelection; selected = newSelection;
selectedByType.clear(); selectedByType.clear();
selectedCount = newSelection.size(); selectedCount = newSelection.size();
actions.clear();
for(ISelectable selectable : newSelection) { for(ISelectable selectable : newSelection) {
Class<? extends ISelectable> clazz = selectable.getClass(); Class<? extends ISelectable> clazz = selectable.getClass();
properName = selectable.getName(); properName = selectable.getName();
genericName = selectable.getGenericName(); genericName = selectable.getGenericName();
for(Action action : selectable.getActions()) {
actions.add(action);
}
if(!selectedByType.containsKey(clazz)) { if(!selectedByType.containsKey(clazz)) {
selectedByType.put(clazz, new ArrayList<ISelectable>()); selectedByType.put(clazz, new ArrayList<ISelectable>());
@ -80,34 +88,53 @@ public class SelectionUI extends ImmediateUI implements ISelectionChangeListener
protected void gui() { protected void gui() {
if(selected.isEmpty()) return; if(selected.isEmpty()) return;
if(selectedByType.size() == 1) { window(padding, 576 - padding - height - BottomBar.bottomBarHeight, width, height, () -> {
if(selectedCount == 1) { if(selectedByType.size() == 1) {
text(properName + "\n "); if(selectedCount == 1) {
group(); text(properName);
Detail[] details = selected.get(0).getDetails(); space(8);
if(details.length == 0) { group(() -> {
text("No details available."); Detail[] details = selected.get(0).getDetails();
} else for(Detail detail : details) { if(details.length == 0) {
text(detail.toString(15)); text("No details available.");
} else for(Detail detail : details) {
text(detail.toString(15));
}
});
} else {
text("" + selectedCount + "x " + genericName);
} }
groupEnd();
} else { } else {
text("" + selectedCount + "x " + genericName); text(this.selected.size() + " items selected");
}
} else { for(var entry : selectedByType.entrySet()) {
text(this.selected.size() + " items selected"); space(8);
text(""); List<ISelectable> list = entry.getValue();
int count = list.size();
for(var entry : selectedByType.entrySet()) { if(count <= 0) continue;
List<ISelectable> list = entry.getValue(); String name = list.get(0).getGenericName();
int count = list.size();
if(count <= 0) continue; if(button(name, count + "x " + name)) {
String name = list.get(0).getGenericName(); newSelection = list;
}
if(button(name, count + "x " + name)) {
newSelection = list;
} }
} }
});
if(selectedByType.size() == 1) {
root(padding * 2 + width, 576 - 32 - padding - BottomBar.bottomBarHeight, 1000, 32, () -> {
horizontal(() -> {
for(Action action : actions) {
if(button(action.name)) {
for(ISelectable selectable : selected) {
selectable.runAction(action);
}
}
space(8);
}
});
});
} }
} }
} }

View File

@ -45,7 +45,7 @@ public class GameScene extends SceneGraph {
} }
objects.add(new SelectionLayer()); objects.add(new SelectionLayer());
// objects.add(new SelectionUI()); objects.add(new SelectionUI());
objects.add(new BuildLayer()); objects.add(new BuildLayer());