Minor formatting cleanup for #131.

Also made some members private.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-09-15 23:20:53 -04:00
parent e1becb3962
commit e0da6a2444
5 changed files with 127 additions and 129 deletions

View File

@ -105,9 +105,7 @@ public class ScoreData implements Comparable<ScoreData> {
/**
* Returns the Buttons Offset
*/
public static float getButtonOffset() {
return buttonOffset;
}
public static float getButtonOffset() { return buttonOffset; }
/**
* Returns true if the coordinates are within the bounds of the
@ -136,7 +134,7 @@ public class ScoreData implements Comparable<ScoreData> {
/**
* Draws the scroll bar for the score buttons.
* @param g the graphics context
* @param index the start button index
* @param pos the start button index
* @param total the total number of buttons
*/
public static void drawScrollbar(Graphics g, float pos, float total) {
@ -238,7 +236,7 @@ public class ScoreData implements Comparable<ScoreData> {
/**
* Draws the score data as a rectangular button.
* @param g the graphics context
* @param index the index (to offset the button from the topmost button)
* @param position the index (to offset the button from the topmost button)
* @param rank the score rank
* @param prevScore the previous (lower) score, or -1 if none
* @param focus whether the button is focused

View File

@ -192,20 +192,17 @@ public class DownloadNode {
}
/**
* Returns the button(Results) offset.
* @return the button offset
* Returns the download results button offset.
* @return the offset
*/
public static float getButtonOffset(){
return buttonOffset;
}
public static float getButtonOffset() { return buttonOffset; }
/**
* Returns the info(Download) height.
* @return the infoHeight
* Returns the download info height.
* @return the height
*/
public static float getInfoHeight(){
return infoHeight;
}
public static float getInfoHeight() { return infoHeight; }
/**
* Returns true if the coordinates are within the bounds of the
* download information button area.

View File

@ -95,7 +95,7 @@ public class DownloadsMenu extends BasicGameState {
private int focusTimer = 0;
/** Current start result button (topmost entry). */
KineticScrolling startResultPos = new KineticScrolling();
private KineticScrolling startResultPos = new KineticScrolling();
/** Total number of results for current query. */
private int totalResults = 0;
@ -116,7 +116,7 @@ public class DownloadsMenu extends BasicGameState {
private boolean rankedOnly = true;
/** Current start download index. */
KineticScrolling startDownloadIndexPos = new KineticScrolling();
private KineticScrolling startDownloadIndexPos = new KineticScrolling();
/** Query thread. */
private Thread queryThread;
@ -455,7 +455,6 @@ public class DownloadsMenu extends BasicGameState {
}
g.clearClip();
// scroll bar
if (downloadsSize > maxDownloadsShown)
DownloadNode.drawDownloadScrollbar(g, startDownloadIndexPos.getPosition(), downloadsSize * DownloadNode.getInfoHeight());
@ -946,15 +945,13 @@ public class DownloadsMenu extends BasicGameState {
*/
private void scrollLists(int cx, int cy, int shift) {
// search results
if (DownloadNode.resultAreaContains(cx, cy)) {
if (DownloadNode.resultAreaContains(cx, cy))
startResultPos.scrollOffset(shift * DownloadNode.getButtonOffset());
}
// downloads
else if (DownloadNode.downloadAreaContains(cx, cy)) {
else if (DownloadNode.downloadAreaContains(cx, cy))
startDownloadIndexPos.scrollOffset(shift * DownloadNode.getInfoHeight());
}
}
/**
* Sends a bar notification upon entering the state.

View File

@ -44,9 +44,9 @@ import itdelatrisu.opsu.beatmap.OszUnpacker;
import itdelatrisu.opsu.db.BeatmapDB;
import itdelatrisu.opsu.db.ScoreDB;
import itdelatrisu.opsu.states.ButtonMenu.MenuState;
import itdelatrisu.opsu.ui.KineticScrolling;
import itdelatrisu.opsu.ui.Colors;
import itdelatrisu.opsu.ui.Fonts;
import itdelatrisu.opsu.ui.KineticScrolling;
import itdelatrisu.opsu.ui.MenuButton;
import itdelatrisu.opsu.ui.StarStream;
import itdelatrisu.opsu.ui.UI;
@ -138,7 +138,7 @@ public class SongMenu extends BasicGameState {
private BeatmapSetNode startNode;
/** The first node is about this high above the header. */
KineticScrolling songScrolling = new KineticScrolling();
private KineticScrolling songScrolling = new KineticScrolling();
/** The number of Nodes to offset from the top to the startNode. */
private int startNodeOffset;
@ -210,8 +210,7 @@ public class SongMenu extends BasicGameState {
private ScoreData[] focusScores;
/** Current start score (topmost score entry). */
KineticScrolling startScorePos = new KineticScrolling();
private KineticScrolling startScorePos = new KineticScrolling();
/** Header and footer end and start y coordinates, respectively. */
private float headerY, footerY;
@ -390,18 +389,17 @@ public class SongMenu extends BasicGameState {
// draw the node
float offset = (node == hoverIndex) ? hoverOffset.getValue() : 0f;
float ypos = buttonY + (i * buttonOffset);
float mid = height/2 - ypos - buttonOffset/2;
float mid = (height / 2) - ypos - (buttonOffset / 2);
final float circleRadi = 700 * GameImage.getUIscale();
//finds points along a very large circle (x^2 = h^2 - y^2)
float t = circleRadi * circleRadi - (mid * mid);
float xpos = (float)(t>0?Math.sqrt(t):0) - circleRadi + 50 * GameImage.getUIscale();
float xpos = (float) ((t > 0) ? Math.sqrt(t) : 0) - circleRadi + 50 * GameImage.getUIscale();
ScoreData[] scores = getScoreDataForNode(node, false);
node.draw(buttonX - offset - xpos, ypos,
(scores == null) ? Grade.NULL : scores[0].getGrade(), (node == focusNode));
}
g.clearClip();
// scroll bar
if (focusNode != null && startNode != null) {
int focusNodes = focusNode.getBeatmapSet().size();
@ -689,7 +687,7 @@ public class SongMenu extends BasicGameState {
// mouse hover
songScrolling.update(delta);
updateDrawnSongPos();
updateDrawnSongPosition();
boolean isHover = false;
if (mouseY > headerY && mouseY < footerY) {
BeatmapSetNode node = startNode;
@ -1041,14 +1039,12 @@ public class SongMenu extends BasicGameState {
return;
// score buttons
if (focusScores != null && focusScores.length >= MAX_SCORE_BUTTONS && ScoreData.areaContains(oldx, oldy)) {
if (focusScores != null && focusScores.length >= MAX_SCORE_BUTTONS && ScoreData.areaContains(oldx, oldy))
startScorePos.dragged(-diff * multiplier);
}
// song buttons
else
songScrolling.dragged(-diff * multiplier);
}
@Override
@ -1067,9 +1063,8 @@ public class SongMenu extends BasicGameState {
int mouseX = input.getMouseX(), mouseY = input.getMouseY();
// score buttons
if (focusScores != null && focusScores.length >= MAX_SCORE_BUTTONS && ScoreData.areaContains(mouseX, mouseY)) {
if (focusScores != null && focusScores.length >= MAX_SCORE_BUTTONS && ScoreData.areaContains(mouseX, mouseY))
startScorePos.scrollOffset(ScoreData.getButtonOffset() * shift);
}
// song buttons
else
@ -1255,7 +1250,7 @@ public class SongMenu extends BasicGameState {
/**
* Updates the song list data required for drawing.
*/
private void updateDrawnSongPos() {
private void updateDrawnSongPosition() {
float songNodePosDrawn = songScrolling.getPosition();
int startNodeIndex = (int) (songNodePosDrawn / buttonOffset);
@ -1271,6 +1266,7 @@ public class SongMenu extends BasicGameState {
} else {
startNodeOffset = 0;
}
// Finds the start node with the expanded focus node in mind.
if (focusNode != null && startNodeIndex >= focusNode.index) {
// below the focus node.
@ -1287,8 +1283,8 @@ public class SongMenu extends BasicGameState {
}
} else
startNode = BeatmapSetList.get().getBaseNode(startNodeIndex);
}
/**
* Sets a new focus node.
* @param node the base node; it will be expanded if it isn't already
@ -1357,13 +1353,10 @@ public class SongMenu extends BasicGameState {
}
// change the focus node
if (changeStartNode || (startNode.index == 0 && startNode.beatmapIndex == -1 && startNode.prev == null)){
if (changeStartNode || (startNode.index == 0 && startNode.beatmapIndex == -1 && startNode.prev == null))
songScrolling.setPosition((node.index - 1) * buttonOffset);
updateDrawnSongPos();
}
updateDrawnSongPos();
updateDrawnSongPosition();
// make sure focusNode is on the screen
int val = focusNode.index + focusNode.beatmapIndex;

View File

@ -1,3 +1,21 @@
/*
* opsu! - an open-source osu! client
* Copyright (C) 2014, 2015 Jeffrey Han
*
* opsu! is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* opsu! is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with opsu!. If not, see <http://www.gnu.org/licenses/>.
*/
package itdelatrisu.opsu.ui;
/**
@ -7,49 +25,44 @@ package itdelatrisu.opsu.ui;
* @author fluddokt (https://github.com/fluddokt)
*/
public class KineticScrolling {
/** The moving averaging constant */
final static private float AVG_CONST = 0.2f;
final static private float ONE_MINUS_AVG_CONST = 1 - AVG_CONST;
/** The moving averaging constant. */
private static final float AVG_CONST = 0.2f, ONE_MINUS_AVG_CONST = 1 - AVG_CONST;
/** The constant used to determine how fast the target position will be reach. */
final static private int TIME_CONST = 200;
private static final int TIME_CONST = 200;
/** The constant used to determine how much of the velocity will be used to launch to the target. */
final static private float AMPLITUDE_CONST = 0.25f;
private static final float AMPLITUDE_CONST = 0.25f;
/** The current position. */
float position;
private float position;
/** The offset to scroll to the target position. */
float amplitude;
private float amplitude;
/** The current target to scroll to. */
float target;
private float target;
/** The total amount of time since the mouse button was released. */
float totalDelta;
private float totalDelta;
/** The maximum and minimum value the position can reach. */
float max = Float.MAX_VALUE;
float min = -Float.MAX_VALUE;
private float max = Float.MAX_VALUE, min = -Float.MAX_VALUE;
/** Whether the mouse is currently pressed or not */
boolean pressed = false;
/** Whether the mouse is currently pressed or not. */
private boolean pressed = false;
/** The change in position since the last update */
float deltaPosition;
/** The change in position since the last update. */
private float deltaPosition;
/** The moving average of the velocity. */
float avgVelocity;
private float avgVelocity;
/**
* Returns the current Position.
* @return the position.
* @return the position
*/
public float getPosition() {
return position;
}
public float getPosition() { return position; }
/**
* Updates the scrolling.
@ -78,7 +91,7 @@ public class KineticScrolling {
/**
* Scrolls to the position.
* @param newPosition the position to scroll to.
* @param newPosition the position to scroll to
*/
public void scrollToPosition(float newPosition) {
amplitude = newPosition - position;
@ -88,7 +101,7 @@ public class KineticScrolling {
/**
* Scrolls to an offset from target.
* @param offset the offset from the target to scroll to.
* @param offset the offset from the target to scroll to
*/
public void scrollOffset(float offset) {
scrollToPosition(target + offset);
@ -107,7 +120,7 @@ public class KineticScrolling {
/**
* Set the position relative to an offset.
* @param offset the offset from the position.
* @param offset the offset from the position
*/
public void addOffset(float offset) {
setPosition(position + offset);