From 56b61e59363dd34ae98152e1b82eb49d188990e3 Mon Sep 17 00:00:00 2001 From: ondra Date: Wed, 16 Apr 2014 16:00:30 +0200 Subject: [PATCH] overlays system --- src/mightypork/gamecore/control/BaseApp.java | 2 +- src/mightypork/gamecore/control/GameLoop.java | 2 +- ...ngeEvent.java => ViewportChangeEvent.java} | 10 +- .../gui/components/PluggableRenderable.java | 1 + .../gui/components/VisualComponent.java | 3 +- .../gamecore/gui/screens/BaseScreen.java | 160 ++++++++++++++++++ .../gamecore/gui/screens/LayeredScreen.java | 25 +-- .../gamecore/gui/screens/Overlay.java | 140 +++++++++++++++ .../gamecore/gui/screens/Screen.java | 151 +---------------- .../gamecore/gui/screens/ScreenLayer.java | 122 +------------ .../gamecore/gui/screens/ScreenRegistry.java | 47 ++++- .../gamecore/render/DisplaySystem.java | 6 +- .../components => render}/Renderable.java | 4 +- src/mightypork/rogue/App.java | 8 +- src/mightypork/rogue/screens/LayerFps.java | 11 +- .../rogue/screens/main_menu/MenuLayer.java | 4 +- .../test_bouncyboxes/LayerBouncyBoxes.java | 4 +- .../screens/test_cat_sound/LayerColor.java | 4 +- .../test_cat_sound/LayerFlyingCat.java | 4 +- .../test_render/LayerTestGradient.java | 6 +- .../util/constraints/ConstraintCache.java | 2 +- .../num/caching/AbstractNumCache.java | 4 +- .../constraints/num/caching/NumCache.java | 2 +- .../rect/caching/AbstractRectCache.java | 2 +- .../constraints/rect/caching/RectCache.java | 2 +- .../vect/caching/AbstractVectCache.java | 2 +- .../constraints/vect/caching/VectCache.java | 2 +- 27 files changed, 386 insertions(+), 344 deletions(-) rename src/mightypork/gamecore/control/events/{ScreenChangeEvent.java => ViewportChangeEvent.java} (79%) create mode 100644 src/mightypork/gamecore/gui/screens/BaseScreen.java create mode 100644 src/mightypork/gamecore/gui/screens/Overlay.java rename src/mightypork/gamecore/{gui/components => render}/Renderable.java (64%) diff --git a/src/mightypork/gamecore/control/BaseApp.java b/src/mightypork/gamecore/control/BaseApp.java index de9f886..cbccdba 100644 --- a/src/mightypork/gamecore/control/BaseApp.java +++ b/src/mightypork/gamecore/control/BaseApp.java @@ -255,7 +255,7 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler { bus.addChannel(LayoutChangeEvent.class, LayoutChangeEvent.Listener.class); // input events - bus.addChannel(ScreenChangeEvent.class, ScreenChangeEvent.Listener.class); + bus.addChannel(ViewportChangeEvent.class, ViewportChangeEvent.Listener.class); bus.addChannel(KeyEvent.class, KeyEvent.Listener.class); bus.addChannel(MouseMotionEvent.class, MouseMotionEvent.Listener.class); bus.addChannel(MouseButtonEvent.class, MouseButtonEvent.Listener.class); diff --git a/src/mightypork/gamecore/control/GameLoop.java b/src/mightypork/gamecore/control/GameLoop.java index 7cd2035..b4ca9d5 100644 --- a/src/mightypork/gamecore/control/GameLoop.java +++ b/src/mightypork/gamecore/control/GameLoop.java @@ -6,8 +6,8 @@ import java.util.concurrent.ConcurrentLinkedQueue; import mightypork.gamecore.control.events.MainLoopTaskRequest; import mightypork.gamecore.control.events.UpdateEvent; -import mightypork.gamecore.gui.components.Renderable; import mightypork.gamecore.gui.screens.ScreenRegistry; +import mightypork.gamecore.render.Renderable; import mightypork.util.annotations.DefaultImpl; import mightypork.util.control.timing.TimerDelta; diff --git a/src/mightypork/gamecore/control/events/ScreenChangeEvent.java b/src/mightypork/gamecore/control/events/ViewportChangeEvent.java similarity index 79% rename from src/mightypork/gamecore/control/events/ScreenChangeEvent.java rename to src/mightypork/gamecore/control/events/ViewportChangeEvent.java index b4d45ef..04ed3d1 100644 --- a/src/mightypork/gamecore/control/events/ScreenChangeEvent.java +++ b/src/mightypork/gamecore/control/events/ViewportChangeEvent.java @@ -10,7 +10,7 @@ import mightypork.util.control.eventbus.events.Event; * * @author MightyPork */ -public class ScreenChangeEvent implements Event { +public class ViewportChangeEvent implements Event { private final boolean fullscreen; private final Vect screenSize; @@ -22,7 +22,7 @@ public class ScreenChangeEvent implements Event { * @param fullscreen is now fullscreen * @param size new screen size */ - public ScreenChangeEvent(boolean fsChanged, boolean fullscreen, Vect size) { + public ViewportChangeEvent(boolean fsChanged, boolean fullscreen, Vect size) { this.fullscreen = fullscreen; this.screenSize = size; this.fsChanged = fsChanged; @@ -59,11 +59,11 @@ public class ScreenChangeEvent implements Event { @Override public void handleBy(Listener handler) { - handler.receive(this); + handler.onViewportChanged(this); } /** - * {@link ScreenChangeEvent} listener + * {@link ViewportChangeEvent} listener * * @author MightyPork */ @@ -74,6 +74,6 @@ public class ScreenChangeEvent implements Event { * * @param event */ - void receive(ScreenChangeEvent event); + void onViewportChanged(ViewportChangeEvent event); } } diff --git a/src/mightypork/gamecore/gui/components/PluggableRenderable.java b/src/mightypork/gamecore/gui/components/PluggableRenderable.java index bb6dfc2..6403c55 100644 --- a/src/mightypork/gamecore/gui/components/PluggableRenderable.java +++ b/src/mightypork/gamecore/gui/components/PluggableRenderable.java @@ -1,6 +1,7 @@ package mightypork.gamecore.gui.components; +import mightypork.gamecore.render.Renderable; import mightypork.util.constraints.rect.Rect; import mightypork.util.constraints.rect.proxy.PluggableRectBound; import mightypork.util.constraints.rect.proxy.RectBound; diff --git a/src/mightypork/gamecore/gui/components/VisualComponent.java b/src/mightypork/gamecore/gui/components/VisualComponent.java index bb943c9..0ec9641 100644 --- a/src/mightypork/gamecore/gui/components/VisualComponent.java +++ b/src/mightypork/gamecore/gui/components/VisualComponent.java @@ -2,6 +2,7 @@ package mightypork.gamecore.gui.components; import mightypork.gamecore.control.events.LayoutChangeEvent; +import mightypork.gamecore.render.Renderable; import mightypork.util.annotations.DefaultImpl; import mightypork.util.constraints.rect.Rect; import mightypork.util.constraints.rect.caching.AbstractRectCache; @@ -79,7 +80,7 @@ public abstract class VisualComponent extends AbstractRectCache implements Compo @Override - public final void onChange() + public final void onConstraintChanged() { updateLayout(); } diff --git a/src/mightypork/gamecore/gui/screens/BaseScreen.java b/src/mightypork/gamecore/gui/screens/BaseScreen.java new file mode 100644 index 0000000..9af6388 --- /dev/null +++ b/src/mightypork/gamecore/gui/screens/BaseScreen.java @@ -0,0 +1,160 @@ +package mightypork.gamecore.gui.screens; + + +import mightypork.gamecore.control.AppAccess; +import mightypork.gamecore.control.AppSubModule; +import mightypork.gamecore.control.events.LayoutChangeEvent; +import mightypork.gamecore.control.events.ViewportChangeEvent; +import mightypork.gamecore.input.KeyBinder; +import mightypork.gamecore.input.KeyBindingPool; +import mightypork.gamecore.input.KeyStroke; +import mightypork.gamecore.render.Render; +import mightypork.util.annotations.DefaultImpl; +import mightypork.util.constraints.rect.Rect; + + +/** + * Screen class. + * + * @author MightyPork + */ +public abstract class BaseScreen extends AppSubModule implements Screen, KeyBinder, ViewportChangeEvent.Listener { + + private final KeyBindingPool keybindings = new KeyBindingPool(); + + private volatile boolean active; + private volatile boolean needSetupViewport = false; + + + /** + * @param app app access + */ + public BaseScreen(AppAccess app) { + super(app); + + // disable events initially + setListening(false); + + addChildClient(keybindings); + } + + + private void fireLayoutChangeEvent() + { + getEventBus().sendDirectToChildren(this, new LayoutChangeEvent()); + } + + + @Override + public final void bindKeyStroke(KeyStroke stroke, Runnable task) + { + keybindings.bindKeyStroke(stroke, task); + } + + + @Override + public final void unbindKeyStroke(KeyStroke stroke) + { + keybindings.unbindKeyStroke(stroke); + } + + + /** + * Prepare for being shown + * + * @param shown true to show, false to hide + */ + @Override + public final void setActive(boolean shown) + { + if (shown) { + active = true; + needSetupViewport = true; + + fireLayoutChangeEvent(); + onScreenEnter(); + + // enable events + setListening(true); + + } else { + onScreenLeave(); + + active = false; + + // disable events + setListening(false); + } + } + + + /** + * @return true if screen is the current screen + */ + @Override + public final boolean isActive() + { + return active; + } + + + @Override + public final void onViewportChanged(ViewportChangeEvent event) + { + if (!isActive()) return; + + // fire event + fireLayoutChangeEvent(); + + needSetupViewport = true; + } + + + @Override + public final Rect getRect() + { + return getDisplay().getRect(); + } + + + @Override + public void render() + { + if (!isActive()) return; + + if (needSetupViewport) { + Render.setupOrtho(getDisplay().getSize()); + } + + Render.pushState(); + + renderScreen(); + + Render.popState(); + } + + + /** + * Called when the screen becomes active + */ + @DefaultImpl + protected void onScreenEnter() + { + } + + + /** + * Called when the screen is no longer active + */ + @DefaultImpl + protected void onScreenLeave() + { + } + + + /** + * Render screen contents (context is ready for 2D rendering) + */ + protected abstract void renderScreen(); + +} diff --git a/src/mightypork/gamecore/gui/screens/LayeredScreen.java b/src/mightypork/gamecore/gui/screens/LayeredScreen.java index 54213a9..6be4b97 100644 --- a/src/mightypork/gamecore/gui/screens/LayeredScreen.java +++ b/src/mightypork/gamecore/gui/screens/LayeredScreen.java @@ -5,7 +5,6 @@ import java.util.Collection; import java.util.TreeSet; import mightypork.gamecore.control.AppAccess; -import mightypork.util.constraints.vect.Vect; /** @@ -13,7 +12,7 @@ import mightypork.util.constraints.vect.Vect; * * @author MightyPork */ -public abstract class LayeredScreen extends Screen { +public abstract class LayeredScreen extends BaseScreen { private final Collection layers = new TreeSet<>(); @@ -47,18 +46,6 @@ public abstract class LayeredScreen extends Screen { } - /** - * Remove a layer - * - * @param layer - */ - protected void removeLayer(ScreenLayer layer) - { - this.layers.remove(layer); - removeChildClient(layer); - } - - @Override protected void onScreenEnter() { @@ -71,19 +58,9 @@ public abstract class LayeredScreen extends Screen { @Override protected void onScreenLeave() { - for (final ScreenLayer layer : layers) { layer.onScreenLeave(); } } - - @Override - protected void onSizeChanged(Vect size) - { - for (final ScreenLayer layer : layers) { - layer.onSizeChanged(size); - } - } - } diff --git a/src/mightypork/gamecore/gui/screens/Overlay.java b/src/mightypork/gamecore/gui/screens/Overlay.java new file mode 100644 index 0000000..15d4f00 --- /dev/null +++ b/src/mightypork/gamecore/gui/screens/Overlay.java @@ -0,0 +1,140 @@ +package mightypork.gamecore.gui.screens; + + +import java.util.Collection; +import java.util.LinkedHashSet; + +import mightypork.gamecore.control.AppAccess; +import mightypork.gamecore.control.AppSubModule; +import mightypork.gamecore.control.events.LayoutChangeEvent; +import mightypork.gamecore.gui.Hideable; +import mightypork.gamecore.gui.components.VisualComponent; +import mightypork.gamecore.gui.components.layout.ConstraintLayout; +import mightypork.gamecore.input.KeyBinder; +import mightypork.gamecore.input.KeyBindingPool; +import mightypork.gamecore.input.KeyStroke; +import mightypork.gamecore.render.Renderable; +import mightypork.util.annotations.DefaultImpl; +import mightypork.util.constraints.vect.Vect; +import mightypork.util.control.timing.Updateable; + + +/** + * Abstract overlay.
+ * Overlay is connected to event bus and is renderable. + * + * @author MightyPork + */ +public abstract class Overlay extends AppSubModule implements Updateable, Comparable, Renderable, KeyBinder, Hideable, LayoutChangeEvent.Listener { + + private boolean visible = true; + private final KeyBindingPool keybindings = new KeyBindingPool(); + + /** Root layout, rendered and attached to the event bus. */ + protected final ConstraintLayout root; + + /** Constraint: Mouse position. */ + protected final Vect mouse; + + /** Extra rendered items (outside root) */ + protected final Collection rendered = new LinkedHashSet<>(); + + /** Extra updated items (outside root - those can just implement Updateable) */ + protected final Collection updated = new LinkedHashSet<>(); + + + public Overlay(AppAccess app) { + super(app); + + this.mouse = getInput().getMousePos(); + + this.root = new ConstraintLayout(app, getDisplay()); + addChildClient(root); + addChildClient(keybindings); + + rendered.add(root); + } + + + @Override + public final void bindKeyStroke(KeyStroke stroke, Runnable task) + { + keybindings.bindKeyStroke(stroke, task); + } + + + @Override + public final void unbindKeyStroke(KeyStroke stroke) + { + keybindings.unbindKeyStroke(stroke); + } + + + @Override + public final boolean isVisible() + { + return visible; + } + + + @Override + public void setVisible(boolean visible) + { + this.visible = visible; + } + + + @Override + public final int compareTo(Overlay o) + { + return getPriority() - o.getPriority(); + } + + + /** + * Get rendering priority + * + * @return higher = on top. + */ + @DefaultImpl + public abstract int getPriority(); + + + /** + * Render the overlay. The caller MUST check for visibility himself. + */ + @Override + public void render() + { + for (Renderable r : rendered) { + r.render(); + } + } + + + @Override + public void update(double delta) + { + for (Updateable u : updated) { + u.update(delta); + } + } + + + /** + *

+ * Screen size changed. + *

+ *

+ * Layouts / components should listen for this event and update their cached + * constraints; components added to root or directly to this overlay as + * child clients will receive the event. + *

+ */ + @Override + @DefaultImpl + public void onLayoutChanged() + { + } + +} diff --git a/src/mightypork/gamecore/gui/screens/Screen.java b/src/mightypork/gamecore/gui/screens/Screen.java index 1cd8b90..5ee8f01 100644 --- a/src/mightypork/gamecore/gui/screens/Screen.java +++ b/src/mightypork/gamecore/gui/screens/Screen.java @@ -2,173 +2,34 @@ package mightypork.gamecore.gui.screens; import mightypork.gamecore.control.AppAccess; -import mightypork.gamecore.control.AppSubModule; -import mightypork.gamecore.control.events.LayoutChangeEvent; -import mightypork.gamecore.control.events.ScreenChangeEvent; -import mightypork.gamecore.gui.components.Renderable; -import mightypork.gamecore.input.KeyBinder; -import mightypork.gamecore.input.KeyBindingPool; -import mightypork.gamecore.input.KeyStroke; -import mightypork.gamecore.render.Render; -import mightypork.util.annotations.DefaultImpl; -import mightypork.util.constraints.rect.Rect; +import mightypork.gamecore.render.Renderable; import mightypork.util.constraints.rect.proxy.RectBound; -import mightypork.util.constraints.vect.Vect; /** - * Screen class. + * Game screen * * @author MightyPork */ -public abstract class Screen extends AppSubModule implements Renderable, KeyBinder, RectBound, ScreenChangeEvent.Listener { - - private final KeyBindingPool keybindings = new KeyBindingPool(); - - private volatile boolean active; - private volatile boolean needSetupViewport = false; - - - /** - * @param app app access - */ - public Screen(AppAccess app) { - super(app); - - // disable events initially - setListening(false); - - addChildClient(keybindings); - } - - - @Override - public final void bindKeyStroke(KeyStroke stroke, Runnable task) - { - keybindings.bindKeyStroke(stroke, task); - } - - - @Override - public final void unbindKeyStroke(KeyStroke stroke) - { - keybindings.unbindKeyStroke(stroke); - } - +public interface Screen extends Renderable, RectBound, AppAccess { /** * Prepare for being shown * * @param shown true to show, false to hide */ - public final void setActive(boolean shown) - { - if (shown) { - active = true; - needSetupViewport = true; - - onSizeChanged(getRect().size()); - onScreenEnter(); - - // enable events - setListening(true); - - } else { - onScreenLeave(); - - active = false; - - // disable events - setListening(false); - } - } + void setActive(boolean shown); /** * @return true if screen is the current screen */ - public final boolean isActive() - { - return active; - } - - - @Override - public final void receive(ScreenChangeEvent event) - { - if (!isActive()) return; - - onSizeChanged(event.getScreenSize()); - - // fire event - getEventBus().sendDirectToChildren(this, new LayoutChangeEvent()); - - needSetupViewport = true; - } - - - @Override - public final Rect getRect() - { - return getDisplay().getRect(); - } - - - @Override - public void render() - { - if (!isActive()) return; - - if (needSetupViewport) { - Render.setupOrtho(getDisplay().getSize()); - } - - Render.pushState(); - - renderScreen(); - - Render.popState(); - } - - - /** - * Called when the screen becomes active - */ - @DefaultImpl - protected void onScreenEnter() - { - } - - - /** - * Called when the screen is no longer active - */ - @DefaultImpl - protected void onScreenLeave() - { - } - - - /** - * Update GUI for new screen size - * - * @param size screen size - */ - @DefaultImpl - protected void onSizeChanged(Vect size) - { - } - - - /** - * Render screen contents (context is ready for 2D rendering) - */ - protected abstract void renderScreen(); + boolean isActive(); /** * @return screen identifier to be used for requests. */ - public abstract String getName(); + String getName(); } diff --git a/src/mightypork/gamecore/gui/screens/ScreenLayer.java b/src/mightypork/gamecore/gui/screens/ScreenLayer.java index ae2b60f..50dead1 100644 --- a/src/mightypork/gamecore/gui/screens/ScreenLayer.java +++ b/src/mightypork/gamecore/gui/screens/ScreenLayer.java @@ -1,19 +1,7 @@ package mightypork.gamecore.gui.screens; -import java.util.Collection; -import java.util.LinkedHashSet; - -import mightypork.gamecore.control.AppSubModule; -import mightypork.gamecore.gui.Hideable; -import mightypork.gamecore.gui.components.Renderable; -import mightypork.gamecore.gui.components.layout.ConstraintLayout; -import mightypork.gamecore.input.KeyBinder; -import mightypork.gamecore.input.KeyBindingPool; -import mightypork.gamecore.input.KeyStroke; import mightypork.util.annotations.DefaultImpl; -import mightypork.util.constraints.vect.Vect; -import mightypork.util.control.timing.Updateable; /** @@ -21,25 +9,10 @@ import mightypork.util.control.timing.Updateable; * * @author MightyPork */ -public abstract class ScreenLayer extends AppSubModule implements Updateable, Comparable, Renderable, KeyBinder, Hideable { - - private boolean visible = true; - - private final KeyBindingPool keybindings = new KeyBindingPool(); - - /** Root layout, rendered and attached to the event bus */ - protected final ConstraintLayout root; - - protected final Vect mouse; +public abstract class ScreenLayer extends Overlay { private final Screen screen; - /** Extra rendered items (outside root) */ - protected final Collection rendered = new LinkedHashSet<>(); - - /** Extra updated items (outside root - those can just implement Updateable) */ - protected final Collection updated = new LinkedHashSet<>(); - /** * @param screen parent screen @@ -48,31 +21,6 @@ public abstract class ScreenLayer extends AppSubModule implements Updateable, Co super(screen); // screen as AppAccess this.screen = screen; - - this.mouse = getInput().getMousePos(); - - this.root = new ConstraintLayout(screen, screen); - addChildClient(root); - addChildClient(keybindings); - - rendered.add(root); - - // root is on the bus, all attached components - // will receive events (such as update) - } - - - @Override - public final void bindKeyStroke(KeyStroke stroke, Runnable task) - { - keybindings.bindKeyStroke(stroke, task); - } - - - @Override - public final void unbindKeyStroke(KeyStroke stroke) - { - keybindings.unbindKeyStroke(stroke); } @@ -85,27 +33,6 @@ public abstract class ScreenLayer extends AppSubModule implements Updateable, Co } - @Override - public final boolean isVisible() - { - return visible; - } - - - @Override - public void setVisible(boolean visible) - { - this.visible = visible; - } - - - @Override - public final int compareTo(ScreenLayer o) - { - return getPriority() - o.getPriority(); - } - - /** * Called when the screen becomes active */ @@ -123,51 +50,4 @@ public abstract class ScreenLayer extends AppSubModule implements Updateable, Co { } - - /** - * Update GUI for new screen size - * - * @param size screen size - */ - @DefaultImpl - protected void onSizeChanged(Vect size) - { - } - - - /** - * @return higher = on top. - */ - @DefaultImpl - public abstract int getPriority(); - - - @Override - public final void render() - { - if (!visible) return; - - renderLayer(); - } - - - /** - * Render layer contents. - */ - protected void renderLayer() - { - // render renderables (including root layout) - for (Renderable r : rendered) - r.render(); - } - - - @Override - public void update(double delta) - { - // update updateables - for (Updateable u : updated) - u.update(delta); - } - } diff --git a/src/mightypork/gamecore/gui/screens/ScreenRegistry.java b/src/mightypork/gamecore/gui/screens/ScreenRegistry.java index b11f065..041ee03 100644 --- a/src/mightypork/gamecore/gui/screens/ScreenRegistry.java +++ b/src/mightypork/gamecore/gui/screens/ScreenRegistry.java @@ -1,12 +1,15 @@ package mightypork.gamecore.gui.screens; +import java.util.Collection; import java.util.HashMap; +import java.util.Map; +import java.util.TreeSet; import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.control.AppModule; import mightypork.gamecore.control.events.ScreenRequestEvent; -import mightypork.gamecore.gui.components.Renderable; +import mightypork.gamecore.render.Renderable; import mightypork.util.annotations.DefaultImpl; import mightypork.util.logging.Log; @@ -18,7 +21,8 @@ import mightypork.util.logging.Log; */ public class ScreenRegistry extends AppModule implements ScreenRequestEvent.Listener, Renderable { - private final HashMap screens = new HashMap<>(); + private final Map screens = new HashMap<>(); + private final Collection overlays = new TreeSet<>(); private volatile Screen active = null; @@ -35,33 +39,58 @@ public class ScreenRegistry extends AppModule implements ScreenRequestEvent.List * * @param screen added screen */ - public void add(Screen screen) + public void addScreen(Screen screen) { screens.put(screen.getName(), screen); addChildClient(screen); } + + + /** + * Add an overlay + * + * @param overlay added overlay + */ + public void addOverlay(Overlay overlay) + { + overlays.add(overlay); + addChildClient(overlay); + } @Override public void showScreen(String key) { Log.f3("Request to show screen \"" + key + "\""); - final Screen toshow = screens.get(key); - if (toshow == null) throw new RuntimeException("Screen " + key + " not defined."); + // find screen to show + final Screen toShow = screens.get(key); + if (toShow == null) { + throw new RuntimeException("Screen " + key + " not defined."); + } - if (active != null) active.setActive(false); + // deactivate last screen + if (active != null) { + active.setActive(false); + } - toshow.setActive(true); + // activate new screen + toShow.setActive(true); - active = toshow; + active = toShow; } @Override public void render() { - if (active != null) active.render(); + if (active != null) { + active.render(); + + for (final Overlay overlay : overlays) { + if (overlay.isVisible()) overlay.render(); + } + } } diff --git a/src/mightypork/gamecore/render/DisplaySystem.java b/src/mightypork/gamecore/render/DisplaySystem.java index 5b5a945..b00e0ad 100644 --- a/src/mightypork/gamecore/render/DisplaySystem.java +++ b/src/mightypork/gamecore/render/DisplaySystem.java @@ -7,7 +7,7 @@ import java.nio.ByteBuffer; import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.control.AppModule; -import mightypork.gamecore.control.events.ScreenChangeEvent; +import mightypork.gamecore.control.events.ViewportChangeEvent; import mightypork.util.constraints.rect.Rect; import mightypork.util.constraints.rect.proxy.RectBound; import mightypork.util.constraints.vect.Vect; @@ -130,7 +130,7 @@ public class DisplaySystem extends AppModule implements RectBound { Display.update(); } - getEventBus().send(new ScreenChangeEvent(true, Display.isFullscreen(), getSize())); + getEventBus().send(new ViewportChangeEvent(true, Display.isFullscreen(), getSize())); } catch (final Throwable t) { Log.e("Failed to toggle fullscreen mode.", t); @@ -221,7 +221,7 @@ public class DisplaySystem extends AppModule implements RectBound { { // handle resize if (Display.wasResized()) { - getEventBus().send(new ScreenChangeEvent(false, Display.isFullscreen(), getSize())); + getEventBus().send(new ViewportChangeEvent(false, Display.isFullscreen(), getSize())); } glLoadIdentity(); diff --git a/src/mightypork/gamecore/gui/components/Renderable.java b/src/mightypork/gamecore/render/Renderable.java similarity index 64% rename from src/mightypork/gamecore/gui/components/Renderable.java rename to src/mightypork/gamecore/render/Renderable.java index ffe6cbb..5f27785 100644 --- a/src/mightypork/gamecore/gui/components/Renderable.java +++ b/src/mightypork/gamecore/render/Renderable.java @@ -1,4 +1,4 @@ -package mightypork.gamecore.gui.components; +package mightypork.gamecore.render; /** @@ -9,7 +9,7 @@ package mightypork.gamecore.gui.components; public interface Renderable { /** - * Render on screen + * Render on screen. */ void render(); diff --git a/src/mightypork/rogue/App.java b/src/mightypork/rogue/App.java index e6201aa..71016b1 100644 --- a/src/mightypork/rogue/App.java +++ b/src/mightypork/rogue/App.java @@ -66,11 +66,11 @@ public class App extends BaseApp { @Override protected void initScreens(ScreenRegistry screens) { - screens.add(new ScreenTestBouncy(this)); - screens.add(new ScreenTestCat(this)); - screens.add(new ScreenTestRender(this)); + screens.addScreen(new ScreenTestBouncy(this)); + screens.addScreen(new ScreenTestCat(this)); + screens.addScreen(new ScreenTestRender(this)); - screens.add(new ScreenMainMenu(this)); + screens.addScreen(new ScreenMainMenu(this)); screens.showScreen("rogue.menu"); } diff --git a/src/mightypork/rogue/screens/LayerFps.java b/src/mightypork/rogue/screens/LayerFps.java index a81ed32..895abcd 100644 --- a/src/mightypork/rogue/screens/LayerFps.java +++ b/src/mightypork/rogue/screens/LayerFps.java @@ -3,7 +3,7 @@ package mightypork.rogue.screens; import mightypork.gamecore.gui.AlignX; import mightypork.gamecore.gui.components.painters.TextPainter; -import mightypork.gamecore.gui.screens.Screen; +import mightypork.gamecore.gui.screens.BaseScreen; import mightypork.gamecore.gui.screens.ScreenLayer; import mightypork.gamecore.input.KeyStroke; import mightypork.gamecore.input.Keys; @@ -21,7 +21,7 @@ public class LayerFps extends ScreenLayer { TextPainter tp; - public LayerFps(Screen screen) { + public LayerFps(BaseScreen screen) { super(screen); /* @@ -56,13 +56,6 @@ public class LayerFps extends ScreenLayer { } - @Override - protected void renderLayer() - { - super.renderLayer(); - } - - @Override public int getPriority() { diff --git a/src/mightypork/rogue/screens/main_menu/MenuLayer.java b/src/mightypork/rogue/screens/main_menu/MenuLayer.java index 08006f0..e2d0150 100644 --- a/src/mightypork/rogue/screens/main_menu/MenuLayer.java +++ b/src/mightypork/rogue/screens/main_menu/MenuLayer.java @@ -4,7 +4,7 @@ package mightypork.rogue.screens.main_menu; import mightypork.gamecore.control.events.ScreenRequestEvent; import mightypork.gamecore.gui.AlignY; import mightypork.gamecore.gui.components.layout.VerticalFixedFlowLayout; -import mightypork.gamecore.gui.screens.Screen; +import mightypork.gamecore.gui.screens.BaseScreen; import mightypork.gamecore.gui.screens.ScreenLayer; import mightypork.rogue.events.ActionRequest; import mightypork.rogue.events.ActionRequest.RequestType; @@ -16,7 +16,7 @@ import mightypork.util.math.color.Color; class MenuLayer extends ScreenLayer { - public MenuLayer(Screen screen) { + public MenuLayer(BaseScreen screen) { super(screen); init(); diff --git a/src/mightypork/rogue/screens/test_bouncyboxes/LayerBouncyBoxes.java b/src/mightypork/rogue/screens/test_bouncyboxes/LayerBouncyBoxes.java index 940d617..fbb6946 100644 --- a/src/mightypork/rogue/screens/test_bouncyboxes/LayerBouncyBoxes.java +++ b/src/mightypork/rogue/screens/test_bouncyboxes/LayerBouncyBoxes.java @@ -7,7 +7,7 @@ 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.BaseScreen; import mightypork.gamecore.gui.screens.ScreenLayer; import mightypork.gamecore.input.KeyStroke; import mightypork.gamecore.input.Keys; @@ -23,7 +23,7 @@ public class LayerBouncyBoxes extends ScreenLayer { private RowHolder layout; - public LayerBouncyBoxes(Screen screen) { + public LayerBouncyBoxes(BaseScreen screen) { super(screen); bindKeyStroke(new KeyStroke(true, Keys.KEY_RIGHT), new Runnable() { diff --git a/src/mightypork/rogue/screens/test_cat_sound/LayerColor.java b/src/mightypork/rogue/screens/test_cat_sound/LayerColor.java index 8076161..fc78ef2 100644 --- a/src/mightypork/rogue/screens/test_cat_sound/LayerColor.java +++ b/src/mightypork/rogue/screens/test_cat_sound/LayerColor.java @@ -2,14 +2,14 @@ package mightypork.rogue.screens.test_cat_sound; import mightypork.gamecore.gui.components.painters.QuadPainter; -import mightypork.gamecore.gui.screens.Screen; +import mightypork.gamecore.gui.screens.BaseScreen; import mightypork.gamecore.gui.screens.ScreenLayer; import mightypork.util.math.color.Color; public class LayerColor extends ScreenLayer { - public LayerColor(Screen screen, Color color) { + public LayerColor(BaseScreen screen, Color color) { super(screen); root.add(new QuadPainter(color)); diff --git a/src/mightypork/rogue/screens/test_cat_sound/LayerFlyingCat.java b/src/mightypork/rogue/screens/test_cat_sound/LayerFlyingCat.java index 6cde594..20ee105 100644 --- a/src/mightypork/rogue/screens/test_cat_sound/LayerFlyingCat.java +++ b/src/mightypork/rogue/screens/test_cat_sound/LayerFlyingCat.java @@ -8,7 +8,7 @@ import mightypork.gamecore.gui.AlignX; 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.Screen; +import mightypork.gamecore.gui.screens.BaseScreen; import mightypork.gamecore.gui.screens.ScreenLayer; import mightypork.gamecore.input.KeyStroke; import mightypork.gamecore.input.Keys; @@ -29,7 +29,7 @@ public class LayerFlyingCat extends ScreenLayer implements MouseButtonEvent.List private final Random rand = new Random(); - public LayerFlyingCat(Screen screen) { + public LayerFlyingCat(BaseScreen screen) { super(screen); // timing diff --git a/src/mightypork/rogue/screens/test_render/LayerTestGradient.java b/src/mightypork/rogue/screens/test_render/LayerTestGradient.java index 7673169..50a4ef1 100644 --- a/src/mightypork/rogue/screens/test_render/LayerTestGradient.java +++ b/src/mightypork/rogue/screens/test_render/LayerTestGradient.java @@ -1,7 +1,7 @@ package mightypork.rogue.screens.test_render; -import mightypork.gamecore.gui.screens.Screen; +import mightypork.gamecore.gui.screens.BaseScreen; import mightypork.gamecore.gui.screens.ScreenLayer; import mightypork.gamecore.render.Render; import mightypork.util.constraints.rect.proxy.RectBound; @@ -14,7 +14,7 @@ public class LayerTestGradient extends ScreenLayer { private final RectBound pos2; - public LayerTestGradient(Screen screen) { + public LayerTestGradient(BaseScreen screen) { super(screen); pos1 = root.topEdge().growDown(64); @@ -23,7 +23,7 @@ public class LayerTestGradient extends ScreenLayer { @Override - protected void renderLayer() + public void render() { Render.quadColor(root, Color.WHITE, Color.BLUE, Color.BLACK, Color.MAGENTA); Render.quadGradH(pos1.getRect(), Color.GREEN, Color.RED); diff --git a/src/mightypork/util/constraints/ConstraintCache.java b/src/mightypork/util/constraints/ConstraintCache.java index 940a292..2d1ee48 100644 --- a/src/mightypork/util/constraints/ConstraintCache.java +++ b/src/mightypork/util/constraints/ConstraintCache.java @@ -12,7 +12,7 @@ public interface ConstraintCache extends Pollable { /** * Called after the cache has changed value (and digest). */ - void onChange(); + void onConstraintChanged(); /** diff --git a/src/mightypork/util/constraints/num/caching/AbstractNumCache.java b/src/mightypork/util/constraints/num/caching/AbstractNumCache.java index 933967e..0958bda 100644 --- a/src/mightypork/util/constraints/num/caching/AbstractNumCache.java +++ b/src/mightypork/util/constraints/num/caching/AbstractNumCache.java @@ -54,12 +54,12 @@ public abstract class AbstractNumCache extends NumAdapter implements ConstraintC // mark my digest dirty markDigestDirty(); - onChange(); + onConstraintChanged(); } @Override - public abstract void onChange(); + public abstract void onConstraintChanged(); @Override diff --git a/src/mightypork/util/constraints/num/caching/NumCache.java b/src/mightypork/util/constraints/num/caching/NumCache.java index ec798fc..0f1ea27 100644 --- a/src/mightypork/util/constraints/num/caching/NumCache.java +++ b/src/mightypork/util/constraints/num/caching/NumCache.java @@ -29,7 +29,7 @@ public class NumCache extends AbstractNumCache { @Override @DefaultImpl - public void onChange() + public void onConstraintChanged() { } diff --git a/src/mightypork/util/constraints/rect/caching/AbstractRectCache.java b/src/mightypork/util/constraints/rect/caching/AbstractRectCache.java index ce68c69..258f62f 100644 --- a/src/mightypork/util/constraints/rect/caching/AbstractRectCache.java +++ b/src/mightypork/util/constraints/rect/caching/AbstractRectCache.java @@ -53,7 +53,7 @@ public abstract class AbstractRectCache extends RectAdapter implements Constrain markDigestDirty(); - onChange(); + onConstraintChanged(); } diff --git a/src/mightypork/util/constraints/rect/caching/RectCache.java b/src/mightypork/util/constraints/rect/caching/RectCache.java index 2cf5430..ccc015a 100644 --- a/src/mightypork/util/constraints/rect/caching/RectCache.java +++ b/src/mightypork/util/constraints/rect/caching/RectCache.java @@ -29,7 +29,7 @@ public class RectCache extends AbstractRectCache { @Override @DefaultImpl - public void onChange() + public void onConstraintChanged() { } diff --git a/src/mightypork/util/constraints/vect/caching/AbstractVectCache.java b/src/mightypork/util/constraints/vect/caching/AbstractVectCache.java index 3db6432..6e93d3f 100644 --- a/src/mightypork/util/constraints/vect/caching/AbstractVectCache.java +++ b/src/mightypork/util/constraints/vect/caching/AbstractVectCache.java @@ -53,7 +53,7 @@ public abstract class AbstractVectCache extends VectAdapter implements Constrain markDigestDirty(); - onChange(); + onConstraintChanged(); } diff --git a/src/mightypork/util/constraints/vect/caching/VectCache.java b/src/mightypork/util/constraints/vect/caching/VectCache.java index 27d0c9d..5fb3977 100644 --- a/src/mightypork/util/constraints/vect/caching/VectCache.java +++ b/src/mightypork/util/constraints/vect/caching/VectCache.java @@ -30,7 +30,7 @@ public class VectCache extends AbstractVectCache { @Override @DefaultImpl - public void onChange() + public void onConstraintChanged() { } }