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:
Jeffrey Han
2015-01-07 22:36:39 -05:00
parent 1e806bc9c6
commit 8671718ce3
5 changed files with 132 additions and 121 deletions

View File

@@ -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();

View File

@@ -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();
}
}
}