Overlay timer on time mode sharing

This commit is contained in:
Lonami Exo 2017-05-14 17:44:50 +02:00
parent 47f07f056c
commit c962128753
4 changed files with 22 additions and 8 deletions

View file

@ -27,7 +27,7 @@ public abstract class ShareChallenge {
public abstract void shareScreenshot(final boolean saveResult); public abstract void shareScreenshot(final boolean saveResult);
// Saves the "Challenge me" shareable image to getShareImageFilePath() // Saves the "Challenge me" shareable image to getShareImageFilePath()
public boolean saveChallengeImage(final int score) { public boolean saveChallengeImage(final int score, final boolean timeMode) {
final File saveAt = getShareImageFilePath(); final File saveAt = getShareImageFilePath();
if (!saveAt.getParentFile().isDirectory()) if (!saveAt.getParentFile().isDirectory())
if (!saveAt.mkdirs()) if (!saveAt.mkdirs())
@ -66,6 +66,12 @@ public abstract class ShareChallenge {
label.setPosition(40, 40); label.setPosition(40, 40);
label.draw(batch, 1); label.draw(batch, 1);
if (timeMode) {
Texture timeModeTexture = new Texture("ui/x1.5/stopwatch.png");
batch.setColor(Color.BLACK);
batch.draw(timeModeTexture, 200, 340);
}
batch.end(); batch.end();
// Get the framebuffer pixels and write them to a local file // Get the framebuffer pixels and write them to a local file

View file

@ -121,13 +121,13 @@ class GameScreen implements Screen, InputProcessor, BinSerializable {
return true; return true;
} }
private void doGameOver(String gameOverReason) { private void doGameOver(final String gameOverReason) {
if (!gameOverDone) { if (!gameOverDone) {
gameOverDone = true; gameOverDone = true;
saveMoney(); saveMoney();
holder.enabled = false; holder.enabled = false;
pauseMenu.showGameOver(gameOverReason); pauseMenu.showGameOver(gameOverReason, scorer instanceof TimeScorer);
if (Klooni.soundsEnabled()) if (Klooni.soundsEnabled())
gameOverSound.play(); gameOverSound.play();
@ -167,6 +167,8 @@ class GameScreen implements Screen, InputProcessor, BinSerializable {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
if (scorer.isGameOver() && !pauseMenu.isShown()) { if (scorer.isGameOver() && !pauseMenu.isShown()) {
// TODO A bit hardcoded (timeOver = scorer instanceof TimeScorer)
// Perhaps have a better mode to pass the required texture to overlay
doGameOver(scorer.gameOverReason()); doGameOver(scorer.gameOverReason());
} }

View file

@ -148,15 +148,16 @@ class PauseMenuStage extends Stage {
addAction(Actions.moveTo(0, 0, 0.75f, Interpolation.swingOut)); addAction(Actions.moveTo(0, 0, 0.75f, Interpolation.swingOut));
} }
void showGameOver(final String gameOverReason) { void showGameOver(final String gameOverReason, final boolean timeMode) {
if (game.shareChallenge != null) { if (game.shareChallenge != null) {
playButton.removeListener(playChangeListener); playButton.removeListener(playChangeListener);
playButton.updateImage("share_texture"); playButton.updateImage("share_texture");
playButton.addListener(new ChangeListener() { playButton.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
// Don't dispose because then it needs to take us to the previous screen // Don't dispose because then it needs to take us to the previous screen
game.transitionTo(new ShareScoreScreen( game.transitionTo(new ShareScoreScreen(
game, game.getScreen(), scorer.getCurrentScore()), false); game, game.getScreen(), scorer.getCurrentScore(), timeMode), false);
} }
}); });
} }

View file

@ -36,17 +36,22 @@ class ShareScoreScreen implements Screen {
private final Label infoLabel; private final Label infoLabel;
private final SpriteBatch spriteBatch; private final SpriteBatch spriteBatch;
private final Screen lastScreen;
private final int score; private final int score;
private final boolean timeMode;
private final Screen lastScreen;
//endregion //endregion
//region Constructor //region Constructor
ShareScoreScreen(final Klooni game, final Screen lastScreen, final int score) { ShareScoreScreen(final Klooni game, final Screen lastScreen,
final int score, final boolean timeMode) {
this.game = game; this.game = game;
this.lastScreen = lastScreen; this.lastScreen = lastScreen;
this.score = score; this.score = score;
this.timeMode = timeMode;
final Label.LabelStyle labelStyle = new Label.LabelStyle(); final Label.LabelStyle labelStyle = new Label.LabelStyle();
labelStyle.font = game.skin.getFont("font_small"); labelStyle.font = game.skin.getFont("font_small");
@ -76,7 +81,7 @@ class ShareScoreScreen implements Screen {
@Override @Override
public void show() { public void show() {
final boolean ok = game.shareChallenge.saveChallengeImage(score); final boolean ok = game.shareChallenge.saveChallengeImage(score, timeMode);
game.shareChallenge.shareScreenshot(ok); game.shareChallenge.shareScreenshot(ok);
goBack(); goBack();
} }