Skip to content
Snippets Groups Projects
Commit 548a7e87 authored by Matyáš Latner's avatar Matyáš Latner
Browse files

Merge branch 'feature-dialog' into 'devel'

Feature dialog

See merge request !21
parents 858abb57 e637da23
No related branches found
No related tags found
No related merge requests found
Showing
with 456 additions and 0 deletions
buttons_atlas.png
size: 512,256
format: RGBA8888
filter: Nearest,Nearest
repeat: none
tablexiabutton_blank_blue_pressed
rotate: false
xy: 2, 170
size: 157, 82
split: 19, 27, 12, 31
pad: 15, 22, 10, 29
orig: 157, 82
offset: 0, 0
index: -1
tablexiabutton_blank_blue_unpressed
rotate: false
xy: 2, 86
size: 157, 82
split: 31, 30, 8, 35
pad: 17, 18, 8, 32
orig: 157, 82
offset: 0, 0
index: -1
tablexiabutton_blank_green_pressed
rotate: false
xy: 161, 170
size: 157, 82
split: 10, 19, 9, 28
pad: 13, 21, 9, 28
orig: 157, 82
offset: 0, 0
index: -1
tablexiabutton_blank_green_unpressed
rotate: false
xy: 2, 2
size: 157, 82
split: 29, 36, 9, 31
pad: 18, 19, 6, 32
orig: 157, 82
offset: 0, 0
index: -1
tablexiabutton_blank_red_pressed
rotate: false
xy: 161, 86
size: 157, 82
split: 52, 27, 9, 28
pad: 56, 27, 6, 32
orig: 157, 82
offset: 0, 0
index: -1
tablexiabutton_blank_red_unpressed
rotate: false
xy: 320, 170
size: 157, 82
split: 61, 27, 9, 31
pad: 60, 27, 6, 32
orig: 157, 82
offset: 0, 0
index: -1
tablexiabutton_disabled
rotate: false
xy: 161, 2
size: 157, 82
split: 40, 36, 12, 33
pad: 14, 20, 10, 30
orig: 157, 82
offset: 0, 0
index: -1
android/assets/atlases/buttons_atlas.png

42.4 KiB

dialog_background.png
size: 1024,512
format: RGBA8888
filter: Nearest,Nearest
repeat: none
bubble_arrow_down
rotate: false
xy: 251, 52
size: 158, 101
split: 62, 16, 3, 54
pad: 5, 7, 2, 52
orig: 158, 101
offset: 0, 0
index: -1
bubble_arrow_left
rotate: false
xy: 758, 267
size: 158, 101
split: 64, 27, 4, 65
pad: 7, 9, 3, 51
orig: 158, 101
offset: 0, 0
index: -1
bubble_classic
rotate: false
xy: 408, 180
size: 123, 69
split: 6, 35, 4, 21
pad: 7, 5, 5, 19
orig: 123, 69
offset: 0, 0
index: -1
bubble_classic_continue_button
rotate: false
xy: 408, 251
size: 348, 245
split: 132, 78, 11, 143
pad: 23, 58, 6, 58
orig: 348, 245
offset: 0, 0
index: -1
dialog_rectangle
rotate: false
xy: 2, 2
size: 247, 151
split: 52, 37, 30, 37
pad: 20, 27, 24, 32
orig: 247, 151
offset: 0, 0
index: -1
dialog_square
rotate: false
xy: 758, 370
size: 150, 126
split: 12, 18, 4, 8
pad: 9, 10, 8, 10
orig: 150, 126
offset: 0, 0
index: -1
dialog_square_borderlines
rotate: false
xy: 2, 155
size: 404, 341
split: 22, 27, 18, 24
pad: 21, 27, 17, 27
orig: 404, 341
offset: 0, 0
index: -1
android/assets/atlases/dialog_background.png

202 KiB

......@@ -17,6 +17,12 @@ import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.screen.AbstractTablexiaScreen;
import cz.nic.tablexia.screen.halloffame.assets.HallOfFameAssets;
import cz.nic.tablexia.screen.halloffame.helper.TrophyHelper;
import cz.nic.tablexia.util.Log;
import cz.nic.tablexia.util.ui.dialog.ImageDialog;
import cz.nic.tablexia.util.ui.dialog.SingleButtonDialog;
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;
public class HallOfFameScreen extends AbstractTablexiaScreen<Void> {
......
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;
/**
* Created by Václav Tarantík on 9.4.15.
*/
public abstract class AbstractButtonDialog extends TablexiaDialog {
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 String BTN_DRAWABLE_PRESSED_ENDING = "_pressed";
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);
}
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);
NinePatch down = buttonAtlas.createPatch(buttonType.getButtonResourceName()+BTN_DRAWABLE_PRESSED_ENDING);
NinePatchDrawable npdDown = new NinePatchDrawable(down);
NinePatch dis = buttonAtlas.createPatch(BTN_DISABLED_ATLAS_NAME);
NinePatchDrawable npdDis = new NinePatchDrawable(dis);
textButton.setStyle(new TextButton.TextButtonStyle(npdUp, npdDown, npdDis, getStyle().titleFont));
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);
}else{
throw new IllegalArgumentException("Invalid dialog type. Buttons not supported for this type.");
}
}
}
package cz.nic.tablexia.util.ui.dialog;
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;
/**
* Created by Václav Tarantík on 19.3.15.
*/
public class ImageDialog extends TablexiaDialog {
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(dialogTextContent);
}
private void prepareContent(DialogTextContent dialogTextContent){
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();
}
getContentTable().add(imageGroup).width(width/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;
/**
* Created by Václav Tarantík on 24.3.15.
*/
public abstract class SingleButtonDialog extends AbstractButtonDialog {
public SingleButtonDialog(float x, float y, float width, float height, BackGroundType backGroundType, DialogTextContent dialogTextContent, ButtonType buttonType,String buttonText) {
super(x, y, width, height, backGroundType, dialogTextContent);
createButton(buttonType,buttonText, new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
buttonAction();
};
});
}
protected abstract void buttonAction();
}
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;
import cz.nic.tablexia.util.ui.dialog.text.DialogTextContent;
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 {
BUBBLE_CLASSIC("bubble_classic"),
BUBBLE_ARROW_DOWN("bubble_arrow_down"),
BUBBLE_ARROW_LEFT("bubble_arrow_left"),
BUBBLE_CLASSIC_CONTINUE_BUTTON("bubble_classic_continue_button"),
DIALOG_RECTANGLE("dialog_rectangle"),
DIALOG_SQUARE("dialog_square"),
DIALOG_SQUARE_BORDERLINES("dialog_square_borderlines");
private String dialogBackgroundTextureName;
BackGroundType(String dialogBackgroundTextureName){
this.dialogBackgroundTextureName = dialogBackgroundTextureName;
}
public String getDialogBackgroundTextureName(){
return dialogBackgroundTextureName;
}
}
public enum ButtonType{
BLUE("tablexiabutton_blank_blue"),
GREEN("tablexiabutton_blank_green"),
RED("tablexiabutton_blank_red");
private String buttonResourceName;
ButtonType(String buttonResourceName){
this.buttonResourceName = buttonResourceName;
}
public String getButtonResourceName(){
return buttonResourceName;
}
}
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);
setModal(true);
setMovable(false);
setResizable(false);
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.backGroundType = backGroundType;
this.dialogTextContent = dialogTextContent;
NinePatch np = backgroundAtlas.createPatch(backGroundType.dialogBackgroundTextureName);
NinePatchDrawable npd = new NinePatchDrawable(np);
setBackground(npd);
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;
}
protected void prepareTextContent(){
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();
}
}
\ No newline at end of file
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;
/**
* 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);
createButton(leftButtonType,leftButtonText,new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
leftButtonAction();
};
});
createButton(rightButtonType,rightButtonText,new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
rightButtonAction();
};
});
}
protected abstract void leftButtonAction();
protected abstract void rightButtonAction();
}
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){
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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment