Skip to content
Snippets Groups Projects
Commit 168a5915 authored by Drahomír Karchňák's avatar Drahomír Karchňák
Browse files

#58 Removed unnecesaary usage of java relflection + little tweaks

parent 8139d131
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,7 @@ import cz.nic.tablexia.menu.game.GameMenuDefinition; ...@@ -8,6 +8,7 @@ import cz.nic.tablexia.menu.game.GameMenuDefinition;
/** /**
* Created by lhoracek on 3/11/15. * Created by lhoracek on 3/11/15.
* Edited by Drahomir Karchnak
*/ */
public final class GameMenuAssets { public final class GameMenuAssets {
...@@ -23,6 +24,45 @@ public final class GameMenuAssets { ...@@ -23,6 +24,45 @@ public final class GameMenuAssets {
STARTBUTTON_PRESSED STARTBUTTON_PRESSED
} }
public enum GameBasePaths {
GAME_ROBBERY(1, "bankovniloupez"),
GAME_PURSUIT(2, "pronasledovani"),
GAME_KIDNAPPING(3, "unos"),
GAME_NIGHT_WATCH(4, "nocnisledovani"),
GAME_SHOOTING_RANGE(5, "strelnice"),
GAME_IN_THE_DARKNESS(6, "potme");
private int id;
private String path;
GameBasePaths(int id, String path) {
this.id = id;
this.path = path;
}
public int getId() {
return id;
}
public String getPath() {
return path;
}
/**
* Gets path to base assets according to game's id
* @param id
* @return path or null, if game with this id doesn't exist
*/
public static String getPathById(int id) {
for(GameBasePaths game : GameBasePaths.values()) {
if(game.getId() == id)
return game.getPath();
}
return null;
}
}
private static final String GFX_PATH = "gfx/"; private static final String GFX_PATH = "gfx/";
public static final String OFFICE = GFX_PATH + "office"; public static final String OFFICE = GFX_PATH + "office";
...@@ -50,15 +90,6 @@ public final class GameMenuAssets { ...@@ -50,15 +90,6 @@ public final class GameMenuAssets {
public static final String WALL_MID = GFX_PATH + "wall_mid"; public static final String WALL_MID = GFX_PATH + "wall_mid";
public static final String WALL_BACK = GFX_PATH + "wall_back"; public static final String WALL_BACK = GFX_PATH + "wall_back";
public static final String GAME_ROBBERY_BASE = "bankovniloupez";
public static final String GAME_PURSUIT_BASE = "pronasledovani";
public static final String GAME_KIDNAPPING_BASE = "unos";
public static final String GAME_SHOOTING_RANGE_BASE = "strelnice";
public static final String GAME_NIGHT_WATCH_BASE = "nocnisledovani";
public static final String GAME_IN_THE_DARKNESS_BASE = "potme";
public static final String TEXT_PATH = "text/gamemenu";
public static List<String> textures = new ArrayList<String>(); public static List<String> textures = new ArrayList<String>();
static { static {
...@@ -87,7 +118,6 @@ public final class GameMenuAssets { ...@@ -87,7 +118,6 @@ public final class GameMenuAssets {
textures.add(WALL_MID); textures.add(WALL_MID);
textures.add(WALL_BACK); textures.add(WALL_BACK);
String baseGameAsset = "MENU_GAME_";
for (GameMenuDefinition gd : GameMenuDefinition.values()) { for (GameMenuDefinition gd : GameMenuDefinition.values()) {
for (GameMenuLayers gml : GameMenuLayers.values()) { for (GameMenuLayers gml : GameMenuLayers.values()) {
textures.add(getResourcePath(gd.getGameDefinition(), gml)); textures.add(getResourcePath(gd.getGameDefinition(), gml));
...@@ -95,12 +125,12 @@ public final class GameMenuAssets { ...@@ -95,12 +125,12 @@ public final class GameMenuAssets {
} }
} }
//TODO - Refactor getResourcePath method
public static String getResourcePath(GameDefinition game, GameMenuLayers layer) { public static String getResourcePath(GameDefinition game, GameMenuLayers layer) {
try { String gameBasePath = GameBasePaths.getPathById(game.getGameNumber());
return GFX_PATH + (GameMenuAssets.class.getField("GAME_" + game.name() + "_BASE").get(null)) + "_" + layer.name().toLowerCase();
} catch (Exception e) { if(gameBasePath == null)
throw new IllegalArgumentException("Error generating path for " + game.name() + " " + layer.name()); throw new IllegalArgumentException("Couldn't find game base assets for ID: " + game.getGameNumber());
} else
return GFX_PATH + gameBasePath + "_" + layer.name().toLowerCase();
} }
} }
\ No newline at end of file
...@@ -177,7 +177,7 @@ public class GameMenuPage extends MenuPage { ...@@ -177,7 +177,7 @@ public class GameMenuPage extends MenuPage {
startButton.addListener(new ClickListenerWithSound() { startButton.addListener(new ClickListenerWithSound() {
@Override @Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
super.touchDown(event, x, y, pointer, button); super.touchDown(event, x + scrollXOffset, y, pointer, button);
startButton.addAction(new AlphaAction()); startButton.addAction(new AlphaAction());
startDownButton.setVisible(true); startDownButton.setVisible(true);
...@@ -189,14 +189,13 @@ public class GameMenuPage extends MenuPage { ...@@ -189,14 +189,13 @@ public class GameMenuPage extends MenuPage {
@Override @Override
public void clicked(InputEvent event, float x, float y) { public void clicked(InputEvent event, float x, float y) {
if(isClick(x, y)) { if(inTapSquare(x, y))
super.clicked(event, x, y); super.clicked(event, x, y);
}
} }
@Override @Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) { public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
super.touchUp(event, x, y, pointer, button); super.touchUp(event, x + scrollXOffset, y, pointer, button);
} }
@Override @Override
......
...@@ -32,28 +32,15 @@ public abstract class MenuPage extends Group { ...@@ -32,28 +32,15 @@ public abstract class MenuPage extends Group {
public abstract void onScroll(float scroll); public abstract void onScroll(float scroll);
public abstract void onScrolledToPage(); public abstract void onScrolledToPage();
/**
* Checks distance between coordinates of the last touchdown event and x, y
* I made this because ClickListeners clicked method doesnt work that good when actor is in scrollpane
* and ClickListeners inTapSquare didn't work on android for some reason
* @param x X coord
* @param y Y coord
* @return returns true if touchup event at x, y was a click
*/
public boolean isClick(float x, float y) {
if(lastTouchX < 0 || lastTouchY < 0) return false;
float deltaX = Math.abs(x - lastTouchX);
float deltaY = Math.abs(y - lastTouchY);
return Math.sqrt(deltaX*deltaX + deltaY*deltaY) <= MAX_CLICK_RADIUS;
}
public void setLastTouch(float x, float y) { public void setLastTouch(float x, float y) {
lastTouchX = x; lastTouchX = x;
lastTouchY = y; lastTouchY = y;
} }
public float getLastTouchX() { return lastTouchX; }
public float getLastTouchY() { return lastTouchY; }
@Override @Override
public void setDebug(boolean enabled) { public void setDebug(boolean enabled) {
super.setDebug(enabled); super.setDebug(enabled);
......
...@@ -77,6 +77,8 @@ public class OfficeMenuPage extends MenuPage { ...@@ -77,6 +77,8 @@ public class OfficeMenuPage extends MenuPage {
//to position all elements correctly //to position all elements correctly
private float pagedScrollPaneOffsetY; private float pagedScrollPaneOffsetY;
private float scrollXOffset = 0;
public OfficeMenuPage(AbstractTablexiaScreen screen) { public OfficeMenuPage(AbstractTablexiaScreen screen) {
super(screen); super(screen);
...@@ -125,7 +127,7 @@ public class OfficeMenuPage extends MenuPage { ...@@ -125,7 +127,7 @@ public class OfficeMenuPage extends MenuPage {
addListener(new ClickListenerWithSound() { addListener(new ClickListenerWithSound() {
@Override @Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
super.touchDown(event, x, y, pointer, button); super.touchDown(event, x + scrollXOffset, y, pointer, button);
setLastTouch(x, y); setLastTouch(x, y);
...@@ -156,13 +158,13 @@ public class OfficeMenuPage extends MenuPage { ...@@ -156,13 +158,13 @@ public class OfficeMenuPage extends MenuPage {
@Override @Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) { public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
super.touchUp(event, x, y, pointer, button); super.touchUp(event, x + scrollXOffset, y, pointer, button);
hideAllActions(); hideAllActions();
} }
@Override @Override
public void clicked(InputEvent event, float x, float y) { public void clicked(InputEvent event, float x, float y) {
if(!isClick(x, y)) if(!inTapSquare(x, y))
return; return;
Color color = getTouchedColor(x, y); Color color = getTouchedColor(x, y);
...@@ -299,7 +301,9 @@ public class OfficeMenuPage extends MenuPage { ...@@ -299,7 +301,9 @@ public class OfficeMenuPage extends MenuPage {
} }
@Override @Override
public void onScroll(float offset) {} public void onScroll(float offset) {
scrollXOffset = offset;
}
/** /**
* Toggles (FadeIn/FadeOut) help overlay * Toggles (FadeIn/FadeOut) help overlay
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment