added further notification implemenation

This commit is contained in:
Cedric Beck
2024-11-30 00:33:10 +01:00
parent 13690cf73d
commit 07f0f55192
14 changed files with 164 additions and 60 deletions

View File

@@ -96,10 +96,6 @@ else if(boardSelect != null) {
}
if(name.equals("Test") &&isPressed){
if(app.getView() instanceof GameView gameView){
gameView.getGuiHandler().test2();
// gameView.getGuiHandler().showDice();
// gameView.getBoardHandler().showDice(Color.AIRFORCE);
}
}
}

View File

@@ -82,13 +82,14 @@ private void handleGame(Notification notification) {
} else if (notification instanceof DiceNowNotification) {
guiHandler.showDice();
} else if (notification instanceof DicingNotification n) {
//TODO
} else if (notification instanceof DrawCardNotification n) {
//TODO ???
} else if (notification instanceof DrawCardNotification n) {
guiHandler.drawCard(n.getColor());
} else if (notification instanceof HomeMoveNotification home) {
boardHandler.moveHomePiece(home.getPieceId(), home.getHomeIndex());
guiHandler.hideText();
} else if (notification instanceof InterruptNotification) {
//TODO
//TODO ???
} else if (notification instanceof MovePieceNotification n) {
if(n.isMoveStart()) {
//StartMove
@@ -111,11 +112,16 @@ private void handleGame(Notification notification) {
}
} else if (notification instanceof PlayerInGameNotification n) {
boardHandler.addPlayer(n.getColor(),n.getPiecesList());
guiHandler.addPlayer(n.getColor(),n.getName(), gameView.getOwnColor() == n.getColor());
guiHandler.addPlayer(n.getColor(),n.getName());
} else if (notification instanceof ResumeNotification) {
} else if (notification instanceof RollDiceNotification n) {
guiHandler.rollDice(n.getEyes());
//TODO multiplicator
if(n.getColor() == gameView.getOwnColor()){
guiHandler.rollDice(n.getEyes(), n.isTurbo() ? n.getMultiplier() : -1);
}
else {
if (n.isTurbo()) guiHandler.showRolledDiceMult(n.getEyes(), n.getMultiplier(), n.getColor());
else guiHandler.showRolledDice(n.getEyes(), n.getColor());
}
} else if (notification instanceof SelectableCardsNotification n) {
guiHandler.setSelectableCards(n.getCards());
} else if (notification instanceof ShieldActiveNotification n) {
@@ -126,12 +132,17 @@ private void handleGame(Notification notification) {
app.enter(MdgaState.MAIN);
} else if (notification instanceof SwapPieceNotification n) {
boardHandler.swapPieces(n.getFirstPiece(), n.getSecondPiece());
guiHandler.swap();
} else if (notification instanceof WaitMoveNotification) {
//TODO disable all hover, highlight, etc
//TODO ???
} else if (notification instanceof SelectableMoveNotification n) {
boardHandler.outlineMove(n.getPieces(), n.getMoveIndexe(), n.getHomeMoves());
} else if (notification instanceof SelectableSwapNotification n) {
boardHandler.outlineSwap(n.getOwnPieces(), n.getEnemyPieces());
} else if (notification instanceof SelectableShieldNotification n) {
boardHandler.outlineShield(n.getOwnPieces());
} else if (notification instanceof TurboActiveNotification){
guiHandler.turbo();
} else {
throw new RuntimeException("notification not expected: " + notification.toString());
}

View File

@@ -431,6 +431,21 @@ public void outlineSwap(List<UUID> ownPieces, List<UUID> enemyPieces){
}
}
public void outlineShield(List<UUID> pieces){
selectableOwnPieces.clear();
selectableEnemyPieces.clear();
selectedOwnPiece = null;
selectedEnemyPiece = null;
for (UUID uuid : pieces){
PieceControl p = this.pieces.get(uuid);
p.highlight(false);
p.setHoverable(true);
p.setSelectable(true);
selectableOwnPieces.add(p);
}
}
//called from inputSynchronizer when a piece is selectable
public void pieceSelect(PieceControl pieceSelected) {
boolean isSelected = pieceSelected.isSelected();

View File

@@ -120,6 +120,9 @@ private ColorRGBA playerColorToColorRGBA(Color color){
};
}
public void hide(){
root.detachAllChildren();
}
}

View File

@@ -54,9 +54,9 @@ public void shutdown() {
cardLayer = null;
}
public void rollDice(int rollNum) {
public void rollDice(int rollNum, Runnable actionAfter) {
if (!(1 <= rollNum && rollNum <= 6)) throw new RuntimeException("rollNum is not in the range [1,6]");
diceControl.rollDice(rollNum);
diceControl.rollDice(rollNum, actionAfter);
}
public void showDice() {

View File

@@ -23,7 +23,7 @@ public class DiceControl extends AbstractControl {
private final Vector3f angularVelocity = new Vector3f();
private float deceleration = 0.5f;
private float timeElapsed = 0.0f;
private float rollDuration = 0.0001f;
private float rollDuration = 1f;
private static final int ANGULAR_MIN = 5;
private static final int ANGULAR_MAX = 15;
private static final int ANGULAR_SPIN = 10;
@@ -31,6 +31,7 @@ public class DiceControl extends AbstractControl {
private boolean slerp = false;
private boolean spin = false;
private final AssetManager assetManager;
private Runnable actionAfter;
public DiceControl(AssetManager assetManager){
this.assetManager = assetManager;
@@ -60,13 +61,14 @@ protected void controlUpdate(float tpf) {
if (timeElapsed > 1.0f) timeElapsed = 1.0f;
Quaternion interpolated = spatial.getLocalRotation().clone();
interpolated.nlerp(targetRotation, lerp(timeElapsed));
interpolated.slerp(targetRotation, timeElapsed);
spatial.setLocalRotation(interpolated);
// Stop rolling once duration is complete
if (timeElapsed >= 1.0f) {
isRolling = false;
slerp = false;
actionAfter.run();
}
}
}else if(spin){
@@ -90,11 +92,11 @@ protected void controlRender(RenderManager rm, ViewPort vp) {
}
public void rollDice(int diceNum) {
public void rollDice(int diceNum, Runnable actionAfter) {
if (isRolling) return;
spin = false;
slerp = false;
this.actionAfter = actionAfter;
angularVelocity.set(
FastMath.nextRandomInt(ANGULAR_MIN,ANGULAR_MAX),
FastMath.nextRandomInt(ANGULAR_MIN,ANGULAR_MAX),

View File

@@ -31,8 +31,23 @@ public void shutdown() {
cardLayerHandler.shutdown();
}
public void rollDice(int rollNum) {
cardLayerHandler.rollDice(rollNum);
public void rollDice(int rollNum, int mult) {
cardLayerHandler.rollDice(rollNum, ()->{
if(mult == -1) actionTextHandler.ownDice(rollNum);
else actionTextHandler.ownDiceMult(rollNum, mult);
hideDice();
//TODO send Model finished
});
}
public void showRolledDiceMult(int rollNum, int mult, Color color) {
String name = playerNameHandler.getName(color);
if(mult == -1) actionTextHandler.diceNum(rollNum, name, color);
else actionTextHandler.diceNumMult(rollNum, mult, name, color);
}
public void showRolledDice(int rollNum, Color color) {
actionTextHandler.diceNum(rollNum, playerNameHandler.getName(color), color);
}
public void showDice() {
@@ -67,8 +82,8 @@ public Node getCardLayerRootNode(){
return cardLayerHandler.getCardLayer().getRootNode();
}
public void addPlayer(Color color, String name, boolean own) {
playerNameHandler.addPlayer(color, name, own);
public void addPlayer(Color color, String name) {
playerNameHandler.addPlayer(color, name, color == ownColor);
}
public void setActivePlayer(Color color) {
@@ -78,14 +93,6 @@ public void setActivePlayer(Color color) {
else actionTextHandler.activePlayer(playerNameHandler.getName(color), color);
}
public void test() {
cardLayerHandler.test();
}
public void test2() {
actionTextHandler.drawCardOwn(Color.NAVY);
}
public void shield(){
cardLayerHandler.shield();
}
@@ -97,4 +104,15 @@ public void swap(){
public void turbo(){
cardLayerHandler.turbo();
}
public void hideText(){
actionTextHandler.hide();
}
public void drawCard(Color color) {
if (ownColor == color) actionTextHandler.drawCardOwn(color);
else actionTextHandler.drawCard(playerNameHandler.getName(color), color);
}
}

View File

@@ -32,9 +32,6 @@ public GameView(MdgaApp app) {
this.boardHandler = new BoardHandler(app, fpp);
app.getViewPort().addProcessor(fpp);
FrameBuffer backFrameBuffer = new FrameBuffer(app.getCamera().getWidth(), app.getCamera().getHeight(), 1);
Texture2D backTexture = new Texture2D(app.getCamera().getWidth(), app.getCamera().getHeight(), Image.Format.RGBA8);
backFrameBuffer.setDepthTarget(FrameBuffer.FrameBufferTarget.newTarget(Image.Format.Depth));
@@ -54,22 +51,6 @@ public void onEnter() {
boardHandler.init();
guiHandler.init();
continueButton.show();
// boardHandler.addPlayer(Color.AIRFORCE, test);
// boardHandler.movePieceStart(player0, 0);
// boardHandler.enableHover(player0);
// boardHandler.enableHover(player1);
// boardHandler.highlight(player0, true);
// boardHandler.outline(player0, true);
// boardHandler.outline(10);
guiHandler.test();
}
@Override