You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
148 lines
3.6 KiB
148 lines
3.6 KiB
11 years ago
|
package mightypork.rogue.screens.game;
|
||
|
|
||
|
|
||
|
import java.io.IOException;
|
||
|
|
||
11 years ago
|
import mightypork.gamecore.Config;
|
||
11 years ago
|
import mightypork.gamecore.gui.Action;
|
||
|
import mightypork.gamecore.gui.AlignX;
|
||
11 years ago
|
import mightypork.gamecore.gui.components.input.TextButton;
|
||
11 years ago
|
import mightypork.gamecore.gui.components.layout.RowLayout;
|
||
11 years ago
|
import mightypork.gamecore.gui.components.layout.linear.LinearLayout;
|
||
11 years ago
|
import mightypork.gamecore.gui.components.painters.QuadPainter;
|
||
|
import mightypork.gamecore.gui.components.painters.TextPainter;
|
||
11 years ago
|
import mightypork.gamecore.gui.screens.impl.FadingLayer;
|
||
11 years ago
|
import mightypork.gamecore.input.KeyStroke.Edge;
|
||
11 years ago
|
import mightypork.gamecore.logging.Log;
|
||
11 years ago
|
import mightypork.gamecore.resources.Res;
|
||
11 years ago
|
import mightypork.gamecore.resources.fonts.GLFont;
|
||
|
import mightypork.gamecore.util.math.color.pal.RGB;
|
||
|
import mightypork.gamecore.util.math.constraints.num.Num;
|
||
|
import mightypork.rogue.screens.game.ScreenGame.GScrState;
|
||
|
import mightypork.rogue.world.WorldProvider;
|
||
|
|
||
|
|
||
11 years ago
|
public class LayerAskSave extends FadingLayer {
|
||
11 years ago
|
|
||
|
public Runnable task;
|
||
|
|
||
|
private final ScreenGame gscreen;
|
||
|
|
||
|
|
||
|
public void setTask(Runnable task)
|
||
|
{
|
||
|
this.task = task;
|
||
|
}
|
||
|
|
||
|
|
||
11 years ago
|
@Override
|
||
|
protected void onHideFinished()
|
||
|
{
|
||
|
if (gscreen.getState() != GScrState.WORLD) {
|
||
|
gscreen.setState(GScrState.WORLD); // go back..
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
public LayerAskSave(final ScreenGame screen)
|
||
11 years ago
|
{
|
||
|
super(screen);
|
||
|
this.gscreen = screen;
|
||
|
|
||
|
// darker down to cover console.
|
||
|
final QuadPainter qp = new QuadPainter(RGB.BLACK_80);
|
||
|
qp.setRect(root);
|
||
|
root.add(qp);
|
||
|
|
||
|
final GLFont thick_font = Res.getFont("thick");
|
||
|
|
||
|
final RowLayout rl = new RowLayout(root, 2);
|
||
|
rl.setRect(root.shrink(Num.ZERO, root.height().perc(40)).moveY(root.height().perc(-10)));
|
||
|
root.add(rl);
|
||
|
|
||
|
final TextPainter txp = new TextPainter(thick_font, AlignX.CENTER, RGB.WHITE, "Save the game?");
|
||
|
rl.add(txp, 1);
|
||
11 years ago
|
txp.setVPaddingPercent(25);
|
||
11 years ago
|
|
||
11 years ago
|
final LinearLayout ll = new LinearLayout(root, AlignX.CENTER);
|
||
|
rl.add(ll);
|
||
11 years ago
|
|
||
11 years ago
|
final double vPadPerc = 20;
|
||
|
|
||
|
final TextButton btn1 = new TextButton(thick_font, "Yes", ScreenGame.COLOR_BTN_GOOD);
|
||
11 years ago
|
btn1.textPainter.setAlign(AlignX.RIGHT);
|
||
11 years ago
|
btn1.textPainter.setVPaddingPercent(vPadPerc);
|
||
|
ll.add(btn1);
|
||
|
ll.gap(50);
|
||
11 years ago
|
|
||
11 years ago
|
final TextButton btn2 = new TextButton(thick_font, "No", ScreenGame.COLOR_BTN_BAD);
|
||
11 years ago
|
btn2.textPainter.setAlign(AlignX.CENTER);
|
||
11 years ago
|
btn2.textPainter.setVPaddingPercent(vPadPerc);
|
||
|
ll.add(btn2);
|
||
|
ll.gap(50);
|
||
11 years ago
|
|
||
11 years ago
|
final TextButton btn3 = new TextButton(thick_font, "Cancel", ScreenGame.COLOR_BTN_CANCEL);
|
||
11 years ago
|
btn3.textPainter.setAlign(AlignX.LEFT);
|
||
11 years ago
|
btn3.textPainter.setVPaddingPercent(vPadPerc);
|
||
|
ll.add(btn3);
|
||
11 years ago
|
|
||
|
final Action cancel = new Action() {
|
||
|
|
||
|
@Override
|
||
|
protected void execute()
|
||
|
{
|
||
11 years ago
|
hide();
|
||
11 years ago
|
}
|
||
|
};
|
||
|
|
||
11 years ago
|
final Action save = new Action() {
|
||
11 years ago
|
|
||
|
@Override
|
||
|
protected void execute()
|
||
|
{
|
||
|
try {
|
||
|
WorldProvider.get().saveWorld();
|
||
|
if (task != null) task.run();
|
||
|
} catch (final IOException e) {
|
||
|
Log.e(e);
|
||
|
}
|
||
|
}
|
||
11 years ago
|
};
|
||
11 years ago
|
|
||
11 years ago
|
final Action discard = new Action() {
|
||
11 years ago
|
|
||
|
@Override
|
||
|
protected void execute()
|
||
|
{
|
||
|
if (task != null) task.run();
|
||
|
}
|
||
11 years ago
|
};
|
||
11 years ago
|
|
||
11 years ago
|
btn1.setAction(save);
|
||
|
btn2.setAction(discard);
|
||
11 years ago
|
btn3.setAction(cancel);
|
||
|
|
||
11 years ago
|
bindKey(Config.getKey("general.close"), Edge.RISING, cancel);
|
||
11 years ago
|
bindKey(Config.getKey("general.cancel"), Edge.RISING, cancel);
|
||
|
|
||
|
bindKey(Config.getKey("general.yes"), Edge.RISING, save);
|
||
|
bindKey(Config.getKey("general.confirm"), Edge.RISING, save);
|
||
|
|
||
|
bindKey(Config.getKey("general.no"), Edge.RISING, discard);
|
||
11 years ago
|
}
|
||
|
|
||
|
|
||
|
@Override
|
||
|
public int getZIndex()
|
||
|
{
|
||
11 years ago
|
return 300;
|
||
11 years ago
|
}
|
||
|
|
||
|
|
||
|
@Override
|
||
11 years ago
|
public void update(double delta)
|
||
11 years ago
|
{
|
||
11 years ago
|
super.update(delta);
|
||
11 years ago
|
}
|
||
|
}
|