enable cursor
This commit is contained in:
parent
95a466f92f
commit
978a41116c
|
@ -467,12 +467,7 @@ public class Options {
|
|||
val = i;
|
||||
}
|
||||
},
|
||||
NEW_CURSOR ("Enable New Cursor", "NewCursor", "Use the new cursor style (may cause higher CPU usage).", true) {
|
||||
@Override
|
||||
public void click() {
|
||||
UI.getCursor().reset();
|
||||
}
|
||||
},
|
||||
NEW_CURSOR ("Enable New Cursor", "NewCursor", "Use the new cursor style (may cause higher CPU usage).", 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),
|
||||
COLOR_MAIN_MENU_LOGO ("Use cursor color as main menu logo tint", "ColorMainMenuLogo", "Colorful main menu logo", false),
|
||||
|
|
|
@ -73,6 +73,7 @@ import yugecin.opsudance.objects.curves.FakeCombinedCurve;
|
|||
import yugecin.opsudance.sbv2.MoveStoryboard;
|
||||
import yugecin.opsudance.ui.OptionsOverlay;
|
||||
import yugecin.opsudance.ui.StoryboardOverlay;
|
||||
import yugecin.opsudance.utils.GLHelper;
|
||||
|
||||
/**
|
||||
* "Game" state.
|
||||
|
@ -449,38 +450,6 @@ public class Game extends ComplexOpsuState {
|
|||
if (GameMod.FLASHLIGHT.isActive())
|
||||
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
|
||||
if (GameMod.FLASHLIGHT.isActive()) {
|
||||
// render hit objects offscreen
|
||||
|
@ -748,22 +717,18 @@ public class Game extends ComplexOpsuState {
|
|||
cursorCirclePulse.drawCentered(pausedMousePosition.x, pausedMousePosition.y);
|
||||
}
|
||||
|
||||
if (isReplay)
|
||||
UI.draw(g, replayX, replayY, replayKeyPressed);
|
||||
else if (GameMod.AUTO.isActive()) {
|
||||
UI.draw(g, (int) autoMousePosition.x, (int) autoMousePosition.y, autoMousePressed);
|
||||
if (isReplay) {
|
||||
displayContainer.cursor.draw(replayKeyPressed);
|
||||
} else if (GameMod.AUTO.isActive()) {
|
||||
displayContainer.cursor.draw(autoMousePressed);
|
||||
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.draw((int) (Math.cos(a) * d + Options.width / 2), (int) (Math.sin(a) * d + Options.height / 2), autoMousePressed);
|
||||
mirrorCursor.draw(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());
|
||||
else
|
||||
UI.draw(g);
|
||||
|
||||
UI.draw(g);
|
||||
|
||||
if (!Options.isHideWM()) {
|
||||
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.
|
||||
* @param mouseX the mouse x coordinate
|
||||
|
@ -1078,11 +1095,6 @@ public class Game extends ComplexOpsuState {
|
|||
boolean overlap = (objectIndex + 1 < gameObjects.length &&
|
||||
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
|
||||
if (gameObjects[objectIndex].update(overlap, delta, mouseX, mouseY, keyPressed, trackPosition)) {
|
||||
skippedObject = true;
|
||||
|
@ -1210,7 +1222,7 @@ public class Game extends ComplexOpsuState {
|
|||
mirrorTo = objectIndex;
|
||||
Options.setMirror(false);
|
||||
} else {
|
||||
mirrorCursor.resetLocations();
|
||||
mirrorCursor.resetLocations((int) autoMousePosition.x, (int) autoMousePosition.y);
|
||||
mirrorFrom = objectIndex;
|
||||
mirrorTo = gameObjects.length;
|
||||
Options.setMirror(true);
|
||||
|
@ -1221,7 +1233,7 @@ public class Game extends ComplexOpsuState {
|
|||
mirrorTo = objectIndex;
|
||||
Options.setMirror(false);
|
||||
} else {
|
||||
mirrorCursor.resetLocations();
|
||||
mirrorCursor.resetLocations((int) autoMousePosition.x, (int) autoMousePosition.y);
|
||||
mirrorFrom = objectIndex;
|
||||
mirrorTo = mirrorFrom + 1;
|
||||
Options.setMirror(true);
|
||||
|
@ -1435,6 +1447,8 @@ public class Game extends ComplexOpsuState {
|
|||
public void enter() {
|
||||
super.enter();
|
||||
|
||||
displayContainer.drawCursor = false;
|
||||
|
||||
overlays.clear();
|
||||
if (Options.isEnableSB()) {
|
||||
overlays.add(optionsOverlay);
|
||||
|
@ -1572,8 +1586,9 @@ public class Game extends ComplexOpsuState {
|
|||
}
|
||||
|
||||
// unhide cursor for "auto" mod and replays
|
||||
if (GameMod.AUTO.isActive() || isReplay)
|
||||
UI.getCursor().show();
|
||||
if (GameMod.AUTO.isActive() || isReplay) {
|
||||
GLHelper.showNativeCursor();
|
||||
}
|
||||
|
||||
// load replay frames
|
||||
if (isReplay) {
|
||||
|
@ -1683,6 +1698,8 @@ public class Game extends ComplexOpsuState {
|
|||
public void leave() {
|
||||
super.leave();
|
||||
|
||||
displayContainer.drawCursor = true;
|
||||
|
||||
MusicController.pause();
|
||||
MusicController.setPitch(1f);
|
||||
MusicController.resume();
|
||||
|
@ -1705,8 +1722,9 @@ public class Game extends ComplexOpsuState {
|
|||
Cursor.nextMirroredObjColor = Color.white;
|
||||
|
||||
// re-hide cursor
|
||||
if (GameMod.AUTO.isActive() || isReplay)
|
||||
UI.getCursor().hide();
|
||||
if (GameMod.AUTO.isActive() || isReplay) {
|
||||
GLHelper.hideNativeCursor();
|
||||
}
|
||||
|
||||
// replays
|
||||
if (isReplay)
|
||||
|
|
|
@ -110,9 +110,6 @@ public class GamePauseMenu extends BaseOpsuState {
|
|||
SoundController.playSound(SoundEffect.MENUBACK);
|
||||
instanceContainer.provide(SongMenu.class).resetGameDataOnLoad();
|
||||
MusicController.playAt(MusicController.getBeatmap().previewTime, true);
|
||||
if (UI.getCursor().isBeatmapSkinned()) {
|
||||
UI.getCursor().reset();
|
||||
}
|
||||
displayContainer.switchState(SongMenu.class);
|
||||
} else {
|
||||
SoundController.playSound(SoundEffect.MENUBACK);
|
||||
|
@ -157,8 +154,9 @@ public class GamePauseMenu extends BaseOpsuState {
|
|||
MusicController.playAt(MusicController.getBeatmap().previewTime, true);
|
||||
else
|
||||
MusicController.resume();
|
||||
if (UI.getCursor().isBeatmapSkinned())
|
||||
UI.getCursor().reset();
|
||||
if (displayContainer.cursor.isBeatmapSkinned()) {
|
||||
displayContainer.resetCursor();
|
||||
}
|
||||
MusicController.setPitch(1.0f);
|
||||
displayContainer.switchState(SongMenu.class);
|
||||
}
|
||||
|
|
|
@ -63,6 +63,7 @@ public class GameRanking extends BaseOpsuState {
|
|||
public GameRanking(DisplayContainer displayContainer, InstanceContainer instanceContainer) {
|
||||
super(displayContainer);
|
||||
this.instanceContainer = instanceContainer;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -242,8 +243,8 @@ public class GameRanking extends BaseOpsuState {
|
|||
songMenu.resetTrackOnLoad();
|
||||
}
|
||||
songMenu.resetGameDataOnLoad();
|
||||
if (UI.getCursor().isBeatmapSkinned()) {
|
||||
UI.getCursor().reset();
|
||||
if (displayContainer.cursor.isBeatmapSkinned()) {
|
||||
displayContainer.resetCursor();
|
||||
}
|
||||
displayContainer.switchState(SongMenu.class);
|
||||
}
|
||||
|
|
|
@ -21,28 +21,19 @@ package itdelatrisu.opsu.ui;
|
|||
import itdelatrisu.opsu.GameImage;
|
||||
import itdelatrisu.opsu.Options;
|
||||
import itdelatrisu.opsu.Utils;
|
||||
import itdelatrisu.opsu.audio.MusicController;
|
||||
import itdelatrisu.opsu.skins.Skin;
|
||||
import itdelatrisu.opsu.ui.animations.AnimationEquation;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.LWJGLException;
|
||||
import org.newdawn.slick.*;
|
||||
import org.newdawn.slick.state.StateBasedGame;
|
||||
import yugecin.opsudance.Dancer;
|
||||
import yugecin.opsudance.core.DisplayContainer;
|
||||
import yugecin.opsudance.core.errorhandling.ErrorHandler;
|
||||
|
||||
/**
|
||||
* Updates and draws the cursor.
|
||||
*/
|
||||
public class Cursor {
|
||||
/** Empty cursor. */
|
||||
private static org.lwjgl.input.Cursor emptyCursor;
|
||||
|
||||
/** Last cursor coordinates. */
|
||||
private Point lastPosition;
|
||||
|
@ -63,13 +54,10 @@ public class Cursor {
|
|||
private static final float CURSOR_SCALE_TIME = 125;
|
||||
|
||||
/** 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;
|
||||
|
||||
// game-related variables
|
||||
private static DisplayContainer displayContainer;
|
||||
|
||||
public static Color lastObjColor = Color.white;
|
||||
public static Color lastMirroredObjColor = Color.white;
|
||||
public static Color nextObjColor = Color.white;
|
||||
|
@ -78,22 +66,6 @@ public class Cursor {
|
|||
|
||||
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.
|
||||
*/
|
||||
|
@ -102,31 +74,15 @@ public class Cursor {
|
|||
}
|
||||
|
||||
public Cursor(boolean isMirrored) {
|
||||
resetLocations();
|
||||
resetLocations(0, 0);
|
||||
this.isMirrored = isMirrored;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public void draw(int mouseX, int mouseY, boolean mousePressed) {
|
||||
public void draw(boolean mousePressed) {
|
||||
if (Options.isCursorDisabled())
|
||||
return;
|
||||
|
||||
|
@ -168,8 +124,6 @@ public class Cursor {
|
|||
cursorTrail = cursorTrail.getScaledCopy(cursorScale);
|
||||
}
|
||||
|
||||
setCursorPosition(mouseX, mouseY);
|
||||
|
||||
Color filter;
|
||||
if (isMirrored) {
|
||||
filter = Dancer.cursorColorMirrorOverride.getMirrorColor();
|
||||
|
@ -191,16 +145,16 @@ public class Cursor {
|
|||
cursorTrailWidth, cursorTrailHeight, cursorTrailRotation);
|
||||
}
|
||||
cursorTrail.drawEmbedded(
|
||||
mouseX - (cursorTrailWidth / 2f), mouseY - (cursorTrailHeight / 2f),
|
||||
lastPosition.x - (cursorTrailWidth / 2f), lastPosition.y - (cursorTrailHeight / 2f),
|
||||
cursorTrailWidth, cursorTrailHeight, cursorTrailRotation);
|
||||
cursorTrail.endUse();
|
||||
|
||||
// draw the other components
|
||||
if (newStyle && skin.isCursorRotated())
|
||||
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)
|
||||
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 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
|
||||
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) {
|
||||
// new style: add all points between cursor movements
|
||||
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.
|
||||
* @param delta the delta interval since the last call
|
||||
*/
|
||||
public void update(int delta) {
|
||||
public void updateAngle(int delta) {
|
||||
cursorAngle += delta / 40f;
|
||||
cursorAngle %= 360;
|
||||
}
|
||||
|
@ -305,14 +259,14 @@ public class Cursor {
|
|||
/**
|
||||
* Resets all cursor data and beatmap skins.
|
||||
*/
|
||||
public void reset() {
|
||||
public void reset(int mouseX, int mouseY) {
|
||||
// destroy skin images
|
||||
GameImage.CURSOR.destroyBeatmapSkinImage();
|
||||
GameImage.CURSOR_MIDDLE.destroyBeatmapSkinImage();
|
||||
GameImage.CURSOR_TRAIL.destroyBeatmapSkinImage();
|
||||
|
||||
// reset locations
|
||||
resetLocations();
|
||||
resetLocations(mouseX, mouseY);
|
||||
|
||||
// reset angles
|
||||
cursorAngle = 0f;
|
||||
|
@ -321,14 +275,12 @@ public class Cursor {
|
|||
/**
|
||||
* Resets all cursor location data.
|
||||
*/
|
||||
public void resetLocations() {
|
||||
public void resetLocations(int mouseX, int mouseY) {
|
||||
trail.clear();
|
||||
if (lastPosition != null) {
|
||||
for (int i = 0; i < 50; i++) {
|
||||
trail.add(new Point(lastPosition));
|
||||
}
|
||||
lastPosition = new Point(mouseX, mouseY);
|
||||
for (int i = 0; i < 50; i++) {
|
||||
trail.add(new Point(lastPosition));
|
||||
}
|
||||
lastPosition = new Point(0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -340,25 +292,4 @@ public class Cursor {
|
|||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,24 +28,16 @@ import itdelatrisu.opsu.replay.ReplayImporter;
|
|||
import itdelatrisu.opsu.ui.animations.AnimatedValue;
|
||||
import itdelatrisu.opsu.ui.animations.AnimationEquation;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
import org.newdawn.slick.Animation;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Image;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.state.StateBasedGame;
|
||||
import yugecin.opsudance.core.DisplayContainer;
|
||||
|
||||
/**
|
||||
* Draws common UI components.
|
||||
*/
|
||||
public class UI {
|
||||
/** Cursor. */
|
||||
private static Cursor cursor = new Cursor();
|
||||
|
||||
/** Back button. */
|
||||
private static MenuButton backButton;
|
||||
|
@ -86,10 +78,6 @@ public class UI {
|
|||
public static void init(DisplayContainer displayContainer) {
|
||||
UI.displayContainer = displayContainer;
|
||||
|
||||
// initialize cursor
|
||||
Cursor.init(displayContainer);
|
||||
cursor.hide();
|
||||
|
||||
// back button
|
||||
if (GameImage.MENU_BACK.getImages() != null) {
|
||||
Animation back = GameImage.MENU_BACK.getAnimation(120);
|
||||
|
@ -108,7 +96,6 @@ public class UI {
|
|||
* @param delta the delta interval since the last call.
|
||||
*/
|
||||
public static void update(int delta) {
|
||||
cursor.update(delta);
|
||||
updateVolumeDisplay(delta);
|
||||
updateBarNotification(delta);
|
||||
tooltipAlpha.update(-delta);
|
||||
|
@ -121,22 +108,6 @@ public class UI {
|
|||
public static void draw(Graphics g) {
|
||||
drawBarNotification(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() {
|
||||
backButton.resetHover();
|
||||
cursor.resetLocations();
|
||||
resetBarNotification();
|
||||
resetTooltip();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the game cursor.
|
||||
*/
|
||||
public static Cursor getCursor() { return cursor; }
|
||||
|
||||
/**
|
||||
* Returns the 'menu-back' MenuButton.
|
||||
*/
|
||||
|
|
|
@ -25,7 +25,9 @@ import itdelatrisu.opsu.beatmap.Beatmap;
|
|||
import itdelatrisu.opsu.downloads.DownloadList;
|
||||
import itdelatrisu.opsu.downloads.Updater;
|
||||
import itdelatrisu.opsu.render.CurveRenderState;
|
||||
import itdelatrisu.opsu.ui.Cursor;
|
||||
import itdelatrisu.opsu.ui.Fonts;
|
||||
import itdelatrisu.opsu.ui.UI;
|
||||
import org.lwjgl.Sys;
|
||||
import org.lwjgl.openal.AL;
|
||||
import org.lwjgl.opengl.Display;
|
||||
|
@ -107,9 +109,14 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
|
|||
|
||||
private long exitconfirmation;
|
||||
|
||||
public final Cursor cursor;
|
||||
public boolean drawCursor;
|
||||
|
||||
public DisplayContainer(InstanceContainer instanceContainer, EventBus eventBus) {
|
||||
this.instanceContainer = instanceContainer;
|
||||
this.eventBus = eventBus;
|
||||
this.cursor = new Cursor();
|
||||
drawCursor = true;
|
||||
|
||||
outTransitionListener = new TransitionFinishedListener() {
|
||||
@Override
|
||||
|
@ -169,7 +176,11 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
|
|||
Music.poll(delta);
|
||||
mouseX = input.getMouseX();
|
||||
mouseY = input.getMouseY();
|
||||
|
||||
state.update();
|
||||
if (drawCursor) {
|
||||
cursor.setCursorPosition(delta, mouseX, mouseY);
|
||||
}
|
||||
|
||||
int maxRenderInterval;
|
||||
if (Display.isVisible() && Display.isActive()) {
|
||||
|
@ -196,6 +207,12 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
|
|||
bubNotifState.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;
|
||||
|
||||
Display.update(false);
|
||||
|
@ -216,6 +233,7 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
|
|||
initGL();
|
||||
glVersion = GL11.glGetString(GL11.GL_VERSION);
|
||||
glVendor = GL11.glGetString(GL11.GL_VENDOR);
|
||||
GLHelper.hideNativeCursor();
|
||||
}
|
||||
|
||||
public void teardown() {
|
||||
|
@ -318,6 +336,10 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
|
|||
eventBus.post(new ResolutionChangedEvent(this.width, this.height));
|
||||
}
|
||||
|
||||
public void resetCursor() {
|
||||
cursor.reset(mouseX, mouseY);
|
||||
}
|
||||
|
||||
private int getDelta() {
|
||||
long time = getTime();
|
||||
int delta = (int) (time - lastFrame);
|
||||
|
|
|
@ -57,8 +57,8 @@ public class OpsuDanceInjector extends Injector {
|
|||
bind(ButtonMenu.class).asEagerSingleton();
|
||||
bind(SongMenu.class).asEagerSingleton();
|
||||
bind(DownloadsMenu.class).asEagerSingleton();
|
||||
bind(GameRanking.class).asEagerSingleton();
|
||||
bind(Game.class).asEagerSingleton();
|
||||
bind(GameRanking.class).asEagerSingleton();
|
||||
bind(GamePauseMenu.class).asEagerSingleton();
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,10 @@
|
|||
*/
|
||||
package yugecin.opsudance.utils;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.LWJGLException;
|
||||
import org.lwjgl.input.Cursor;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.Display;
|
||||
import org.lwjgl.opengl.DisplayMode;
|
||||
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.util.Log;
|
||||
import org.newdawn.slick.util.ResourceLoader;
|
||||
import yugecin.opsudance.core.errorhandling.ErrorHandler;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
public class GLHelper {
|
||||
|
||||
|
@ -85,4 +90,22 @@ public class GLHelper {
|
|||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user