Allow challenging your friends on Android (closes #10)

This commit is contained in:
Lonami Exo 2017-05-07 10:54:32 +02:00
parent 5b942374e8
commit ac990ae05d
6 changed files with 91 additions and 10 deletions

View file

@ -21,6 +21,8 @@ public class Klooni extends Game {
public static Theme theme;
public Skin skin;
public ShareChallenge shareChallenge;
public static boolean onDesktop;
private final static float SCORE_TO_MONEY = 1f / 100f;
@ -32,6 +34,12 @@ public class Klooni extends Game {
//region Creation
// TODO Possibly implement a 'ShareChallenge'
// for other platforms instead passing null
public Klooni(final ShareChallenge shareChallenge) {
this.shareChallenge = shareChallenge;
}
@Override
public void create() {
onDesktop = Gdx.app.getType().equals(Application.ApplicationType.Desktop);

View file

@ -19,17 +19,21 @@ public class SoftButton extends ImageButton {
//region Constructor
public SoftButton(int styleIndex, String imageName) {
public SoftButton(final int styleIndex, final String imageName) {
super(Klooni.theme.getStyle(styleIndex));
this.styleIndex = styleIndex;
image = Theme.skin.getDrawable(imageName);
updateImage(imageName);
}
//endregion
//region Public methods
public void updateImage(final String imageName) {
image = Theme.skin.getDrawable(imageName);
}
@Override
public void draw(Batch batch, float parentAlpha) {
// Always update the style to make sure we're using the right image.

View file

@ -1,8 +1,10 @@
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.GL20;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Interpolation;
@ -13,7 +15,10 @@ 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;
@ -31,8 +36,10 @@ class PauseMenuStage extends Stage {
private final ShapeRenderer shapeRenderer;
private final Klooni game;
private final Band band;
private final BaseScorer scorer;
private final SoftButton playButton;
//endregion
@ -40,6 +47,7 @@ class PauseMenuStage extends Stage {
// We need the score to save the maximum score if a new record was beaten
PauseMenuStage(final GameLayout layout, final Klooni game, final BaseScorer scorer, final int gameMode) {
this.game = game;
this.scorer = scorer;
shapeRenderer = new ShapeRenderer(20); // 20 vertex seems to be enough for a rectangle
@ -90,8 +98,7 @@ class PauseMenuStage extends Stage {
});
// Continue playing OR share (if game over) button
// TODO Enable both actions for this button? Or leave play?
final SoftButton playButton = new SoftButton(2, "play_texture");
playButton = new SoftButton(2, "play_texture");
table.add(playButton).space(16);
playButton.addListener(new ChangeListener() {
@ -143,6 +150,16 @@ class PauseMenuStage extends Stage {
}
void showGameOver(final String gameOverReason) {
if (game.shareChallenge != null) {
playButton.updateImage("share_texture");
playButton.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
game.shareChallenge.shareScreenshot(
game.shareChallenge.saveChallengeImage(scorer.getCurrentScore()));
}
});
}
band.setMessage(gameOverReason);
show();
}