make the eventbus static
This commit is contained in:
@@ -66,7 +66,6 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
|
||||
|
||||
private static SGL GL = Renderer.get();
|
||||
|
||||
public final EventBus eventBus;
|
||||
private final InstanceContainer instanceContainer;
|
||||
|
||||
private FpsRenderState fpsState;
|
||||
@@ -117,9 +116,8 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
|
||||
public final Cursor cursor;
|
||||
public boolean drawCursor;
|
||||
|
||||
public DisplayContainer(InstanceContainer instanceContainer, EventBus eventBus) {
|
||||
public DisplayContainer(InstanceContainer instanceContainer) {
|
||||
this.instanceContainer = instanceContainer;
|
||||
this.eventBus = eventBus;
|
||||
this.cursor = new Cursor();
|
||||
drawCursor = true;
|
||||
instance = this;
|
||||
@@ -143,7 +141,7 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
|
||||
}
|
||||
};
|
||||
|
||||
eventBus.subscribe(ResolutionOrSkinChangedEvent.class, new EventListener<ResolutionOrSkinChangedEvent>() {
|
||||
EventBus.subscribe(ResolutionOrSkinChangedEvent.class, new EventListener<ResolutionOrSkinChangedEvent>() {
|
||||
@Override
|
||||
public void onEvent(ResolutionOrSkinChangedEvent event) {
|
||||
destroyImages();
|
||||
@@ -291,13 +289,13 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
|
||||
return true;
|
||||
}
|
||||
if (DownloadList.get().hasActiveDownloads()) {
|
||||
eventBus.post(new BubbleNotificationEvent(DownloadList.EXIT_CONFIRMATION, BubbleNotificationEvent.COMMONCOLOR_PURPLE));
|
||||
EventBus.post(new BubbleNotificationEvent(DownloadList.EXIT_CONFIRMATION, BubbleNotificationEvent.COMMONCOLOR_PURPLE));
|
||||
exitRequested = false;
|
||||
exitconfirmation = System.currentTimeMillis();
|
||||
return false;
|
||||
}
|
||||
if (Updater.get().getStatus() == Updater.Status.UPDATE_DOWNLOADING) {
|
||||
eventBus.post(new BubbleNotificationEvent(Updater.EXIT_CONFIRMATION, BubbleNotificationEvent.COMMONCOLOR_PURPLE));
|
||||
EventBus.post(new BubbleNotificationEvent(Updater.EXIT_CONFIRMATION, BubbleNotificationEvent.COMMONCOLOR_PURPLE));
|
||||
exitRequested = false;
|
||||
exitconfirmation = System.currentTimeMillis();
|
||||
return false;
|
||||
@@ -321,7 +319,7 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
|
||||
if (fullscreen) {
|
||||
fullscreen = false;
|
||||
Log.warn("could not find fullscreen displaymode for " + width + "x" + height);
|
||||
eventBus.post(new BubbleNotificationEvent("Fullscreen mode is not supported for " + width + "x" + height, BubbleNotificationEvent.COLOR_ORANGE));
|
||||
EventBus.post(new BubbleNotificationEvent("Fullscreen mode is not supported for " + width + "x" + height, BubbleNotificationEvent.COLOR_ORANGE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -357,7 +355,7 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
|
||||
GameImage.init(width, height);
|
||||
Fonts.init();
|
||||
|
||||
eventBus.post(new ResolutionOrSkinChangedEvent());
|
||||
EventBus.post(new ResolutionOrSkinChangedEvent());
|
||||
}
|
||||
|
||||
public void resetCursor() {
|
||||
|
||||
@@ -22,21 +22,16 @@ import java.util.*;
|
||||
@SuppressWarnings("unchecked")
|
||||
public class EventBus {
|
||||
|
||||
@Deprecated
|
||||
public static EventBus instance; // TODO get rid of this
|
||||
|
||||
private final List<Subscriber> subscribers;
|
||||
|
||||
public EventBus() {
|
||||
subscribers = new LinkedList<>();
|
||||
instance = this;
|
||||
private EventBus() {
|
||||
}
|
||||
|
||||
public <T> void subscribe(Class<T> eventType, EventListener<T> eventListener) {
|
||||
private static final List<Subscriber> subscribers = new LinkedList<>();
|
||||
|
||||
public static <T> void subscribe(Class<T> eventType, EventListener<T> eventListener) {
|
||||
subscribers.add(new Subscriber<>(eventType, eventListener));
|
||||
}
|
||||
|
||||
public void post(Object event) {
|
||||
public static void post(Object event) {
|
||||
for (Subscriber s : subscribers) {
|
||||
if (s.eventType.isInstance(event)) {
|
||||
s.listener.onEvent(event);
|
||||
@@ -44,7 +39,7 @@ public class EventBus {
|
||||
}
|
||||
}
|
||||
|
||||
private class Subscriber<T> {
|
||||
private static class Subscriber<T> {
|
||||
|
||||
private final Class<T> eventType;
|
||||
private final EventListener<T> listener;
|
||||
|
||||
@@ -20,7 +20,6 @@ package yugecin.opsudance.core.inject;
|
||||
import itdelatrisu.opsu.states.*;
|
||||
import yugecin.opsudance.PreStartupInitializer;
|
||||
import yugecin.opsudance.core.DisplayContainer;
|
||||
import yugecin.opsudance.core.events.EventBus;
|
||||
import yugecin.opsudance.core.state.specialstates.BarNotificationState;
|
||||
import yugecin.opsudance.core.state.specialstates.BubbleNotificationState;
|
||||
import yugecin.opsudance.core.state.specialstates.FpsRenderState;
|
||||
@@ -34,8 +33,6 @@ import yugecin.opsudance.states.EmptyState;
|
||||
public class OpsuDanceInjector extends Injector {
|
||||
|
||||
protected void configure() {
|
||||
bind(EventBus.class).asEagerSingleton();
|
||||
|
||||
bind(PreStartupInitializer.class).asEagerSingleton();
|
||||
bind(DisplayContainer.class).asEagerSingleton();
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import itdelatrisu.opsu.ui.UI;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Input;
|
||||
import yugecin.opsudance.core.DisplayContainer;
|
||||
import yugecin.opsudance.core.events.EventBus;
|
||||
import yugecin.opsudance.core.events.EventListener;
|
||||
import yugecin.opsudance.events.ResolutionOrSkinChangedEvent;
|
||||
|
||||
@@ -41,7 +42,7 @@ public abstract class BaseOpsuState implements OpsuState, EventListener<Resoluti
|
||||
|
||||
public BaseOpsuState(DisplayContainer displayContainer) {
|
||||
this.displayContainer = displayContainer;
|
||||
displayContainer.eventBus.subscribe(ResolutionOrSkinChangedEvent.class, this);
|
||||
EventBus.subscribe(ResolutionOrSkinChangedEvent.class, this);
|
||||
}
|
||||
|
||||
protected void revalidate() {
|
||||
|
||||
@@ -49,13 +49,13 @@ public class BarNotificationState implements EventListener<BarNotificationEvent>
|
||||
private int barHalfTargetHeight;
|
||||
private int barHalfHeight;
|
||||
|
||||
public BarNotificationState(DisplayContainer displayContainer, EventBus eventBus) {
|
||||
public BarNotificationState(DisplayContainer displayContainer) {
|
||||
this.displayContainer = displayContainer;
|
||||
this.bgcol = new Color(Color.black);
|
||||
this.textCol = new Color(Color.white);
|
||||
this.timeShown = TOTAL_TIME;
|
||||
eventBus.subscribe(BarNotificationEvent.class, this);
|
||||
eventBus.subscribe(ResolutionOrSkinChangedEvent.class, new EventListener<ResolutionOrSkinChangedEvent>() {
|
||||
EventBus.subscribe(BarNotificationEvent.class, this);
|
||||
EventBus.subscribe(ResolutionOrSkinChangedEvent.class, new EventListener<ResolutionOrSkinChangedEvent>() {
|
||||
@Override
|
||||
public void onEvent(ResolutionOrSkinChangedEvent event) {
|
||||
if (timeShown >= TOTAL_TIME) {
|
||||
|
||||
@@ -44,12 +44,12 @@ public class BubbleNotificationState implements EventListener<BubbleNotification
|
||||
private int addAnimationTime;
|
||||
private int addAnimationHeight;
|
||||
|
||||
public BubbleNotificationState(DisplayContainer displayContainer, EventBus eventBus) {
|
||||
public BubbleNotificationState(DisplayContainer displayContainer) {
|
||||
this.displayContainer = displayContainer;
|
||||
this.bubbles = new LinkedList<>();
|
||||
this.addAnimationTime = IN_TIME;
|
||||
eventBus.subscribe(BubbleNotificationEvent.class, this);
|
||||
eventBus.subscribe(ResolutionOrSkinChangedEvent.class, new EventListener<ResolutionOrSkinChangedEvent>() {
|
||||
EventBus.subscribe(BubbleNotificationEvent.class, this);
|
||||
EventBus.subscribe(ResolutionOrSkinChangedEvent.class, new EventListener<ResolutionOrSkinChangedEvent>() {
|
||||
@Override
|
||||
public void onEvent(ResolutionOrSkinChangedEvent event) {
|
||||
calculatePositions();
|
||||
|
||||
@@ -22,6 +22,7 @@ import itdelatrisu.opsu.ui.Fonts;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import yugecin.opsudance.core.DisplayContainer;
|
||||
import yugecin.opsudance.core.events.EventBus;
|
||||
import yugecin.opsudance.core.events.EventListener;
|
||||
import yugecin.opsudance.events.ResolutionOrSkinChangedEvent;
|
||||
import yugecin.opsudance.utils.FPSMeter;
|
||||
@@ -44,7 +45,7 @@ public class FpsRenderState implements EventListener<ResolutionOrSkinChangedEven
|
||||
this.displayContainer = displayContainer;
|
||||
fpsMeter = new FPSMeter(10);
|
||||
upsMeter = new FPSMeter(10);
|
||||
displayContainer.eventBus.subscribe(ResolutionOrSkinChangedEvent.class, this);
|
||||
EventBus.subscribe(ResolutionOrSkinChangedEvent.class, this);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
|
||||
@@ -186,7 +186,7 @@ public class MoveStoryboard extends OverlayOpsuState{
|
||||
|
||||
private StoryboardMove getCurrentMoveOrCreateNew() {
|
||||
if (gameObjects[objectIndex].isSlider() && trackPosition > gameObjects[objectIndex].getTime() && trackPosition < gameObjects[objectIndex].getEndTime()) {
|
||||
EventBus.instance.post(new BarNotificationEvent("Wait until the slider ended"));
|
||||
EventBus.post(new BarNotificationEvent("Wait until the slider ended"));
|
||||
return dummyMove;
|
||||
}
|
||||
if (moves[objectIndex] == null) {
|
||||
|
||||
@@ -20,6 +20,7 @@ package yugecin.opsudance.states;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import yugecin.opsudance.core.DisplayContainer;
|
||||
import yugecin.opsudance.core.events.EventBus;
|
||||
import yugecin.opsudance.core.state.OpsuState;
|
||||
import yugecin.opsudance.events.BarNotificationEvent;
|
||||
import yugecin.opsudance.events.BubbleNotificationEvent;
|
||||
@@ -74,7 +75,7 @@ public class EmptyRedState implements OpsuState {
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int key, char c) {
|
||||
displayContainer.eventBus.post(new BubbleNotificationEvent("this is a bubble notification... bubbly bubbly bubbly linewraaaaaaaaaap", BubbleNotificationEvent.COMMONCOLOR_RED));
|
||||
EventBus.post(new BubbleNotificationEvent("this is a bubble notification... bubbly bubbly bubbly linewraaaaaaaaaap", BubbleNotificationEvent.COMMONCOLOR_RED));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -85,7 +86,7 @@ public class EmptyRedState implements OpsuState {
|
||||
|
||||
@Override
|
||||
public boolean mouseWheelMoved(int delta) {
|
||||
displayContainer.eventBus.post(new BubbleNotificationEvent("Life is like a box of chocolates. It's all going to melt by the end of the day.\n-Emily", BubbleNotificationEvent.COMMONCOLOR_PURPLE));
|
||||
EventBus.post(new BubbleNotificationEvent("Life is like a box of chocolates. It's all going to melt by the end of the day.\n-Emily", BubbleNotificationEvent.COMMONCOLOR_PURPLE));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -96,7 +97,7 @@ public class EmptyRedState implements OpsuState {
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(int button, int x, int y) {
|
||||
displayContainer.eventBus.post(new BarNotificationEvent("this is a\nbar notification"));
|
||||
EventBus.post(new BarNotificationEvent("this is a\nbar notification"));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user