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
@ -538,6 +538,17 @@ public enum GameImage {
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.
* The skin images takes priority over the default images. * The skin images takes priority over the default images.

View File

@ -347,6 +347,7 @@ public class MenuButton {
*/ */
private void setHoverRadius() { private void setHoverRadius() {
int xOffset = 0, yOffset = 0; int xOffset = 0, yOffset = 0;
if(img != null){
if (dir != Expand.CENTER) { if (dir != Expand.CENTER) {
// offset by difference between normal/scaled image dimensions // offset by difference between normal/scaled image dimensions
xOffset = (int) ((scale - 1f) * img.getWidth()); xOffset = (int) ((scale - 1f) * img.getWidth());
@ -362,5 +363,7 @@ public class MenuButton {
} }
this.xRadius = ((img.getWidth() * scale) + xOffset) / 2f; this.xRadius = ((img.getWidth() * scale) + xOffset) / 2f;
this.yRadius = ((img.getHeight() * scale) + yOffset) / 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?
if (GameImage.MENU_BACK.getImages() != null){
Animation back = GameImage.MENU_BACK.getAnimation(200);
backButton = new MenuButton(back, backButton = new MenuButton(back,
back.getWidth() / 2f, back.getWidth() / 2f,
height - (back.getHeight() / 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,10 +809,18 @@ 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...