3434 * The menu remains open for as long as the digital action remains held. When the action is released where the hand is
3535 * controls what is selected (if anything)
3636 */
37+ @ SuppressWarnings ("unused" )
3738public class HandRingMenuFunction <T > implements BoundHandFunction {
3839
3940 private final List <MenuItem <T >> topLevelMenuItems ;
4041 private List <MenuBranch <T >> currentOpenPath = List .of ();
4142
4243 private final Consumer <Optional <T >> selectionConsumer ;
4344
44- ActionHandle digitalActionToOpenMenu ;
45-
4645 private BoundHand boundHand ;
4746 private XrActionBaseAppState actionBasedOpenVrState ;
4847 private XrBaseAppState vrAppState ;
@@ -93,6 +92,8 @@ public class HandRingMenuFunction<T> implements BoundHandFunction{
9392 */
9493 Map <Node , Supplier <Spatial >> dynamicGeometrySuppliers = new HashMap <>();
9594
95+ private final Supplier <Boolean > shouldBeOpenSupplier ;
96+
9697 /**
9798 * @param menuItems the tree of menu items
9899 * @param selectionConsumer when an item is selected it is given to this consumer
@@ -101,9 +102,14 @@ public class HandRingMenuFunction<T> implements BoundHandFunction{
101102 public HandRingMenuFunction (List <MenuItem <T >> menuItems , Consumer <Optional <T >> selectionConsumer , ActionHandle digitalActionToOpenMenu ){
102103 this .topLevelMenuItems = menuItems ;
103104 this .selectionConsumer = selectionConsumer ;
104- this .digitalActionToOpenMenu = digitalActionToOpenMenu ;
105- }
105+ this .shouldBeOpenSupplier = () -> this .actionBasedOpenVrState .getBooleanActionState (digitalActionToOpenMenu , boundHand .getHandSide ().restrictToInputString ).getState ();
106106
107+ }
108+ public HandRingMenuFunction (List <MenuItem <T >> menuItems , Consumer <Optional <T >> selectionConsumer , Supplier <Boolean > shouldBeOpenSupplier ){
109+ this .topLevelMenuItems = menuItems ;
110+ this .selectionConsumer = selectionConsumer ;
111+ this .shouldBeOpenSupplier = shouldBeOpenSupplier ;
112+ }
107113
108114 @ Override
109115 public void onBind (BoundHand boundHand , AppStateManager stateManager ){
@@ -124,12 +130,12 @@ public void onUnbind(BoundHand boundHand, AppStateManager stateManager){
124130
125131 @ Override
126132 public void update (float timeSlice , BoundHand boundHand , AppStateManager stateManager ){
127- BooleanActionState menuButtonPressed = actionBasedOpenVrState . getBooleanActionState ( digitalActionToOpenMenu , boundHand . getHandSide (). restrictToInputString );
128- if (menuButtonPressed . getState () && !this .menuOpen ){
133+ boolean menuButtonPressed = shouldBeOpenSupplier . get ( );
134+ if (menuButtonPressed && !this .menuOpen ){
129135 openMenu ();
130136 }
131137
132- if (!menuButtonPressed . getState () && this .menuOpen ){
138+ if (!menuButtonPressed && this .menuOpen ){
133139 closeMenuAndSelect ();
134140 }
135141
0 commit comments