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

#11 Clickmap in office

parent f60ab1b6
Branches
Tags
No related merge requests found
......@@ -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);
......
......@@ -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());
......
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());
}
}
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