Skip to content

Commit

Permalink
Feat: Added widget enum
Browse files Browse the repository at this point in the history
Added widget enum that functions similarily to ViewEnum. Also added event subscribing to ingamecontroller so any publisher can change widget.
  • Loading branch information
tommyah committed May 24, 2026
1 parent e62eb66 commit 2172322
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
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()));
}
}
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
}

0 comments on commit 2172322

Please sign in to comment.