parent
fa1d2b577b
commit
06c7303988
@ -0,0 +1,55 @@ |
||||
package mightypork.rogue; |
||||
|
||||
|
||||
import mightypork.gamecore.app.AppAccess; |
||||
import mightypork.gamecore.app.AppModule; |
||||
import mightypork.gamecore.gui.events.CrossfadeRequest; |
||||
import mightypork.gamecore.logging.Log; |
||||
import mightypork.rogue.world.WorldProvider; |
||||
|
||||
|
||||
public class GameStateManager extends AppModule { |
||||
|
||||
public GameStateManager(AppAccess app) |
||||
{ |
||||
super(app); |
||||
} |
||||
|
||||
public static enum GameState |
||||
{ |
||||
MAIN_MENU, SELECT_WORLD, PLAY_WORLD, EXIT |
||||
} |
||||
|
||||
|
||||
public void triggerAction(GameState state) |
||||
{ |
||||
switch (state) { |
||||
case MAIN_MENU: |
||||
getEventBus().send(new CrossfadeRequest("main_menu")); |
||||
break; |
||||
|
||||
case SELECT_WORLD: |
||||
getEventBus().send(new CrossfadeRequest("select_world")); |
||||
break; |
||||
|
||||
case PLAY_WORLD: |
||||
|
||||
if (WorldProvider.get().getWorld() == null) { |
||||
Log.w("WorldProvider has no world."); |
||||
} |
||||
|
||||
getEventBus().send(new CrossfadeRequest("game")); |
||||
break; |
||||
|
||||
case EXIT: |
||||
getEventBus().send(new CrossfadeRequest(null)); |
||||
break; |
||||
|
||||
default: |
||||
Log.w("Unknown action: " + state); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,25 @@ |
||||
package mightypork.rogue.events; |
||||
|
||||
|
||||
import mightypork.gamecore.eventbus.BusEvent; |
||||
import mightypork.rogue.GameStateManager; |
||||
import mightypork.rogue.GameStateManager.GameState; |
||||
|
||||
|
||||
public class GameStateRequest extends BusEvent<GameStateManager> { |
||||
|
||||
final private GameState requested; |
||||
|
||||
|
||||
public GameStateRequest(GameState requested) |
||||
{ |
||||
this.requested = requested; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected void handleBy(GameStateManager handler) |
||||
{ |
||||
handler.triggerAction(requested); |
||||
} |
||||
} |
@ -1,101 +0,0 @@ |
||||
package mightypork.rogue.screens.menu; |
||||
|
||||
|
||||
import mightypork.gamecore.gui.Action; |
||||
import mightypork.gamecore.gui.components.layout.GridLayout; |
||||
import mightypork.gamecore.gui.components.painters.ImagePainter; |
||||
import mightypork.gamecore.gui.components.painters.QuadPainter; |
||||
import mightypork.gamecore.gui.events.CrossfadeRequest; |
||||
import mightypork.gamecore.gui.screens.Screen; |
||||
import mightypork.gamecore.gui.screens.ScreenLayer; |
||||
import mightypork.gamecore.util.math.color.Color; |
||||
import mightypork.gamecore.util.math.color.pal.PAL16; |
||||
import mightypork.gamecore.util.math.constraints.num.Num; |
||||
import mightypork.gamecore.util.math.constraints.rect.Rect; |
||||
import mightypork.rogue.Res; |
||||
|
||||
|
||||
class MenuLayer extends ScreenLayer { |
||||
|
||||
public MenuLayer(Screen screen) |
||||
{ |
||||
super(screen); |
||||
|
||||
init(); |
||||
} |
||||
|
||||
|
||||
private void init() |
||||
{ |
||||
final Rect menuBox = root.shrink(Num.ZERO, root.height().mul(0.15)).moveY(root.height().mul(-0.04)); |
||||
|
||||
final GridLayout layout = new GridLayout(root, menuBox, 11, 1); |
||||
layout.enableCaching(true); |
||||
|
||||
final QuadPainter bg = QuadPainter.gradV(Color.fromHex(0x007eb3), PAL16.SEABLUE); |
||||
bg.setRect(root); |
||||
root.add(bg); |
||||
|
||||
root.add(layout); |
||||
|
||||
int r = 0; |
||||
final ImagePainter ip = new ImagePainter(Res.txq("logo")); |
||||
ip.keepAspectRatio(); |
||||
layout.put(ip, r, 0, 5, 1); |
||||
r += 6; |
||||
|
||||
MenuButton btn; |
||||
|
||||
|
||||
// world button
|
||||
btn = new MenuButton("Game", PAL16.SLIMEGREEN); |
||||
btn.setAction(new Action() { |
||||
|
||||
@Override |
||||
protected void execute() |
||||
{ |
||||
getEventBus().send(new CrossfadeRequest("game")); |
||||
} |
||||
}); |
||||
layout.put(btn, r, 0, 2, 1); |
||||
r += 3; |
||||
|
||||
/* |
||||
// bouncy text button
|
||||
btn = new MenuButton("Bouncy", PAL16.CLOUDBLUE); |
||||
btn.setAction(new Action() { |
||||
|
||||
@Override |
||||
protected void execute() |
||||
{ |
||||
getEventBus().send(new CrossfadeRequest("test.bouncy")); |
||||
} |
||||
}); |
||||
layout.put(btn, r, 0, 2, 1); |
||||
r += 3; |
||||
*/ |
||||
|
||||
// quit button
|
||||
btn = new MenuButton("Bye!", PAL16.BLOODRED); |
||||
btn.setAction(new Action() { |
||||
|
||||
@Override |
||||
protected void execute() |
||||
{ |
||||
getEventBus().send(new CrossfadeRequest(null)); // null -> fade and halt
|
||||
} |
||||
}); |
||||
layout.put(btn, r, 0, 2, 1); |
||||
|
||||
|
||||
root.add(layout); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public int getZIndex() |
||||
{ |
||||
return 2; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,65 @@ |
||||
package mightypork.rogue.screens.select_world; |
||||
|
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Collection; |
||||
import java.util.List; |
||||
|
||||
import mightypork.gamecore.eventbus.clients.DelegatingClient; |
||||
import mightypork.gamecore.gui.components.ClickableComponent; |
||||
import mightypork.gamecore.gui.components.Component; |
||||
|
||||
|
||||
public class ClickableWrapper extends ClickableComponent implements DelegatingClient { |
||||
|
||||
|
||||
private final Component wrapped; |
||||
private final List<Component> list; |
||||
|
||||
|
||||
public ClickableWrapper(Component wrapped) |
||||
{ |
||||
this.wrapped = wrapped; |
||||
wrapped.setRect(this); |
||||
|
||||
list = new ArrayList<>(1); |
||||
list.add(wrapped); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public Collection<?> getChildClients() |
||||
{ |
||||
return list; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public boolean doesDelegate() |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public boolean isEnabled() |
||||
{ |
||||
return super.isEnabled() && wrapped.isEnabled(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void enable(boolean yes) |
||||
{ |
||||
super.enable(yes); |
||||
wrapped.enable(yes); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected void renderComponent() |
||||
{ |
||||
wrapped.render(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,86 @@ |
||||
package mightypork.rogue.screens.select_world; |
||||
|
||||
|
||||
import mightypork.gamecore.app.AppAccess; |
||||
import mightypork.gamecore.gui.AlignX; |
||||
import mightypork.gamecore.gui.components.layout.GridLayout; |
||||
import mightypork.gamecore.gui.components.painters.QuadPainter; |
||||
import mightypork.gamecore.gui.components.painters.TextPainter; |
||||
import mightypork.gamecore.gui.screens.LayeredScreen; |
||||
import mightypork.gamecore.gui.screens.Screen; |
||||
import mightypork.gamecore.gui.screens.ScreenLayer; |
||||
import mightypork.gamecore.util.math.color.Color; |
||||
import mightypork.gamecore.util.math.color.pal.PAL16; |
||||
import mightypork.gamecore.util.math.color.pal.RGB; |
||||
import mightypork.gamecore.util.math.constraints.rect.Rect; |
||||
import mightypork.rogue.Paths; |
||||
import mightypork.rogue.Res; |
||||
|
||||
|
||||
/** |
||||
* Main menu screen |
||||
* |
||||
* @author MightyPork |
||||
*/ |
||||
public class ScreenSelectWorld extends LayeredScreen { |
||||
|
||||
|
||||
public ScreenSelectWorld(AppAccess app) |
||||
{ |
||||
super(app); |
||||
|
||||
addLayer(new WorldsLayer(this)); |
||||
} |
||||
|
||||
|
||||
class WorldsLayer extends ScreenLayer { |
||||
|
||||
public WorldsLayer(Screen screen) |
||||
{ |
||||
super(screen); |
||||
|
||||
init(); |
||||
} |
||||
|
||||
|
||||
private void init() |
||||
{ |
||||
final Rect menuBox = root.shrink(root.width().perc(25), root.height().perc(20)); |
||||
|
||||
|
||||
final QuadPainter bg = QuadPainter.gradV(Color.fromHex(0x007eb3), PAL16.SEABLUE); |
||||
bg.setRect(root); |
||||
root.add(bg); |
||||
|
||||
final GridLayout layout = new GridLayout(root, menuBox, 7, 1); |
||||
layout.enableCaching(true); |
||||
root.add(layout); |
||||
|
||||
TextPainter tp; |
||||
|
||||
layout.put(tp = new TextPainter(Res.getFont("thick"), AlignX.CENTER, RGB.YELLOW, "Save slot:"), 0, 0, 1, 1); |
||||
tp.setPaddingHPerc(0, 20); |
||||
tp.setShadow(RGB.BLACK_50, tp.height().mul(0.6 / 8D).toVectXY()); |
||||
|
||||
|
||||
WorldSlot wsl; |
||||
|
||||
wsl = new WorldSlot(root, Paths.SAVE_SLOT_1); |
||||
layout.put(wsl, 1, 0, 1, 1); |
||||
|
||||
wsl = new WorldSlot(root, Paths.SAVE_SLOT_2); |
||||
layout.put(wsl, 2, 0, 1, 1); |
||||
|
||||
wsl = new WorldSlot(root, Paths.SAVE_SLOT_3); |
||||
layout.put(wsl, 3, 0, 1, 1); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public int getZIndex() |
||||
{ |
||||
return 2; |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,132 @@ |
||||
package mightypork.rogue.screens.select_world; |
||||
|
||||
|
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
|
||||
import mightypork.gamecore.app.AppAccess; |
||||
import mightypork.gamecore.gui.Action; |
||||
import mightypork.gamecore.gui.AlignX; |
||||
import mightypork.gamecore.gui.components.layout.ConstraintLayout; |
||||
import mightypork.gamecore.gui.components.layout.GridLayout; |
||||
import mightypork.gamecore.gui.components.painters.QuadPainter; |
||||
import mightypork.gamecore.gui.components.painters.TextPainter; |
||||
import mightypork.gamecore.resources.fonts.GLFont; |
||||
import mightypork.gamecore.util.ion.Ion; |
||||
import mightypork.gamecore.util.ion.IonBundle; |
||||
import mightypork.gamecore.util.math.color.pal.RGB; |
||||
import mightypork.gamecore.util.math.constraints.num.Num; |
||||
import mightypork.gamecore.util.math.constraints.rect.Rect; |
||||
import mightypork.gamecore.util.strings.StringProvider; |
||||
import mightypork.rogue.GameStateManager.GameState; |
||||
import mightypork.rogue.Res; |
||||
import mightypork.rogue.events.GameStateRequest; |
||||
import mightypork.rogue.world.World; |
||||
import mightypork.rogue.world.WorldProvider; |
||||
|
||||
|
||||
public class WorldSlot extends ConstraintLayout { |
||||
|
||||
private final StringProvider lblStrp = new StringProvider() { |
||||
|
||||
@Override |
||||
public String getString() |
||||
{ |
||||
return label; |
||||
} |
||||
}; |
||||
|
||||
private File file; |
||||
private String label; |
||||
|
||||
private IonBundle worldBundle; |
||||
|
||||
|
||||
public WorldSlot(AppAccess app, File worldFile) |
||||
{ |
||||
super(app); |
||||
|
||||
this.file = worldFile; |
||||
|
||||
final Rect innerRect = shrink(height().perc(5)); |
||||
|
||||
final QuadPainter qp = new QuadPainter(RGB.BLACK.withAlpha(new Num() { |
||||
|
||||
@Override |
||||
public double value() |
||||
{ |
||||
return isMouseOver() ? 0.2 : 0.1; |
||||
} |
||||
})); |
||||
|
||||
|
||||
qp.setRect(innerRect); |
||||
add(qp); |
||||
|
||||
|
||||
final GridLayout gridl = new GridLayout(app, 1, 8); |
||||
gridl.setRect(innerRect.shrink(width().perc(10), Num.ZERO)); |
||||
add(gridl); |
||||
|
||||
TextPainter tp; |
||||
ClickableWrapper btn; |
||||
final GLFont font = Res.getFont("thick"); |
||||
|
||||
tp = new TextPainter(font, AlignX.LEFT, RGB.WHITE, lblStrp); |
||||
tp.setPaddingHPerc(0, 20); |
||||
|
||||
gridl.put(btn = new ClickableWrapper(tp), 0, 0, 1, 7); |
||||
btn.setAction(new Action() { |
||||
|
||||
@Override |
||||
protected void execute() |
||||
{ |
||||
try { |
||||
final World w = new World(); |
||||
w.setSaveFile(file); |
||||
w.load(worldBundle); |
||||
WorldProvider.get().setWorld(w); |
||||
} catch (final Exception e) { |
||||
WorldProvider.get().createWorld(Double.doubleToLongBits(Math.random())); |
||||
} |
||||
|
||||
getEventBus().send(new GameStateRequest(GameState.PLAY_WORLD)); |
||||
} |
||||
}); |
||||
|
||||
tp = new TextPainter(font, AlignX.LEFT, RGB.RED, "X"); |
||||
tp.setPaddingHPerc(0, 20); |
||||
gridl.put(btn = new ClickableWrapper(tp), 0, 7, 1, 1); |
||||
btn.setAction(new Action() { |
||||
|
||||
@Override |
||||
protected void execute() |
||||
{ |
||||
file.delete(); |
||||
refresh(); |
||||
} |
||||
}); |
||||
|
||||
refresh(); |
||||
} |
||||
|
||||
|
||||
public void refresh() |
||||
{ |
||||
if (!file.exists()) { |
||||
label = "<empty>"; |
||||
} else { |
||||
try { |
||||
worldBundle = Ion.fromFile(file); |
||||
final int lvl = worldBundle.get("meta.last_level", -1); |
||||
|
||||
if (lvl == -1) throw new RuntimeException(); // let the catch block handle it
|
||||
|
||||
label = "Floor " + (lvl + 1); |
||||
} catch (final IOException e) { |
||||
label = "<corrupt>"; |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,76 +0,0 @@ |
||||
package mightypork.rogue.screens.test_bouncyboxes; |
||||
|
||||
|
||||
import java.util.Random; |
||||
|
||||
import mightypork.gamecore.eventbus.events.Updateable; |
||||
import mightypork.gamecore.gui.components.BaseComponent; |
||||
import mightypork.gamecore.render.Render; |
||||
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.constraints.rect.Rect; |
||||
import mightypork.gamecore.util.math.constraints.rect.caching.RectCache; |
||||
|
||||
|
||||
public class BouncyBox extends BaseComponent implements Updateable { |
||||
|
||||
private final Random rand = new Random(); |
||||
|
||||
private final RectCache box; |
||||
|
||||
private final NumAnimated pos = new NumAnimated(0, Easing.BOUNCE_OUT); |
||||
|
||||
|
||||
public BouncyBox() |
||||
{ |
||||
super(); |
||||
enableCaching(true); |
||||
|
||||
Rect abox; |
||||
|
||||
abox = leftEdge().growRight(height()); |
||||
abox = abox.move(width().sub(height()).mul(pos), Num.ZERO); |
||||
abox = abox.shrink(height().perc(10)); |
||||
|
||||
box = abox.cached(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void renderComponent() |
||||
{ |
||||
Render.quad(box, RGB.GREEN); |
||||
} |
||||
|
||||
|
||||
public void goLeft() |
||||
{ |
||||
pos.animate(1, 0, 1 + rand.nextDouble() * 1); |
||||
} |
||||
|
||||
|
||||
public void goRight() |
||||
{ |
||||
pos.animate(0, 1, 1 + rand.nextDouble() * 1); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void update(double delta) |
||||
{ |
||||
if (pos.isInProgress()) { |
||||
pos.update(delta); |
||||
box.poll(); |
||||
} |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void updateLayout() |
||||
{ |
||||
box.poll(); |
||||
} |
||||
|
||||
} |
@ -1,88 +0,0 @@ |
||||
package mightypork.rogue.screens.test_bouncyboxes; |
||||
|
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import mightypork.gamecore.gui.AlignX; |
||||
import mightypork.gamecore.gui.components.layout.RowHolder; |
||||
import mightypork.gamecore.gui.components.painters.TextPainter; |
||||
import mightypork.gamecore.gui.screens.Screen; |
||||
import mightypork.gamecore.gui.screens.ScreenLayer; |
||||
import mightypork.gamecore.input.KeyStroke; |
||||
import mightypork.gamecore.input.Keys; |
||||
import mightypork.gamecore.util.math.color.pal.RGB; |
||||
import mightypork.gamecore.util.math.constraints.num.Num; |
||||
import mightypork.gamecore.util.math.constraints.vect.Vect; |
||||
import mightypork.rogue.Res; |
||||
|
||||
|
||||
public class LayerBouncyBoxes extends ScreenLayer { |
||||
|
||||
List<BouncyBox> boxes = new ArrayList<>(); |
||||
private RowHolder layout; |
||||
|
||||
|
||||
public LayerBouncyBoxes(Screen screen) |
||||
{ |
||||
super(screen); |
||||
|
||||
bindKey(new KeyStroke(true, Keys.RIGHT), new Runnable() { |
||||
|
||||
@Override |
||||
public void run() |
||||
{ |
||||
goRight(); |
||||
} |
||||
}); |
||||
|
||||
bindKey(new KeyStroke(true, Keys.LEFT), new Runnable() { |
||||
|
||||
@Override |
||||
public void run() |
||||
{ |
||||
goLeft(); |
||||
} |
||||
}); |
||||
|
||||
// shrink screen rect by 8% on all sides
|
||||
|
||||
root.add(layout = new RowHolder(this, root.shrink(root.height().perc(5)), 10)); |
||||
|
||||
for (int i = 0; i < 9; i++) { |
||||
final BouncyBox bbr = new BouncyBox(); |
||||
layout.add(bbr); |
||||
boxes.add(bbr); |
||||
} |
||||
|
||||
final TextPainter tp = new TextPainter(Res.getFont("thick"), AlignX.LEFT, RGB.WHITE); |
||||
tp.setText("Press left & right to move."); |
||||
final Num shadowOffset = tp.height().div(16); |
||||
tp.setShadow(RGB.RED, Vect.make(shadowOffset, shadowOffset)); |
||||
|
||||
layout.add(tp); |
||||
} |
||||
|
||||
|
||||
public void goLeft() |
||||
{ |
||||
for (final BouncyBox bbr : boxes) { |
||||
bbr.goLeft(); |
||||
} |
||||
} |
||||
|
||||
|
||||
public void goRight() |
||||
{ |
||||
for (final BouncyBox bbr : boxes) { |
||||
bbr.goRight(); |
||||
} |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public int getZIndex() |
||||
{ |
||||
return 0; |
||||
} |
||||
} |
@ -1,17 +0,0 @@ |
||||
package mightypork.rogue.screens.test_bouncyboxes; |
||||
|
||||
|
||||
import mightypork.gamecore.app.AppAccess; |
||||
import mightypork.gamecore.gui.screens.LayeredScreen; |
||||
|
||||
|
||||
public class ScreenTestBouncy extends LayeredScreen { |
||||
|
||||
public ScreenTestBouncy(AppAccess app) |
||||
{ |
||||
super(app); |
||||
|
||||
addLayer(new LayerBouncyBoxes(this)); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue