Skip to content

Commit

Permalink
Right-click/drag in the song menu now scrolls to the mouse position.
Browse files Browse the repository at this point in the history
Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
  • Loading branch information
itdelatrisu committed Jan 8, 2017
1 parent f111730 commit 41a27fe
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 13 deletions.
43 changes: 30 additions & 13 deletions src/itdelatrisu/opsu/states/SongMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,12 @@ public void mousePressed(int button, int x, int y) {
if (isScrollingToFocusNode)
return;

songScrolling.pressed();
if (input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON)) {
// scroll to the mouse position on the screen
songScrolling.setSpeedMultiplier(2f);
scrollSongsToPosition(y);
} else
songScrolling.pressed();
startScorePos.pressed();
}

Expand All @@ -951,6 +956,8 @@ public void mouseReleased(int button, int x, int y) {
if (isScrollingToFocusNode)
return;

if (songScrolling.isPressed())
songScrolling.setSpeedMultiplier(1f);
songScrolling.released();
startScorePos.released();
}
Expand Down Expand Up @@ -1254,26 +1261,25 @@ public void mouseDragged(int oldx, int oldy, int newx, int newy) {
if (isInputBlocked())
return;

int diff = newy - oldy;
if (diff == 0)
// check mouse button
if (input.isMouseButtonDown(Input.MOUSE_MIDDLE_BUTTON))
return;

// check mouse button (right click scrolls faster on songs)
int multiplier;
if (input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON))
multiplier = 10;
else if (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON))
multiplier = 1;
else
int diff = newy - oldy;
if (diff == 0)
return;

// score buttons
if (focusScores != null && focusScores.length >= MAX_SCORE_BUTTONS && ScoreData.areaContains(oldx, oldy))
startScorePos.dragged(-diff * multiplier);
startScorePos.dragged(-diff);

// song buttons
else
songScrolling.dragged(-diff * multiplier);
else {
if (songScrolling.isPressed())
songScrolling.dragged(-diff);
else
scrollSongsToPosition(newy);
}
}

@Override
Expand Down Expand Up @@ -1801,6 +1807,17 @@ private BeatmapSetNode getNodeAtPosition(int x, int y) {
return null;
}

/**
* Scrolls the song list to the given y position.
* @param y the y coordinate (will be clamped)
*/
private void scrollSongsToPosition(int y) {
float scrollBase = headerY + DIVIDER_LINE_WIDTH / 2;
float scrollHeight = MAX_SONG_BUTTONS * buttonOffset;
float t = Utils.clamp((y - scrollBase) / scrollHeight, 0f, 1f);
songScrolling.scrollToPosition(songScrolling.getMin() + t * (songScrolling.getMax() - songScrolling.getMin()));
}

/**
* Calculates all star ratings for a beatmap set.
* @param beatmapSet the set of beatmaps
Expand Down
18 changes: 18 additions & 0 deletions src/itdelatrisu/opsu/ui/KineticScrolling.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@ public class KineticScrolling {
*/
public float getTargetPosition() { return target; }

/**
* Returns the minimum value.
* @return the min
*/
public float getMin() { return min; }

/**
* Returns the minimum value.
* @return the max
*/
public float getMax() { return max; }

/**
* Returns if the mouse state is currently pressed.
* @return true if pressed
*/
public boolean isPressed() { return pressed; }

/**
* Updates the scrolling.
* @param delta the elapsed time since the last update
Expand Down

0 comments on commit 41a27fe

Please # to comment.