2014-06-30 04:17:04 +02:00
|
|
|
/*
|
|
|
|
* opsu! - an open-source osu! client
|
|
|
|
* Copyright (C) 2014 Jeffrey Han
|
|
|
|
*
|
|
|
|
* opsu! is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* opsu! is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with opsu!. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package itdelatrisu.opsu.states;
|
|
|
|
|
|
|
|
import itdelatrisu.opsu.GUIMenuButton;
|
|
|
|
import itdelatrisu.opsu.Opsu;
|
2014-07-02 01:32:03 +02:00
|
|
|
import itdelatrisu.opsu.Utils;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
import org.newdawn.slick.Color;
|
|
|
|
import org.newdawn.slick.GameContainer;
|
|
|
|
import org.newdawn.slick.Graphics;
|
|
|
|
import org.newdawn.slick.Image;
|
|
|
|
import org.newdawn.slick.Input;
|
|
|
|
import org.newdawn.slick.SlickException;
|
|
|
|
import org.newdawn.slick.state.BasicGameState;
|
|
|
|
import org.newdawn.slick.state.StateBasedGame;
|
|
|
|
import org.newdawn.slick.state.transition.EmptyTransition;
|
|
|
|
import org.newdawn.slick.state.transition.FadeInTransition;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* "Confirm Exit" state.
|
|
|
|
* <ul>
|
|
|
|
* <li>[Yes] - quit game
|
|
|
|
* <li>[No] - return to main menu
|
|
|
|
* </ul>
|
|
|
|
*/
|
|
|
|
public class MainMenuExit extends BasicGameState {
|
|
|
|
/**
|
|
|
|
* "Yes" and "No" buttons.
|
|
|
|
*/
|
|
|
|
private GUIMenuButton yesButton, noButton;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initial x coordinate offsets left/right of center (for shifting animation).
|
|
|
|
*/
|
|
|
|
private float centerOffset;
|
|
|
|
|
2014-07-07 05:13:33 +02:00
|
|
|
// game-related variables
|
2014-06-30 04:17:04 +02:00
|
|
|
private GameContainer container;
|
|
|
|
private StateBasedGame game;
|
|
|
|
private int state;
|
|
|
|
|
|
|
|
public MainMenuExit(int state) {
|
|
|
|
this.state = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void init(GameContainer container, StateBasedGame game)
|
|
|
|
throws SlickException {
|
|
|
|
this.container = container;
|
|
|
|
this.game = game;
|
|
|
|
|
|
|
|
int width = container.getWidth();
|
|
|
|
int height = container.getHeight();
|
|
|
|
|
2014-07-15 19:21:37 +02:00
|
|
|
centerOffset = width / 18f;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// initialize buttons
|
|
|
|
Image button = new Image("button-middle.png");
|
|
|
|
Image buttonL = new Image("button-left.png");
|
|
|
|
Image buttonR = new Image("button-right.png");
|
|
|
|
button = button.getScaledCopy(width / 2, button.getHeight());
|
|
|
|
yesButton = new GUIMenuButton(button, buttonL, buttonR,
|
2014-07-15 19:21:37 +02:00
|
|
|
width / 2f + centerOffset, height * 0.2f
|
2014-06-30 04:17:04 +02:00
|
|
|
);
|
|
|
|
noButton = new GUIMenuButton(button, buttonL, buttonR,
|
2014-07-15 19:21:37 +02:00
|
|
|
width / 2f - centerOffset, height * 0.2f + (button.getHeight() * 1.25f)
|
2014-06-30 04:17:04 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void render(GameContainer container, StateBasedGame game, Graphics g)
|
|
|
|
throws SlickException {
|
|
|
|
g.setBackground(Color.black);
|
|
|
|
g.setColor(Color.white);
|
|
|
|
|
|
|
|
// draw text
|
|
|
|
float c = container.getWidth() * 0.02f;
|
2014-07-02 01:32:03 +02:00
|
|
|
Utils.FONT_LARGE.drawString(c, c, "Are you sure you want to exit opsu!?");
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// draw buttons
|
|
|
|
yesButton.draw(Color.green);
|
|
|
|
noButton.draw(Color.red);
|
2014-07-02 01:32:03 +02:00
|
|
|
g.setFont(Utils.FONT_XLARGE);
|
2014-06-30 04:17:04 +02:00
|
|
|
g.drawString("1. Yes",
|
2014-07-02 01:32:03 +02:00
|
|
|
yesButton.getX() - (Utils.FONT_XLARGE.getWidth("1. Yes") / 2f),
|
2014-08-24 20:48:27 +02:00
|
|
|
yesButton.getY() - (Utils.FONT_XLARGE.getLineHeight() / 2f)
|
2014-06-30 04:17:04 +02:00
|
|
|
);
|
|
|
|
g.drawString("2. No",
|
2014-07-02 01:32:03 +02:00
|
|
|
noButton.getX() - (Utils.FONT_XLARGE.getWidth("2. No") / 2f),
|
2014-08-24 20:48:27 +02:00
|
|
|
noButton.getY() - (Utils.FONT_XLARGE.getLineHeight() / 2f)
|
2014-06-30 04:17:04 +02:00
|
|
|
);
|
|
|
|
|
2014-07-02 01:32:03 +02:00
|
|
|
Utils.drawFPS();
|
|
|
|
Utils.drawCursor();
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void update(GameContainer container, StateBasedGame game, int delta)
|
|
|
|
throws SlickException {
|
2014-07-07 05:13:33 +02:00
|
|
|
Utils.updateCursor(delta);
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
// move buttons to center
|
|
|
|
float yesX = yesButton.getX(), noX = noButton.getX();
|
|
|
|
float center = container.getWidth() / 2f;
|
|
|
|
if (yesX < center)
|
2014-07-18 03:16:15 +02:00
|
|
|
yesButton.setX(Math.min(yesX + (delta / 5f), center));
|
2014-06-30 04:17:04 +02:00
|
|
|
if (noX > center)
|
2014-07-18 03:16:15 +02:00
|
|
|
noButton.setX(Math.max(noX - (delta / 5f), center));
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getID() { return state; }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void mousePressed(int button, int x, int y) {
|
|
|
|
// check mouse button
|
|
|
|
if (button != Input.MOUSE_LEFT_BUTTON)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (yesButton.contains(x, y)) {
|
|
|
|
Options.saveOptions();
|
2014-06-30 18:37:37 +02:00
|
|
|
Opsu.closeSocket();
|
2014-06-30 04:17:04 +02:00
|
|
|
container.exit();
|
|
|
|
} else if (noButton.contains(x, y))
|
|
|
|
game.enterState(Opsu.STATE_MAINMENU, new EmptyTransition(), new FadeInTransition(Color.black));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void keyPressed(int key, char c) {
|
|
|
|
switch (key) {
|
|
|
|
case Input.KEY_1:
|
|
|
|
Options.saveOptions();
|
2014-06-30 18:37:37 +02:00
|
|
|
Opsu.closeSocket();
|
2014-06-30 04:17:04 +02:00
|
|
|
container.exit();
|
|
|
|
break;
|
|
|
|
case Input.KEY_2:
|
|
|
|
case Input.KEY_ESCAPE:
|
|
|
|
game.enterState(Opsu.STATE_MAINMENU, new EmptyTransition(), new FadeInTransition(Color.black));
|
|
|
|
break;
|
|
|
|
case Input.KEY_F12:
|
2014-07-02 01:32:03 +02:00
|
|
|
Utils.takeScreenShot();
|
2014-06-30 04:17:04 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void enter(GameContainer container, StateBasedGame game)
|
|
|
|
throws SlickException {
|
|
|
|
float center = container.getWidth() / 2f;
|
|
|
|
yesButton.setX(center - centerOffset);
|
|
|
|
noButton.setX(center + centerOffset);
|
|
|
|
}
|
|
|
|
}
|