Skip to content

Commit

Permalink
Feat: Now possible to access stock via market.
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyah committed May 26, 2026
1 parent 5be283a commit 76de2f1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,14 @@ public enum EventType implements EventChannel {
* edu.ntnu.idi.idatt2003.g40.mappe.model.SaveGame} that was loaded
* but most listeners don't inspect it.</p>
* */
STATE_RESET;
STATE_RESET,

/**
* Event for selecting a specific stock on the dashboard.
*
* <p>Published by
* {@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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public DashBoardController(final DashBoardView viewElement,
this.selectedTimeRange = DashBoardTimeRange.DEFAULT;
super(viewElement, eventManager);
eventManager.addSubscriber(this, EventType.STATE_RESET);
eventManager.addSubscriber(this, EventType.SELECT_STOCK_FOR_DASHBOARD);
}

/**
Expand Down Expand Up @@ -259,5 +260,13 @@ public <T> void handleEvent(final EventData<T> data) {
getViewElement().setCurrentStock(first, owned.floatValue());
}
getViewElement().updateGraph(selectedTimeRange);

if(data.channel() == EventType.SELECT_STOCK_FOR_DASHBOARD && data.data() instanceof Stock s) {
handleStockSelection(
s,
player.getPortfolio().getTotalShareQuantityBySymbol(s.getSymbol()).floatValue()
);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventType;
import edu.ntnu.idi.idatt2003.g40.mappe.utils.Validator;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.WidgetEnum;

import java.math.BigDecimal;
import java.util.List;
Expand Down Expand Up @@ -63,6 +64,17 @@ protected void initInteractions() {
getViewElement().setOwnedLookup(this::ownedQuantity);
getViewElement().setStocks(stockList);

getViewElement().setOnStockSelected(
(stock) -> {
EventData<Stock> eventData =
new EventData<>(EventType.SELECT_STOCK_FOR_DASHBOARD, stock);
EventData<WidgetEnum> changeViewData =
new EventData<>(EventType.CHANGE_INGAME_CENTER, WidgetEnum.DASHBOARD);
invoke(eventData);
invoke(changeViewData);
}
);

getViewElement().setOnAction(MarketActions.SORT_TICKER,
() -> getViewElement().setSort(MarketSort.TICKER));
getViewElement().setOnAction(MarketActions.SORT_PRICE,
Expand Down

0 comments on commit 76de2f1

Please sign in to comment.