Skip to content

Commit

Permalink
BindScreen: when selecting a bound hotkey, also select its action
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Jan 4, 2018
1 parent 8cc0bcd commit a36ebf0
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions nifty/src/main/java/jme3utilities/nifty/bind/BindScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,28 @@ private void bindSelected() {
}

/**
* Find the list-box item for the specified universal code.
* Find the list-box item for the specified action.
*
* @param actionName the name of the action to find (not null)
* @return the pre-existing item, or null if none found
*/
private ActionItem findActionItem(String actionName) {
assert actionName != null;

ListBox<ActionItem> actionBox = getActionBox();
List<ActionItem> list = actionBox.getItems();
for (ActionItem item : list) {
String name = item.getActionName();
if (actionName.equals(name)) {
return item;
}
}

return null;
}

/**
* Find the hotkey list-box item for the specified universal code.
*
* @param code universal code (&ge;0)
* @return the pre-existing item, or null if none found
Expand Down Expand Up @@ -490,7 +511,8 @@ private void populateHotkeyBox(boolean boundFlag) {
}

/**
* Select the hotkey with the specified code.
* Select the hotkey with the specified code. If the hotkey is bound, also
* select the action it's bound to.
*
* @param code universal code of the hotkey to select (&ge;0)
*/
Expand All @@ -501,6 +523,14 @@ private void selectHotkey(int code) {
ListBox<HotkeyItem> listBox = getHotkeyBox();
listBox.setFocusItem(item);
listBox.selectItem(item);

Hotkey hotkey = item.getHotkey();
if (subjectMode.binds(hotkey)) {
String actionName = subjectMode.getActionName(hotkey);
ActionItem actionItem = findActionItem(actionName);
ListBox<ActionItem> actionBox = getActionBox();
actionBox.selectItem(actionItem);
}
}

/**
Expand Down

0 comments on commit a36ebf0

Please sign in to comment.