Skip to content
Snippets Groups Projects
Commit 5460606d authored by Luboš Horáček's avatar Luboš Horáček
Browse files

Merge branch 'feature-dialog_devel' into 'feature-dialog'

Dialog transparent background, closing dialogs on outside click

Merge into devel after succesfull merge into feature-dialog.

See merge request !37
parents 99c1a8f2 1b93f646
Branches
Tags
No related merge requests found
......@@ -15,6 +15,7 @@ import cz.nic.tablexia.game.games.night_watch.NightWatchScreen;
import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.screen.AbstractTablexiaScreen;
import cz.nic.tablexia.screen.createuser.FormScreen;
import cz.nic.tablexia.screen.halloffame.HallOfFameScreen;
import cz.nic.tablexia.util.Log;
import cz.nic.tablexia.util.Utility;
......@@ -25,7 +26,7 @@ public class TablexiaSettings {
private static final int MIN_SCREEN_HEIGHT = (int) (DEFAULT_SCREEN_WIDTH * MAXIMUM_RATIO);
private static final boolean DEBUG_SHOW_BOUNDING_BOXES = true;
public static final Class<? extends AbstractTablexiaScreen<?>> INITIAL_SCREEN = FormScreen.class;
public static final Class<? extends AbstractTablexiaScreen<?>> INITIAL_SCREEN = HallOfFameScreen.class;
public static final int AVATAR_COUNT = 8;
private static final String PREFERENCES_KEY = "cz.nic.tablexia.";
......
......@@ -145,6 +145,8 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
TablexiaButton.ButtonType.GREEN,
ApplicationTextManager.getInstance().getText(ApplicationTextManager.ApplicationTextsAssets.VICTORYSCREEN_BUTTON_CHANGEGAME),
ApplicationTextManager.getInstance().getText(ApplicationTextManager.ApplicationTextsAssets.VICTORYSCREEN_BUTTON_REPLAY));
//dialog does not hide on click outside the BG area
setHideOnOutsideClick(false);
}
@Override
......
......@@ -2,15 +2,24 @@ package cz.nic.tablexia.util.ui.dialog;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
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.Dialog;
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 cz.nic.tablexia.loader.application.ApplicationFontManager;
import cz.nic.tablexia.util.Log;
import cz.nic.tablexia.util.ui.dialog.text.DialogTextContent;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.sequence;
......@@ -23,7 +32,7 @@ public class TablexiaDialog extends Dialog {
public static TextureAtlas backgroundAtlas;
public static TextureAtlas buttonAtlas;
protected DialogTextContent dialogTextContent;
private boolean hideOnOutsideClick = true;
public enum BackGroundType {
BUBBLE_CLASSIC("bubble_classic"),
......@@ -47,9 +56,9 @@ public class TablexiaDialog extends Dialog {
}
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))));
super("", new DialogStyle(ApplicationFontManager.getInstance().getDefaultApplicationRegularFont(),
Color.BLACK,
new NinePatchDrawable(backgroundAtlas.createPatch(backGroundType.dialogBackgroundTextureName)), createDrawable(new Color(0, 0, 0, 0.5f))));
setModal(true);
setMovable(false);
......@@ -58,6 +67,23 @@ public class TablexiaDialog extends Dialog {
setBounds(x, y, width, height);
getBackground().setMinWidth(width);
getBackground().setMinHeight(height);
final float dialogX = x;
final float dialogY = y;
final float dialogWidth = width;
final float dialogHeight = height;
addListener(new ClickListener(){
@Override
public void clicked(InputEvent event, float x, float y) {
if((x<0||x>(dialogWidth))||(y<0||y>dialogHeight)){
//user clicked outside the dialog window
if(hideOnOutsideClick){
hide();
}
}
}
});
}
@Override
......@@ -70,4 +96,24 @@ public class TablexiaDialog extends Dialog {
protected void prepareContent(){
//no content here
}
}
\ No newline at end of file
public static Drawable createDrawable (Color c) {
Pixmap p = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
p.setColor(c);
p.drawPixel(0, 0);
return new SpriteDrawable(new Sprite(new Texture(p)));
}
public static class DialogStyle extends WindowStyle{
public DialogStyle (BitmapFont titleFont, Color titleFontColor, Drawable background,Drawable stageBackground){
super(titleFont,titleFontColor,background);
super.stageBackground = stageBackground;
}
}
//hide dialog on click outside the background area? true by default
public void setHideOnOutsideClick(boolean hideOnOutsideClick){
this.hideOnOutsideClick = hideOnOutsideClick;
}
}
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