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 java.nio.IntBuffer;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
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.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
|
@ -42,6 +46,9 @@ public class UI {
|
|||
/** Back button. */
|
||||
private static MenuButton backButton;
|
||||
|
||||
/** Empty cursor. */
|
||||
private static Cursor emptyCursor;
|
||||
|
||||
/** Last cursor coordinates. */
|
||||
private static int lastX = -1, lastY = -1;
|
||||
|
||||
|
@ -88,6 +95,16 @@ public class UI {
|
|||
UI.game = game;
|
||||
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
|
||||
if (GameImage.MENU_BACK.getImages() != null) {
|
||||
Animation back = GameImage.MENU_BACK.getAnimation(120);
|
||||
|
@ -343,6 +360,26 @@ public class UI {
|
|||
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.
|
||||
* 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.URL;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
@ -46,8 +45,6 @@ import java.util.Scanner;
|
|||
import javax.imageio.ImageIO;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.LWJGLException;
|
||||
import org.lwjgl.input.Cursor;
|
||||
import org.lwjgl.opengl.Display;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.newdawn.slick.Animation;
|
||||
|
@ -131,6 +128,8 @@ public class Utils {
|
|||
public static void init(GameContainer container, StateBasedGame game)
|
||||
throws SlickException {
|
||||
input = container.getInput();
|
||||
int width = container.getWidth();
|
||||
int height = container.getHeight();
|
||||
|
||||
// game settings
|
||||
container.setTargetFrameRate(Options.getTargetFPS());
|
||||
|
@ -141,20 +140,6 @@ public class Utils {
|
|||
container.setAlwaysRender(true);
|
||||
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
|
||||
float fontBase;
|
||||
if (height <= 600)
|
||||
|
|
|
@ -696,8 +696,12 @@ public class Game extends BasicGameState {
|
|||
return;
|
||||
|
||||
// watching replay
|
||||
if (replay != null)
|
||||
if (replay != null) {
|
||||
// only allow skip button
|
||||
if (button != Input.MOUSE_MIDDLE_BUTTON && skipButton.contains(x, y))
|
||||
skipIntro();
|
||||
return;
|
||||
}
|
||||
|
||||
// mouse wheel: pause the game
|
||||
if (button == Input.MOUSE_MIDDLE_BUTTON && !Options.isMouseWheelDisabled()) {
|
||||
|
@ -834,6 +838,9 @@ public class Game extends BasicGameState {
|
|||
|
||||
// load replay frames
|
||||
if (replay != null) {
|
||||
// unhide cursor
|
||||
UI.showCursor();
|
||||
|
||||
// load mods
|
||||
previousMods = GameMod.getModState();
|
||||
GameMod.loadModState(replay.mods);
|
||||
|
@ -869,9 +876,11 @@ public class Game extends BasicGameState {
|
|||
throws SlickException {
|
||||
// container.setMouseGrabbed(false);
|
||||
|
||||
// reset previous mod state
|
||||
if (replay != null)
|
||||
// reset previous mod state and re-hide cursor
|
||||
if (replay != null) {
|
||||
GameMod.loadModState(previousMods);
|
||||
UI.hideCursor();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -41,7 +41,6 @@ import itdelatrisu.opsu.audio.SoundController;
|
|||
import itdelatrisu.opsu.audio.SoundEffect;
|
||||
import itdelatrisu.opsu.db.OsuDB;
|
||||
import itdelatrisu.opsu.db.ScoreDB;
|
||||
import itdelatrisu.opsu.replay.Replay;
|
||||
import itdelatrisu.opsu.states.ButtonMenu.MenuState;
|
||||
|
||||
import java.io.File;
|
||||
|
|
Loading…
Reference in New Issue
Block a user