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) {
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) {
hoverOffset.update(delta); hoverOffset.update(delta);
} else { else {
hoverIndex = node; hoverIndex = node;
hoverOffset.setTime(0); hoverOffset.setTime(0);
} }
isHover = true; return;
break; } else { // not hovered
}
}
}
if (!isHover) {
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,14 +805,9 @@ 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;
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(); int oldHoverOffsetTime = hoverOffset.getTime();
BeatmapSetNode oldHoverIndex = hoverIndex; BeatmapSetNode oldHoverIndex = hoverIndex;
@ -857,8 +842,6 @@ public class SongMenu extends BasicGameState {
return; return;
} }
}
}
// score buttons // score buttons
if (focusScores != null && ScoreData.areaContains(x, y)) { if (focusScores != null && ScoreData.areaContains(x, y)) {
@ -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