Skip to content
Snippets Groups Projects
Commit 9de9934b authored by Matyáš Latner's avatar Matyáš Latner
Browse files

#7 Victory screens rating stars

parent 7040570b
Branches
Tags
No related merge requests found
core/assets/common/application/victoryscreen/ratingstar_disabled.png

10.4 KiB

core/assets/common/application/victoryscreen/ratingstar_enabled.png

7.66 KiB

......@@ -6,7 +6,12 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Cell;
import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Stack;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import java.util.List;
......@@ -21,6 +26,7 @@ import cz.nic.tablexia.util.ui.dialog.TwoButtonDialog;
import cz.nic.tablexia.util.ui.dialog.text.DialogTextContent;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.alpha;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.delay;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.fadeIn;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.fadeOut;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.run;
......@@ -33,6 +39,8 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
private static final int SCREEN_TRANSACTION_FADE_DELAY = 1;
public static final String VICTORYSCREEN_RESULTSBANNER = "application/victoryscreen/resultsbanner.png";
public static final String VICTORYSCREEN_RATINGSTAR_DISABLED = "application/victoryscreen/ratingstar_disabled.png";
public static final String VICTORYSCREEN_RATINGSTAR_ENABLED = "application/victoryscreen/ratingstar_enabled.png";
private RandomAccess randomAccess;
private GameDifficulty gameDifficulty;
......@@ -66,6 +74,8 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
@Override
protected final void prepareScreenTextureAssetNames(List<String> textureFileNames) {
textureFileNames.add(VICTORYSCREEN_RESULTSBANNER);
textureFileNames.add(VICTORYSCREEN_RATINGSTAR_DISABLED);
textureFileNames.add(VICTORYSCREEN_RATINGSTAR_ENABLED);
prepareGameTextureAssetNames(textureFileNames);
}
......@@ -112,12 +122,18 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
private final float DIALOG_POSITION_X = (AbstractTablexiaGame.this.getStage().getWidth() / 2) - (DIALOG_WIDTH / 2);
private final float DIALOG_POSITION_Y = (AbstractTablexiaGame.this.getStage().getHeight() / 2) - (DIALOG_HEIGHT / 2);
private class VitoryDialog extends TwoButtonDialog {
private class VictoryDialog extends TwoButtonDialog {
public static final int RATINGSTARS_COUNT = 3;
public static final float RATINGSTAR_DELAY = 0.75f;
public static final float RESULTSBANNER_WIDTH_RATIO = 2f / 3;
public static final float RESULTSBANNER_TOPPADDING_RATIO = 1f / 30;
public static final float RATINGSTAR_HEIGHT_RATIO = 1f / 8;
Image[] ratingStarsEnabled;
public VitoryDialog() {
public VictoryDialog() {
super(DIALOG_POSITION_X,
DIALOG_POSITION_Y,
DIALOG_WIDTH,
......@@ -136,10 +152,58 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
Image resultsBanner = new Image(getTexture(VICTORYSCREEN_RESULTSBANNER));
float resultBannerWidth = getWidth() * RESULTSBANNER_WIDTH_RATIO;
float resultsBannerSizeRatio = resultBannerWidth / resultsBanner.getWidth();
getContentTable().add(resultsBanner).width(resultBannerWidth).height(resultsBanner.getHeight() * resultsBannerSizeRatio).padTop(getHeight() * RESULTSBANNER_TOPPADDING_RATIO).center().row();
getContentTable().add(resultsBanner).width(resultBannerWidth).height(resultsBanner.getHeight() * resultsBannerSizeRatio).padTop(getHeight() * RESULTSBANNER_TOPPADDING_RATIO).center().colspan(3);
// RATING STARS
getContentTable().row();
Table ratingStarTable = new Table();
ratingStarsEnabled = new Image[RATINGSTARS_COUNT];
for (int i = 0; i < RATINGSTARS_COUNT; i++) {
createRatingStar(i, ratingStarTable);
}
getContentTable().add(ratingStarTable).center();
getContentTable().row();
getContentTable().add(new Actor()).expand();
}
private void createRatingStar(int starNumber, Table ratingStartTable) {
Stack ratingStack = new Stack();
Image ratingStarDisabled = new Image(getTexture(VICTORYSCREEN_RATINGSTAR_DISABLED));
Image ratingStarEnabled = new Image(getTexture(VICTORYSCREEN_RATINGSTAR_ENABLED));
ratingStarEnabled.setVisible(false);
ratingStarsEnabled[starNumber] = ratingStarEnabled;
ratingStack.add(ratingStarDisabled);
ratingStack.add(ratingStarEnabled);
float ratingStarHeight = getWidth() * RATINGSTAR_HEIGHT_RATIO;
float ratingStarSizeRatio = ratingStarHeight / ratingStarDisabled.getHeight();
Cell<Stack> cell = ratingStartTable.add(ratingStack);
cell.height(ratingStarHeight).width(ratingStarDisabled.getWidth() * ratingStarSizeRatio);
}
public Dialog show(int score, Stage stage) {
if (score < 0 || score > RATINGSTARS_COUNT) {
throw new IllegalArgumentException("Invalid score value: " + score);
}
super.show(stage);
for (int i = 0; i < score; i++) {
final Image ratingStarEnabled = ratingStarsEnabled[i];
addAction(sequence(delay((i + 1) * RATINGSTAR_DELAY), run(new Runnable() {
@Override
public void run() {
ratingStarEnabled.setVisible(true);
}
})));
}
return this;
}
@Override
protected void leftButtonAction() {
}
......@@ -158,8 +222,8 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
return gameDifficulty;
}
public void gameComplete() {
(new VitoryDialog()).show(getStage());
public void gameComplete(int score) {
(new VictoryDialog()).show(score, getStage());
}
private void startNewGame() {
......
......@@ -382,6 +382,6 @@ public class RobberyScreen extends AbstractTablexiaGame<GameRule> {
}
static void gameRobberyComplete() {
instance.gameComplete();
instance.gameComplete(2);
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment