diff --git a/src/itdelatrisu/opsu/GameImage.java b/src/itdelatrisu/opsu/GameImage.java index 0b38c7ff..ac6ad301 100644 --- a/src/itdelatrisu/opsu/GameImage.java +++ b/src/itdelatrisu/opsu/GameImage.java @@ -34,12 +34,42 @@ public enum GameImage { SECTION_PASS ("section-pass.png"), SECTION_FAIL ("section-fail.png"), WARNINGARROW ("play-warningarrow.png"), - SKIP ("play-skip.png"), - COUNTDOWN_READY ("ready.png"), - COUNTDOWN_3 ("count3.png"), - COUNTDOWN_2 ("count2.png"), - COUNTDOWN_1 ("count1.png"), - COUNTDOWN_GO ("go.png"), + SKIP ("play-skip.png") { + @Override + protected Image process_sub(Image img, int w, int h) { + return img.getScaledCopy((h * 0.1f) / img.getHeight()); + } + }, + COUNTDOWN_READY ("ready.png") { + @Override + protected Image process_sub(Image img, int w, int h) { + return img.getScaledCopy((h / 3f) / img.getHeight()); + } + }, + COUNTDOWN_3 ("count3.png") { + @Override + protected Image process_sub(Image img, int w, int h) { + return img.getScaledCopy((h / 3f) / img.getHeight()); + } + }, + COUNTDOWN_2 ("count2.png") { + @Override + protected Image process_sub(Image img, int w, int h) { + return img.getScaledCopy((h / 3f) / img.getHeight()); + } + }, + COUNTDOWN_1 ("count1.png") { + @Override + protected Image process_sub(Image img, int w, int h) { + return img.getScaledCopy((h / 3f) / img.getHeight()); + } + }, + COUNTDOWN_GO ("go.png") { + @Override + protected Image process_sub(Image img, int w, int h) { + return img.getScaledCopy((h / 3f) / img.getHeight()); + } + }, HITCIRCLE_SELECT ("hitcircleselect.png"), UNRANKED ("play-unranked.png"), @@ -47,8 +77,20 @@ public enum GameImage { PAUSE_CONTINUE ("pause-continue.png"), PAUSE_RETRY ("pause-retry.png"), PAUSE_BACK ("pause-back.png"), - PAUSE_OVERLAY ("pause-overlay.png"), - FAIL_BACKGROUND ("fail-background.png"), + PAUSE_OVERLAY ("pause-overlay.png") { + @Override + protected Image process_sub(Image img, int w, int h) { + img.setAlpha(0.7f); + return img.getScaledCopy(w, h); + } + }, + FAIL_BACKGROUND ("fail-background.png") { + @Override + protected Image process_sub(Image img, int w, int h) { + img.setAlpha(0.7f); + return img.getScaledCopy(w, h); + } + }, // Circle HITCIRCLE ("hitcircle.png"), @@ -69,8 +111,18 @@ public enum GameImage { SPINNER_OSU ("spinner-osu.png"), // Game Score - SCOREBAR_BG ("scorebar-bg.png"), - SCOREBAR_COLOUR ("scorebar-colour.png"), + SCOREBAR_BG ("scorebar-bg.png") { + @Override + protected Image process_sub(Image img, int w, int h) { + return img.getScaledCopy(w / 2, img.getHeight()); + } + }, + SCOREBAR_COLOUR ("scorebar-colour.png") { + @Override + protected Image process_sub(Image img, int w, int h) { + return img.getScaledCopy(w / 2, img.getHeight()); + } + }, SCOREBAR_KI ("scorebar-ki.png"), SCOREBAR_KI_DANGER ("scorebar-kidanger.png"), SCOREBAR_KI_DANGER2 ("scorebar-kidanger2.png"), @@ -99,11 +151,36 @@ public enum GameImage { RANKING_C_SMALL ("ranking-C-small.png"), RANKING_D ("ranking-D.png"), RANKING_D_SMALL ("ranking-D-small.png"), - RANKING_PANEL ("ranking-panel.png"), - RANKING_PERFECT ("ranking-perfect.png"), - RANKING_TITLE ("ranking-title.png"), - RANKING_MAXCOMBO ("ranking-maxcombo.png"), - RANKING_ACCURACY ("ranking-accuracy.png"), + RANKING_PANEL ("ranking-panel.png") { + @Override + protected Image process_sub(Image img, int w, int h) { + return img.getScaledCopy((h * 0.63f) / img.getHeight()); + } + }, + RANKING_PERFECT ("ranking-perfect.png") { + @Override + protected Image process_sub(Image img, int w, int h) { + return img.getScaledCopy((h * 0.16f) / img.getHeight()); + } + }, + RANKING_TITLE ("ranking-title.png") { + @Override + protected Image process_sub(Image img, int w, int h) { + return img.getScaledCopy((h * 0.15f) / img.getHeight()); + } + }, + RANKING_MAXCOMBO ("ranking-maxcombo.png") { + @Override + protected Image process_sub(Image img, int w, int h) { + return img.getScaledCopy((h * 0.05f) / img.getHeight()); + } + }, + RANKING_ACCURACY ("ranking-accuracy.png") { + @Override + protected Image process_sub(Image img, int w, int h) { + return img.getScaledCopy((h * 0.05f) / img.getHeight()); + } + }, DEFAULT_0 ("default-0.png"), DEFAULT_1 ("default-1.png"), DEFAULT_2 ("default-2.png"), @@ -145,9 +222,19 @@ public enum GameImage { private Image skinImage; /** - * Whether or not the default image has been scaled. + * Container dimensions. */ - private boolean scaled; + private static int containerWidth, containerHeight; + + /** + * Initializes the GameImage class with container dimensions. + * @param width the container width + * @param height the container height + */ + public static void init(int width, int height) { + containerWidth = width; + containerHeight = height; + } /** * Constructor. @@ -185,7 +272,6 @@ public enum GameImage { defaultImage.destroy(); defaultImage = new Image(filename); - scaled = false; } catch (SlickException e) { Log.error(String.format("Failed to set default image '%s'.", filename), e); } @@ -194,8 +280,9 @@ public enum GameImage { /** * Sets the associated skin image. * If the path does not contain the image, the default image is used. + * @return true if a new skin image is loaded, false otherwise */ - public void setSkinImage(File dir) { + public boolean setSkinImage(File dir) { try { // destroy the existing image, if any if (skinImage != null && !skinImage.isDestroyed()) @@ -203,22 +290,34 @@ public enum GameImage { // set a new image File file = new File(dir, filename); - if (file.isFile() && !Options.isBeatmapSkinIgnored()) + if (file.isFile() && !Options.isBeatmapSkinIgnored()) { skinImage = new Image(file.getAbsolutePath()); - else + return true; + } else { skinImage = null; + return false; + } } catch (SlickException e) { Log.error(String.format("Failed to set skin image '%s'.", filename), e); + return false; } } /** - * Returns whether or not the image has been scaled. + * Sub-method for image processing actions (via an override). + * @param img the image to process + * @param w the container width + * @param h the container height + * @return the processed image */ - public boolean isScaled() { return (skinImage != null) ? false : scaled; } + protected Image process_sub(Image img, int w, int h) { + return img; + } /** - * Sets the scaled status of the image. + * Performs individual post-loading actions on the image. */ - public void setScaled() { if (skinImage == null) this.scaled = true; } + public void process() { + setImage(process_sub(getImage(), containerWidth, containerHeight)); + } } \ No newline at end of file diff --git a/src/itdelatrisu/opsu/GameScore.java b/src/itdelatrisu/opsu/GameScore.java index b828b58a..69785322 100644 --- a/src/itdelatrisu/opsu/GameScore.java +++ b/src/itdelatrisu/opsu/GameScore.java @@ -313,19 +313,6 @@ public class GameScore { } } - // scorebar - int bgWidth = width / 2; - if (!GameImage.SCOREBAR_BG.isScaled()) { - Image bg = GameImage.SCOREBAR_BG.getImage(); - GameImage.SCOREBAR_BG.setImage(bg.getScaledCopy(bgWidth, bg.getHeight())); - GameImage.SCOREBAR_BG.setScaled(); - } - if (!GameImage.SCOREBAR_COLOUR.isScaled()) { - Image colour = GameImage.SCOREBAR_COLOUR.getImage(); - GameImage.SCOREBAR_COLOUR.setImage(colour.getScaledCopy(bgWidth, colour.getHeight())); - GameImage.SCOREBAR_COLOUR.setScaled(); - } - // default symbol images defaultSymbols = new Image[10]; defaultSymbols[0] = GameImage.DEFAULT_0.getImage(); @@ -387,33 +374,6 @@ public class GameScore { gradesSmall[GRADE_C] = GameImage.RANKING_C_SMALL.getImage(); gradesLarge[GRADE_D] = GameImage.RANKING_D.getImage(); gradesSmall[GRADE_D] = GameImage.RANKING_D_SMALL.getImage(); - - // ranking screen elements - if (!GameImage.RANKING_PANEL.isScaled()) { - Image rankingPanel = GameImage.RANKING_PANEL.getImage(); - GameImage.RANKING_PANEL.setImage(rankingPanel.getScaledCopy((height * 0.63f) / rankingPanel.getHeight())); - GameImage.RANKING_PANEL.setScaled(); - } - if (!GameImage.RANKING_PERFECT.isScaled()) { - Image rankingPerfect = GameImage.RANKING_PERFECT.getImage(); - GameImage.RANKING_PERFECT.setImage(rankingPerfect.getScaledCopy((height * 0.16f) / rankingPerfect.getHeight())); - GameImage.RANKING_PERFECT.setScaled(); - } - if (!GameImage.RANKING_TITLE.isScaled()) { - Image rankingTitle = GameImage.RANKING_TITLE.getImage(); - GameImage.RANKING_TITLE.setImage(rankingTitle.getScaledCopy((height * 0.15f) / rankingTitle.getHeight())); - GameImage.RANKING_TITLE.setScaled(); - } - if (!GameImage.RANKING_MAXCOMBO.isScaled()) { - Image rankingMaxCombo = GameImage.RANKING_MAXCOMBO.getImage(); - GameImage.RANKING_MAXCOMBO.setImage(rankingMaxCombo.getScaledCopy((height * 0.05f) / rankingMaxCombo.getHeight())); - GameImage.RANKING_MAXCOMBO.setScaled(); - } - if (!GameImage.RANKING_ACCURACY.isScaled()) { - Image rankingAccuracy = GameImage.RANKING_ACCURACY.getImage(); - GameImage.RANKING_ACCURACY.setImage(rankingAccuracy.getScaledCopy((height * 0.05f) / rankingAccuracy.getHeight())); - GameImage.RANKING_ACCURACY.setScaled(); - } } /** diff --git a/src/itdelatrisu/opsu/Utils.java b/src/itdelatrisu/opsu/Utils.java index 8ef4d455..e8d807a7 100644 --- a/src/itdelatrisu/opsu/Utils.java +++ b/src/itdelatrisu/opsu/Utils.java @@ -203,8 +203,11 @@ public class Utils { backButton.setHoverDir(MenuButton.Expand.UP_RIGHT); // set default game images - for (GameImage img : GameImage.values()) + GameImage.init(width, height); + for (GameImage img : GameImage.values()) { img.setDefaultImage(); + img.process(); + } // initialize game mods for (GameMod mod : GameMod.values()) diff --git a/src/itdelatrisu/opsu/states/Game.java b/src/itdelatrisu/opsu/states/Game.java index a3baf27c..e4817c6f 100644 --- a/src/itdelatrisu/opsu/states/Game.java +++ b/src/itdelatrisu/opsu/states/Game.java @@ -857,55 +857,18 @@ public class Game extends BasicGameState { // set images File parent = osu.getFile().getParentFile(); - for (GameImage o : GameImage.values()) - o.setSkinImage(parent); + for (GameImage img : GameImage.values()) { + if (img.setSkinImage(parent)) + img.process(); + } // skip button Image skip = GameImage.SKIP.getImage(); - if (!GameImage.SKIP.isScaled()) { - float skipScale = (height * 0.1f) / skip.getHeight(); - skip = skip.getScaledCopy(skipScale); - GameImage.SKIP.setImage(skip); - GameImage.SKIP.setScaled(); - } skipButton = new MenuButton(skip, width - (skip.getWidth() / 2f), height - (skip.getHeight() / 2f)); skipButton.setHoverDir(MenuButton.Expand.UP_LEFT); - // countdown - float countdownHeight = height / 3f; - if (!GameImage.COUNTDOWN_READY.isScaled()) { - Image countdownReady = GameImage.COUNTDOWN_READY.getImage(); - GameImage.COUNTDOWN_READY.setImage( - countdownReady.getScaledCopy(countdownHeight / countdownReady.getHeight())); - GameImage.COUNTDOWN_READY.setScaled(); - } - if (!GameImage.COUNTDOWN_3.isScaled()) { - Image countdown3 = GameImage.COUNTDOWN_3.getImage(); - GameImage.COUNTDOWN_3.setImage( - countdown3.getScaledCopy(countdownHeight / countdown3.getHeight())); - GameImage.COUNTDOWN_3.setScaled(); - } - if (!GameImage.COUNTDOWN_2.isScaled()) { - Image countdown2 = GameImage.COUNTDOWN_2.getImage(); - GameImage.COUNTDOWN_2.setImage( - countdown2.getScaledCopy(countdownHeight / countdown2.getHeight())); - GameImage.COUNTDOWN_2.setScaled(); - } - if (!GameImage.COUNTDOWN_1.isScaled()) { - Image countdown1 = GameImage.COUNTDOWN_1.getImage(); - GameImage.COUNTDOWN_1.setImage( - countdown1.getScaledCopy(countdownHeight / countdown1.getHeight())); - GameImage.COUNTDOWN_1.setScaled(); - } - if (!GameImage.COUNTDOWN_GO.isScaled()) { - Image countdownGo = GameImage.COUNTDOWN_GO.getImage(); - GameImage.COUNTDOWN_GO.setImage( - countdownGo.getScaledCopy(countdownHeight / countdownGo.getHeight())); - GameImage.COUNTDOWN_GO.setScaled(); - } - // load other images... ((GamePauseMenu) game.getState(Opsu.STATE_GAMEPAUSEMENU)).loadImages(); score.loadImages(); diff --git a/src/itdelatrisu/opsu/states/GamePauseMenu.java b/src/itdelatrisu/opsu/states/GamePauseMenu.java index 24de29a7..f2c12ee3 100644 --- a/src/itdelatrisu/opsu/states/GamePauseMenu.java +++ b/src/itdelatrisu/opsu/states/GamePauseMenu.java @@ -200,19 +200,5 @@ public class GamePauseMenu extends BasicGameState { continueButton = new MenuButton(GameImage.PAUSE_CONTINUE.getImage(), width / 2f, height * 0.25f); retryButton = new MenuButton(GameImage.PAUSE_RETRY.getImage(), width / 2f, height * 0.5f); backButton = new MenuButton(GameImage.PAUSE_BACK.getImage(), width / 2f, height * 0.75f); - - // pause background image - if (!GameImage.PAUSE_OVERLAY.isScaled()) { - GameImage.PAUSE_OVERLAY.setImage(GameImage.PAUSE_OVERLAY.getImage().getScaledCopy(width, height)); - GameImage.PAUSE_OVERLAY.getImage().setAlpha(0.7f); - GameImage.PAUSE_OVERLAY.setScaled(); - } - - // fail image - if (!GameImage.FAIL_BACKGROUND.isScaled()) { - GameImage.FAIL_BACKGROUND.setImage(GameImage.FAIL_BACKGROUND.getImage().getScaledCopy(width, height)); - GameImage.FAIL_BACKGROUND.getImage().setAlpha(0.7f); - GameImage.FAIL_BACKGROUND.setScaled(); - } } }