Skip to content

Commit

Permalink
Feat: Fixed quit options
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyah committed May 26, 2026
1 parent ce6e36f commit da9852e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,14 @@ public enum EventType implements EventChannel {
* {@link edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.market.MarketController}
* and handled by {@link edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.dashboard.DashBoardController}</p>
* */
SELECT_STOCK_FOR_DASHBOARD;
SELECT_STOCK_FOR_DASHBOARD,

/**
* Event for showing quit options.
*
* <p>Published by the {@link edu.ntnu.idi.idatt2003.g40.mappe.view.ingame.InGameController}.
* Handled by the {@link edu.ntnu.idi.idatt2003.g40.mappe.view.ingame.quit.QuitDialogController}.</p>
* */
SHOW_QUIT_OPTIONS;

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventSubscriber;
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventType;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewData;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewEnum;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.WidgetEnum;
import java.util.EnumMap;
import javafx.scene.Node;
Expand Down Expand Up @@ -53,14 +51,6 @@ public void addwidget(final WidgetEnum widgetEnum, final Node widgetRoot) {
widgetMap.put(widgetEnum, widgetRoot);
}

/**
* Getter method for currently active widget.
* */
private WidgetEnum getActiveWidget() {
return activeWidget;
}


@Override
protected void initInteractions() {

Expand All @@ -75,8 +65,8 @@ public <T> void handleEvent(final EventData<T> data) {
if (data.data() == WidgetEnum.DASHBOARD) {
getViewElement().getTopBarView().setQuitText("Quit");
if (activeWidget == WidgetEnum.DASHBOARD) {
ViewData viewData = new ViewData(ViewEnum.MAIN_MENU);
EventData<ViewData> eventData = new EventData<>(EventType.SCENE_CHANGE, viewData);
EventData<Boolean> eventData =
new EventData<>(EventType.SHOW_QUIT_OPTIONS, true);
invoke(eventData);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import edu.ntnu.idi.idatt2003.g40.mappe.model.SaveGame;
import edu.ntnu.idi.idatt2003.g40.mappe.service.GameStateLoader;
import edu.ntnu.idi.idatt2003.g40.mappe.service.SaveGameService;
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventData;
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventManager;
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventSubscriber;
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventType;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewEnum;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ingame.InGameView;
Expand All @@ -30,7 +33,8 @@
* no-op rather than an error, since there's nothing meaningful to write.</p>
* */
public final class QuitDialogController
extends ViewController<QuitDialogView> {
extends ViewController<QuitDialogView>
implements EventSubscriber {

/** The in-game view hosting this overlay. */
private final InGameView inGameView;
Expand Down Expand Up @@ -67,6 +71,7 @@ public QuitDialogController(final QuitDialogView view,
this.gameStateLoader = gameStateLoader;
this.saveGameService = saveGameService;
super(view, eventManager);
eventManager.addSubscriber(this, EventType.SHOW_QUIT_OPTIONS);
if (inGameView == null
|| gameStateLoader == null
|| saveGameService == null) {
Expand Down Expand Up @@ -185,4 +190,9 @@ private boolean performSave() {
return false;
}
}

@Override
public <T> void handleEvent(EventData<T> data) {
show();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventManager;
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventType;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewEnum;
import javafx.scene.Node;
import java.util.function.Consumer;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.WidgetEnum;
import javafx.scene.Node;

/**
* Controller class for {@link TopBarView}.
Expand All @@ -17,46 +13,6 @@
* */
public class TopBarController extends ViewController<TopBarView> {

/**
* Whether the market is currently the active center-view.
*
* <p>
* When true, the quit/back button returns to the dashboard instead
* of exiting to the main menu.
* </p>
*/
private boolean inMarketView = false;

/**
* Whether the stats screen is currently the active center-view.
*
* <p>
* When true, the quit/back button returns to the dashboard instead
* of exiting to the main menu.
* </p>
*/
private boolean inStatsView = false;

/**
* Whether the transactions screen is currently the active center-view.
*
* <p>
* When true, the quit/back button returns to the dashboard instead
* of exiting to the main menu.
* </p>
*/
private boolean inTransactionsView = false;

/**
* Whether the minigames screen is currently the active center-view.
*
* <p>
* When true, the quit/back button returns to the dashboard instead
* of exiting to the main menu.
* </p>
*/
private boolean inMinigamesView = false;

/**
* Optional hook invoked just before the in-game session is left
* (when the quit/back button returns to the main menu).
Expand Down

0 comments on commit da9852e

Please sign in to comment.