Commit 3e6a99ef authored by Matyáš Latner's avatar Matyáš Latner

Merge branch 'feature-ranksystem-merge' into V3.2.1

parents 20839978 20c4fc8c
......@@ -25,6 +25,7 @@ import net.engio.mbassy.listener.Handler;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
......@@ -215,6 +216,8 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
private ArrayList<TablexiaComponentDialog> receivedTrophyDialogs;
private TablexiaComponentDialog victoryDialog;
private RankAnimation rankAnimation;
private LinkedList<ExperienceStar> experienceStars;
private static TablexiaButton debugEndGameButton;
......@@ -872,6 +875,7 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
@Override
public void clicked(InputEvent event, float x, float y) {
clearReceivedTrophyDialogs();
hideVictoryDialogAndStars();
goToGameMenuGamePage();
}
},
......@@ -917,14 +921,6 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
}
});
adapters.add(new BackButtonHideComponent() {
@Override
protected void hideDialog() {
super.hideDialog();
backButtonPressed();
}
});
//Create the dialog
victoryDialog = TablexiaComponentDialogFactory.getInstance().createDialog(
adapters.toArray(new TablexiaDialogComponentAdapter[]{}));
......@@ -1036,7 +1032,7 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
screenState.put(HallOfFameScreen.SCROLL_TO_TROPHY_KEY, trophyDefinition.name());
ApplicationBus.getInstance().post(new Tablexia.ChangeScreenEvent(HallOfFameScreen.class, TablexiaApplication.ScreenTransaction.FADE, screenState)).asynchronously();
victoryDialog.hide();
hideVictoryDialogAndStars();
clearReceivedTrophyDialogs();
}
return false;
......@@ -1065,17 +1061,26 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
}
components.add(new FixedSpaceContentDialogComponent());
components.add(new BackButtonHideComponent());
TablexiaComponentDialog tcd = TablexiaComponentDialogFactory.getInstance().createDialog(
TablexiaComponentDialog.TablexiaDialogType.DIALOG_SQUARE,
components.toArray(new TablexiaDialogComponentAdapter[]{}));
receivedTrophyDialogs.add(tcd);
}
private void hideVictoryDialogAndStars() {
if(victoryDialog != null) victoryDialog.hide();
if(experienceStars != null) {
for(ExperienceStar star : experienceStars) star.hide();
}
}
private void clearReceivedTrophyDialogs() {
if(receivedTrophyDialogs == null) return;
for (TablexiaComponentDialog dialog : receivedTrophyDialogs) {
dialog.hide();
if(dialog != null) dialog.hide();
}
receivedTrophyDialogs.clear();
......@@ -1091,6 +1096,8 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
}
public static class ExperienceStar extends Image {
private static final float FADE_OUT_DURATION = 0.5f;
private Vector2 relativeEndPosition;
private ExperienceStarListener listener;
......@@ -1158,6 +1165,10 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
public void setStarListener(ExperienceStarListener starListener) {
this.listener = starListener;
}
public void hide() {
this.addAction(new SequenceAction(Actions.fadeOut(FADE_OUT_DURATION), Actions.removeActor()));
}
}
private void animateProgressBarAndExperienceStars(Image[] cupsImages, final GameDifficulty gameDifficulty, final UserRankManager.RankProgress rankProgress, final TablexiaProgressBar progressBar) {
Vector2 progressBarStagePosition = progressBar.localToStageCoordinates(new Vector2(0, progressBar.getHeight() / 2));
......@@ -1166,6 +1177,9 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
int starCountPerCup = gameDifficulty.getExperiencePointsMultiplier();
if(experienceStars == null) experienceStars = new LinkedList<ExperienceStar>();
experienceStars.clear();
//Listener for all stars...
final ExperienceStarListener starListener = new ExperienceStarListener() {
@Override
......@@ -1234,13 +1248,15 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
gameRankProgress.setCurrXP(gameRankProgress.getCurrXP() + 1);
TablexiaComponentDialogFactory.getDialogStage().addActor(experienceStar);
experienceStars.add(experienceStar);
}
}
}
public void onRankUp(UserRankManager.UserRank previousRank, UserRankManager.UserRank newRank) {
final Stage dialogStage = TablexiaComponentDialogFactory.getDialogStage();
final RankAnimation rankAnimation = RankAnimation.createRankAnimation(
rankAnimation = RankAnimation.createRankAnimation(
dialogStage,
previousRank,
newRank
......@@ -1276,7 +1292,7 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
private void hideDialogsAndChangeScreen(Class<? extends AbstractTablexiaScreen<?>> screen, TablexiaApplication.ScreenTransaction screenTransaction) {
ApplicationBus.getInstance().post(new Tablexia.ChangeScreenEvent(screen, screenTransaction)).asynchronously();
victoryDialog.hide();
hideVictoryDialogAndStars();
clearReceivedTrophyDialogs();
}
......@@ -1361,11 +1377,17 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
//////////////////////////// BACK BUTTON CALLBACK
@Override
public void backButtonPressed() {
goToGameMenuGamePage();
if(rankAnimation != null && !rankAnimation.isHidden())
rankAnimation.hide();
else {
hideVictoryDialogAndStars();
clearReceivedTrophyDialogs();
goToGameMenuGamePage();
}
}
//////////////////////////// GAME SCORE
public <T> void setGameScore(String key, T value) {
......
......@@ -63,6 +63,8 @@ public class RankAnimation extends Group {
private final Group shinesGroup;
private final UserRankManager.UserRank oldRank, newRank;
private boolean hidden = true;
private RankAnimation(float width, float height, UserRankManager.UserRank oldRank, UserRankManager.UserRank newRank) {
setSize(width, height);
this.oldRank = oldRank;
......@@ -213,6 +215,8 @@ public class RankAnimation extends Group {
////////////////////////////////
public void hide() {
hidden = true;
this.addAction(new SequenceAction(
Actions.fadeOut(HIDE_FADEOUT_DURATION),
Actions.removeActor()
......@@ -221,9 +225,11 @@ public class RankAnimation extends Group {
public void show() {
if(getStage() == null) {
Log.err(getClass(), "Couldn't show Rank Animation, because there is not stage!");
Log.err(getClass(), "Couldn't show Rank Animation, because there is no stage!");
}
hidden = false;
this.addAction(new SequenceAction(
Actions.fadeIn(SHOW_FADEIN_DURATION),
Actions.run(new Runnable() {
......@@ -235,6 +241,10 @@ public class RankAnimation extends Group {
));
}
public boolean isHidden() {
return hidden;
}
public void setNewBadgeEventListener(EventListener eventListener) {
if(eventListener == null) return;
......
......@@ -36,7 +36,7 @@ public class UserTrophy {
public static class AllGamesInOneDay implements UserTrophyResolver {
public static final String ALL_IN_ONE_DAY_SELECT = "SELECT game_number, end_time FROM game WHERE user_id = ? AND end_time IS NOT NULL";
public static final String ALL_IN_ONE_DAY_SELECT = "SELECT game_number, end_time FROM game WHERE user_id = ? AND end_time IS NOT NULL AND difficulty_number != 0";
@Override
public boolean hasGameTrophy(User user, UserTrophyDefinition trophyDef) {
......
Markdown is supported
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