enable cursor

This commit is contained in:
yugecin 2017-01-21 13:11:34 +01:00
parent 95a466f92f
commit 978a41116c
9 changed files with 142 additions and 189 deletions

View File

@ -467,12 +467,7 @@ public class Options {
val = i; val = i;
} }
}, },
NEW_CURSOR ("Enable New Cursor", "NewCursor", "Use the new cursor style (may cause higher CPU usage).", true) { NEW_CURSOR ("Enable New Cursor", "NewCursor", "Use the new cursor style (may cause higher CPU usage).", true),
@Override
public void click() {
UI.getCursor().reset();
}
},
DYNAMIC_BACKGROUND ("Enable Dynamic Backgrounds", "DynamicBackground", "The song background will be used as the main menu background.", true), DYNAMIC_BACKGROUND ("Enable Dynamic Backgrounds", "DynamicBackground", "The song background will be used as the main menu background.", true),
LOAD_VERBOSE ("Show Detailed Loading Progress", "LoadVerbose", "Display more specific loading information in the splash screen.", false), LOAD_VERBOSE ("Show Detailed Loading Progress", "LoadVerbose", "Display more specific loading information in the splash screen.", false),
COLOR_MAIN_MENU_LOGO ("Use cursor color as main menu logo tint", "ColorMainMenuLogo", "Colorful main menu logo", false), COLOR_MAIN_MENU_LOGO ("Use cursor color as main menu logo tint", "ColorMainMenuLogo", "Colorful main menu logo", false),

View File

@ -73,6 +73,7 @@ import yugecin.opsudance.objects.curves.FakeCombinedCurve;
import yugecin.opsudance.sbv2.MoveStoryboard; import yugecin.opsudance.sbv2.MoveStoryboard;
import yugecin.opsudance.ui.OptionsOverlay; import yugecin.opsudance.ui.OptionsOverlay;
import yugecin.opsudance.ui.StoryboardOverlay; import yugecin.opsudance.ui.StoryboardOverlay;
import yugecin.opsudance.utils.GLHelper;
/** /**
* "Game" state. * "Game" state.
@ -449,38 +450,6 @@ public class Game extends ComplexOpsuState {
if (GameMod.FLASHLIGHT.isActive()) if (GameMod.FLASHLIGHT.isActive())
Graphics.setCurrent(g); Graphics.setCurrent(g);
// "auto" and "autopilot" mods: move cursor automatically
// TODO: this should really be in update(), not render()
autoMousePosition.set(width / 2, height / 2);
autoMousePressed = false;
if (GameMod.AUTO.isActive() || GameMod.AUTOPILOT.isActive()) {
Vec2f autoPoint;
if (objectIndex < beatmap.objects.length - Dancer.instance.getPolyMoverFactoryMinBufferSize()) {
Dancer d = Dancer.instance;
d.update(trackPosition, objectIndex);
autoPoint = new Vec2f(d.x, d.y);
if (trackPosition < gameObjects[objectIndex].getTime()) {
autoMousePressed = true;
}
} else {
if (objectIndex < beatmap.objects.length) {
autoPoint = gameObjects[objectIndex].getPointAt(trackPosition);
} else {
// last object
autoPoint = gameObjects[objectIndex - 1].getPointAt(trackPosition);
}
}
float[] sbPosition = moveStoryboardOverlay.getPoint(trackPosition);
if (sbPosition != null) {
autoPoint.x = sbPosition[0];
autoPoint.y = sbPosition[1];
}
// set mouse coordinates
autoMousePosition.set(autoPoint.x, autoPoint.y);
}
// "flashlight" mod: restricted view of hit objects around cursor // "flashlight" mod: restricted view of hit objects around cursor
if (GameMod.FLASHLIGHT.isActive()) { if (GameMod.FLASHLIGHT.isActive()) {
// render hit objects offscreen // render hit objects offscreen
@ -748,22 +717,18 @@ public class Game extends ComplexOpsuState {
cursorCirclePulse.drawCentered(pausedMousePosition.x, pausedMousePosition.y); cursorCirclePulse.drawCentered(pausedMousePosition.x, pausedMousePosition.y);
} }
if (isReplay) if (isReplay) {
UI.draw(g, replayX, replayY, replayKeyPressed); displayContainer.cursor.draw(replayKeyPressed);
else if (GameMod.AUTO.isActive()) { } else if (GameMod.AUTO.isActive()) {
UI.draw(g, (int) autoMousePosition.x, (int) autoMousePosition.y, autoMousePressed); displayContainer.cursor.draw(autoMousePressed);
if (Options.isMirror() && GameMod.AUTO.isActive()) { if (Options.isMirror() && GameMod.AUTO.isActive()) {
double dx = autoMousePosition.x - Options.width / 2d; mirrorCursor.draw(autoMousePressed);
double dy = autoMousePosition.y - Options.height / 2d;
double d = Math.sqrt(dx * dx + dy * dy);
double a = Math.atan2(dy, dx) + Math.PI;
mirrorCursor.draw((int) (Math.cos(a) * d + Options.width / 2), (int) (Math.sin(a) * d + Options.height / 2), autoMousePressed);
} }
} else if (GameMod.AUTOPILOT.isActive()) {
displayContainer.cursor.draw(Utils.isGameKeyPressed());
} }
else if (GameMod.AUTOPILOT.isActive())
UI.draw(g, (int) autoMousePosition.x, (int) autoMousePosition.y, Utils.isGameKeyPressed()); UI.draw(g);
else
UI.draw(g);
if (!Options.isHideWM()) { if (!Options.isHideWM()) {
Fonts.SMALL.drawString(0.3f, 0.3f, "opsu!dance " + Updater.get().getCurrentVersion() + " by robin_be | https://github.com/yugecin/opsu-dance"); Fonts.SMALL.drawString(0.3f, 0.3f, "opsu!dance " + Updater.get().getCurrentVersion() + " by robin_be | https://github.com/yugecin/opsu-dance");
@ -926,6 +891,58 @@ public class Game extends ComplexOpsuState {
} }
} }
@Override
public void update() {
super.update();
int trackPosition = MusicController.getPosition();
// "auto" and "autopilot" mods: move cursor automatically
autoMousePressed = false;
if (GameMod.AUTO.isActive() || GameMod.AUTOPILOT.isActive()) {
Vec2f autoPoint;
if (objectIndex < beatmap.objects.length - Dancer.instance.getPolyMoverFactoryMinBufferSize()) {
Dancer d = Dancer.instance;
d.update(trackPosition, objectIndex);
autoPoint = new Vec2f(d.x, d.y);
if (trackPosition < gameObjects[objectIndex].getTime()) {
autoMousePressed = true;
}
} else {
if (objectIndex < beatmap.objects.length) {
autoPoint = gameObjects[objectIndex].getPointAt(trackPosition);
} else {
// last object
autoPoint = gameObjects[objectIndex - 1].getPointAt(trackPosition);
}
}
float[] sbPosition = moveStoryboardOverlay.getPoint(trackPosition);
if (sbPosition != null) {
autoPoint.x = sbPosition[0];
autoPoint.y = sbPosition[1];
}
// set mouse coordinates
autoMousePosition.set(autoPoint.x, autoPoint.y);
}
if (isReplay) {
displayContainer.cursor.setCursorPosition(displayContainer.delta, replayX, replayY);
} else if (GameMod.AUTO.isActive()) {
displayContainer.cursor.setCursorPosition(displayContainer.delta, (int) autoMousePosition.x, (int) autoMousePosition.y);
if (Options.isMirror() && GameMod.AUTO.isActive()) {
double dx = autoMousePosition.x - Options.width / 2d;
double dy = autoMousePosition.y - Options.height / 2d;
double d = Math.sqrt(dx * dx + dy * dy);
double a = Math.atan2(dy, dx) + Math.PI;
mirrorCursor.setCursorPosition(displayContainer.delta, (int) (Math.cos(a) * d + Options.width / 2), (int) (Math.sin(a) * d + Options.height / 2));
}
} else if (GameMod.AUTOPILOT.isActive()) {
displayContainer.cursor.setCursorPosition(displayContainer.delta, (int) autoMousePosition.x, (int) autoMousePosition.y);
}
}
/** /**
* Updates the game. * Updates the game.
* @param mouseX the mouse x coordinate * @param mouseX the mouse x coordinate
@ -1078,11 +1095,6 @@ public class Game extends ComplexOpsuState {
boolean overlap = (objectIndex + 1 < gameObjects.length && boolean overlap = (objectIndex + 1 < gameObjects.length &&
trackPosition > beatmap.objects[objectIndex + 1].getTime() - hitResultOffset[GameData.HIT_50]); trackPosition > beatmap.objects[objectIndex + 1].getTime() - hitResultOffset[GameData.HIT_50]);
if (skippedObject && (GameMod.AUTO.isActive() || GameMod.AUTOPILOT.isActive())) {
Vec2f start = gameObjects[objectIndex - 1].start;
UI.getCursor().setCursorPosition((int) start.x, (int) start.y);
}
// update hit object and check completion status // update hit object and check completion status
if (gameObjects[objectIndex].update(overlap, delta, mouseX, mouseY, keyPressed, trackPosition)) { if (gameObjects[objectIndex].update(overlap, delta, mouseX, mouseY, keyPressed, trackPosition)) {
skippedObject = true; skippedObject = true;
@ -1210,7 +1222,7 @@ public class Game extends ComplexOpsuState {
mirrorTo = objectIndex; mirrorTo = objectIndex;
Options.setMirror(false); Options.setMirror(false);
} else { } else {
mirrorCursor.resetLocations(); mirrorCursor.resetLocations((int) autoMousePosition.x, (int) autoMousePosition.y);
mirrorFrom = objectIndex; mirrorFrom = objectIndex;
mirrorTo = gameObjects.length; mirrorTo = gameObjects.length;
Options.setMirror(true); Options.setMirror(true);
@ -1221,7 +1233,7 @@ public class Game extends ComplexOpsuState {
mirrorTo = objectIndex; mirrorTo = objectIndex;
Options.setMirror(false); Options.setMirror(false);
} else { } else {
mirrorCursor.resetLocations(); mirrorCursor.resetLocations((int) autoMousePosition.x, (int) autoMousePosition.y);
mirrorFrom = objectIndex; mirrorFrom = objectIndex;
mirrorTo = mirrorFrom + 1; mirrorTo = mirrorFrom + 1;
Options.setMirror(true); Options.setMirror(true);
@ -1435,6 +1447,8 @@ public class Game extends ComplexOpsuState {
public void enter() { public void enter() {
super.enter(); super.enter();
displayContainer.drawCursor = false;
overlays.clear(); overlays.clear();
if (Options.isEnableSB()) { if (Options.isEnableSB()) {
overlays.add(optionsOverlay); overlays.add(optionsOverlay);
@ -1572,8 +1586,9 @@ public class Game extends ComplexOpsuState {
} }
// unhide cursor for "auto" mod and replays // unhide cursor for "auto" mod and replays
if (GameMod.AUTO.isActive() || isReplay) if (GameMod.AUTO.isActive() || isReplay) {
UI.getCursor().show(); GLHelper.showNativeCursor();
}
// load replay frames // load replay frames
if (isReplay) { if (isReplay) {
@ -1683,6 +1698,8 @@ public class Game extends ComplexOpsuState {
public void leave() { public void leave() {
super.leave(); super.leave();
displayContainer.drawCursor = true;
MusicController.pause(); MusicController.pause();
MusicController.setPitch(1f); MusicController.setPitch(1f);
MusicController.resume(); MusicController.resume();
@ -1705,8 +1722,9 @@ public class Game extends ComplexOpsuState {
Cursor.nextMirroredObjColor = Color.white; Cursor.nextMirroredObjColor = Color.white;
// re-hide cursor // re-hide cursor
if (GameMod.AUTO.isActive() || isReplay) if (GameMod.AUTO.isActive() || isReplay) {
UI.getCursor().hide(); GLHelper.hideNativeCursor();
}
// replays // replays
if (isReplay) if (isReplay)

View File

@ -110,9 +110,6 @@ public class GamePauseMenu extends BaseOpsuState {
SoundController.playSound(SoundEffect.MENUBACK); SoundController.playSound(SoundEffect.MENUBACK);
instanceContainer.provide(SongMenu.class).resetGameDataOnLoad(); instanceContainer.provide(SongMenu.class).resetGameDataOnLoad();
MusicController.playAt(MusicController.getBeatmap().previewTime, true); MusicController.playAt(MusicController.getBeatmap().previewTime, true);
if (UI.getCursor().isBeatmapSkinned()) {
UI.getCursor().reset();
}
displayContainer.switchState(SongMenu.class); displayContainer.switchState(SongMenu.class);
} else { } else {
SoundController.playSound(SoundEffect.MENUBACK); SoundController.playSound(SoundEffect.MENUBACK);
@ -157,8 +154,9 @@ public class GamePauseMenu extends BaseOpsuState {
MusicController.playAt(MusicController.getBeatmap().previewTime, true); MusicController.playAt(MusicController.getBeatmap().previewTime, true);
else else
MusicController.resume(); MusicController.resume();
if (UI.getCursor().isBeatmapSkinned()) if (displayContainer.cursor.isBeatmapSkinned()) {
UI.getCursor().reset(); displayContainer.resetCursor();
}
MusicController.setPitch(1.0f); MusicController.setPitch(1.0f);
displayContainer.switchState(SongMenu.class); displayContainer.switchState(SongMenu.class);
} }

View File

@ -63,6 +63,7 @@ public class GameRanking extends BaseOpsuState {
public GameRanking(DisplayContainer displayContainer, InstanceContainer instanceContainer) { public GameRanking(DisplayContainer displayContainer, InstanceContainer instanceContainer) {
super(displayContainer); super(displayContainer);
this.instanceContainer = instanceContainer; this.instanceContainer = instanceContainer;
} }
@Override @Override
@ -242,8 +243,8 @@ public class GameRanking extends BaseOpsuState {
songMenu.resetTrackOnLoad(); songMenu.resetTrackOnLoad();
} }
songMenu.resetGameDataOnLoad(); songMenu.resetGameDataOnLoad();
if (UI.getCursor().isBeatmapSkinned()) { if (displayContainer.cursor.isBeatmapSkinned()) {
UI.getCursor().reset(); displayContainer.resetCursor();
} }
displayContainer.switchState(SongMenu.class); displayContainer.switchState(SongMenu.class);
} }

View File

@ -21,28 +21,19 @@ package itdelatrisu.opsu.ui;
import itdelatrisu.opsu.GameImage; import itdelatrisu.opsu.GameImage;
import itdelatrisu.opsu.Options; import itdelatrisu.opsu.Options;
import itdelatrisu.opsu.Utils; import itdelatrisu.opsu.Utils;
import itdelatrisu.opsu.audio.MusicController;
import itdelatrisu.opsu.skins.Skin; import itdelatrisu.opsu.skins.Skin;
import itdelatrisu.opsu.ui.animations.AnimationEquation; import itdelatrisu.opsu.ui.animations.AnimationEquation;
import java.awt.Point; import java.awt.Point;
import java.nio.IntBuffer;
import java.util.LinkedList; import java.util.LinkedList;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.newdawn.slick.*; import org.newdawn.slick.*;
import org.newdawn.slick.state.StateBasedGame;
import yugecin.opsudance.Dancer; import yugecin.opsudance.Dancer;
import yugecin.opsudance.core.DisplayContainer;
import yugecin.opsudance.core.errorhandling.ErrorHandler;
/** /**
* Updates and draws the cursor. * Updates and draws the cursor.
*/ */
public class Cursor { public class Cursor {
/** Empty cursor. */
private static org.lwjgl.input.Cursor emptyCursor;
/** Last cursor coordinates. */ /** Last cursor coordinates. */
private Point lastPosition; private Point lastPosition;
@ -63,13 +54,10 @@ public class Cursor {
private static final float CURSOR_SCALE_TIME = 125; private static final float CURSOR_SCALE_TIME = 125;
/** Stores all previous cursor locations to display a trail. */ /** Stores all previous cursor locations to display a trail. */
private LinkedList<Point> trail = new LinkedList<Point>(); private LinkedList<Point> trail = new LinkedList<>();
private boolean newStyle; private boolean newStyle;
// game-related variables
private static DisplayContainer displayContainer;
public static Color lastObjColor = Color.white; public static Color lastObjColor = Color.white;
public static Color lastMirroredObjColor = Color.white; public static Color lastMirroredObjColor = Color.white;
public static Color nextObjColor = Color.white; public static Color nextObjColor = Color.white;
@ -78,22 +66,6 @@ public class Cursor {
private boolean isMirrored; private boolean isMirrored;
/**
* Initializes the class.
*/
public static void init(DisplayContainer displayContainer) {
Cursor.displayContainer = displayContainer;
// create empty cursor to simulate hiding the cursor
try {
int min = org.lwjgl.input.Cursor.getMinCursorSize();
IntBuffer tmp = BufferUtils.createIntBuffer(min * min);
emptyCursor = new org.lwjgl.input.Cursor(min, min, min/2, min/2, 1, tmp, null);
} catch (LWJGLException e) {
ErrorHandler.error("Failed to create hidden cursor.", e).show();
}
}
/** /**
* Constructor. * Constructor.
*/ */
@ -102,31 +74,15 @@ public class Cursor {
} }
public Cursor(boolean isMirrored) { public Cursor(boolean isMirrored) {
resetLocations(); resetLocations(0, 0);
this.isMirrored = isMirrored; this.isMirrored = isMirrored;
} }
/** /**
* Draws the cursor. * Draws the cursor.
*/
public void draw() {
/*
int state = game.getCurrentStateID();
boolean mousePressed =
(((state == Opsu.STATE_GAME || state == Opsu.STATE_GAMEPAUSEMENU) && Utils.isGameKeyPressed()) ||
((input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) || input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON)) &&
!(state == Opsu.STATE_GAME && Options.isMouseDisabled())));
draw(input.getMouseX(), input.getMouseY(), mousePressed);
*/
}
/**
* Draws the cursor.
* @param mouseX the mouse x coordinate
* @param mouseY the mouse y coordinate
* @param mousePressed whether or not the mouse button is pressed * @param mousePressed whether or not the mouse button is pressed
*/ */
public void draw(int mouseX, int mouseY, boolean mousePressed) { public void draw(boolean mousePressed) {
if (Options.isCursorDisabled()) if (Options.isCursorDisabled())
return; return;
@ -168,8 +124,6 @@ public class Cursor {
cursorTrail = cursorTrail.getScaledCopy(cursorScale); cursorTrail = cursorTrail.getScaledCopy(cursorScale);
} }
setCursorPosition(mouseX, mouseY);
Color filter; Color filter;
if (isMirrored) { if (isMirrored) {
filter = Dancer.cursorColorMirrorOverride.getMirrorColor(); filter = Dancer.cursorColorMirrorOverride.getMirrorColor();
@ -191,16 +145,16 @@ public class Cursor {
cursorTrailWidth, cursorTrailHeight, cursorTrailRotation); cursorTrailWidth, cursorTrailHeight, cursorTrailRotation);
} }
cursorTrail.drawEmbedded( cursorTrail.drawEmbedded(
mouseX - (cursorTrailWidth / 2f), mouseY - (cursorTrailHeight / 2f), lastPosition.x - (cursorTrailWidth / 2f), lastPosition.y - (cursorTrailHeight / 2f),
cursorTrailWidth, cursorTrailHeight, cursorTrailRotation); cursorTrailWidth, cursorTrailHeight, cursorTrailRotation);
cursorTrail.endUse(); cursorTrail.endUse();
// draw the other components // draw the other components
if (newStyle && skin.isCursorRotated()) if (newStyle && skin.isCursorRotated())
cursor.setRotation(cursorAngle); cursor.setRotation(cursorAngle);
cursor.drawCentered(mouseX, mouseY, Options.isCursorOnlyColorTrail() ? Color.white : filter); cursor.drawCentered(lastPosition.x, lastPosition.y, Options.isCursorOnlyColorTrail() ? Color.white : filter);
if (hasMiddle) if (hasMiddle)
cursorMiddle.drawCentered(mouseX, mouseY, Options.isCursorOnlyColorTrail() ? Color.white : filter); cursorMiddle.drawCentered(lastPosition.x, lastPosition.y, Options.isCursorOnlyColorTrail() ? Color.white : filter);
} }
/** /**
@ -208,10 +162,10 @@ public class Cursor {
* @param mouseX x coordinate to set position to * @param mouseX x coordinate to set position to
* @param mouseY y coordinate to set position to * @param mouseY y coordinate to set position to
*/ */
public void setCursorPosition(int mouseX, int mouseY) { public void setCursorPosition(int delta, int mouseX, int mouseY) {
// TODO: use an image buffer // TODO: use an image buffer
int removeCount = 0; int removeCount = 0;
float FPSmod = Math.max(1000 / displayContainer.renderDelta, 1) / 30f; // TODO float FPSmod = Math.max(1000 / Math.max(delta, 1), 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)) {
@ -297,7 +251,7 @@ public class Cursor {
* If the old style cursor is being used, this will do nothing. * If the old style cursor is being used, this will do nothing.
* @param delta the delta interval since the last call * @param delta the delta interval since the last call
*/ */
public void update(int delta) { public void updateAngle(int delta) {
cursorAngle += delta / 40f; cursorAngle += delta / 40f;
cursorAngle %= 360; cursorAngle %= 360;
} }
@ -305,14 +259,14 @@ public class Cursor {
/** /**
* Resets all cursor data and beatmap skins. * Resets all cursor data and beatmap skins.
*/ */
public void reset() { public void reset(int mouseX, int mouseY) {
// destroy skin images // destroy skin images
GameImage.CURSOR.destroyBeatmapSkinImage(); GameImage.CURSOR.destroyBeatmapSkinImage();
GameImage.CURSOR_MIDDLE.destroyBeatmapSkinImage(); GameImage.CURSOR_MIDDLE.destroyBeatmapSkinImage();
GameImage.CURSOR_TRAIL.destroyBeatmapSkinImage(); GameImage.CURSOR_TRAIL.destroyBeatmapSkinImage();
// reset locations // reset locations
resetLocations(); resetLocations(mouseX, mouseY);
// reset angles // reset angles
cursorAngle = 0f; cursorAngle = 0f;
@ -321,14 +275,12 @@ public class Cursor {
/** /**
* Resets all cursor location data. * Resets all cursor location data.
*/ */
public void resetLocations() { public void resetLocations(int mouseX, int mouseY) {
trail.clear(); trail.clear();
if (lastPosition != null) { lastPosition = new Point(mouseX, mouseY);
for (int i = 0; i < 50; i++) { for (int i = 0; i < 50; i++) {
trail.add(new Point(lastPosition)); trail.add(new Point(lastPosition));
}
} }
lastPosition = new Point(0, 0);
} }
/** /**
@ -340,25 +292,4 @@ public class Cursor {
GameImage.CURSOR_TRAIL.hasBeatmapSkinImage()); GameImage.CURSOR_TRAIL.hasBeatmapSkinImage());
} }
/**
* Hides the cursor, if possible.
*/
public void hide() {
if (emptyCursor != null) {
/*
try {
container.setMouseCursor(emptyCursor, 0, 0);
} catch (SlickException e) {
ErrorHandler.error("Failed to hide the cursor.", e, true);
}
*/
}
}
/**
* Unhides the cursor.
*/
public void show() {
//container.setDefaultMouseCursor();
}
} }

View File

@ -28,24 +28,16 @@ import itdelatrisu.opsu.replay.ReplayImporter;
import itdelatrisu.opsu.ui.animations.AnimatedValue; import itdelatrisu.opsu.ui.animations.AnimatedValue;
import itdelatrisu.opsu.ui.animations.AnimationEquation; import itdelatrisu.opsu.ui.animations.AnimationEquation;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import org.newdawn.slick.Animation; import org.newdawn.slick.Animation;
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.Image; import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.state.StateBasedGame;
import yugecin.opsudance.core.DisplayContainer; import yugecin.opsudance.core.DisplayContainer;
/** /**
* Draws common UI components. * Draws common UI components.
*/ */
public class UI { public class UI {
/** Cursor. */
private static Cursor cursor = new Cursor();
/** Back button. */ /** Back button. */
private static MenuButton backButton; private static MenuButton backButton;
@ -86,10 +78,6 @@ public class UI {
public static void init(DisplayContainer displayContainer) { public static void init(DisplayContainer displayContainer) {
UI.displayContainer = displayContainer; UI.displayContainer = displayContainer;
// initialize cursor
Cursor.init(displayContainer);
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);
@ -108,7 +96,6 @@ public class UI {
* @param delta the delta interval since the last call. * @param delta the delta interval since the last call.
*/ */
public static void update(int delta) { public static void update(int delta) {
cursor.update(delta);
updateVolumeDisplay(delta); updateVolumeDisplay(delta);
updateBarNotification(delta); updateBarNotification(delta);
tooltipAlpha.update(-delta); tooltipAlpha.update(-delta);
@ -121,22 +108,6 @@ public class UI {
public static void draw(Graphics g) { public static void draw(Graphics g) {
drawBarNotification(g); drawBarNotification(g);
drawVolume(g); drawVolume(g);
cursor.draw();
drawTooltip(g);
}
/**
* Draws the global UI components: cursor, FPS, volume bar, tooltips, bar notifications.
* @param g the graphics context
* @param mouseX the mouse x coordinate
* @param mouseY the mouse y coordinate
* @param mousePressed whether or not the mouse button is pressed
*/
public static void draw(Graphics g, int mouseX, int mouseY, boolean mousePressed) {
drawBarNotification(g);
drawVolume(g);
cursor.draw(mouseX, mouseY, mousePressed);
drawTooltip(g);
} }
/** /**
@ -144,16 +115,10 @@ public class UI {
*/ */
public static void enter() { public static void enter() {
backButton.resetHover(); backButton.resetHover();
cursor.resetLocations();
resetBarNotification(); resetBarNotification();
resetTooltip(); resetTooltip();
} }
/**
* Returns the game cursor.
*/
public static Cursor getCursor() { return cursor; }
/** /**
* Returns the 'menu-back' MenuButton. * Returns the 'menu-back' MenuButton.
*/ */

View File

@ -25,7 +25,9 @@ import itdelatrisu.opsu.beatmap.Beatmap;
import itdelatrisu.opsu.downloads.DownloadList; import itdelatrisu.opsu.downloads.DownloadList;
import itdelatrisu.opsu.downloads.Updater; import itdelatrisu.opsu.downloads.Updater;
import itdelatrisu.opsu.render.CurveRenderState; import itdelatrisu.opsu.render.CurveRenderState;
import itdelatrisu.opsu.ui.Cursor;
import itdelatrisu.opsu.ui.Fonts; import itdelatrisu.opsu.ui.Fonts;
import itdelatrisu.opsu.ui.UI;
import org.lwjgl.Sys; import org.lwjgl.Sys;
import org.lwjgl.openal.AL; import org.lwjgl.openal.AL;
import org.lwjgl.opengl.Display; import org.lwjgl.opengl.Display;
@ -107,9 +109,14 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
private long exitconfirmation; private long exitconfirmation;
public final Cursor cursor;
public boolean drawCursor;
public DisplayContainer(InstanceContainer instanceContainer, EventBus eventBus) { public DisplayContainer(InstanceContainer instanceContainer, EventBus eventBus) {
this.instanceContainer = instanceContainer; this.instanceContainer = instanceContainer;
this.eventBus = eventBus; this.eventBus = eventBus;
this.cursor = new Cursor();
drawCursor = true;
outTransitionListener = new TransitionFinishedListener() { outTransitionListener = new TransitionFinishedListener() {
@Override @Override
@ -169,7 +176,11 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
Music.poll(delta); Music.poll(delta);
mouseX = input.getMouseX(); mouseX = input.getMouseX();
mouseY = input.getMouseY(); mouseY = input.getMouseY();
state.update(); state.update();
if (drawCursor) {
cursor.setCursorPosition(delta, mouseX, mouseY);
}
int maxRenderInterval; int maxRenderInterval;
if (Display.isVisible() && Display.isActive()) { if (Display.isVisible() && Display.isActive()) {
@ -196,6 +207,12 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
bubNotifState.render(graphics); bubNotifState.render(graphics);
barNotifState.render(graphics); barNotifState.render(graphics);
cursor.updateAngle(renderDelta);
if (drawCursor) {
cursor.draw(input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) || input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON));
}
UI.drawTooltip(graphics);
timeSinceLastRender = 0; timeSinceLastRender = 0;
Display.update(false); Display.update(false);
@ -216,6 +233,7 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
initGL(); initGL();
glVersion = GL11.glGetString(GL11.GL_VERSION); glVersion = GL11.glGetString(GL11.GL_VERSION);
glVendor = GL11.glGetString(GL11.GL_VENDOR); glVendor = GL11.glGetString(GL11.GL_VENDOR);
GLHelper.hideNativeCursor();
} }
public void teardown() { public void teardown() {
@ -318,6 +336,10 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
eventBus.post(new ResolutionChangedEvent(this.width, this.height)); eventBus.post(new ResolutionChangedEvent(this.width, this.height));
} }
public void resetCursor() {
cursor.reset(mouseX, mouseY);
}
private int getDelta() { private int getDelta() {
long time = getTime(); long time = getTime();
int delta = (int) (time - lastFrame); int delta = (int) (time - lastFrame);

View File

@ -57,8 +57,8 @@ public class OpsuDanceInjector extends Injector {
bind(ButtonMenu.class).asEagerSingleton(); bind(ButtonMenu.class).asEagerSingleton();
bind(SongMenu.class).asEagerSingleton(); bind(SongMenu.class).asEagerSingleton();
bind(DownloadsMenu.class).asEagerSingleton(); bind(DownloadsMenu.class).asEagerSingleton();
bind(GameRanking.class).asEagerSingleton();
bind(Game.class).asEagerSingleton(); bind(Game.class).asEagerSingleton();
bind(GameRanking.class).asEagerSingleton();
bind(GamePauseMenu.class).asEagerSingleton(); bind(GamePauseMenu.class).asEagerSingleton();
} }

View File

@ -17,7 +17,10 @@
*/ */
package yugecin.opsudance.utils; package yugecin.opsudance.utils;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException; import org.lwjgl.LWJGLException;
import org.lwjgl.input.Cursor;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display; import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode; import org.lwjgl.opengl.DisplayMode;
import org.newdawn.slick.opengl.ImageIOImageData; import org.newdawn.slick.opengl.ImageIOImageData;
@ -25,8 +28,10 @@ import org.newdawn.slick.opengl.LoadableImageData;
import org.newdawn.slick.opengl.TGAImageData; import org.newdawn.slick.opengl.TGAImageData;
import org.newdawn.slick.util.Log; import org.newdawn.slick.util.Log;
import org.newdawn.slick.util.ResourceLoader; import org.newdawn.slick.util.ResourceLoader;
import yugecin.opsudance.core.errorhandling.ErrorHandler;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.IntBuffer;
public class GLHelper { public class GLHelper {
@ -85,4 +90,22 @@ public class GLHelper {
Display.setIcon(bufs); Display.setIcon(bufs);
} }
public static void hideNativeCursor() {
try {
int min = Cursor.getMinCursorSize();
IntBuffer tmp = BufferUtils.createIntBuffer(min * min);
Mouse.setNativeCursor(new Cursor(min, min, min / 2, min / 2, 1, tmp, null));
} catch (LWJGLException e) {
ErrorHandler.error("Cannot hide native cursor", e).show();
}
}
public static void showNativeCursor() {
try {
Mouse.setNativeCursor(null);
} catch (LWJGLException e) {
ErrorHandler.error("Cannot show native cursor", e).show();
}
}
} }