From 5a09689b4c69dd2349a12aeb19fcb7506e3fde3f Mon Sep 17 00:00:00 2001 From: Jeffrey Han Date: Sat, 10 Jan 2015 23:14:22 -0500 Subject: [PATCH] Added mouse hover effects for tabs. Signed-off-by: Jeffrey Han --- src/itdelatrisu/opsu/SongSort.java | 5 +++-- src/itdelatrisu/opsu/Utils.java | 8 +++++--- src/itdelatrisu/opsu/states/Options.java | 14 ++++++++++++-- src/itdelatrisu/opsu/states/SongMenu.java | 12 ++++++++++-- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/itdelatrisu/opsu/SongSort.java b/src/itdelatrisu/opsu/SongSort.java index 902fce09..76d90133 100644 --- a/src/itdelatrisu/opsu/SongSort.java +++ b/src/itdelatrisu/opsu/SongSort.java @@ -195,8 +195,9 @@ public enum SongSort { /** * Draws the sort tab. * @param selected whether the tab is selected (white) or not (red) + * @param isHover whether to include a hover effect (unselected only) */ - public void draw(boolean selected) { - Utils.drawTab(tab.getX(), tab.getY(), name, selected); + public void draw(boolean selected, boolean isHover) { + Utils.drawTab(tab.getX(), tab.getY(), name, selected, isHover); } } \ No newline at end of file diff --git a/src/itdelatrisu/opsu/Utils.java b/src/itdelatrisu/opsu/Utils.java index 3cfdcbc1..01a51b36 100644 --- a/src/itdelatrisu/opsu/Utils.java +++ b/src/itdelatrisu/opsu/Utils.java @@ -66,7 +66,8 @@ public class Utils { COLOR_RED_OBJECT = new Color(243, 48, 77), COLOR_ORANGE_OBJECT = new Color(255, 200, 32), COLOR_YELLOW_ALPHA = new Color(255, 255, 0, 0.4f), - COLOR_WHITE_FADE = new Color(255, 255, 255, 1f); + COLOR_WHITE_FADE = new Color(255, 255, 255, 1f), + COLOR_RED_HOVER = new Color(255, 112, 112); /** * The default map colors, used when a map does not provide custom colors. @@ -217,8 +218,9 @@ public class Utils { * @param y the center y coordinate * @param text the text to draw inside the tab * @param selected whether the tab is selected (white) or not (red) + * @param isHover whether to include a hover effect (unselected only) */ - public static void drawTab(float x, float y, String text, boolean selected) { + public static void drawTab(float x, float y, String text, boolean selected, boolean isHover) { Image tabImage = GameImage.MENU_TAB.getImage(); float tabTextX = x - (Utils.FONT_MEDIUM.getWidth(text) / 2); float tabTextY = y - (tabImage.getHeight() / 2f) + @@ -228,7 +230,7 @@ public class Utils { filter = Color.white; textColor = Color.black; } else { - filter = Color.red; + filter = (isHover) ? Utils.COLOR_RED_HOVER : Color.red; textColor = Color.white; } Utils.drawCentered(tabImage, x, y, filter); diff --git a/src/itdelatrisu/opsu/states/Options.java b/src/itdelatrisu/opsu/states/Options.java index 870858b9..3b01897e 100644 --- a/src/itdelatrisu/opsu/states/Options.java +++ b/src/itdelatrisu/opsu/states/Options.java @@ -453,6 +453,7 @@ public class Options extends BasicGameState { int width = container.getWidth(); int height = container.getHeight(); + int mouseX = input.getMouseX(), mouseY = input.getMouseY(); // title Utils.FONT_XLARGE.drawString( @@ -487,11 +488,20 @@ public class Options extends BasicGameState { } // option tabs + int hoverTab = -1; + for (int i = 0; i < optionTabs.length; i++) { + if (optionTabs[i].contains(mouseX, mouseY)) { + hoverTab = i; + break; + } + } for (int i = optionTabs.length - 1; i >= 0; i--) { if (i != currentTab) - Utils.drawTab(optionTabs[i].getX(), optionTabs[i].getY(), TAB_NAMES[i], false); + Utils.drawTab(optionTabs[i].getX(), optionTabs[i].getY(), + TAB_NAMES[i], false, i == hoverTab); } - Utils.drawTab(optionTabs[currentTab].getX(), optionTabs[currentTab].getY(), TAB_NAMES[currentTab], true); + Utils.drawTab(optionTabs[currentTab].getX(), optionTabs[currentTab].getY(), + TAB_NAMES[currentTab], true, false); g.setColor(Color.white); g.setLineWidth(2f); float lineY = optionTabs[0].getY() + (GameImage.MENU_TAB.getImage().getHeight() / 2f); diff --git a/src/itdelatrisu/opsu/states/SongMenu.java b/src/itdelatrisu/opsu/states/SongMenu.java index c7f7fa79..e5b40d65 100644 --- a/src/itdelatrisu/opsu/states/SongMenu.java +++ b/src/itdelatrisu/opsu/states/SongMenu.java @@ -204,6 +204,7 @@ public class SongMenu extends BasicGameState { int width = container.getWidth(); int height = container.getHeight(); + int mouseX = input.getMouseX(), mouseY = input.getMouseY(); // background if (focusNode != null) @@ -255,11 +256,18 @@ public class SongMenu extends BasicGameState { // sorting tabs SongSort currentSort = SongSort.getSort(); + SongSort hoverSort = null; + for (SongSort sort : SongSort.values()) { + if (sort.contains(mouseX, mouseY)) { + hoverSort = sort; + break; + } + } for (SongSort sort : SongSort.VALUES_REVERSED) { if (sort != currentSort) - sort.draw(false); + sort.draw(false, sort == hoverSort); } - currentSort.draw(true); + currentSort.draw(true, false); // search Image searchIcon = GameImage.MENU_SEARCH.getImage();