Back and Skip animation

removed minimum time before skip button is shown.
This commit is contained in:
fd 2015-02-17 22:03:11 -05:00
parent 987a406123
commit ffed4b260a
4 changed files with 60 additions and 29 deletions

View File

@ -22,6 +22,7 @@ import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.newdawn.slick.Animation;
import org.newdawn.slick.Image; import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException; import org.newdawn.slick.SlickException;
@ -40,7 +41,7 @@ public enum GameImage {
SECTION_PASS ("section-pass", "png"), SECTION_PASS ("section-pass", "png"),
SECTION_FAIL ("section-fail", "png"), SECTION_FAIL ("section-fail", "png"),
WARNINGARROW ("play-warningarrow", "png"), WARNINGARROW ("play-warningarrow", "png"),
SKIP ("play-skip", "png"), SKIP ("play-skip", "play-skip-%d","png"),
COUNTDOWN_READY ("ready", "png") { COUNTDOWN_READY ("ready", "png") {
@Override @Override
protected Image process_sub(Image img, int w, int h) { protected Image process_sub(Image img, int w, int h) {
@ -138,7 +139,7 @@ public enum GameImage {
COMBO_BURST ("comboburst", "comboburst-%d", "png"), COMBO_BURST ("comboburst", "comboburst-%d", "png"),
SCOREBAR_BG ("scorebar-bg", "png"), SCOREBAR_BG ("scorebar-bg", "png"),
SCOREBAR_COLOUR ("scorebar-colour", "scorebar-colour-%d", "png"), SCOREBAR_COLOUR ("scorebar-colour", "scorebar-colour-%d", "png"),
//scorebar-marker? //TODO scorebar-marker?
SCOREBAR_KI ("scorebar-ki", "png"), SCOREBAR_KI ("scorebar-ki", "png"),
SCOREBAR_KI_DANGER ("scorebar-kidanger", "png"), SCOREBAR_KI_DANGER ("scorebar-kidanger", "png"),
SCOREBAR_KI_DANGER2 ("scorebar-kidanger2", "png"), SCOREBAR_KI_DANGER2 ("scorebar-kidanger2", "png"),
@ -268,8 +269,7 @@ public enum GameImage {
return img.getScaledCopy((h * 0.3f) / img.getHeight()); return img.getScaledCopy((h * 0.3f) / img.getHeight());
} }
}, },
MENU_BACK ("menu-back", "png", false, false), MENU_BACK ("menu-back", "menu-back-%d","png"),
//MENU_BACK ("menu-back", "menu-back-%d","png") //TODO menu-back animation
MENU_BUTTON_BG ("menu-button-background", "png", false, false), MENU_BUTTON_BG ("menu-button-background", "png", false, false),
MENU_TAB ("selection-tab", "png", false, false) { MENU_TAB ("selection-tab", "png", false, false) {
@Override @Override
@ -537,6 +537,17 @@ public enum GameImage {
setDefaultImage(); setDefaultImage();
return (skinImage != null) ? skinImage : defaultImage; return (skinImage != null) ? skinImage : defaultImage;
} }
/**
* Returns an Animation based on the image array.
* If no image array exist, returns the single image as an animation.
*/
public Animation getAnimation(int duration){
Image[] images = getImages();
if (images == null)
images = new Image[]{ getImage() };
return new Animation(images, duration);
}
/** /**
* Returns the image array associated with this resource. * Returns the image array associated with this resource.

View File

@ -347,20 +347,23 @@ public class MenuButton {
*/ */
private void setHoverRadius() { private void setHoverRadius() {
int xOffset = 0, yOffset = 0; int xOffset = 0, yOffset = 0;
if (dir != Expand.CENTER) { if(img != null){
// offset by difference between normal/scaled image dimensions if (dir != Expand.CENTER) {
xOffset = (int) ((scale - 1f) * img.getWidth()); // offset by difference between normal/scaled image dimensions
yOffset = (int) ((scale - 1f) * img.getHeight()); xOffset = (int) ((scale - 1f) * img.getWidth());
if (dir == Expand.UP || dir == Expand.DOWN) yOffset = (int) ((scale - 1f) * img.getHeight());
xOffset = 0; // no horizontal offset if (dir == Expand.UP || dir == Expand.DOWN)
if (dir == Expand.RIGHT || dir == Expand.LEFT) xOffset = 0; // no horizontal offset
yOffset = 0; // no vertical offset if (dir == Expand.RIGHT || dir == Expand.LEFT)
if (dir == Expand.RIGHT || dir == Expand.DOWN_RIGHT || dir == Expand.UP_RIGHT) yOffset = 0; // no vertical offset
xOffset *= -1; // flip x for right if (dir == Expand.RIGHT || dir == Expand.DOWN_RIGHT || dir == Expand.UP_RIGHT)
if (dir == Expand.DOWN || dir == Expand.DOWN_LEFT || dir == Expand.DOWN_RIGHT) xOffset *= -1; // flip x for right
yOffset *= -1; // flip y for down if (dir == Expand.DOWN || dir == Expand.DOWN_LEFT || dir == Expand.DOWN_RIGHT)
yOffset *= -1; // flip y for down
}
this.xRadius = ((img.getWidth() * scale) + xOffset) / 2f;
this.yRadius = ((img.getHeight() * scale) + yOffset) / 2f;
} }
this.xRadius = ((img.getWidth() * scale) + xOffset) / 2f;
this.yRadius = ((img.getHeight() * scale) + yOffset) / 2f;
} }
} }

View File

@ -229,11 +229,21 @@ public class Utils {
DownloadNode.init(width, height); DownloadNode.init(width, height);
// back button // back button
Image back = GameImage.MENU_BACK.getImage(); //TODO: this is annoying perhaps we can just pass in GameImage to MenuButton?
backButton = new MenuButton(back, if (GameImage.MENU_BACK.getImages() != null){
back.getWidth() / 2f, Animation back = GameImage.MENU_BACK.getAnimation(200);
height - (back.getHeight() / 2f)); backButton = new MenuButton(back,
back.getWidth() / 2f,
height - (back.getHeight() / 2f));
}else{
Image back = GameImage.MENU_BACK.getImage();
backButton = new MenuButton(GameImage.MENU_BACK.getImage(),
back.getWidth() / 2f,
height - (back.getHeight() / 2f));
}
backButton.setHoverExpand(MenuButton.Expand.UP_RIGHT); backButton.setHoverExpand(MenuButton.Expand.UP_RIGHT);
} }
/** /**

View File

@ -45,6 +45,7 @@ import java.util.Stack;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.lwjgl.input.Keyboard; import org.lwjgl.input.Keyboard;
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;
import org.newdawn.slick.Graphics; import org.newdawn.slick.Graphics;
@ -268,7 +269,6 @@ public class Game extends BasicGameState {
// skip beginning // skip beginning
if (objectIndex == 0 && if (objectIndex == 0 &&
firstObjectTime - SKIP_OFFSET > 5000 &&
trackPosition < osu.objects[0].getTime() - SKIP_OFFSET) trackPosition < osu.objects[0].getTime() - SKIP_OFFSET)
skipButton.draw(); skipButton.draw();
@ -782,7 +782,6 @@ public class Game extends BasicGameState {
int firstObjectTime = osu.objects[0].getTime(); int firstObjectTime = osu.objects[0].getTime();
int trackPosition = MusicController.getPosition(); int trackPosition = MusicController.getPosition();
if (objectIndex == 0 && if (objectIndex == 0 &&
firstObjectTime - SKIP_OFFSET > 4000 &&
trackPosition < firstObjectTime - SKIP_OFFSET) { trackPosition < firstObjectTime - SKIP_OFFSET) {
if (isLeadIn()) { if (isLeadIn()) {
leadInTime = 0; leadInTime = 0;
@ -810,12 +809,20 @@ public class Game extends BasicGameState {
} }
// skip button // skip button
Image skip = GameImage.SKIP.getImage(); //TODO: this is annoying perhaps we can just pass in GameImage to MenuButton?
skipButton = new MenuButton(skip, if (GameImage.SKIP.getImages() != null){
width - (skip.getWidth() / 2f), Animation back = GameImage.SKIP.getAnimation(200);
height - (skip.getHeight() / 2f)); skipButton = new MenuButton(back,
width - back.getWidth() / 2f,
height - (back.getHeight() / 2f));
}else{
Image back = GameImage.SKIP.getImage();
skipButton = new MenuButton(GameImage.SKIP.getImage(),
width - back.getWidth() / 2f,
height - (back.getHeight() / 2f));
}
skipButton.setHoverExpand(MenuButton.Expand.UP_LEFT); skipButton.setHoverExpand(MenuButton.Expand.UP_LEFT);
// load other images... // load other images...
((GamePauseMenu) game.getState(Opsu.STATE_GAMEPAUSEMENU)).loadImages(); ((GamePauseMenu) game.getState(Opsu.STATE_GAMEPAUSEMENU)).loadImages();
data.loadImages(); data.loadImages();