overlays system
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
+5
-5
@@ -10,7 +10,7 @@ import mightypork.util.control.eventbus.events.Event;
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public class ScreenChangeEvent implements Event<ScreenChangeEvent.Listener> {
|
||||
public class ViewportChangeEvent implements Event<ViewportChangeEvent.Listener> {
|
||||
|
||||
private final boolean fullscreen;
|
||||
private final Vect screenSize;
|
||||
@@ -22,7 +22,7 @@ public class ScreenChangeEvent implements Event<ScreenChangeEvent.Listener> {
|
||||
* @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<ScreenChangeEvent.Listener> {
|
||||
@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<ScreenChangeEvent.Listener> {
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
void receive(ScreenChangeEvent event);
|
||||
void onViewportChanged(ViewportChangeEvent event);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
@@ -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<ScreenLayer> 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.<br>
|
||||
* Overlay is connected to event bus and is renderable.
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public abstract class Overlay extends AppSubModule implements Updateable, Comparable<Overlay>, 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<Renderable> rendered = new LinkedHashSet<>();
|
||||
|
||||
/** Extra updated items (outside root - those can just implement Updateable) */
|
||||
protected final Collection<Updateable> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Screen size changed.
|
||||
* </p>
|
||||
* <p>
|
||||
* 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.
|
||||
* </p>
|
||||
*/
|
||||
@Override
|
||||
@DefaultImpl
|
||||
public void onLayoutChanged()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
|
||||
@@ -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<ScreenLayer>, 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<Renderable> rendered = new LinkedHashSet<>();
|
||||
|
||||
/** Extra updated items (outside root - those can just implement Updateable) */
|
||||
protected final Collection<Updateable> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<String, Screen> screens = new HashMap<>();
|
||||
private final Map<String, Screen> screens = new HashMap<>();
|
||||
private final Collection<Overlay> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
+2
-2
@@ -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();
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -12,7 +12,7 @@ public interface ConstraintCache<C> extends Pollable {
|
||||
/**
|
||||
* Called after the cache has changed value (and digest).
|
||||
*/
|
||||
void onChange();
|
||||
void onConstraintChanged();
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -29,7 +29,7 @@ public class NumCache extends AbstractNumCache {
|
||||
|
||||
@Override
|
||||
@DefaultImpl
|
||||
public void onChange()
|
||||
public void onConstraintChanged()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public abstract class AbstractRectCache extends RectAdapter implements Constrain
|
||||
|
||||
markDigestDirty();
|
||||
|
||||
onChange();
|
||||
onConstraintChanged();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ public class RectCache extends AbstractRectCache {
|
||||
|
||||
@Override
|
||||
@DefaultImpl
|
||||
public void onChange()
|
||||
public void onConstraintChanged()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public abstract class AbstractVectCache extends VectAdapter implements Constrain
|
||||
|
||||
markDigestDirty();
|
||||
|
||||
onChange();
|
||||
onConstraintChanged();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public class VectCache extends AbstractVectCache {
|
||||
|
||||
@Override
|
||||
@DefaultImpl
|
||||
public void onChange()
|
||||
public void onConstraintChanged()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user