Moved most GameImage scaling/processing to a single file.
- To scale an image, override process_sub() in its enum definition. All GameImages call the process() method when loaded. - Skin GameImage overrides will now call process() immediately, so there's no more need for the hackish scaling status. Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
parent
1e806bc9c6
commit
8671718ce3
|
@ -34,12 +34,42 @@ public enum GameImage {
|
||||||
SECTION_PASS ("section-pass.png"),
|
SECTION_PASS ("section-pass.png"),
|
||||||
SECTION_FAIL ("section-fail.png"),
|
SECTION_FAIL ("section-fail.png"),
|
||||||
WARNINGARROW ("play-warningarrow.png"),
|
WARNINGARROW ("play-warningarrow.png"),
|
||||||
SKIP ("play-skip.png"),
|
SKIP ("play-skip.png") {
|
||||||
COUNTDOWN_READY ("ready.png"),
|
@Override
|
||||||
COUNTDOWN_3 ("count3.png"),
|
protected Image process_sub(Image img, int w, int h) {
|
||||||
COUNTDOWN_2 ("count2.png"),
|
return img.getScaledCopy((h * 0.1f) / img.getHeight());
|
||||||
COUNTDOWN_1 ("count1.png"),
|
}
|
||||||
COUNTDOWN_GO ("go.png"),
|
},
|
||||||
|
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"),
|
HITCIRCLE_SELECT ("hitcircleselect.png"),
|
||||||
UNRANKED ("play-unranked.png"),
|
UNRANKED ("play-unranked.png"),
|
||||||
|
|
||||||
|
@ -47,8 +77,20 @@ public enum GameImage {
|
||||||
PAUSE_CONTINUE ("pause-continue.png"),
|
PAUSE_CONTINUE ("pause-continue.png"),
|
||||||
PAUSE_RETRY ("pause-retry.png"),
|
PAUSE_RETRY ("pause-retry.png"),
|
||||||
PAUSE_BACK ("pause-back.png"),
|
PAUSE_BACK ("pause-back.png"),
|
||||||
PAUSE_OVERLAY ("pause-overlay.png"),
|
PAUSE_OVERLAY ("pause-overlay.png") {
|
||||||
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);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
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
|
// Circle
|
||||||
HITCIRCLE ("hitcircle.png"),
|
HITCIRCLE ("hitcircle.png"),
|
||||||
|
@ -69,8 +111,18 @@ public enum GameImage {
|
||||||
SPINNER_OSU ("spinner-osu.png"),
|
SPINNER_OSU ("spinner-osu.png"),
|
||||||
|
|
||||||
// Game Score
|
// Game Score
|
||||||
SCOREBAR_BG ("scorebar-bg.png"),
|
SCOREBAR_BG ("scorebar-bg.png") {
|
||||||
SCOREBAR_COLOUR ("scorebar-colour.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 ("scorebar-ki.png"),
|
||||||
SCOREBAR_KI_DANGER ("scorebar-kidanger.png"),
|
SCOREBAR_KI_DANGER ("scorebar-kidanger.png"),
|
||||||
SCOREBAR_KI_DANGER2 ("scorebar-kidanger2.png"),
|
SCOREBAR_KI_DANGER2 ("scorebar-kidanger2.png"),
|
||||||
|
@ -99,11 +151,36 @@ public enum GameImage {
|
||||||
RANKING_C_SMALL ("ranking-C-small.png"),
|
RANKING_C_SMALL ("ranking-C-small.png"),
|
||||||
RANKING_D ("ranking-D.png"),
|
RANKING_D ("ranking-D.png"),
|
||||||
RANKING_D_SMALL ("ranking-D-small.png"),
|
RANKING_D_SMALL ("ranking-D-small.png"),
|
||||||
RANKING_PANEL ("ranking-panel.png"),
|
RANKING_PANEL ("ranking-panel.png") {
|
||||||
RANKING_PERFECT ("ranking-perfect.png"),
|
@Override
|
||||||
RANKING_TITLE ("ranking-title.png"),
|
protected Image process_sub(Image img, int w, int h) {
|
||||||
RANKING_MAXCOMBO ("ranking-maxcombo.png"),
|
return img.getScaledCopy((h * 0.63f) / img.getHeight());
|
||||||
RANKING_ACCURACY ("ranking-accuracy.png"),
|
}
|
||||||
|
},
|
||||||
|
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_0 ("default-0.png"),
|
||||||
DEFAULT_1 ("default-1.png"),
|
DEFAULT_1 ("default-1.png"),
|
||||||
DEFAULT_2 ("default-2.png"),
|
DEFAULT_2 ("default-2.png"),
|
||||||
|
@ -145,9 +222,19 @@ public enum GameImage {
|
||||||
private Image skinImage;
|
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.
|
* Constructor.
|
||||||
|
@ -185,7 +272,6 @@ public enum GameImage {
|
||||||
defaultImage.destroy();
|
defaultImage.destroy();
|
||||||
|
|
||||||
defaultImage = new Image(filename);
|
defaultImage = new Image(filename);
|
||||||
scaled = false;
|
|
||||||
} catch (SlickException e) {
|
} catch (SlickException e) {
|
||||||
Log.error(String.format("Failed to set default image '%s'.", filename), 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.
|
* Sets the associated skin image.
|
||||||
* If the path does not contain the image, the default image is used.
|
* 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 {
|
try {
|
||||||
// destroy the existing image, if any
|
// destroy the existing image, if any
|
||||||
if (skinImage != null && !skinImage.isDestroyed())
|
if (skinImage != null && !skinImage.isDestroyed())
|
||||||
|
@ -203,22 +290,34 @@ public enum GameImage {
|
||||||
|
|
||||||
// set a new image
|
// set a new image
|
||||||
File file = new File(dir, filename);
|
File file = new File(dir, filename);
|
||||||
if (file.isFile() && !Options.isBeatmapSkinIgnored())
|
if (file.isFile() && !Options.isBeatmapSkinIgnored()) {
|
||||||
skinImage = new Image(file.getAbsolutePath());
|
skinImage = new Image(file.getAbsolutePath());
|
||||||
else
|
return true;
|
||||||
|
} else {
|
||||||
skinImage = null;
|
skinImage = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
} catch (SlickException e) {
|
} catch (SlickException e) {
|
||||||
Log.error(String.format("Failed to set skin image '%s'.", filename), 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));
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -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
|
// default symbol images
|
||||||
defaultSymbols = new Image[10];
|
defaultSymbols = new Image[10];
|
||||||
defaultSymbols[0] = GameImage.DEFAULT_0.getImage();
|
defaultSymbols[0] = GameImage.DEFAULT_0.getImage();
|
||||||
|
@ -387,33 +374,6 @@ public class GameScore {
|
||||||
gradesSmall[GRADE_C] = GameImage.RANKING_C_SMALL.getImage();
|
gradesSmall[GRADE_C] = GameImage.RANKING_C_SMALL.getImage();
|
||||||
gradesLarge[GRADE_D] = GameImage.RANKING_D.getImage();
|
gradesLarge[GRADE_D] = GameImage.RANKING_D.getImage();
|
||||||
gradesSmall[GRADE_D] = GameImage.RANKING_D_SMALL.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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -203,8 +203,11 @@ public class Utils {
|
||||||
backButton.setHoverDir(MenuButton.Expand.UP_RIGHT);
|
backButton.setHoverDir(MenuButton.Expand.UP_RIGHT);
|
||||||
|
|
||||||
// set default game images
|
// set default game images
|
||||||
for (GameImage img : GameImage.values())
|
GameImage.init(width, height);
|
||||||
|
for (GameImage img : GameImage.values()) {
|
||||||
img.setDefaultImage();
|
img.setDefaultImage();
|
||||||
|
img.process();
|
||||||
|
}
|
||||||
|
|
||||||
// initialize game mods
|
// initialize game mods
|
||||||
for (GameMod mod : GameMod.values())
|
for (GameMod mod : GameMod.values())
|
||||||
|
|
|
@ -857,55 +857,18 @@ public class Game extends BasicGameState {
|
||||||
|
|
||||||
// set images
|
// set images
|
||||||
File parent = osu.getFile().getParentFile();
|
File parent = osu.getFile().getParentFile();
|
||||||
for (GameImage o : GameImage.values())
|
for (GameImage img : GameImage.values()) {
|
||||||
o.setSkinImage(parent);
|
if (img.setSkinImage(parent))
|
||||||
|
img.process();
|
||||||
|
}
|
||||||
|
|
||||||
// skip button
|
// skip button
|
||||||
Image skip = GameImage.SKIP.getImage();
|
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,
|
skipButton = new MenuButton(skip,
|
||||||
width - (skip.getWidth() / 2f),
|
width - (skip.getWidth() / 2f),
|
||||||
height - (skip.getHeight() / 2f));
|
height - (skip.getHeight() / 2f));
|
||||||
skipButton.setHoverDir(MenuButton.Expand.UP_LEFT);
|
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...
|
// load other images...
|
||||||
((GamePauseMenu) game.getState(Opsu.STATE_GAMEPAUSEMENU)).loadImages();
|
((GamePauseMenu) game.getState(Opsu.STATE_GAMEPAUSEMENU)).loadImages();
|
||||||
score.loadImages();
|
score.loadImages();
|
||||||
|
|
|
@ -200,19 +200,5 @@ public class GamePauseMenu extends BasicGameState {
|
||||||
continueButton = new MenuButton(GameImage.PAUSE_CONTINUE.getImage(), width / 2f, height * 0.25f);
|
continueButton = new MenuButton(GameImage.PAUSE_CONTINUE.getImage(), width / 2f, height * 0.25f);
|
||||||
retryButton = new MenuButton(GameImage.PAUSE_RETRY.getImage(), width / 2f, height * 0.5f);
|
retryButton = new MenuButton(GameImage.PAUSE_RETRY.getImage(), width / 2f, height * 0.5f);
|
||||||
backButton = new MenuButton(GameImage.PAUSE_BACK.getImage(), width / 2f, height * 0.75f);
|
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user