parent
1ca0b9e0e9
commit
2699d8d549
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 3.3 KiB |
Binary file not shown.
@ -1,61 +0,0 @@ |
||||
package mightypork.gamecore.gui.components.layout; |
||||
|
||||
|
||||
import mightypork.gamecore.app.AppAccess; |
||||
import mightypork.gamecore.gui.components.Component; |
||||
import mightypork.gamecore.gui.components.LayoutComponent; |
||||
import mightypork.gamecore.util.math.constraints.rect.builders.TiledRect; |
||||
import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound; |
||||
|
||||
|
||||
/** |
||||
* Holder with evenly spaced columns |
||||
* |
||||
* @author MightyPork |
||||
*/ |
||||
public class ColumnHolder extends LayoutComponent { |
||||
|
||||
private final TiledRect tiler; |
||||
private int col = 0; |
||||
|
||||
|
||||
/** |
||||
* @param app app access |
||||
* @param context context |
||||
* @param cols number of columns |
||||
*/ |
||||
public ColumnHolder(AppAccess app, RectBound context, int cols) |
||||
{ |
||||
super(app, context); |
||||
this.tiler = columns(cols); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* make a new holder.<br> |
||||
* Context must be assigned before rendering. |
||||
* |
||||
* @param app app access |
||||
* @param cols number of columns |
||||
*/ |
||||
public ColumnHolder(AppAccess app, int cols) |
||||
{ |
||||
this(app, null, cols); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Add a row to the holder. |
||||
* |
||||
* @param elem |
||||
*/ |
||||
public void add(final Component elem) |
||||
{ |
||||
if (elem == null) return; |
||||
|
||||
elem.setRect(tiler.column(col++)); |
||||
|
||||
attach(elem); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,45 @@ |
||||
package mightypork.gamecore.gui.components.layout; |
||||
|
||||
|
||||
import mightypork.gamecore.app.AppAccess; |
||||
import mightypork.gamecore.gui.components.Component; |
||||
import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound; |
||||
|
||||
|
||||
public class ColumnLayout extends GridLayout { |
||||
|
||||
private int col = 0; |
||||
|
||||
|
||||
public ColumnLayout(AppAccess app, int rows) |
||||
{ |
||||
this(app, null, rows); |
||||
} |
||||
|
||||
|
||||
public ColumnLayout(AppAccess app, RectBound context, int cols) |
||||
{ |
||||
super(app, context, 1, cols); |
||||
} |
||||
|
||||
|
||||
public void add(final Component elem) |
||||
{ |
||||
add(elem, 1); |
||||
} |
||||
|
||||
|
||||
public void add(final Component elem, int colSpan) |
||||
{ |
||||
if (elem == null) return; |
||||
|
||||
put(elem, 0, col, 1, colSpan); |
||||
col += colSpan; |
||||
} |
||||
|
||||
|
||||
public void skip(int cols) |
||||
{ |
||||
col += cols; |
||||
} |
||||
} |
@ -1,61 +0,0 @@ |
||||
package mightypork.gamecore.gui.components.layout; |
||||
|
||||
|
||||
import mightypork.gamecore.app.AppAccess; |
||||
import mightypork.gamecore.gui.components.Component; |
||||
import mightypork.gamecore.gui.components.LayoutComponent; |
||||
import mightypork.gamecore.util.math.constraints.rect.builders.TiledRect; |
||||
import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound; |
||||
|
||||
|
||||
/** |
||||
* Holder with evenly spaced rows |
||||
* |
||||
* @author MightyPork |
||||
*/ |
||||
public class RowHolder extends LayoutComponent { |
||||
|
||||
private final TiledRect tiler; |
||||
private int row = 0; |
||||
|
||||
|
||||
/** |
||||
* Make a row holder.<br> |
||||
* Context must be assigned before rendering. |
||||
* |
||||
* @param app app access |
||||
* @param rows number of rows |
||||
*/ |
||||
public RowHolder(AppAccess app, int rows) |
||||
{ |
||||
this(app, null, rows); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* @param app app access |
||||
* @param context bounding context |
||||
* @param rows number of rows |
||||
*/ |
||||
public RowHolder(AppAccess app, RectBound context, int rows) |
||||
{ |
||||
super(app, context); |
||||
this.tiler = rows(rows); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Add a row to the holder. |
||||
* |
||||
* @param elem |
||||
*/ |
||||
public void add(final Component elem) |
||||
{ |
||||
if (elem == null) return; |
||||
|
||||
elem.setRect(tiler.row(row++)); |
||||
|
||||
attach(elem); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,45 @@ |
||||
package mightypork.gamecore.gui.components.layout; |
||||
|
||||
|
||||
import mightypork.gamecore.app.AppAccess; |
||||
import mightypork.gamecore.gui.components.Component; |
||||
import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound; |
||||
|
||||
|
||||
public class RowLayout extends GridLayout { |
||||
|
||||
private int row = 0; |
||||
|
||||
|
||||
public RowLayout(AppAccess app, int rows) |
||||
{ |
||||
this(app, null, rows); |
||||
} |
||||
|
||||
|
||||
public RowLayout(AppAccess app, RectBound context, int rows) |
||||
{ |
||||
super(app, context, rows, 1); |
||||
} |
||||
|
||||
|
||||
public void add(final Component elem) |
||||
{ |
||||
add(elem, 1); |
||||
} |
||||
|
||||
|
||||
public void add(final Component elem, int rowSpan) |
||||
{ |
||||
if (elem == null) return; |
||||
|
||||
put(elem, row, 0, rowSpan, 1); |
||||
row += rowSpan; |
||||
} |
||||
|
||||
|
||||
public void skip(int rows) |
||||
{ |
||||
row += rows; |
||||
} |
||||
} |
@ -0,0 +1,156 @@ |
||||
package mightypork.rogue.screens.game; |
||||
|
||||
|
||||
import java.io.IOException; |
||||
|
||||
import mightypork.gamecore.gui.Action; |
||||
import mightypork.gamecore.gui.AlignX; |
||||
import mightypork.gamecore.gui.components.layout.ColumnLayout; |
||||
import mightypork.gamecore.gui.components.layout.RowLayout; |
||||
import mightypork.gamecore.gui.components.painters.QuadPainter; |
||||
import mightypork.gamecore.gui.components.painters.TextPainter; |
||||
import mightypork.gamecore.gui.screens.ScreenLayer; |
||||
import mightypork.gamecore.input.KeyStroke; |
||||
import mightypork.gamecore.input.Keys; |
||||
import mightypork.gamecore.logging.Log; |
||||
import mightypork.gamecore.resources.fonts.GLFont; |
||||
import mightypork.gamecore.util.math.Easing; |
||||
import mightypork.gamecore.util.math.color.pal.RGB; |
||||
import mightypork.gamecore.util.math.constraints.num.Num; |
||||
import mightypork.gamecore.util.math.constraints.num.mutable.NumAnimated; |
||||
import mightypork.gamecore.util.math.timing.TimedTask; |
||||
import mightypork.rogue.Res; |
||||
import mightypork.rogue.screens.PushButton; |
||||
import mightypork.rogue.screens.game.ScreenGame.GScrState; |
||||
import mightypork.rogue.world.WorldProvider; |
||||
|
||||
|
||||
public class AskSaveLayer extends ScreenLayer { |
||||
|
||||
public Runnable task; |
||||
|
||||
NumAnimated numa = new NumAnimated(0, Easing.QUADRATIC_OUT); |
||||
TimedTask hideTT = new TimedTask() { |
||||
|
||||
@Override |
||||
public void run() |
||||
{ |
||||
gscreen.setState(GScrState.WORLD); // go back..
|
||||
} |
||||
}; |
||||
|
||||
private final ScreenGame gscreen; |
||||
|
||||
|
||||
public void setTask(Runnable task) |
||||
{ |
||||
this.task = task; |
||||
} |
||||
|
||||
|
||||
public AskSaveLayer(final ScreenGame screen) |
||||
{ |
||||
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); |
||||
txp.setPaddingHPerc(0, 25); |
||||
|
||||
final ColumnLayout cl = new ColumnLayout(root, 21); |
||||
cl.skip(2); |
||||
rl.add(cl); |
||||
|
||||
final PushButton btn1 = new PushButton(thick_font, "Yes", ScreenGame.COLOR_BTN_GOOD); |
||||
btn1.textPainter.setAlign(AlignX.RIGHT); |
||||
btn1.textPainter.setPaddingHPerc(25, 20); |
||||
btn1.disableHover(); |
||||
cl.add(btn1, 6); |
||||
|
||||
final PushButton btn2 = new PushButton(thick_font, "No", ScreenGame.COLOR_BTN_BAD); |
||||
btn2.textPainter.setAlign(AlignX.CENTER); |
||||
btn2.textPainter.setPaddingHPerc(25, 20); |
||||
btn2.disableHover(); |
||||
cl.add(btn2, 3); |
||||
|
||||
final PushButton btn3 = new PushButton(thick_font, "Cancel", ScreenGame.COLOR_BTN_CANCEL); |
||||
btn3.textPainter.setAlign(AlignX.LEFT); |
||||
btn3.textPainter.setPaddingHPerc(25, 20); |
||||
btn3.disableHover(); |
||||
cl.add(btn3, 10); |
||||
|
||||
final Action cancel = new Action() { |
||||
|
||||
@Override |
||||
protected void execute() |
||||
{ |
||||
if (numa.isFinished()) { |
||||
numa.fadeOut(0.3); |
||||
hideTT.start(0.3); |
||||
} |
||||
} |
||||
}; |
||||
|
||||
btn1.setAction(new Action() { |
||||
|
||||
@Override |
||||
protected void execute() |
||||
{ |
||||
try { |
||||
WorldProvider.get().saveWorld(); |
||||
if (task != null) task.run(); |
||||
} catch (final IOException e) { |
||||
Log.e(e); |
||||
} |
||||
} |
||||
}); |
||||
|
||||
btn2.setAction(new Action() { |
||||
|
||||
@Override |
||||
protected void execute() |
||||
{ |
||||
if (task != null) task.run(); |
||||
} |
||||
}); |
||||
|
||||
btn3.setAction(cancel); |
||||
|
||||
bindKey(new KeyStroke(Keys.ESCAPE), cancel); |
||||
|
||||
updated.add(numa); |
||||
updated.add(hideTT); |
||||
|
||||
setAlpha(numa); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public int getZIndex() |
||||
{ |
||||
return 301; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void show() |
||||
{ |
||||
if (!isVisible()) { |
||||
super.show(); |
||||
numa.fadeIn(0.3); |
||||
hideTT.stop(); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,95 @@ |
||||
package mightypork.rogue.screens.game; |
||||
|
||||
|
||||
import java.io.IOException; |
||||
|
||||
import mightypork.gamecore.gui.Action; |
||||
import mightypork.gamecore.gui.AlignX; |
||||
import mightypork.gamecore.gui.components.layout.ColumnLayout; |
||||
import mightypork.gamecore.gui.components.layout.RowLayout; |
||||
import mightypork.gamecore.gui.components.painters.ImagePainter; |
||||
import mightypork.gamecore.gui.components.painters.QuadPainter; |
||||
import mightypork.gamecore.gui.components.painters.TextPainter; |
||||
import mightypork.gamecore.gui.screens.ScreenLayer; |
||||
import mightypork.gamecore.logging.Log; |
||||
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.GameStateManager.GameState; |
||||
import mightypork.rogue.Res; |
||||
import mightypork.rogue.events.GameStateRequest; |
||||
import mightypork.rogue.screens.PushButton; |
||||
import mightypork.rogue.screens.game.ScreenGame.GScrState; |
||||
import mightypork.rogue.world.WorldProvider; |
||||
|
||||
|
||||
public class DeathLayer extends ScreenLayer { |
||||
|
||||
public DeathLayer(final ScreenGame screen) |
||||
{ |
||||
super(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, 5); |
||||
rl.setRect(root.shrink(Num.ZERO, root.height().perc(20))); |
||||
root.add(rl); |
||||
|
||||
final TextPainter txp = new TextPainter(thick_font, AlignX.CENTER, RGB.YELLOW, "You're dead!"); |
||||
rl.add(txp, 1); |
||||
txp.setPaddingHPerc(0, 15); |
||||
|
||||
final ImagePainter img = new ImagePainter(Res.getTxQuad("death")); |
||||
img.keepAspectRatio(); |
||||
rl.add(img, 3); |
||||
|
||||
final ColumnLayout cl = new ColumnLayout(root, 2); |
||||
rl.add(cl); |
||||
|
||||
final PushButton btn1 = new PushButton(thick_font, "Retry", ScreenGame.COLOR_BTN_GOOD); |
||||
btn1.textPainter.setAlign(AlignX.RIGHT); |
||||
btn1.textPainter.setPaddingHPerc(20, 25); |
||||
cl.add(btn1); |
||||
|
||||
final PushButton btn2 = new PushButton(thick_font, "Quit", ScreenGame.COLOR_BTN_BAD); |
||||
btn2.textPainter.setAlign(AlignX.LEFT); |
||||
btn2.textPainter.setPaddingHPerc(20, 25); |
||||
cl.add(btn2); |
||||
|
||||
btn1.setAction(new Action() { |
||||
|
||||
@Override |
||||
protected void execute() |
||||
{ |
||||
try { |
||||
WorldProvider.get().loadWorld(WorldProvider.get().getWorld().getSaveFile()); |
||||
screen.setState(GScrState.WORLD); |
||||
} catch (final IOException e) { |
||||
Log.e(e); |
||||
} |
||||
} |
||||
}); |
||||
|
||||
btn2.setAction(new Action() { |
||||
|
||||
@Override |
||||
protected void execute() |
||||
{ |
||||
getEventBus().send(new GameStateRequest(GameState.MAIN_MENU)); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public int getZIndex() |
||||
{ |
||||
return 300; |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue