Commit 8be19bf7 authored by Matyáš Latner's avatar Matyáš Latner

#75 Game quit warning dialog

parent 08a293c4
......@@ -3,6 +3,8 @@ language_czech=Čeština
language_slovak=Slovenština
language_german=Němčina
system_confirm=Ano
system_decline=Ne
system_exit=Konec
system_retry=Znovu
......@@ -40,6 +42,7 @@ game_score_duration=Trvání hry:
game_averagescore=Průměrný počet bodů:
game_averagescore_error=Průměrný počet chyb:
game_averagescore_duration=Průměrné trvání hry:
game_quit_question=Opravdu chceš ukončit hru?
game_robbery_title=Lupiči
game_robbery_description=Procvičování pracovní paměti
......
......@@ -3,6 +3,8 @@ language_czech=Tschechisch
language_slovak=Slowakisch
language_german=Deutsch
system_confirm=Ja
system_decline=Nein
system_exit=Verlassen
system_retry=Wieder
......@@ -40,6 +42,7 @@ game_score_duration=Spieldauer:
game_averagescore=Durchschnittliche Punktzahl:
game_averagescore_error=Durchschnittliche Fehlerzahl:
game_averagescore_duration=Durchschnittliche Spieldauer:
game_quit_question=Zkontrolovat: Wollen Sie wirklich, um das Spiel zu beenden?
game_robbery_title=Einbrecher
game_robbery_description=Training des Arbeitsgedächtnisses
......
......@@ -3,6 +3,8 @@ language_czech=Čeština
language_slovak=Slovenčina
language_german=Nemčina
system_confirm=Áno
system_decline=Nie
system_exit=Koniec
system_retry=Znovu
......@@ -40,6 +42,7 @@ game_score_duration=Trvanie hry:
game_averagescore=Priemerný počet bodov:
game_averagescore_error=Priemerný počet chýb:
game_averagescore_duration=Priemerné trvanie hry:
game_quit_question=Naozaj chceš ukončiť hru?
game_robbery_title=Lupiči
game_robbery_description=Precvičovanie pracovnej pamäti
......
......@@ -23,6 +23,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import net.engio.mbassy.listener.Handler;
......@@ -30,18 +31,23 @@ import net.engio.mbassy.listener.Handler;
import cz.nic.tablexia.bus.ApplicationBus;
import cz.nic.tablexia.bus.ApplicationBus.ApplicationEvent;
import cz.nic.tablexia.bus.event.DimmerControlEvent;
import cz.nic.tablexia.bus.event.MenuControlEvent;
import cz.nic.tablexia.debug.DebugInfo;
import cz.nic.tablexia.loader.TablexiaAbstractFileManager;
import cz.nic.tablexia.loader.TablexiaAtlasManager;
import cz.nic.tablexia.loader.application.ApplicationAtlasManager;
import cz.nic.tablexia.loader.application.ApplicationFontManager;
import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.menu.AbstractMenu;
import cz.nic.tablexia.menu.MenuController;
import cz.nic.tablexia.menu.main.MainMenu;
import cz.nic.tablexia.screen.AbstractTablexiaScreen;
import cz.nic.tablexia.screen.AbstractTablexiaScreen.ScreenLoadingListener;
import cz.nic.tablexia.util.Log;
import cz.nic.tablexia.util.ui.TablexiaButton;
import cz.nic.tablexia.util.ui.dialog.TablexiaDialog;
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.fadeIn;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.fadeOut;
......@@ -489,50 +495,134 @@ public abstract class TablexiaApplication implements ApplicationListener {
* @param screenTransaction screen transaction type
*/
public void setScreen(final AbstractTablexiaScreen<?> newScreen, final ScreenTransaction screenTransaction) {
screenPrepared = false;
if (screenTransaction == null) {
setScreen(newScreen);
Runnable newScreenAction = new Runnable() {
@Override
public void run() {
screenPrepared = false;
if (screenTransaction == null) {
setScreen(newScreen);
} else {
// for case there is incomplete transaction
processLastScreen();
lastScreen = screen;
screen = newScreen;
screenTransaction.processTransaction(lastScreen, newScreen,
new Runnable() {
@Override
public void run() {
processNewScreen(screen);
}
},
new Runnable() {
@Override
public void run() {
processLastScreen();
}
},
new Runnable() {
@Override
public void run() {
processScreenVisible(screen);
}
},
new Runnable() {
@Override
public void run() {
processStartLoading(newScreen, screenTransaction);
}
},
new Runnable() {
@Override
public void run() {
processLoadingComplete(screenTransaction);
}
});
}
}
};
QuitConfirmDialog quitConfirmDialog = screen.hasQuitConfirmDialog();
if (quitConfirmDialog != null) {
quitConfirmDialog.show(getStage(), newScreenAction);
} else {
// for case there is incomplete transaction
processLastScreen();
newScreenAction.run();
}
}
lastScreen = screen;
screen = newScreen;
screenTransaction.processTransaction(lastScreen, newScreen,
public static class QuitConfirmDialog extends TwoButtonDialog {
new Runnable() {
private static final float HEIGHT_RATIO = 2f / 5;
private static final float WIDTH_RATIO = 5f / 4;
private static final float BUTTON_WIDTH_RATIO = 1f / 3;
private static final int BUTTON_TEXT_ALIGN = Align.center;
private static final ApplicationFontManager.FontType TEXT_FONT_SIZE = ApplicationFontManager.FontType.ROBOTO_REGULAR_18;
@Override
public void run() {
processNewScreen(screen);
}
},
private Runnable action;
new Runnable() {
@Override
public void run() {
processLastScreen();
}
},
public QuitConfirmDialog(DialogTextContent dialogTextContent) {
super(0, 0, 0, 0,
BackGroundType.DIALOG_SQUARE_BORDERLINES,
dialogTextContent,
TablexiaButton.ButtonType.RED,
TablexiaButton.ButtonType.GREEN,
ApplicationTextManager.getInstance().getText(ApplicationTextManager.ApplicationTextsAssets.SYSTEM_DECLINE),
ApplicationTextManager.getInstance().getText(ApplicationTextManager.ApplicationTextsAssets.SYSTEM_CONFIRM));
}
new Runnable() {
@Override
public void run() {
processScreenVisible(screen);
}
},
public final Dialog show(Stage stage, Runnable action) {
float height = TablexiaSettings.getViewportHeight(stage) * HEIGHT_RATIO;
float width = height * WIDTH_RATIO;
setBounds(TablexiaSettings.getViewportWidth(stage) / 2 - width / 2,
TablexiaSettings.getViewportHeight(stage) / 2 - height / 2,
width,
height);
getBackground().setMinWidth(width);
getBackground().setMinHeight(height);
new Runnable() {
@Override
public void run() {processStartLoading(newScreen, screenTransaction);
}
},
new Runnable() {
@Override
public void run() { processLoadingComplete(screenTransaction);
}
});
this.action = action;
ApplicationBus.getInstance().post(new MenuControlEvent(MainMenu.class, AbstractMenu.MenuAction.OPEN, true)).asynchronously();
return super.show(stage);
}
@Override
protected ApplicationFontManager.FontType prepareContentFontSize() {
return TEXT_FONT_SIZE;
}
protected float getButtonWidth() {
return getWidth() * BUTTON_WIDTH_RATIO;
}
protected float getButtonHeight() {
return getButtonWidth() * BUTTON_HEIGHT_RATIO;
}
@Override
protected int getTextAlignment() {
return BUTTON_TEXT_ALIGN;
}
@Override
protected final void leftButtonAction() {
hide();
}
@Override
protected final void rightButtonAction() {
if (action != null) {
action.run();
}
hide();
}
}
......
......@@ -48,6 +48,7 @@ import cz.nic.tablexia.screen.halloffame.trophy.TrophyHelper;
import cz.nic.tablexia.util.Log;
import cz.nic.tablexia.util.ui.TablexiaButton;
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.delay;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.run;
......@@ -111,12 +112,13 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
private static final String RATINGSTAR3_SOUND = GAME_GLOBAL_PATH + "victoryscreen_star3.mp3";
private static final String VICTORY_DIALOG_SHOW_SOUND = GAME_GLOBAL_PATH + "victoryscreen_show.mp3";
public static final String VICTORY_DIALOG_RESULTSBANNER = "resultsbanner";
public static final String VICTORY_DIALOG_RATINGSTAR_DISABLED = "ratingstar_disabled";
public static final String VICTORY_DIALOG_RATINGSTAR_ENABLED = "ratingstar_enabled";
public static final String VICTORY_DIALOG_SUMMARY_ICON_STATS = "stats";
public static final String VICTORY_DIALOG_SUMMARY_ICON_TIME = "time";
private static final String VICTORY_DIALOG_TUTORIAL_TEXT = "victoryscreen_text_tutorial";
public static final String VICTORY_DIALOG_RESULTSBANNER = "resultsbanner";
public static final String VICTORY_DIALOG_RATINGSTAR_DISABLED = "ratingstar_disabled";
public static final String VICTORY_DIALOG_RATINGSTAR_ENABLED = "ratingstar_enabled";
public static final String VICTORY_DIALOG_SUMMARY_ICON_STATS = "stats";
public static final String VICTORY_DIALOG_SUMMARY_ICON_TIME = "time";
private static final String VICTORY_DIALOG_TUTORIAL_TEXT = "victoryscreen_text_tutorial";
private static final String QUIT_DIALOG_WARNING = "quitdialog_warning";
private static final Color VICTORY_DIALOG_BUTTON_TEXT_FONT_COLOR = Color.BLACK;
private static final ApplicationFontManager.FontType VICTORY_DIALOG_BUTTON_TEXT_FONT_TYPE = ApplicationFontManager.FontType.ROBOTO_BOLD_14;
......@@ -144,7 +146,32 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
}
//////////////////////////// LOADER
//////////////////////////// QUIT CONFIRMATION
private class GameQuitConfirmDialog extends TablexiaApplication.QuitConfirmDialog {
private static final float WARNING_IMAGE_TOP_PADDING_RATIO = 1f / 10;
public GameQuitConfirmDialog() {
super(new DialogTextContent(ApplicationTextManager.getInstance().getText(ApplicationTextManager.ApplicationTextsAssets.GAME_QUIT_QUESTION)));
}
@Override
protected void prepareContent() {
Image warningImage = new Image(getGameGlobalTextureRegion(QUIT_DIALOG_WARNING));
getContentTable().add(warningImage).padTop(getHeight() * WARNING_IMAGE_TOP_PADDING_RATIO);
getContentTable().row();
super.prepareContent();
}
}
@Override
public TablexiaApplication.QuitConfirmDialog hasQuitConfirmDialog() {
return new GameQuitConfirmDialog();
}
//////////////////////////// PRELOADER
@Override
public boolean hasPreloader() {
......
......@@ -29,6 +29,8 @@ public class ApplicationTextManager extends TablexiaDataManager<I18NBundle> impl
public static final String PRELOADER_TITLE = "preloader_title";
public static final String CONFIRM_BUTTON = "confirm_button";
public static final String SYSTEM_CONFIRM = "system_confirm";
public static final String SYSTEM_DECLINE = "system_decline";
public static final String SYSTEM_EXIT = "system_exit";
public static final String SYSTEM_RETRY = "system_retry";
......@@ -77,6 +79,7 @@ public class ApplicationTextManager extends TablexiaDataManager<I18NBundle> impl
public static final String GAME_AVERAGE_SCORE = "game_averagescore";
public static final String GAME_AVERAGE_SCORE_ERROR = "game_averagescore_error";
public static final String GAME_AVERAGE_SCORE_DURATION = "game_averagescore_duration";
public static final String GAME_QUIT_QUESTION = "game_quit_question";
}
private static final String APPLICATION_TEXT_RESOURCE_FILE = "text/application/application";
......
......@@ -47,6 +47,7 @@ import cz.nic.tablexia.util.Log;
import cz.nic.tablexia.util.ScaleUtil;
import cz.nic.tablexia.util.Utility;
import cz.nic.tablexia.util.ui.XFillViewport;
import cz.nic.tablexia.util.ui.dialog.TablexiaDialog;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.moveTo;
......@@ -305,6 +306,13 @@ public abstract class AbstractTablexiaScreen<T> extends ScreenAdapter {
}
//////////////////////////// QUIT CONFIRMATION
public TablexiaApplication.QuitConfirmDialog hasQuitConfirmDialog() {
return null;
}
//////////////////////////// PRELOADER
private static final String PRELOADER_DEFAULT_ASSETS_PATH = "_preloader/";
......
......@@ -30,13 +30,18 @@ public abstract class AbstractButtonDialog extends TextDialog {
if (textButton != null) {
textButton.addListener(clickListener);
float buttonWidth = getWidth() * BUTTON_WIDTH_RATIO_TO_DIALOG_WIDTH;
float buttonHeight = buttonWidth * BUTTON_HEIGHT_RATIO;
button(textButton);
getButtonTable().getCell(textButton).width(buttonWidth).height(buttonHeight).spaceLeft(buttonWidth / 3);
getButtonTable().getCell(textButton).width(getButtonWidth()).height(getButtonHeight()).spaceLeft(getButtonWidth() / 4);
} else {
throw new IllegalArgumentException("Invalid dialog type. Buttons not supported for this type.");
}
}
protected float getButtonWidth() {
return getWidth() * BUTTON_WIDTH_RATIO_TO_DIALOG_WIDTH;
}
protected float getButtonHeight() {
return getButtonWidth() * BUTTON_HEIGHT_RATIO;
}
}
......@@ -15,6 +15,8 @@ import cz.nic.tablexia.util.ui.dialog.text.DialogTextContent;
*/
public class TextDialog extends TablexiaDialog {
private static final ApplicationFontManager.FontType DEFAULT_FONT_SIZE = ApplicationFontManager.FontType.ROBOTO_REGULAR_14;
private DialogTextContent dialogTextContent;
public TextDialog(float x, float y, float width, float height, BackGroundType backGroundType, DialogTextContent dialogTextContent) {
......@@ -33,10 +35,14 @@ public class TextDialog extends TablexiaDialog {
addLabel(dialogTextContent.getTitle(), ApplicationFontManager.getInstance().getFont(ApplicationFontManager.FontType.ROBOTO_BOLD_16));
getContentTable().row();
}
addLabel(dialogTextContent.getContent(), ApplicationFontManager.getInstance().getFont(ApplicationFontManager.FontType.ROBOTO_REGULAR_14)).center().expand().top().fillX().fillY();
addLabel(dialogTextContent.getContent(), ApplicationFontManager.getInstance().getFont(prepareContentFontSize())).center().expand().top().fillX().fillY();
}
}
protected ApplicationFontManager.FontType prepareContentFontSize() {
return DEFAULT_FONT_SIZE;
}
protected Cell<Label> addLabel(String text, BitmapFont font) {
return super.addLabel(text, new Label.LabelStyle(font, Color.BLACK), getTextAlignment());
}
......
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