don't use MenuButton for the logo image

This commit is contained in:
yugecin 2018-07-07 19:27:47 +02:00
parent 3baefd2c0b
commit 8fd49d7015
No known key found for this signature in database
GPG Key ID: 2C5AC035A7068E44
2 changed files with 55 additions and 32 deletions

View File

@ -80,8 +80,8 @@ public class MainMenu extends BaseOpsuState {
private float barHeight; private float barHeight;
/** Logo button that reveals other buttons on click. */ private ImagePosition logo;
private MenuButton logo; private AnimatedValue logoHover;
/** Logo states. */ /** Logo states. */
private enum LogoState { DEFAULT, OPENING, OPEN, CLOSING } private enum LogoState { DEFAULT, OPENING, OPEN, CLOSING }
@ -158,6 +158,7 @@ public class MainMenu extends BaseOpsuState {
public MainMenu() { public MainMenu() {
this.nowPlayingPosition = new AnimatedValue(1000, 0, 0, OUT_QUART); this.nowPlayingPosition = new AnimatedValue(1000, 0, 0, OUT_QUART);
this.logoClickScale = new AnimatedValue(300, .9f, 1f, OUT_QUAD); this.logoClickScale = new AnimatedValue(300, .9f, 1f, OUT_QUAD);
this.logoHover = new AnimatedValue(350, 1f, 1.096f, IN_OUT_EXPO);
this.buttonAnimation = new AnimatedValue(1, 0f, 1f, OUT_QUAD); this.buttonAnimation = new AnimatedValue(1, 0f, 1f, OUT_QUAD);
this.buttonAnimations = new AnimatedValue[3]; this.buttonAnimations = new AnimatedValue[3];
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
@ -180,16 +181,6 @@ public class MainMenu extends BaseOpsuState {
this.textTopMarginY = (int) (height * 0.01f); this.textTopMarginY = (int) (height * 0.01f);
this.textLineHeight = (int) (Fonts.MEDIUM.getLineHeight() * 0.925f); this.textLineHeight = (int) (Fonts.MEDIUM.getLineHeight() * 0.925f);
// initialize menu buttons
Image logoImg = GameImage.MENU_LOGO.getImage();
logo = new MenuButton(logoImg, displayContainer.width / 2f, displayContainer.height / 2f);
final int logoAnimationDuration = 350;
logo.setHoverAnimationDuration(logoAnimationDuration);
final AnimationEquation logoAnimationEquation = AnimationEquation.IN_OUT_EXPO;
logo.setHoverAnimationEquation(logoAnimationEquation);
final float logoHoverScale = 1.096f;
logo.setHoverExpand(logoHoverScale);
// initialize music buttons // initialize music buttons
final int musicSize = (int) (this.textLineHeight * 0.8f); final int musicSize = (int) (this.textLineHeight * 0.8f);
final float musicScale = (float) musicSize / MUSIC_STOP.getImage().getWidth(); final float musicScale = (float) musicSize / MUSIC_STOP.getImage().getWidth();
@ -258,6 +249,7 @@ public class MainMenu extends BaseOpsuState {
starFountain = new StarFountain(displayContainer.width, displayContainer.height); starFountain = new StarFountain(displayContainer.width, displayContainer.height);
// logo & buttons // logo & buttons
this.logo = new ImagePosition(MENU_LOGO.getImage());
logoPositionOffsetX = 0.35f * MENU_LOGO.getImage().getHeight(); logoPositionOffsetX = 0.35f * MENU_LOGO.getImage().getHeight();
logoPosition = new AnimatedValue(1, 0, 1, AnimationEquation.OUT_QUAD); logoPosition = new AnimatedValue(1, 0, 1, AnimationEquation.OUT_QUAD);
logoButtonAlpha = new AnimatedValue(200, 0f, 1f, AnimationEquation.LINEAR); logoButtonAlpha = new AnimatedValue(200, 0f, 1f, AnimationEquation.LINEAR);
@ -313,7 +305,7 @@ public class MainMenu extends BaseOpsuState {
beatPosition = System.currentTimeMillis() % 1000 / 1000f; beatPosition = System.currentTimeMillis() % 1000 / 1000f;
beatLength = 1000f; beatLength = 1000f;
} }
final float hoverScale = logo.getCurrentHoverExpandValue(); final float hoverScale = this.logoHover.getValue();
if (beatPosition < this.lastPulseProgress) { if (beatPosition < this.lastPulseProgress) {
this.pulseData.add(new PulseData((int) (beatPosition*beatLength), hoverScale)); this.pulseData.add(new PulseData((int) (beatPosition*beatLength), hoverScale));
} }
@ -339,7 +331,7 @@ public class MainMenu extends BaseOpsuState {
final float scale = (pd.initialScale + (0.432f * progress)) * clickScale; final float scale = (pd.initialScale + (0.432f * progress)) * clickScale;
final Image p = MENU_LOGO_PULSE.getScaledImage(scale); final Image p = MENU_LOGO_PULSE.getScaledImage(scale);
p.setAlpha(0.15f * (1f - IN_QUAD.calc(progress))); p.setAlpha(0.15f * (1f - IN_QUAD.calc(progress)));
p.drawCentered(logo.getX(), logo.getY(), logoColor); p.drawCentered(this.logo.middleX(), this.logo.middleY(), logoColor);
} }
// draw buttons // draw buttons
@ -365,7 +357,7 @@ public class MainMenu extends BaseOpsuState {
final float yoff = (i - 1f) * halfradius; final float yoff = (i - 1f) * halfradius;
final double cliptop = cr * cos(asin((yoff - btnhalfheight) / cr)); final double cliptop = cr * cos(asin((yoff - btnhalfheight) / cr));
final double clipbot = cr * cos(asin((yoff + btnhalfheight) / cr)); final double clipbot = cr * cos(asin((yoff + btnhalfheight) / cr));
final float clipxstart = bx - this.logo.getX(); final float clipxstart = bx - this.logo.middleX();
final int ct = (int) (cliptop - clipxstart); final int ct = (int) (cliptop - clipxstart);
final int cb = (int) (clipbot - clipxstart); final int cb = (int) (clipbot - clipxstart);
final int y = (int) (basey + yoff); final int y = (int) (basey + yoff);
@ -375,16 +367,17 @@ public class MainMenu extends BaseOpsuState {
} }
// draw logo // draw logo
logo.draw(logoColor, logoScale); this.logo.scale(logoScale);
this.logo.draw(logoColor);
if (renderPiece) { if (renderPiece) {
final Image piece = MENU_LOGO_PIECE.getScaledImage(hoverScale * clickScale); final Image piece = MENU_LOGO_PIECE.getScaledImage(hoverScale * logoScale);
piece.rotate(beatPosition * 360f); piece.rotate(beatPosition * 360f);
piece.drawCentered(logo.getX(), logo.getY(), logoColor); piece.drawCentered(this.logo.middleX(), this.logo.middleY(), logoColor);
} }
final float ghostScale = hoverScale * 1.0186f - smoothExpandProgress * 0.0186f; final float ghostScale = hoverScale * 1.0186f - smoothExpandProgress * 0.0186f;
Image ghostLogo = MENU_LOGO.getScaledImage(ghostScale * clickScale); Image ghostLogo = MENU_LOGO.getScaledImage(ghostScale * clickScale);
ghostLogo.setAlpha(0.25f); ghostLogo.setAlpha(0.25f);
ghostLogo.drawCentered(logo.getX(), logo.getY(), logoColor); ghostLogo.drawCentered(this.logo.middleX(), this.logo.middleY(), logoColor);
// now playing // now playing
final Image np = GameImage.MUSIC_NOWPLAYING.getImage(); final Image np = GameImage.MUSIC_NOWPLAYING.getImage();
@ -500,7 +493,6 @@ public class MainMenu extends BaseOpsuState {
nextTrack(false); // end of track: go to next track nextTrack(false); // end of track: go to next track
int mouseX = displayContainer.mouseX; int mouseX = displayContainer.mouseX;
int mouseY = displayContainer.mouseY; int mouseY = displayContainer.mouseY;
logo.hoverUpdate(delta, mouseX, mouseY, 0.25f);
if (repoButton != null) { if (repoButton != null) {
repoButton.hoverUpdate(delta, mouseX, mouseY); repoButton.hoverUpdate(delta, mouseX, mouseY);
danceRepoButton.hoverUpdate(delta, mouseX, mouseY); danceRepoButton.hoverUpdate(delta, mouseX, mouseY);
@ -534,13 +526,18 @@ public class MainMenu extends BaseOpsuState {
} }
// buttons // buttons
int centerX = displayContainer.width / 2; this.logo.width = MENU_LOGO.getImage().getWidth();
this.logo.height = MENU_LOGO.getImage().getHeight();
this.logo.x = (displayContainer.width - this.logo.width) / 2;
this.logo.y = (displayContainer.height - this.logo.height) / 2;
if (this.logoState != LogoState.DEFAULT) {
this.logo.x -= (int) this.logoPosition.getValue();
}
switch (logoState) { switch (logoState) {
case DEFAULT: case DEFAULT:
break; break;
case OPENING: case OPENING:
if (logoPosition.update(delta)) { if (logoPosition.update(delta)) {
logo.setX(centerX - logoPosition.getValue());
this.buttonAnimation.update(delta); this.buttonAnimation.update(delta);
} else { } else {
this.buttonAnimation.setTime(this.buttonAnimation.getDuration()); this.buttonAnimation.setTime(this.buttonAnimation.getDuration());
@ -565,7 +562,6 @@ public class MainMenu extends BaseOpsuState {
case CLOSING: case CLOSING:
logoButtonAlpha.update(-delta); logoButtonAlpha.update(-delta);
if (logoPosition.update(-delta)) { if (logoPosition.update(-delta)) {
logo.setX(centerX - logoPosition.getValue());
this.buttonAnimation.update(-delta); this.buttonAnimation.update(-delta);
} else { } else {
this.logoState = LogoState.DEFAULT; this.logoState = LogoState.DEFAULT;
@ -574,6 +570,15 @@ public class MainMenu extends BaseOpsuState {
break; break;
} }
this.logoClickScale.update(delta); this.logoClickScale.update(delta);
if (this.logo.contains(mouseX, mouseY, 0.25f)) {
this.logoHover.update(delta);
} else {
this.logoHover.update(-delta);
}
final float hoverScale = this.logoHover.getValue();
if (hoverScale != 1f) {
this.logo.scale(hoverScale);
}
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
final ImagePosition pos = this.buttonPositions[i]; final ImagePosition pos = this.buttonPositions[i];
final AnimatedValue anim = this.buttonAnimations[i]; final AnimatedValue anim = this.buttonAnimations[i];
@ -620,7 +625,6 @@ public class MainMenu extends BaseOpsuState {
public void enter() { public void enter() {
super.enter(); super.enter();
logo.setX(displayContainer.width / 2);
logoPosition.setTime(0); logoPosition.setTime(0);
logoButtonAlpha.setTime(0); logoButtonAlpha.setTime(0);
nowPlayingPosition.setTime(0); nowPlayingPosition.setTime(0);
@ -645,8 +649,6 @@ public class MainMenu extends BaseOpsuState {
// reset button hover states if mouse is not currently hovering over the button // reset button hover states if mouse is not currently hovering over the button
int mouseX = displayContainer.mouseX; int mouseX = displayContainer.mouseX;
int mouseY = displayContainer.mouseY; int mouseY = displayContainer.mouseY;
if (!logo.contains(mouseX, mouseY, 0.25f))
logo.resetHover();
for (MenuButton b : this.musicButtons) { for (MenuButton b : this.musicButtons) {
if (!b.contains(mouseX, mouseY)) { if (!b.contains(mouseX, mouseY)) {
b.resetHover(); b.resetHover();
@ -778,7 +780,7 @@ public class MainMenu extends BaseOpsuState {
// start moving logo (if clicked) // start moving logo (if clicked)
if (logoState == LogoState.DEFAULT || logoState == LogoState.CLOSING) { if (logoState == LogoState.DEFAULT || logoState == LogoState.CLOSING) {
if (logo.contains(x, y, 0.25f)) { if (this.logo.contains(x, y, 0.25f)) {
this.openLogo(); this.openLogo();
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
this.logoClickScale.setTime(0); this.logoClickScale.setTime(0);
@ -789,7 +791,7 @@ public class MainMenu extends BaseOpsuState {
// other button actions (if visible) // other button actions (if visible)
else if (logoState == LogoState.OPEN || logoState == LogoState.OPENING) { else if (logoState == LogoState.OPEN || logoState == LogoState.OPENING) {
boolean logocontains = false; boolean logocontains = false;
if (logo.contains(x, y, 0.25f)) { if (this.logo.contains(x, y, 0.25f)) {
logocontains = true; logocontains = true;
this.logoClickScale.setTime(0); this.logoClickScale.setTime(0);
} }

View File

@ -17,11 +17,12 @@
*/ */
package yugecin.opsudance.ui; package yugecin.opsudance.ui;
import java.awt.Rectangle; import java.awt.geom.Rectangle2D;
import org.newdawn.slick.Color;
import org.newdawn.slick.Image; import org.newdawn.slick.Image;
public class ImagePosition extends Rectangle { public class ImagePosition extends Rectangle2D.Float {
private Image image; private Image image;
@ -33,9 +34,29 @@ public class ImagePosition extends Rectangle {
if (!super.contains(x, y)) { if (!super.contains(x, y)) {
return false; return false;
} }
final int ix = x - this.x; final int ix = x - (int) this.x;
final int iy = y - this.y; final int iy = y - (int) this.y;
return this.image.getAlphaAt(ix, iy) > alphaThreshold; return this.image.getAlphaAt(ix, iy) > alphaThreshold;
} }
public float middleX() {
return this.x + this.width / 2;
}
public float middleY() {
return this.y + this.height / 2;
}
public void scale(float scale) {
final float width = this.width * scale;
final float height = this.height * scale;
this.x -= (width - this.width) / 2f;
this.y -= (height - this.height) / 2f;
this.width = width;
this.height = height;
}
public void draw(Color filter) {
this.image.draw(this.x, this.y, this.width, this.height, filter);
}
} }