Fix hovering bug with < max nodes in kinetic scrolling.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-09-19 13:04:53 -04:00
parent 84ce2d1531
commit 5634a673bb

View File

@ -672,7 +672,7 @@ public class SongMenu extends BasicGameState {
} }
oldFocusNode = null; oldFocusNode = null;
} else if (!search.getText().isEmpty()) } else if (!search.getText().isEmpty())
searchResultString = "No matches found. Hit 'esc' to reset."; searchResultString = "No matches found. Hit ESC to reset.";
} }
} }
if (searchTransitionTimer < SEARCH_TRANSITION_TIME) { if (searchTransitionTimer < SEARCH_TRANSITION_TIME) {
@ -700,29 +700,19 @@ public class SongMenu extends BasicGameState {
updateDrawnSongPosition(); updateDrawnSongPosition();
// mouse hover // mouse hover
boolean isHover = false; BeatmapSetNode node = getNodeAtPosition(mouseX, mouseY);
if (mouseY > headerY && mouseY < footerY) { if (node != null) {
BeatmapSetNode node = startNode; if (node == hoverIndex)
for (int i = 0; i < MAX_SONG_BUTTONS + 1 && node != null; i++, node = node.next) { hoverOffset.update(delta);
float cx = (node.index == BeatmapSetList.get().getExpandedIndex()) ? buttonX * 0.9f : buttonX; else {
if ((mouseX > cx && mouseX < cx + buttonWidth) && hoverIndex = node;
(mouseY > buttonY + (i * buttonOffset) && mouseY < buttonY + (i * buttonOffset) + buttonHeight)) { hoverOffset.setTime(0);
if (node == hoverIndex) {
hoverOffset.update(delta);
} else {
hoverIndex = node;
hoverOffset.setTime(0);
}
isHover = true;
break;
}
} }
} return;
if (!isHover) { } else { // not hovered
hoverOffset.setTime(0); hoverOffset.setTime(0);
hoverIndex = null; hoverIndex = null;
} else }
return;
// tooltips // tooltips
if (focusScores != null && ScoreData.areaContains(mouseX, mouseY)) { if (focusScores != null && ScoreData.areaContains(mouseX, mouseY)) {
@ -815,49 +805,42 @@ public class SongMenu extends BasicGameState {
} }
// song buttons // song buttons
if (y > headerY && y < footerY) { BeatmapSetNode node = getNodeAtPosition(x, y);
if (node != null) {
int expandedIndex = BeatmapSetList.get().getExpandedIndex(); int expandedIndex = BeatmapSetList.get().getExpandedIndex();
BeatmapSetNode node = startNode; int oldHoverOffsetTime = hoverOffset.getTime();
for (int i = startNodeOffset; i < MAX_SONG_BUTTONS + 1 && node != null; i++, node = node.next) { BeatmapSetNode oldHoverIndex = hoverIndex;
// is button at this index clicked?
float cx = (node.index == expandedIndex) ? buttonX * 0.9f : buttonX;
if ((x > cx && x < cx + buttonWidth) &&
(y > buttonY + (i * buttonOffset) && y < buttonY + (i * buttonOffset) + buttonHeight)) {
int oldHoverOffsetTime = hoverOffset.getTime();
BeatmapSetNode oldHoverIndex = hoverIndex;
// clicked node is already expanded // clicked node is already expanded
if (node.index == expandedIndex) { if (node.index == expandedIndex) {
if (node.beatmapIndex == focusNode.beatmapIndex) { if (node.beatmapIndex == focusNode.beatmapIndex) {
// if already focused, load the beatmap // if already focused, load the beatmap
if (button != Input.MOUSE_RIGHT_BUTTON) if (button != Input.MOUSE_RIGHT_BUTTON)
startGame(); startGame();
else else
SoundController.playSound(SoundEffect.MENUCLICK);
} else {
// focus the node
SoundController.playSound(SoundEffect.MENUCLICK);
setFocus(node, 0, false, true);
}
}
// clicked node is a new group
else {
SoundController.playSound(SoundEffect.MENUCLICK); SoundController.playSound(SoundEffect.MENUCLICK);
setFocus(node, -1, false, true); } else {
} // focus the node
SoundController.playSound(SoundEffect.MENUCLICK);
// restore hover data setFocus(node, 0, false, true);
hoverOffset.setTime(oldHoverOffsetTime);
hoverIndex = oldHoverIndex;
// open beatmap menu
if (button == Input.MOUSE_RIGHT_BUTTON)
beatmapMenuTimer = (node.index == expandedIndex) ? BEATMAP_MENU_DELAY * 4 / 5 : 0;
return;
} }
} }
// clicked node is a new group
else {
SoundController.playSound(SoundEffect.MENUCLICK);
setFocus(node, -1, false, true);
}
// restore hover data
hoverOffset.setTime(oldHoverOffsetTime);
hoverIndex = oldHoverIndex;
// open beatmap menu
if (button == Input.MOUSE_RIGHT_BUTTON)
beatmapMenuTimer = (node.index == expandedIndex) ? BEATMAP_MENU_DELAY * 4 / 5 : 0;
return;
} }
// score buttons // score buttons
@ -1385,12 +1368,11 @@ public class SongMenu extends BasicGameState {
updateDrawnSongPosition(); updateDrawnSongPosition();
// make sure focusNode is on the screen // make sure focusNode is on the screen
int val = focusNode.index + focusNode.beatmapIndex; int val = focusNode.index + focusNode.beatmapIndex;
if (val * buttonOffset <= songScrolling.getPosition()) if (val * buttonOffset <= songScrolling.getPosition())
songScrolling.scrollToPosition(val * buttonOffset); songScrolling.scrollToPosition(val * buttonOffset);
else if (val* buttonOffset - (footerY - headerY - buttonOffset) >= songScrolling.getPosition()) else if (val * buttonOffset - (footerY - headerY - buttonOffset) >= songScrolling.getPosition())
songScrolling.scrollToPosition(val * buttonOffset - (footerY - headerY - buttonOffset)); songScrolling.scrollToPosition(val * buttonOffset - (footerY - headerY - buttonOffset));
/* /*
@ -1554,6 +1536,27 @@ public class SongMenu extends BasicGameState {
return (reloadThread != null || beatmapMenuTimer > -1 || isScrollingToFocusNode); return (reloadThread != null || beatmapMenuTimer > -1 || isScrollingToFocusNode);
} }
/**
* Returns the beatmap node at the given location.
* @param x the x coordinate
* @param y the y coordinate
* @return the node, or {@code null} if none
*/
private BeatmapSetNode getNodeAtPosition(int x, int y) {
if (y <= headerY || y >= footerY)
return null;
int expandedIndex = BeatmapSetList.get().getExpandedIndex();
BeatmapSetNode node = startNode;
for (int i = startNodeOffset; i < MAX_SONG_BUTTONS + 1 && node != null; i++, node = node.next) {
float cx = (node.index == expandedIndex) ? buttonX * 0.9f : buttonX;
if ((x > cx && x < cx + buttonWidth) &&
(y > buttonY + (i * buttonOffset) && y < buttonY + (i * buttonOffset) + buttonHeight))
return node;
}
return null;
}
/** /**
* Calculates all star ratings for a beatmap set. * Calculates all star ratings for a beatmap set.
* @param beatmapSet the set of beatmaps * @param beatmapSet the set of beatmaps