-
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.
Added widget enum that functions similarily to ViewEnum. Also added event subscribing to ingamecontroller so any publisher can change widget.
- Loading branch information
Showing
2 changed files
with
34 additions
and
2 deletions.
There are no files selected for viewing
26 changes: 24 additions & 2 deletions
26
src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ingame/InGameController.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 |
|---|---|---|
| @@ -1,21 +1,43 @@ | ||
| package edu.ntnu.idi.idatt2003.g40.mappe.view.ingame; | ||
|
|
||
| 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.widgets.WidgetEnum; | ||
| import javafx.scene.Node; | ||
| import java.util.EnumMap; | ||
|
|
||
| public class InGameController extends ViewController<InGameView> { | ||
| public final class InGameController extends ViewController<InGameView> | ||
| implements EventSubscriber { | ||
|
|
||
| private final EnumMap<WidgetEnum, Node> widgetMap = new EnumMap<>(WidgetEnum.class); | ||
|
|
||
| /** | ||
| * {@inheritDoc}. | ||
| */ | ||
| protected InGameController(final InGameView viewElement, | ||
| public InGameController(final InGameView viewElement, | ||
| final EventManager eventManager) | ||
| throws IllegalArgumentException { | ||
| super(viewElement, eventManager); | ||
| eventManager.addSubscriber(this, EventType.CHANGE_INGAME_CENTER); | ||
| } | ||
|
|
||
| public void addwidget(final WidgetEnum widgetEnum, final Node widgetRoot) { | ||
| widgetMap.put(widgetEnum, widgetRoot); | ||
| } | ||
|
|
||
| @Override | ||
| protected void initInteractions() { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public <T> void handleEvent(final EventData<T> data) { | ||
| if (!(data.data() instanceof WidgetEnum) || !widgetMap.containsKey(data.data())) { | ||
| throw new IllegalArgumentException("Invalid event thrown!"); | ||
| } | ||
| getViewElement().changeCenterView(widgetMap.get(data.data())); | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/WidgetEnum.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,10 @@ | ||
| package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets; | ||
|
|
||
| public enum WidgetEnum { | ||
| DASHBOARD, | ||
| MARKET, | ||
| MINIGAMES_OVERVIEW, | ||
| MINIGAMES_ENGINE, | ||
| STATS, | ||
| TRANSACTIONS | ||
| } |