mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
Start input handling
This commit is contained in:
@@ -1,24 +1,23 @@
|
|||||||
package forge;
|
package forge;
|
||||||
|
|
||||||
import com.badlogic.gdx.Screen;
|
|
||||||
|
|
||||||
import forge.Forge.Graphics;
|
import forge.Forge.Graphics;
|
||||||
import forge.assets.FSkinColor;
|
import forge.assets.FSkinColor;
|
||||||
import forge.assets.FSkinImage;
|
import forge.assets.FSkinImage;
|
||||||
import forge.assets.FSkinColor.Colors;
|
import forge.assets.FSkinColor.Colors;
|
||||||
import forge.toolbox.FContainer;
|
import forge.toolbox.FContainer;
|
||||||
|
|
||||||
public abstract class FScreen extends FContainer implements Screen {
|
public abstract class FScreen extends FContainer {
|
||||||
private static final FSkinColor clrTheme = FSkinColor.get(Colors.CLR_THEME);
|
private static final FSkinColor clrTheme = FSkinColor.get(Colors.CLR_THEME);
|
||||||
|
|
||||||
@Override
|
public void onOpen() {
|
||||||
public final void resize(int width, int height) {
|
|
||||||
setSize(width, height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public boolean onSwitch() {
|
||||||
public final void render(float delta) {
|
return true;
|
||||||
Graphics.drawScreen(this);
|
}
|
||||||
|
|
||||||
|
public boolean onClose() {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -26,24 +25,4 @@ public abstract class FScreen extends FContainer implements Screen {
|
|||||||
g.drawImage(FSkinImage.BG_TEXTURE, 0, 0, getWidth(), getHeight());
|
g.drawImage(FSkinImage.BG_TEXTURE, 0, 0, getWidth(), getHeight());
|
||||||
g.fillRect(clrTheme, 0, 0, getWidth(), getHeight());
|
g.fillRect(clrTheme, 0, 0, getWidth(), getHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void show() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void hide() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void pause() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void resume() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void dispose() {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package forge;
|
|||||||
|
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
import com.badlogic.gdx.Game;
|
import com.badlogic.gdx.ApplicationListener;
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.GL10;
|
import com.badlogic.gdx.graphics.GL10;
|
||||||
@@ -13,7 +13,10 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
|||||||
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
|
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
|
||||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
|
||||||
|
import com.badlogic.gdx.input.GestureDetector;
|
||||||
|
import com.badlogic.gdx.input.GestureDetector.GestureListener;
|
||||||
import com.badlogic.gdx.math.Rectangle;
|
import com.badlogic.gdx.math.Rectangle;
|
||||||
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.badlogic.gdx.scenes.scene2d.utils.ScissorStack;
|
import com.badlogic.gdx.scenes.scene2d.utils.ScissorStack;
|
||||||
|
|
||||||
import forge.assets.FSkin;
|
import forge.assets.FSkin;
|
||||||
@@ -23,12 +26,13 @@ import forge.assets.FSkinImage;
|
|||||||
import forge.screens.home.HomeScreen;
|
import forge.screens.home.HomeScreen;
|
||||||
import forge.toolbox.FDisplayObject;
|
import forge.toolbox.FDisplayObject;
|
||||||
|
|
||||||
public class Forge extends Game {
|
public class Forge implements ApplicationListener {
|
||||||
private static Forge game;
|
private static Forge game;
|
||||||
private static int screenWidth;
|
private static int screenWidth;
|
||||||
private static int screenHeight;
|
private static int screenHeight;
|
||||||
private static SpriteBatch batch;
|
private static SpriteBatch batch;
|
||||||
private static ShapeRenderer shapeRenderer;
|
private static ShapeRenderer shapeRenderer;
|
||||||
|
private static FScreen currentScreen;
|
||||||
private static final Stack<FScreen> screens = new Stack<FScreen>();
|
private static final Stack<FScreen> screens = new Stack<FScreen>();
|
||||||
|
|
||||||
public Forge() {
|
public Forge() {
|
||||||
@@ -43,6 +47,7 @@ public class Forge extends Game {
|
|||||||
batch = new SpriteBatch();
|
batch = new SpriteBatch();
|
||||||
shapeRenderer = new ShapeRenderer();
|
shapeRenderer = new ShapeRenderer();
|
||||||
Gdx.graphics.setContinuousRendering(false); //save power consumption by disabling continuous rendering
|
Gdx.graphics.setContinuousRendering(false); //save power consumption by disabling continuous rendering
|
||||||
|
Gdx.input.setInputProcessor(new GestureDetector(new FGestureListener()));
|
||||||
|
|
||||||
FSkin.loadLight("journeyman", true);
|
FSkin.loadLight("journeyman", true);
|
||||||
FSkin.loadFull(true);
|
FSkin.loadFull(true);
|
||||||
@@ -51,47 +56,112 @@ public class Forge extends Game {
|
|||||||
|
|
||||||
public static void back() {
|
public static void back() {
|
||||||
if (screens.size() < 2) { return; } //don't allow going back from initial screen
|
if (screens.size() < 2) { return; } //don't allow going back from initial screen
|
||||||
screens.pop().dispose();
|
screens.pop();
|
||||||
game.setScreen(screens.lastElement());
|
setCurrentScreen(screens.lastElement());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void openScreen(FScreen screen0) {
|
public static void openScreen(FScreen screen0) {
|
||||||
if (game.getScreen() == screen0) { return; }
|
if (currentScreen == screen0) { return; }
|
||||||
screens.push(screen0);
|
screens.push(screen0);
|
||||||
game.setScreen(screen0);
|
setCurrentScreen(screen0);
|
||||||
|
screen0.onOpen();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setCurrentScreen(FScreen screen0) {
|
||||||
|
currentScreen = screen0;
|
||||||
|
currentScreen.setSize(screenWidth, screenHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render () {
|
public void render () {
|
||||||
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); // Clear the screen.
|
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); // Clear the screen.
|
||||||
|
if (currentScreen != null) {
|
||||||
batch.begin();
|
batch.begin();
|
||||||
super.render();
|
Graphics g = new Graphics();
|
||||||
|
currentScreen.draw(g);
|
||||||
batch.end();
|
batch.end();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resize(int width, int height) {
|
public void resize(int width, int height) {
|
||||||
super.resize(width, height);
|
|
||||||
screenWidth = width;
|
screenWidth = width;
|
||||||
screenHeight = height;
|
screenHeight = height;
|
||||||
|
if (currentScreen != null) {
|
||||||
|
currentScreen.setSize(width, height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pause() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resume() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose () {
|
public void dispose () {
|
||||||
super.dispose();
|
currentScreen = null;
|
||||||
|
screens.clear();
|
||||||
batch.dispose();
|
batch.dispose();
|
||||||
shapeRenderer.dispose();
|
shapeRenderer.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class FGestureListener implements GestureListener {
|
||||||
|
@Override
|
||||||
|
public boolean touchDown(float x, float y, int pointer, int button) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean tap(float x, float y, int count, int button) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean longPress(float x, float y) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean fling(float velocityX, float velocityY, int button) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean pan(float x, float y, float deltaX, float deltaY) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean panStop(float x, float y, int pointer, int button) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean zoom(float initialDistance, float distance) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean pinch(Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class Graphics {
|
public static class Graphics {
|
||||||
private Rectangle bounds;
|
private Rectangle bounds;
|
||||||
private int failedClipCount;
|
private int failedClipCount;
|
||||||
|
|
||||||
public static void drawScreen(FScreen screen) {
|
|
||||||
Graphics g = new Graphics();
|
|
||||||
g.draw(screen);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Graphics() {
|
private Graphics() {
|
||||||
bounds = new Rectangle(0, 0, screenWidth, screenHeight);
|
bounds = new Rectangle(0, 0, screenWidth, screenHeight);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package forge.toolbox;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.math.Vector2;
|
||||||
|
|
||||||
import forge.Forge.Graphics;
|
import forge.Forge.Graphics;
|
||||||
|
|
||||||
public abstract class FContainer extends FDisplayObject {
|
public abstract class FContainer extends FDisplayObject {
|
||||||
@@ -45,4 +47,53 @@ public abstract class FContainer extends FDisplayObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void doLayout(float width, float height);
|
protected abstract void doLayout(float width, float height);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean touchDown(float x, float y, int pointer, int button) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean tap(float x, float y, int count, int button) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean longPress(float x, float y) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean fling(float velocityX, float velocityY, int button) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean pan(float x, float y, float deltaX, float deltaY) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean panStop(float x, float y, int pointer, int button) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean zoom(float initialDistance, float distance) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean pinch(Vector2 initialPointer1, Vector2 initialPointer2,
|
||||||
|
Vector2 pointer1, Vector2 pointer2) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
package forge.toolbox;
|
package forge.toolbox;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.input.GestureDetector.GestureListener;
|
||||||
import com.badlogic.gdx.math.Rectangle;
|
import com.badlogic.gdx.math.Rectangle;
|
||||||
|
import com.badlogic.gdx.math.Vector2;
|
||||||
|
|
||||||
import forge.Forge.Graphics;
|
import forge.Forge.Graphics;
|
||||||
|
|
||||||
public abstract class FDisplayObject {
|
public abstract class FDisplayObject implements GestureListener {
|
||||||
private final Rectangle bounds = new Rectangle();
|
private final Rectangle bounds = new Rectangle();
|
||||||
|
|
||||||
public void setPosition(float x, float y) {
|
public void setPosition(float x, float y) {
|
||||||
@@ -36,4 +38,44 @@ public abstract class FDisplayObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public abstract void draw(Graphics g);
|
public abstract void draw(Graphics g);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean touchDown(float x, float y, int pointer, int button) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean tap(float x, float y, int count, int button) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean longPress(float x, float y) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean fling(float velocityX, float velocityY, int button) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean pan(float x, float y, float deltaX, float deltaY) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean panStop(float x, float y, int pointer, int button) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean zoom(float initialDistance, float distance) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean pinch(Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user