Skip to content
Snippets Groups Projects
Commit 094e83b3 authored by Frantisek Simon's avatar Frantisek Simon
Browse files

#62 Dialogs refactoring - first draft

parent 72119df4
Branches
Tags
No related merge requests found
......@@ -446,7 +446,7 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
}
@Override
protected Cell<Label> addLabel(String text, BitmapFont font) {
public Cell<Label> addLabel(String text, BitmapFont font) {
Cell<Label> labelCell = super.addLabel(text, font);
labelCell.padTop(getHeight() * TEXT_TOP_PADDING_RATIO);
return labelCell;
......@@ -458,7 +458,7 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
Image resultsBanner = new Image(getGameGlobalTextureRegion(VICTORY_DIALOG_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().colspan(3);
addImage(resultsBanner, resultsBannerSizeRatio).center().colspan(3);
// RATING STARS
getContentTable().row();
......@@ -479,10 +479,8 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
victoryDialogText = textKey != null ? getText(textKey) : "";
}
getContentTable().row();
Label resultText = new Label(victoryDialogText, new Label.LabelStyle(ApplicationFontManager.getInstance().getFont(VICTORY_DIALOG_TEXT_FONT_TYPE), VICTORY_DIALOG_TEXT_FONT_COLOR));
resultText.setAlignment(Align.center);
resultText.setFontScale(VICTORY_DIALOG_TEXT_FONT_SCALE);
getContentTable().add(resultText).padBottom(VICTORY_DIALOG_TEXT_PADDING_BOTTOM).padTop(VICTORY_DIALOG_TEXT_PADDING_TOP).center();
addLabel(victoryDialogText, ApplicationFontManager.getInstance().getFont(VICTORY_DIALOG_TEXT_FONT_TYPE));
getContentTable().row();
// SUMMARY TEXT
......
......@@ -29,9 +29,7 @@ import cz.nic.tablexia.screen.AbstractTablexiaScreen;
import cz.nic.tablexia.util.ScaleUtil;
import cz.nic.tablexia.util.Utility;
import cz.nic.tablexia.util.ui.TablexiaNoBlendingImage;
import cz.nic.tablexia.util.ui.dialog.TablexiaDialog;
import cz.nic.tablexia.util.ui.dialog.TextDialog;
import cz.nic.tablexia.util.ui.dialog.text.DialogTextContent;
import cz.nic.tablexia.util.ui.dialog.DialogFactory;
/**
* Screen showing street animation and office before user create form
......@@ -490,7 +488,7 @@ public class PanoramaScreen extends AbstractTablexiaScreen<int[][]> {
*/
private void showDialog(final int num) {
String text = getText("createuser_detective_" + num);
final Dialog dialog = new TextDialog(getStage().getWidth() * 0.3f, getStage().getWidth() * 0.26f, getStage().getWidth() * 0.3f, getStage().getWidth() * 0.2f, TablexiaDialog.BackGroundType.BUBBLE_CLASSIC_CONTINUE_BUTTON, new DialogTextContent("", text)).show(getStage());
final Dialog dialog = DialogFactory.createBubbleContinueDialog(text, getStage().getWidth() * 0.3f, getStage().getWidth() * 0.26f, getStage().getWidth() * 0.3f, getStage().getWidth() * 0.2f).show(getStage());
playMusic(MFX_PATH + "detective/" + num + ".mp3");
dialog.addListener(new ClickListener() {
@Override
......
......@@ -19,6 +19,7 @@ import java.util.List;
import java.util.Map;
import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.util.Point;
import cz.nic.tablexia.game.trophy.GameTrophyDefinition;
import cz.nic.tablexia.game.trophy.ITrophyDefinition;
......@@ -29,9 +30,8 @@ import cz.nic.tablexia.screen.halloffame.trophy.TrophyDialog;
import cz.nic.tablexia.screen.halloffame.trophy.TrophyHelper;
import cz.nic.tablexia.util.Log;
import cz.nic.tablexia.util.structure.Trio;
import cz.nic.tablexia.util.ui.dialog.DialogFactory;
import cz.nic.tablexia.util.ui.dialog.TablexiaDialog;
import cz.nic.tablexia.util.ui.dialog.TextDialog;
import cz.nic.tablexia.util.ui.dialog.text.DialogTextContent;
public class HallOfFameScreen extends AbstractTablexiaScreen<Void> {
private static final Point SCREEN_SIZE = new Point(TablexiaSettings.getWorldWidth(),TablexiaSettings.getMinWorldHeight());
......@@ -181,7 +181,11 @@ public class HallOfFameScreen extends AbstractTablexiaScreen<Void> {
TextureRegion banner = getScreenTextureRegion(HallOfFameAssets.HALL_OF_FAME_DIALOG_BANNER);
TextureRegion texture = getScreenTextureRegion(TrophyHelper.getFullPath(trophies.get(currentIndex).getTrophyName(), TrophyHelper.TrophyType.SMALL));
TextureRegion[] textures = new TextureRegion[] {banner, texture};
final TrophyDialog trophyDialog = new TrophyDialog(SCREEN_SIZE.x / 2 - TROPHY_DIALOG_WIDTH / 2, SCREEN_SIZE.y/2-TROPHY_DIALOG_HEIGHT/2, TROPHY_DIALOG_WIDTH, TROPHY_DIALOG_HEIGHT, TablexiaDialog.BackGroundType.DIALOG_SQUARE_BORDERLINES, new DialogTextContent(getText(trophies.get(currentIndex).getTrophyName()), getText(trophies.get(currentIndex).getTrophyDescription())), textures);
String name = getText(trophies.get(currentIndex).getTrophyName());
String desc = getText(trophies.get(currentIndex).getTrophyDescription());
final TrophyDialog trophyDialog = DialogFactory.createTrophyDialog(TROPHY_DIALOG_WIDTH, TROPHY_DIALOG_HEIGHT, name, desc, textures);
trophyDialog.show(getStage());
trophyDialog.addListener(new ClickListener() {
@Override
......@@ -218,7 +222,7 @@ public class HallOfFameScreen extends AbstractTablexiaScreen<Void> {
TextureRegion mousePressedTexture = getScreenTextureRegion(HallOfFameAssets.HALL_OF_FAME_MOUSE_PRESSED);
mouseImage.setDrawable(new SpriteDrawable(new Sprite(mousePressedTexture)));
mouseImage.setTouchable(Touchable.disabled);
final TablexiaDialog mouseDialog = new TextDialog(390, 170, 300, 70, TablexiaDialog.BackGroundType.BUBBLE_CLASSIC, new DialogTextContent("", getText(mouseTexts[Math.min(currentMouseTextIndex++, mouseTexts.length - 1)])));
final TablexiaDialog mouseDialog = DialogFactory.createBubbleDialog(getText(mouseTexts[Math.min(currentMouseTextIndex++, mouseTexts.length - 1)]), 390, 170, 300, 70);
mouseDialog.show(getStage());
new Timer().scheduleTask(new Timer.Task() {
@Override
......
package cz.nic.tablexia.screen.halloffame.trophy;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.utils.Align;
import cz.nic.tablexia.loader.application.ApplicationFontManager;
import cz.nic.tablexia.util.ui.dialog.ImageDialog;
import cz.nic.tablexia.util.ui.dialog.TablexiaDialog;
import cz.nic.tablexia.util.ui.dialog.text.DialogTextContent;
/**
* Created by Václav Tarantík on 27.4.15.
*/
public class TrophyDialog extends ImageDialog {
public class TrophyDialog extends TablexiaDialog {
private static final float BANNER_SIZE_RATIO_TO_ORIGINAL_SIZE = 0.8f;
private static final float IMAGE_SIZE_RATIO_TO_ORIGINAL_SIZE = 0.5f;
......@@ -20,7 +23,7 @@ public class TrophyDialog extends ImageDialog {
//textures[0] used for banner "Trophy", textures[1] used for trophy texture
public TrophyDialog(float x, float y, float width, float height, BackGroundType backGroundType, DialogTextContent dialogTextContent, TextureRegion... textures) {
super(x, y, width, height, backGroundType, dialogTextContent, textures);
super(x, y, width, height, backGroundType);
this.dialogTextContent = dialogTextContent;
bannerTexture = textures[0];
trophyTexture = textures[1];
......@@ -33,15 +36,8 @@ public class TrophyDialog extends ImageDialog {
addImage(trophyTexture, IMAGE_SIZE_RATIO_TO_ORIGINAL_SIZE);
getContentTable().row();
getContentTable().setDebug(true);
addLabel(dialogTextContent.getTitle(), ApplicationFontManager.getInstance().getFont(ApplicationFontManager.APPLICATION_DEFAULT_FONT_BOLD));
addLabel(dialogTextContent.getTitle(), new Label.LabelStyle(ApplicationFontManager.getInstance().getFont(ApplicationFontManager.APPLICATION_DEFAULT_FONT_BOLD), Color.BLACK), Align.center);
getContentTable().row();
addLabel(dialogTextContent.getContent(),ApplicationFontManager.getInstance().getFont(ApplicationFontManager.APPLICATION_DEFAULT_FONT_REGULAR)).fillX();
}
@Override
protected int getTextAlignment() {
return Align.center;
addLabel(dialogTextContent.getContent(), new Label.LabelStyle(ApplicationFontManager.getInstance().getFont(ApplicationFontManager.APPLICATION_DEFAULT_FONT_REGULAR), Color.BLACK), Align.center).fillX();
}
}
package cz.nic.tablexia.util.ui.dialog;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.screen.halloffame.trophy.TrophyDialog;
import cz.nic.tablexia.util.Point;
import cz.nic.tablexia.util.ui.dialog.text.DialogTextContent;
/**
* Created by frantisek on 10.11.15.
*/
public class DialogFactory {
private static final int DIALOG_IMAGE_BORDER_PADDING = 20;
public static TablexiaDialog createBubbleDialog(String label, float x, float y, float width, float height) {
TextDialog dialog = new TextDialog(x, y, width, height, TablexiaDialog.BackGroundType.BUBBLE_CLASSIC, new DialogTextContent(label));
return dialog;
}
public static TablexiaDialog createBubbleContinueDialog(String label, float x, float y, float width, float height) {
TextDialog dialog = new TextDialog(x, y, width, height, TablexiaDialog.BackGroundType.BUBBLE_CLASSIC_CONTINUE_BUTTON, new DialogTextContent(label));
return dialog;
}
public static TablexiaDialog createImageDialog(TextureRegion texture) {
final Point screenSize = new Point(TablexiaSettings.getWorldWidth(),TablexiaSettings.getMinWorldHeight());
int width = texture.getRegionWidth() + DIALOG_IMAGE_BORDER_PADDING;
int height = texture.getRegionHeight() + DIALOG_IMAGE_BORDER_PADDING;
ImageDialog dialog = new ImageDialog(screenSize.x / 2 - width / 2, screenSize.y / 2 - height / 2, width, height, TablexiaDialog.BackGroundType.DIALOG_SQUARE_BORDERLINES, texture);
return dialog;
}
public static TrophyDialog createTrophyDialog(float width, float height, String name, String desc, TextureRegion... textures) {
final Point screenSize = new Point(TablexiaSettings.getWorldWidth(),TablexiaSettings.getMinWorldHeight());
TrophyDialog dialog = new TrophyDialog(screenSize.x / 2 - width / 2, screenSize.y / 2 - height / 2, width, height, TablexiaDialog.BackGroundType.DIALOG_SQUARE_BORDERLINES, new DialogTextContent(name, desc), textures);
return dialog;
}
}
package cz.nic.tablexia.util.ui.dialog;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.ui.Cell;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
......@@ -9,45 +10,43 @@ import cz.nic.tablexia.util.ui.dialog.text.DialogTextContent;
/**
* Created by Václav Tarantík on 19.3.15.
*/
public class ImageDialog extends TextDialog {
private Table imageTable;
public class ImageDialog extends TablexiaDialog {
private TextureRegion[] textures;
public ImageDialog(float x, float y,float width, float height,BackGroundType backGroundType, DialogTextContent dialogTextContent, TextureRegion... textures) {
super(x, y, width, height, backGroundType, dialogTextContent);
public ImageDialog(float x, float y,float width, float height,BackGroundType backGroundType, TextureRegion... textures) {
super(x, y, width, height, backGroundType);
this.textures = textures;
imageTable = new Table();
}
protected void prepareContent(){
protected void prepareContent() {
super.prepareContent();
getContentTable().row();
for(TextureRegion texture: textures){
for (TextureRegion texture: textures){
addImage(texture, 1);
getContentTable().row();
}
}
//TODO find the source of deformation of bigger images
protected void addImage(TextureRegion texture, float sizeRatioToOriginalSize){
float textureMaxHeight = getHeight()/2;
float textureMaxWidth = getWidth()-20;//20 is approx the padding from both sides
public Cell<Image> addImage(TextureRegion texture, float sizeRatioToOriginalSize) {
float textureMaxHeight = getHeight() / 2;
float textureMaxWidth = getWidth() - 20; //20 is approx the padding from both sides
float textureMeasureRatio = (float)texture.getRegionWidth() / (float)texture.getRegionWidth();
float textureMeasureRatio = (float)texture.getRegionHeight() / (float)texture.getRegionWidth();
float textureNewWidth = texture.getRegionWidth() * sizeRatioToOriginalSize;
float textureNewHeight = textureNewWidth*textureMeasureRatio;
if(textureNewHeight>textureMaxHeight){
float textureNewHeight = textureNewWidth * textureMeasureRatio;
if (textureNewHeight > textureMaxHeight) {
textureNewHeight = textureMaxHeight;
textureNewWidth = (1/textureMeasureRatio)*textureNewHeight;
if(textureNewWidth>textureMaxWidth){
textureNewWidth = (1 / textureMeasureRatio) * textureNewHeight;
if (textureNewWidth > textureMaxWidth) {
textureNewWidth = textureMaxWidth;
textureNewHeight = textureNewWidth*textureMeasureRatio;
textureNewHeight = textureNewWidth * textureMeasureRatio;
}
}
Image image = new Image(texture);
image.getDrawable().setMinHeight(textureNewHeight);
image.getDrawable().setMinWidth(textureNewWidth);
getContentTable().add(image);
return getContentTable().add(image);
}
}
......@@ -4,15 +4,23 @@ import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
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.Label;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable;
import com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable;
import com.badlogic.gdx.utils.Align;
import java.util.ArrayList;
import java.util.List;
import cz.nic.tablexia.loader.application.ApplicationAtlasManager;
import cz.nic.tablexia.loader.application.ApplicationFontManager;
......@@ -25,6 +33,8 @@ import static com.badlogic.gdx.scenes.scene2d.actions.Actions.sequence;
*/
public class TablexiaDialog extends Dialog {
List<TablexiaDialog> childDialogs = new ArrayList<TablexiaDialog>();
public enum BackGroundType {
BUBBLE_CLASSIC (ApplicationAtlasManager.DIALOG_BUBBLE_CLASSIC),
BUBBLE_ARROW_DOWN (ApplicationAtlasManager.DIALOG_BUBBLE_ARROW_DOWN),
......@@ -51,10 +61,10 @@ public class TablexiaDialog extends Dialog {
public TablexiaDialog(float x, float y, float width, float height, NinePatchDrawable backgroundTypeDrawable) {
super("",
new DialogStyle(ApplicationFontManager.getInstance().getDefaultApplicationRegularFont(),
Color.BLACK,
backgroundTypeDrawable,
new SpriteDrawable(new Sprite(ApplicationAtlasManager.getInstance().getColorTexture(ApplicationAtlasManager.COLOR_OVERLAY)))));
new DialogStyle(ApplicationFontManager.getInstance().getDefaultApplicationRegularFont(),
Color.BLACK,
backgroundTypeDrawable,
new SpriteDrawable(new Sprite(ApplicationAtlasManager.getInstance().getColorTexture(ApplicationAtlasManager.COLOR_OVERLAY)))));
setModal(true);
setMovable(false);
......@@ -80,13 +90,45 @@ public class TablexiaDialog extends Dialog {
});
}
public void disableOverlay() {
getStyle().stageBackground = null;
setModal(false);
}
public void addChildDialog(TablexiaDialog dialog) {
childDialogs.add(dialog);
}
@Override
public Dialog show(Stage stage) {
prepareContent();
show(stage, sequence(Actions.alpha(0), Actions.fadeIn(0.4f, Interpolation.fade)));
for (TablexiaDialog dialog : childDialogs) {
dialog.show(getStage());
}
return this;
}
@Override
public void hide() {
for (TablexiaDialog dialog : childDialogs) {
dialog.hide();
}
super.hide();
}
/**
* Keep child dialogs above parent
*/
@Override
public void toFront() {
super.toFront();
for (TablexiaDialog dialog : childDialogs) {
dialog.toFront();
}
}
protected void prepareContent() {
//no content here
}
......@@ -102,4 +144,54 @@ public class TablexiaDialog extends Dialog {
protected void drawStageBackground(Batch batch, float parentAlpha, float x, float y, float width, float height) {
super.drawStageBackground(batch, parentAlpha, ScaleUtil.getViewportPositionY(getStage()), ScaleUtil.getViewportPositionY(getStage()), ScaleUtil.getViewportWidth(), ScaleUtil.getViewportHeight());
}
protected Cell<Image> addImage(TextureRegion texture, float sizeRatioToOriginalSize) {
return addImage(new Image(texture), sizeRatioToOriginalSize);
}
protected Cell<Image> addImage(Image image, float sizeRatioToOriginalSize) {
float imageMaxHeight = getHeight() / 2;
float imageMaxWidth = getWidth() - 20; //20 is approx the padding from both sides
float imageMeasureRatio = image.getHeight() / image.getWidth();
float imageNewWidth = image.getWidth() * sizeRatioToOriginalSize;
float imageNewHeight = imageNewWidth * imageMeasureRatio;
if (imageNewHeight > imageMaxHeight) {
imageNewHeight = imageMaxHeight;
imageNewWidth = (1 / imageMeasureRatio) * imageNewHeight;
if (imageNewWidth > imageMaxWidth) {
imageNewWidth = imageMaxWidth;
imageNewHeight = imageNewWidth * imageMeasureRatio;
}
}
image.getDrawable().setMinHeight(imageNewHeight);
image.getDrawable().setMinWidth(imageNewWidth);
return getContentTable().add(image);
}
protected Cell<Label> addLabel(String text, Label.LabelStyle labelStyle) {
return addLabel(text, labelStyle, Align.left);
}
protected Cell<Label> addLabel(String text, Label.LabelStyle labelStyle, int align) {
Label label = new Label(text, labelStyle);
label.setWrap(true);
label.setAlignment(align);
Cell<Label> cell = getContentTable().add(label);
switch (align) {
case Align.left:
cell.expand().left();
break;
case Align.right:
cell.expand().right();
break;
case Align.center:
cell.expand().center();
break;
}
return cell;
}
}
......@@ -14,6 +14,7 @@ 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;
......@@ -40,12 +41,7 @@ public class TextDialog extends TablexiaDialog {
}
protected Cell<Label> addLabel(String text, BitmapFont font) {
Label.LabelStyle labelStyle = new Label.LabelStyle(font, Color.BLACK);
labelStyle.font.getData().setScale(TITLE_FONT_SCALE);
Label label = new Label(text, labelStyle);
label.setWrap(true);
label.setAlignment(getTextAlignment());
return getContentTable().add(label);
return super.addLabel(text, new Label.LabelStyle(font, Color.BLACK), getTextAlignment());
}
protected int getTextAlignment() {
......
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