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;
} 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) {
@ -700,29 +700,19 @@ public class SongMenu extends BasicGameState {
updateDrawnSongPosition();
// mouse hover
boolean isHover = false;
if (mouseY > headerY && mouseY < footerY) {
BeatmapSetNode node = startNode;
for (int i = 0; i < MAX_SONG_BUTTONS + 1 && node != null; i++, node = node.next) {
float cx = (node.index == BeatmapSetList.get().getExpandedIndex()) ? buttonX * 0.9f : buttonX;
if ((mouseX > cx && mouseX < cx + buttonWidth) &&
(mouseY > buttonY + (i * buttonOffset) && mouseY < buttonY + (i * buttonOffset) + buttonHeight)) {
if (node == hoverIndex) {
BeatmapSetNode node = getNodeAtPosition(mouseX, mouseY);
if (node != null) {
if (node == hoverIndex)
hoverOffset.update(delta);
} else {
else {
hoverIndex = node;
hoverOffset.setTime(0);
}
isHover = true;
break;
}
}
}
if (!isHover) {
return;
} else { // not hovered
hoverOffset.setTime(0);
hoverIndex = null;
} else
return;
}
// tooltips
if (focusScores != null && ScoreData.areaContains(mouseX, mouseY)) {
@ -815,14 +805,9 @@ public class SongMenu extends BasicGameState {
}
// song buttons
if (y > headerY && y < footerY) {
BeatmapSetNode node = getNodeAtPosition(x, y);
if (node != null) {
int expandedIndex = BeatmapSetList.get().getExpandedIndex();
BeatmapSetNode node = startNode;
for (int i = startNodeOffset; i < MAX_SONG_BUTTONS + 1 && node != null; i++, node = node.next) {
// 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;
@ -857,8 +842,6 @@ public class SongMenu extends BasicGameState {
return;
}
}
}
// score buttons
if (focusScores != null && ScoreData.areaContains(x, y)) {
@ -1385,7 +1368,6 @@ public class SongMenu extends BasicGameState {
updateDrawnSongPosition();
// make sure focusNode is on the screen
int val = focusNode.index + focusNode.beatmapIndex;
if (val * buttonOffset <= songScrolling.getPosition())
@ -1554,6 +1536,27 @@ public class SongMenu extends BasicGameState {
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.
* @param beatmapSet the set of beatmaps