From 0b0bb87df3fd6e13efcb9b8f3141317c8d298389 Mon Sep 17 00:00:00 2001 From: "v.tarantik" <v.tarantik@gmail.com> Date: Thu, 9 Apr 2015 11:26:35 +0200 Subject: [PATCH] #20 AbstractButton dialog, refactoring, problems fix --- android/assets/atlases/buttons_atlas.pack~ | 69 ----------------- android/assets/atlases/dialog_atlas.pack~ | 77 ------------------- .../ApplicationTextureManager.java | 4 - .../screen/halloffame/HallOfFameScreen.java | 9 ++- .../util/ui/dialog/AbstractButtonDialog.java | 56 ++++++++++++++ .../util/ui/dialog/SingleButtonDialog.java | 48 ++---------- .../util/ui/dialog/TablexiaDialog.java | 18 +---- .../util/ui/dialog/TwoButtonDialog.java | 64 ++------------- .../nic/tablexia/desktop/DesktopLauncher.java | 2 +- 9 files changed, 82 insertions(+), 265 deletions(-) delete mode 100644 android/assets/atlases/buttons_atlas.pack~ delete mode 100644 android/assets/atlases/dialog_atlas.pack~ create mode 100644 core/src/cz/nic/tablexia/util/ui/dialog/AbstractButtonDialog.java diff --git a/android/assets/atlases/buttons_atlas.pack~ b/android/assets/atlases/buttons_atlas.pack~ deleted file mode 100644 index dc044a6cf..000000000 --- a/android/assets/atlases/buttons_atlas.pack~ +++ /dev/null @@ -1,69 +0,0 @@ - -buttons_atlas.pack.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 diff --git a/android/assets/atlases/dialog_atlas.pack~ b/android/assets/atlases/dialog_atlas.pack~ deleted file mode 100644 index a9aa879a4..000000000 --- a/android/assets/atlases/dialog_atlas.pack~ +++ /dev/null @@ -1,77 +0,0 @@ - -dialog_atlas.png -format: RGBA8888 -filter: Nearest,Nearest -repeat: none -newuser_signature_background - rotate: false - xy: 1, 662 - size: 406, 343 - split: 24, 29, 20, 26 - orig: 406, 343 - offset: 0, 0 - index: -1 -howto_background - rotate: false - xy: 1, 319 - size: 404, 341 - split: 22, 27, 18, 24 - orig: 404, 341 - offset: 0, 0 - index: -1 -dialog_background - rotate: false - xy: 409, 783 - size: 401, 222 - split: 21, 27, 22, 28 - orig: 401, 222 - offset: 0, 0 - index: -1 -detectiveoffice_bubble - rotate: false - xy: 1, 72 - size: 348, 245 - split: 11, 143, 132, 78 - orig: 348, 245 - offset: 0, 0 - index: -1 -newuser_dialog_background - rotate: false - xy: 409, 630 - size: 247, 151 - split: 52, 37, 30, 37 - orig: 247, 151 - offset: 0, 0 - index: -1 -victoryscreen_trophy_background - rotate: false - xy: 812, 879 - size: 150, 126 - split: 12, 18, 4, 8 - orig: 150, 126 - offset: 0, 0 - index: -1 -newuser_helpbubble_left - rotate: false - xy: 407, 527 - size: 158, 101 - split: 64, 27, 4, 65 - orig: 158, 101 - offset: 0, 0 - index: -1 -newuser_helpbubble_straight - rotate: false - xy: 407, 424 - size: 158, 101 - split: 62, 16, 3, 54 - orig: 158, 101 - offset: 0, 0 - index: -1 -screen_halloffame_mouse_bubble - rotate: false - xy: 1, 1 - size: 123, 69 - split: 6, 35, 4, 21 - orig: 123, 69 - offset: 0, 0 - index: -1 diff --git a/core/src/cz/nic/tablexia/loader/application/ApplicationTextureManager.java b/core/src/cz/nic/tablexia/loader/application/ApplicationTextureManager.java index 881693d6d..c2e56a16b 100644 --- a/core/src/cz/nic/tablexia/loader/application/ApplicationTextureManager.java +++ b/core/src/cz/nic/tablexia/loader/application/ApplicationTextureManager.java @@ -37,12 +37,8 @@ public class ApplicationTextureManager extends TablexiaTextureManager implements private static final String GAMEMENU_PATH = "screen/gamemenu/"; public static final String STARTMENU_BACKGROUND = GAMEMENU_PATH + "screen_gamemenu_startmenu_background.jpg"; - private static final String HALLOFFAME_PATH = "screen/halloffame/"; - public static final String DIALOG_BUBBLE =HALLOFFAME_PATH+ "screen_halloffame_mouse_bubble.9.png"; - public void load() { loadTexture(MAINMENU_BACKGROUND); loadTexture(STARTMENU_BACKGROUND); - loadTexture(DIALOG_BUBBLE); } } \ No newline at end of file diff --git a/core/src/cz/nic/tablexia/screen/halloffame/HallOfFameScreen.java b/core/src/cz/nic/tablexia/screen/halloffame/HallOfFameScreen.java index 59c0a39ff..e3607dd5e 100644 --- a/core/src/cz/nic/tablexia/screen/halloffame/HallOfFameScreen.java +++ b/core/src/cz/nic/tablexia/screen/halloffame/HallOfFameScreen.java @@ -17,6 +17,7 @@ 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; @@ -131,7 +132,13 @@ public class HallOfFameScreen extends AbstractTablexiaScreen<Void> { //TODO add action for leaving to main menu Texture[] textuures = new Texture[]{getTexture(HallOfFameAssets.HALL_OF_FAME_DOOR),getTexture(HallOfFameAssets.HALL_OF_FAME_BACKGROUND_TILE)}; - new ImageDialog(400, 200, 400, 200, TablexiaDialog.BackGroundType.DIALOG_SQUARE_BORDERLINES,new DialogTextContent("HOU", "HEY YAAAAAAAAAAAA"),textuures).show(getStage()); + + new SingleButtonDialog(100, 200, 800, 200, TablexiaDialog.BackGroundType.DIALOG_SQUARE_BORDERLINES, new DialogTextContent("A", "B"), TablexiaDialog.ButtonType.GREEN, "Click" ){ + @Override + protected void buttonAction() { + Log.info(this.getClass(),"Button clicked"); + } + }.show(getStage()); } }); foregroundGroup.addActor(imgDoorButton); diff --git a/core/src/cz/nic/tablexia/util/ui/dialog/AbstractButtonDialog.java b/core/src/cz/nic/tablexia/util/ui/dialog/AbstractButtonDialog.java new file mode 100644 index 000000000..326a6b426 --- /dev/null +++ b/core/src/cz/nic/tablexia/util/ui/dialog/AbstractButtonDialog.java @@ -0,0 +1,56 @@ +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."); + } + + } +} diff --git a/core/src/cz/nic/tablexia/util/ui/dialog/SingleButtonDialog.java b/core/src/cz/nic/tablexia/util/ui/dialog/SingleButtonDialog.java index 577fe9428..433406974 100644 --- a/core/src/cz/nic/tablexia/util/ui/dialog/SingleButtonDialog.java +++ b/core/src/cz/nic/tablexia/util/ui/dialog/SingleButtonDialog.java @@ -13,55 +13,21 @@ import cz.nic.tablexia.util.ui.dialog.text.DialogTextContent; /** * Created by Václav TarantĂk on 24.3.15. */ -public abstract class SingleButtonDialog 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; +public abstract class SingleButtonDialog extends AbstractButtonDialog { - private static final String BTN_DRAWABLE_PRESSED_ENDING = "_pressed"; - private static final String BTN_DRAWABLE_UNPRESSED_ENDING = "_unpressed"; + 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); - private TextButton confirmButton; - - 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); - prepareButton(buttonType,buttonText); - } - - private void prepareButton(ButtonType buttonType, String buttonText){ - if(!buttonType.equals(null)){ - - confirmButton = 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); - - confirmButton.setStyle(new TextButton.TextButtonStyle(npdUp, npdDown, npdDis,getStyle().titleFont)); - confirmButton.addListener(new ClickListener() { + createButton(buttonType,buttonText, new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { buttonAction(); - } - - ; + }; }); + } - float buttonWidth = getPrefWidth()* BUTTON_WIDTH_RATIO_TO_DIALOG_WIDTH; - float buttonHeight = buttonWidth*BUTTON_HEIGHT_RATIO; - getButtonTable().add(confirmButton).width(buttonWidth).height(buttonHeight); + protected abstract void buttonAction(); - }else{ - throw new IllegalArgumentException("Invalid dialog type. Buttons not supported for this type."); - } - } - public abstract void buttonAction(); } 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 2cd843144..8d9480c81 100644 --- a/core/src/cz/nic/tablexia/util/ui/dialog/TablexiaDialog.java +++ b/core/src/cz/nic/tablexia/util/ui/dialog/TablexiaDialog.java @@ -69,6 +69,7 @@ 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")); @@ -96,33 +97,20 @@ public class TablexiaDialog extends Dialog { @Override public Dialog show(Stage stage) { show(stage, sequence(Actions.alpha(0), Actions.fadeIn(0.4f, Interpolation.fade))); - setPosition(x, y); + setBounds(x,y,width,height); return this; } protected void prepareTextContent(){ //TODO fix fonts and other styles - getContentTable().setDebug(true); - if(!dialogTextContent.getTitle().equals("")&&dialogTextContent.getTitle()!=null){ + if(dialogTextContent.getTitle() != null && !dialogTextContent.getTitle().equals("")){ Label titleLabel = new Label(dialogTextContent.getTitle(),skin); titleLabel.setColor(Color.BLACK); - titleLabel.setDebug(true); getContentTable().add(titleLabel).center() ; getContentTable().row(); } Label label = new Label(dialogTextContent.getContent(),skin); label.setWrap(true); - label.setDebug(true); getContentTable().add(label).left().top().expand().fillX(); } - - @Override - public float getPrefWidth() { - return width; - } - - @Override - public float getPrefHeight() { - return height; - } } \ No newline at end of file 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 6bedc8301..60c16aff2 100644 --- a/core/src/cz/nic/tablexia/util/ui/dialog/TwoButtonDialog.java +++ b/core/src/cz/nic/tablexia/util/ui/dialog/TwoButtonDialog.java @@ -13,75 +13,25 @@ import cz.nic.tablexia.util.ui.dialog.text.DialogTextContent; /** * Created by Václav TarantĂk on 26.3.15. */ -public abstract class TwoButtonDialog 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"; - - - private TextButton leftButton; - private TextButton rightButton; - - public TwoButtonDialog(float x, float y,float width, float height, BackGroundType backGroundType,DialogTextContent dialogTextContent, ButtonType leftButtonType, ButtonType rightButtonType,String buttonLeftText, String buttonRightText) { +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); - prepareButtons(leftButtonType,rightButtonType,buttonLeftText,buttonRightText); - } - - private void prepareButtons(ButtonType leftButtonType,ButtonType rightButtonType,String buttonLeftText,String buttonRightText){ - if(!leftButtonType.equals(null)&&!rightButtonType.equals(null)){ - - Skin defaultSkin = new Skin(Gdx.files.internal("uiskin.json")); - NinePatch ninePatchBtnDisabled = buttonAtlas.createPatch(BTN_DISABLED_ATLAS_NAME); - NinePatchDrawable ninePatchDrawableBtnDisabled = new NinePatchDrawable(ninePatchBtnDisabled); - - leftButton = new TextButton(buttonLeftText, defaultSkin); - NinePatch ninepatchBtnLeftUp = buttonAtlas.createPatch(leftButtonType.getButtonResourceName()+BTN_DRAWABLE_UNPRESSED_ENDING); - NinePatchDrawable ninePatchDrawableBtnLeftUp = new NinePatchDrawable(ninepatchBtnLeftUp); - - NinePatch ninePatchBtnLeftDown = buttonAtlas.createPatch(leftButtonType.getButtonResourceName()+BTN_DRAWABLE_PRESSED_ENDING); - NinePatchDrawable ninePatchDrawableBtnLeftDown = new NinePatchDrawable(ninePatchBtnLeftDown); - leftButton.setStyle(new TextButton.TextButtonStyle(ninePatchDrawableBtnLeftUp, ninePatchDrawableBtnLeftDown, ninePatchDrawableBtnDisabled, getStyle().titleFont)); - - float buttonWidth = getPrefWidth()* BUTTON_WIDTH_RATIO_TO_DIALOG_WIDTH; - float buttonHeight = buttonWidth*BUTTON_HEIGHT_RATIO; - getButtonTable().add(leftButton).width(buttonWidth).height(buttonHeight); - leftButton.addListener( new ClickListener() { + createButton(leftButtonType,leftButtonText,new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { leftButtonAction(); }; }); - - rightButton = new TextButton(buttonRightText, defaultSkin); - NinePatch up = buttonAtlas.createPatch(rightButtonType.getButtonResourceName()+BTN_DRAWABLE_UNPRESSED_ENDING); - NinePatchDrawable npdUp = new NinePatchDrawable(up); - - NinePatch down = buttonAtlas.createPatch(rightButtonType.getButtonResourceName()+BTN_DRAWABLE_PRESSED_ENDING); - NinePatchDrawable npdDown = new NinePatchDrawable(down); - - rightButton.setStyle(new TextButton.TextButtonStyle(npdUp, npdDown, ninePatchDrawableBtnDisabled, getStyle().titleFont)); - - getButtonTable().add(rightButton).width(buttonWidth).height(buttonHeight); - rightButton.addListener(new ClickListener() { + createButton(rightButtonType,rightButtonText,new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { rightButtonAction(); - } - - ; + }; }); - - }else{ - throw new IllegalArgumentException("Invalid dialog type. Only dialog types with two button support allowed here."); - } } - public abstract void leftButtonAction(); - - public abstract void rightButtonAction(); + protected abstract void leftButtonAction(); + protected abstract void rightButtonAction(); } diff --git a/desktop/src/cz/nic/tablexia/desktop/DesktopLauncher.java b/desktop/src/cz/nic/tablexia/desktop/DesktopLauncher.java index f720c8b91..d2fdb15fd 100644 --- a/desktop/src/cz/nic/tablexia/desktop/DesktopLauncher.java +++ b/desktop/src/cz/nic/tablexia/desktop/DesktopLauncher.java @@ -30,7 +30,7 @@ public class DesktopLauncher { String applicationId = loadAttributeFromManifest(APPLICATION_ID_MANIFEST_ATTRIBUTE); LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); - config.resizable = true; + config.resizable = false; config.width = 1280; config.height = 800; -- GitLab