From 05d309718915e30051273c4b12a85d513196102d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Hor=C3=A1=C4=8Dek?= <horaceklubos@gmail.com> Date: Mon, 30 Mar 2015 18:01:58 +0200 Subject: [PATCH] #11 Clickmap in office --- .../screen/gamemenu/GameMenuAssets.java | 2 + .../screen/gamemenu/pages/GameMenuPage.java | 16 +++++- .../screen/gamemenu/pages/OfficeMenuPage.java | 55 ++++++++++++++++++- 3 files changed, 70 insertions(+), 3 deletions(-) diff --git a/core/src/cz/nic/tablexia/screen/gamemenu/GameMenuAssets.java b/core/src/cz/nic/tablexia/screen/gamemenu/GameMenuAssets.java index 0cd9edead..20c688976 100644 --- a/core/src/cz/nic/tablexia/screen/gamemenu/GameMenuAssets.java +++ b/core/src/cz/nic/tablexia/screen/gamemenu/GameMenuAssets.java @@ -21,6 +21,7 @@ public final class GameMenuAssets { private static final String GAMEMENU_PATH = "screen/gamemenu/"; public static final String OFFICE = GAMEMENU_PATH + "office.jpg"; + public static final String OFFICE_CLICKMAP = GAMEMENU_PATH + "clickablemap.png"; public static final String OFFICE_HELP = GAMEMENU_PATH + "helplayer.png"; public static final String VIGNETTE = GAMEMENU_PATH + "vignetting.png"; public static final String DESK = GAMEMENU_PATH + "desk.png"; @@ -49,6 +50,7 @@ public final class GameMenuAssets { static { textures.add(OFFICE); + textures.add(OFFICE_CLICKMAP); textures.add(DESK); textures.add(OFFICE_HELP); textures.add(VIGNETTE); diff --git a/core/src/cz/nic/tablexia/screen/gamemenu/pages/GameMenuPage.java b/core/src/cz/nic/tablexia/screen/gamemenu/pages/GameMenuPage.java index e6fa02398..b36b5cc80 100644 --- a/core/src/cz/nic/tablexia/screen/gamemenu/pages/GameMenuPage.java +++ b/core/src/cz/nic/tablexia/screen/gamemenu/pages/GameMenuPage.java @@ -55,10 +55,22 @@ public class GameMenuPage extends MenuPage implements ViewPager.ScrollListener { addActor(diffButton); diffButton.addListener(new DragListener() { + float lastX; + + @Override + public void dragStart(InputEvent event, float x, float y, int pointer) { + super.dragStart(event, x, y, pointer); + lastX = x; + event.handle(); + } + @Override public void drag(InputEvent event, float x, float y, int pointer) { super.drag(event, x, y, pointer); - diffButton.setX(diffButton.getX() + x); + // example code below for origin and position + //diffButton.setPosition(lastX - x, diffButton.getY()); + lastX = x; + event.handle(); } }); } @@ -72,7 +84,7 @@ public class GameMenuPage extends MenuPage implements ViewPager.ScrollListener { int srcWidth = (int) (back.getWidth() - (scrollHalf * 2)); float x = getX() + Math.abs(Math.min(scrollOffset, 0)); float width = getWidth() - Math.abs(scrollOffset); - + batch.draw(back, x, getY(), width, getHeight(), srcX, 0, srcWidth, back.getHeight(), false, false); batch.draw(getScreen().getTexture(GameMenuAssets.getResourcePath(game, GameMenuAssets.GameMenuLayers.MID)), getX(), getY(), getWidth(), getHeight()); batch.draw(getScreen().getTexture(GameMenuAssets.getResourcePath(game, GameMenuAssets.GameMenuLayers.FORE)), getX() + (scrollOffset / 2), getY(), getWidth(), getHeight()); diff --git a/core/src/cz/nic/tablexia/screen/gamemenu/pages/OfficeMenuPage.java b/core/src/cz/nic/tablexia/screen/gamemenu/pages/OfficeMenuPage.java index 5218309ef..d9a60ffbb 100644 --- a/core/src/cz/nic/tablexia/screen/gamemenu/pages/OfficeMenuPage.java +++ b/core/src/cz/nic/tablexia/screen/gamemenu/pages/OfficeMenuPage.java @@ -1,16 +1,70 @@ package cz.nic.tablexia.screen.gamemenu.pages; +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.Pixmap; +import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.scenes.scene2d.InputEvent; +import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; +import cz.nic.tablexia.menu.MainMenuDefinition; import cz.nic.tablexia.screen.AbstractTablexiaScreen; import cz.nic.tablexia.screen.gamemenu.GameMenuAssets; +import cz.nic.tablexia.util.Log; /** * Created by lhoracek on 3/4/15. */ public class OfficeMenuPage extends MenuPage { + + public static final Color STREET_COLOR = Color.YELLOW; + public static final Color HALLOFFAME_COLOR = Color.GREEN; + public static final Color STATISTICS_COLOR = Color.RED; + public static final Color ENCYCLOPEDIA_COLOR = Color.BLACK; + public static final Color PROFILE_COLOR = Color.BLUE; + + public OfficeMenuPage(AbstractTablexiaScreen screen) { super(screen); + addListener(new ClickListener() { + @Override + public void clicked(InputEvent event, float x, float y) { + super.clicked(event, x, y); + + Color color = getTouchedColor(x, y); + + if (color.equals(ENCYCLOPEDIA_COLOR)) { + MainMenuDefinition.ENCYCLOPEDIA.performAction(); + } else if (color.equals(STATISTICS_COLOR)) { + MainMenuDefinition.STATISTICS.performAction(); + } else if (color.equals(HALLOFFAME_COLOR)) { + MainMenuDefinition.HALL_OF_FAME.performAction(); + } else if (color.equals(STREET_COLOR)) { + Log.info(((Object) this).getClass().getName(), "Clicked STREET_COLOR"); + // TODO go to street + } else if (color.equals(PROFILE_COLOR)) { + // TODO show profile + } else { + // TODO hide help layer + } + } + }); + } + + + private Color getTouchedColor(float x, float y) { + Texture clickmap = getScreen().getTexture(GameMenuAssets.OFFICE_CLICKMAP); + if (!clickmap.getTextureData().isPrepared()) { + clickmap.getTextureData().prepare(); + } + + Pixmap pixmap = clickmap.getTextureData().consumePixmap(); + int clickX = (int) (x / getWidth() * clickmap.getWidth()); + int clickY = clickmap.getHeight() - (int) (y / getHeight() * clickmap.getHeight()); + + Log.info(((Object) this).getClass().getName(), "Color map " + clickmap.getWidth() + ":" + clickmap.getHeight() + " at " + clickX + ": " + clickY); + + return new Color(pixmap.getPixel(clickX, clickY)); } @@ -28,6 +82,5 @@ public class OfficeMenuPage extends MenuPage { batch.draw(getScreen().getTexture(GameMenuAssets.HALLOFFAME_PRESSED), getX(), getY(), getWidth(), getHeight()); batch.draw(getScreen().getTexture(GameMenuAssets.OFFICE_HELP), getX(), getY(), getWidth(), getHeight()); - } } -- GitLab