From 29872005666c0f3d7172675b6edbaf9822304680 Mon Sep 17 00:00:00 2001 From: "v.tarantik" <v.tarantik@gmail.com> Date: Fri, 24 Apr 2015 09:46:39 +0200 Subject: [PATCH] #20 Text dialog type, change of prepare dialog content strategy --- .../tablexia/game/AbstractTablexiaGame.java | 2 +- .../util/ui/dialog/AbstractButtonDialog.java | 4 +- .../tablexia/util/ui/dialog/ImageDialog.java | 23 +++++++----- .../util/ui/dialog/TablexiaDialog.java | 18 ++------- .../tablexia/util/ui/dialog/TextDialog.java | 37 +++++++++++++++++++ .../util/ui/dialog/TwoButtonDialog.java | 19 +++++++++- 6 files changed, 75 insertions(+), 28 deletions(-) create mode 100644 core/src/cz/nic/tablexia/util/ui/dialog/TextDialog.java diff --git a/core/src/cz/nic/tablexia/game/AbstractTablexiaGame.java b/core/src/cz/nic/tablexia/game/AbstractTablexiaGame.java index 63e9a9008..430e66010 100644 --- a/core/src/cz/nic/tablexia/game/AbstractTablexiaGame.java +++ b/core/src/cz/nic/tablexia/game/AbstractTablexiaGame.java @@ -147,7 +147,7 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T> } @Override - protected void prepareDialogContent() { + protected void prepareContent() { // RESULTS BANNER Image resultsBanner = new Image(getTexture(VICTORYSCREEN_RESULTSBANNER)); float resultBannerWidth = getWidth() * RESULTSBANNER_WIDTH_RATIO; diff --git a/core/src/cz/nic/tablexia/util/ui/dialog/AbstractButtonDialog.java b/core/src/cz/nic/tablexia/util/ui/dialog/AbstractButtonDialog.java index 7d73d7616..857bbf21a 100644 --- a/core/src/cz/nic/tablexia/util/ui/dialog/AbstractButtonDialog.java +++ b/core/src/cz/nic/tablexia/util/ui/dialog/AbstractButtonDialog.java @@ -12,7 +12,7 @@ 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 { +public abstract class AbstractButtonDialog extends TextDialog { private static final Color DEFAULT_BUTTON_TEXT_COLOR = Color.BLACK; private static final String DEFAULT_BUTTON_TEXT_FONT = ApplicationFontManager.APPLICATION_DEFAULT_FONT_REGULAR; @@ -25,7 +25,7 @@ public abstract class AbstractButtonDialog extends TablexiaDialog { private static final String BTN_DRAWABLE_UNPRESSED_ENDING = "_unpressed"; public AbstractButtonDialog(float x, float y, float width, float height, BackGroundType backGroundType, DialogTextContent dialogTextContent) { - super(x, y, width, height, backGroundType, dialogTextContent); + super(x, y, width, height, backGroundType,dialogTextContent); } public void createButton(ButtonType buttonType, String buttonText, ClickListener clickListener){ diff --git a/core/src/cz/nic/tablexia/util/ui/dialog/ImageDialog.java b/core/src/cz/nic/tablexia/util/ui/dialog/ImageDialog.java index a6dbedc21..9c729eac5 100644 --- a/core/src/cz/nic/tablexia/util/ui/dialog/ImageDialog.java +++ b/core/src/cz/nic/tablexia/util/ui/dialog/ImageDialog.java @@ -9,29 +9,34 @@ import cz.nic.tablexia.util.ui.dialog.text.DialogTextContent; /** * Created by Václav TarantĂk on 19.3.15. */ -public class ImageDialog extends TablexiaDialog { +public class ImageDialog extends TextDialog { + private Table imageTable; private Texture[] textures; public ImageDialog(float x, float y,float width, float height,BackGroundType backGroundType, DialogTextContent dialogTextContent,Texture... textures) { super(x,y,width,height, backGroundType,dialogTextContent); this.textures = textures; - - prepareContent(); + imageTable = new Table(); } - private void prepareContent(){ + protected void prepareContent(){ + super.prepareContent(); getContentTable().row(); prepareImages(); } private void prepareImages(){ - Table imageGroup = new Table(); for(Texture texture:textures){ - Image image = new Image(texture); - imageGroup.add(image).padBottom(20f); - imageGroup.row(); + addImage(texture); } - getContentTable().add(imageGroup).width(getWidth() / 2); + getContentTable().add(imageTable).width(getWidth() / 2).height(getHeight()/2); + } + + protected void addImage(Texture texture){ + Image image = new Image(texture); + imageTable.add(image).padBottom(20f); + imageTable.row(); } + } diff --git a/core/src/cz/nic/tablexia/util/ui/dialog/TablexiaDialog.java b/core/src/cz/nic/tablexia/util/ui/dialog/TablexiaDialog.java index 142160fb3..eff62ca0f 100644 --- a/core/src/cz/nic/tablexia/util/ui/dialog/TablexiaDialog.java +++ b/core/src/cz/nic/tablexia/util/ui/dialog/TablexiaDialog.java @@ -62,7 +62,7 @@ public class TablexiaDialog extends Dialog { buttonAtlas = new TextureAtlas(Gdx.files.internal("atlases/buttons_atlas.pack")); } - public TablexiaDialog(float x, float y,float width,float height, BackGroundType backGroundType,DialogTextContent dialogTextContent) { + public TablexiaDialog(float x, float y,float width,float height, BackGroundType backGroundType) { super("", new WindowStyle(ApplicationFontManager.getInstance().getDefaultApplicationRegularFont(), Color.BLACK, new NinePatchDrawable(backgroundAtlas.createPatch(backGroundType.dialogBackgroundTextureName)))); @@ -74,26 +74,16 @@ public class TablexiaDialog extends Dialog { setBounds(x, y, width, height); getBackground().setMinWidth(width); getBackground().setMinHeight(height); - - this.dialogTextContent = dialogTextContent; - prepareDialogContent(); } @Override public Dialog show(Stage stage) { + prepareContent(); show(stage, sequence(Actions.alpha(0), Actions.fadeIn(0.4f, Interpolation.fade))); return this; } - protected void prepareDialogContent(){ - Label.LabelStyle labelStyle = new Label.LabelStyle(ApplicationFontManager.getInstance().getFont(ApplicationFontManager.APPLICATION_DEFAULT_FONT_REGULAR),Color.BLACK); - if(dialogTextContent.getTitle() != null && !dialogTextContent.getTitle().equals("")){ - Label titleLabel = new Label(dialogTextContent.getTitle(),labelStyle); - getContentTable().add(titleLabel).center() ; - getContentTable().row(); - } - Label label = new Label(dialogTextContent.getContent(),labelStyle); - label.setWrap(true); - getContentTable().add(label).left().top().expand().fillX(); + protected void prepareContent(){ + //no content here } } \ No newline at end of file diff --git a/core/src/cz/nic/tablexia/util/ui/dialog/TextDialog.java b/core/src/cz/nic/tablexia/util/ui/dialog/TextDialog.java new file mode 100644 index 000000000..ccd69cbeb --- /dev/null +++ b/core/src/cz/nic/tablexia/util/ui/dialog/TextDialog.java @@ -0,0 +1,37 @@ +package cz.nic.tablexia.util.ui.dialog; + +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.scenes.scene2d.ui.Label; + +import cz.nic.tablexia.loader.application.ApplicationFontManager; +import cz.nic.tablexia.util.ui.dialog.text.DialogTextContent; + +/** + * Created by Václav TarantĂk on 24.4.15. + */ +public class TextDialog extends TablexiaDialog { + private static final float TITLE_FONT_SCALE = 0.7f; + private static final float CONTENT_FONT_SCALE = 0.5f; + private DialogTextContent dialogTextContent; + + public TextDialog(float x, float y, float width, float height, BackGroundType backGroundType, DialogTextContent dialogTextContent) { + super(x, y, width, height, backGroundType); + this.dialogTextContent = dialogTextContent; + } + + @Override + protected void prepareContent() { + Label.LabelStyle titleLabelStyle = new Label.LabelStyle(ApplicationFontManager.getInstance().getFont(ApplicationFontManager.APPLICATION_DEFAULT_FONT_BOLD), Color.BLACK); + titleLabelStyle.font.setScale(TITLE_FONT_SCALE); + if(dialogTextContent.getTitle() != null && !dialogTextContent.getTitle().equals("")){ + Label titleLabel = new Label(dialogTextContent.getTitle(),titleLabelStyle); + getContentTable().add(titleLabel).center() ; + getContentTable().row(); + } + Label.LabelStyle contentLabelStyle = new Label.LabelStyle(ApplicationFontManager.getInstance().getFont(ApplicationFontManager.APPLICATION_DEFAULT_FONT_REGULAR), Color.BLACK); + contentLabelStyle.font.setScale(CONTENT_FONT_SCALE); + Label label = new Label(dialogTextContent.getContent(),contentLabelStyle); + label.setWrap(true); + getContentTable().add(label).left().top().expand().fillX(); + } +} diff --git a/core/src/cz/nic/tablexia/util/ui/dialog/TwoButtonDialog.java b/core/src/cz/nic/tablexia/util/ui/dialog/TwoButtonDialog.java index df3861a3d..462f59bbe 100644 --- a/core/src/cz/nic/tablexia/util/ui/dialog/TwoButtonDialog.java +++ b/core/src/cz/nic/tablexia/util/ui/dialog/TwoButtonDialog.java @@ -9,14 +9,29 @@ 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 { + private ButtonType leftButtonType; + private ButtonType rightButtonType; + private String leftButtonText; + private String rightButtonText; + 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); + this.leftButtonType = leftButtonType; + this.rightButtonType = rightButtonType; + this.leftButtonText = leftButtonText; + this.rightButtonText = rightButtonText; + } - createButton(leftButtonType,leftButtonText,new ClickListener() { + @Override + protected void prepareContent() { + super.prepareContent(); + createButton(leftButtonType, leftButtonText, new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { leftButtonAction(); - }; + } + + ; }); createButton(rightButtonType,rightButtonText,new ClickListener() { -- GitLab