Commit d1908074 authored by Matyáš Latner's avatar Matyáš Latner

#7 Victory screen basic dialog, dialog framework refactoring

parent 3f193235
......@@ -14,9 +14,12 @@ gamedifficulty_easy=Lehká
gamedifficulty_medium=Střední
gamedifficulty_hard=Těžká
victoryscreen_button_replay=Hrát znovu
victoryscreen_button_changegame=Jinou hru
game_robbery_title=Lupiči
game_kidnapping_title=Únos
game_pursuit_title=Pronásledování
game_night_watch_title=Hlídka
game_shooting_range_title=Střelnice
game_in_the_darkness_title=Potmě
\ No newline at end of file
game_in_the_darkness_title=Potmě
......@@ -14,6 +14,9 @@ gamedifficulty_easy=Ľahká
gamedifficulty_medium=Stredná
gamedifficulty_hard=Ťažká
victoryscreen_button_replay=Hráť znovu
victoryscreen_button_changegame=Inú hru
game_robbery_title=Lupiči
game_kidnapping_title=Únos
game_pursuit_title=Prenasledovanie
......
......@@ -11,8 +11,11 @@ import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.game.common.RandomAccess;
import cz.nic.tablexia.game.difficulty.GameDifficulty;
import cz.nic.tablexia.graphics.ColorTexture;
import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.screen.AbstractTablexiaScreen;
import cz.nic.tablexia.util.Log;
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.fadeIn;
......@@ -90,6 +93,36 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
//////////////////////////// ABSTRACT TABLEXIA GAME
private final float DIALOG_HEIGHT = AbstractTablexiaGame.this.getStage().getHeight() * (3f/4);
private final float DIALOG_WIDTH = DIALOG_HEIGHT * 1.2f;
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 {
public VitoryDialog() {
super(DIALOG_POSITION_X,
DIALOG_POSITION_Y,
DIALOG_WIDTH,
DIALOG_HEIGHT,
BackGroundType.DIALOG_SQUARE_BORDERLINES,
new DialogTextContent("TEXT"),
ButtonType.BLUE,
ButtonType.GREEN,
ApplicationTextManager.getInstance().getText(ApplicationTextManager.ApplicationTextsAssets.VICTORYSCREEN_BUTTON_CHANGEGAME),
ApplicationTextManager.getInstance().getText(ApplicationTextManager.ApplicationTextsAssets.VICTORYSCREEN_BUTTON_REPLAY));
}
@Override
protected void leftButtonAction() {
}
@Override
protected void rightButtonAction() {
startNewGame();
}
}
protected RandomAccess getRandomAccess() {
return randomAccess;
}
......@@ -99,8 +132,7 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
}
public void gameComplete() {
//TODO show results dialog
startNewGame();
(new VitoryDialog()).show(getStage());
}
private void startNewGame() {
......
......@@ -221,6 +221,7 @@ public class RobberyScreen extends AbstractTablexiaGame<GameRule> {
isRootScreenVisible = false;
isComponentScreenVisible = false;
inputMultiplexer = new InputMultiplexer();
inputMultiplexer.addProcessor(getStage());
}
@Override
......
......@@ -68,4 +68,12 @@ public class ApplicationFontManager extends AssetManager implements IApplication
public BitmapFont getFont(String fontName) {
return get(fontName, BitmapFont.class);
}
public BitmapFont getDefaultApplicationRegularFont() {
return getFont(APPLICATION_DEFAULT_FONT_REGULAR);
}
public BitmapFont getDefaultApplicationBoldFont() {
return getFont(APPLICATION_DEFAULT_FONT_BOLD);
}
}
\ No newline at end of file
......@@ -7,9 +7,8 @@ import com.badlogic.gdx.utils.async.AsyncTask;
import java.util.Locale;
import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.loader.TablexiaDataManager;
import cz.nic.tablexia.loader.IApplicationLoader;
import cz.nic.tablexia.loader.TablexiaDataManager;
/**
* Texture loader and manager for application context.
......@@ -18,6 +17,11 @@ import cz.nic.tablexia.loader.IApplicationLoader;
*
*/
public class ApplicationTextManager extends TablexiaDataManager<I18NBundle> implements IApplicationLoader {
public static final class ApplicationTextsAssets {
public static final String VICTORYSCREEN_BUTTON_REPLAY = "victoryscreen_button_replay";
public static final String VICTORYSCREEN_BUTTON_CHANGEGAME = "victoryscreen_button_changegame";
}
private static final String APPLICATION_TEXT_RESOURCE_FILE = "text/application/application";
......
......@@ -348,11 +348,11 @@ public abstract class AbstractTablexiaScreen<T> extends ScreenAdapter {
}
public BitmapFont getDefaultRegularFont() {
return ApplicationFontManager.getInstance().getFont(ApplicationFontManager.APPLICATION_DEFAULT_FONT_REGULAR);
return ApplicationFontManager.getInstance().getDefaultApplicationRegularFont();
}
public BitmapFont getDefaultBoldFont() {
return ApplicationFontManager.getInstance().getFont(ApplicationFontManager.APPLICATION_DEFAULT_FONT_BOLD);
return ApplicationFontManager.getInstance().getDefaultApplicationBoldFont();
}
public String getFormattedText(String key, Object... args) {
......
package cz.nic.tablexia.util.ui.dialog;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.NinePatch;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable;
import cz.nic.tablexia.loader.application.ApplicationFontManager;
import cz.nic.tablexia.util.ui.dialog.text.DialogTextContent;
/**
* Created by Václav Tarantík on 9.4.15.
*/
public abstract class AbstractButtonDialog extends TablexiaDialog {
private static final Color DEFAULT_BUTTON_TEXT_COLOR = Color.BLACK;
private static final BitmapFont DEFAULT_BUTTON_TEXT_FONT = ApplicationFontManager.getInstance().getDefaultApplicationRegularFont();
private static final String BTN_DISABLED_ATLAS_NAME = "tablexiabutton_disabled";
private static final float BUTTON_WIDTH_RATIO_TO_DIALOG_WIDTH = 0.3f;
private static final float BUTTON_HEIGHT_RATIO = 0.53f;
private static final float BUTTON_WIDTH_RATIO_TO_DIALOG_WIDTH = 0.27f;
private static final float BUTTON_HEIGHT_RATIO = 0.5f;
private static final String BTN_DRAWABLE_PRESSED_ENDING = "_pressed";
private static final String BTN_DRAWABLE_UNPRESSED_ENDING = "_unpressed";
......@@ -25,13 +29,9 @@ public abstract class AbstractButtonDialog extends TablexiaDialog {
super(x, y, width, height, backGroundType, dialogTextContent);
}
public void createButton(ButtonType buttonType, String buttonText,ClickListener clickListener){
public void createButton(ButtonType buttonType, String buttonText, ClickListener clickListener){
if(buttonType!=null){
// usikin.json is the system default skin used by libgdx
TextButton textButton = new TextButton(buttonText, new Skin(Gdx.files.internal("uiskin.json")));
NinePatch up = buttonAtlas.createPatch(buttonType.getButtonResourceName()+BTN_DRAWABLE_UNPRESSED_ENDING);
NinePatchDrawable npdUp = new NinePatchDrawable(up);
......@@ -41,12 +41,17 @@ public abstract class AbstractButtonDialog extends TablexiaDialog {
NinePatch dis = buttonAtlas.createPatch(BTN_DISABLED_ATLAS_NAME);
NinePatchDrawable npdDis = new NinePatchDrawable(dis);
textButton.setStyle(new TextButton.TextButtonStyle(npdUp, npdDown, npdDis, getStyle().titleFont));
TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle(npdUp, npdDown, npdDis, DEFAULT_BUTTON_TEXT_FONT);
textButtonStyle.fontColor = DEFAULT_BUTTON_TEXT_COLOR;
TextButton textButton = new TextButton(buttonText, textButtonStyle);
textButton.addListener(clickListener);
float buttonWidth = getPrefWidth()* BUTTON_WIDTH_RATIO_TO_DIALOG_WIDTH;
float buttonHeight = buttonWidth*BUTTON_HEIGHT_RATIO;
getButtonTable().add(textButton).width(buttonWidth).height(buttonHeight);
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);
}else{
throw new IllegalArgumentException("Invalid dialog type. Buttons not supported for this type.");
......
......@@ -4,8 +4,6 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import java.util.List;
import cz.nic.tablexia.util.ui.dialog.text.DialogTextContent;
/**
......@@ -18,10 +16,10 @@ public class ImageDialog extends TablexiaDialog {
super(x,y,width,height, backGroundType,dialogTextContent);
this.textures = textures;
prepareContent(dialogTextContent);
prepareContent();
}
private void prepareContent(DialogTextContent dialogTextContent){
private void prepareContent(){
getContentTable().row();
prepareImages();
}
......@@ -34,6 +32,6 @@ public class ImageDialog extends TablexiaDialog {
imageGroup.add(image).padBottom(20f);
imageGroup.row();
}
getContentTable().add(imageGroup).width(width/2);
getContentTable().add(imageGroup).width(getWidth() / 2);
}
}
package cz.nic.tablexia.util.ui.dialog;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.NinePatch;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable;
import cz.nic.tablexia.util.ui.dialog.text.DialogTextContent;
......
......@@ -2,14 +2,12 @@ package cz.nic.tablexia.util.ui.dialog;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.NinePatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable;
import cz.nic.tablexia.loader.application.ApplicationFontManager;
......@@ -21,15 +19,10 @@ import static com.badlogic.gdx.scenes.scene2d.actions.Actions.sequence;
* Created by Václav Tarantík on 17.3.15.
*/
public class TablexiaDialog extends Dialog {
protected static Skin skin;
public static TextureAtlas backgroundAtlas;
public static TextureAtlas buttonAtlas;
protected float width;
protected float height;
protected float x;
protected float y;
protected BackGroundType backGroundType;
protected DialogTextContent dialogTextContent;
public enum BackGroundType {
......@@ -46,11 +39,6 @@ public class TablexiaDialog extends Dialog {
BackGroundType(String dialogBackgroundTextureName){
this.dialogBackgroundTextureName = dialogBackgroundTextureName;
}
public String getDialogBackgroundTextureName(){
return dialogBackgroundTextureName;
}
}
public enum ButtonType{
......@@ -70,35 +58,30 @@ public class TablexiaDialog extends Dialog {
}
static {
//uiskin.json is libgdx system default skin
skin = new Skin(Gdx.files.internal("uiskin.json"));
backgroundAtlas = new TextureAtlas(Gdx.files.internal("atlases/dialog_background.atlas"));
buttonAtlas = new TextureAtlas(Gdx.files.internal("atlases/buttons_atlas.pack"));
}
public TablexiaDialog(float x, float y,float width,float height, BackGroundType backGroundType,DialogTextContent dialogTextContent) {
super("",skin);
super("", new WindowStyle(ApplicationFontManager.getInstance().getDefaultApplicationRegularFont(),
Color.BLACK,
new NinePatchDrawable(backgroundAtlas.createPatch(backGroundType.dialogBackgroundTextureName))));
setModal(true);
setMovable(false);
setResizable(false);
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.backGroundType = backGroundType;
this.dialogTextContent = dialogTextContent;
setBounds(x, y, width, height);
getBackground().setMinWidth(width);
getBackground().setMinHeight(height);
NinePatch np = backgroundAtlas.createPatch(backGroundType.dialogBackgroundTextureName);
NinePatchDrawable npd = new NinePatchDrawable(np);
setBackground(npd);
this.dialogTextContent = dialogTextContent;
prepareTextContent();
}
@Override
public Dialog show(Stage stage) {
show(stage, sequence(Actions.alpha(0), Actions.fadeIn(0.4f, Interpolation.fade)));
setBounds(x,y,width,height);
return this;
}
......
package cz.nic.tablexia.util.ui.dialog;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.NinePatch;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable;
import cz.nic.tablexia.util.ui.dialog.text.DialogTextContent;
......@@ -14,8 +9,8 @@ import cz.nic.tablexia.util.ui.dialog.text.DialogTextContent;
* Created by Václav Tarantík on 26.3.15.
*/
public abstract class TwoButtonDialog extends AbstractButtonDialog {
public TwoButtonDialog(float x, float y,float width, float height, BackGroundType backGroundType,DialogTextContent dialogTextContent, ButtonType leftButtonType, ButtonType rightButtonType,String leftButtonText, String rightButtonText) {
super(x,y,width, height, backGroundType,dialogTextContent);
public TwoButtonDialog(float x, float y, float width, float height, BackGroundType backGroundType,DialogTextContent dialogTextContent, ButtonType leftButtonType, ButtonType rightButtonType,String leftButtonText, String rightButtonText) {
super(x, y, width, height, backGroundType, dialogTextContent);
createButton(leftButtonType,leftButtonText,new ClickListener() {
@Override
......
......@@ -4,28 +4,25 @@ package cz.nic.tablexia.util.ui.dialog.text;
* Created by Václav Tarantík on 27.3.15.
*/
public class DialogTextContent {
private String title;
private String content;
public DialogTextContent(String title,String content){
public DialogTextContent(String content) {
this(null, content);
}
public DialogTextContent(String title, String content) {
this.title = title;
this.content = content;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
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