2017-01-09 22:42:59 +01:00
|
|
|
/*
|
|
|
|
* opsu!dance - fork of opsu! with cursordance auto
|
|
|
|
* Copyright (C) 2017 yugecin
|
|
|
|
*
|
|
|
|
* opsu!dance is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* opsu!dance is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with opsu!dance. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package yugecin.opsudance.core;
|
|
|
|
|
2017-01-18 19:40:31 +01:00
|
|
|
import itdelatrisu.opsu.GameData;
|
2017-01-15 23:36:21 +01:00
|
|
|
import itdelatrisu.opsu.GameImage;
|
2017-01-17 23:18:12 +01:00
|
|
|
import itdelatrisu.opsu.Options;
|
2017-02-02 01:34:37 +01:00
|
|
|
import itdelatrisu.opsu.Utils;
|
2017-01-18 19:22:14 +01:00
|
|
|
import itdelatrisu.opsu.audio.MusicController;
|
2017-01-18 19:40:31 +01:00
|
|
|
import itdelatrisu.opsu.beatmap.Beatmap;
|
2017-01-20 00:15:50 +01:00
|
|
|
import itdelatrisu.opsu.downloads.DownloadList;
|
|
|
|
import itdelatrisu.opsu.downloads.Updater;
|
2017-01-21 01:16:27 +01:00
|
|
|
import itdelatrisu.opsu.render.CurveRenderState;
|
2017-01-21 13:11:34 +01:00
|
|
|
import itdelatrisu.opsu.ui.Cursor;
|
2017-01-15 23:36:21 +01:00
|
|
|
import itdelatrisu.opsu.ui.Fonts;
|
2017-01-21 13:11:34 +01:00
|
|
|
import itdelatrisu.opsu.ui.UI;
|
2017-01-09 22:42:59 +01:00
|
|
|
import org.lwjgl.Sys;
|
|
|
|
import org.lwjgl.openal.AL;
|
|
|
|
import org.lwjgl.opengl.Display;
|
|
|
|
import org.lwjgl.opengl.DisplayMode;
|
2017-01-11 20:41:13 +01:00
|
|
|
import org.lwjgl.opengl.GL11;
|
2017-01-18 17:39:46 +01:00
|
|
|
import org.newdawn.slick.*;
|
2017-01-09 22:42:59 +01:00
|
|
|
import org.newdawn.slick.opengl.InternalTextureLoader;
|
|
|
|
import org.newdawn.slick.opengl.renderer.Renderer;
|
|
|
|
import org.newdawn.slick.opengl.renderer.SGL;
|
|
|
|
import org.newdawn.slick.util.Log;
|
2017-01-15 22:46:09 +01:00
|
|
|
import yugecin.opsudance.core.events.EventBus;
|
2017-01-16 21:53:48 +01:00
|
|
|
import yugecin.opsudance.core.errorhandling.ErrorDumpable;
|
2017-01-21 14:31:03 +01:00
|
|
|
import yugecin.opsudance.core.events.EventListener;
|
2017-01-16 22:36:50 +01:00
|
|
|
import yugecin.opsudance.core.inject.InstanceContainer;
|
|
|
|
import yugecin.opsudance.core.state.OpsuState;
|
2017-01-17 11:25:36 +01:00
|
|
|
import yugecin.opsudance.core.state.specialstates.BarNotificationState;
|
2017-01-17 16:11:59 +01:00
|
|
|
import yugecin.opsudance.core.state.specialstates.BubbleNotificationState;
|
2017-01-16 22:36:50 +01:00
|
|
|
import yugecin.opsudance.core.state.specialstates.FpsRenderState;
|
|
|
|
import yugecin.opsudance.core.state.transitions.*;
|
2017-01-18 11:59:30 +01:00
|
|
|
import yugecin.opsudance.events.BubbleNotificationEvent;
|
2017-01-21 15:30:07 +01:00
|
|
|
import yugecin.opsudance.events.ResolutionOrSkinChangedEvent;
|
2017-01-09 22:42:59 +01:00
|
|
|
import yugecin.opsudance.utils.GLHelper;
|
|
|
|
|
2017-01-11 20:41:13 +01:00
|
|
|
import java.io.StringWriter;
|
2017-01-09 22:42:59 +01:00
|
|
|
|
2017-01-16 21:53:48 +01:00
|
|
|
import static yugecin.opsudance.core.Entrypoint.sout;
|
2017-01-09 23:10:51 +01:00
|
|
|
|
2017-01-09 22:42:59 +01:00
|
|
|
/**
|
|
|
|
* based on org.newdawn.slick.AppGameContainer
|
|
|
|
*/
|
2017-01-16 22:36:50 +01:00
|
|
|
public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListener {
|
2017-01-09 22:42:59 +01:00
|
|
|
|
2017-01-21 14:23:34 +01:00
|
|
|
@Deprecated
|
|
|
|
public static DisplayContainer instance; // TODO d remove this
|
|
|
|
|
2017-01-09 22:42:59 +01:00
|
|
|
private static SGL GL = Renderer.get();
|
|
|
|
|
2017-01-15 22:46:09 +01:00
|
|
|
public final EventBus eventBus;
|
2017-01-16 22:36:50 +01:00
|
|
|
private final InstanceContainer instanceContainer;
|
|
|
|
|
|
|
|
private FpsRenderState fpsState;
|
2017-01-17 11:25:36 +01:00
|
|
|
private BarNotificationState barNotifState;
|
2017-01-17 16:11:59 +01:00
|
|
|
private BubbleNotificationState bubNotifState;
|
2017-01-16 22:36:50 +01:00
|
|
|
|
|
|
|
private TransitionState outTransitionState;
|
|
|
|
private TransitionState inTransitionState;
|
|
|
|
|
|
|
|
private final TransitionFinishedListener outTransitionListener;
|
|
|
|
private final TransitionFinishedListener inTransitionListener;
|
|
|
|
|
|
|
|
private OpsuState state;
|
2017-01-15 22:46:09 +01:00
|
|
|
|
2017-01-17 23:18:12 +01:00
|
|
|
public final DisplayMode nativeDisplayMode;
|
2017-01-09 22:42:59 +01:00
|
|
|
|
|
|
|
private Graphics graphics;
|
2017-01-18 17:31:29 +01:00
|
|
|
public Input input;
|
2017-01-09 22:42:59 +01:00
|
|
|
|
|
|
|
public int width;
|
|
|
|
public int height;
|
|
|
|
|
2017-01-17 16:11:59 +01:00
|
|
|
public int mouseX;
|
|
|
|
public int mouseY;
|
|
|
|
|
2017-01-17 21:06:59 +01:00
|
|
|
private int targetUpdatesPerSecond;
|
|
|
|
public int targetUpdateInterval;
|
|
|
|
private int targetRendersPerSecond;
|
2017-01-10 13:02:40 +01:00
|
|
|
public int targetRenderInterval;
|
|
|
|
public int targetBackgroundRenderInterval;
|
|
|
|
|
2017-01-17 18:45:17 +01:00
|
|
|
public int renderDelta;
|
2017-01-10 13:02:40 +01:00
|
|
|
public int delta;
|
|
|
|
|
2017-01-18 16:55:30 +01:00
|
|
|
public boolean exitRequested;
|
|
|
|
|
2017-01-10 13:02:40 +01:00
|
|
|
public int timeSinceLastRender;
|
|
|
|
|
2017-01-09 22:42:59 +01:00
|
|
|
private long lastFrame;
|
|
|
|
|
2017-01-18 19:22:14 +01:00
|
|
|
private boolean wasMusicPlaying;
|
|
|
|
|
2017-01-11 20:41:13 +01:00
|
|
|
private String glVersion;
|
|
|
|
private String glVendor;
|
|
|
|
|
2017-01-20 00:15:50 +01:00
|
|
|
private long exitconfirmation;
|
|
|
|
|
2017-01-21 13:11:34 +01:00
|
|
|
public final Cursor cursor;
|
|
|
|
public boolean drawCursor;
|
|
|
|
|
2017-01-16 22:36:50 +01:00
|
|
|
public DisplayContainer(InstanceContainer instanceContainer, EventBus eventBus) {
|
|
|
|
this.instanceContainer = instanceContainer;
|
2017-01-15 22:46:09 +01:00
|
|
|
this.eventBus = eventBus;
|
2017-01-21 13:11:34 +01:00
|
|
|
this.cursor = new Cursor();
|
|
|
|
drawCursor = true;
|
2017-01-21 14:23:34 +01:00
|
|
|
instance = this;
|
2017-01-16 22:36:50 +01:00
|
|
|
|
|
|
|
outTransitionListener = new TransitionFinishedListener() {
|
|
|
|
@Override
|
|
|
|
public void onFinish() {
|
|
|
|
state.leave();
|
|
|
|
outTransitionState.getApplicableState().leave();
|
|
|
|
state = inTransitionState;
|
|
|
|
state.enter();
|
|
|
|
inTransitionState.getApplicableState().enter();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
inTransitionListener = new TransitionFinishedListener() {
|
|
|
|
@Override
|
|
|
|
public void onFinish() {
|
|
|
|
state.leave();
|
|
|
|
state = inTransitionState.getApplicableState();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-01-21 15:30:07 +01:00
|
|
|
eventBus.subscribe(ResolutionOrSkinChangedEvent.class, new EventListener<ResolutionOrSkinChangedEvent>() {
|
2017-01-21 14:31:03 +01:00
|
|
|
@Override
|
2017-01-21 15:30:07 +01:00
|
|
|
public void onEvent(ResolutionOrSkinChangedEvent event) {
|
2017-01-21 14:31:03 +01:00
|
|
|
destroyImages();
|
2017-02-02 01:34:37 +01:00
|
|
|
Utils.init(DisplayContainer.this); // TODO this shouldn't be here
|
2017-02-02 01:13:25 +01:00
|
|
|
UI.revalidate(); // TODO this shouldn't be here
|
2017-01-21 14:31:03 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-01-09 22:42:59 +01:00
|
|
|
this.nativeDisplayMode = Display.getDisplayMode();
|
2017-01-17 21:06:59 +01:00
|
|
|
setUPS(1000);
|
|
|
|
setFPS(60);
|
2017-01-10 13:02:40 +01:00
|
|
|
targetBackgroundRenderInterval = 41; // ~24 fps
|
2017-01-09 22:42:59 +01:00
|
|
|
lastFrame = getTime();
|
2017-01-15 23:38:20 +01:00
|
|
|
delta = 1;
|
2017-01-17 18:45:17 +01:00
|
|
|
renderDelta = 1;
|
2017-01-09 22:42:59 +01:00
|
|
|
}
|
|
|
|
|
2017-01-17 21:06:59 +01:00
|
|
|
public void setUPS(int ups) {
|
|
|
|
targetUpdatesPerSecond = ups;
|
|
|
|
targetUpdateInterval = 1000 / targetUpdatesPerSecond;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setFPS(int fps) {
|
|
|
|
targetRendersPerSecond = fps;
|
|
|
|
targetRenderInterval = 1000 / targetRendersPerSecond;
|
|
|
|
}
|
|
|
|
|
2017-01-16 22:36:50 +01:00
|
|
|
public void init(Class<? extends OpsuState> startingState) {
|
|
|
|
state = instanceContainer.provide(startingState);
|
|
|
|
state.enter();
|
|
|
|
|
|
|
|
fpsState = instanceContainer.provide(FpsRenderState.class);
|
2017-01-17 16:11:59 +01:00
|
|
|
bubNotifState = instanceContainer.provide(BubbleNotificationState.class);
|
2017-01-17 17:13:25 +01:00
|
|
|
barNotifState = instanceContainer.provide(BarNotificationState.class);
|
2017-01-16 22:36:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-18 19:22:14 +01:00
|
|
|
public void run() throws Exception {
|
2017-01-20 00:15:50 +01:00
|
|
|
while(!exitRequested && !(Display.isCloseRequested() && state.onCloseRequest()) || !confirmExit()) {
|
2017-01-10 13:02:40 +01:00
|
|
|
delta = getDelta();
|
|
|
|
|
|
|
|
timeSinceLastRender += delta;
|
|
|
|
|
2017-01-10 12:43:05 +01:00
|
|
|
input.poll(width, height);
|
2017-01-18 17:39:46 +01:00
|
|
|
Music.poll(delta);
|
2017-01-17 16:11:59 +01:00
|
|
|
mouseX = input.getMouseX();
|
|
|
|
mouseY = input.getMouseY();
|
2017-01-21 13:11:34 +01:00
|
|
|
|
2017-01-17 18:45:17 +01:00
|
|
|
state.update();
|
2017-01-21 13:11:34 +01:00
|
|
|
if (drawCursor) {
|
|
|
|
cursor.setCursorPosition(delta, mouseX, mouseY);
|
|
|
|
}
|
2017-01-10 13:02:40 +01:00
|
|
|
|
|
|
|
int maxRenderInterval;
|
|
|
|
if (Display.isVisible() && Display.isActive()) {
|
|
|
|
maxRenderInterval = targetRenderInterval;
|
|
|
|
} else {
|
|
|
|
maxRenderInterval = targetBackgroundRenderInterval;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (timeSinceLastRender >= maxRenderInterval) {
|
|
|
|
GL.glClear(SGL.GL_COLOR_BUFFER_BIT);
|
|
|
|
|
|
|
|
/*
|
|
|
|
graphics.resetTransform();
|
|
|
|
graphics.resetFont();
|
|
|
|
graphics.resetLineWidth();
|
|
|
|
graphics.resetTransform();
|
|
|
|
*/
|
|
|
|
|
2017-01-17 18:45:17 +01:00
|
|
|
renderDelta = timeSinceLastRender;
|
|
|
|
|
|
|
|
state.preRenderUpdate();
|
2017-01-16 22:36:50 +01:00
|
|
|
state.render(graphics);
|
|
|
|
fpsState.render(graphics);
|
2017-01-17 18:45:17 +01:00
|
|
|
bubNotifState.render(graphics);
|
|
|
|
barNotifState.render(graphics);
|
2017-01-10 13:02:40 +01:00
|
|
|
|
2017-01-21 13:11:34 +01:00
|
|
|
cursor.updateAngle(renderDelta);
|
|
|
|
if (drawCursor) {
|
|
|
|
cursor.draw(input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) || input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON));
|
|
|
|
}
|
|
|
|
UI.drawTooltip(graphics);
|
|
|
|
|
2017-01-10 13:02:40 +01:00
|
|
|
timeSinceLastRender = 0;
|
|
|
|
|
|
|
|
Display.update(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
Display.processMessages();
|
2017-01-17 21:06:59 +01:00
|
|
|
Display.sync(targetUpdatesPerSecond);
|
2017-01-09 22:42:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-15 23:36:21 +01:00
|
|
|
public void setup() throws Exception {
|
2017-01-11 20:41:13 +01:00
|
|
|
width = height = -1;
|
2017-01-10 13:16:57 +01:00
|
|
|
Input.disableControllers();
|
2017-01-09 22:42:59 +01:00
|
|
|
Display.setTitle("opsu!dance");
|
2017-01-18 10:27:40 +01:00
|
|
|
Options.setDisplayMode(this);
|
2017-01-11 20:41:13 +01:00
|
|
|
Display.create();
|
|
|
|
GLHelper.setIcons(new String[] { "icon16.png", "icon32.png" });
|
2017-01-18 10:27:40 +01:00
|
|
|
initGL();
|
2017-01-11 20:41:13 +01:00
|
|
|
glVersion = GL11.glGetString(GL11.GL_VERSION);
|
|
|
|
glVendor = GL11.glGetString(GL11.GL_VENDOR);
|
2017-01-21 13:11:34 +01:00
|
|
|
GLHelper.hideNativeCursor();
|
2017-01-09 22:42:59 +01:00
|
|
|
}
|
|
|
|
|
2017-01-11 20:41:13 +01:00
|
|
|
public void teardown() {
|
2017-01-21 14:31:03 +01:00
|
|
|
destroyImages();
|
|
|
|
CurveRenderState.shutdown();
|
|
|
|
Display.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void destroyImages() {
|
2017-01-18 19:33:58 +01:00
|
|
|
InternalTextureLoader.get().clear();
|
2017-01-18 19:40:31 +01:00
|
|
|
GameImage.destroyImages();
|
|
|
|
GameData.Grade.destroyImages();
|
|
|
|
Beatmap.destroyBackgroundImageCache();
|
2017-01-18 19:22:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void teardownAL() {
|
2017-01-09 22:42:59 +01:00
|
|
|
AL.destroy();
|
|
|
|
}
|
|
|
|
|
2017-01-18 19:22:14 +01:00
|
|
|
public void pause() {
|
|
|
|
wasMusicPlaying = MusicController.isPlaying();
|
|
|
|
if (wasMusicPlaying) {
|
|
|
|
MusicController.pause();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void resume() {
|
|
|
|
if (wasMusicPlaying) {
|
|
|
|
MusicController.resume();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-20 00:15:50 +01:00
|
|
|
private boolean confirmExit() {
|
|
|
|
if (System.currentTimeMillis() - exitconfirmation < 10000) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (DownloadList.get().hasActiveDownloads()) {
|
|
|
|
eventBus.post(new BubbleNotificationEvent(DownloadList.EXIT_CONFIRMATION, BubbleNotificationEvent.COMMONCOLOR_PURPLE));
|
|
|
|
exitRequested = false;
|
2017-01-20 00:25:32 +01:00
|
|
|
exitconfirmation = System.currentTimeMillis();
|
2017-01-20 00:15:50 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (Updater.get().getStatus() == Updater.Status.UPDATE_DOWNLOADING) {
|
|
|
|
eventBus.post(new BubbleNotificationEvent(Updater.EXIT_CONFIRMATION, BubbleNotificationEvent.COMMONCOLOR_PURPLE));
|
|
|
|
exitRequested = false;
|
2017-01-20 00:25:32 +01:00
|
|
|
exitconfirmation = System.currentTimeMillis();
|
2017-01-20 00:15:50 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-15 23:36:21 +01:00
|
|
|
public void setDisplayMode(int width, int height, boolean fullscreen) throws Exception {
|
2017-01-09 22:42:59 +01:00
|
|
|
if (this.width == width && this.height == height) {
|
|
|
|
Display.setFullscreen(fullscreen);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DisplayMode displayMode = null;
|
|
|
|
if (fullscreen) {
|
|
|
|
displayMode = GLHelper.findFullscreenDisplayMode(nativeDisplayMode.getBitsPerPixel(), nativeDisplayMode.getFrequency(), width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (displayMode == null) {
|
2017-01-17 22:02:40 +01:00
|
|
|
displayMode = new DisplayMode(width, height);
|
2017-01-09 22:42:59 +01:00
|
|
|
if (fullscreen) {
|
|
|
|
fullscreen = false;
|
|
|
|
Log.warn("could not find fullscreen displaymode for " + width + "x" + height);
|
2017-01-18 11:59:30 +01:00
|
|
|
eventBus.post(new BubbleNotificationEvent("Fullscreen mode is not supported for " + width + "x" + height, BubbleNotificationEvent.COLOR_ORANGE));
|
2017-01-09 22:42:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.width = displayMode.getWidth();
|
|
|
|
this.height = displayMode.getHeight();
|
|
|
|
|
|
|
|
Display.setDisplayMode(displayMode);
|
|
|
|
Display.setFullscreen(fullscreen);
|
|
|
|
|
2017-01-18 10:27:40 +01:00
|
|
|
if (Display.isCreated()) {
|
|
|
|
initGL();
|
|
|
|
}
|
2017-01-09 22:42:59 +01:00
|
|
|
|
|
|
|
if (displayMode.getBitsPerPixel() == 16) {
|
|
|
|
InternalTextureLoader.get().set16BitMode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-15 23:36:21 +01:00
|
|
|
private void initGL() throws Exception {
|
2017-01-09 22:42:59 +01:00
|
|
|
GL.initDisplay(width, height);
|
|
|
|
GL.enterOrtho(width, height);
|
|
|
|
|
|
|
|
graphics = new Graphics(width, height);
|
|
|
|
graphics.setAntiAlias(false);
|
|
|
|
|
2017-01-10 12:43:05 +01:00
|
|
|
input = new Input(height);
|
2017-01-17 23:18:12 +01:00
|
|
|
input.enableKeyRepeat();
|
2017-01-16 22:36:50 +01:00
|
|
|
input.addKeyListener(this);
|
|
|
|
input.addMouseListener(this);
|
2017-01-15 23:36:21 +01:00
|
|
|
|
2017-01-18 11:59:30 +01:00
|
|
|
sout("GL ready");
|
|
|
|
|
2017-01-15 23:36:21 +01:00
|
|
|
GameImage.init(width, height);
|
|
|
|
Fonts.init();
|
2017-01-18 11:59:30 +01:00
|
|
|
|
2017-01-21 15:30:07 +01:00
|
|
|
eventBus.post(new ResolutionOrSkinChangedEvent());
|
2017-01-09 22:42:59 +01:00
|
|
|
}
|
|
|
|
|
2017-01-21 13:11:34 +01:00
|
|
|
public void resetCursor() {
|
|
|
|
cursor.reset(mouseX, mouseY);
|
|
|
|
}
|
|
|
|
|
2017-01-09 22:42:59 +01:00
|
|
|
private int getDelta() {
|
|
|
|
long time = getTime();
|
|
|
|
int delta = (int) (time - lastFrame);
|
|
|
|
lastFrame = time;
|
|
|
|
return delta;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getTime() {
|
|
|
|
return (Sys.getTime() * 1000) / Sys.getTimerResolution();
|
|
|
|
}
|
|
|
|
|
2017-01-11 20:41:13 +01:00
|
|
|
@Override
|
|
|
|
public void writeErrorDump(StringWriter dump) {
|
2017-01-15 00:11:52 +01:00
|
|
|
dump.append("> DisplayContainer dump\n");
|
|
|
|
dump.append("OpenGL version: ").append(glVersion).append( "(").append(glVendor).append(")\n");
|
2017-01-16 22:36:50 +01:00
|
|
|
if (isTransitioning()) {
|
|
|
|
dump.append("doing a transition\n");
|
|
|
|
dump.append("using out transition ").append(outTransitionState.getClass().getSimpleName()).append('\n');
|
|
|
|
dump.append("using in transition ").append(inTransitionState.getClass().getSimpleName()).append('\n');
|
|
|
|
if (state == inTransitionState) {
|
|
|
|
dump.append("currently doing the in transition\n");
|
|
|
|
} else {
|
|
|
|
dump.append("currently doing the out transition\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
state.writeErrorDump(dump);
|
|
|
|
}
|
|
|
|
|
2017-01-18 17:31:29 +01:00
|
|
|
public boolean isInState(Class<? extends OpsuState> state) {
|
|
|
|
return state.isInstance(state);
|
|
|
|
}
|
|
|
|
|
2017-01-16 22:36:50 +01:00
|
|
|
public boolean isTransitioning() {
|
|
|
|
return state instanceof TransitionState;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void switchState(Class<? extends OpsuState> newState) {
|
|
|
|
switchState(newState, FadeOutTransitionState.class, 200, FadeInTransitionState.class, 300);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void switchStateNow(Class<? extends OpsuState> newState) {
|
2017-01-19 19:23:31 +01:00
|
|
|
switchState(newState, EmptyTransitionState.class, 0, FadeInTransitionState.class, 300);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void switchStateInstantly(Class<? extends OpsuState> newState) {
|
|
|
|
state.leave();
|
|
|
|
state = instanceContainer.provide(newState);
|
|
|
|
state.enter();
|
2017-01-11 20:41:13 +01:00
|
|
|
}
|
|
|
|
|
2017-01-16 22:36:50 +01:00
|
|
|
public void switchState(Class<? extends OpsuState> newState, Class<? extends TransitionState> outTransition, int outTime, Class<? extends TransitionState> inTransition, int inTime) {
|
|
|
|
if (isTransitioning()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
outTransitionState = instanceContainer.provide(outTransition).set(state, outTime, outTransitionListener);
|
|
|
|
inTransitionState = instanceContainer.provide(inTransition).set(instanceContainer.provide(newState), inTime, inTransitionListener);
|
|
|
|
state = outTransitionState;
|
|
|
|
state.enter();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* input events below, see org.newdawn.slick.KeyListener & org.newdawn.slick.MouseListener
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void keyPressed(int key, char c) {
|
|
|
|
state.keyPressed(key, c);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void keyReleased(int key, char c) {
|
|
|
|
state.keyReleased(key, c);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void mouseWheelMoved(int change) {
|
|
|
|
state.mouseWheelMoved(change);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void mouseClicked(int button, int x, int y, int clickCount) { }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void mousePressed(int button, int x, int y) {
|
|
|
|
state.mousePressed(button, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void mouseReleased(int button, int x, int y) {
|
2017-01-17 16:11:59 +01:00
|
|
|
if (bubNotifState.mouseReleased(x, y)) {
|
|
|
|
return;
|
|
|
|
}
|
2017-01-16 22:36:50 +01:00
|
|
|
state.mouseReleased(button, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void mouseMoved(int oldx, int oldy, int newx, int newy) { }
|
|
|
|
|
|
|
|
@Override
|
2017-01-18 21:48:27 +01:00
|
|
|
public void mouseDragged(int oldx, int oldy, int newx, int newy) {
|
|
|
|
state.mouseDragged(oldx, oldy, newx, newy);
|
|
|
|
}
|
2017-01-16 22:36:50 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setInput(Input input) { }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isAcceptingInput() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void inputEnded() { }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void inputStarted() { }
|
|
|
|
|
2017-01-09 22:42:59 +01:00
|
|
|
}
|