World loading screen

v5stable
ondra 11 years ago
parent 021c68bc69
commit 8d23f7959c
  1. 2
      src/mightypork/gamecore/gui/components/layout/ClickableWrapper.java
  2. 4
      src/mightypork/gamecore/gui/events/ScreenRequest.java
  3. 2
      src/mightypork/gamecore/gui/events/ScreenRequestListener.java
  4. 4
      src/mightypork/gamecore/gui/screens/impl/CrossfadeOverlay.java
  5. 4
      src/mightypork/gamecore/input/KeyBinding.java
  6. 2
      src/mightypork/gamecore/util/math/constraints/num/Num.java
  7. 2
      src/mightypork/rogue/App.java
  8. 5
      src/mightypork/rogue/GameStateManager.java
  9. 32
      src/mightypork/rogue/screens/LoaderRequest.java
  10. 91
      src/mightypork/rogue/screens/LoadingOverlay.java
  11. 49
      src/mightypork/rogue/screens/select_world/WorldSlot.java

@ -1,4 +1,4 @@
package mightypork.rogue.screens.select_world; package mightypork.gamecore.gui.components.layout;
import java.util.ArrayList; import java.util.ArrayList;

@ -11,7 +11,7 @@ import mightypork.gamecore.eventbus.event_flags.SingleReceiverEvent;
* @author MightyPork * @author MightyPork
*/ */
@SingleReceiverEvent @SingleReceiverEvent
public class ScreenRequestEvent extends BusEvent<ScreenRequestListener> { public class ScreenRequest extends BusEvent<ScreenRequestListener> {
private final String scrName; private final String scrName;
@ -19,7 +19,7 @@ public class ScreenRequestEvent extends BusEvent<ScreenRequestListener> {
/** /**
* @param screenKey screen name * @param screenKey screen name
*/ */
public ScreenRequestEvent(String screenKey) public ScreenRequest(String screenKey)
{ {
scrName = screenKey; scrName = screenKey;
} }

@ -2,7 +2,7 @@ package mightypork.gamecore.gui.events;
/** /**
* {@link ScreenRequestEvent} listener * {@link ScreenRequest} listener
* *
* @author MightyPork * @author MightyPork
*/ */

@ -3,7 +3,7 @@ package mightypork.gamecore.gui.screens.impl;
import mightypork.gamecore.app.AppAccess; import mightypork.gamecore.app.AppAccess;
import mightypork.gamecore.gui.components.painters.QuadPainter; import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.events.ScreenRequestEvent; import mightypork.gamecore.gui.events.ScreenRequest;
import mightypork.gamecore.gui.screens.Overlay; import mightypork.gamecore.gui.screens.Overlay;
import mightypork.gamecore.util.math.Easing; import mightypork.gamecore.util.math.Easing;
import mightypork.gamecore.util.math.color.Color; import mightypork.gamecore.util.math.color.Color;
@ -31,7 +31,7 @@ public class CrossfadeOverlay extends Overlay {
if (requestedScreenName == null) { if (requestedScreenName == null) {
getEventBus().send(new ActionRequest(RequestType.SHUTDOWN)); getEventBus().send(new ActionRequest(RequestType.SHUTDOWN));
} else { } else {
getEventBus().send(new ScreenRequestEvent(requestedScreenName)); getEventBus().send(new ScreenRequest(requestedScreenName));
} }
blackLevel.setEasing(Easing.SINE_OUT); blackLevel.setEasing(Easing.SINE_OUT);
blackLevel.fadeOut(T_OUT); blackLevel.fadeOut(T_OUT);

@ -3,6 +3,7 @@ package mightypork.gamecore.input;
import mightypork.gamecore.input.events.KeyEvent; import mightypork.gamecore.input.events.KeyEvent;
import mightypork.gamecore.input.events.KeyListener; import mightypork.gamecore.input.events.KeyListener;
import mightypork.gamecore.logging.Log;
/** /**
@ -54,8 +55,11 @@ public class KeyBinding implements KeyListener {
@Override @Override
public void receive(KeyEvent event) public void receive(KeyEvent event)
{ {
/*Log.f3("evt k="+event.getKey()+", c="+(int)event.getChar());
// ignore unrelated events // ignore unrelated events
if (!keystroke.getKeys().contains(event.getKey())) return; if (!keystroke.getKeys().contains(event.getKey())) return;
*/
// run handler when event was met // run handler when event was met
if (keystroke.isActive() && !wasActive) { if (keystroke.isActive() && !wasActive) {

@ -307,7 +307,7 @@ public abstract class Num implements NumBound, Digestable<NumDigest> {
public Num perc(final double percent) public Num perc(final double percent)
{ {
return mul(percent / 100); return mul(percent / 100D);
} }

@ -22,6 +22,7 @@ import mightypork.rogue.events.ActionRequest;
import mightypork.rogue.events.ActionRequest.RequestType; import mightypork.rogue.events.ActionRequest.RequestType;
import mightypork.rogue.events.GameStateRequest; import mightypork.rogue.events.GameStateRequest;
import mightypork.rogue.screens.FpsOverlay; import mightypork.rogue.screens.FpsOverlay;
import mightypork.rogue.screens.LoadingOverlay;
import mightypork.rogue.screens.game.ScreenGame; import mightypork.rogue.screens.game.ScreenGame;
import mightypork.rogue.screens.menu.ScreenMainMenu; import mightypork.rogue.screens.menu.ScreenMainMenu;
import mightypork.rogue.screens.select_world.ScreenSelectWorld; import mightypork.rogue.screens.select_world.ScreenSelectWorld;
@ -120,6 +121,7 @@ public final class App extends BaseApp {
screens.addScreen("game", new ScreenGame(this)); screens.addScreen("game", new ScreenGame(this));
screens.addOverlay(new FpsOverlay(this)); screens.addOverlay(new FpsOverlay(this));
screens.addOverlay(new LoadingOverlay(this));
} }

@ -33,11 +33,6 @@ public class GameStateManager extends AppModule {
break; break;
case PLAY_WORLD: case PLAY_WORLD:
if (WorldProvider.get().getWorld() == null) {
Log.w("WorldProvider has no world.");
}
getEventBus().send(new CrossfadeRequest("game")); getEventBus().send(new CrossfadeRequest("game"));
break; break;

@ -0,0 +1,32 @@
package mightypork.rogue.screens;
import mightypork.gamecore.eventbus.BusEvent;
public class LoaderRequest extends BusEvent<LoadingOverlay> {
private final boolean show;
private final String msg;
public LoaderRequest(boolean show, String msg) {
this.show = show;
this.msg = msg;
}
public LoaderRequest(boolean show) {
this.show = show;
this.msg = null;
}
@Override
protected void handleBy(LoadingOverlay handler)
{
if(show) {
handler.show(msg);
}else {
handler.hide();
}
}
}

@ -0,0 +1,91 @@
package mightypork.rogue.screens;
import mightypork.gamecore.app.AppAccess;
import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.events.ScreenRequest;
import mightypork.gamecore.gui.screens.Overlay;
import mightypork.gamecore.util.math.Easing;
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.num.Num;
import mightypork.gamecore.util.math.constraints.num.mutable.NumAnimated;
import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.gamecore.util.math.timing.TimedTask;
import mightypork.gamecore.util.strings.StringProvider;
import mightypork.rogue.Res;
import mightypork.rogue.events.ActionRequest;
import mightypork.rogue.events.ActionRequest.RequestType;
public class LoadingOverlay extends Overlay {
private static final double T_IN = 0.5;
private static final double T_OUT = 1;
private final NumAnimated alpha = new NumAnimated(0);
private final StringProvider msgStrProv = new StringProvider() {
@Override
public String getString()
{
return msg == null ? "" : msg;
}
};
private String msg;
public LoadingOverlay(AppAccess app) {
super(app);
final QuadPainter qp = new QuadPainter(PAL16.SEABLUE);
qp.setRect(root);
root.add(qp);
updated.add(alpha);
Rect textRect = root.shrink(Num.ZERO, root.height().perc(48));
textRect = textRect.moveY(root.height().perc(-10));
final TextPainter tp = new TextPainter(Res.getFont("thick"), AlignX.CENTER, RGB.WHITE, msgStrProv);
tp.setRect(textRect);
tp.setShadow(RGB.BLACK_60, tp.height().mul(1/8D).toVectXY());
root.add(tp);
}
@Override
public int getZIndex()
{
return 10001; // not too high, so app can put something on top
}
public void show(String message)
{
this.msg = message;
alpha.setEasing(Easing.SINE_IN);
alpha.fadeIn(T_IN);
}
public void hide()
{
alpha.setEasing(Easing.SINE_OUT);
alpha.fadeOut(T_OUT);
}
@Override
public void render()
{
Color.pushAlpha(alpha);
super.render();
Color.popAlpha();
}
}

@ -7,11 +7,15 @@ import java.io.IOException;
import mightypork.gamecore.app.AppAccess; import mightypork.gamecore.app.AppAccess;
import mightypork.gamecore.gui.Action; import mightypork.gamecore.gui.Action;
import mightypork.gamecore.gui.AlignX; import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.layout.ClickableWrapper;
import mightypork.gamecore.gui.components.layout.ConstraintLayout; import mightypork.gamecore.gui.components.layout.ConstraintLayout;
import mightypork.gamecore.gui.components.layout.GridLayout; import mightypork.gamecore.gui.components.layout.GridLayout;
import mightypork.gamecore.gui.components.painters.QuadPainter; import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.components.painters.TextPainter; import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.events.CrossfadeRequest;
import mightypork.gamecore.gui.events.ScreenRequest;
import mightypork.gamecore.resources.fonts.GLFont; import mightypork.gamecore.resources.fonts.GLFont;
import mightypork.gamecore.util.Utils;
import mightypork.gamecore.util.ion.Ion; import mightypork.gamecore.util.ion.Ion;
import mightypork.gamecore.util.ion.IonBundle; import mightypork.gamecore.util.ion.IonBundle;
import mightypork.gamecore.util.math.color.pal.RGB; import mightypork.gamecore.util.math.color.pal.RGB;
@ -21,6 +25,7 @@ import mightypork.gamecore.util.strings.StringProvider;
import mightypork.rogue.GameStateManager.GameState; import mightypork.rogue.GameStateManager.GameState;
import mightypork.rogue.Res; import mightypork.rogue.Res;
import mightypork.rogue.events.GameStateRequest; import mightypork.rogue.events.GameStateRequest;
import mightypork.rogue.screens.LoaderRequest;
import mightypork.rogue.world.World; import mightypork.rogue.world.World;
import mightypork.rogue.world.WorldProvider; import mightypork.rogue.world.WorldProvider;
@ -42,8 +47,7 @@ public class WorldSlot extends ConstraintLayout {
private IonBundle worldBundle; private IonBundle worldBundle;
public WorldSlot(AppAccess app, File worldFile) public WorldSlot(AppAccess app, File worldFile) {
{
super(app); super(app);
this.file = worldFile; this.file = worldFile;
@ -59,11 +63,9 @@ public class WorldSlot extends ConstraintLayout {
} }
})); }));
qp.setRect(innerRect); qp.setRect(innerRect);
add(qp); add(qp);
final GridLayout gridl = new GridLayout(app, 1, 8); final GridLayout gridl = new GridLayout(app, 1, 8);
gridl.setRect(innerRect.shrink(width().perc(10), Num.ZERO)); gridl.setRect(innerRect.shrink(width().perc(10), Num.ZERO));
add(gridl); add(gridl);
@ -81,16 +83,37 @@ public class WorldSlot extends ConstraintLayout {
@Override @Override
protected void execute() protected void execute()
{ {
try { String msg;
final World w = new World();
w.setSaveFile(file); if (worldBundle != null) {
w.load(worldBundle); msg = "Loading world...";
WorldProvider.get().setWorld(w); } else {
} catch (final Exception e) { msg = "Creating world...";
WorldProvider.get().createWorld(Double.doubleToLongBits(Math.random()));
} }
getEventBus().send(new GameStateRequest(GameState.PLAY_WORLD)); getEventBus().send(new LoaderRequest(true, msg));
Utils.runAsThread(new Runnable() {
@Override
public void run()
{
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 LoaderRequest(false));
//getEventBus().send(new GameStateRequest(GameState.PLAY_WORLD));
getEventBus().send(new ScreenRequest("game"));
}
});
} }
}); });
@ -121,7 +144,7 @@ public class WorldSlot extends ConstraintLayout {
final int lvl = worldBundle.get("meta.last_level", -1); final int lvl = worldBundle.get("meta.last_level", -1);
if (lvl == -1) throw new RuntimeException(); // let the catch block handle it if (lvl == -1) throw new RuntimeException(); // let the catch block handle it
label = "Floor " + (lvl + 1); label = "Floor " + (lvl + 1);
} catch (final IOException e) { } catch (final IOException e) {
label = "<corrupt>"; label = "<corrupt>";

Loading…
Cancel
Save