Add a nicer share screen

This commit is contained in:
Lonami Exo 2017-05-14 17:27:08 +02:00
parent acc80677fe
commit 17f3fe40e6
2 changed files with 126 additions and 12 deletions

View file

@ -1,10 +1,8 @@
package io.github.lonamiwebs.klooni.screens;
import com.badlogic.gdx.Application;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
@ -16,10 +14,7 @@ import com.badlogic.gdx.scenes.scene2d.actions.RunnableAction;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import java.io.File;
import io.github.lonamiwebs.klooni.Klooni;
import io.github.lonamiwebs.klooni.ShareChallenge;
import io.github.lonamiwebs.klooni.actors.Band;
import io.github.lonamiwebs.klooni.actors.SoftButton;
import io.github.lonamiwebs.klooni.game.BaseScorer;
@ -102,11 +97,7 @@ class PauseMenuStage extends Stage {
playButton = new SoftButton(2, "play_texture");
table.add(playButton).space(16);
playButton.addListener(new ChangeListener() {
public void changed (ChangeEvent event, Actor actor) {
hide();
}
});
playButton.addListener(playChangeListener);
}
//endregion
@ -131,6 +122,13 @@ class PauseMenuStage extends Stage {
scorer.resume();
}
private final ChangeListener playChangeListener = new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
hide();
}
};
//endregion
//region Package local methods
@ -152,11 +150,13 @@ class PauseMenuStage extends Stage {
void showGameOver(final String gameOverReason) {
if (game.shareChallenge != null) {
playButton.removeListener(playChangeListener);
playButton.updateImage("share_texture");
playButton.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
game.shareChallenge.shareScreenshot(
game.shareChallenge.saveChallengeImage(scorer.getCurrentScore()));
// Don't dispose because then it needs to take us to the previous screen
game.transitionTo(new ShareScoreScreen(
game, game.getScreen(), scorer.getCurrentScore()), false);
}
});
}

View file

@ -0,0 +1,114 @@
package io.github.lonamiwebs.klooni.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.Align;
import io.github.lonamiwebs.klooni.Klooni;
import io.github.lonamiwebs.klooni.Theme;
import io.github.lonamiwebs.klooni.actors.MoneyBuyBand;
import io.github.lonamiwebs.klooni.actors.SoftButton;
import io.github.lonamiwebs.klooni.actors.ThemeCard;
import io.github.lonamiwebs.klooni.game.GameLayout;
// Screen where the user can customize the look and feel of the game
class ShareScoreScreen implements Screen {
//region Members
private Klooni game;
private final Label infoLabel;
private final SpriteBatch spriteBatch;
private final Screen lastScreen;
private final int score;
//endregion
//region Constructor
ShareScoreScreen(final Klooni game, final Screen lastScreen, final int score) {
this.game = game;
this.lastScreen = lastScreen;
this.score = score;
final Label.LabelStyle labelStyle = new Label.LabelStyle();
labelStyle.font = game.skin.getFont("font_small");
infoLabel = new Label("Generating image...", labelStyle);
infoLabel.setColor(Klooni.theme.textColor);
infoLabel.setAlignment(Align.center);
infoLabel.layout();
infoLabel.setPosition(
(Gdx.graphics.getWidth() - infoLabel.getWidth()) * 0.5f,
(Gdx.graphics.getHeight() - infoLabel.getHeight()) * 0.5f);
spriteBatch = new SpriteBatch();
}
//endregion
//region Private methods
private void goBack() {
game.transitionTo(lastScreen);
}
//endregion
//region Public methods
@Override
public void show() {
final boolean ok = game.shareChallenge.saveChallengeImage(score);
game.shareChallenge.shareScreenshot(ok);
goBack();
}
@Override
public void render(float delta) {
Klooni.theme.glClearBackground();
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
spriteBatch.begin();
infoLabel.draw(spriteBatch, 1);
spriteBatch.end();
}
//endregion
//region Empty methods
@Override
public void resize(int width, int height) { }
@Override
public void dispose() { }
@Override
public void pause() { }
@Override
public void resume() { }
@Override
public void hide() { }
//endregion
}