From ed8356577c673f0d29c8cc22ad1fe94c06b80d62 Mon Sep 17 00:00:00 2001 From: LQ63 Date: Fri, 13 Dec 2024 11:07:53 +0100 Subject: [PATCH] added PickTrumpsuit Menu --- .../de/knockoutwhist/ui/gui/GUIMain.scala | 18 ++- .../scala/de/knockoutwhist/ui/gui/Game.scala | 6 +- .../knockoutwhist/ui/gui/PickTrumsuit.scala | 139 ++++++++++++++++++ 3 files changed, 157 insertions(+), 6 deletions(-) create mode 100644 src/main/scala/de/knockoutwhist/ui/gui/PickTrumsuit.scala diff --git a/src/main/scala/de/knockoutwhist/ui/gui/GUIMain.scala b/src/main/scala/de/knockoutwhist/ui/gui/GUIMain.scala index 642fc62..20bcb8f 100644 --- a/src/main/scala/de/knockoutwhist/ui/gui/GUIMain.scala +++ b/src/main/scala/de/knockoutwhist/ui/gui/GUIMain.scala @@ -2,8 +2,10 @@ package de.knockoutwhist.ui.gui import atlantafx.base.theme.PrimerDark import de.knockoutwhist.events.PLAYER_STATUS.SHOW_TURN -import de.knockoutwhist.events.{ShowGlobalStatus, ShowPlayerStatus} -import de.knockoutwhist.events.directional.RequestPlayersEvent +import de.knockoutwhist.events.ROUND_STATUS.WON_ROUND +import de.knockoutwhist.events.{ShowGlobalStatus, ShowPlayerStatus, ShowRoundStatus} +import de.knockoutwhist.events.directional.{RequestCardEvent, RequestPickTrumpsuitEvent, RequestPlayersEvent} +import de.knockoutwhist.events.round.ShowCurrentTrickEvent import de.knockoutwhist.events.ui.GameState.{INGAME, MAIN_MENU} import de.knockoutwhist.events.ui.GameStateUpdateEvent import de.knockoutwhist.ui.UI @@ -43,7 +45,17 @@ object GUIMain extends JFXApp3 with EventListener with UI { Game.updateStatus(event.player) Game.updatePlayerCards(event.player.hand.get) case _ => - + case event: ShowCurrentTrickEvent => + Game.updatePlayedCards(event.trick) + case event: ShowRoundStatus => + event.status match + case WON_ROUND => + Game.showWon(event.currentRound) + case _ => + case event: RequestCardEvent => + Game.requestCard = Some(event) + case event: RequestPickTrumpsuitEvent => + PickTrumsuit.showPickTrumpsuit(event) case event: SimpleEvent => println(s"Event ${event.id} not handled") } diff --git a/src/main/scala/de/knockoutwhist/ui/gui/Game.scala b/src/main/scala/de/knockoutwhist/ui/gui/Game.scala index 693dd5b..68c30a3 100644 --- a/src/main/scala/de/knockoutwhist/ui/gui/Game.scala +++ b/src/main/scala/de/knockoutwhist/ui/gui/Game.scala @@ -191,8 +191,8 @@ object Game { private[gui] var requestCard: Option[RequestCardEvent] = None - - def matchcard(card: Card): Boolean = { - true + def showWon(round: Round): Unit = { + val playerwon = round.winner + statusLabel.text = s"${playerwon.name} won the round!" } } \ No newline at end of file diff --git a/src/main/scala/de/knockoutwhist/ui/gui/PickTrumsuit.scala b/src/main/scala/de/knockoutwhist/ui/gui/PickTrumsuit.scala new file mode 100644 index 0000000..25fa387 --- /dev/null +++ b/src/main/scala/de/knockoutwhist/ui/gui/PickTrumsuit.scala @@ -0,0 +1,139 @@ +package de.knockoutwhist.ui.gui + +import de.knockoutwhist.cards.Suit +import de.knockoutwhist.control.{ControlHandler, ControlThread, PlayerLogic} +import de.knockoutwhist.events.directional.RequestPickTrumpsuitEvent +import de.knockoutwhist.events.ui.GameState.{INGAME, MAIN_MENU} +import de.knockoutwhist.events.ui.GameStateUpdateEvent +import de.knockoutwhist.utils.gui.Animations +import scalafx.geometry.Insets +import scalafx.geometry.Pos.{BottomCenter, TopCenter} +import scalafx.scene.control.Label +import scalafx.scene.image.{Image, ImageView} +import scalafx.scene.layout.Priority.Always +import scalafx.scene.layout.{HBox, StackPane, VBox} +import scalafx.scene.text.Font +import scalafx.util.Duration + +import scala.util.Try + +object PickTrumsuit { + + def showPickTrumpsuit(event: RequestPickTrumpsuitEvent): Unit = { + MainMenu.changeChild( + new StackPane { + children = Seq( + new VBox { + alignment = TopCenter + spacing = 10 + margin = Insets(20, 0, 0, 0) + hgrow = Always + children = Seq( + new Label { + alignment = TopCenter + text = "Pick your trumpsuit" + font = Font.font(30) + }, + new HBox { + alignment = BottomCenter + spacing = 10 + margin = Insets(200, 0, 20, 0) + children = Seq( + new ImageView { + alignment = BottomCenter + image = new Image("cards/AS.png") + fitWidth = 170 + fitHeight = 250 + onMouseClicked = _ => { + val slideOut = Animations.slideOutUp(children.head.asInstanceOf[javafx.scene.image.ImageView], Duration(400), -350) + slideOut.onFinished = _ => { + visible = false + } + slideOut.play() + ControlThread.runLater { + PlayerLogic.trumpSuitSelected(event.matchImpl, Try { + Suit.Spades + }, event.remaining_players, event.firstRound, event.player) + } + + } + }, + new ImageView { + alignment = BottomCenter + image = new Image("cards/AC.png") + fitWidth = 170 + fitHeight = 250 + onMouseClicked = _ => { + val slideOut = Animations.slideOutUp(children.head.asInstanceOf[javafx.scene.image.ImageView], Duration(400), -350) + slideOut.onFinished = _ => { + visible = false + } + slideOut.play() + ControlThread.runLater { + PlayerLogic.trumpSuitSelected(event.matchImpl, Try { + Suit.Clubs + }, event.remaining_players, event.firstRound, event.player) + } + + } + },new ImageView { + alignment = BottomCenter + image = new Image("cards/AH.png") + fitWidth = 170 + fitHeight = 250 + onMouseClicked = _ => { + val slideOut = Animations.slideOutUp(children.head.asInstanceOf[javafx.scene.image.ImageView], Duration(400), -350) + slideOut.onFinished = _ => { + visible = false + } + slideOut.play() + ControlThread.runLater { + PlayerLogic.trumpSuitSelected(event.matchImpl, Try { + Suit.Hearts + }, event.remaining_players, event.firstRound, event.player) + } + + + } + }, + new ImageView { + alignment = BottomCenter + image = new Image("cards/AD.png") + fitWidth = 170 + fitHeight = 250 + onMouseClicked = _ => { + val slideOut = Animations.slideOutUp(children.head.asInstanceOf[javafx.scene.image.ImageView], Duration(400), -350) + slideOut.onFinished = _ => { + visible = false + } + slideOut.play() + ControlThread.runLater { + PlayerLogic.trumpSuitSelected(event.matchImpl, Try{Suit.Diamonds}, event.remaining_players, event.firstRound, event.player) + } + } + }, + + ) + }, + new Label { + alignment = TopCenter + text = "Your Cards" + font = Font.font(20) + }, + new HBox { + alignment = TopCenter + alignment = BottomCenter + spacing = 10 + margin = Insets(200, 0, 20, 0) + children = event.player.currentHand().get.cards.map( i => new ImageView { + image = CardUtils.cardtoImage(i) + fitWidth = 170 + fitHeight = 250 + }) + } + ) + }, + ) + }) + } +}