Small follow-up to 70c70fd.

- Page back/forward are now expanding buttons instead of static images.
- Fixed a mistake in DownloadList.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-02-01 02:53:01 -05:00
parent 70c70fd812
commit cfc0449ab2
3 changed files with 42 additions and 53 deletions

View File

@ -18,6 +18,8 @@
package itdelatrisu.opsu.downloads; package itdelatrisu.opsu.downloads;
import itdelatrisu.opsu.ErrorHandler;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -26,8 +28,6 @@ import java.util.Map;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.UIManager; import javax.swing.UIManager;
import org.newdawn.slick.util.Log;
/** /**
* Maintains the current downloads list. * Maintains the current downloads list.
*/ */
@ -134,7 +134,7 @@ public class DownloadList {
try { try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) { } catch (Exception e) {
Log.error("Could not set system look and feel for Container.", e); ErrorHandler.error("Could not set system look and feel for DownloadList.", e, true);
} }
int n = JOptionPane.showConfirmDialog(null, int n = JOptionPane.showConfirmDialog(null,
"Beatmap downloads are in progress.\nAre you sure you want to quit opsu!?", "Beatmap downloads are in progress.\nAre you sure you want to quit opsu!?",

View File

@ -155,30 +155,6 @@ public class DownloadNode {
(cy > infoBaseY && cy < infoBaseY + infoHeight * DownloadsMenu.MAX_DOWNLOADS_SHOWN)); (cy > infoBaseY && cy < infoBaseY + infoHeight * DownloadsMenu.MAX_DOWNLOADS_SHOWN));
} }
/**
* Returns true if the coordinates are within the bounds of the
* previous page icon.
* @param cx the x coordinate
* @param cy the y coordinate
*/
public static boolean prevPageContains(float cx, float cy) {
Image img = GameImage.MUSIC_PREVIOUS.getImage();
return ((cx > buttonBaseX && cx < buttonBaseX + img.getWidth()) &&
(cy > buttonBaseY - img.getHeight() && cy < buttonBaseY));
}
/**
* Returns true if the coordinates are within the bounds of the
* next page icon.
* @param cx the x coordinate
* @param cy the y coordinate
*/
public static boolean nextPageContains(float cx, float cy) {
Image img = GameImage.MUSIC_NEXT.getImage();
return ((cx > buttonBaseX + buttonWidth - img.getWidth() && cx < buttonBaseX + buttonWidth) &&
(cy > buttonBaseY - img.getHeight() && cy < buttonBaseY));
}
/** /**
* Draws the scroll bar for the download result buttons. * Draws the scroll bar for the download result buttons.
* @param g the graphics context * @param g the graphics context
@ -215,27 +191,6 @@ public class DownloadNode {
g.fillRect(infoBaseX + infoWidth - scrollbarWidth, infoBaseY + offsetY, scrollbarWidth, scrollbarHeight); g.fillRect(infoBaseX + infoWidth - scrollbarWidth, infoBaseY + offsetY, scrollbarWidth, scrollbarHeight);
} }
/**
* Draws the page number text and previous/next page icons.
* @param page the current page number
* @param prev whether to draw the previous page icon
* @param next whether to draw the next page icon
*/
public static void drawPageIcons(int page, boolean prev, boolean next) {
String pageText = String.format("Page %d", page);
Utils.FONT_BOLD.drawString(
buttonBaseX + (buttonWidth - Utils.FONT_BOLD.getWidth("Page 1")) / 2f,
buttonBaseY - Utils.FONT_BOLD.getLineHeight() * 1.3f, pageText, Color.white);
if (prev) {
Image prevImg = GameImage.MUSIC_PREVIOUS.getImage();
prevImg.draw(buttonBaseX, buttonBaseY - prevImg.getHeight());
}
if (next) {
Image nextImg = GameImage.MUSIC_NEXT.getImage();
nextImg.draw(buttonBaseX + buttonWidth - nextImg.getWidth(), buttonBaseY - nextImg.getHeight());
}
}
/** /**
* Constructor. * Constructor.
*/ */

View File

@ -19,6 +19,7 @@
package itdelatrisu.opsu.states; package itdelatrisu.opsu.states;
import itdelatrisu.opsu.GameImage; import itdelatrisu.opsu.GameImage;
import itdelatrisu.opsu.MenuButton;
import itdelatrisu.opsu.Opsu; import itdelatrisu.opsu.Opsu;
import itdelatrisu.opsu.Utils; import itdelatrisu.opsu.Utils;
import itdelatrisu.opsu.audio.SoundController; import itdelatrisu.opsu.audio.SoundController;
@ -34,6 +35,7 @@ import java.io.IOException;
import org.newdawn.slick.Color; import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer; import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics; import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input; import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException; import org.newdawn.slick.SlickException;
import org.newdawn.slick.gui.TextField; import org.newdawn.slick.gui.TextField;
@ -124,6 +126,9 @@ public class DownloadsMenu extends BasicGameState {
/** Number of active requests. */ /** Number of active requests. */
private int activeRequests = 0; private int activeRequests = 0;
/** Previous and next page buttons. */
private MenuButton prevPage, nextPage;
/** "Ranked only?" checkbox coordinates. */ /** "Ranked only?" checkbox coordinates. */
private float rankedBoxX, rankedBoxY, rankedBoxLength; private float rankedBoxX, rankedBoxY, rankedBoxLength;
@ -144,13 +149,14 @@ public class DownloadsMenu extends BasicGameState {
int width = container.getWidth(); int width = container.getWidth();
int height = container.getHeight(); int height = container.getHeight();
float baseX = width * 0.024f;
// search // search
searchTimer = SEARCH_DELAY; searchTimer = SEARCH_DELAY;
searchResultString = "Type to search!"; searchResultString = "Type to search!";
search = new TextField( search = new TextField(
container, Utils.FONT_DEFAULT, container, Utils.FONT_DEFAULT,
(int) (width * 0.024f), (int) (height * 0.05f) + Utils.FONT_LARGE.getLineHeight(), (int) baseX, (int) (height * 0.05f) + Utils.FONT_LARGE.getLineHeight(),
(int) (width * 0.35f), Utils.FONT_MEDIUM.getLineHeight() (int) (width * 0.35f), Utils.FONT_MEDIUM.getLineHeight()
); );
search.setBackgroundColor(DownloadNode.BG_NORMAL); search.setBackgroundColor(DownloadNode.BG_NORMAL);
@ -163,6 +169,18 @@ public class DownloadsMenu extends BasicGameState {
rankedBoxX = search.getX() + search.getWidth() * 1.2f; rankedBoxX = search.getX() + search.getWidth() * 1.2f;
rankedBoxY = search.getY(); rankedBoxY = search.getY();
rankedBoxLength = search.getHeight(); rankedBoxLength = search.getHeight();
// page buttons
float buttonY = height * 0.2f;
float buttonWidth = width * 0.7f;
Image prevImg = GameImage.MUSIC_PREVIOUS.getImage();
Image nextImg = GameImage.MUSIC_NEXT.getImage();
prevPage = new MenuButton(prevImg, baseX + prevImg.getWidth() / 2f,
buttonY - prevImg.getHeight() / 2f);
nextPage = new MenuButton(nextImg, baseX + buttonWidth - nextImg.getWidth() / 2f,
buttonY - nextImg.getHeight() / 2f);
prevPage.setHoverScale(1.5f);
nextPage.setHoverScale(1.5f);
} }
@Override @Override
@ -208,8 +226,20 @@ public class DownloadsMenu extends BasicGameState {
DownloadNode.drawResultScrollbar(g, startResult, nodes.length); DownloadNode.drawResultScrollbar(g, startResult, nodes.length);
// pages // pages
if (nodes.length > 0) if (nodes.length > 0) {
DownloadNode.drawPageIcons(page, (page > 1), (pageResultTotal < totalResults)); float baseX = width * 0.024f;
float buttonY = height * 0.2f;
float buttonWidth = width * 0.7f;
Utils.FONT_BOLD.drawString(
baseX + (buttonWidth - Utils.FONT_BOLD.getWidth("Page 1")) / 2f,
buttonY - Utils.FONT_BOLD.getLineHeight() * 1.3f,
String.format("Page %d", page), Color.white
);
if (page > 1)
prevPage.draw();
if (pageResultTotal < totalResults)
nextPage.draw();
}
} }
// downloads // downloads
@ -245,6 +275,8 @@ public class DownloadsMenu extends BasicGameState {
Utils.updateVolumeDisplay(delta); Utils.updateVolumeDisplay(delta);
int mouseX = input.getMouseX(), mouseY = input.getMouseY(); int mouseX = input.getMouseX(), mouseY = input.getMouseY();
Utils.getBackButton().hoverUpdate(delta, mouseX, mouseY); Utils.getBackButton().hoverUpdate(delta, mouseX, mouseY);
prevPage.hoverUpdate(delta, mouseX, mouseY);
nextPage.hoverUpdate(delta, mouseX, mouseY);
// focus timer // focus timer
if (focusResult != -1 && focusTimer < FOCUS_DELAY) if (focusResult != -1 && focusTimer < FOCUS_DELAY)
@ -388,7 +420,7 @@ public class DownloadsMenu extends BasicGameState {
// pages // pages
if (nodes.length > 0) { if (nodes.length > 0) {
if (page > 1 && DownloadNode.prevPageContains(x, y)) { if (page > 1 && prevPage.contains(x, y)) {
if (lastQueryDir == Page.PREVIOUS && queryThread != null && queryThread.isAlive()) if (lastQueryDir == Page.PREVIOUS && queryThread != null && queryThread.isAlive())
; // don't send consecutive requests ; // don't send consecutive requests
else { else {
@ -398,7 +430,7 @@ public class DownloadsMenu extends BasicGameState {
} }
return; return;
} }
if (pageResultTotal < totalResults && DownloadNode.nextPageContains(x, y)) { if (pageResultTotal < totalResults && nextPage.contains(x, y)) {
if (lastQueryDir == Page.NEXT && queryThread != null && queryThread.isAlive()) if (lastQueryDir == Page.NEXT && queryThread != null && queryThread.isAlive())
; // don't send consecutive requests ; // don't send consecutive requests
else { else {
@ -503,6 +535,8 @@ public class DownloadsMenu extends BasicGameState {
public void enter(GameContainer container, StateBasedGame game) public void enter(GameContainer container, StateBasedGame game)
throws SlickException { throws SlickException {
Utils.getBackButton().setScale(1f); Utils.getBackButton().setScale(1f);
prevPage.setScale(1f);
nextPage.setScale(1f);
focusResult = -1; focusResult = -1;
startResult = 0; startResult = 0;
startDownloadIndex = 0; startDownloadIndex = 0;