mainmenu: put the repo buttons in the bottom left corner

Also speed up their expansion animations
This commit is contained in:
yugecin 2018-07-01 23:40:23 +02:00
parent 455d8fe7c8
commit 5f2c9c5291
No known key found for this signature in database
GPG Key ID: 2C5AC035A7068E44

View File

@ -54,6 +54,7 @@ import yugecin.opsudance.core.state.OpsuState;
import static itdelatrisu.opsu.GameImage.*; import static itdelatrisu.opsu.GameImage.*;
import static itdelatrisu.opsu.ui.Colors.*; import static itdelatrisu.opsu.ui.Colors.*;
import static itdelatrisu.opsu.ui.animations.AnimationEquation.*; import static itdelatrisu.opsu.ui.animations.AnimationEquation.*;
import static java.awt.Desktop.Action.*;
import static org.lwjgl.input.Keyboard.*; import static org.lwjgl.input.Keyboard.*;
import static yugecin.opsudance.core.InstanceContainer.*; import static yugecin.opsudance.core.InstanceContainer.*;
import static yugecin.opsudance.options.Options.*; import static yugecin.opsudance.options.Options.*;
@ -70,6 +71,8 @@ public class MainMenu extends BaseOpsuState {
/** Max alpha level of the menu background. */ /** Max alpha level of the menu background. */
private static final float BG_MAX_ALPHA = 0.9f; private static final float BG_MAX_ALPHA = 0.9f;
private float barHeight;
/** Logo button that reveals other buttons on click. */ /** Logo button that reveals other buttons on click. */
private MenuButton logo; private MenuButton logo;
@ -113,7 +116,6 @@ public class MainMenu extends BaseOpsuState {
private int textMarginX; private int textMarginX;
private int textTopMarginY; private int textTopMarginY;
private int textBottomMarginY;
private int textLineHeight; private int textLineHeight;
/** Application start time, for drawing the total running time. */ /** Application start time, for drawing the total running time. */
@ -137,11 +139,15 @@ public class MainMenu extends BaseOpsuState {
/** The star fountain. */ /** The star fountain. */
private StarFountain starFountain; private StarFountain starFountain;
/** Time format used to show running time. */
private final SimpleDateFormat timeFormat;
private LinkedList<PulseData> pulseData = new LinkedList<>(); private LinkedList<PulseData> pulseData = new LinkedList<>();
private float lastPulseProgress; private float lastPulseProgress;
public MainMenu() { public MainMenu() {
this.nowPlayingPosition = new AnimatedValue(1000, 0, 0, OUT_QUART); this.nowPlayingPosition = new AnimatedValue(1000, 0, 0, OUT_QUART);
this.timeFormat = new SimpleDateFormat("HH:mm");
} }
@Override @Override
@ -152,9 +158,10 @@ public class MainMenu extends BaseOpsuState {
final int width = displayContainer.width; final int width = displayContainer.width;
final int height = displayContainer.height; final int height = displayContainer.height;
this.barHeight = height * 0.1125f;
this.textMarginX = (int) (width * 0.015f); this.textMarginX = (int) (width * 0.015f);
this.textTopMarginY = (int) (height * 0.01f); this.textTopMarginY = (int) (height * 0.01f);
this.textBottomMarginY = (int) (height * 0.015f);
this.textLineHeight = (int) (Fonts.MEDIUM.getLineHeight() * 0.925f); this.textLineHeight = (int) (Fonts.MEDIUM.getLineHeight() * 0.925f);
// initialize menu buttons // initialize menu buttons
@ -219,24 +226,18 @@ public class MainMenu extends BaseOpsuState {
downloadsButton.setHoverAnimationEquation(AnimationEquation.IN_OUT_BACK); downloadsButton.setHoverAnimationEquation(AnimationEquation.IN_OUT_BACK);
downloadsButton.setHoverExpand(1.03f, Expand.LEFT); downloadsButton.setHoverExpand(1.03f, Expand.LEFT);
// initialize repository button // initialize repository button (only if a webpage can be opened)
float startX = displayContainer.width * 0.997f, startY = displayContainer.height * 0.997f; if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(BROWSE)) {
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { // only if a webpage can be opened final Image repoImg = GameImage.REPOSITORY.getImage();
Image repoImg; float repoX = this.textMarginX + repoImg.getWidth() / 2;
repoImg = GameImage.REPOSITORY.getImage(); final float repoY = height - this.barHeight / 2;
repoButton = new MenuButton(repoImg, repoButton = new MenuButton(repoImg, repoX, repoY);
startX - repoImg.getWidth() * 2.5f, startY - repoImg.getHeight() repoButton.setHoverAnimationDuration(100);
); repoButton.setHoverExpand(1.1f);
repoButton.setHoverAnimationDuration(350); repoX += repoImg.getWidth() * 1.5f;
repoButton.setHoverAnimationEquation(AnimationEquation.IN_OUT_BACK); danceRepoButton = new MenuButton(repoImg, repoX, repoY);
repoButton.setHoverExpand(); danceRepoButton.setHoverAnimationDuration(100);
repoImg = GameImage.REPOSITORY.getImage(); danceRepoButton.setHoverExpand(1.1f);
danceRepoButton = new MenuButton(repoImg,
startX - repoImg.getWidth(), startY - repoImg.getHeight()
);
danceRepoButton.setHoverAnimationDuration(350);
danceRepoButton.setHoverAnimationEquation(AnimationEquation.IN_OUT_BACK);
danceRepoButton.setHoverExpand();
} }
// initialize update buttons // initialize update buttons
@ -282,9 +283,8 @@ public class MainMenu extends BaseOpsuState {
float oldAlpha = Colors.BLACK_ALPHA.a; float oldAlpha = Colors.BLACK_ALPHA.a;
Colors.BLACK_ALPHA.a = 0.4f; Colors.BLACK_ALPHA.a = 0.4f;
g.setColor(Colors.BLACK_ALPHA); g.setColor(Colors.BLACK_ALPHA);
final float barheight = height * 0.1125f; g.fillRect(0, 0, width, this.barHeight);
g.fillRect(0, 0, width, barheight); g.fillRect(0, height - this.barHeight, width, this.barHeight);
g.fillRect(0, height - barheight, width, barheight);
Colors.BLACK_ALPHA.a = oldAlpha; Colors.BLACK_ALPHA.a = oldAlpha;
// draw star fountain // draw star fountain
@ -428,7 +428,7 @@ public class MainMenu extends BaseOpsuState {
g.drawString(txt, textMarginX, textTopMarginY + textLineHeight); g.drawString(txt, textMarginX, textTopMarginY + textLineHeight);
txt = String.format( txt = String.format(
"It is currently %s.", "It is currently %s.",
new SimpleDateFormat("HH:mm").format(new Date()) this.timeFormat.format(new Date())
); );
g.drawString(txt, textMarginX, textTopMarginY + textLineHeight * 2); g.drawString(txt, textMarginX, textTopMarginY + textLineHeight * 2);