Slight changes to DropdownMenu behavior.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-09-09 13:25:48 -04:00
parent 643a7c4589
commit 7f1193bb77
2 changed files with 22 additions and 24 deletions

View File

@ -524,8 +524,12 @@ public class DownloadsMenu extends BasicGameState {
}
// dropdown menu
if (serverMenu.click(x, y)) {
int oldServerIndex = serverMenu.getSelectedIndex(), serverMenuClickResult = serverMenu.click(x, y);
if (serverMenuClickResult > -2) {
SoundController.playSound(SoundEffect.MENUCLICK);
if (serverMenuClickResult == -1 || serverMenuClickResult == oldServerIndex)
return;
resultList = null;
startResult = 0;
focusResult = -1;
@ -541,8 +545,6 @@ public class DownloadsMenu extends BasicGameState {
resetSearchTimer();
return;
}
if (serverMenu.contains(x, y))
return;
// search results
DownloadNode[] nodes = resultList;

View File

@ -173,6 +173,12 @@ public class DropdownMenu<E> {
*/
public boolean isOpen() { return expanded; }
/**
* Opens or closes the dropdown menu.
* @param flag true to open, false to close
*/
public void open(boolean flag) { this.expanded = flag; }
/**
* Returns true if the coordinates are within the menu bounds.
* @param cx the x coordinate
@ -180,8 +186,8 @@ public class DropdownMenu<E> {
*/
public boolean contains(float cx, float cy) {
return (cx > x && cx < x + width && (
(cy > y && cy < y + baseHeight) ||
(expanded && cy > y + offsetY && cy < y + height)));
(cy > y && cy < y + baseHeight) ||
(expanded && cy > y + offsetY && cy < y + height)));
}
/**
@ -280,35 +286,25 @@ public class DropdownMenu<E> {
* Registers a click at the given location.
* If the base item is clicked and the menu is unexpanded, it will be expanded;
* in all other cases, the menu will be unexpanded. If an item different from
* the current one is selected, this will select that item and return {@code true}.
* Otherwise, this will return {@code false}.
* the current one is selected, that item will be selected.
* @param cx the x coordinate
* @param cy the y coordinate
* @return the index of the item at the given location, -1 for the base item,
* and -2 if there is no item at the location
*/
public boolean click(float cx, float cy) {
public int click(float cx, float cy) {
int idx = getIndexAt(cx, cy);
if (idx == -2) {
this.expanded = false;
return false;
} else if (idx == -1) {
this.expanded = !expanded;
return false;
} else {
this.expanded = false;
if (itemIndex == idx)
return false;
else {
itemIndex = idx;
return true;
}
}
this.expanded = (idx == -1) ? !expanded : false;
if (idx >= 0)
this.itemIndex = idx;
return idx;
}
/**
* Resets the menu state.
*/
public void reset() {
expanded = false;
this.expanded = false;
expandProgress.setTime(0);
}