-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
326 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/minigames/MiniGamesActions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames; | ||
|
|
||
| /** | ||
| * Action set for the associated {@link MiniGamesView}. | ||
| * */ | ||
| public enum MiniGamesActions { | ||
| /** | ||
| * Action when selecting clicker game. | ||
| * */ | ||
| CLICKER_GAME, | ||
|
|
||
| /** | ||
| * Action when selecting "find stock" game. | ||
| * */ | ||
| FIND_STOCK, | ||
|
|
||
| /** | ||
| * Action when selecting "time click" game. | ||
| * */ | ||
| TIME_CLICKS, | ||
|
|
||
| /** | ||
| * Action when clicking the question mark box (help section). | ||
| * */ | ||
| HELP | ||
| } |
62 changes: 62 additions & 0 deletions
62
...ain/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/minigames/MiniGamesController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames; | ||
|
|
||
| import edu.ntnu.idi.idatt2003.g40.mappe.model.Stock; | ||
| import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventManager; | ||
| import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewController; | ||
|
|
||
| /** | ||
| * Controller class for the associated {@link MiniGamesView} object. | ||
| * | ||
| * <p>Extends {@link ViewController}</p> | ||
| * */ | ||
| public final class MiniGamesController extends ViewController<MiniGamesView> { | ||
| private Stock activeStock; | ||
|
|
||
| public MiniGamesController(final MiniGamesView viewElement, | ||
| final EventManager eventManager, | ||
| final Stock initialStock) { | ||
| super(viewElement, eventManager); | ||
| this.activeStock = initialStock; | ||
| refresh(); | ||
| } | ||
|
|
||
| @Override | ||
| protected void initInteractions() { | ||
| getViewElement().setOnAction(MiniGamesActions.HELP, () -> { | ||
| // Implement help dialog or print logic | ||
| }); | ||
|
|
||
| getViewElement().setOnAction(MiniGamesActions.CLICKER_GAME, () -> { | ||
| // Logic for launching Clicker Game | ||
| }); | ||
|
|
||
| getViewElement().setOnAction(MiniGamesActions.FIND_STOCK, () -> { | ||
| // Logic for launching Find Stock Game | ||
| }); | ||
|
|
||
| getViewElement().setOnAction(MiniGamesActions.TIME_CLICKS, () -> { | ||
| // Logic for launching Time Clicks Game | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Sets the target stock context for the minigames. | ||
| * | ||
| * @param stock Chosen active layout context stock. | ||
| */ | ||
| public void setActiveStock(final Stock stock) { | ||
| this.activeStock = stock; | ||
| refresh(); | ||
| } | ||
|
|
||
| /** | ||
| * Syncs the current model status with view text properties. | ||
| */ | ||
| public void refresh() { | ||
| if (activeStock != null) { | ||
| getViewElement().setSelectedStockText(activeStock.getSymbol()); | ||
| } else { | ||
| getViewElement().setSelectedStockText("None"); | ||
| } | ||
| } | ||
| } |
120 changes: 120 additions & 0 deletions
120
src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/minigames/MiniGamesView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames; | ||
|
|
||
| import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewElement; | ||
| import javafx.geometry.Pos; | ||
| import javafx.scene.control.Button; | ||
| import javafx.scene.control.Label; | ||
| import javafx.scene.layout.HBox; | ||
| import javafx.scene.layout.Priority; | ||
| import javafx.scene.layout.Region; | ||
| import javafx.scene.layout.VBox; | ||
|
|
||
| /** | ||
| * Minigames view in the in game section of the application. | ||
| * */ | ||
| public final class MiniGamesView extends ViewElement<VBox, MiniGamesActions> { | ||
|
|
||
| private HBox headerBar; | ||
| private HBox gamesContainer; | ||
|
|
||
| private Label titleLabel; | ||
| private Label selectedStockLabel; | ||
| private Label stockValueLabel; | ||
|
|
||
| private Button helpBtn; | ||
| private Button clickerGameBtn; | ||
| private Button findStockBtn; | ||
| private Button timeClicksBtn; | ||
|
|
||
| /** | ||
| * Constructor. | ||
| */ | ||
| public MiniGamesView() throws IllegalArgumentException { | ||
| super(new VBox(), MiniGamesActions.class); | ||
| } | ||
|
|
||
| @Override | ||
| protected void initLayout() { | ||
| // Top header layout | ||
| headerBar = new HBox(); | ||
| headerBar.setAlignment(Pos.TOP_LEFT); | ||
|
|
||
| VBox titleSection = new VBox(); | ||
| titleLabel = new Label("Mini games"); | ||
|
|
||
| HBox stockSelectionRow = new HBox(); | ||
| stockSelectionRow.setAlignment(Pos.CENTER_LEFT); | ||
| selectedStockLabel = new Label("Selected stock: "); | ||
| stockValueLabel = new Label("AAPL"); | ||
| stockSelectionRow.getChildren().addAll(selectedStockLabel, stockValueLabel); | ||
|
|
||
| titleSection.getChildren().addAll(titleLabel, stockSelectionRow); | ||
|
|
||
| Region topSpacer = new Region(); | ||
| HBox.setHgrow(topSpacer, Priority.ALWAYS); | ||
|
|
||
| helpBtn = new Button("?"); | ||
| headerBar.getChildren().addAll(titleSection, topSpacer, helpBtn); | ||
|
|
||
| // Main central row container for games | ||
| gamesContainer = new HBox(); | ||
| gamesContainer.setAlignment(Pos.CENTER); | ||
|
|
||
| clickerGameBtn = new Button("Clicker game"); | ||
| findStockBtn = new Button("Find correct\nstock"); | ||
| timeClicksBtn = new Button("Time your clicks"); | ||
|
|
||
| // Make buttons fill equal proportions | ||
| HBox.setHgrow(clickerGameBtn, Priority.ALWAYS); | ||
| HBox.setHgrow(findStockBtn, Priority.ALWAYS); | ||
| HBox.setHgrow(timeClicksBtn, Priority.ALWAYS); | ||
|
|
||
| // Equal constraints on dimensions | ||
| configureGameButton(clickerGameBtn); | ||
| configureGameButton(findStockBtn); | ||
| configureGameButton(timeClicksBtn); | ||
|
|
||
| gamesContainer.getChildren().addAll(clickerGameBtn, findStockBtn, timeClicksBtn); | ||
|
|
||
| // Assemble view layers | ||
| VBox.setVgrow(gamesContainer, Priority.ALWAYS); | ||
| getRootPane().getChildren().addAll(headerBar, gamesContainer); | ||
|
|
||
| // Map interactions | ||
| registerButton(MiniGamesActions.HELP, helpBtn); | ||
| registerButton(MiniGamesActions.CLICKER_GAME, clickerGameBtn); | ||
| registerButton(MiniGamesActions.FIND_STOCK, findStockBtn); | ||
| registerButton(MiniGamesActions.TIME_CLICKS, timeClicksBtn); | ||
| } | ||
|
|
||
| private void configureGameButton(final Button btn) { | ||
| btn.setMaxWidth(Double.MAX_VALUE); | ||
| btn.setMaxHeight(Double.MAX_VALUE); | ||
| btn.setAlignment(Pos.CENTER); | ||
| } | ||
|
|
||
| /** | ||
| * Updates the selected stock text. | ||
| * | ||
| * @param symbol the symbol representing the stock selected. | ||
| */ | ||
| public void setSelectedStockText(final String symbol) { | ||
| stockValueLabel.setText(symbol); | ||
| } | ||
|
|
||
| @Override | ||
| protected void initStyling() { | ||
| getRootPane().getStyleClass().add("minigames-root"); | ||
| headerBar.getStyleClass().add("minigames-headerBar"); | ||
| titleLabel.getStyleClass().add("minigames-titleLabel"); | ||
| selectedStockLabel.getStyleClass().add("minigames-stockLabel"); | ||
| stockValueLabel.getStyleClass().add("minigames-stockValue"); | ||
|
|
||
| helpBtn.getStyleClass().add("minigames-helpBtn"); | ||
| gamesContainer.getStyleClass().add("minigames-container"); | ||
|
|
||
| clickerGameBtn.getStyleClass().add("minigames-cardBtn"); | ||
| findStockBtn.getStyleClass().add("minigames-cardBtn"); | ||
| timeClicksBtn.getStyleClass().add("minigames-cardBtn"); | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,5 +5,6 @@ public enum TopBarActions { | |
| STATS, | ||
| MARKET, | ||
| SETTINGS, | ||
| TRANSACTIONS; | ||
| TRANSACTIONS, | ||
| MINIGAMES; | ||
| } | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.