use the new errorhandler & bubble notifs

This commit is contained in:
yugecin
2017-01-21 01:16:27 +01:00
parent aceebb95ca
commit f730935622
35 changed files with 199 additions and 147 deletions

View File

@@ -23,7 +23,6 @@ import itdelatrisu.opsu.beatmap.BeatmapWatchService;
import itdelatrisu.opsu.db.DBController;
import itdelatrisu.opsu.downloads.DownloadList;
import itdelatrisu.opsu.downloads.Updater;
import itdelatrisu.opsu.render.CurveRenderState;
import itdelatrisu.opsu.states.Splash;
import org.newdawn.slick.util.Log;
import yugecin.opsudance.core.DisplayContainer;
@@ -78,7 +77,6 @@ public class OpsuDance {
DBController.closeConnections();
DownloadList.get().cancelAllDownloads();
Utils.deleteDirectory(Options.TEMP_DIR);
CurveRenderState.shutdown();
if (!Options.isWatchServiceEnabled()) {
BeatmapWatchService.destroy();
}
@@ -89,7 +87,7 @@ public class OpsuDance {
container.setup();
container.resume();
} catch (Exception e) {
ErrorHandler.error("could not initialize GL", e).preventContinue().show();
ErrorHandler.error("could not initialize GL", e).allowTerminate().preventContinue().show();
return false;
}
Exception caughtException = null;
@@ -100,7 +98,7 @@ public class OpsuDance {
}
container.teardown();
container.pause();
return caughtException != null && ErrorHandler.error("update/render error", caughtException).show().shouldIgnoreAndContinue();
return caughtException != null && ErrorHandler.error("update/render error", caughtException).allowTerminate().show().shouldIgnoreAndContinue();
}
private void initDatabase() {
@@ -174,7 +172,7 @@ public class OpsuDance {
}
private void errorAndExit(String errstr) {
ErrorHandler.error(errstr, new Throwable()).preventContinue().show();
ErrorHandler.error(errstr, new Throwable()).allowTerminate().preventContinue().show();
System.exit(1);
}

View File

@@ -24,6 +24,7 @@ import itdelatrisu.opsu.audio.MusicController;
import itdelatrisu.opsu.beatmap.Beatmap;
import itdelatrisu.opsu.downloads.DownloadList;
import itdelatrisu.opsu.downloads.Updater;
import itdelatrisu.opsu.render.CurveRenderState;
import itdelatrisu.opsu.ui.Fonts;
import org.lwjgl.Sys;
import org.lwjgl.openal.AL;
@@ -222,6 +223,7 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
GameImage.destroyImages();
GameData.Grade.destroyImages();
Beatmap.destroyBackgroundImageCache();
CurveRenderState.shutdown();
Display.destroy();
}

View File

@@ -52,6 +52,7 @@ public class ErrorHandler {
private boolean preventContinue;
private boolean preventReport;
private boolean ignoreAndContinue;
private boolean allowTerminate;
public ErrorHandler(DisplayContainer displayContainer) {
this.displayContainer = displayContainer;
@@ -95,6 +96,11 @@ public class ErrorHandler {
return this;
}
public ErrorHandler allowTerminate() {
allowTerminate = true;
return this;
}
public ErrorHandler preventContinue() {
preventContinue = true;
return this;
@@ -127,7 +133,9 @@ public class ErrorHandler {
Object[] messageComponents = new Object[] { message, new JScrollPane(textArea), createViewLogButton(), createReportButton() };
String[] buttons;
if (preventContinue) {
if (!allowTerminate && !preventContinue) {
buttons = new String[] { "Ignore & continue" };
} else if (preventContinue) {
buttons = new String[] { "Terminate" };
} else {
buttons = new String[] { "Terminate", "Ignore & continue" };
@@ -145,7 +153,7 @@ public class ErrorHandler {
null,
buttons,
buttons[buttons.length - 1]);
ignoreAndContinue = result == 1;
ignoreAndContinue = !allowTerminate || result == 1;
frame.dispose();
return this;

View File

@@ -22,10 +22,14 @@ 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;
}
public <T> void subscribe(Class<T> eventType, EventListener<T> eventListener) {