Better history management

This commit is contained in:
Cavallium 2018-10-05 16:00:15 +02:00
parent 518bfc6c4a
commit b11d8ea4ed
23 changed files with 662 additions and 21 deletions

View File

@ -11,9 +11,9 @@ import it.cavallium.warppi.event.Key;
import it.cavallium.warppi.event.KeyPressedEvent;
import it.cavallium.warppi.event.KeyReleasedEvent;
import it.cavallium.warppi.event.KeyboardEventListener;
import it.cavallium.warppi.extra.mario.MarioScreen;
import it.cavallium.warppi.gui.GUIErrorMessage;
import it.cavallium.warppi.gui.screens.KeyboardDebugScreen;
import it.cavallium.warppi.gui.screens.MarioScreen;
import it.cavallium.warppi.gui.screens.Screen;
public class Keyboard {
@ -923,6 +923,11 @@ public class Keyboard {
Engine.INSTANCE.getHardwareDevice().getDisplayManager().goForward();
refresh = true;
break;
case BACK:
Engine.getPlatform().getConsoleUtils().out().println(ConsoleUtils.OUTPUTLEVEL_DEBUG_MIN, "Closing current screen.");
Engine.INSTANCE.getHardwareDevice().getDisplayManager().closeScreen();
refresh = true;
break;
default:
break;
}

View File

@ -1,14 +1,16 @@
package it.cavallium.warppi.gui.screens;
package it.cavallium.warppi.extra.mario;
import java.io.IOException;
import it.cavallium.warppi.Engine;
import it.cavallium.warppi.StaticVars;
import it.cavallium.warppi.Platform.ConsoleUtils;
import it.cavallium.warppi.device.Keyboard;
import it.cavallium.warppi.extra.mario.MarioGame;
import it.cavallium.warppi.extra.mario.MarioWorld;
import it.cavallium.warppi.event.KeyPressedEvent;
import it.cavallium.warppi.gui.HistoryBehavior;
import it.cavallium.warppi.gui.graphicengine.BinaryFont;
import it.cavallium.warppi.gui.graphicengine.Skin;
import it.cavallium.warppi.gui.screens.Screen;
public class MarioScreen extends Screen {
@ -38,7 +40,7 @@ public class MarioScreen extends Screen {
public MarioScreen() {
super();
canBeInHistory = false;
historyBehavior = HistoryBehavior.ALWAYS_KEEP_IN_HISTORY;
}
@Override

View File

@ -0,0 +1,10 @@
package it.cavallium.warppi.extra.tetris;
public enum BlockType {
RED,
GREEN,
YELLOW,
BLUE,
ORANGE,
VIOLET
}

View File

@ -0,0 +1,9 @@
package it.cavallium.warppi.extra.tetris;
public enum GameStatus {
INITIAL,
PLAYING,
LOST,
WIN,
ENDED
}

View File

@ -0,0 +1,33 @@
package it.cavallium.warppi.extra.tetris;
public class MarioBlock {
private final int x;
private final int y;
private final byte id;
public MarioBlock(final int x, final int y, final byte b) {
this.x = x;
this.y = y;
id = b;
}
public boolean isSolid() {
return MarioBlock.isSolid(id);
}
public byte getID() {
return id;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public static boolean isSolid(final byte id) {
return id != 0b0;
}
}

View File

@ -0,0 +1,9 @@
package it.cavallium.warppi.extra.tetris;
public class MarioEnemy extends MarioEntity {
public MarioEnemy(final double x, final double y, final double forceX, final double forceY, final boolean onGround, final boolean subjectToGravity) {
super(x, y, forceX, forceY, onGround, subjectToGravity);
}
}

View File

@ -0,0 +1,85 @@
package it.cavallium.warppi.extra.tetris;
public class MarioEntity {
protected double x;
protected double y;
public double forceX;
public double forceY;
public boolean collisionUp;
public boolean collisionDown;
public boolean collisionLeft;
public boolean collisionRight;
public boolean subjectToGravity;
public MarioEntity(final double x, final double y, final double forceX, final double forceY, final boolean onGround, final boolean subjectToGravity) {
this.x = x;
this.y = y;
this.forceX = forceX;
this.forceY = forceY;
collisionDown = onGround;
this.subjectToGravity = subjectToGravity;
}
public void setPosition(final double x, final double y) {
this.x = x;
this.y = y;
}
public void setPosition(final double x, final double y, final boolean onGround) {
this.x = x;
this.y = y;
collisionDown = onGround;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public boolean isOnGround() {
return collisionDown;
}
public void setOnGround(final boolean onGround) {
collisionDown = onGround;
}
public void gameTick(final double dt) {
x = computeFutureDX(dt);
y = computeFutureDY(dt);
forceX = computeFutureForceDX(dt);
forceY = computeFutureForceDY(dt);
}
public double computeFutureDX(final double dt) {
return x + dt * forceX - x;
}
public double computeFutureDY(final double dt) {
final double forceY = this.forceY;
double y = this.y;
if (!collisionDown) {
y += dt * forceY;
}
return y - this.y;
}
public double computeFutureForceDX(final double dt) {
double forceX = this.forceX;
forceX *= 0.75;
return forceX - this.forceX;
}
public double computeFutureForceDY(final double dt) {
double forceY = this.forceY;
if (subjectToGravity && !collisionDown) {
forceY -= dt * 1569.6 / 16f;
} else {
forceY *= 0.75;
}
return forceY - this.forceY;
}
}

View File

@ -0,0 +1,5 @@
package it.cavallium.warppi.extra.tetris;
public class MarioEvent {
}

View File

@ -0,0 +1,69 @@
package it.cavallium.warppi.extra.tetris;
public class MarioWorld {
private final int[] spawnPoint;
private final int width;
private final int height;
private final byte[][] data;
@SuppressWarnings("unused")
private final MarioEvent[] events;
private final MarioEntity[] entities;
/**
* @param width
* @param height
* @param data
* @param events
* @param marioEnemies
*/
public MarioWorld(final int[] spawnPoint, final int width, final int height, final byte[][] data, final MarioEvent[] events, final MarioEntity[] entities) {
this.spawnPoint = spawnPoint;
this.width = width;
this.height = height;
this.data = data;
this.events = events;
this.entities = entities;
}
public byte getBlockIdAt(final int x, final int y) {
final int idy = height - 1 - y;
if (idy < 0 || idy >= data.length) {
return 0b0;
}
final int idx = x;
if (idx < 0 || idx >= data[0].length) {
return 0b0;
}
return data[idy][idx];
}
public MarioBlock getBlockAt(final int x, final int y) {
return new MarioBlock(x, y, getBlockIdAt(x, y));
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public void reset() {
}
public double getSpawnPointX() {
return spawnPoint[0];
}
public double getSpawnPointY() {
return spawnPoint[1];
}
public MarioEntity[] getEntities() {
return entities;
}
}

View File

@ -0,0 +1,138 @@
package it.cavallium.warppi.extra.tetris;
public class PlayerEntity extends MarioEntity {
@SuppressWarnings("unused")
private final int life;
public float walkAnimation = 0;
public float jumptime = 0;
public boolean walking = false;
public boolean running = false;
public boolean jumping = false;
public boolean flipped = false;
public int[] marioSkinPos = new int[] { 0, 0 };
private double controllerDX;
private double controllerDY;
public PlayerEntity(final double x, final double y, final int life) {
super(x, y, 0, 0, true, true);
this.life = life;
}
@Override
public void gameTick(final double dt) {
walkAnimation += dt;
x += computeFutureDX(dt);
y += computeFutureDY(dt);
forceX += computeFutureForceDX(dt);
forceY += computeFutureForceDY(dt);
if (controllerDX == 0) {
walking = false;
walkAnimation = 0;
} else {
if (controllerDX > 0) { //RIGHT
walking = true;
flipped = false;
}
if (controllerDX < 0) { //LEFT
walking = true;
flipped = true;
}
}
if (controllerDY > 0) { //JUMP
if (collisionUp) {
jumptime = Float.MAX_VALUE;
jumping = false;
}
jumptime += dt;
if (jumptime <= 0.5f && !jumping && collisionDown) {
jumping = true;
collisionDown = false;
} else if (jumptime <= 0.5f) {} else {
jumping = false;
}
} else {
jumping = false;
if (collisionDown) {
jumptime = 0;
} else {
jumptime = Float.MAX_VALUE;
}
}
if (!walking & !running & !jumping) {
marioSkinPos[0] = 0;
marioSkinPos[1] = 0;
} else if (collisionDown & walking & !running & !jumping && walkAnimation >= 0.08) {
while (walkAnimation > 0.08) {
walkAnimation -= 0.08;
if (marioSkinPos[0] == 1 & marioSkinPos[1] == 0) {
marioSkinPos[0] += 2;
} else if (marioSkinPos[0] == 3 & marioSkinPos[1] == 0) {
marioSkinPos[0] -= 1;
} else if (marioSkinPos[0] == 2 & marioSkinPos[1] == 0) {
marioSkinPos[0] -= 1;
} else {
marioSkinPos[0] = 1;
marioSkinPos[1] = 0;
}
}
} else if (jumping) {
marioSkinPos[0] = 5;
marioSkinPos[1] = 1;
}
}
@Override
public double computeFutureDX(final double dt) {
return super.computeFutureDX(dt);
}
public double computeFuturedDY(final double dt) {
return super.computeFutureDY(dt);
}
@Override
public double computeFutureForceDX(final double dt) {
double forceX = this.forceX;
if (controllerDX == 0) {} else {
if (controllerDX > 0) {
if (forceX < 500f / 16f) {
forceX += dt * 500f / 16f;
}
}
if (controllerDX < 0) {
if (forceX > -500f / 16f) {
forceX -= dt * 500f / 16f;
}
}
}
return forceX + super.computeFutureForceDX(dt) - this.forceX;
}
@Override
public double computeFutureForceDY(final double dt) {
float jumptime = this.jumptime;
double forceY = this.forceY;
if (controllerDY > 0) { //JUMP
if (collisionUp) {
jumptime = Float.MAX_VALUE;
}
jumptime += dt;
if (jumptime <= 0.5f && !jumping && collisionDown) {
forceY = dt * (4 * 1569.6f) / 16f;
} else if (jumptime <= 0.5f) {
forceY = dt * (4 * 1569.6f) / 16f;
}
}
return forceY + super.computeFutureForceDY(dt) - this.forceY;
}
public void move(final float dt, final double dX, final double dY) {
walkAnimation += dt;
controllerDX = dX;
controllerDY = dY;
}
}

View File

@ -0,0 +1,5 @@
package it.cavallium.warppi.extra.tetris;
public class PositionEvent extends MarioEvent {
}

View File

@ -0,0 +1,21 @@
package it.cavallium.warppi.extra.tetris;
public class TetrisGame {
private static final int WIDTH = 10, HEIGHT = 22;
private BlockType[] grid;
private BlockType[] hovergrid;
private GameStatus gameStatus = GameStatus.INITIAL;
private int score = 0;
public TetrisGame() {
}
private void playAgain() {
grid = new BlockType[WIDTH * HEIGHT];
hovergrid = new BlockType[WIDTH * HEIGHT];
score = 0;
gameStatus = GameStatus.PLAYING;
}
}

View File

@ -0,0 +1,185 @@
package it.cavallium.warppi.extra.tetris;
import java.io.IOException;
import it.cavallium.warppi.Engine;
import it.cavallium.warppi.StaticVars;
import it.cavallium.warppi.device.Keyboard;
import it.cavallium.warppi.gui.HistoryBehavior;
import it.cavallium.warppi.gui.graphicengine.BinaryFont;
import it.cavallium.warppi.gui.graphicengine.Skin;
import it.cavallium.warppi.gui.screens.Screen;
public class TetrisScreen extends Screen {
private TetrisGame g;
private static Skin skin;
public TetrisScreen() {
super();
historyBehavior = HistoryBehavior.ALWAYS_KEEP_IN_HISTORY;
}
@Override
public void initialized() {
// try {
// if (TetrisScreen.skin == null) {
// TetrisScreen.skin = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.loadSkin("/marioskin.png");
// }
// if (TetrisScreen.groundskin == null) {
// TetrisScreen.groundskin = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.loadSkin("/marioground.png");
// }
// if (TetrisScreen.gpuTest2 == null) {
// try {
// TetrisScreen.gpuTest2 = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.loadFont("N:\\gputest\\gputest2");
// } catch (final Exception ex) {}
// }
// if (TetrisScreen.gpuTest1 == null) {
// try {
// TetrisScreen.gpuTest1 = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.loadFont("N:\\gputest\\gputest12");
// TetrisScreen.gpuTest12 = true;
// } catch (final Exception ex) {
// TetrisScreen.gpuTest12 = false;
// try {
// TetrisScreen.gpuTest1 = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.loadFont("N:\\gputest\\gputest1");
// } catch (final Exception ex2) {}
// }
// }
// if (TetrisScreen.gpuTest3 == null) {
// try {
// TetrisScreen.gpuTest3 = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.loadSkin("N:\\gputest\\font_gputest3.png");
// } catch (final Exception ex) {
// ex.printStackTrace();
// }
// }
// } catch (final IOException e) {
// e.printStackTrace();
// }
}
@Override
public void created() throws InterruptedException {
// if (!errored) {
// g = new MarioGame();
// }
}
@Override
public void beforeRender(final float dt) {
// if (!errored) {
// final boolean rightPressed = Keyboard.isKeyDown(2, 5);
// final boolean leftPressed = Keyboard.isKeyDown(2, 3);
// final boolean jumpPressed = Keyboard.isKeyDown(2, 1);
// final boolean upPressed = false, downPressed = false, runPressed = false;
// g.gameTick(dt, upPressed, downPressed, leftPressed, rightPressed, jumpPressed, runPressed);
//
// gpuTestElapsed += dt;
// while (gpuTestElapsed >= 0.04) {
// gpuTestNum = (gpuTestNum + 1) % gpuTestMax;
// gpuTestElapsed -= 0.04;
// }
// gpuCharTestt1Elapsed += dt;
// while (gpuCharTestt1Elapsed >= 1.5) {
// gpuCharTest1Num = (gpuCharTest1Num + 1) % gpuCharTest1.length;
// gpuCharTestt1Elapsed -= 1.5;
// }
//
// Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glClearColor(0xff000000);
// }
}
@Override
public void render() {
// if (errored) {
// Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringLeft(0, 20, "ERROR");
// } else {
// if (TetrisScreen.groundskin != null) {
// final double playerX = g.getPlayer().getX();
// final double playerY = g.getPlayer().getY();
// TetrisScreen.groundskin.use(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine);
// final MarioWorld w = g.getCurrentWorld();
// final int width = w.getWidth();
// final int height = w.getHeight();
// final float screenX = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getWidth() / 2f - 8f;
// final float screenY = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getHeight() / 2f - 8f;
// final float shiftX = -8 + 16 * (float) playerX;
// final float shiftY = -8 + 16 * (height - (float) playerY);
// int blue = -1;
// for (int ix = 0; ix < width; ix++) {
// for (int iy = 0; iy < height; iy++) {
// final double distX = Math.abs(playerX - ix);
// final double distY = Math.abs(playerY - iy - 1.5d);
// if (distX * distX + distY * distY / 2d < 25d) {
// final byte b = w.getBlockIdAt(ix, iy);
// if (b == 0) {
// if (blue != 1) {
// blue = 1;
// Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor(0xff9290ff);
// }
// Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glFillColor(screenX - shiftX + 16 * ix, screenY - shiftY + 16 * (height - iy), 16, 16);
// } else {
// if (blue != 0) {
// blue = 0;
// Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor(0xffffffff);
// }
// Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glFillRect(screenX - shiftX + 16 * ix, screenY - shiftY + 16 * (height - iy), 16, 16, 0, 0, 16, 16);
// }
// }
// }
// }
// if (blue != 0) {
// blue = 0;
// Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor(0xffffffff);
// }
//
// //DRAW MARIO
// TetrisScreen.skin.use(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine);
// Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glFillRect(screenX - (g.getPlayer().flipped ? 3 : 0), screenY, 35, 27, 35 * (g.getPlayer().marioSkinPos[0] + (g.getPlayer().flipped ? 2 : 1)), 27 * g.getPlayer().marioSkinPos[1], 35 * (g.getPlayer().flipped ? -1 : 1), 27);
//// PIDisplay.renderer.glDrawSkin(getPosX() - 18, 25 + getPosY(), 35 * (marioSkinPos[0] + (flipped ? 2 : 1)), 27 * marioSkinPos[1], 35 * (marioSkinPos[0] + (flipped ? 1 : 2)), 27 * (marioSkinPos[1] + 1), true);
// }
//
//// GPU PERFORMANCE TEST
// if (TetrisScreen.gpuTest1 != null) {
// Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor3f(1, 1, 1);
// Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glFillColor(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getWidth() - (TetrisScreen.gpuTest12 ? 512 : 256), Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getHeight() / 2 - (TetrisScreen.gpuTest12 ? 256 : 128), TetrisScreen.gpuTest12 ? 512 : 256, TetrisScreen.gpuTest12 ? 512 : 256);
// TetrisScreen.gpuTest1.use(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine);
// Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor3f(0, 0, 0);
// Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringRight(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getWidth(), Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getHeight() / 2 - (TetrisScreen.gpuTest12 ? 256 : 128), gpuCharTest1[gpuCharTest1Num]);
// }
// if (TetrisScreen.gpuTest3 != null) {
// TetrisScreen.gpuTest3.use(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine);
// Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor4f(1, 1, 1, 0.7f);
// Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glFillRect(0, StaticVars.screenSize[1] - 128, 224, 128, gpuTestNum * 224, 0, 224, 128);
// }
// if (TetrisScreen.gpuTest2 != null) {
// TetrisScreen.gpuTest2.use(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine);
// Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor(0xFF000000);
// Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringRight(StaticVars.screenSize[0], Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getHeight() - TetrisScreen.gpuTest2.getCharacterHeight(), "A");
// Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor(0xFF800000);
// Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringRight(StaticVars.screenSize[0], Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getHeight() - TetrisScreen.gpuTest2.getCharacterHeight(), "B");
// Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor(0xFFeea28e);
// Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringRight(StaticVars.screenSize[0], Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getHeight() - TetrisScreen.gpuTest2.getCharacterHeight(), "C");
// Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor(0xFFee7255);
// Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringRight(StaticVars.screenSize[0], Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getHeight() - TetrisScreen.gpuTest2.getCharacterHeight(), "D");
// Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor(0xFFeac0b0);
// Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringRight(StaticVars.screenSize[0], Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getHeight() - TetrisScreen.gpuTest2.getCharacterHeight(), "E");
// Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor(0xFFf3d8ce);
// Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringRight(StaticVars.screenSize[0], Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getHeight() - TetrisScreen.gpuTest2.getCharacterHeight(), "F");
// Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor(0xFFffede7);
// Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringRight(StaticVars.screenSize[0], Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getHeight() - TetrisScreen.gpuTest2.getCharacterHeight(), "G");
// }
// }
}
@Override
public boolean mustBeRefreshed() {
return true;
}
@Override
public String getSessionTitle() {
return "Absolutely not Super Mario";
}
}

View File

@ -112,7 +112,7 @@ public class CalculatorHUD extends HUD {
allSessions.add(0, session);
}
Screen curScreen = Engine.INSTANCE.getHardwareDevice().getDisplayManager().getScreen();
if (curScreen.canBeInHistory == false) {
if (curScreen.historyBehavior == HistoryBehavior.DONT_KEEP_IN_HISTORY) {
allSessions.add(curScreen);
}
@ -121,8 +121,10 @@ public class CalculatorHUD extends HUD {
String title = session.getSessionTitle();
if (title != null && title.length() > 0) {
Utils.getFont(true).use(engine);
if (session.canBeInHistory == false) {
if (session.historyBehavior == HistoryBehavior.DONT_KEEP_IN_HISTORY) {
r.glColor(0xFF3333FF);
} else if (session.historyBehavior == HistoryBehavior.ALWAYS_KEEP_IN_HISTORY) {
r.glColor(0xFFFF33FF);
} else {
r.glColor(0xFF990000);
}

View File

@ -2,6 +2,7 @@ package it.cavallium.warppi.gui;
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import org.apache.commons.lang3.tuple.Pair;
@ -165,6 +166,31 @@ public final class DisplayManager implements RenderingLoop {
throw new UnsupportedOperationException("No graphic engines available.");
}
public void closeScreen() {
boolean isLastSession = sessions[1] == null;
if (!isLastSession) {
if (currentSession >= 0) {
List<Screen> newSessions = new LinkedList<>();
int i = 0;
for (Screen s : sessions) {
if (i != currentSession && s != null) {
newSessions.add(s);
}
i++;
}
sessions = newSessions.toArray(new Screen[5]);
if (currentSession >= newSessions.size()) {
currentSession--;
}
} else {
currentSession = 0;
}
updateCurrentScreen(sessions[currentSession]);
}
}
public void setScreen(final Screen screen) {
boolean mustBeAddedToHistory = screen.initialized == false;
if (!mustBeAddedToHistory) {
@ -175,12 +201,30 @@ public final class DisplayManager implements RenderingLoop {
mustBeAddedToHistory |= !found;
}
if (mustBeAddedToHistory) {
if (screen.canBeInHistory) {
if (screen.historyBehavior == HistoryBehavior.NORMAL || screen.historyBehavior == HistoryBehavior.ALWAYS_KEEP_IN_HISTORY) {
if (currentSession > 0) {
final int sl = sessions.length + 5; //TODO: I don't know why if i don't add +5 or more some items disappear
sessions = Arrays.copyOfRange(sessions, currentSession, sl);
final int sl = sessions.length; //TODO: I don't know why if i don't add +5 or more some items disappear
List<Screen> newSessions = new LinkedList<>();
int i = 0;
for (Screen s : sessions) {
if (s != null) {
if (i < currentSession) {
if (s.historyBehavior != HistoryBehavior.DONT_KEEP_IN_HISTORY)
newSessions.add(s);
} else {
if (s.historyBehavior == HistoryBehavior.ALWAYS_KEEP_IN_HISTORY) {
newSessions.add(s);
}
}
}
i++;
}
sessions = newSessions.toArray(new Screen[5]);
currentSession = newSessions.indexOf(screen);
// sessions = Arrays.copyOfRange(sessions, currentSession, sl);
} else {
currentSession = 0;
}
currentSession = 0;
for (int i = sessions.length - 1; i >= 1; i--) {
sessions[i] = sessions[i - 1];
}
@ -189,6 +233,10 @@ public final class DisplayManager implements RenderingLoop {
currentSession = -1;
}
}
updateCurrentScreen(screen);
}
private void updateCurrentScreen(Screen screen) {
screen.d = this;
try {
if (screen.created == false) {
@ -207,7 +255,7 @@ public final class DisplayManager implements RenderingLoop {
public void replaceScreen(final Screen screen) {
if (screen.initialized == false) {
if (screen.canBeInHistory) {
if (screen.historyBehavior == HistoryBehavior.NORMAL || screen.historyBehavior == HistoryBehavior.ALWAYS_KEEP_IN_HISTORY) {
sessions[currentSession] = screen;
} else {
currentSession = -1;
@ -231,7 +279,7 @@ public final class DisplayManager implements RenderingLoop {
}
public boolean canGoBack() {
if (currentSession == -1) {
if (currentSession <= -1) {
return sessions[0] != null;
}
if (screen != sessions[currentSession]) {

View File

@ -0,0 +1,7 @@
package it.cavallium.warppi.gui;
public enum HistoryBehavior {
DONT_KEEP_IN_HISTORY,
ALWAYS_KEEP_IN_HISTORY,
NORMAL
}

View File

@ -3,6 +3,7 @@ package it.cavallium.warppi.gui.screens;
import it.cavallium.warppi.Engine;
import it.cavallium.warppi.StaticVars;
import it.cavallium.warppi.event.KeyPressedEvent;
import it.cavallium.warppi.gui.HistoryBehavior;
import it.cavallium.warppi.math.Function;
import it.cavallium.warppi.math.functions.Variable.VariableValue;
import it.cavallium.warppi.util.Utils;
@ -15,7 +16,7 @@ public class ChooseVariableValueScreen extends Screen {
public ChooseVariableValueScreen(final MathInputScreen es, final VariableValue variableValue) {
super();
canBeInHistory = false;
historyBehavior = HistoryBehavior.DONT_KEEP_IN_HISTORY;
this.es = es;
}

View File

@ -1,12 +1,14 @@
package it.cavallium.warppi.gui.screens;
import it.cavallium.warppi.gui.HistoryBehavior;
public class EmptyScreen extends Screen {
public float endLoading;
public EmptyScreen() {
super();
canBeInHistory = false;
historyBehavior = HistoryBehavior.DONT_KEEP_IN_HISTORY;
}
@Override

View File

@ -4,6 +4,7 @@ import it.cavallium.warppi.Engine;
import it.cavallium.warppi.StaticVars;
import it.cavallium.warppi.event.KeyPressedEvent;
import it.cavallium.warppi.event.KeyReleasedEvent;
import it.cavallium.warppi.gui.HistoryBehavior;
import it.cavallium.warppi.gui.graphicengine.Renderer;
public class KeyboardDebugScreen extends Screen {
@ -17,7 +18,7 @@ public class KeyboardDebugScreen extends Screen {
public KeyboardDebugScreen() {
super();
canBeInHistory = false;
historyBehavior = HistoryBehavior.DONT_KEEP_IN_HISTORY;
}
@Override

View File

@ -3,6 +3,7 @@ package it.cavallium.warppi.gui.screens;
import it.cavallium.warppi.Engine;
import it.cavallium.warppi.StaticVars;
import it.cavallium.warppi.gui.GraphicUtils;
import it.cavallium.warppi.gui.HistoryBehavior;
public class LoadingScreen extends Screen {
@ -15,7 +16,7 @@ public class LoadingScreen extends Screen {
public LoadingScreen() {
super();
canBeInHistory = false;
historyBehavior = HistoryBehavior.DONT_KEEP_IN_HISTORY;
}
@Override

View File

@ -11,6 +11,7 @@ import it.cavallium.warppi.device.Keyboard;
import it.cavallium.warppi.event.Key;
import it.cavallium.warppi.event.KeyPressedEvent;
import it.cavallium.warppi.event.KeyReleasedEvent;
import it.cavallium.warppi.gui.HistoryBehavior;
import it.cavallium.warppi.gui.expression.InputContext;
import it.cavallium.warppi.gui.expression.blocks.Block;
import it.cavallium.warppi.gui.expression.blocks.BlockContainer;
@ -60,7 +61,7 @@ public class MathInputScreen extends Screen {
public MathInputScreen() {
super();
canBeInHistory = true;
historyBehavior = HistoryBehavior.NORMAL;
}
/**
@ -69,7 +70,7 @@ public class MathInputScreen extends Screen {
*/
private MathInputScreen(MathInputScreen old) {
this.calc = new MathContext(old.calc);
this.canBeInHistory = old.canBeInHistory;
this.historyBehavior = old.historyBehavior;
this.created = old.created;
this.currentStep = old.currentStep;
this.d = old.d;

View File

@ -4,12 +4,13 @@ import it.cavallium.warppi.event.KeyboardEventListener;
import it.cavallium.warppi.event.TouchEventListener;
import it.cavallium.warppi.gui.DisplayManager;
import it.cavallium.warppi.gui.GraphicalInterface;
import it.cavallium.warppi.gui.HistoryBehavior;
public abstract class Screen implements KeyboardEventListener, TouchEventListener, GraphicalInterface {
public DisplayManager d;
public boolean created = false;
public boolean initialized = false;
public boolean canBeInHistory = false;
public HistoryBehavior historyBehavior = HistoryBehavior.NORMAL;
public static long lastDebugScreenID = 1;
public final long debugScreenID;

View File

@ -3,6 +3,7 @@ package it.cavallium.warppi.gui.screens;
import it.cavallium.warppi.Engine;
import it.cavallium.warppi.StaticVars;
import it.cavallium.warppi.event.KeyPressedEvent;
import it.cavallium.warppi.gui.HistoryBehavior;
public class SolveForXScreen extends Screen {
@ -11,7 +12,7 @@ public class SolveForXScreen extends Screen {
public SolveForXScreen(final MathInputScreen es) {
super();
canBeInHistory = false;
historyBehavior = HistoryBehavior.DONT_KEEP_IN_HISTORY;
this.es = es;
}