From 4cd4e29bca895e7316f3bc643bd687bdf3afbebb Mon Sep 17 00:00:00 2001 From: Ivory Date: Tue, 3 Jan 2023 00:51:03 -0500 Subject: [PATCH] better selections --- .../hadean/gameobjects/SelectionUI.java | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/src/main/java/xyz/valnet/hadean/gameobjects/SelectionUI.java b/src/main/java/xyz/valnet/hadean/gameobjects/SelectionUI.java index 29e6034..3028626 100644 --- a/src/main/java/xyz/valnet/hadean/gameobjects/SelectionUI.java +++ b/src/main/java/xyz/valnet/hadean/gameobjects/SelectionUI.java @@ -2,7 +2,9 @@ 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.math.Vector4f; import xyz.valnet.engine.scenegraph.GameObject; @@ -129,21 +131,37 @@ public class SelectionUI extends GameObject implements ISelectionChangeListener, } } if(selectedTypes.size() == 1) { - // TODO this should only pull common actions to all elements, but rn just pulls the first things actions - Action[] actions = selected.get(0).getActions(); - Button[] actionButtons = new Button[actions.length]; - for(int i = 0; i < actions.length; i ++) { - actionButtons[i] = new SimpleButton(actions[i].name, width + padding * 2 + i * (actionButtonSize + padding), 576 - padding - actionButtonSize - BottomBar.bottomBarHeight, actionButtonSize, actionButtonSize, Layers.GENERAL_UI_INTERACTABLE); - actionButtons[i].registerClickListener(this); - buttonActionMap.put(actionButtons[i], actions[i]); - } - setActionButtons(actionButtons); + createActionButtons(); } if(selectedTypes.size() <= 1) { clearNarrowButtons(); } } + private void createActionButtons() { + + buttonActionMap.clear(); + setActionButtons(ACTIONS_BUTTONS_NULL); + + Set actionSet = new HashSet(); + for(ISelectable selectable : selected) { + for(Action action : selectable.getActions()) { + actionSet.add(action); + } + } + + Action[] actions = new Action[actionSet.size()]; + actionSet.toArray(actions); + + Button[] actionButtons = new Button[actions.length]; + for(int i = 0; i < actions.length; i ++) { + actionButtons[i] = new SimpleButton(actions[i].name, width + padding * 2 + i * (actionButtonSize + padding), 576 - padding - actionButtonSize - BottomBar.bottomBarHeight, actionButtonSize, actionButtonSize, Layers.GENERAL_UI_INTERACTABLE); + actionButtons[i].registerClickListener(this); + buttonActionMap.put(actionButtons[i], actions[i]); + } + setActionButtons(actionButtons); + } + private void setActionButtons(Button[] buttons) { for(Button btn : this.actionButtons) { remove(btn); @@ -163,6 +181,7 @@ public class SelectionUI extends GameObject implements ISelectionChangeListener, for(ISelectable selectable : selected) { selectable.runAction(action); } + createActionButtons(); } }