Fixed bugs in input handling
This commit is contained in:
parent
35d878fba7
commit
494f8e854f
|
@ -6,21 +6,26 @@ public class TetrisGame {
|
|||
private BlockType[] grid;
|
||||
private BlockType[] hovergrid;
|
||||
private BlockType[] renderedGrid;
|
||||
private GameStatus gameStatus = GameStatus.INITIAL;
|
||||
private int score = 0;
|
||||
private double currentTime = 0;
|
||||
private GameStatus gameStatus;
|
||||
private int score;
|
||||
private double currentTime;
|
||||
|
||||
public TetrisGame() {
|
||||
|
||||
resetVariables();
|
||||
}
|
||||
|
||||
void playAgain() {
|
||||
resetVariables();
|
||||
gameStatus = GameStatus.PLAYING;
|
||||
}
|
||||
|
||||
private void resetVariables() {
|
||||
grid = new BlockType[WIDTH * HEIGHT];
|
||||
hovergrid = new BlockType[WIDTH * HEIGHT];
|
||||
renderedGrid = new BlockType[WIDTH * HEIGHT];
|
||||
score = 0;
|
||||
currentTime = 0;
|
||||
gameStatus = GameStatus.PLAYING;
|
||||
gameStatus = GameStatus.INITIAL;
|
||||
}
|
||||
|
||||
public void gameTick(float dt, boolean leftPressed, boolean rightPressed, boolean downPressed, boolean okPressed, boolean backPressed) {
|
||||
|
|
|
@ -49,7 +49,7 @@ public class TetrisScreen extends Screen {
|
|||
if (TetrisScreen.skin == null) {
|
||||
TetrisScreen.skin = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.loadSkin("/tetrisskin.png");
|
||||
}
|
||||
StaticVars.windowZoom.onNext(1f);
|
||||
StaticVars.windowZoom.onNext(2f);
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.util.Arrays;
|
|||
import it.cavallium.warppi.event.KeyboardEventListener;
|
||||
import it.cavallium.warppi.gui.expression.blocks.Block;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockVariable;
|
||||
import it.cavallium.warppi.gui.expression.blocks.TreeContainer;
|
||||
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
||||
import it.cavallium.warppi.gui.graphicengine.Renderer;
|
||||
|
||||
|
@ -45,7 +46,7 @@ public abstract class ExtraMenu<T extends Block> implements KeyboardEventListene
|
|||
return false;
|
||||
}
|
||||
|
||||
public abstract ExtraMenu<T> clone(InputContext ic);
|
||||
public abstract ExtraMenu<T> clone(final TreeContainer parent, InputContext ic);
|
||||
|
||||
public abstract ExtraMenu<T> clone(T newBlockVariable);
|
||||
|
||||
|
|
|
@ -18,6 +18,22 @@ public abstract class Block implements TreeBlock, GraphicalElement {
|
|||
protected int height;
|
||||
protected int line;
|
||||
protected TreeContainer parent;
|
||||
|
||||
public Block() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy
|
||||
* @param b
|
||||
*/
|
||||
public Block(TreeContainer parent, Block b) {
|
||||
this.small = b.small;
|
||||
this.width = b.width;
|
||||
this.height = b.height;
|
||||
this.line = b.line;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -95,5 +111,5 @@ public abstract class Block implements TreeBlock, GraphicalElement {
|
|||
this.parent = parent;
|
||||
}
|
||||
|
||||
public abstract Block clone(InputContext ic);
|
||||
public abstract Block clone(TreeContainer parent, InputContext ic);
|
||||
}
|
||||
|
|
|
@ -18,9 +18,14 @@ public class BlockChar extends Block {
|
|||
recomputeDimensions();
|
||||
}
|
||||
|
||||
public BlockChar(final char ch, InputContext ic) {
|
||||
this.ch = ch;
|
||||
recomputeDimensions();
|
||||
/**
|
||||
* Copy
|
||||
* @param b
|
||||
* @param ic
|
||||
*/
|
||||
protected BlockChar(final TreeContainer parent, final BlockChar b, InputContext ic) {
|
||||
super(parent, b);
|
||||
this.ch = b.ch;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -83,8 +88,8 @@ public class BlockChar extends Block {
|
|||
}
|
||||
|
||||
@Override
|
||||
public BlockChar clone(InputContext ic) {
|
||||
return new BlockChar(ch, ic);
|
||||
public BlockChar clone(final TreeContainer parent, InputContext ic) {
|
||||
return new BlockChar(parent, this, ic);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -79,24 +79,25 @@ public class BlockContainer implements TreeContainer, GraphicalElement {
|
|||
recomputeDimensions();
|
||||
}
|
||||
|
||||
private BlockContainer(BlockContainer old, InputContext ic) {
|
||||
private BlockContainer(final TreeBlock parent, BlockContainer old, InputContext ic) {
|
||||
this.autoMinimums = old.autoMinimums;
|
||||
this.content = new ObjectArrayList<>();
|
||||
for (Block b : old.content) {
|
||||
this.content.add(b.clone(ic));
|
||||
this.content.add(b.clone(this, ic));
|
||||
}
|
||||
|
||||
this.height = old.height;
|
||||
this.line = old.line;
|
||||
this.minHeight = old.minHeight;
|
||||
this.minWidth = old.minWidth;
|
||||
this.parent = old.parent;
|
||||
this.parent = parent;
|
||||
this.small = old.small;
|
||||
this.width = old.width;
|
||||
this.withBorder = old.withBorder;
|
||||
}
|
||||
|
||||
public BlockContainer clone(InputContext ic) {
|
||||
return new BlockContainer(this, ic);
|
||||
public BlockContainer clone(final TreeBlock parent, InputContext ic) {
|
||||
return new BlockContainer(parent, this, ic);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -261,18 +262,21 @@ public class BlockContainer implements TreeContainer, GraphicalElement {
|
|||
innerContainersBeforeCaret++;
|
||||
}
|
||||
}
|
||||
removeAt(pos - 1);
|
||||
if (blocks != null) {
|
||||
ObjectListIterator<Block> blocksIterator = blocks.iterator();
|
||||
int blockNum = 0;
|
||||
while (blocksIterator.hasNext()) {
|
||||
Block block = blocksIterator.next();
|
||||
addBlockUnsafe(pos - 1 + blockNum, block);
|
||||
blockNum++;
|
||||
// If the caret is at the end of a block with inner containers don't delete anything and enter into that block.
|
||||
if (innerContainers == null || (innerContainers.size() - innerContainersBeforeCaret != 0)) {
|
||||
removeAt(pos - 1);
|
||||
if (blocks != null) {
|
||||
ObjectListIterator<Block> blocksIterator = blocks.iterator();
|
||||
int blockNum = 0;
|
||||
while (blocksIterator.hasNext()) {
|
||||
Block block = blocksIterator.next();
|
||||
addBlockUnsafe(pos - 1 + blockNum, block);
|
||||
blockNum++;
|
||||
}
|
||||
}
|
||||
caret.setPosition(caretOldPos - innerContainersBeforeCaret);
|
||||
removed = true;
|
||||
}
|
||||
caret.setPosition(caretOldPos - innerContainersBeforeCaret);
|
||||
removed = true;
|
||||
}
|
||||
}
|
||||
caret.skip(1);
|
||||
|
|
|
@ -27,10 +27,14 @@ public class BlockDivision extends Block {
|
|||
recomputeDimensions();
|
||||
}
|
||||
|
||||
private BlockDivision(BlockDivision old, InputContext ic) {
|
||||
containerUp = old.containerUp.clone(ic);
|
||||
containerDown = old.containerDown.clone(ic);
|
||||
recomputeDimensions();
|
||||
private BlockDivision(final TreeContainer parent, BlockDivision old, InputContext ic) {
|
||||
super(parent, old);
|
||||
containerUp = old.containerUp.clone(this, ic);
|
||||
containerDown = old.containerDown.clone(this, ic);
|
||||
paddingLeftLower = old.paddingLeftLower;
|
||||
paddingLeftUpper = old.paddingLeftUpper;
|
||||
h1 = old.h1;
|
||||
System.out.println(String.join(",", ""+h1, ""+old.h1, ""+line, ""+old.line));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -144,7 +148,7 @@ public class BlockDivision extends Block {
|
|||
}
|
||||
|
||||
@Override
|
||||
public BlockDivision clone(InputContext ic) {
|
||||
return new BlockDivision(this, ic);
|
||||
public BlockDivision clone(final TreeContainer parent, InputContext ic) {
|
||||
return new BlockDivision(parent, this, ic);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package it.cavallium.warppi.gui.expression.blocks;
|
||||
|
||||
import it.cavallium.warppi.gui.expression.Caret;
|
||||
import it.cavallium.warppi.gui.expression.InputContext;
|
||||
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
||||
import it.cavallium.warppi.gui.graphicengine.Renderer;
|
||||
|
||||
|
@ -8,6 +9,21 @@ public class BlockExponentialNotation extends BlockPower {
|
|||
private int bw;
|
||||
private int bh;
|
||||
|
||||
public BlockExponentialNotation() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy
|
||||
* @param old
|
||||
* @param ic
|
||||
*/
|
||||
private BlockExponentialNotation(final TreeContainer parent, BlockExponentialNotation old, InputContext ic) {
|
||||
super(parent, old, ic);
|
||||
this.bw = old.bw;
|
||||
this.bh = old.bh;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(final GraphicEngine ge, final Renderer r, final int x, final int y, final Caret caret) {
|
||||
BlockContainer.getDefaultFont(small).use(ge);
|
||||
|
@ -23,4 +39,9 @@ public class BlockExponentialNotation extends BlockPower {
|
|||
bh = BlockContainer.getDefaultCharHeight(small);
|
||||
width += bw;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockExponentialNotation clone(final TreeContainer parent, InputContext ic) {
|
||||
return new BlockExponentialNotation(parent, this, ic);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,10 +40,19 @@ public class BlockLogarithm extends Block implements IParenthesis {
|
|||
recomputeDimensions();
|
||||
}
|
||||
|
||||
private BlockLogarithm(BlockLogarithm old, InputContext ic) {
|
||||
containerBase = old.containerBase.clone(ic);
|
||||
containerNumber = old.containerNumber.clone(ic);
|
||||
recomputeDimensions();
|
||||
private BlockLogarithm(final TreeContainer parent, BlockLogarithm old, InputContext ic) {
|
||||
super(parent, old);
|
||||
containerBase = old.containerBase.clone(this, ic);
|
||||
containerNumber = old.containerNumber.clone(this, ic);
|
||||
this.prw = old.prw;
|
||||
this.bw = old.bw;
|
||||
this.bh = old.bh;
|
||||
this.bl = old.bl;
|
||||
this.chw = old.chw;
|
||||
this.chh = old.chh;
|
||||
this.schh = old.schh;
|
||||
this.nmbh = old.nmbh;
|
||||
this.toph = old.toph;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -183,8 +192,8 @@ public class BlockLogarithm extends Block implements IParenthesis {
|
|||
}
|
||||
|
||||
@Override
|
||||
public BlockLogarithm clone(InputContext ic) {
|
||||
return new BlockLogarithm(this, ic);
|
||||
public BlockLogarithm clone(final TreeContainer parent, InputContext ic) {
|
||||
return new BlockLogarithm(parent, this, ic);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,9 +1,19 @@
|
|||
package it.cavallium.warppi.gui.expression.blocks;
|
||||
|
||||
import it.cavallium.warppi.gui.expression.InputContext;
|
||||
|
||||
public class BlockNumericChar extends BlockChar {
|
||||
|
||||
public BlockNumericChar(final char ch) {
|
||||
super(ch);
|
||||
}
|
||||
|
||||
private BlockNumericChar(final TreeContainer parent, BlockNumericChar old, InputContext ic) {
|
||||
super(parent, old, ic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockNumericChar clone(final TreeContainer parent, InputContext ic) {
|
||||
return new BlockNumericChar(parent, this, ic);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,8 +15,8 @@ public class BlockParenthesis extends BlockParenthesisAbstract {
|
|||
super(blocks);
|
||||
}
|
||||
|
||||
private BlockParenthesis(BlockParenthesis old, InputContext ic) {
|
||||
super(old, ic);
|
||||
private BlockParenthesis(final TreeContainer parent, BlockParenthesis old, InputContext ic) {
|
||||
super(parent, old, ic);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -38,8 +38,8 @@ public class BlockParenthesis extends BlockParenthesisAbstract {
|
|||
}
|
||||
|
||||
@Override
|
||||
public BlockParenthesis clone(InputContext ic) {
|
||||
return new BlockParenthesis(this, ic);
|
||||
public BlockParenthesis clone(final TreeContainer parent, InputContext ic) {
|
||||
return new BlockParenthesis(parent, this, ic);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,10 +31,18 @@ public abstract class BlockParenthesisAbstract extends Block implements IParenth
|
|||
recomputeDimensions();
|
||||
}
|
||||
|
||||
BlockParenthesisAbstract(BlockParenthesisAbstract old, InputContext ic) {
|
||||
containerNumber = old.containerNumber.clone(ic);
|
||||
prefix = old.prefix == null ? null : new String(old.prefix);
|
||||
recomputeDimensions();
|
||||
/**
|
||||
* Copy
|
||||
* @param old
|
||||
* @param ic
|
||||
*/
|
||||
BlockParenthesisAbstract(final TreeContainer parent, BlockParenthesisAbstract old, InputContext ic) {
|
||||
super(parent, old);
|
||||
containerNumber = old.containerNumber.clone(this, ic);
|
||||
prefix = old.prefix;
|
||||
prw = old.prw;
|
||||
chw = old.chw;
|
||||
chh = old.chh;
|
||||
}
|
||||
|
||||
public BlockParenthesisAbstract(final ObjectArrayList<Block> blocks) {
|
||||
|
|
|
@ -20,8 +20,9 @@ public class BlockPower extends Block {
|
|||
recomputeDimensions();
|
||||
}
|
||||
|
||||
private BlockPower(BlockPower old, InputContext ic) {
|
||||
this.containerExponent = old.containerExponent.clone(ic);
|
||||
protected BlockPower(final TreeContainer parent, BlockPower old, InputContext ic) {
|
||||
super(parent, old);
|
||||
this.containerExponent = old.containerExponent.clone(this, ic);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -100,7 +101,7 @@ public class BlockPower extends Block {
|
|||
}
|
||||
|
||||
@Override
|
||||
public BlockPower clone(InputContext ic) {
|
||||
return new BlockPower(this, ic);
|
||||
public BlockPower clone(final TreeContainer parent, InputContext ic) {
|
||||
return new BlockPower(parent, this, ic);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,8 +21,9 @@ public class BlockPower2 extends Block {
|
|||
recomputeDimensions();
|
||||
}
|
||||
|
||||
private BlockPower2(BlockPower2 old, InputContext ic) {
|
||||
this.containerExponent = old.containerExponent.clone(ic);
|
||||
private BlockPower2(final TreeContainer parent, BlockPower2 old, InputContext ic) {
|
||||
super(parent, old);
|
||||
this.containerExponent = old.containerExponent.clone(this, ic);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -106,7 +107,7 @@ public class BlockPower2 extends Block {
|
|||
}
|
||||
|
||||
@Override
|
||||
public BlockPower2 clone(InputContext ic) {
|
||||
return new BlockPower2(this, ic);
|
||||
public BlockPower2 clone(final TreeContainer parent, InputContext ic) {
|
||||
return new BlockPower2(parent, this, ic);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,8 +13,8 @@ public class BlockSine extends BlockParenthesisAbstract {
|
|||
super("SIN");
|
||||
}
|
||||
|
||||
private BlockSine(BlockSine old, InputContext ic) {
|
||||
super(old, ic);
|
||||
private BlockSine(final TreeContainer parent, BlockSine old, InputContext ic) {
|
||||
super(parent, old, ic);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,7 +24,7 @@ public class BlockSine extends BlockParenthesisAbstract {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Block clone(InputContext ic) {
|
||||
return new BlockSine(this, ic);
|
||||
public BlockSine clone(final TreeContainer parent, InputContext ic) {
|
||||
return new BlockSine(parent, this, ic);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,9 +22,10 @@ public class BlockSquareRoot extends Block {
|
|||
recomputeDimensions();
|
||||
}
|
||||
|
||||
private BlockSquareRoot(BlockSquareRoot old, InputContext ic) {
|
||||
this.containerNumber = old.containerNumber.clone(ic);
|
||||
recomputeDimensions();
|
||||
private BlockSquareRoot(final TreeContainer parent, BlockSquareRoot old, InputContext ic) {
|
||||
super(parent, old);
|
||||
this.containerNumber = old.containerNumber.clone(this, ic);
|
||||
this.h1 = old.h1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -118,7 +119,7 @@ public class BlockSquareRoot extends Block {
|
|||
}
|
||||
|
||||
@Override
|
||||
public BlockSquareRoot clone(InputContext ic) {
|
||||
return new BlockSquareRoot(this, ic);
|
||||
public BlockSquareRoot clone(final TreeContainer parent, InputContext ic) {
|
||||
return new BlockSquareRoot(parent, this, ic);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,8 +16,8 @@ public class BlockUndefined extends Block {
|
|||
recomputeDimensions();
|
||||
}
|
||||
|
||||
private BlockUndefined(BlockUndefined old, InputContext ic) {
|
||||
recomputeDimensions();
|
||||
private BlockUndefined(final TreeContainer parent, BlockUndefined old, InputContext ic) {
|
||||
super(parent, old);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -76,8 +76,8 @@ public class BlockUndefined extends Block {
|
|||
}
|
||||
|
||||
@Override
|
||||
public BlockUndefined clone(InputContext ic) {
|
||||
return new BlockUndefined(this, ic);
|
||||
public BlockUndefined clone(final TreeContainer parent, InputContext ic) {
|
||||
return new BlockUndefined(parent, this, ic);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -45,7 +45,8 @@ public class BlockVariable extends Block {
|
|||
recomputeDimensions();
|
||||
}
|
||||
|
||||
private BlockVariable(BlockVariable old, InputContext ic) {
|
||||
private BlockVariable(final TreeContainer parent, BlockVariable old, InputContext ic) {
|
||||
super(parent, old);
|
||||
this.ic = ic;
|
||||
this.ch = old.ch;
|
||||
type = old.type;
|
||||
|
@ -53,8 +54,7 @@ public class BlockVariable extends Block {
|
|||
typeDirtyID = old.typeDirtyID;
|
||||
this.typeLocked = old.typeLocked;
|
||||
menu = old.menu == null ? null : new VariableMenu(old.menu, this);
|
||||
retrieveValue();
|
||||
recomputeDimensions();
|
||||
mustRefresh = old.mustRefresh;
|
||||
}
|
||||
|
||||
private void retrieveValue() {
|
||||
|
@ -273,8 +273,8 @@ public class BlockVariable extends Block {
|
|||
}
|
||||
|
||||
@Override
|
||||
public VariableMenu clone(InputContext ic) {
|
||||
return new VariableMenu(this, block.clone(ic));
|
||||
public VariableMenu clone(final TreeContainer parent, InputContext ic) {
|
||||
return new VariableMenu(this, block.clone(parent, ic));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -295,7 +295,7 @@ public class BlockVariable extends Block {
|
|||
}
|
||||
|
||||
@Override
|
||||
public BlockVariable clone(InputContext ic) {
|
||||
return new BlockVariable(this, ic);
|
||||
public BlockVariable clone(final TreeContainer parent, InputContext ic) {
|
||||
return new BlockVariable(parent, this, ic);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ import it.cavallium.warppi.util.Error;
|
|||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
public abstract class InputContainer implements GraphicalElement, InputLayout {
|
||||
private static final long serialVersionUID = 923589369317765667L;
|
||||
protected BlockContainer root;
|
||||
protected Caret caret;
|
||||
private static final float CARET_DURATION = 0.5f;
|
||||
|
@ -61,11 +60,11 @@ public abstract class InputContainer implements GraphicalElement, InputLayout {
|
|||
*/
|
||||
protected InputContainer(InputContainer old, InputContext ic) {
|
||||
this.caretTime = old.caretTime;
|
||||
this.extra = old.extra == null ? null : old.extra.clone(ic);
|
||||
this.extra = old.extra == null ? null : old.extra.clone(null, ic);
|
||||
this.maxPosition = old.maxPosition;
|
||||
this.caret = old.caret == null ? null : new Caret(old.caret);
|
||||
this.inputContext = ic;
|
||||
this.root = old.root == null ? null : old.root.clone(ic);
|
||||
this.root = old.root == null ? null : old.root.clone(null, ic);
|
||||
this.parsed = old.parsed;
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,6 @@ public class NormalInputContainer extends InputContainer {
|
|||
* @param userInput
|
||||
* @param ic
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public NormalInputContainer(InputContainer old, InputContext ic) {
|
||||
super(old, ic);
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ public class SwingEngine implements GraphicEngine {
|
|||
exitSemaphore = new Semaphore(0);
|
||||
INSTANCE = new SwingWindow(this);
|
||||
setResizable(Engine.getPlatform().getSettings().isDebugEnabled());
|
||||
setDisplayMode(StaticVars.screenSize[0], StaticVars.screenSize[1]);
|
||||
setDisplayMode((int) (StaticVars.screenSize[0] / StaticVars.windowZoom.getLastValue()), (int) (StaticVars.screenSize[1] / StaticVars.windowZoom.getLastValue()));
|
||||
INSTANCE.setVisible(true);
|
||||
initialized = true;
|
||||
if (onInitialized != null)
|
||||
|
|
Loading…
Reference in New Issue
Block a user