From 8798edfe16abfd7923914576fa79a13dffd833ea Mon Sep 17 00:00:00 2001 From: "v.tarantik" <v.tarantik@gmail.com> Date: Wed, 4 Mar 2015 16:40:24 +0100 Subject: [PATCH] ScrollPane for HallOfFameScreen --- .../screen/halloffame/HallOfFameScreen.java | 126 ++++++++++++------ .../halloffame/assets/HallOfFameAssets.java | 27 +++- 2 files changed, 107 insertions(+), 46 deletions(-) diff --git a/core/src/cz/nic/tablexia/screen/halloffame/HallOfFameScreen.java b/core/src/cz/nic/tablexia/screen/halloffame/HallOfFameScreen.java index 9833f1180..fba81ae4a 100644 --- a/core/src/cz/nic/tablexia/screen/halloffame/HallOfFameScreen.java +++ b/core/src/cz/nic/tablexia/screen/halloffame/HallOfFameScreen.java @@ -1,78 +1,116 @@ package cz.nic.tablexia.screen.halloffame; -import com.badlogic.gdx.ApplicationListener; -import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.graphics.Camera; -import com.badlogic.gdx.graphics.Color; -import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.Texture; -import com.badlogic.gdx.graphics.g2d.BitmapFont; -import com.badlogic.gdx.graphics.g2d.SpriteBatch; -import com.badlogic.gdx.scenes.scene2d.Group; +import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.scenes.scene2d.InputEvent; -import com.badlogic.gdx.scenes.scene2d.Stage; +import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup; import com.badlogic.gdx.scenes.scene2d.ui.Image; -import com.badlogic.gdx.scenes.scene2d.ui.Label; -import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle; import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane; -import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; -import com.badlogic.gdx.scenes.scene2d.utils.DragListener; -import com.badlogic.gdx.scenes.scene2d.utils.DragScrollListener; -import com.badlogic.gdx.utils.viewport.ScreenViewport; +import com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable; -import cz.nic.tablexia.game.games.robbery.assets.RobberyAssets; -import cz.nic.tablexia.loader.ApplicationFontManager; import cz.nic.tablexia.screen.AbstractTablexiaScreen; import cz.nic.tablexia.screen.halloffame.assets.HallOfFameAssets; -import cz.nic.tablexia.util.Log; public class HallOfFameScreen extends AbstractTablexiaScreen<Void> { + private static enum TrophyHeapAssets { + + HALLOFFAME_TROPHYHEAP_00(HallOfFameAssets.HALL_OF_FAME_TROPHY_HEAP_00, 0), // + HALLOFFAME_TROPHYHEAP_01(HallOfFameAssets.HALL_OF_FAME_TROPHY_HEAP_01, 1), // + HALLOFFAME_TROPHYHEAP_02(HallOfFameAssets.HALL_OF_FAME_TROPHY_HEAP_02, 2), // + HALLOFFAME_TROPHYHEAP_03(HallOfFameAssets.HALL_OF_FAME_TROPHY_HEAP_03, 3), // + HALLOFFAME_TROPHYHEAP_04(HallOfFameAssets.HALL_OF_FAME_TROPHY_HEAP_04, 4), // + HALLOFFAME_TROPHYHEAP_05(HallOfFameAssets.HALL_OF_FAME_TROPHY_HEAP_05, 5), // + HALLOFFAME_TROPHYHEAP_06(HallOfFameAssets.HALL_OF_FAME_TROPHY_HEAP_06, 6), // + HALLOFFAME_TROPHYHEAP_07(HallOfFameAssets.HALL_OF_FAME_TROPHY_HEAP_07, 7), // + HALLOFFAME_TROPHYHEAP_08(HallOfFameAssets.HALL_OF_FAME_TROPHY_HEAP_08, 8), // + HALLOFFAME_TROPHYHEAP_09(HallOfFameAssets.HALL_OF_FAME_TROPHY_HEAP_09, 9), // + HALLOFFAME_TROPHYHEAP_10(HallOfFameAssets.HALL_OF_FAME_TROPHY_HEAP_10, 10), // + HALLOFFAME_TROPHYHEAP_15(HallOfFameAssets.HALL_OF_FAME_TROPHY_HEAP_15, 15), // + HALLOFFAME_TROPHYHEAP_20(HallOfFameAssets.HALL_OF_FAME_TROPHY_HEAP_20, 20), // + HALLOFFAME_TROPHYHEAP_30(HallOfFameAssets.HALL_OF_FAME_TROPHY_HEAP_30, 30), // + HALLOFFAME_TROPHYHEAP_35(HallOfFameAssets.HALL_OF_FAME_TROPHY_HEAP_35, 35), // + HALLOFFAME_TROPHYHEAP_40(HallOfFameAssets.HALL_OF_FAME_TROPHY_HEAP_40, 40), // + HALLOFFAME_TROPHYHEAP_50(HallOfFameAssets.HALL_OF_FAME_TROPHY_HEAP_50, 50), // + HALLOFFAME_TROPHYHEAP_60(HallOfFameAssets.HALL_OF_FAME_TROPHY_HEAP_60, 60); + + private String trophyHeapAsset; + private int starCount; + + private TrophyHeapAssets(String trophyHeapAsset, int starCount) { + this.trophyHeapAsset = trophyHeapAsset; + this.starCount = starCount; + } + + public String getTrophyHeapAssetName() { + return trophyHeapAsset; + } + + public int getStarCount() { + return starCount; + } + + public static String getTrophyHeapImageForStarCount(int starCount) { + for (int i = TrophyHeapAssets.values().length - 1; i >= 0; i--) { + TrophyHeapAssets trophyHeapAssets = TrophyHeapAssets.values()[i]; + if (starCount >= trophyHeapAssets.getStarCount()) { + return trophyHeapAssets.getTrophyHeapAssetName(); + } + } + return TrophyHeapAssets.values()[0].getTrophyHeapAssetName(); + } + } private static final int BACKGROUND_TILE_REPEAT_COUNT = 37; @Override protected void screenLoaded() { - DragListener dragListener = new DragListener(){ - @Override - public void touchDragged(InputEvent event, float x, float y, int pointer) { - super.drag(event, x, y, pointer); - Log.info(getClass().getName(), "[ ------- DELTA X: ------- ]"+getDeltaX()); - Log.info(getClass().getName(), "[ ------- STAGE X: ------- ]"+event.getStageX()); - Log.info(getClass().getName(), "[ ------- X: ------- ]"+x); - getStage().getCamera().translate(getStage().getCamera().viewportWidth-x,0,0); - getStage().getCamera().update(); - } - }; - getStage().addListener(dragListener); - prepareBackground(); - + prepareScrolPane(); + // prepareDoorButton(); } - private void prepareBackground() { + + + private void prepareScrolPane(){ + HorizontalGroup group = new HorizontalGroup(); + group.setHeight(getStage().getHeight()); + + Texture textureDoor = new Texture(HallOfFameAssets.HALL_OF_FAME_DOOR); + Image imgDoor = new Image(textureDoor); + imgDoor.setHeight(getStage().getHeight()); + + group.addActor(imgDoor); + Texture textureTile = new Texture(HallOfFameAssets.HALL_OF_FAME_BACKGROUND_TILE); - Image imgDoor = prepareDoor(); for (int i = 0; i < BACKGROUND_TILE_REPEAT_COUNT; i++) { Image imgBackground = new Image(textureTile); - float currentX = imgDoor.getWidth()+i*imgBackground.getWidth(); - imgBackground.setHeight(getStage().getHeight()); - imgBackground.setX(currentX); - getStage().addActor(imgBackground); + group.addActor(imgBackground); } - Log.info(getClass().getName(), "[ ------- STAGE SIZE: ------- ]"+getStage().getWidth()); + ScrollPane scrollPane = new ScrollPane(group); + scrollPane.setScrollingDisabled(false,true); + scrollPane.setHeight(getStage().getHeight()); + scrollPane.setWidth(getStage().getWidth()); + getStage().addActor(scrollPane); } - private Image prepareDoor(){ - Texture textureDoor = new Texture(HallOfFameAssets.HALL_OF_FAME_DOOR); - - Image imgDoor = new Image(textureDoor); + private void prepareDoorButton(){ + //TODO positioning + final Texture textureDoor = new Texture(HallOfFameAssets.HALL_OF_FAME_DOOR_BUTTON_PRESSED); + final Image imgDoor = new Image(textureDoor); imgDoor.setHeight(getStage().getHeight()); + + imgDoor.addListener(new ClickListener(){ + @Override + public void clicked(InputEvent event, float x, float y) { + Texture textureDoor = new Texture(HallOfFameAssets.HALL_OF_FAME_DOOR_BUTTON_UNPRESSED); + imgDoor.setDrawable(new SpriteDrawable(new Sprite(textureDoor))); + } + }); getStage().addActor(imgDoor); - return imgDoor; } } \ No newline at end of file diff --git a/core/src/cz/nic/tablexia/screen/halloffame/assets/HallOfFameAssets.java b/core/src/cz/nic/tablexia/screen/halloffame/assets/HallOfFameAssets.java index e8cb81a3d..383259b1f 100644 --- a/core/src/cz/nic/tablexia/screen/halloffame/assets/HallOfFameAssets.java +++ b/core/src/cz/nic/tablexia/screen/halloffame/assets/HallOfFameAssets.java @@ -4,13 +4,36 @@ package cz.nic.tablexia.screen.halloffame.assets; * Created by Václav TarantĂk on 2.3.15. */ public final class HallOfFameAssets { + public static final String HALL_OF_FAME_ASSET_PREFIX = "screen_halloffame_"; + public static final String HALL_OF_FAME_ASSET_TROPHYHEAP = "trophyheap_"; public static final String HALL_OF_FAME_PATH = "screen/halloffame/"; public static final String TEXT_PATH = HALL_OF_FAME_PATH + "text/halloffame"; public static final String HALL_OF_FAME_GFX = HALL_OF_FAME_PATH+"gfx/"; - public static final String HALL_OF_FAME_BACKGROUND_TILE = HALL_OF_FAME_GFX+"screen_halloffame_background_tile.jpg"; - public static final String HALL_OF_FAME_DOOR = HALL_OF_FAME_GFX + "screen_halloffame_background_start.jpg"; + public static final String HALL_OF_FAME_BACKGROUND_TILE = HALL_OF_FAME_GFX+HALL_OF_FAME_ASSET_PREFIX+"background_tile.jpg"; + public static final String HALL_OF_FAME_DOOR = HALL_OF_FAME_GFX + HALL_OF_FAME_ASSET_PREFIX+"background_start.jpg"; + public static final String HALL_OF_FAME_DOOR_BUTTON_PRESSED = HALL_OF_FAME_GFX + HALL_OF_FAME_ASSET_PREFIX+"background_door_pressed.png"; + public static final String HALL_OF_FAME_DOOR_BUTTON_UNPRESSED = HALL_OF_FAME_GFX + HALL_OF_FAME_ASSET_PREFIX+"background_door_unpressed.png"; + + public static final String HALL_OF_FAME_TROPHY_HEAP_00 = HALL_OF_FAME_GFX+HALL_OF_FAME_ASSET_PREFIX+HALL_OF_FAME_ASSET_TROPHYHEAP +"00.png"; + public static final String HALL_OF_FAME_TROPHY_HEAP_01 = HALL_OF_FAME_GFX+HALL_OF_FAME_ASSET_PREFIX+HALL_OF_FAME_ASSET_TROPHYHEAP +"01.png"; + public static final String HALL_OF_FAME_TROPHY_HEAP_02 = HALL_OF_FAME_GFX+HALL_OF_FAME_ASSET_PREFIX+HALL_OF_FAME_ASSET_TROPHYHEAP +"02.png"; + public static final String HALL_OF_FAME_TROPHY_HEAP_03 = HALL_OF_FAME_GFX+HALL_OF_FAME_ASSET_PREFIX+HALL_OF_FAME_ASSET_TROPHYHEAP +"03.png"; + public static final String HALL_OF_FAME_TROPHY_HEAP_04 = HALL_OF_FAME_GFX+HALL_OF_FAME_ASSET_PREFIX+HALL_OF_FAME_ASSET_TROPHYHEAP +"04.png"; + public static final String HALL_OF_FAME_TROPHY_HEAP_05 = HALL_OF_FAME_GFX+HALL_OF_FAME_ASSET_PREFIX+HALL_OF_FAME_ASSET_TROPHYHEAP +"05.png"; + public static final String HALL_OF_FAME_TROPHY_HEAP_06 = HALL_OF_FAME_GFX+HALL_OF_FAME_ASSET_PREFIX+HALL_OF_FAME_ASSET_TROPHYHEAP +"06.png"; + public static final String HALL_OF_FAME_TROPHY_HEAP_07 = HALL_OF_FAME_GFX+HALL_OF_FAME_ASSET_PREFIX+HALL_OF_FAME_ASSET_TROPHYHEAP +"07.png"; + public static final String HALL_OF_FAME_TROPHY_HEAP_08 = HALL_OF_FAME_GFX+HALL_OF_FAME_ASSET_PREFIX+HALL_OF_FAME_ASSET_TROPHYHEAP +"08.png"; + public static final String HALL_OF_FAME_TROPHY_HEAP_09 = HALL_OF_FAME_GFX+HALL_OF_FAME_ASSET_PREFIX+HALL_OF_FAME_ASSET_TROPHYHEAP +"09.png"; + public static final String HALL_OF_FAME_TROPHY_HEAP_10 = HALL_OF_FAME_GFX+HALL_OF_FAME_ASSET_PREFIX+HALL_OF_FAME_ASSET_TROPHYHEAP +"10.png"; + public static final String HALL_OF_FAME_TROPHY_HEAP_15 = HALL_OF_FAME_GFX+HALL_OF_FAME_ASSET_PREFIX+HALL_OF_FAME_ASSET_TROPHYHEAP +"15.png"; + public static final String HALL_OF_FAME_TROPHY_HEAP_20 = HALL_OF_FAME_GFX+HALL_OF_FAME_ASSET_PREFIX+HALL_OF_FAME_ASSET_TROPHYHEAP +"20.png"; + public static final String HALL_OF_FAME_TROPHY_HEAP_30 = HALL_OF_FAME_GFX+HALL_OF_FAME_ASSET_PREFIX+HALL_OF_FAME_ASSET_TROPHYHEAP +"30.png"; + public static final String HALL_OF_FAME_TROPHY_HEAP_35 = HALL_OF_FAME_GFX+HALL_OF_FAME_ASSET_PREFIX+HALL_OF_FAME_ASSET_TROPHYHEAP +"35.png"; + public static final String HALL_OF_FAME_TROPHY_HEAP_40 = HALL_OF_FAME_GFX+HALL_OF_FAME_ASSET_PREFIX+HALL_OF_FAME_ASSET_TROPHYHEAP +"40.png"; + public static final String HALL_OF_FAME_TROPHY_HEAP_50 = HALL_OF_FAME_GFX+HALL_OF_FAME_ASSET_PREFIX+HALL_OF_FAME_ASSET_TROPHYHEAP +"50.png"; + public static final String HALL_OF_FAME_TROPHY_HEAP_60 = HALL_OF_FAME_GFX+HALL_OF_FAME_ASSET_PREFIX+HALL_OF_FAME_ASSET_TROPHYHEAP +"60.png"; public static final String HALL_OF_FAME_SFX = HALL_OF_FAME_PATH+"sfx/"; -- GitLab