added show/hide functionality for select button

This commit is contained in:
Cedric Beck
2024-12-01 23:33:28 +01:00
parent bec199036c
commit d3fe2fec14
5 changed files with 48 additions and 20 deletions

View File

@@ -107,7 +107,7 @@ public void simpleInitApp() {
gameView = new GameView(this);
ceremonyView = new CeremonyView(this);
enter(MdgaState.MAIN);
enter(MdgaState.GAME);
}
/**

View File

@@ -23,15 +23,22 @@ public class ModelSynchronizer {
private UUID a;
private UUID b;
private BonusCard card;
private boolean swap;
ModelSynchronizer(MdgaApp app) {
this.app = app;
swap = false;
}
public void animationEnd() {
app.getGameLogic().selectAnimationEnd();
}
public void select(UUID a, UUID b){
if(swap) selectSwap(a,b);
else selectPiece(a);
}
public void selectSwap(UUID a, UUID b) {
// TODO call from somewhere
LOGGER.log(Level.INFO, "selectPiece");
@@ -134,4 +141,8 @@ public void enter(MdgaState state) {
LOGGER.log(Level.INFO, "enter: {0}", state);
//app.enter(state);
}
public void setSwap(boolean swap){
this.swap = swap;
}
}

View File

@@ -21,10 +21,12 @@ public class NotificationSynchronizer {
public void addTestNotification(Notification n) {
notifications.add(n);
handleGame(n);
}
public void update() {
Notification n = app.getGameLogic().getNotification();
if(n != null) {
switch (app.getState()) {
case MAIN:
@@ -43,7 +45,6 @@ public void update() {
throw new RuntimeException("no notification expected: " + n.toString());
}
}
notifications.clear();
}
private void handleMain(Notification notification) {
@@ -75,6 +76,7 @@ private void handleGame(Notification notification) {
GameView gameView = (GameView) app.getView();
GuiHandler guiHandler = gameView.getGuiHandler();
BoardHandler boardHandler = gameView.getBoardHandler();
ModelSynchronizer modelSynchronizer = app.getModelSynchronize();
if (notification instanceof AcquireCardNotification n) {
guiHandler.addCard(n.getBonusCard());
@@ -166,10 +168,13 @@ private void handleGame(Notification notification) {
//TODO ???
} else if (notification instanceof SelectableMoveNotification n) {
boardHandler.outlineMove(n.getPieces(), n.getMoveIndices(), n.getHomeMoves());
modelSynchronizer.setSwap(false);
} else if (notification instanceof SelectableSwapNotification n) {
boardHandler.outlineSwap(n.getOwnPieces(), n.getEnemyPieces());
modelSynchronizer.setSwap(true);
} else if (notification instanceof SelectableShieldNotification n) {
boardHandler.outlineShield(n.getPieces());
modelSynchronizer.setSwap(false);
} else if (notification instanceof TurboActiveNotification){
guiHandler.turbo();
} else {

View File

@@ -439,6 +439,8 @@ else if(selectableEnemyPieces.contains(pieceSelected)) {
}
}
else throw new RuntimeException("pieceSelected is not in own/enemySelectablePieces");
app.getModelSynchronize().select(getKeyByValue(pieces, selectedOwnPiece), getKeyByValue(pieces, selectedEnemyPiece));
}
//called when view is no longer needed to select pieces
@@ -477,5 +479,13 @@ public void hideDice(){
diceControl.hide();
}
private <K, V> K getKeyByValue(Map<K, V> map, V value) {
for (Map.Entry<K, V> entry : map.entrySet()) {
if (entry.getValue().equals(value)) {
return entry.getKey();
}
}
return null;
}
}

View File

@@ -20,6 +20,7 @@
import pp.mdga.notification.RollDiceNotification;
import pp.mdga.notification.SelectableCardsNotification;
import pp.mdga.notification.SelectableMoveNotification;
import pp.mdga.notification.SelectableSwapNotification;
import pp.mdga.notification.ShieldActiveNotification;
import java.util.ArrayList;
@@ -69,27 +70,28 @@ public void onEnter() {
//Test
// List<UUID> uuid1 = new ArrayList<>();
// UUID p1 = UUID.randomUUID();
// UUID p2 = UUID.randomUUID();
// uuid1.add(p1);
// uuid1.add(p2);
// uuid1.add(UUID.randomUUID());
// uuid1.add(UUID.randomUUID());
// List<UUID> uuid2 = new ArrayList<>();
// UUID p1_2 = UUID.randomUUID();
// UUID p2_2 = UUID.randomUUID();
// uuid2.add(p1_2);
// uuid2.add(p2_2);
// uuid2.add(UUID.randomUUID());
// uuid2.add(UUID.randomUUID());
List<UUID> uuid1 = new ArrayList<>();
UUID p1 = UUID.randomUUID();
UUID p2 = UUID.randomUUID();
uuid1.add(p1);
uuid1.add(p2);
uuid1.add(UUID.randomUUID());
uuid1.add(UUID.randomUUID());
List<UUID> uuid2 = new ArrayList<>();
UUID p1_2 = UUID.randomUUID();
UUID p2_2 = UUID.randomUUID();
uuid2.add(p1_2);
uuid2.add(p2_2);
uuid2.add(UUID.randomUUID());
uuid2.add(UUID.randomUUID());
// app.getNotificationSynchronizer().addTestNotification(new PlayerInGameNotification(Color.AIRFORCE, uuid1, "Cedric"));
// app.getNotificationSynchronizer().addTestNotification(new PlayerInGameNotification(Color.NAVY, uuid2, "Test"));
// app.getNotificationSynchronizer().addTestNotification(new MovePieceNotification(p1, 0, true));
// app.getNotificationSynchronizer().addTestNotification(new MovePieceNotification(p1_2, 30, true));
app.getNotificationSynchronizer().addTestNotification(new PlayerInGameNotification(Color.AIRFORCE, uuid1, "Cedric"));
app.getNotificationSynchronizer().addTestNotification(new PlayerInGameNotification(Color.NAVY, uuid2, "Test"));
app.getNotificationSynchronizer().addTestNotification(new MovePieceNotification(p1, 0, true));
app.getNotificationSynchronizer().addTestNotification(new MovePieceNotification(p1_2, 20, true));
// app.getNotificationSynchronizer().addTestNotification(new SelectableMoveNotification(List.of(p1), List.of(4), List.of(false)));
// app.getNotificationSynchronizer().addTestNotification(new AcquireCardNotification(BonusCard.SHIELD));
app.getNotificationSynchronizer().addTestNotification(new SelectableSwapNotification(List.of(p1), List.of(p1_2)));
// app.getNotificationSynchronizer().addTestNotification(new SelectableCardsNotification(List.of(BonusCard.SHIELD)));
// app.getNotificationSynchronizer().addTestNotification(new ShieldActiveNotification(p1));