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

#12 Auto x-filling centering viewport

parent 3f193235
Branches
Tags
No related merge requests found
core/assets/common/screen/debug/black.png

86 B

core/assets/common/screen/debug/blue.png

86 B

core/assets/common/screen/debug/pink.png

86 B

core/assets/common/screen/debug/red.png

86 B

core/assets/common/screen/debug/yellow.png

86 B

......@@ -13,7 +13,7 @@ import cz.nic.tablexia.game.GameDefinition;
import cz.nic.tablexia.game.difficulty.GameDifficulty;
import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.screen.AbstractTablexiaScreen;
import cz.nic.tablexia.screen.gamemenu.GameMenuScreen;
import cz.nic.tablexia.screen.viewport.ViewportDebugScreen;
import cz.nic.tablexia.util.Log;
import cz.nic.tablexia.util.Utility;
......@@ -24,7 +24,7 @@ public class TablexiaSettings {
private static final int MIN_SCREEN_HEIGHT = (int) (DEFAULT_SCREEN_WIDTH * MAXIMUM_RATIO);
private static final boolean DEBUG_SHOW_BOUNDING_BOXES = true;
public static final Class<? extends AbstractTablexiaScreen<?>> INITIAL_SCREEN = GameMenuScreen.class;
public static final Class<? extends AbstractTablexiaScreen<?>> INITIAL_SCREEN = ViewportDebugScreen.class;
private static final String PREFERENCES_KEY = "cz.nic.tablexia.";
public static final String LOCALE_KEY = "locale";
......
package cz.nic.tablexia.screen.loader;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
......@@ -12,7 +13,7 @@ public class LoaderScreen extends AbstractTablexiaScreen<Void> {
private static final String LOADER_BACKGROUND = "gfx/screen_loader_background.jpg";
private static final String LOADER_SMALL_HAND = "gfx/screen_loader_smallhand.png";
private static final String LOADER_BIG_HAND = "gfx/screen_loader_bighand.png";
private static final String LOADER_BIG_HAND = "gfx/screen_loader_bighand.png";
public LoaderScreen() {
super(false, false, TablexiaAssetManager.StorageType.INTERNAL);
......@@ -33,17 +34,24 @@ public class LoaderScreen extends AbstractTablexiaScreen<Void> {
getStage().addActor(background);
Image smallhand = new Image(getTexture(LOADER_SMALL_HAND));
smallhand.setPosition(getStage().getWidth()*0.22f, getStage().getHeight() * 0.64f);
smallhand.setSize(getStage().getWidth()*0.01f, getStage().getHeight()*0.06f);
smallhand.setPosition(getStage().getWidth() * 0.22f, getStage().getHeight() * 0.64f);
smallhand.setSize(getStage().getWidth() * 0.01f, getStage().getHeight() * 0.06f);
getStage().addActor(smallhand);
smallhand.setOrigin(smallhand.getWidth()/2,0);
smallhand.setOrigin(smallhand.getWidth() / 2, 0);
smallhand.addAction(Actions.forever(Actions.rotateBy(-360, 6)));
Image bighand = new Image(getTexture(LOADER_BIG_HAND));
bighand.setPosition(getStage().getWidth()*0.22f, getStage().getHeight() * 0.64f);
bighand.setSize(getStage().getWidth()*0.01f, getStage().getHeight()*0.06f);
bighand.setPosition(getStage().getWidth() * 0.22f, getStage().getHeight() * 0.64f);
bighand.setSize(getStage().getWidth() * 0.01f, getStage().getHeight() * 0.06f);
getStage().addActor(bighand);
bighand.setOrigin(bighand.getWidth()/2,0);
bighand.setOrigin(bighand.getWidth() / 2, 0);
bighand.addAction(Actions.forever(Actions.rotateBy(-360, 0.5f)));
}
@Override
public Texture getTexture(String textureName) {
Texture t = super.getTexture(textureName);
t.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
return t;
}
}
package cz.nic.tablexia.screen.viewport;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import java.util.List;
import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.screen.AbstractTablexiaScreen;
/**
* Created by lhoracek on 4/13/15.
*/
public class ViewportDebugScreen extends AbstractTablexiaScreen<Void> {
private static final String BASE = "screen/debug/";
@Override
protected void prepareScreenTextureAssetNames(List<String> textureFileNames) {
textureFileNames.add(BASE + "red.png");
textureFileNames.add(BASE + "blue.png");
textureFileNames.add(BASE + "yellow.png");
textureFileNames.add(BASE + "pink.png");
textureFileNames.add(BASE + "black.png");
}
@Override
protected void screenLoaded() {
getStage().setDebugAll(true);
Image large = new Image(getTexture("yellow.png"));
large.setSize(TablexiaSettings.getDefaultScreenWidth(), TablexiaSettings.getMinScreenHeight()*2);
large.setPosition(0,TablexiaSettings.getMinScreenHeight()/-2.0f);
getStage().addActor(large);
Image widescreen = new Image(getTexture("red.png"));
widescreen.setSize(TablexiaSettings.getDefaultScreenWidth(), TablexiaSettings.getMinScreenHeight());
widescreen.setPosition(0,0);
getStage().addActor(widescreen);
// TODO
}
@Override
public Texture getTexture(String textureName) {
return super.getTexture(BASE + textureName);
}
}
package cz.nic.tablexia.util.ui;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.utils.viewport.Viewport;
......@@ -12,9 +13,6 @@ import cz.nic.tablexia.util.Log;
*/
public class XFillViewport extends Viewport {
private float worldWidth, worldHeight;
/**
* Creates a new viewport using a new {@link com.badlogic.gdx.graphics.OrthographicCamera} with no maximum world size.
*/
......@@ -31,10 +29,35 @@ public class XFillViewport extends Viewport {
setCamera(camera);
}
private int screenX, screenY, screenWidth, screenHeight;
private float cameraYOffset;
@Override
public void update(int screenWidth, int screenHeight, boolean centerCamera) {
int height = (int) Math.min(screenHeight, screenWidth * TablexiaSettings.getMaximumRatio());
setScreenBounds(0, Math.max(0, (screenHeight - height) / 2), screenWidth, height);
float newWorldHeight = getWorldWidth() / ((float) screenWidth / (float) screenHeight);
// FIT into screen keeping at least minimum ration
this.screenX = (newWorldHeight < TablexiaSettings.getMinScreenHeight()) ? ((int) ((screenWidth - (screenHeight / TablexiaSettings.getMaximumRatio())) / 2)) : 0;
this.screenY = 0;
this.screenWidth = (newWorldHeight < TablexiaSettings.getMinScreenHeight()) ? ((int) (screenHeight / TablexiaSettings.getMaximumRatio())) : screenWidth;
this.screenHeight = screenHeight;
// SET NEW WORLD HEIGHT
this.setWorldHeight(newWorldHeight < TablexiaSettings.getMinScreenHeight() ? TablexiaSettings.getMinScreenHeight() : newWorldHeight); // World width dooes not change
cameraYOffset = (getWorldHeight() - TablexiaSettings.getMinScreenHeight()) / 2;
Log.info(getClass().getName(), "New viewport size: update: " + screenWidth + "x" + screenHeight + " - position: " + screenX + "x" + screenY + " - bounds: " + this.screenWidth + "x" + this.screenHeight + " - world: " + getWorldWidth() + "x" + getWorldHeight() + " - y offset: " + cameraYOffset);
apply(centerCamera);
}
@Override
public void apply(boolean centerCamera) {
Gdx.gl.glViewport(screenX, screenY, screenWidth, screenHeight);
getCamera().viewportWidth = getWorldWidth();
getCamera().viewportHeight = getWorldHeight();
if (centerCamera) getCamera().position.set(getWorldWidth() / 2, getWorldHeight() / 2, 0);
getCamera().position.y -= cameraYOffset;
getCamera().update();
}
}
\ No newline at end of file
......@@ -32,7 +32,7 @@ public class DesktopLauncher {
String versionName = loadAttributeFromManifest(VERSION_NAME_MANIFEST_ATTRIBUTE);
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.resizable = false;
config.resizable = buildType == null || buildType.equals(TablexiaSettings.BuildType.DEVEL.getKey());
config.width = 1280;
config.height = 800;
......
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