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