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,25 +88,27 @@ public class SelectionUI extends ImmediateUI implements ISelectionChangeListener
protected void gui() { protected void gui() {
if(selected.isEmpty()) return; if(selected.isEmpty()) return;
window(padding, 576 - padding - height - BottomBar.bottomBarHeight, width, height, () -> {
if(selectedByType.size() == 1) { if(selectedByType.size() == 1) {
if(selectedCount == 1) { if(selectedCount == 1) {
text(properName + "\n "); text(properName);
group(); space(8);
group(() -> {
Detail[] details = selected.get(0).getDetails(); Detail[] details = selected.get(0).getDetails();
if(details.length == 0) { if(details.length == 0) {
text("No details available."); text("No details available.");
} else for(Detail detail : details) { } else for(Detail detail : details) {
text(detail.toString(15)); text(detail.toString(15));
} }
groupEnd(); });
} else { } else {
text("" + selectedCount + "x " + genericName); text("" + selectedCount + "x " + genericName);
} }
} else { } else {
text(this.selected.size() + " items selected"); text(this.selected.size() + " items selected");
text("");
for(var entry : selectedByType.entrySet()) { for(var entry : selectedByType.entrySet()) {
space(8);
List<ISelectable> list = entry.getValue(); List<ISelectable> list = entry.getValue();
int count = list.size(); int count = list.size();
if(count <= 0) continue; if(count <= 0) continue;
@ -109,5 +119,22 @@ public class SelectionUI extends ImmediateUI implements ISelectionChangeListener
} }
} }
} }
});
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());