Show the default mouse cursor during replays.
Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
parent
f6412f06e8
commit
fa6132808e
|
@ -20,12 +20,16 @@ package itdelatrisu.opsu;
|
||||||
|
|
||||||
import itdelatrisu.opsu.audio.SoundController;
|
import itdelatrisu.opsu.audio.SoundController;
|
||||||
|
|
||||||
|
import java.nio.IntBuffer;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
|
|
||||||
|
import org.lwjgl.BufferUtils;
|
||||||
|
import org.lwjgl.LWJGLException;
|
||||||
|
import org.lwjgl.input.Cursor;
|
||||||
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.GameContainer;
|
||||||
|
@ -42,6 +46,9 @@ public class UI {
|
||||||
/** Back button. */
|
/** Back button. */
|
||||||
private static MenuButton backButton;
|
private static MenuButton backButton;
|
||||||
|
|
||||||
|
/** Empty cursor. */
|
||||||
|
private static Cursor emptyCursor;
|
||||||
|
|
||||||
/** Last cursor coordinates. */
|
/** Last cursor coordinates. */
|
||||||
private static int lastX = -1, lastY = -1;
|
private static int lastX = -1, lastY = -1;
|
||||||
|
|
||||||
|
@ -88,6 +95,16 @@ public class UI {
|
||||||
UI.game = game;
|
UI.game = game;
|
||||||
UI.input = container.getInput();
|
UI.input = container.getInput();
|
||||||
|
|
||||||
|
// hide native cursor
|
||||||
|
try {
|
||||||
|
int min = Cursor.getMinCursorSize();
|
||||||
|
IntBuffer tmp = BufferUtils.createIntBuffer(min * min);
|
||||||
|
emptyCursor = new Cursor(min, min, min/2, min/2, 1, tmp, null);
|
||||||
|
hideCursor();
|
||||||
|
} catch (LWJGLException e) {
|
||||||
|
ErrorHandler.error("Failed to create hidden cursor.", e, true);
|
||||||
|
}
|
||||||
|
|
||||||
// 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);
|
||||||
|
@ -343,6 +360,26 @@ public class UI {
|
||||||
GameImage.CURSOR.getImage().setRotation(0f);
|
GameImage.CURSOR.getImage().setRotation(0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hides the cursor, if possible.
|
||||||
|
*/
|
||||||
|
public static void hideCursor() {
|
||||||
|
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 static void showCursor() {
|
||||||
|
container.setDefaultMouseCursor();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws the FPS at the bottom-right corner of the game container.
|
* Draws the FPS at the bottom-right corner of the game container.
|
||||||
* If the option is not activated, this will do nothing.
|
* If the option is not activated, this will do nothing.
|
||||||
|
|
|
@ -34,7 +34,6 @@ import java.net.HttpURLConnection;
|
||||||
import java.net.SocketTimeoutException;
|
import java.net.SocketTimeoutException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.IntBuffer;
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -46,8 +45,6 @@ import java.util.Scanner;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
import org.lwjgl.BufferUtils;
|
import org.lwjgl.BufferUtils;
|
||||||
import org.lwjgl.LWJGLException;
|
|
||||||
import org.lwjgl.input.Cursor;
|
|
||||||
import org.lwjgl.opengl.Display;
|
import org.lwjgl.opengl.Display;
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
import org.newdawn.slick.Animation;
|
import org.newdawn.slick.Animation;
|
||||||
|
@ -131,6 +128,8 @@ public class Utils {
|
||||||
public static void init(GameContainer container, StateBasedGame game)
|
public static void init(GameContainer container, StateBasedGame game)
|
||||||
throws SlickException {
|
throws SlickException {
|
||||||
input = container.getInput();
|
input = container.getInput();
|
||||||
|
int width = container.getWidth();
|
||||||
|
int height = container.getHeight();
|
||||||
|
|
||||||
// game settings
|
// game settings
|
||||||
container.setTargetFrameRate(Options.getTargetFPS());
|
container.setTargetFrameRate(Options.getTargetFPS());
|
||||||
|
@ -141,20 +140,6 @@ public class Utils {
|
||||||
container.setAlwaysRender(true);
|
container.setAlwaysRender(true);
|
||||||
container.setUpdateOnlyWhenVisible(false);
|
container.setUpdateOnlyWhenVisible(false);
|
||||||
|
|
||||||
int width = container.getWidth();
|
|
||||||
int height = container.getHeight();
|
|
||||||
|
|
||||||
// set the cursor
|
|
||||||
try {
|
|
||||||
// hide the native cursor
|
|
||||||
int min = Cursor.getMinCursorSize();
|
|
||||||
IntBuffer tmp = BufferUtils.createIntBuffer(min * min);
|
|
||||||
Cursor emptyCursor = new Cursor(min, min, min/2, min/2, 1, tmp, null);
|
|
||||||
container.setMouseCursor(emptyCursor, 0, 0);
|
|
||||||
} catch (LWJGLException e) {
|
|
||||||
ErrorHandler.error("Failed to set the cursor.", e, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// create fonts
|
// create fonts
|
||||||
float fontBase;
|
float fontBase;
|
||||||
if (height <= 600)
|
if (height <= 600)
|
||||||
|
|
|
@ -696,8 +696,12 @@ public class Game extends BasicGameState {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// watching replay
|
// watching replay
|
||||||
if (replay != null)
|
if (replay != null) {
|
||||||
|
// only allow skip button
|
||||||
|
if (button != Input.MOUSE_MIDDLE_BUTTON && skipButton.contains(x, y))
|
||||||
|
skipIntro();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// mouse wheel: pause the game
|
// mouse wheel: pause the game
|
||||||
if (button == Input.MOUSE_MIDDLE_BUTTON && !Options.isMouseWheelDisabled()) {
|
if (button == Input.MOUSE_MIDDLE_BUTTON && !Options.isMouseWheelDisabled()) {
|
||||||
|
@ -834,6 +838,9 @@ public class Game extends BasicGameState {
|
||||||
|
|
||||||
// load replay frames
|
// load replay frames
|
||||||
if (replay != null) {
|
if (replay != null) {
|
||||||
|
// unhide cursor
|
||||||
|
UI.showCursor();
|
||||||
|
|
||||||
// load mods
|
// load mods
|
||||||
previousMods = GameMod.getModState();
|
previousMods = GameMod.getModState();
|
||||||
GameMod.loadModState(replay.mods);
|
GameMod.loadModState(replay.mods);
|
||||||
|
@ -869,9 +876,11 @@ public class Game extends BasicGameState {
|
||||||
throws SlickException {
|
throws SlickException {
|
||||||
// container.setMouseGrabbed(false);
|
// container.setMouseGrabbed(false);
|
||||||
|
|
||||||
// reset previous mod state
|
// reset previous mod state and re-hide cursor
|
||||||
if (replay != null)
|
if (replay != null) {
|
||||||
GameMod.loadModState(previousMods);
|
GameMod.loadModState(previousMods);
|
||||||
|
UI.hideCursor();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -41,7 +41,6 @@ import itdelatrisu.opsu.audio.SoundController;
|
||||||
import itdelatrisu.opsu.audio.SoundEffect;
|
import itdelatrisu.opsu.audio.SoundEffect;
|
||||||
import itdelatrisu.opsu.db.OsuDB;
|
import itdelatrisu.opsu.db.OsuDB;
|
||||||
import itdelatrisu.opsu.db.ScoreDB;
|
import itdelatrisu.opsu.db.ScoreDB;
|
||||||
import itdelatrisu.opsu.replay.Replay;
|
|
||||||
import itdelatrisu.opsu.states.ButtonMenu.MenuState;
|
import itdelatrisu.opsu.states.ButtonMenu.MenuState;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user