make the eventbus static

This commit is contained in:
yugecin 2017-02-06 00:39:45 +01:00
parent 8c53973fa5
commit 77a5ebf537
29 changed files with 97 additions and 104 deletions

View File

@ -729,7 +729,7 @@ public enum GameImage {
String err = String.format("Could not find default image '%s'.", filename);
Log.warn(err);
EventBus.instance.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
EventBus.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
}
/**
@ -788,7 +788,7 @@ public enum GameImage {
img = img.getScaledCopy(0.5f);
list.add(img);
} catch (SlickException e) {
EventBus.instance.post(new BubbleNotificationEvent(String.format("Failed to set image '%s'.", name), BubbleNotificationEvent.COMMONCOLOR_RED));
EventBus.post(new BubbleNotificationEvent(String.format("Failed to set image '%s'.", name), BubbleNotificationEvent.COMMONCOLOR_RED));
break;
}
}
@ -814,7 +814,7 @@ public enum GameImage {
img = img.getScaledCopy(0.5f);
return img;
} catch (SlickException e) {
EventBus.instance.post(new BubbleNotificationEvent(String.format("Failed to set image '%s'.", filename), BubbleNotificationEvent.COMMONCOLOR_RED));
EventBus.post(new BubbleNotificationEvent(String.format("Failed to set image '%s'.", filename), BubbleNotificationEvent.COMMONCOLOR_RED));
}
}
}

View File

@ -689,7 +689,7 @@ public class Options {
public void clickListItem(int index) {
if (Game.isInGame && Dancer.moverFactories[index] instanceof PolyMoverFactory) {
// TODO remove this when #79 is fixed
EventBus.instance.post(new BarNotificationEvent("This mover is disabled in the storyboard right now"));
EventBus.post(new BarNotificationEvent("This mover is disabled in the storyboard right now"));
return;
}
Dancer.instance.setMoverFactoryIndex(index);
@ -1343,7 +1343,7 @@ public class Options {
public static void setNextFPS(DisplayContainer displayContainer) {
GameOption.displayContainer = displayContainer; // TODO dirty shit
GameOption.TARGET_FPS.clickListItem((targetFPSindex + 1) % targetFPS.length);
EventBus.instance.post(new BarNotificationEvent(String.format("Frame limiter: %s", GameOption.TARGET_FPS.getValueString())));
EventBus.post(new BarNotificationEvent(String.format("Frame limiter: %s", GameOption.TARGET_FPS.getValueString())));
}
/**
@ -1430,7 +1430,7 @@ public class Options {
try {
container.setDisplayMode(width, height, isFullscreen());
} catch (Exception e) {
container.eventBus.post(new BubbleNotificationEvent("Failed to change resolution", BubbleNotificationEvent.COMMONCOLOR_RED));
EventBus.post(new BubbleNotificationEvent("Failed to change resolution", BubbleNotificationEvent.COMMONCOLOR_RED));
Log.error("Failed to set display mode.", e);
}
@ -1755,7 +1755,7 @@ public class Options {
*/
public static void toggleMouseDisabled() {
GameOption.DISABLE_MOUSE_BUTTONS.click();
EventBus.instance.post(new BarNotificationEvent((GameOption.DISABLE_MOUSE_BUTTONS.getBooleanValue()) ?
EventBus.post(new BarNotificationEvent((GameOption.DISABLE_MOUSE_BUTTONS.getBooleanValue()) ?
"Mouse buttons are disabled." : "Mouse buttons are enabled."));
}
@ -1845,7 +1845,7 @@ public class Options {
// use default directory
beatmapDir = BEATMAP_DIR;
if (!beatmapDir.isDirectory() && !beatmapDir.mkdir())
EventBus.instance.post(new BubbleNotificationEvent(String.format("Failed to create beatmap directory at '%s'.", beatmapDir.getAbsolutePath()), BubbleNotificationEvent.COMMONCOLOR_RED));
EventBus.post(new BubbleNotificationEvent(String.format("Failed to create beatmap directory at '%s'.", beatmapDir.getAbsolutePath()), BubbleNotificationEvent.COMMONCOLOR_RED));
return beatmapDir;
}
@ -1860,7 +1860,7 @@ public class Options {
oszDir = new File(DATA_DIR, "SongPacks/");
if (!oszDir.isDirectory() && !oszDir.mkdir())
EventBus.instance.post(new BubbleNotificationEvent(String.format("Failed to create song packs directory at '%s'.", oszDir.getAbsolutePath()), BubbleNotificationEvent.COMMONCOLOR_RED));
EventBus.post(new BubbleNotificationEvent(String.format("Failed to create song packs directory at '%s'.", oszDir.getAbsolutePath()), BubbleNotificationEvent.COMMONCOLOR_RED));
return oszDir;
}
@ -1875,7 +1875,7 @@ public class Options {
replayImportDir = new File(DATA_DIR, "ReplayImport/");
if (!replayImportDir.isDirectory() && !replayImportDir.mkdir())
EventBus.instance.post(new BubbleNotificationEvent(String.format("Failed to create replay import directory at '%s'.", replayImportDir.getAbsolutePath()), BubbleNotificationEvent.COMMONCOLOR_RED));
EventBus.post(new BubbleNotificationEvent(String.format("Failed to create replay import directory at '%s'.", replayImportDir.getAbsolutePath()), BubbleNotificationEvent.COMMONCOLOR_RED));
return replayImportDir;
}
@ -1925,14 +1925,14 @@ public class Options {
// use default directory
skinRootDir = SKIN_ROOT_DIR;
if (!skinRootDir.isDirectory() && !skinRootDir.mkdir())
EventBus.instance.post(new BubbleNotificationEvent(String.format("Failed to create skins directory at '%s'.", skinRootDir.getAbsolutePath()), BubbleNotificationEvent.COMMONCOLOR_RED));
EventBus.post(new BubbleNotificationEvent(String.format("Failed to create skins directory at '%s'.", skinRootDir.getAbsolutePath()), BubbleNotificationEvent.COMMONCOLOR_RED));
return skinRootDir;
}
public static void reloadSkin() {
loadSkin();
SoundController.init();
EventBus.instance.post(new ResolutionOrSkinChangedEvent());
EventBus.post(new ResolutionOrSkinChangedEvent());
}
/**
@ -2065,7 +2065,7 @@ public class Options {
} catch (IOException e) {
String err = String.format("Failed to read file '%s'.", OPTIONS_FILE.getAbsolutePath());
Log.error(err, e);
EventBus.instance.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
EventBus.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
}
}
@ -2096,7 +2096,7 @@ public class Options {
} catch (IOException e) {
String err = String.format("Failed to write to file '%s'.", OPTIONS_FILE.getAbsolutePath());
Log.error(err, e);
EventBus.instance.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
EventBus.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
}
}
}

View File

@ -248,7 +248,7 @@ public class Utils {
// create the screenshot directory
File dir = Options.getScreenshotDir();
if (!dir.isDirectory() && !dir.mkdir()) {
EventBus.instance.post(new BubbleNotificationEvent(String.format("Failed to create screenshot directory at '%s'.", dir.getAbsolutePath()), BubbleNotificationEvent.COMMONCOLOR_RED));
EventBus.post(new BubbleNotificationEvent(String.format("Failed to create screenshot directory at '%s'.", dir.getAbsolutePath()), BubbleNotificationEvent.COMMONCOLOR_RED));
return;
}
@ -282,7 +282,7 @@ public class Utils {
}
}
ImageIO.write(image, Options.getScreenshotFormat(), file);
EventBus.instance.post(new BubbleNotificationEvent("Created " + fileName, BubbleNotificationEvent.COMMONCOLOR_PURPLE));
EventBus.post(new BubbleNotificationEvent("Created " + fileName, BubbleNotificationEvent.COMMONCOLOR_PURPLE));
} catch (Exception e) {
ErrorHandler.error("Failed to take a screenshot.", e).show();
}

View File

@ -102,7 +102,7 @@ public class MusicController {
if (lastBeatmap == null || !beatmap.audioFilename.equals(lastBeatmap.audioFilename)) {
final File audioFile = beatmap.audioFilename;
if (!audioFile.isFile() && !ResourceLoader.resourceExists(audioFile.getPath())) {
EventBus.instance.post(new BarNotificationEvent(String.format("Could not find track '%s'.", audioFile.getName())));
EventBus.post(new BarNotificationEvent(String.format("Could not find track '%s'.", audioFile.getName())));
return;
}
@ -157,7 +157,7 @@ public class MusicController {
} catch (Exception e) {
String err = String.format("Could not play track '%s'.", file.getName());
Log.error(err, e);
EventBus.instance.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
EventBus.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
}
}

View File

@ -217,7 +217,7 @@ public class SoundController {
// menu and game sounds
for (SoundEffect s : SoundEffect.values()) {
if ((currentFileName = getSoundFileName(s.getFileName())) == null) {
EventBus.instance.post(new BubbleNotificationEvent("Could not find sound file " + s.getFileName(), BubbleNotificationEvent.COLOR_ORANGE));
EventBus.post(new BubbleNotificationEvent("Could not find sound file " + s.getFileName(), BubbleNotificationEvent.COLOR_ORANGE));
continue;
}
MultiClip newClip = loadClip(currentFileName, currentFileName.endsWith(".mp3"));
@ -236,7 +236,7 @@ public class SoundController {
for (HitSound s : HitSound.values()) {
String filename = String.format("%s-%s", ss.getName(), s.getFileName());
if ((currentFileName = getSoundFileName(filename)) == null) {
EventBus.instance.post(new BubbleNotificationEvent("Could not find hit sound file " + filename, BubbleNotificationEvent.COLOR_ORANGE));
EventBus.post(new BubbleNotificationEvent("Could not find hit sound file " + filename, BubbleNotificationEvent.COLOR_ORANGE));
continue;
}
MultiClip newClip = loadClip(currentFileName, false);
@ -392,7 +392,7 @@ public class SoundController {
@Override
public void error() {
EventBus.instance.post(new BarNotificationEvent("Failed to download track preview."));
EventBus.post(new BarNotificationEvent("Failed to download track preview."));
}
});
try {

View File

@ -160,7 +160,7 @@ public class BeatmapParser {
beatmap = parseFile(file, dir, beatmaps, false);
} catch(Exception e) {
Log.error("could not parse beatmap " + file.getName() + ": " + e.getMessage());
EventBus.instance.post(new BubbleNotificationEvent("Could not parse beatmap " + file.getName(), BubbleNotificationEvent.COLOR_ORANGE));
EventBus.post(new BubbleNotificationEvent("Could not parse beatmap " + file.getName(), BubbleNotificationEvent.COLOR_ORANGE));
}
// add to parsed beatmap list
@ -249,7 +249,7 @@ public class BeatmapParser {
} catch (IOException e) {
String err = String.format("Failed to read file '%s'.", map.getFile().getAbsolutePath());
Log.error(err, e);
EventBus.instance.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
EventBus.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
} catch (NoSuchAlgorithmException e) {
ErrorHandler.error("Failed to get MD5 hash stream.", e).show();
@ -654,7 +654,7 @@ public class BeatmapParser {
} catch (IOException e) {
String err = String.format("Failed to read file '%s'.", file.getAbsolutePath());
Log.error(err, e);
EventBus.instance.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
EventBus.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
} catch (NoSuchAlgorithmException e) {
ErrorHandler.error("Failed to get MD5 hash stream.", e).show();
@ -737,7 +737,7 @@ public class BeatmapParser {
} catch (IOException e) {
String err = String.format("Failed to read file '%s'.", beatmap.getFile().getAbsolutePath());
Log.error(err, e);
EventBus.instance.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
EventBus.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
}
}
@ -817,7 +817,7 @@ public class BeatmapParser {
} catch (IOException e) {
String err = String.format("Failed to read file '%s'.", beatmap.getFile().getAbsolutePath());
Log.error(err, e);
EventBus.instance.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
EventBus.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
}
}

View File

@ -216,7 +216,7 @@ public class BeatmapSetList {
try {
Utils.deleteToTrash(dir);
} catch (IOException e) {
EventBus.instance.post(new BubbleNotificationEvent("Could not delete song group", BubbleNotificationEvent.COLOR_ORANGE));
EventBus.post(new BubbleNotificationEvent("Could not delete song group", BubbleNotificationEvent.COLOR_ORANGE));
}
if (ws != null)
ws.resume();
@ -271,7 +271,7 @@ public class BeatmapSetList {
try {
Utils.deleteToTrash(file);
} catch (IOException e) {
EventBus.instance.post(new BubbleNotificationEvent("Could not delete song", BubbleNotificationEvent.COLOR_ORANGE));
EventBus.post(new BubbleNotificationEvent("Could not delete song", BubbleNotificationEvent.COLOR_ORANGE));
}
if (ws != null)
ws.resume();

View File

@ -98,7 +98,7 @@ public class BeatmapWatchService {
ws.register(Options.getBeatmapDir().toPath());
} catch (IOException e) {
Log.error("Could not create watch service", e);
EventBus.instance.post(new BubbleNotificationEvent("Could not create watch service", BubbleNotificationEvent.COMMONCOLOR_RED));
EventBus.post(new BubbleNotificationEvent("Could not create watch service", BubbleNotificationEvent.COMMONCOLOR_RED));
return;
}
@ -120,7 +120,7 @@ public class BeatmapWatchService {
ws = null;
} catch (IOException e) {
Log.error("An I/O exception occurred while closing the previous watch service.", e);
EventBus.instance.post(new BubbleNotificationEvent("An I/O exception occurred while closing the previous watch service.", BubbleNotificationEvent.COMMONCOLOR_RED));
EventBus.post(new BubbleNotificationEvent("An I/O exception occurred while closing the previous watch service.", BubbleNotificationEvent.COMMONCOLOR_RED));
ws = null;
}
}

View File

@ -101,7 +101,7 @@ public class OszUnpacker {
} catch (ZipException e) {
String err = String.format("Failed to unzip file %s to dest %s.", file.getAbsolutePath(), dest.getAbsolutePath());
Log.error(err, e);
EventBus.instance.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
EventBus.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
}
}

View File

@ -217,7 +217,7 @@ public class Download {
else if (redirectCount > MAX_REDIRECTS)
error = String.format("Download for URL '%s' is attempting too many redirects (over %d).", base.toString(), MAX_REDIRECTS);
if (error != null) {
EventBus.instance.post(new BubbleNotificationEvent(error, BubbleNotificationEvent.COLOR_ORANGE));
EventBus.post(new BubbleNotificationEvent(error, BubbleNotificationEvent.COLOR_ORANGE));
throw new IOException();
}

View File

@ -278,12 +278,12 @@ public class DownloadNode {
download.setListener(new DownloadListener() {
@Override
public void completed() {
EventBus.instance.post(new BarNotificationEvent(String.format("Download complete: %s", getTitle())));
EventBus.post(new BarNotificationEvent(String.format("Download complete: %s", getTitle())));
}
@Override
public void error() {
EventBus.instance.post(new BarNotificationEvent("Download failed due to a connection error."));
EventBus.post(new BarNotificationEvent("Download failed due to a connection error."));
}
});
this.download = download;
@ -404,7 +404,7 @@ public class DownloadNode {
public void drawDownload(Graphics g, float position, int id, boolean hover) {
Download download = this.download; // in case clearDownload() is called asynchronously
if (download == null) {
EventBus.instance.post(new BubbleNotificationEvent("Trying to draw download information for button without Download object", BubbleNotificationEvent.COLOR_ORANGE));
EventBus.post(new BubbleNotificationEvent("Trying to draw download information for button without Download object", BubbleNotificationEvent.COLOR_ORANGE));
return;
}

View File

@ -251,13 +251,13 @@ public class Updater {
@Override
public void completed() {
status = Status.UPDATE_DOWNLOADED;
EventBus.instance.post(new BarNotificationEvent("Update has finished downloading"));
EventBus.post(new BarNotificationEvent("Update has finished downloading"));
}
@Override
public void error() {
status = Status.CONNECTION_ERROR;
EventBus.instance.post(new BarNotificationEvent("Update failed due to a connection error."));
EventBus.post(new BarNotificationEvent("Update failed due to a connection error."));
}
});
}

View File

@ -275,7 +275,7 @@ public class Replay {
File dir = Options.getReplayDir();
if (!dir.isDirectory()) {
if (!dir.mkdir()) {
EventBus.instance.post(new BubbleNotificationEvent("Failed to create replay directory.", BubbleNotificationEvent.COMMONCOLOR_RED));
EventBus.post(new BubbleNotificationEvent("Failed to create replay directory.", BubbleNotificationEvent.COMMONCOLOR_RED));
return;
}
}

View File

@ -73,7 +73,7 @@ public class ReplayImporter {
if (!replayDir.mkdir()) {
String err = String.format("Failed to create replay directory '%s'.", replayDir.getAbsolutePath());
Log.error(err);
EventBus.instance.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
EventBus.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
return;
}
}
@ -88,7 +88,7 @@ public class ReplayImporter {
moveToFailedDirectory(file);
String err = String.format("Failed to import replay '%s'. The replay file could not be parsed.", file.getName());
Log.error(err, e);
EventBus.instance.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
EventBus.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
continue;
}
Beatmap beatmap = BeatmapSetList.get().getBeatmapFromHash(r.beatmapHash);
@ -107,7 +107,7 @@ public class ReplayImporter {
moveToFailedDirectory(file);
String err = String.format("Failed to import replay '%s'. The associated beatmap could not be found.", file.getName());
Log.error(err);
EventBus.instance.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
EventBus.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
}
}

View File

@ -293,7 +293,7 @@ public class SkinLoader {
} catch (IOException e) {
String err = String.format("Failed to read file '%s'.", skinFile.getAbsolutePath());
Log.error(err, e);
EventBus.instance.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
EventBus.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
}
return skin;

View File

@ -280,7 +280,7 @@ public class DownloadsMenu extends ComplexOpsuState {
this.importedNode = BeatmapParser.parseDirectories(dirs);
if (importedNode != null) {
// send notification
EventBus.instance.post(new BarNotificationEvent((dirs.length == 1) ? "Imported 1 new song." :
EventBus.post(new BarNotificationEvent((dirs.length == 1) ? "Imported 1 new song." :
String.format("Imported %d new songs.", dirs.length)));
}
}
@ -687,7 +687,7 @@ public class DownloadsMenu extends ComplexOpsuState {
if (playing)
previewID = node.getID();
} catch (SlickException e) {
EventBus.instance.post(new BarNotificationEvent("Failed to load track preview. See log for details."));
EventBus.post(new BarNotificationEvent("Failed to load track preview. See log for details."));
Log.error(e);
}
}
@ -710,7 +710,7 @@ public class DownloadsMenu extends ComplexOpsuState {
if (!DownloadList.get().contains(node.getID())) {
node.createDownload(serverMenu.getSelectedItem());
if (node.getDownload() == null) {
EventBus.instance.post(new BarNotificationEvent("The download could not be started"));
EventBus.post(new BarNotificationEvent("The download could not be started"));
} else {
DownloadList.get().addNode(node);
node.getDownload().start();
@ -952,7 +952,7 @@ public class DownloadsMenu extends ComplexOpsuState {
pageDir = Page.RESET;
previewID = -1;
if (barNotificationOnLoad != null) {
EventBus.instance.post(new BarNotificationEvent(barNotificationOnLoad));
EventBus.post(new BarNotificationEvent(barNotificationOnLoad));
barNotificationOnLoad = null;
}
}

View File

@ -344,7 +344,7 @@ public class Game extends ComplexOpsuState {
gOffscreen.setBackground(Color.black);
} catch (SlickException e) {
Log.error("could not create offscreen graphics", e);
displayContainer.eventBus.post(new BubbleNotificationEvent("Exception while creating offscreen graphics. See logfile for details.", BubbleNotificationEvent.COMMONCOLOR_RED));
EventBus.post(new BubbleNotificationEvent("Exception while creating offscreen graphics. See logfile for details.", BubbleNotificationEvent.COMMONCOLOR_RED));
}
// initialize music position bar location
@ -1184,7 +1184,7 @@ public class Game extends ComplexOpsuState {
int position = (pauseTime > -1) ? pauseTime : trackPosition;
if (Options.setCheckpoint(position / 1000)) {
SoundController.playSound(SoundEffect.MENUCLICK);
EventBus.instance.post(new BarNotificationEvent("Checkpoint saved."));
EventBus.post(new BarNotificationEvent("Checkpoint saved."));
}
}
break;
@ -1196,7 +1196,7 @@ public class Game extends ComplexOpsuState {
break; // invalid checkpoint
loadCheckpoint(checkpoint);
SoundController.playSound(SoundEffect.MENUHIT);
EventBus.instance.post(new BarNotificationEvent("Checkpoint loaded."));
EventBus.post(new BarNotificationEvent("Checkpoint loaded."));
}
break;
case Input.KEY_F:
@ -1241,12 +1241,12 @@ public class Game extends ComplexOpsuState {
break;
case Input.KEY_MINUS:
currentMapMusicOffset += 5;
EventBus.instance.post(new BarNotificationEvent("Current map offset: " + currentMapMusicOffset));
EventBus.post(new BarNotificationEvent("Current map offset: " + currentMapMusicOffset));
break;
}
if (key == Input.KEY_ADD || c == '+') {
currentMapMusicOffset -= 5;
EventBus.instance.post(new BarNotificationEvent("Current map offset: " + currentMapMusicOffset));
EventBus.post(new BarNotificationEvent("Current map offset: " + currentMapMusicOffset));
}
return true;
@ -1466,7 +1466,7 @@ public class Game extends ComplexOpsuState {
}
if (beatmap == null || beatmap.objects == null) {
displayContainer.eventBus.post(new BubbleNotificationEvent("Game was running without a beatmap", BubbleNotificationEvent.COMMONCOLOR_RED));
EventBus.post(new BubbleNotificationEvent("Game was running without a beatmap", BubbleNotificationEvent.COMMONCOLOR_RED));
displayContainer.switchStateInstantly(SongMenu.class);
}
@ -1568,7 +1568,7 @@ public class Game extends ComplexOpsuState {
} catch (Exception e) {
String message = String.format("Failed to create %s at index %d:\n%s", hitObject.getTypeName(), i, hitObject.toString());
Log.error(message, e);
displayContainer.eventBus.post(new BubbleNotificationEvent(message, BubbleNotificationEvent.COMMONCOLOR_RED));
EventBus.post(new BubbleNotificationEvent(message, BubbleNotificationEvent.COMMONCOLOR_RED));
gameObjects[i] = new DummyObject(hitObject);
}
}
@ -2154,7 +2154,7 @@ public class Game extends ComplexOpsuState {
this.replay = null;
} else {
if (replay.frames == null) {
displayContainer.eventBus.post(new BubbleNotificationEvent("Attempting to set a replay with no frames.", BubbleNotificationEvent.COLOR_ORANGE));
EventBus.post(new BubbleNotificationEvent("Attempting to set a replay with no frames.", BubbleNotificationEvent.COLOR_ORANGE));
return;
}
this.isReplay = true;

View File

@ -166,13 +166,13 @@ public class GameRanking extends BaseOpsuState {
gameState.setRestart((data.isGameplay()) ? Game.Restart.REPLAY : Game.Restart.NEW);
returnToGame = true;
} catch (FileNotFoundException e) {
EventBus.instance.post(new BarNotificationEvent("Replay file not found."));
EventBus.post(new BarNotificationEvent("Replay file not found."));
} catch (IOException e) {
Log.error("Failed to load replay data.", e);
EventBus.instance.post(new BarNotificationEvent("Failed to load replay data. See log for details."));
EventBus.post(new BarNotificationEvent("Failed to load replay data. See log for details."));
}
} else
EventBus.instance.post(new BarNotificationEvent("Replay file not found."));
EventBus.post(new BarNotificationEvent("Replay file not found."));
}
// retry

View File

@ -471,10 +471,10 @@ public class MainMenu extends BaseOpsuState {
UI.enter();
if (!enterNotification) {
if (Updater.get().getStatus() == Updater.Status.UPDATE_AVAILABLE) {
EventBus.instance.post(new BarNotificationEvent("An opsu! update is available."));
EventBus.post(new BarNotificationEvent("An opsu! update is available."));
enterNotification = true;
} else if (Updater.get().justUpdated()) {
EventBus.instance.post(new BarNotificationEvent("opsu! is now up to date!"));
EventBus.post(new BarNotificationEvent("opsu! is now up to date!"));
enterNotification = true;
}
}
@ -537,15 +537,15 @@ public class MainMenu extends BaseOpsuState {
if (musicPlay.contains(x, y)) {
if (MusicController.isPlaying()) {
MusicController.pause();
EventBus.instance.post(new BarNotificationEvent("Pause"));
EventBus.post(new BarNotificationEvent("Pause"));
} else if (!MusicController.isTrackLoading()) {
MusicController.resume();
EventBus.instance.post(new BarNotificationEvent("Play"));
EventBus.post(new BarNotificationEvent("Play"));
}
return true;
} else if (musicNext.contains(x, y)) {
nextTrack(true);
EventBus.instance.post(new BarNotificationEvent(">> Next"));
EventBus.post(new BarNotificationEvent(">> Next"));
return true;
} else if (musicPrevious.contains(x, y)) {
lastMeasureProgress = 0f;
@ -555,7 +555,7 @@ public class MainMenu extends BaseOpsuState {
bgAlpha.setTime(0);
} else
MusicController.setPosition(0);
EventBus.instance.post(new BarNotificationEvent("<< Previous"));
EventBus.post(new BarNotificationEvent("<< Previous"));
return true;
}
@ -571,10 +571,10 @@ public class MainMenu extends BaseOpsuState {
try {
Desktop.getDesktop().browse(Options.REPOSITORY_URI);
} catch (UnsupportedOperationException e) {
EventBus.instance.post(new BarNotificationEvent("The repository web page could not be opened."));
EventBus.post(new BarNotificationEvent("The repository web page could not be opened."));
} catch (IOException e) {
Log.error("could not browse to repo", e);
displayContainer.eventBus.post(new BubbleNotificationEvent("Could not browse to repo", BubbleNotificationEvent.COLOR_ORANGE));
EventBus.post(new BubbleNotificationEvent("Could not browse to repo", BubbleNotificationEvent.COLOR_ORANGE));
}
return true;
}
@ -583,10 +583,10 @@ public class MainMenu extends BaseOpsuState {
try {
Desktop.getDesktop().browse(Options.DANCE_REPOSITORY_URI);
} catch (UnsupportedOperationException e) {
EventBus.instance.post(new BarNotificationEvent("The repository web page could not be opened."));
EventBus.post(new BarNotificationEvent("The repository web page could not be opened."));
} catch (IOException e) {
Log.error("could not browse to repo", e);
displayContainer.eventBus.post(new BubbleNotificationEvent("Could not browse to repo", BubbleNotificationEvent.COLOR_ORANGE));
EventBus.post(new BubbleNotificationEvent("Could not browse to repo", BubbleNotificationEvent.COLOR_ORANGE));
}
return true;
}

View File

@ -455,7 +455,7 @@ public class SongMenu extends ComplexOpsuState {
if (!songFolderChanged && kind != StandardWatchEventKinds.ENTRY_MODIFY) {
songFolderChanged = true;
if (displayContainer.isInState(SongMenu.class)) {
EventBus.instance.post(new BarNotificationEvent("Changed is Songs folder detected. Hit F5 to refresh."));
EventBus.post(new BarNotificationEvent("Changed is Songs folder detected. Hit F5 to refresh."));
}
}
}
@ -961,7 +961,7 @@ public class SongMenu extends ComplexOpsuState {
setFocus(BeatmapSetList.get().getRandomNode(), -1, true, true);
if (BeatmapSetList.get().size() < 1 && group.getEmptyMessage() != null) {
EventBus.instance.post(new BarNotificationEvent(group.getEmptyMessage()));
EventBus.post(new BarNotificationEvent(group.getEmptyMessage()));
}
}
return true;
@ -1773,7 +1773,7 @@ public class SongMenu extends ComplexOpsuState {
Beatmap beatmap = MusicController.getBeatmap();
if (focusNode == null || beatmap != focusNode.getSelectedBeatmap()) {
EventBus.instance.post(new BarNotificationEvent("Unable to load the beatmap audio."));
EventBus.post(new BarNotificationEvent("Unable to load the beatmap audio."));
return;
}

View File

@ -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() {

View File

@ -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;

View File

@ -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();

View File

@ -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() {

View File

@ -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) {

View File

@ -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();

View File

@ -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() {

View File

@ -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) {

View File

@ -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;
}