working splash state

This commit is contained in:
yugecin 2017-01-17 23:18:12 +01:00
parent 5e09a1d24a
commit 8b226f3afc
11 changed files with 114 additions and 133 deletions

View File

@ -85,7 +85,7 @@ public class Opsu extends StateBasedGame {
@Override @Override
public void initStatesList(GameContainer container) throws SlickException { public void initStatesList(GameContainer container) throws SlickException {
addState(new Splash(STATE_SPLASH)); //addState(new Splash(STATE_SPLASH));
addState(new MainMenu(STATE_MAINMENU)); addState(new MainMenu(STATE_MAINMENU));
addState(new ButtonMenu(STATE_BUTTONMENU)); addState(new ButtonMenu(STATE_BUTTONMENU));
addState(new SongMenu(STATE_SONGMENU)); addState(new SongMenu(STATE_SONGMENU));
@ -206,7 +206,7 @@ public class Opsu extends StateBasedGame {
Container app = new Container(opsu); Container app = new Container(opsu);
// basic game settings // basic game settings
Options.setDisplayMode(app); //Options.setDisplayMode(app);
String[] icons = { "icon16.png", "icon32.png" }; String[] icons = { "icon16.png", "icon32.png" };
try { try {
app.setIcons(icons); app.setIcons(icons);

View File

@ -59,6 +59,8 @@ import com.sun.jna.platform.win32.Advapi32Util;
import com.sun.jna.platform.win32.Win32Exception; import com.sun.jna.platform.win32.Win32Exception;
import com.sun.jna.platform.win32.WinReg; import com.sun.jna.platform.win32.WinReg;
import yugecin.opsudance.*; import yugecin.opsudance.*;
import yugecin.opsudance.core.DisplayContainer;
import yugecin.opsudance.events.BubbleNotificationEvent;
import yugecin.opsudance.movers.factories.ExgonMoverFactory; import yugecin.opsudance.movers.factories.ExgonMoverFactory;
import yugecin.opsudance.movers.factories.QuadraticBezierMoverFactory; import yugecin.opsudance.movers.factories.QuadraticBezierMoverFactory;
import yugecin.opsudance.movers.slidermovers.DefaultSliderMoverController; import yugecin.opsudance.movers.slidermovers.DefaultSliderMoverController;
@ -1294,10 +1296,9 @@ public class Options {
/** /**
* Sets the master volume level (if within valid range). * Sets the master volume level (if within valid range).
* @param container the game container
* @param volume the volume [0, 1] * @param volume the volume [0, 1]
*/ */
public static void setMasterVolume(GameContainer container, float volume) { public static void setMasterVolume(float volume) {
if (volume >= 0f && volume <= 1f) { if (volume >= 0f && volume <= 1f) {
GameOption.MASTER_VOLUME.setValue((int) (volume * 100f)); GameOption.MASTER_VOLUME.setValue((int) (volume * 100f));
MusicController.setVolume(getMasterVolume() * getMusicVolume()); MusicController.setVolume(getMasterVolume() * getMusicVolume());
@ -1346,11 +1347,10 @@ public class Options {
* <p> * <p>
* If the configured resolution is larger than the screen size, the smallest * If the configured resolution is larger than the screen size, the smallest
* available resolution will be used. * available resolution will be used.
* @param app the game container
*/ */
public static void setDisplayMode(Container app) { public static void setDisplayMode(DisplayContainer container) {
int screenWidth = app.getScreenWidth(); int screenWidth = container.nativeDisplayMode.getWidth();
int screenHeight = app.getScreenHeight(); int screenHeight = container.nativeDisplayMode.getHeight();
resolutions[0] = screenWidth + "x" + screenHeight; resolutions[0] = screenWidth + "x" + screenHeight;
if (resolutionIdx < 0 || resolutionIdx > resolutions.length) { if (resolutionIdx < 0 || resolutionIdx > resolutions.length) {
@ -1370,9 +1370,10 @@ public class Options {
} }
try { try {
app.setDisplayMode(width, height, isFullscreen()); container.setDisplayMode(width, height, isFullscreen());
} catch (SlickException e) { } catch (Exception e) {
ErrorHandler.error("Failed to set display mode.", e, true); container.eventBus.post(new BubbleNotificationEvent("Failed to change resolution", BubbleNotificationEvent.COMMONCOLOR_RED));
Log.error("Failed to set display mode.", e);
} }
if (!isFullscreen()) { if (!isFullscreen()) {

View File

@ -18,6 +18,7 @@
package itdelatrisu.opsu; package itdelatrisu.opsu;
import itdelatrisu.opsu.audio.MusicController;
import itdelatrisu.opsu.audio.SoundController; import itdelatrisu.opsu.audio.SoundController;
import itdelatrisu.opsu.audio.SoundEffect; import itdelatrisu.opsu.audio.SoundEffect;
import itdelatrisu.opsu.beatmap.HitObject; import itdelatrisu.opsu.beatmap.HitObject;
@ -71,6 +72,7 @@ import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.util.Log; import org.newdawn.slick.util.Log;
import com.sun.jna.platform.FileUtils; import com.sun.jna.platform.FileUtils;
import yugecin.opsudance.core.DisplayContainer;
/** /**
* Contains miscellaneous utilities. * Contains miscellaneous utilities.
@ -89,40 +91,18 @@ public class Utils {
Arrays.sort(illegalChars); Arrays.sort(illegalChars);
} }
// game-related variables
private static Input input;
// This class should not be instantiated. // This class should not be instantiated.
private Utils() {} private Utils() {}
/** /**
* Initializes game settings and class data. * Initializes game settings and class data.
* @param container the game container
* @param game the game object
*/ */
public static void init(GameContainer container, StateBasedGame game) { public static void init(DisplayContainer displayContainer) {
input = container.getInput(); // TODO clean this up
int width = container.getWidth();
int height = container.getHeight();
// game settings // game settings
container.setTargetFrameRate(Options.getTargetFPS()); displayContainer.setFPS(Options.getTargetFPS()); // TODO move this elsewhere
container.setVSync(Options.getTargetFPS() == 60); MusicController.setMusicVolume(Options.getMusicVolume() * Options.getMasterVolume());
container.setMusicVolume(Options.getMusicVolume() * Options.getMasterVolume());
container.setShowFPS(false);
container.getInput().enableKeyRepeat();
container.setAlwaysRender(true);
container.setUpdateOnlyWhenVisible(false);
// calculate UI scale
GameImage.init(width, height);
// create fonts
try {
Fonts.init();
} catch (Exception e) {
ErrorHandler.error("Failed to load fonts.", e, true);
}
// load skin // load skin
Options.loadSkin(); Options.loadSkin();
@ -134,19 +114,19 @@ public class Utils {
} }
// initialize game mods // initialize game mods
GameMod.init(width, height); GameMod.init(displayContainer.width, displayContainer.height);
// initialize playback buttons // initialize playback buttons
PlaybackSpeed.init(width, height); PlaybackSpeed.init(displayContainer.width, displayContainer.height);
// initialize hit objects // initialize hit objects
HitObject.init(width, height); HitObject.init(displayContainer.width, displayContainer.height);
// initialize download nodes // initialize download nodes
DownloadNode.init(width, height); DownloadNode.init(displayContainer.width, displayContainer.height);
// initialize UI components // initialize UI components
UI.init(container, game); UI.init(displayContainer);
} }
/** /**
@ -246,12 +226,15 @@ public class Utils {
* @return true if pressed * @return true if pressed
*/ */
public static boolean isGameKeyPressed() { public static boolean isGameKeyPressed() {
/*
boolean mouseDown = !Options.isMouseDisabled() && ( boolean mouseDown = !Options.isMouseDisabled() && (
input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) || input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) ||
input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON)); input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON));
return (mouseDown || return (mouseDown ||
input.isKeyDown(Options.getGameKeyLeft()) || input.isKeyDown(Options.getGameKeyLeft()) ||
input.isKeyDown(Options.getGameKeyRight())); input.isKeyDown(Options.getGameKeyRight()));
*/
return true;
} }
/** /**

View File

@ -578,4 +578,13 @@ public class MusicController {
ErrorHandler.error("Failed to destroy OpenAL.", e, true); ErrorHandler.error("Failed to destroy OpenAL.", e, true);
} }
} }
/**
* Set the default volume for music
* @param volume the new default value for music volume
*/
public static void setMusicVolume(float volume) {
SoundStore.get().setMusicVolume(volume);
}
} }

View File

@ -19,7 +19,6 @@
package itdelatrisu.opsu.states; package itdelatrisu.opsu.states;
import itdelatrisu.opsu.GameImage; import itdelatrisu.opsu.GameImage;
import itdelatrisu.opsu.Opsu;
import itdelatrisu.opsu.Options; import itdelatrisu.opsu.Options;
import itdelatrisu.opsu.Utils; import itdelatrisu.opsu.Utils;
import itdelatrisu.opsu.audio.MusicController; import itdelatrisu.opsu.audio.MusicController;
@ -36,19 +35,18 @@ import itdelatrisu.opsu.ui.animations.AnimationEquation;
import java.io.File; import java.io.File;
import org.newdawn.slick.Color; import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics; import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input; import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException; import yugecin.opsudance.core.DisplayContainer;
import org.newdawn.slick.state.BasicGameState; import yugecin.opsudance.core.state.BaseOpsuState;
import org.newdawn.slick.state.StateBasedGame;
/** /**
* "Splash Screen" state. * "Splash Screen" state.
* <p> * <p>
* Loads game resources and enters "Main Menu" state. * Loads game resources and enters "Main Menu" state.
*/ */
public class Splash extends BasicGameState { public class Splash extends BaseOpsuState {
/** Minimum time, in milliseconds, to display the splash screen (and fade in the logo). */ /** Minimum time, in milliseconds, to display the splash screen (and fade in the logo). */
private static final int MIN_SPLASH_TIME = 400; private static final int MIN_SPLASH_TIME = 400;
@ -71,18 +69,15 @@ public class Splash extends BasicGameState {
private AnimatedValue logoAlpha; private AnimatedValue logoAlpha;
// game-related variables // game-related variables
private final int state;
private GameContainer container;
private boolean init = false; private boolean init = false;
public Splash(int state) { public Splash(DisplayContainer displayContainer) {
this.state = state; super(displayContainer);
} }
@Override @Override
public void init(GameContainer container, StateBasedGame game) protected void revalidate() {
throws SlickException { super.revalidate();
this.container = container;
// check if skin changed // check if skin changed
if (Options.getSkin() != null) if (Options.getSkin() != null)
@ -92,7 +87,7 @@ public class Splash extends BasicGameState {
this.watchServiceChange = Options.isWatchServiceEnabled() && BeatmapWatchService.get() == null; this.watchServiceChange = Options.isWatchServiceEnabled() && BeatmapWatchService.get() == null;
// load Utils class first (needed in other 'init' methods) // load Utils class first (needed in other 'init' methods)
Utils.init(container, game); Utils.init(displayContainer);
// fade in logo // fade in logo
this.logoAlpha = new AnimatedValue(MIN_SPLASH_TIME, 0f, 1f, AnimationEquation.LINEAR); this.logoAlpha = new AnimatedValue(MIN_SPLASH_TIME, 0f, 1f, AnimationEquation.LINEAR);
@ -100,16 +95,14 @@ public class Splash extends BasicGameState {
} }
@Override @Override
public void render(GameContainer container, StateBasedGame game, Graphics g) public void render(Graphics g) {
throws SlickException {
g.setBackground(Color.black); g.setBackground(Color.black);
GameImage.MENU_LOGO.getImage().drawCentered(container.getWidth() / 2, container.getHeight() / 2); GameImage.MENU_LOGO.getImage().drawCentered(displayContainer.width / 2, displayContainer.height / 2);
UI.drawLoadingProgress(g); UI.drawLoadingProgress(g);
} }
@Override @Override
public void update(GameContainer container, StateBasedGame game, int delta) public void update() {
throws SlickException {
if (!init) { if (!init) {
init = true; init = true;
@ -165,7 +158,7 @@ public class Splash extends BasicGameState {
} }
// fade in logo // fade in logo
if (logoAlpha.update(delta)) if (logoAlpha.update(displayContainer.delta))
GameImage.MENU_LOGO.getImage().setAlpha(logoAlpha.getValue()); GameImage.MENU_LOGO.getImage().setAlpha(logoAlpha.getValue());
// change states when loading complete // change states when loading complete
@ -176,30 +169,32 @@ public class Splash extends BasicGameState {
if (Options.isThemeSongEnabled()) if (Options.isThemeSongEnabled())
MusicController.playThemeSong(); MusicController.playThemeSong();
else else
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).setFocus(BeatmapSetList.get().getRandomNode(), -1, true, true); //((SongMenu) game.getState(Opsu.STATE_SONGMENU)).setFocus(BeatmapSetList.get().getRandomNode(), -1, true, true);
System.out.println(("todo"));
// TODO
} }
// play the theme song // play the theme song
else else
MusicController.playThemeSong(); MusicController.playThemeSong();
game.enterState(Opsu.STATE_MAINMENU); //game.enterState(Opsu.STATE_MAINMENU);
} }
} }
@Override @Override
public int getID() { return state; } public boolean keyPressed(int key, char c) {
@Override
public void keyPressed(int key, char c) {
if (key == Input.KEY_ESCAPE) { if (key == Input.KEY_ESCAPE) {
// close program // close program
if (++escapeCount >= 3) if (++escapeCount >= 3) System.out.println("hi");
container.exit(); //container.exit(); // TODO
// stop parsing beatmaps by sending interrupt to BeatmapParser // stop parsing beatmaps by sending interrupt to BeatmapParser
else if (thread != null) else if (thread != null)
thread.interrupt(); thread.interrupt();
return true;
} }
return false;
} }
} }

View File

@ -36,6 +36,7 @@ import org.lwjgl.LWJGLException;
import org.newdawn.slick.*; import org.newdawn.slick.*;
import org.newdawn.slick.state.StateBasedGame; import org.newdawn.slick.state.StateBasedGame;
import yugecin.opsudance.Dancer; import yugecin.opsudance.Dancer;
import yugecin.opsudance.core.DisplayContainer;
/** /**
* Updates and draws the cursor. * Updates and draws the cursor.
@ -68,9 +69,7 @@ public class Cursor {
private boolean newStyle; private boolean newStyle;
// game-related variables // game-related variables
private static GameContainer container; private static DisplayContainer displayContainer;
private static StateBasedGame game;
private static Input input;
public static Color lastObjColor = Color.white; public static Color lastObjColor = Color.white;
public static Color lastMirroredObjColor = Color.white; public static Color lastMirroredObjColor = Color.white;
@ -82,13 +81,9 @@ public class Cursor {
/** /**
* Initializes the class. * Initializes the class.
* @param container the game container
* @param game the game object
*/ */
public static void init(GameContainer container, StateBasedGame game) { public static void init(DisplayContainer displayContainer) {
Cursor.container = container; Cursor.displayContainer = displayContainer;
Cursor.game = game;
Cursor.input = container.getInput();
// create empty cursor to simulate hiding the cursor // create empty cursor to simulate hiding the cursor
try { try {
@ -116,12 +111,14 @@ public class Cursor {
* Draws the cursor. * Draws the cursor.
*/ */
public void draw() { public void draw() {
/*
int state = game.getCurrentStateID(); int state = game.getCurrentStateID();
boolean mousePressed = boolean mousePressed =
(((state == Opsu.STATE_GAME || state == Opsu.STATE_GAMEPAUSEMENU) && Utils.isGameKeyPressed()) || (((state == Opsu.STATE_GAME || state == Opsu.STATE_GAMEPAUSEMENU) && Utils.isGameKeyPressed()) ||
((input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) || input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON)) && ((input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) || input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON)) &&
!(state == Opsu.STATE_GAME && Options.isMouseDisabled()))); !(state == Opsu.STATE_GAME && Options.isMouseDisabled())));
draw(input.getMouseX(), input.getMouseY(), mousePressed); draw(input.getMouseX(), input.getMouseY(), mousePressed);
*/
} }
/** /**
@ -215,7 +212,7 @@ public class Cursor {
public void setCursorPosition(int mouseX, int mouseY) { public void setCursorPosition(int mouseX, int mouseY) {
// TODO: use an image buffer // TODO: use an image buffer
int removeCount = 0; int removeCount = 0;
float FPSmod = Math.max(container.getFPS(), 1) / 30f; float FPSmod = Math.max(1000 / displayContainer.renderDelta, 1) / 30f; // TODO
if (newStyle) { if (newStyle) {
// new style: add all points between cursor movements // new style: add all points between cursor movements
if ((lastPosition.x == 0 && lastPosition.y == 0) || !addCursorPoints(lastPosition.x, lastPosition.y, mouseX, mouseY)) { if ((lastPosition.x == 0 && lastPosition.y == 0) || !addCursorPoints(lastPosition.x, lastPosition.y, mouseX, mouseY)) {
@ -349,11 +346,13 @@ public class Cursor {
*/ */
public void hide() { public void hide() {
if (emptyCursor != null) { if (emptyCursor != null) {
/*
try { try {
container.setMouseCursor(emptyCursor, 0, 0); container.setMouseCursor(emptyCursor, 0, 0);
} catch (SlickException e) { } catch (SlickException e) {
ErrorHandler.error("Failed to hide the cursor.", e, true); ErrorHandler.error("Failed to hide the cursor.", e, true);
} }
*/
} }
} }
@ -361,6 +360,6 @@ public class Cursor {
* Unhides the cursor. * Unhides the cursor.
*/ */
public void show() { public void show() {
container.setDefaultMouseCursor(); //container.setDefaultMouseCursor();
} }
} }

View File

@ -39,6 +39,7 @@ import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image; import org.newdawn.slick.Image;
import org.newdawn.slick.Input; import org.newdawn.slick.Input;
import org.newdawn.slick.state.StateBasedGame; import org.newdawn.slick.state.StateBasedGame;
import yugecin.opsudance.core.DisplayContainer;
/** /**
* Draws common UI components. * Draws common UI components.
@ -75,7 +76,7 @@ public class UI {
private static AnimatedValue tooltipAlpha = new AnimatedValue(200, 0f, 1f, AnimationEquation.LINEAR); private static AnimatedValue tooltipAlpha = new AnimatedValue(200, 0f, 1f, AnimationEquation.LINEAR);
// game-related variables // game-related variables
private static GameContainer container; private static DisplayContainer displayContainer;
private static Input input; private static Input input;
// This class should not be instantiated. // This class should not be instantiated.
@ -83,24 +84,21 @@ public class UI {
/** /**
* Initializes UI data. * Initializes UI data.
* @param container the game container
* @param game the game object
*/ */
public static void init(GameContainer container, StateBasedGame game) { public static void init(DisplayContainer displayContainer) {
UI.container = container; UI.displayContainer = displayContainer;
UI.input = container.getInput();
// initialize cursor // initialize cursor
Cursor.init(container, game); Cursor.init(displayContainer);
cursor.hide(); cursor.hide();
// back button // back button
if (GameImage.MENU_BACK.getImages() != null) { if (GameImage.MENU_BACK.getImages() != null) {
Animation back = GameImage.MENU_BACK.getAnimation(120); Animation back = GameImage.MENU_BACK.getAnimation(120);
backButton = new MenuButton(back, back.getWidth() / 2f, container.getHeight() - (back.getHeight() / 2f)); backButton = new MenuButton(back, back.getWidth() / 2f, displayContainer.height - (back.getHeight() / 2f));
} else { } else {
Image back = GameImage.MENU_BACK.getImage(); Image back = GameImage.MENU_BACK.getImage();
backButton = new MenuButton(back, back.getWidth() / 2f, container.getHeight() - (back.getHeight() / 2f)); backButton = new MenuButton(back, back.getWidth() / 2f, displayContainer.height - (back.getHeight() / 2f));
} }
backButton.setHoverAnimationDuration(350); backButton.setHoverAnimationDuration(350);
backButton.setHoverAnimationEquation(AnimationEquation.IN_OUT_BACK); backButton.setHoverAnimationEquation(AnimationEquation.IN_OUT_BACK);
@ -125,7 +123,6 @@ public class UI {
public static void draw(Graphics g) { public static void draw(Graphics g) {
drawBarNotification(g); drawBarNotification(g);
drawVolume(g); drawVolume(g);
drawFPS();
cursor.draw(); cursor.draw();
drawTooltip(g); drawTooltip(g);
} }
@ -140,7 +137,6 @@ public class UI {
public static void draw(Graphics g, int mouseX, int mouseY, boolean mousePressed) { public static void draw(Graphics g, int mouseX, int mouseY, boolean mousePressed) {
drawBarNotification(g); drawBarNotification(g);
drawVolume(g); drawVolume(g);
drawFPS();
cursor.draw(mouseX, mouseY, mousePressed); cursor.draw(mouseX, mouseY, mousePressed);
drawTooltip(g); drawTooltip(g);
} }
@ -189,27 +185,6 @@ public class UI {
Fonts.MEDIUM.drawString(tabTextX, tabTextY, text, textColor); Fonts.MEDIUM.drawString(tabTextX, tabTextY, text, textColor);
} }
/**
* Draws the FPS at the bottom-right corner of the game container.
* If the option is not activated, this will do nothing.
*/
public static void drawFPS() {
if (!Options.isFPSCounterEnabled())
return;
String fps = String.format("%dFPS", container.getFPS());
Fonts.BOLD.drawString(
container.getWidth() * 0.997f - Fonts.BOLD.getWidth(fps),
container.getHeight() * 0.997f - Fonts.BOLD.getHeight(fps),
Integer.toString(container.getFPS()), Color.white
);
Fonts.DEFAULT.drawString(
container.getWidth() * 0.997f - Fonts.BOLD.getWidth("FPS"),
container.getHeight() * 0.997f - Fonts.BOLD.getHeight("FPS"),
"FPS", Color.white
);
}
/** /**
* Draws the volume bar on the middle right-hand side of the game container. * Draws the volume bar on the middle right-hand side of the game container.
* Only draws if the volume has recently been changed using with {@link #changeVolume(int)}. * Only draws if the volume has recently been changed using with {@link #changeVolume(int)}.
@ -219,7 +194,6 @@ public class UI {
if (volumeDisplay == -1) if (volumeDisplay == -1)
return; return;
int width = container.getWidth(), height = container.getHeight();
Image img = GameImage.VOLUME.getImage(); Image img = GameImage.VOLUME.getImage();
// move image in/out // move image in/out
@ -230,13 +204,13 @@ public class UI {
else if (ratio >= 0.9f) else if (ratio >= 0.9f)
xOffset = img.getWidth() * (1 - ((1 - ratio) * 10f)); xOffset = img.getWidth() * (1 - ((1 - ratio) * 10f));
img.drawCentered(width - img.getWidth() / 2f + xOffset, height / 2f); img.drawCentered(displayContainer.width - img.getWidth() / 2f + xOffset, displayContainer.height / 2f);
float barHeight = img.getHeight() * 0.9f; float barHeight = img.getHeight() * 0.9f;
float volume = Options.getMasterVolume(); float volume = Options.getMasterVolume();
g.setColor(Color.white); g.setColor(Color.white);
g.fillRoundRect( g.fillRoundRect(
width - (img.getWidth() * 0.368f) + xOffset, displayContainer.width - (img.getWidth() * 0.368f) + xOffset,
(height / 2f) - (img.getHeight() * 0.47f) + (barHeight * (1 - volume)), (displayContainer.height / 2f) - (img.getHeight() * 0.47f) + (barHeight * (1 - volume)),
img.getWidth() * 0.15f, barHeight * volume, 3 img.getWidth() * 0.15f, barHeight * volume, 3
); );
} }
@ -260,7 +234,7 @@ public class UI {
*/ */
public static void changeVolume(int units) { public static void changeVolume(int units) {
final float UNIT_OFFSET = 0.05f; final float UNIT_OFFSET = 0.05f;
Options.setMasterVolume(container, Utils.clamp(Options.getMasterVolume() + (UNIT_OFFSET * units), 0f, 1f)); Options.setMasterVolume(Utils.clamp(Options.getMasterVolume() + (UNIT_OFFSET * units), 0f, 1f));
if (volumeDisplay == -1) if (volumeDisplay == -1)
volumeDisplay = 0; volumeDisplay = 0;
else if (volumeDisplay >= VOLUME_DISPLAY_TIME / 10) else if (volumeDisplay >= VOLUME_DISPLAY_TIME / 10)
@ -294,8 +268,8 @@ public class UI {
return; return;
// draw loading info // draw loading info
float marginX = container.getWidth() * 0.02f, marginY = container.getHeight() * 0.02f; float marginX = displayContainer.width * 0.02f, marginY = displayContainer.height * 0.02f;
float lineY = container.getHeight() - marginY; float lineY = displayContainer.height - marginY;
int lineOffsetY = Fonts.MEDIUM.getLineHeight(); int lineOffsetY = Fonts.MEDIUM.getLineHeight();
if (Options.isLoadVerbose()) { if (Options.isLoadVerbose()) {
// verbose: display percentages and file names // verbose: display percentages and file names
@ -308,7 +282,7 @@ public class UI {
Fonts.MEDIUM.drawString(marginX, lineY - (lineOffsetY * 2), text, Color.white); Fonts.MEDIUM.drawString(marginX, lineY - (lineOffsetY * 2), text, Color.white);
g.setColor(Color.white); g.setColor(Color.white);
g.fillRoundRect(marginX, lineY - (lineOffsetY / 2f), g.fillRoundRect(marginX, lineY - (lineOffsetY / 2f),
(container.getWidth() - (marginX * 2f)) * progress / 100f, lineOffsetY / 4f, 4 (displayContainer.width - (marginX * 2f)) * progress / 100f, lineOffsetY / 4f, 4
); );
} }
} }
@ -332,7 +306,7 @@ public class UI {
float unitBaseX, float unitBaseY, float unitWidth, float scrollAreaHeight, float unitBaseX, float unitBaseY, float unitWidth, float scrollAreaHeight,
Color bgColor, Color scrollbarColor, boolean right Color bgColor, Color scrollbarColor, boolean right
) { ) {
float scrollbarWidth = container.getWidth() * 0.00347f; float scrollbarWidth = displayContainer.width * 0.00347f;
float scrollbarHeight = scrollAreaHeight * lengthShown / totalLength; float scrollbarHeight = scrollAreaHeight * lengthShown / totalLength;
float offsetY = (scrollAreaHeight - scrollbarHeight) * (position / (totalLength - lengthShown)); float offsetY = (scrollAreaHeight - scrollbarHeight) * (position / (totalLength - lengthShown));
float scrollbarX = unitBaseX + unitWidth - ((right) ? scrollbarWidth : 0); float scrollbarX = unitBaseX + unitWidth - ((right) ? scrollbarWidth : 0);
@ -368,8 +342,7 @@ public class UI {
if (tooltipAlpha.getTime() == 0 || tooltip == null) if (tooltipAlpha.getTime() == 0 || tooltip == null)
return; return;
int containerWidth = container.getWidth(), containerHeight = container.getHeight(); int margin = displayContainer.width / 100, textMarginX = 2;
int margin = containerWidth / 100, textMarginX = 2;
int offset = GameImage.CURSOR_MIDDLE.getImage().getWidth() / 2; int offset = GameImage.CURSOR_MIDDLE.getImage().getWidth() / 2;
int lineHeight = Fonts.SMALL.getLineHeight(); int lineHeight = Fonts.SMALL.getLineHeight();
int textWidth = textMarginX * 2, textHeight = lineHeight; int textWidth = textMarginX * 2, textHeight = lineHeight;
@ -388,12 +361,12 @@ public class UI {
// get drawing coordinates // get drawing coordinates
int x = input.getMouseX() + offset, y = input.getMouseY() + offset; int x = input.getMouseX() + offset, y = input.getMouseY() + offset;
if (x + textWidth > containerWidth - margin) if (x + textWidth > displayContainer.width - margin)
x = containerWidth - margin - textWidth; x = displayContainer.width - margin - textWidth;
else if (x < margin) else if (x < margin)
x = margin; x = margin;
if (y + textHeight > containerHeight - margin) if (y + textHeight > displayContainer.height - margin)
y = containerHeight - margin - textHeight; y = displayContainer.height - margin - textHeight;
else if (y < margin) else if (y < margin)
y = margin; y = margin;
@ -467,13 +440,13 @@ public class UI {
float alpha = 1f; float alpha = 1f;
if (barNotifTimer >= BAR_NOTIFICATION_TIME * 0.9f) if (barNotifTimer >= BAR_NOTIFICATION_TIME * 0.9f)
alpha -= 1 - ((BAR_NOTIFICATION_TIME - barNotifTimer) / (BAR_NOTIFICATION_TIME * 0.1f)); alpha -= 1 - ((BAR_NOTIFICATION_TIME - barNotifTimer) / (BAR_NOTIFICATION_TIME * 0.1f));
int midX = container.getWidth() / 2, midY = container.getHeight() / 2; int midX = displayContainer.width / 2, midY = displayContainer.height / 2;
float barHeight = Fonts.LARGE.getLineHeight() * (1f + 0.6f * Math.min(barNotifTimer * 15f / BAR_NOTIFICATION_TIME, 1f)); float barHeight = Fonts.LARGE.getLineHeight() * (1f + 0.6f * Math.min(barNotifTimer * 15f / BAR_NOTIFICATION_TIME, 1f));
float oldAlphaB = Colors.BLACK_ALPHA.a, oldAlphaW = Colors.WHITE_ALPHA.a; float oldAlphaB = Colors.BLACK_ALPHA.a, oldAlphaW = Colors.WHITE_ALPHA.a;
Colors.BLACK_ALPHA.a *= alpha; Colors.BLACK_ALPHA.a *= alpha;
Colors.WHITE_ALPHA.a = alpha; Colors.WHITE_ALPHA.a = alpha;
g.setColor(Colors.BLACK_ALPHA); g.setColor(Colors.BLACK_ALPHA);
g.fillRect(0, midY - barHeight / 2f, container.getWidth(), barHeight); g.fillRect(0, midY - barHeight / 2f, displayContainer.width, barHeight);
Fonts.LARGE.drawString( Fonts.LARGE.drawString(
midX - Fonts.LARGE.getWidth(barNotif) / 2f, midX - Fonts.LARGE.getWidth(barNotif) / 2f,
midY - Fonts.LARGE.getLineHeight() / 2.2f, midY - Fonts.LARGE.getLineHeight() / 2.2f,

View File

@ -22,6 +22,7 @@ import itdelatrisu.opsu.Utils;
import itdelatrisu.opsu.db.DBController; import itdelatrisu.opsu.db.DBController;
import itdelatrisu.opsu.downloads.DownloadList; import itdelatrisu.opsu.downloads.DownloadList;
import itdelatrisu.opsu.downloads.Updater; import itdelatrisu.opsu.downloads.Updater;
import itdelatrisu.opsu.states.Splash;
import org.newdawn.slick.util.Log; import org.newdawn.slick.util.Log;
import yugecin.opsudance.core.DisplayContainer; import yugecin.opsudance.core.DisplayContainer;
import yugecin.opsudance.core.errorhandling.ErrorHandler; import yugecin.opsudance.core.errorhandling.ErrorHandler;
@ -61,7 +62,8 @@ public class OpsuDance {
initUpdater(args); initUpdater(args);
sout("database & updater initialized"); sout("database & updater initialized");
container.init(EmptyState.class); //container.init(EmptyState.class);
container.init(Splash.class);
} catch (Exception e) { } catch (Exception e) {
errorAndExit("startup failure", e); errorAndExit("startup failure", e);
} }

View File

@ -18,6 +18,7 @@
package yugecin.opsudance.core; package yugecin.opsudance.core;
import itdelatrisu.opsu.GameImage; import itdelatrisu.opsu.GameImage;
import itdelatrisu.opsu.Options;
import itdelatrisu.opsu.ui.Fonts; import itdelatrisu.opsu.ui.Fonts;
import org.lwjgl.LWJGLException; import org.lwjgl.LWJGLException;
import org.lwjgl.Sys; import org.lwjgl.Sys;
@ -29,6 +30,7 @@ import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input; import org.newdawn.slick.Input;
import org.newdawn.slick.KeyListener; import org.newdawn.slick.KeyListener;
import org.newdawn.slick.MouseListener; import org.newdawn.slick.MouseListener;
import org.newdawn.slick.openal.SoundStore;
import org.newdawn.slick.opengl.InternalTextureLoader; import org.newdawn.slick.opengl.InternalTextureLoader;
import org.newdawn.slick.opengl.renderer.Renderer; import org.newdawn.slick.opengl.renderer.Renderer;
import org.newdawn.slick.opengl.renderer.SGL; import org.newdawn.slick.opengl.renderer.SGL;
@ -70,7 +72,7 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
private OpsuState state; private OpsuState state;
private final DisplayMode nativeDisplayMode; public final DisplayMode nativeDisplayMode;
private Graphics graphics; private Graphics graphics;
private Input input; private Input input;
@ -204,7 +206,7 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
Display.setDisplayMode(new DisplayMode(100, 100)); Display.setDisplayMode(new DisplayMode(100, 100));
Display.create(); Display.create();
GLHelper.setIcons(new String[] { "icon16.png", "icon32.png" }); GLHelper.setIcons(new String[] { "icon16.png", "icon32.png" });
setDisplayMode(800, 600, false); Options.setDisplayMode(this);
sout("GL ready"); sout("GL ready");
glVersion = GL11.glGetString(GL11.GL_VERSION); glVersion = GL11.glGetString(GL11.GL_VERSION);
glVendor = GL11.glGetString(GL11.GL_VENDOR); glVendor = GL11.glGetString(GL11.GL_VENDOR);
@ -257,6 +259,7 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
graphics.setAntiAlias(false); graphics.setAntiAlias(false);
input = new Input(height); input = new Input(height);
input.enableKeyRepeat();
input.addKeyListener(this); input.addKeyListener(this);
input.addMouseListener(this); input.addMouseListener(this);

View File

@ -17,6 +17,7 @@
*/ */
package yugecin.opsudance.core.inject; package yugecin.opsudance.core.inject;
import itdelatrisu.opsu.states.Splash;
import yugecin.opsudance.PreStartupInitializer; import yugecin.opsudance.PreStartupInitializer;
import yugecin.opsudance.core.DisplayContainer; import yugecin.opsudance.core.DisplayContainer;
import yugecin.opsudance.core.events.EventBus; import yugecin.opsudance.core.events.EventBus;
@ -50,6 +51,8 @@ public class OpsuDanceInjector extends Injector {
bind(EmptyRedState.class).asEagerSingleton(); bind(EmptyRedState.class).asEagerSingleton();
bind(EmptyState.class).asEagerSingleton(); bind(EmptyState.class).asEagerSingleton();
bind(Splash.class).asEagerSingleton();
} }
} }

View File

@ -17,6 +17,7 @@
*/ */
package yugecin.opsudance.core.state; package yugecin.opsudance.core.state;
import org.newdawn.slick.Graphics;
import yugecin.opsudance.core.DisplayContainer; import yugecin.opsudance.core.DisplayContainer;
import yugecin.opsudance.core.events.EventListener; import yugecin.opsudance.core.events.EventListener;
import yugecin.opsudance.events.ResolutionChangedEvent; import yugecin.opsudance.events.ResolutionChangedEvent;
@ -41,6 +42,18 @@ public abstract class BaseOpsuState implements OpsuState, EventListener<Resoluti
protected void revalidate() { protected void revalidate() {
} }
@Override
public void update() {
}
@Override
public void preRenderUpdate() {
}
@Override
public void render(Graphics g) {
}
@Override @Override
public void onEvent(ResolutionChangedEvent event) { public void onEvent(ResolutionChangedEvent event) {
if (isCurrentState) { if (isCurrentState) {