overhaul event system

This commit is contained in:
yugecin
2017-05-26 21:32:55 +02:00
parent b8dd507dc5
commit 1df25520e4
36 changed files with 354 additions and 324 deletions

View File

@@ -30,8 +30,7 @@ import org.newdawn.slick.SlickException;
import org.newdawn.slick.util.Log;
import org.newdawn.slick.util.ResourceLoader;
import yugecin.opsudance.core.errorhandling.ErrorHandler;
import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.events.BubbleNotificationEvent;
import yugecin.opsudance.events.BubNotifListener;
import yugecin.opsudance.skinning.SkinService;
import yugecin.opsudance.utils.SlickUtil;
@@ -733,7 +732,7 @@ public enum GameImage {
String err = String.format("Could not find default image '%s'.", filename);
Log.warn(err);
EventBus.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
BubNotifListener.EVENT.make().onBubNotif(err, BubNotifListener.COMMONCOLOR_RED);
}
/**
@@ -776,31 +775,34 @@ public enum GameImage {
* @return an array of the loaded images, or null if not found
*/
private Image[] loadImageArray(File dir) {
if (filenameFormat != null) {
for (String suffix : getSuffixes()) {
List<Image> list = new ArrayList<Image>();
int i = 0;
while (true) {
// look for next image
String filenameFormatted = String.format(filenameFormat + suffix, i++);
String name = getImageFileName(filenameFormatted, dir, type, true);
if (name == null)
break;
if (filenameFormat == null) {
return null;
}
for (String suffix : getSuffixes()) {
List<Image> list = new ArrayList<Image>();
int i = 0;
while (true) {
// look for next image
String filenameFormatted = String.format(filenameFormat + suffix, i++);
String name = getImageFileName(filenameFormatted, dir, type, true);
if (name == null)
break;
// add image to list
try {
Image img = new Image(name);
if (suffix.equals(HD_SUFFIX))
img = img.getScaledCopy(0.5f);
list.add(img);
} catch (SlickException e) {
EventBus.post(new BubbleNotificationEvent(String.format("Failed to set image '%s'.", name), BubbleNotificationEvent.COMMONCOLOR_RED));
break;
}
// add image to list
try {
Image img = new Image(name);
if (suffix.equals(HD_SUFFIX))
img = img.getScaledCopy(0.5f);
list.add(img);
} catch (SlickException e) {
BubNotifListener.EVENT.make().onBubNotif(
String.format("Failed to set image '%s'.", name),
BubNotifListener.COMMONCOLOR_RED);
break;
}
if (!list.isEmpty())
return list.toArray(new Image[list.size()]);
}
if (!list.isEmpty())
return list.toArray(new Image[list.size()]);
}
return null;
}
@@ -813,15 +815,18 @@ public enum GameImage {
private Image loadImageSingle(File dir) {
for (String suffix : getSuffixes()) {
String name = getImageFileName(filename + suffix, dir, type, true);
if (name != null) {
try {
Image img = new Image(name);
if (suffix.equals(HD_SUFFIX))
img = img.getScaledCopy(0.5f);
return img;
} catch (SlickException e) {
EventBus.post(new BubbleNotificationEvent(String.format("Failed to set image '%s'.", filename), BubbleNotificationEvent.COMMONCOLOR_RED));
}
if (name == null) {
continue;
}
try {
Image img = new Image(name);
if (suffix.equals(HD_SUFFIX))
img = img.getScaledCopy(0.5f);
return img;
} catch (SlickException e) {
BubNotifListener.EVENT.make().onBubNotif(
String.format("Failed to set image '%s'.", filename),
BubNotifListener.COMMONCOLOR_RED);
}
}
return null;

View File

@@ -47,6 +47,7 @@ import com.sun.jna.platform.FileUtils;
import yugecin.opsudance.core.NotNull;
import yugecin.opsudance.core.Nullable;
import yugecin.opsudance.core.errorhandling.ErrorHandler;
import yugecin.opsudance.events.BubNotifListener;
import static yugecin.opsudance.core.InstanceContainer.*;

View File

@@ -45,9 +45,8 @@ import org.newdawn.slick.util.Log;
import org.newdawn.slick.util.ResourceLoader;
import org.tritonus.share.sampled.file.TAudioFileFormat;
import yugecin.opsudance.core.errorhandling.ErrorHandler;
import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.events.BarNotificationEvent;
import yugecin.opsudance.events.BubbleNotificationEvent;
import yugecin.opsudance.events.BarNotifListener;
import yugecin.opsudance.events.BubNotifListener;
import static yugecin.opsudance.options.Options.*;
@@ -103,7 +102,8 @@ public class MusicController {
if (lastBeatmap == null || !beatmap.audioFilename.equals(lastBeatmap.audioFilename)) {
final File audioFile = beatmap.audioFilename;
if (!audioFile.isFile() && !ResourceLoader.resourceExists(audioFile.getPath())) {
EventBus.post(new BarNotificationEvent(String.format("Could not find track '%s'.", audioFile.getName())));
BarNotifListener.EVENT.make().onBarNotif(String.format("Could not find track '%s'.",
audioFile.getName()));
return;
}
@@ -158,7 +158,7 @@ public class MusicController {
} catch (Exception e) {
String err = String.format("Could not play track '%s'.", file.getName());
Log.error(err, e);
EventBus.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
BubNotifListener.EVENT.make().onBubNotif(err, BubNotifListener.COMMONCOLOR_RED);
}
}

View File

@@ -39,9 +39,8 @@ import javax.sound.sampled.LineUnavailableException;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.util.ResourceLoader;
import yugecin.opsudance.core.errorhandling.ErrorHandler;
import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.events.BarNotificationEvent;
import yugecin.opsudance.events.BubbleNotificationEvent;
import yugecin.opsudance.events.BarNotifListener;
import yugecin.opsudance.events.BubNotifListener;
import yugecin.opsudance.options.Configuration;
import yugecin.opsudance.skinning.SkinService;
@@ -220,7 +219,9 @@ public class SoundController {
// menu and game sounds
for (SoundEffect s : SoundEffect.values()) {
if ((currentFileName = getSoundFileName(s.getFileName())) == null) {
EventBus.post(new BubbleNotificationEvent("Could not find sound file " + s.getFileName(), BubbleNotificationEvent.COLOR_ORANGE));
BubNotifListener.EVENT.make().onBubNotif(
"Could not find sound file " + s.getFileName(),
BubNotifListener.COLOR_ORANGE);
continue;
}
MultiClip newClip = loadClip(currentFileName, currentFileName.endsWith(".mp3"));
@@ -239,7 +240,9 @@ public class SoundController {
for (HitSound s : HitSound.values()) {
String filename = String.format("%s-%s", ss.getName(), s.getFileName());
if ((currentFileName = getSoundFileName(filename)) == null) {
EventBus.post(new BubbleNotificationEvent("Could not find hit sound file " + filename, BubbleNotificationEvent.COLOR_ORANGE));
BubNotifListener.EVENT.make().onBubNotif(
"Could not find hit sound file " + filename,
BubNotifListener.COLOR_ORANGE);
continue;
}
MultiClip newClip = loadClip(currentFileName, false);
@@ -396,7 +399,8 @@ public class SoundController {
@Override
public void error() {
EventBus.post(new BarNotificationEvent("Failed to download track preview."));
BarNotifListener.EVENT.make().onBarNotif(
"Failed to download track preview");
}
});
try {

View File

@@ -33,9 +33,9 @@ import java.util.Map;
import org.newdawn.slick.Color;
import org.newdawn.slick.util.Log;
import yugecin.opsudance.core.Nullable;
import yugecin.opsudance.core.errorhandling.ErrorHandler;
import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.events.BubbleNotificationEvent;
import yugecin.opsudance.events.BubNotifListener;
import yugecin.opsudance.skinning.SkinService;
import static yugecin.opsudance.core.InstanceContainer.*;
@@ -93,8 +93,8 @@ public class BeatmapParser {
* @param dirs the array of directories to parse
* @return the last BeatmapSetNode parsed, or null if none
*/
public BeatmapSetNode parseDirectories(File[] dirs) {
if (dirs == null)
public BeatmapSetNode parseDirectories(@Nullable File[] dirs) {
if (dirs == null || dirs.length == 0)
return null;
// progress tracking
@@ -159,8 +159,8 @@ public class BeatmapParser {
try {
beatmap = parseFile(file, dir, beatmaps, false);
} catch(Exception e) {
Log.error("could not parse beatmap " + file.getName() + ": " + e.getMessage());
EventBus.post(new BubbleNotificationEvent("Could not parse beatmap " + file.getName(), BubbleNotificationEvent.COLOR_ORANGE));
logAndShowErrorNotification(e, "Could not parse beatmap %s: %s",
file.getName(), e.getMessage());
}
// add to parsed beatmap list
@@ -247,9 +247,7 @@ public class BeatmapParser {
}
map.timingPoints.trimToSize();
} catch (IOException e) {
String err = String.format("Failed to read file '%s'.", map.getFile().getAbsolutePath());
Log.error(err, e);
EventBus.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
logAndShowErrorNotification(e, "Failed to read file '%s'.", map.getFile().getAbsolutePath());
} catch (NoSuchAlgorithmException e) {
ErrorHandler.error("Failed to get MD5 hash stream.", e).show();
@@ -652,9 +650,7 @@ public class BeatmapParser {
if (md5stream != null)
beatmap.md5Hash = md5stream.getMD5();
} catch (IOException e) {
String err = String.format("Failed to read file '%s'.", file.getAbsolutePath());
Log.error(err, e);
EventBus.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
logAndShowErrorNotification(e, "Failed to read file '%s'.", file.getAbsolutePath());
} catch (NoSuchAlgorithmException e) {
ErrorHandler.error("Failed to get MD5 hash stream.", e).show();
@@ -735,9 +731,8 @@ public class BeatmapParser {
}
beatmap.timingPoints.trimToSize();
} catch (IOException e) {
String err = String.format("Failed to read file '%s'.", beatmap.getFile().getAbsolutePath());
Log.error(err, e);
EventBus.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
logAndShowErrorNotification(e, "Failed to read file '%s'.",
beatmap.getFile().getAbsolutePath());
}
}
@@ -818,9 +813,8 @@ public class BeatmapParser {
ErrorHandler.error(String.format("Parsed %d objects for beatmap '%s', %d objects expected.",
objectIndex, beatmap.toString(), beatmap.objects.length), new Exception("no")).show();
} catch (IOException e) {
String err = String.format("Failed to read file '%s'.", beatmap.getFile().getAbsolutePath());
Log.error(err, e);
EventBus.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
logAndShowErrorNotification(e, "Failed to read file '%s'.",
beatmap.getFile().getAbsolutePath());
}
}
@@ -891,4 +885,10 @@ public class BeatmapParser {
return DBString;
}
private static void logAndShowErrorNotification(Exception e, String message, Object... formatArgs) {
message = String.format(message, formatArgs);
Log.error(message, e);
BubNotifListener.EVENT.make().onBubNotif(message, BubNotifListener.COMMONCOLOR_RED);
}
}

View File

@@ -21,8 +21,7 @@ package itdelatrisu.opsu.beatmap;
import itdelatrisu.opsu.Utils;
import itdelatrisu.opsu.audio.MusicController;
import itdelatrisu.opsu.db.BeatmapDB;
import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.events.BubbleNotificationEvent;
import yugecin.opsudance.events.BubNotifListener;
import java.io.File;
import java.io.IOException;
@@ -215,7 +214,8 @@ public class BeatmapSetList {
try {
Utils.deleteToTrash(dir);
} catch (IOException e) {
EventBus.post(new BubbleNotificationEvent("Could not delete song group", BubbleNotificationEvent.COLOR_ORANGE));
BubNotifListener.EVENT.make().onBubNotif("Could not delete song group",
BubNotifListener.COLOR_ORANGE);
}
if (ws != null)
ws.resume();
@@ -271,7 +271,7 @@ public class BeatmapSetList {
try {
Utils.deleteToTrash(file);
} catch (IOException e) {
EventBus.post(new BubbleNotificationEvent("Could not delete song", BubbleNotificationEvent.COLOR_ORANGE));
BubNotifListener.EVENT.make().onBubNotif("Could not delete song", BubNotifListener.COLOR_ORANGE);
}
if (ws != null)
ws.resume();

View File

@@ -39,8 +39,8 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.newdawn.slick.util.Log;
import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.events.BubbleNotificationEvent;
import yugecin.opsudance.events.BarNotifListener;
import yugecin.opsudance.events.BubNotifListener;
import static yugecin.opsudance.core.InstanceContainer.*;
import static yugecin.opsudance.options.Options.*;
@@ -100,7 +100,8 @@ public class BeatmapWatchService {
ws.register(config.beatmapDir.toPath());
} catch (IOException e) {
Log.error("Could not create watch service", e);
EventBus.post(new BubbleNotificationEvent("Could not create watch service", BubbleNotificationEvent.COMMONCOLOR_RED));
BubNotifListener.EVENT.make().onBubNotif("Could not create watch service",
BubNotifListener.COMMONCOLOR_RED);
return;
}
@@ -121,8 +122,9 @@ public class BeatmapWatchService {
ws.service.shutdownNow();
ws = null;
} catch (IOException e) {
Log.error("An I/O exception occurred while closing the previous watch service.", e);
EventBus.post(new BubbleNotificationEvent("An I/O exception occurred while closing the previous watch service.", BubbleNotificationEvent.COMMONCOLOR_RED));
String msg = "An I/O exception occurred while closing the previous watch service.";
Log.error(msg, e);
BarNotifListener.EVENT.make().onBarNotif(msg);
ws = null;
}
}
@@ -137,7 +139,10 @@ public class BeatmapWatchService {
return ws;
}
/** Watch service listener interface. */
/**
* Watch service listener interface.
* TODO: replace by event system?
*/
public interface BeatmapWatchServiceListener {
/**
* Indication that an event was received.

View File

@@ -26,8 +26,7 @@ import java.util.List;
import net.lingala.zip4j.core.ZipFile;
import net.lingala.zip4j.exception.ZipException;
import org.newdawn.slick.util.Log;
import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.events.BubbleNotificationEvent;
import yugecin.opsudance.events.BubNotifListener;
import static yugecin.opsudance.core.InstanceContainer.*;
@@ -97,7 +96,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.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
BubNotifListener.EVENT.make().onBubNotif(err, BubNotifListener.COMMONCOLOR_RED);
}
}

View File

@@ -35,8 +35,7 @@ import java.nio.file.StandardCopyOption;
import org.newdawn.slick.util.Log;
import yugecin.opsudance.core.errorhandling.ErrorHandler;
import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.events.BubbleNotificationEvent;
import yugecin.opsudance.events.BubNotifListener;
/**
* File download.
@@ -219,7 +218,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.post(new BubbleNotificationEvent(error, BubbleNotificationEvent.COLOR_ORANGE));
BubNotifListener.EVENT.make().onBubNotif(error, BubNotifListener.COLOR_ORANGE);
throw new IOException();
}

View File

@@ -33,9 +33,8 @@ import java.io.File;
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.events.BarNotificationEvent;
import yugecin.opsudance.events.BubbleNotificationEvent;
import yugecin.opsudance.events.BarNotifListener;
import yugecin.opsudance.events.BubNotifListener;
import static yugecin.opsudance.core.InstanceContainer.*;
import static yugecin.opsudance.options.Options.*;
@@ -281,12 +280,14 @@ public class DownloadNode {
download.setListener(new DownloadListener() {
@Override
public void completed() {
EventBus.post(new BarNotificationEvent(String.format("Download complete: %s", getTitle())));
BarNotifListener.EVENT.make().onBarNotif(
String.format("Download complete: %s", getTitle()));
}
@Override
public void error() {
EventBus.post(new BarNotificationEvent("Download failed due to a connection error."));
BarNotifListener.EVENT.make().onBarNotif(
"Download failed due to a connection error.");
}
});
this.download = download;
@@ -408,7 +409,9 @@ 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.post(new BubbleNotificationEvent("Trying to draw download information for button without Download object", BubbleNotificationEvent.COLOR_ORANGE));
BubNotifListener.EVENT.make().onBubNotif(
"Trying to draw download information for button without Download object",
BubNotifListener.COLOR_ORANGE);
return;
}

View File

@@ -37,8 +37,7 @@ import org.newdawn.slick.util.Log;
import org.newdawn.slick.util.ResourceLoader;
import yugecin.opsudance.core.Constants;
import yugecin.opsudance.core.errorhandling.ErrorHandler;
import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.events.BarNotificationEvent;
import yugecin.opsudance.events.BarNotifListener;
import static yugecin.opsudance.core.InstanceContainer.*;
@@ -242,13 +241,14 @@ public class Updater {
@Override
public void completed() {
status = Status.UPDATE_DOWNLOADED;
EventBus.post(new BarNotificationEvent("Update has finished downloading"));
BarNotifListener.EVENT.make().onBarNotif("Update has finished downloading");
}
@Override
public void error() {
status = Status.CONNECTION_ERROR;
EventBus.post(new BarNotificationEvent("Update failed due to a connection error."));
BarNotifListener.EVENT.make().onBarNotif(
"Update failed due to a connection error.");
}
});
}

View File

@@ -44,8 +44,7 @@ import org.newdawn.slick.util.Log;
import lzma.streams.LzmaOutputStream;
import yugecin.opsudance.core.errorhandling.ErrorHandler;
import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.events.BubbleNotificationEvent;
import yugecin.opsudance.events.BubNotifListener;
import static yugecin.opsudance.core.InstanceContainer.*;
@@ -275,7 +274,7 @@ public class Replay {
public void save() {
// create replay directory
if (!config.replayDir.isDirectory() && !config.replayDir.mkdir()) {
EventBus.post(new BubbleNotificationEvent("Failed to create replay directory.", BubbleNotificationEvent.COMMONCOLOR_RED));
BubNotifListener.EVENT.make().onBubNotif("Failed to create replay directory", BubNotifListener.COMMONCOLOR_RED);
return;
}

View File

@@ -29,8 +29,7 @@ import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import org.newdawn.slick.util.Log;
import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.events.BubbleNotificationEvent;
import yugecin.opsudance.events.BubNotifListener;
import static yugecin.opsudance.core.InstanceContainer.*;
@@ -69,7 +68,7 @@ public class ReplayImporter {
if (!config.replayDir.isDirectory() && !config.replayDir.mkdir()) {
String err = String.format("Failed to create replay directory '%s'.", config.replayDir.getAbsolutePath());
Log.error(err);
EventBus.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
BubNotifListener.EVENT.make().onBubNotif(err, BubNotifListener.COMMONCOLOR_RED);
return;
}
@@ -83,7 +82,8 @@ 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.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
BubNotifListener.EVENT.make().onBubNotif(err,
BubNotifListener.COMMONCOLOR_RED);
continue;
}
Beatmap beatmap = BeatmapSetList.get().getBeatmapFromHash(r.beatmapHash);
@@ -102,7 +102,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.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
BubNotifListener.EVENT.make().onBubNotif(err, BubNotifListener.COMMONCOLOR_RED);
}
}

View File

@@ -31,8 +31,7 @@ import java.util.LinkedList;
import org.newdawn.slick.Color;
import org.newdawn.slick.util.Log;
import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.events.BubbleNotificationEvent;
import yugecin.opsudance.events.BubNotifListener;
/**
* Loads skin configuration files.
@@ -293,7 +292,8 @@ public class SkinLoader {
} catch (IOException e) {
String err = String.format("Failed to read file '%s'.", skinFile.getAbsolutePath());
Log.error(err, e);
EventBus.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED));
BubNotifListener.EVENT.make().onBubNotif(err,
BubNotifListener.COMMONCOLOR_RED);
}
return skin;

View File

@@ -52,9 +52,8 @@ import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.gui.TextField;
import org.newdawn.slick.util.Log;
import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.core.state.ComplexOpsuState;
import yugecin.opsudance.events.BarNotificationEvent;
import yugecin.opsudance.events.BarNotifListener;
import static yugecin.opsudance.core.InstanceContainer.*;
@@ -266,16 +265,20 @@ public class DownloadsMenu extends ComplexOpsuState {
private void importBeatmaps() {
// invoke unpacker and parser
File[] dirs = oszunpacker.unpackAll();
if (dirs != null && dirs.length > 0) {
this.importedNode = beatmapParser.parseDirectories(dirs);
if (importedNode != null) {
// send notification
EventBus.post(new BarNotificationEvent((dirs.length == 1) ? "Imported 1 new song." :
String.format("Imported %d new songs.", dirs.length)));
}
}
this.importedNode = beatmapParser.parseDirectories(dirs);
DownloadList.get().clearDownloads(Download.Status.COMPLETE);
if (this.importedNode == null) {
return;
}
String msg;
if (dirs.length == 1) {
msg = "Imported 1 new song.";
} else {
msg = String.format("Imported %d new songs.", dirs.length);
}
BarNotifListener.EVENT.make().onBarNotif(msg);
}
}
@@ -682,7 +685,7 @@ public class DownloadsMenu extends ComplexOpsuState {
if (playing)
previewID = node.getID();
} catch (SlickException e) {
EventBus.post(new BarNotificationEvent("Failed to load track preview. See log for details."));
BarNotifListener.EVENT.make().onBarNotif("Failed to load track preview. See log for details.");
Log.error(e);
}
}
@@ -705,7 +708,7 @@ public class DownloadsMenu extends ComplexOpsuState {
if (!DownloadList.get().contains(node.getID())) {
node.createDownload(serverMenu.getSelectedItem());
if (node.getDownload() == null) {
EventBus.post(new BarNotificationEvent("The download could not be started"));
BarNotifListener.EVENT.make().onBarNotif("The download could not be started");
} else {
DownloadList.get().addNode(node);
node.getDownload().start();
@@ -947,7 +950,7 @@ public class DownloadsMenu extends ComplexOpsuState {
pageDir = Page.RESET;
previewID = -1;
if (barNotificationOnLoad != null) {
EventBus.post(new BarNotificationEvent(barNotificationOnLoad));
BarNotifListener.EVENT.make().onBarNotif(barNotificationOnLoad);
barNotificationOnLoad = null;
}
}

View File

@@ -24,7 +24,6 @@ import itdelatrisu.opsu.audio.MusicController;
import itdelatrisu.opsu.audio.SoundController;
import itdelatrisu.opsu.audio.SoundEffect;
import itdelatrisu.opsu.beatmap.Beatmap;
import itdelatrisu.opsu.beatmap.BeatmapParser;
import itdelatrisu.opsu.beatmap.HitObject;
import itdelatrisu.opsu.beatmap.TimingPoint;
import itdelatrisu.opsu.db.BeatmapDB;
@@ -57,13 +56,11 @@ import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.util.Log;
import yugecin.opsudance.*;
import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.core.state.ComplexOpsuState;
import yugecin.opsudance.events.BarNotificationEvent;
import yugecin.opsudance.events.BubbleNotificationEvent;
import yugecin.opsudance.events.BarNotifListener;
import yugecin.opsudance.events.BubNotifListener;
import yugecin.opsudance.objects.curves.FakeCombinedCurve;
import yugecin.opsudance.options.OptionGroups;
import yugecin.opsudance.options.Options;
import yugecin.opsudance.sbv2.MoveStoryboard;
import yugecin.opsudance.skinning.SkinService;
import yugecin.opsudance.ui.OptionsOverlay;
@@ -337,7 +334,9 @@ public class Game extends ComplexOpsuState {
gOffscreen.setBackground(Color.black);
} catch (SlickException e) {
Log.error("could not create offscreen graphics", e);
EventBus.post(new BubbleNotificationEvent("Exception while creating offscreen graphics. See logfile for details.", BubbleNotificationEvent.COMMONCOLOR_RED));
BubNotifListener.EVENT.make().onBubNotif(
"Exception while creating offscreen graphics. See logfile for details.",
BubNotifListener.COMMONCOLOR_RED);
}
// initialize music position bar location
@@ -1172,7 +1171,7 @@ public class Game extends ComplexOpsuState {
if (0 <= time && time < 3600) {
OPTION_CHECKPOINT.setValue(time);
SoundController.playSound(SoundEffect.MENUCLICK);
EventBus.post(new BarNotificationEvent("Checkpoint saved."));
BarNotifListener.EVENT.make().onBarNotif("Checkpoint saved.");
}
}
break;
@@ -1184,7 +1183,7 @@ public class Game extends ComplexOpsuState {
break; // invalid checkpoint
loadCheckpoint(checkpoint);
SoundController.playSound(SoundEffect.MENUHIT);
EventBus.post(new BarNotificationEvent("Checkpoint loaded."));
BarNotifListener.EVENT.make().onBarNotif("Checkpoint loaded.");
}
break;
case Input.KEY_F:
@@ -1227,12 +1226,12 @@ public class Game extends ComplexOpsuState {
break;
case Input.KEY_MINUS:
currentMapMusicOffset += 5;
EventBus.post(new BarNotificationEvent("Current map offset: " + currentMapMusicOffset));
BarNotifListener.EVENT.make().onBarNotif("Current map offset: " + currentMapMusicOffset);
break;
}
if (key == Input.KEY_ADD || c == '+') {
currentMapMusicOffset -= 5;
EventBus.post(new BarNotificationEvent("Current map offset: " + currentMapMusicOffset));
BarNotifListener.EVENT.make().onBarNotif("Current map offset: " + currentMapMusicOffset);
}
return true;
@@ -1454,7 +1453,8 @@ public class Game extends ComplexOpsuState {
}
if (beatmap == null || beatmap.objects == null) {
EventBus.post(new BubbleNotificationEvent("Game was running without a beatmap", BubbleNotificationEvent.COMMONCOLOR_RED));
BubNotifListener.EVENT.make().onBubNotif("Game was running without a beatmap",
BubNotifListener.COMMONCOLOR_RED);
displayContainer.switchStateInstantly(songMenuState);
}
@@ -1561,7 +1561,8 @@ 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);
EventBus.post(new BubbleNotificationEvent(message, BubbleNotificationEvent.COMMONCOLOR_RED));
BubNotifListener.EVENT.make().onBubNotif(message,
BubNotifListener.COMMONCOLOR_RED);
gameObjects[i] = new DummyObject(hitObject);
}
}
@@ -2147,7 +2148,8 @@ public class Game extends ComplexOpsuState {
this.replay = null;
} else {
if (replay.frames == null) {
EventBus.post(new BubbleNotificationEvent("Attempting to set a replay with no frames.", BubbleNotificationEvent.COLOR_ORANGE));
BubNotifListener.EVENT.make().onBubNotif("Attempting to set a replay with no frames.",
BubNotifListener.COLOR_ORANGE);
return;
}
this.isReplay = true;

View File

@@ -36,9 +36,8 @@ import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.util.Log;
import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.core.state.BaseOpsuState;
import yugecin.opsudance.events.BarNotificationEvent;
import yugecin.opsudance.events.BarNotifListener;
import static yugecin.opsudance.core.InstanceContainer.*;
@@ -157,13 +156,14 @@ public class GameRanking extends BaseOpsuState {
gameState.setRestart((data.isGameplay()) ? Game.Restart.REPLAY : Game.Restart.NEW);
returnToGame = true;
} catch (FileNotFoundException e) {
EventBus.post(new BarNotificationEvent("Replay file not found."));
BarNotifListener.EVENT.make().onBarNotif("Replay file not found.");
} catch (IOException e) {
Log.error("Failed to load replay data.", e);
EventBus.post(new BarNotificationEvent("Failed to load replay data. See log for details."));
BarNotifListener.EVENT.make().onBarNotif(
"Failed to load replay data. See log for details.");
}
} else
EventBus.post(new BarNotificationEvent("Replay file not found."));
BarNotifListener.EVENT.make().onBarNotif("Replay file not found.");
}
// retry

View File

@@ -46,11 +46,10 @@ import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.util.Log;
import yugecin.opsudance.core.Constants;
import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.core.state.BaseOpsuState;
import yugecin.opsudance.core.state.OpsuState;
import yugecin.opsudance.events.BarNotificationEvent;
import yugecin.opsudance.events.BubbleNotificationEvent;
import yugecin.opsudance.events.BarNotifListener;
import yugecin.opsudance.events.BubNotifListener;
import static yugecin.opsudance.core.InstanceContainer.*;
import static yugecin.opsudance.options.Options.*;
@@ -466,12 +465,11 @@ public class MainMenu extends BaseOpsuState {
UI.enter();
if (!enterNotification) {
if (updater.getStatus() == Updater.Status.UPDATE_AVAILABLE) {
EventBus.post(new BarNotificationEvent("An opsu! update is available."));
enterNotification = true;
BarNotifListener.EVENT.make().onBarNotif("An opsu! update is available.");
} else if (updater.justUpdated()) {
EventBus.post(new BarNotificationEvent("opsu! is now up to date!"));
enterNotification = true;
BarNotifListener.EVENT.make().onBarNotif("opsu! is now up to date!");
}
enterNotification = true;
}
// reset measure info
@@ -532,15 +530,15 @@ public class MainMenu extends BaseOpsuState {
if (musicPlay.contains(x, y)) {
if (MusicController.isPlaying()) {
MusicController.pause();
EventBus.post(new BarNotificationEvent("Pause"));
BarNotifListener.EVENT.make().onBarNotif("Pause");
} else if (!MusicController.isTrackLoading()) {
MusicController.resume();
EventBus.post(new BarNotificationEvent("Play"));
BarNotifListener.EVENT.make().onBarNotif("Play");
}
return true;
} else if (musicNext.contains(x, y)) {
nextTrack(true);
EventBus.post(new BarNotificationEvent(">> Next"));
BarNotifListener.EVENT.make().onBarNotif(">> Next");
return true;
} else if (musicPrevious.contains(x, y)) {
lastMeasureProgress = 0f;
@@ -552,7 +550,7 @@ public class MainMenu extends BaseOpsuState {
} else {
MusicController.setPosition(0);
}
EventBus.post(new BarNotificationEvent("<< Previous"));
BarNotifListener.EVENT.make().onBarNotif("<< Previous");
return true;
}
@@ -568,10 +566,12 @@ public class MainMenu extends BaseOpsuState {
try {
Desktop.getDesktop().browse(Constants.REPOSITORY_URI);
} catch (UnsupportedOperationException e) {
EventBus.post(new BarNotificationEvent("The repository web page could not be opened."));
BarNotifListener.EVENT.make().onBarNotif(
"The repository web page could not be opened.");
} catch (IOException e) {
Log.error("could not browse to repo", e);
EventBus.post(new BubbleNotificationEvent("Could not browse to repo", BubbleNotificationEvent.COLOR_ORANGE));
BubNotifListener.EVENT.make().onBubNotif("Could not browse to repo",
BubNotifListener.COLOR_ORANGE);
}
return true;
}
@@ -580,10 +580,12 @@ public class MainMenu extends BaseOpsuState {
try {
Desktop.getDesktop().browse(Constants.DANCE_REPOSITORY_URI);
} catch (UnsupportedOperationException e) {
EventBus.post(new BarNotificationEvent("The repository web page could not be opened."));
BarNotifListener.EVENT.make().onBarNotif(
"The repository web page could not be opened.");
} catch (IOException e) {
Log.error("could not browse to repo", e);
EventBus.post(new BubbleNotificationEvent("Could not browse to repo", BubbleNotificationEvent.COLOR_ORANGE));
BubNotifListener.EVENT.make().onBubNotif("Could not browse to repo",
BubNotifListener.COLOR_ORANGE);
}
return true;
}

View File

@@ -35,7 +35,6 @@ import itdelatrisu.opsu.beatmap.BeatmapSortOrder;
import itdelatrisu.opsu.beatmap.BeatmapWatchService;
import itdelatrisu.opsu.beatmap.BeatmapWatchService.BeatmapWatchServiceListener;
import itdelatrisu.opsu.beatmap.LRUCache;
import itdelatrisu.opsu.beatmap.OszUnpacker;
import itdelatrisu.opsu.db.BeatmapDB;
import itdelatrisu.opsu.db.ScoreDB;
import itdelatrisu.opsu.states.ButtonMenu.MenuState;
@@ -63,9 +62,8 @@ import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SpriteSheet;
import org.newdawn.slick.gui.TextField;
import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.core.state.ComplexOpsuState;
import yugecin.opsudance.events.BarNotificationEvent;
import yugecin.opsudance.events.BarNotifListener;
import yugecin.opsudance.options.OptionGroups;
import yugecin.opsudance.ui.OptionsOverlay;
@@ -439,12 +437,15 @@ public class SongMenu extends ComplexOpsuState {
BeatmapWatchService.addListener(new BeatmapWatchServiceListener() {
@Override
public void eventReceived(Kind<?> kind, Path child) {
if (!songFolderChanged && kind != StandardWatchEventKinds.ENTRY_MODIFY) {
songFolderChanged = true;
if (displayContainer.isInState(SongMenu.class)) {
EventBus.post(new BarNotificationEvent("Changed is Songs folder detected. Hit F5 to refresh."));
}
if (songFolderChanged || kind == StandardWatchEventKinds.ENTRY_MODIFY) {
return;
}
songFolderChanged = true;
if (!displayContainer.isInState(SongMenu.class)) {
return;
}
BarNotifListener.EVENT.make().onBarNotif(
"Changed is Songs folder detected. Hit F5 to refresh.");
}
});
@@ -929,30 +930,32 @@ public class SongMenu extends ComplexOpsuState {
// group tabs
for (BeatmapGroup group : BeatmapGroup.values()) {
if (group.contains(x, y)) {
if (group != BeatmapGroup.current()) {
BeatmapGroup.set(group);
SoundController.playSound(SoundEffect.MENUCLICK);
startNode = focusNode = null;
oldFocusNode = null;
randomStack = new Stack<SongNode>();
songInfo = null;
scoreMap = null;
focusScores = null;
searchTextField.setText("");
searchTimer = SEARCH_DELAY;
searchTransitionTimer = SEARCH_TRANSITION_TIME;
searchResultString = null;
BeatmapSetList.get().reset();
BeatmapSetList.get().init();
setFocus(BeatmapSetList.get().getRandomNode(), -1, true, true);
if (BeatmapSetList.get().size() < 1 && group.getEmptyMessage() != null) {
EventBus.post(new BarNotificationEvent(group.getEmptyMessage()));
}
}
if (!group.contains(x, y)) {
continue;
}
if (group == BeatmapGroup.current()) {
return true;
}
BeatmapGroup.set(group);
SoundController.playSound(SoundEffect.MENUCLICK);
startNode = focusNode = null;
oldFocusNode = null;
randomStack = new Stack<SongNode>();
songInfo = null;
scoreMap = null;
focusScores = null;
searchTextField.setText("");
searchTimer = SEARCH_DELAY;
searchTransitionTimer = SEARCH_TRANSITION_TIME;
searchResultString = null;
BeatmapSetList.get().reset();
BeatmapSetList.get().init();
setFocus(BeatmapSetList.get().getRandomNode(), -1, true, true);
if (BeatmapSetList.get().size() < 1 && group.getEmptyMessage() != null) {
BarNotifListener.EVENT.make().onBarNotif(group.getEmptyMessage());
}
return true;
}
if (focusNode == null) {
@@ -1760,7 +1763,7 @@ public class SongMenu extends ComplexOpsuState {
Beatmap beatmap = MusicController.getBeatmap();
if (focusNode == null || beatmap != focusNode.getSelectedBeatmap()) {
EventBus.post(new BarNotificationEvent("Unable to load the beatmap audio."));
BarNotifListener.EVENT.make().onBarNotif("Unable to load the beatmap audio.");
return;
}