You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.2 KiB
62 lines
1.2 KiB
package mightypork.gamecore.gui.screens;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import mightypork.gamecore.control.AppAccess;
|
|
import mightypork.gamecore.control.AppModule;
|
|
import mightypork.gamecore.control.bus.events.ScreenRequestEvent;
|
|
import mightypork.gamecore.control.interf.NoImpl;
|
|
import mightypork.gamecore.gui.renderers.Renderable;
|
|
import mightypork.utils.logging.Log;
|
|
|
|
|
|
public class ScreenRegistry extends AppModule implements ScreenRequestEvent.Listener, Renderable {
|
|
|
|
private final HashMap<String, Screen> screens = new HashMap<>();
|
|
private Screen active = null;
|
|
|
|
|
|
public ScreenRegistry(AppAccess app) {
|
|
super(app);
|
|
}
|
|
|
|
|
|
public void add(Screen screen)
|
|
{
|
|
screens.put(screen.getId(), screen);
|
|
addChildClient(screen);
|
|
}
|
|
|
|
|
|
@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.");
|
|
|
|
if (active != null) active.setActive(false);
|
|
|
|
toshow.setActive(true);
|
|
|
|
active = toshow;
|
|
}
|
|
|
|
|
|
@Override
|
|
public void render()
|
|
{
|
|
if (active != null) active.render();
|
|
}
|
|
|
|
|
|
@Override
|
|
@NoImpl
|
|
protected void deinit()
|
|
{
|
|
//
|
|
}
|
|
|
|
}
|
|
|