parent
3987b234bb
commit
ae57315df9
@ -1,33 +0,0 @@ |
||||
package mightypork.gamecore.core.events; |
||||
|
||||
|
||||
import mightypork.gamecore.core.App; |
||||
import mightypork.gamecore.core.MainLoop; |
||||
import mightypork.utils.eventbus.BusEvent; |
||||
import mightypork.utils.eventbus.events.flags.NonConsumableEvent; |
||||
import mightypork.utils.eventbus.events.flags.SingleReceiverEvent; |
||||
|
||||
|
||||
/** |
||||
* Shutdown request, non-interactive. Shutdown needs to execute on GL thread for |
||||
* display to deinit properly. |
||||
* |
||||
* @author Ondřej Hruška (MightyPork) |
||||
*/ |
||||
@SingleReceiverEvent |
||||
@NonConsumableEvent |
||||
public class ShudownRequest extends BusEvent<MainLoop> { |
||||
|
||||
@Override |
||||
public void handleBy(final MainLoop handler) |
||||
{ |
||||
handler.queueTask(new Runnable() { |
||||
|
||||
@Override |
||||
public void run() |
||||
{ |
||||
App.shutdown(); |
||||
} |
||||
}, true); |
||||
} |
||||
} |
@ -0,0 +1,47 @@ |
||||
package mightypork.gamecore.core.events; |
||||
|
||||
|
||||
import mightypork.utils.eventbus.BusEvent; |
||||
import mightypork.utils.eventbus.EventBus; |
||||
import mightypork.utils.logging.Log; |
||||
|
||||
|
||||
/** |
||||
* Shutdown event.<br> |
||||
* This event is dispatched when the <code>App.shutdown()</code> method is |
||||
* called. If no client consumes it, the shutdown will immediately follow.<br> |
||||
* This is a way to allow clients to abort the shutdown (ie. ask user to save |
||||
* game). After the game is saved, the <code>App.shutdown()</code> method can be |
||||
* called again. |
||||
* |
||||
* @author Ondřej Hruška (MightyPork) |
||||
*/ |
||||
public class ShutdownEvent extends BusEvent<ShutdownListener> { |
||||
|
||||
private Runnable shutdownTask; |
||||
|
||||
|
||||
public ShutdownEvent(Runnable doShutdown) { |
||||
this.shutdownTask = doShutdown; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected void handleBy(ShutdownListener handler) |
||||
{ |
||||
handler.onShutdown(this); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void onDispatchComplete(EventBus bus) |
||||
{ |
||||
if (!isConsumed()) { |
||||
Log.i("Shutting down..."); |
||||
shutdownTask.run(); |
||||
} else { |
||||
Log.i("Shutdown aborted."); |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,32 +0,0 @@ |
||||
package mightypork.gamecore.core.events; |
||||
|
||||
|
||||
import mightypork.utils.eventbus.BusEvent; |
||||
import mightypork.utils.eventbus.EventBus; |
||||
|
||||
|
||||
/** |
||||
* User quit request. This event is triggered when user clicks the "close" |
||||
* titlebar button, and if no client consumes it, the application will be shut |
||||
* down. |
||||
* |
||||
* @author Ondřej Hruška (MightyPork) |
||||
*/ |
||||
public class UserQuitRequest extends BusEvent<UserQuitRequestListener> { |
||||
|
||||
@Override |
||||
protected void handleBy(UserQuitRequestListener handler) |
||||
{ |
||||
handler.onQuitRequest(this); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void onDispatchComplete(EventBus bus) |
||||
{ |
||||
if (!isConsumed()) { |
||||
bus.send(new ShudownRequest()); |
||||
} |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue