Skip to content

Commit

Permalink
Support more skin options; dropped option to use old cursor style.
Browse files Browse the repository at this point in the history
- Now supported: SliderBallFlip, CursorCentre, AnimationFramerate
- Better cursor loading (only load cursor-middle from whichever directory cursor came from).
- Assume new style cursors if cursor-middle is loaded.

Signed-off-by: Jeffrey Han <[email protected]>
  • Loading branch information
itdelatrisu committed Jan 8, 2017
1 parent cf53c3d commit 0f40ff4
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 46 deletions.
Binary file removed res/cursor2.png
Binary file not shown.
Binary file removed res/cursortrail2.png
Binary file not shown.
5 changes: 3 additions & 2 deletions src/itdelatrisu/opsu/GameData.java
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,9 @@ public void loadImages() {
comboBurstImages = new Image[]{ GameImage.COMBO_BURST.getImage() };

// scorebar-colour animation
Image[] scorebar = GameImage.SCOREBAR_COLOUR.getImages();
scorebarColour = (scorebar != null) ? new Animation(scorebar, 60) : null;
scorebarColour = null;
if (GameImage.SCOREBAR_COLOUR.getImages() != null)
scorebarColour = GameImage.SCOREBAR_COLOUR.getAnimation();

// default symbol images
defaultSymbols = new Image[10];
Expand Down
19 changes: 17 additions & 2 deletions src/itdelatrisu/opsu/GameImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ public enum GameImage {
CURSOR ("cursor", "png"),
CURSOR_MIDDLE ("cursormiddle", "png"),
CURSOR_TRAIL ("cursortrail", "png"),
CURSOR_OLD ("cursor2", "png", false, false), // custom
CURSOR_TRAIL_OLD ("cursortrail2", "png", false, false), // custom

// Game
SECTION_PASS ("section-pass", "png"),
Expand Down Expand Up @@ -565,6 +563,22 @@ public Image getImage() {
return (skinImage != null) ? skinImage : defaultImage;
}

/**
* Returns an Animation based on the image array.
* If no image array exists, returns the single image as an animation.
*/
public Animation getAnimation() {
Image[] images = getImages();
if (images == null)
images = new Image[] { getImage() };

int fps = Options.getSkin().getAnimationFramerate();
if (fps == -1)
fps = images.length;

return new Animation(images, 1000 / fps);
}

/**
* Returns an Animation based on the image array.
* If no image array exists, returns the single image as an animation.
Expand All @@ -574,6 +588,7 @@ public Animation getAnimation(int duration){
Image[] images = getImages();
if (images == null)
images = new Image[] { getImage() };

return new Animation(images, duration);
}

Expand Down
1 change: 0 additions & 1 deletion src/itdelatrisu/opsu/OptionGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public class OptionGroup {
GameOption.DISABLE_MOUSE_WHEEL,
GameOption.DISABLE_MOUSE_BUTTONS,
GameOption.CURSOR_SIZE,
GameOption.NEW_CURSOR,
GameOption.DISABLE_CURSOR
}),
new OptionGroup("Custom", new GameOption[] {
Expand Down
13 changes: 0 additions & 13 deletions src/itdelatrisu/opsu/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -479,13 +479,6 @@ public void read(String s) {
val = i;
}
},
NEW_CURSOR ("Enable New Cursor", "NewCursor", "Use the new cursor style (may cause higher CPU usage).", true) {
@Override
public void toggle(GameContainer container) {
super.toggle(container);
UI.getCursor().reset();
}
},
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),
MASTER_VOLUME ("Master Volume", "VolumeUniversal", "Global volume level.", 35, 0, 100) {
Expand Down Expand Up @@ -1039,12 +1032,6 @@ public static void setDisplayMode(Container app) {
*/
public static float getCursorScale() { return GameOption.CURSOR_SIZE.getIntegerValue() / 100f; }

/**
* Returns whether or not the new cursor type is enabled.
* @return true if enabled
*/
public static boolean isNewCursorEnabled() { return GameOption.NEW_CURSOR.getBooleanValue(); }

/**
* Returns whether or not the main menu background should be the current track image.
* @return true if enabled
Expand Down
2 changes: 2 additions & 0 deletions src/itdelatrisu/opsu/objects/Slider.java
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ public void draw(Graphics g, int trackPosition) {
// float dis = hitObject.getPixelLength() * HitObject.getXMultiplier() * (t - (int) t);
// Image sliderBallFrame = sliderBallImages[(int) (dis / (diameter * Math.PI) * 30) % sliderBallImages.length];
Image sliderBallFrame = sliderBallImages[(int) (t * sliderTime * 60 / 1000) % sliderBallImages.length];
if (currentRepeats % 2 == 1 && Options.getSkin().isSliderBallFlipped())
sliderBallFrame = sliderBallFrame.getFlippedCopy(true, false);
float angle = (float) (Math.atan2(c2.y - c.y, c2.x - c.x) * 180 / Math.PI);
sliderBallFrame.setRotation(angle);
sliderBallFrame.drawCentered(c.x, c.y);
Expand Down
2 changes: 1 addition & 1 deletion src/itdelatrisu/opsu/skins/Skin.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public Skin(File dir) {

/**
* Returns the frame rate of animations.
* @return the FPS, or {@code -1} (TODO)
* @return the FPS, or {@code -1} if not set
*/
public int getAnimationFramerate() { return animationFramerate; }

Expand Down
2 changes: 1 addition & 1 deletion src/itdelatrisu/opsu/states/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -1723,7 +1723,7 @@ private void loadImages() {

// skip button
if (GameImage.SKIP.getImages() != null) {
Animation skip = GameImage.SKIP.getAnimation(120);
Animation skip = GameImage.SKIP.getAnimation();
skipButton = new MenuButton(skip, width - skip.getWidth() / 2f, height - (skip.getHeight() / 2f));
} else {
Image skip = GameImage.SKIP.getImage();
Expand Down
56 changes: 31 additions & 25 deletions src/itdelatrisu/opsu/ui/Cursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,24 +118,19 @@ public void draw(int mouseX, int mouseY, boolean mousePressed) {
if (Options.isCursorDisabled())
return;

// determine correct cursor image
Image cursor = null, cursorMiddle = null, cursorTrail = null;
boolean beatmapSkinned = GameImage.CURSOR.hasBeatmapSkinImage();
boolean newStyle, hasMiddle;
Skin skin = Options.getSkin();
if (beatmapSkinned) {
newStyle = true; // osu! currently treats all beatmap cursors as new-style cursors
hasMiddle = GameImage.CURSOR_MIDDLE.hasBeatmapSkinImage();

// determine correct cursor image
Image cursor = GameImage.CURSOR.getImage();
Image cursorTrail = GameImage.CURSOR_TRAIL.getImage();
Image cursorMiddle = null;
if (GameImage.CURSOR.hasBeatmapSkinImage()) {
if (GameImage.CURSOR_MIDDLE.hasBeatmapSkinImage())
cursorMiddle = GameImage.CURSOR_MIDDLE.getImage();
} else if (GameImage.CURSOR.hasGameSkinImage()) {
if (GameImage.CURSOR_MIDDLE.hasGameSkinImage())
cursorMiddle = GameImage.CURSOR_MIDDLE.getImage();
} else
newStyle = hasMiddle = Options.isNewCursorEnabled();
if (newStyle || beatmapSkinned) {
cursor = GameImage.CURSOR.getImage();
cursorTrail = GameImage.CURSOR_TRAIL.getImage();
} else {
cursor = GameImage.CURSOR.hasGameSkinImage() ? GameImage.CURSOR.getImage() : GameImage.CURSOR_OLD.getImage();
cursorTrail = GameImage.CURSOR_TRAIL.hasGameSkinImage() ? GameImage.CURSOR_TRAIL.getImage() : GameImage.CURSOR_TRAIL_OLD.getImage();
}
if (hasMiddle)
cursorMiddle = GameImage.CURSOR_MIDDLE.getImage();

// scale cursor
Expand All @@ -159,7 +154,7 @@ public void draw(int mouseX, int mouseY, boolean mousePressed) {
// TODO: use an image buffer
int removeCount = 0;
float FPSmod = Math.max(container.getFPS(), 1) / 60f;
if (newStyle) {
if (cursorMiddle != null) {
// new style: add all points between cursor movements
if (lastPosition == null) {
lastPosition = new Point(mouseX, mouseY);
Expand Down Expand Up @@ -187,25 +182,36 @@ public void draw(int mouseX, int mouseY, boolean mousePressed) {
float t = 2f / trail.size();
int cursorTrailWidth = cursorTrail.getWidth(), cursorTrailHeight = cursorTrail.getHeight();
float cursorTrailRotation = (skin.isCursorTrailRotated()) ? cursorAngle : 0;
float offsetX = -cursorTrailWidth / 2f, offsetY = -cursorTrailHeight / 2f;
if (!skin.isCursorCentered())
offsetX = offsetY = 0f;
cursorTrail.startUse();
for (Point p : trail) {
alpha += t;
cursorTrail.setImageColor(1f, 1f, 1f, alpha);
cursorTrail.drawEmbedded(
p.x - (cursorTrailWidth / 2f), p.y - (cursorTrailHeight / 2f),
cursorTrailWidth, cursorTrailHeight, cursorTrailRotation);
p.x + offsetX, p.y + offsetY,
cursorTrailWidth, cursorTrailHeight, cursorTrailRotation
);
}
cursorTrail.drawEmbedded(
mouseX - (cursorTrailWidth / 2f), mouseY - (cursorTrailHeight / 2f),
cursorTrailWidth, cursorTrailHeight, cursorTrailRotation);
mouseX + offsetX, mouseY + offsetY,
cursorTrailWidth, cursorTrailHeight, cursorTrailRotation
);
cursorTrail.endUse();

// draw the other components
if (newStyle && skin.isCursorRotated())
if (skin.isCursorRotated())
cursor.setRotation(cursorAngle);
cursor.drawCentered(mouseX, mouseY);
if (hasMiddle)
cursorMiddle.drawCentered(mouseX, mouseY);
if (skin.isCursorCentered()) {
cursor.drawCentered(mouseX, mouseY);
if (cursorMiddle != null)
cursorMiddle.drawCentered(mouseX, mouseY);
} else {
cursor.draw(mouseX, mouseY);
if (cursorMiddle != null)
cursorMiddle.drawCentered(mouseX + cursor.getWidth() / 2, mouseY + cursor.getHeight() / 2);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/itdelatrisu/opsu/ui/UI.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static void init(GameContainer container, StateBasedGame game) {

// back button
if (GameImage.MENU_BACK.getImages() != null) {
Animation back = GameImage.MENU_BACK.getAnimation(120);
Animation back = GameImage.MENU_BACK.getAnimation();
backButton = new MenuButton(back, back.getWidth() / 2f, container.getHeight() - (back.getHeight() / 2f));
} else {
Image back = GameImage.MENU_BACK.getImage();
Expand Down

0 comments on commit 0f40ff4

Please sign in to comment.