summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2015-02-06 12:24:12 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2015-02-08 23:46:57 +0100
commitcf428773cfdabd137eecee3c9313e355c16b4872 (patch)
tree4245578ef8691656fbf0c5cb4336b2e0210dcd07 /core/src/ch/asynk
parent88a0900bc5486da860580a108c2d13519573e85a (diff)
downloadRustAndDust-cf428773cfdabd137eecee3c9313e355c16b4872.zip
RustAndDust-cf428773cfdabd137eecee3c9313e355c16b4872.tar.gz
Screens: add hud size correction depending on screen density
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r--core/src/ch/asynk/tankontank/TankOnTank.java4
-rw-r--r--core/src/ch/asynk/tankontank/game/Hud.java4
-rw-r--r--core/src/ch/asynk/tankontank/screens/GameCamera.java28
-rw-r--r--core/src/ch/asynk/tankontank/screens/GameScreen.java8
-rw-r--r--core/src/ch/asynk/tankontank/screens/MenuCamera.java36
-rw-r--r--core/src/ch/asynk/tankontank/screens/MenuScreen.java4
6 files changed, 67 insertions, 17 deletions
diff --git a/core/src/ch/asynk/tankontank/TankOnTank.java b/core/src/ch/asynk/tankontank/TankOnTank.java
index 40e4240..70b118f 100644
--- a/core/src/ch/asynk/tankontank/TankOnTank.java
+++ b/core/src/ch/asynk/tankontank/TankOnTank.java
@@ -20,6 +20,7 @@ public class TankOnTank extends Game
public Factory factory;
public Ctrl ctrl;
public Config config;
+ public int hudCorrection;
public TextureAtlas uiAtlas;
public TextureAtlas menuAtlas;
@@ -48,7 +49,8 @@ public class TankOnTank extends Game
public void create ()
{
Gdx.app.setLogLevel(Gdx.app.LOG_DEBUG);
- debug("TankOnTank", "create() [" + Gdx.graphics.getWidth() + ";" + Gdx.graphics.getHeight() + "] " + Gdx.graphics.getDensity());
+ this.hudCorrection = ((int) (125 * Gdx.graphics.getDensity()) - 75);
+ debug("TankOnTank", "create() [" + Gdx.graphics.getWidth() + ";" + Gdx.graphics.getHeight() + "] " + Gdx.graphics.getDensity() + " -> " + hudCorrection);
manager = new AssetManager();
factory = new Factory(this);
diff --git a/core/src/ch/asynk/tankontank/game/Hud.java b/core/src/ch/asynk/tankontank/game/Hud.java
index 5aa8075..0afc999 100644
--- a/core/src/ch/asynk/tankontank/game/Hud.java
+++ b/core/src/ch/asynk/tankontank/game/Hud.java
@@ -69,9 +69,9 @@ public class Hud implements Disposable, Animation
stats.dispose();
}
- public void resize(int width, int height)
+ public void resize(int left, int bottom, int width, int height)
{
- Position.update(width, height);
+ Position.update(left, bottom, width, height);
playerInfo.updatePosition();
actionButtons.updatePosition();
msg.updatePosition();
diff --git a/core/src/ch/asynk/tankontank/screens/GameCamera.java b/core/src/ch/asynk/tankontank/screens/GameCamera.java
index b812269..52ef271 100644
--- a/core/src/ch/asynk/tankontank/screens/GameCamera.java
+++ b/core/src/ch/asynk/tankontank/screens/GameCamera.java
@@ -24,8 +24,11 @@ public class GameCamera extends OrthographicCamera
private Rectangle window;
private Matrix4 hudMatrix;
private Matrix4 hudInvProjMatrix;
+ private int hudCorrection;
+ private int hudLeft;
+ private int hudBottom;
- public GameCamera(float virtualWidth, float virtualHeight, float zoomOut, float zoomIn)
+ public GameCamera(float virtualWidth, float virtualHeight, float zoomOut, float zoomIn, int hudCorrection)
{
super(virtualWidth, virtualHeight);
this.zoomOut = zoomOut;
@@ -36,6 +39,9 @@ public class GameCamera extends OrthographicCamera
this.window = new Rectangle();
this.hudMatrix = new Matrix4();
this.hudInvProjMatrix = new Matrix4();
+ this.hudLeft = 0;
+ this.hudBottom = 0;
+ this.hudCorrection = hudCorrection;
}
public void updateViewport(int screenWidth, int screenHeight)
@@ -52,12 +58,16 @@ public class GameCamera extends OrthographicCamera
window.x = ((screenWidth - window.width) / 2f);
window.y = 0f;
viewportWidth = (viewportHeight * (window.width / window.height));
+ hudBottom = hudCorrection;
+ hudLeft = (int) (hudBottom * viewportWidth / viewportHeight);
} else if (diff > ZEROF) {
window.width = screenWidth;
window.height = java.lang.Math.min((screenWidth * viewportAspect / zoom), screenHeight);
window.x = 0f;
window.y = ((screenHeight - window.height) / 2f);
viewportHeight = (viewportWidth * (window.height / window.width));
+ hudLeft = hudCorrection;
+ hudBottom = (int) (hudLeft / viewportWidth * viewportHeight);
}
Gdx.gl.glViewport((int)window.x, (int)window.y, (int)window.width, (int)window.height);
@@ -68,7 +78,7 @@ public class GameCamera extends OrthographicCamera
clampPosition();
update(true);
hudMatrix.set(combined);
- hudMatrix.setToOrtho2D(0, 0, window.width, window.height);
+ hudMatrix.setToOrtho2D(getHudLeft(), getHudBottom(), getHudWidth(), getHudHeight());
hudInvProjMatrix.set(hudMatrix);
Matrix4.inv(hudInvProjMatrix.val);
}
@@ -88,14 +98,24 @@ public class GameCamera extends OrthographicCamera
return screenHeight;
}
+ public int getHudLeft()
+ {
+ return hudLeft;
+ }
+
+ public int getHudBottom()
+ {
+ return hudBottom;
+ }
+
public int getHudWidth()
{
- return (int) window.width;
+ return (int) window.width - (2 * getHudLeft());
}
public int getHudHeight()
{
- return (int) window.height;
+ return (int) window.height - (2 * getHudBottom());
}
public void centerOnWorld()
diff --git a/core/src/ch/asynk/tankontank/screens/GameScreen.java b/core/src/ch/asynk/tankontank/screens/GameScreen.java
index a71e52e..d5fa401 100644
--- a/core/src/ch/asynk/tankontank/screens/GameScreen.java
+++ b/core/src/ch/asynk/tankontank/screens/GameScreen.java
@@ -54,7 +54,7 @@ public class GameScreen implements Screen
this.batch = new SpriteBatch();
this.ctrl = new Ctrl(game, game.config.battle);
- this.cam = new GameCamera(ctrl.map.getWidth(), ctrl.map.getHeight(), ZOOM_OUT_MAX, ZOOM_IN_MAX);
+ this.cam = new GameCamera(ctrl.map.getWidth(), ctrl.map.getHeight(), ZOOM_OUT_MAX, ZOOM_IN_MAX, game.hudCorrection);
if (DEBUG) this.debugShapes = new ShapeRenderer();
@@ -73,7 +73,7 @@ public class GameScreen implements Screen
cam.zoom(ZOOM_GESTURE_FACTOR);
else
cam.zoom(-ZOOM_GESTURE_FACTOR);
- ctrl.hud.resize(cam.getHudWidth(), cam.getHudHeight());
+ ctrl.hud.resize(cam.getHudLeft(), cam.getHudBottom(), cam.getHudWidth(), cam.getHudHeight());
blocked = true;
inputDelay = INPUT_DELAY;
return true;
@@ -120,7 +120,7 @@ public class GameScreen implements Screen
public boolean scrolled(int amount)
{
cam.zoom(amount * ZOOM_SCROLL_FACTOR);
- ctrl.hud.resize(cam.getHudWidth(), cam.getHudHeight());
+ ctrl.hud.resize(cam.getHudLeft(), cam.getHudBottom(), cam.getHudWidth(), cam.getHudHeight());
return true;
}
});
@@ -179,7 +179,7 @@ public class GameScreen implements Screen
{
// TankOnTank.debug("GameScreen", "resize (" + width + "," + height + ")");
cam.updateViewport(width, height);
- ctrl.hud.resize(cam.getHudWidth(), cam.getHudHeight());
+ ctrl.hud.resize(cam.getHudLeft(), cam.getHudBottom(), cam.getHudWidth(), cam.getHudHeight());
}
@Override
diff --git a/core/src/ch/asynk/tankontank/screens/MenuCamera.java b/core/src/ch/asynk/tankontank/screens/MenuCamera.java
index 99edc87..9e27f16 100644
--- a/core/src/ch/asynk/tankontank/screens/MenuCamera.java
+++ b/core/src/ch/asynk/tankontank/screens/MenuCamera.java
@@ -13,11 +13,14 @@ public class MenuCamera extends OrthographicCamera
private float virtualAspect;
private final Rectangle virtual;
private final Rectangle window;
+ private int hudLeft;
+ private int hudBottom;
+ private int hudCorrection;
private Matrix4 uiMatrix;
private Matrix4 uiInvProjMatrix;
- public MenuCamera(int cx, int cy, int width, int height)
+ public MenuCamera(int cx, int cy, int width, int height, int hudCorrection)
{
super(width, height);
this.virtual = new Rectangle();
@@ -26,6 +29,9 @@ public class MenuCamera extends OrthographicCamera
this.window = new Rectangle();
this.window.set(0, 0, 0, 0);
this.position.set(virtual.x, virtual.y, 0f);
+ this.hudLeft = 0;
+ this.hudBottom = 0;
+ this.hudCorrection = hudCorrection;
this.uiMatrix = new Matrix4();
this.uiInvProjMatrix = new Matrix4();
@@ -44,15 +50,17 @@ public class MenuCamera extends OrthographicCamera
viewportHeight = (virtual.width / aspect);
}
- window.width= screenWidth;
- window.height= screenHeight;
+ window.width = screenWidth;
+ window.height = screenHeight;
+ hudLeft = hudCorrection;
+ hudBottom = (int) (hudLeft / aspect);
Gdx.gl.glViewport((int)window.x, (int)window.y, (int)window.width, (int)window.height);
update(true);
uiMatrix.set(combined);
- uiMatrix.setToOrtho2D(0, 0, screenWidth, screenHeight);
+ uiMatrix.setToOrtho2D(getHudLeft(), getHudBottom(), getHudWidth(), getHudHeight());
uiInvProjMatrix.set(uiMatrix);
Matrix4.inv(uiInvProjMatrix.val);
}
@@ -67,6 +75,26 @@ public class MenuCamera extends OrthographicCamera
return window.height;
}
+ public int getHudLeft()
+ {
+ return hudLeft;
+ }
+
+ public int getHudBottom()
+ {
+ return hudBottom;
+ }
+
+ public int getHudWidth()
+ {
+ return (int) window.width - (2 * getHudLeft());
+ }
+
+ public int getHudHeight()
+ {
+ return (int) window.height - (2 * getHudBottom());
+ }
+
public void uiUnproject(float x, float y, Vector3 v)
{
x = x - window.x;
diff --git a/core/src/ch/asynk/tankontank/screens/MenuScreen.java b/core/src/ch/asynk/tankontank/screens/MenuScreen.java
index cc6d567..f47ba2d 100644
--- a/core/src/ch/asynk/tankontank/screens/MenuScreen.java
+++ b/core/src/ch/asynk/tankontank/screens/MenuScreen.java
@@ -67,7 +67,7 @@ public class MenuScreen implements Screen
float width = Gdx.graphics.getWidth();
float height = Gdx.graphics.getHeight();
- this.camera = new MenuCamera(V_CENTER_X, V_CENTER_Y, V_WIDTH, V_HEIGHT);
+ this.camera = new MenuCamera(V_CENTER_X, V_CENTER_Y, V_WIDTH, V_HEIGHT, game.hudCorrection);
this.gameAssetsLoading = false;
@@ -208,7 +208,7 @@ public class MenuScreen implements Screen
private void update(int width, int height)
{
camera.updateViewport(width, height);
- Position.update(width, height);
+ Position.update(camera.getHudLeft(), camera.getHudBottom(), camera.getHudWidth(), camera.getHudHeight());
setCenteredPosition(from, xPath[0], yPath[0]);
setCenteredPosition(to, xPath[n - 1], yPath[n - 1]);