Fixed some javadoc

master
Ondřej Hruška 11 years ago
parent 6208a0c2eb
commit abd5bec682
  1. 8
      src/junk/BaseApp.java
  2. 6
      src/mightypork/gamecore/audio/AudioModule.java
  3. 16
      src/mightypork/gamecore/audio/players/LoopPlayer.java
  4. 28
      src/mightypork/gamecore/core/App.java
  5. 3
      src/mightypork/gamecore/core/AppBackend.java
  6. 6
      src/mightypork/gamecore/core/AppPlugin.java
  7. 6
      src/mightypork/gamecore/core/BackendModule.java
  8. 32
      src/mightypork/gamecore/core/InitTask.java
  9. 35
      src/mightypork/gamecore/core/MainLoop.java
  10. 91
      src/mightypork/gamecore/core/WorkDir.java
  11. 7
      src/mightypork/gamecore/core/config/Config.java
  12. 7
      src/mightypork/gamecore/core/config/KeyStrokeProperty.java
  13. 9
      src/mightypork/gamecore/core/events/ShutdownEvent.java
  14. 2
      src/mightypork/gamecore/core/init/InitTaskLog.java
  15. 4
      src/mightypork/gamecore/core/init/InitTaskLogHeader.java
  16. 8
      src/mightypork/gamecore/core/init/InitTaskWorkdir.java
  17. 2
      src/mightypork/gamecore/core/plugins/screenshot/InitTaskPluginScreenshot.java
  18. 2
      src/mightypork/gamecore/core/plugins/screenshot/TaskTakeScreenshot.java
  19. 6
      src/mightypork/gamecore/graphics/FullscreenToggleRequest.java
  20. 25
      src/mightypork/gamecore/graphics/GraphicsModule.java
  21. 91
      src/mightypork/gamecore/graphics/fonts/DeferredFont.java
  22. 4
      src/mightypork/gamecore/graphics/fonts/FontRegistry.java
  23. 21
      src/mightypork/gamecore/graphics/fonts/Glyphs.java
  24. 2
      src/mightypork/gamecore/graphics/textures/DeferredTexture.java
  25. 5
      src/mightypork/gamecore/graphics/textures/FilterMode.java
  26. 8
      src/mightypork/gamecore/graphics/textures/QuadGrid.java
  27. 10
      src/mightypork/gamecore/graphics/textures/TextureRegistry.java
  28. 8
      src/mightypork/gamecore/graphics/textures/TxQuad.java
  29. 10
      src/mightypork/gamecore/graphics/textures/TxSheet.java
  30. 8
      src/mightypork/gamecore/graphics/textures/WrapMode.java
  31. 2
      src/mightypork/gamecore/gui/Action.java
  32. 26
      src/mightypork/gamecore/gui/ActionGroup.java
  33. 2
      src/mightypork/gamecore/gui/HasAction.java
  34. 8
      src/mightypork/gamecore/gui/components/BaseComponent.java
  35. 12
      src/mightypork/gamecore/gui/components/DynamicWidthComponent.java
  36. 8
      src/mightypork/gamecore/gui/components/InputComponent.java
  37. 14
      src/mightypork/gamecore/gui/components/LayoutComponent.java
  38. 19
      src/mightypork/gamecore/gui/components/LinearComponent.java
  39. 4
      src/mightypork/gamecore/gui/components/input/ClickableComponent.java
  40. 5
      src/mightypork/gamecore/gui/components/painters/ImagePainter.java
  41. 9
      src/mightypork/gamecore/gui/events/LayoutChangeEvent.java
  42. 8
      src/mightypork/gamecore/gui/events/LayoutChangeListener.java
  43. 5
      src/mightypork/gamecore/gui/events/ScreenRequest.java
  44. 8
      src/mightypork/gamecore/gui/screens/LayeredScreen.java
  45. 22
      src/mightypork/gamecore/gui/screens/Overlay.java
  46. 7
      src/mightypork/gamecore/gui/screens/Screen.java
  47. 13
      src/mightypork/gamecore/gui/screens/impl/CrossfadeOverlay.java
  48. 6
      src/mightypork/gamecore/gui/screens/impl/FadingLayer.java
  49. 12
      src/mightypork/gamecore/gui/screens/impl/LayerColor.java

@ -6,12 +6,12 @@ import java.lang.Thread.UncaughtExceptionHandler;
import mightypork.gamecore.core.App; import mightypork.gamecore.core.App;
import mightypork.gamecore.core.AppBackend; import mightypork.gamecore.core.AppBackend;
import mightypork.gamecore.core.MainLoop; import mightypork.gamecore.core.MainLoop;
import mightypork.gamecore.core.WorkDir;
import mightypork.gamecore.core.config.Config; import mightypork.gamecore.core.config.Config;
import mightypork.gamecore.gui.screens.ScreenRegistry; import mightypork.gamecore.gui.screens.ScreenRegistry;
import mightypork.gamecore.gui.screens.impl.CrossfadeOverlay; import mightypork.gamecore.gui.screens.impl.CrossfadeOverlay;
import mightypork.gamecore.resources.Res; import mightypork.gamecore.resources.Res;
import mightypork.gamecore.resources.ResourceSetup; import mightypork.gamecore.resources.ResourceSetup;
import mightypork.utils.files.WorkDir;
import mightypork.utils.logging.Log; import mightypork.utils.logging.Log;
@ -76,7 +76,7 @@ public abstract class BaseApp extends App implements UncaughtExceptionHandler {
*/ */
protected void initialize() protected void initialize()
{ {
WorkDir.init(opt.workdir); WorkDir.setBaseDir(opt.workdir);
if (opt.sigleInstance) initLock(); if (opt.sigleInstance) initLock();
lockObtained = true; lockObtained = true;
@ -135,10 +135,10 @@ public abstract class BaseApp extends App implements UncaughtExceptionHandler {
*/ */
Log.f1("Loading resources..."); Log.f1("Loading resources...");
if (opt.resourceLoader != null) { if (opt.resourceLoader != null) {
opt.resourceLoader.init(this); opt.resourceLoader.setBaseDir(this);
} }
Res.init(this); Res.setBaseDir(this);
for (final ResourceSetup rl : opt.resourceLists) { for (final ResourceSetup rl : opt.resourceLists) {
Res.load(rl); Res.load(rl);

@ -82,7 +82,7 @@ public abstract class AudioModule extends BackendModule implements Updateable {
*/ */
public EffectPlayer createEffect(String resource, double pitch, double gain) public EffectPlayer createEffect(String resource, double pitch, double gain)
{ {
return new EffectPlayer(createResource(resource), pitch, gain, effectsVolume); return new EffectPlayer(createAudio(resource), pitch, gain, effectsVolume);
} }
@ -98,7 +98,7 @@ public abstract class AudioModule extends BackendModule implements Updateable {
*/ */
public LoopPlayer createLoop(String resource, double pitch, double gain, double fadeIn, double fadeOut) public LoopPlayer createLoop(String resource, double pitch, double gain, double fadeIn, double fadeOut)
{ {
final LoopPlayer p = new LoopPlayer(createResource(resource), pitch, gain, loopsVolume); final LoopPlayer p = new LoopPlayer(createAudio(resource), pitch, gain, loopsVolume);
p.setFadeTimes(fadeIn, fadeOut); p.setFadeTimes(fadeIn, fadeOut);
loopPlayers.add(p); loopPlayers.add(p);
return p; return p;
@ -113,7 +113,7 @@ public abstract class AudioModule extends BackendModule implements Updateable {
* @return the resource * @return the resource
* @throws IllegalArgumentException if resource is already registered * @throws IllegalArgumentException if resource is already registered
*/ */
protected DeferredAudio createResource(String res) protected DeferredAudio createAudio(String res)
{ {
final DeferredAudio a = doCreateResource(res); final DeferredAudio a = doCreateResource(res);
App.bus().send(new ResourceLoadRequest(a)); App.bus().send(new ResourceLoadRequest(a));

@ -15,8 +15,6 @@ import mightypork.utils.math.animation.NumAnimated;
*/ */
public class LoopPlayer extends BaseAudioPlayer implements Updateable, Pauseable { public class LoopPlayer extends BaseAudioPlayer implements Updateable, Pauseable {
private final int sourceID = -1;
/** animator for fade in and fade out */ /** animator for fade in and fade out */
private final NumAnimated fadeAnim = new NumAnimated(0); private final NumAnimated fadeAnim = new NumAnimated(0);
@ -61,7 +59,7 @@ public class LoopPlayer extends BaseAudioPlayer implements Updateable, Pauseable
private void initLoop() private void initLoop()
{ {
if (hasAudio() && sourceID == -1) { if (hasAudio()) {
getAudio().play(computePitch(1), computeGain(1), true); getAudio().play(computePitch(1), computeGain(1), true);
getAudio().pauseLoop(); getAudio().pauseLoop();
} }
@ -122,28 +120,28 @@ public class LoopPlayer extends BaseAudioPlayer implements Updateable, Pauseable
/** /**
* Resume if paused, and fade in (pick up from current volume). * Resume if paused, and fade in (pick up from current volume).
* *
* @param secs * @param fadeTime fade time (s)
*/ */
public void fadeIn(double secs) public void fadeIn(double fadeTime)
{ {
if (!hasAudio()) return; if (!hasAudio()) return;
if (isPaused()) fadeAnim.setTo(0); if (isPaused()) fadeAnim.setTo(0);
resume(); resume();
fadeAnim.fadeIn(secs); fadeAnim.fadeIn(fadeTime);
} }
/** /**
* Fade out and pause when reached zero volume * Fade out and pause when reached zero volume
* *
* @param secs fade duration * @param fadeTime fade time (s)
*/ */
public void fadeOut(double secs) public void fadeOut(double fadeTime)
{ {
if (!hasAudio()) return; if (!hasAudio()) return;
if (isPaused()) return; if (isPaused()) return;
fadeAnim.fadeOut(secs); fadeAnim.fadeOut(fadeTime);
} }

@ -30,14 +30,16 @@ public class App extends BusNode {
private final EventBus eventBus = new EventBus(); private final EventBus eventBus = new EventBus();
private boolean started = false; private boolean started = false;
/** List of installed App plugins */
protected final DelegatingList plugins = new DelegatingList(); protected final DelegatingList plugins = new DelegatingList();
/** List of initializers */
protected final List<InitTask> initializers = new ArrayList<>(); protected final List<InitTask> initializers = new ArrayList<>();
/** /**
* Create an app with given backend. * Create an app with given backend.
* *
* @param backend * @param backend the backend to use
*/ */
public App(AppBackend backend) public App(AppBackend backend)
{ {
@ -56,8 +58,8 @@ public class App extends BusNode {
// initialize and use backend // initialize and use backend
this.backend = backend; this.backend = backend;
this.eventBus.subscribe(backend);
this.backend.bind(this); this.backend.bind(this);
this.eventBus.subscribe(backend);
this.backend.initialize(); this.backend.initialize();
} }
@ -84,7 +86,7 @@ public class App extends BusNode {
/** /**
* Add an initializer to the app. * Add an initializer to the app.
* *
* @param initializer * @param initializer the added init task
*/ */
public void addInitTask(InitTask initializer) public void addInitTask(InitTask initializer)
{ {
@ -128,11 +130,21 @@ public class App extends BusNode {
// sort initializers by order. // sort initializers by order.
final List<InitTask> orderedInitializers = InitTask.inOrder(initializers); final List<InitTask> orderedInitializers = InitTask.inOrder(initializers);
for (final InitTask initializer : orderedInitializers) { for (final InitTask initTask : orderedInitializers) {
Log.f1("Running init task \"" + initializer.getName() + "\"..."); Log.f1("Running init task \"" + initTask.getName() + "\"...");
initializer.bind(this);
initializer.init(); initTask.bind(this);
initializer.run();
// set the task options
initTask.init();
initTask.before();
// main task action
initTask.run();
// after hook for extra actions immeditaely after the task completes
initTask.after();
} }
Log.i("=== Initialization sequence completed ==="); Log.i("=== Initialization sequence completed ===");

@ -17,11 +17,12 @@ import mightypork.utils.eventbus.clients.BusNode;
*/ */
public abstract class AppBackend extends BusNode { public abstract class AppBackend extends BusNode {
/** App instance assigned using <code>bind()</code> */
protected App app; protected App app;
/** /**
* Assign an app instance. * Assign the initialized app instance to an "app" field.
* *
* @param app app * @param app app
*/ */

@ -14,9 +14,15 @@ import mightypork.utils.eventbus.clients.BusNode;
*/ */
public class AppPlugin extends BusNode { public class AppPlugin extends BusNode {
/** App instance assigned using <code>bind()</code> */
protected App app; protected App app;
/**
* Assign the initialized app instance to an "app" field.
*
* @param app app
*/
void bind(App app) void bind(App app)
{ {
this.app = app; this.app = app;

@ -13,6 +13,12 @@ import mightypork.utils.interfaces.Destroyable;
*/ */
public abstract class BackendModule extends BusNode implements Destroyable { public abstract class BackendModule extends BusNode implements Destroyable {
/**
* Initialize the backend module.<br>
* Any initialization that would normally be done in constructor shall be
* done here, to avoid pitfalls with
* "call to overridable method from constructor"
*/
public abstract void init(); public abstract void init();

@ -21,37 +21,61 @@ import mightypork.utils.logging.Log;
*/ */
public abstract class InitTask { public abstract class InitTask {
/** App instance assigned using <code>bind()</code> */
protected App app; protected App app;
/** /**
* Assign the initialized app instance to a protected "app" field. * Assign the initialized app instance to an "app" field.
* *
* @param app app * @param app app
*/ */
void bind(App app) final void bind(App app)
{ {
this.app = app; this.app = app;
} }
/** /**
* An intialization method that is called before the run() method.<br> * An init method that is called before the <code>run()</code> method.<br>
* This method should be left unimplemented in the task, and can be used to * This method should be left unimplemented in the task, and can be used to
* configure the init task when using it as anonymous inner type. * configure the init task when using it as anonymous inner type.
*/ */
@Stub @Stub
public void init() public void init()
{ {
//
} }
/** /**
* Run the initalizer on app. * Hook for extra action before the main task action.<br>
* Can be overridden during app configuration to "bake-in" extra actions.
*/
@Stub
public void before()
{
//
}
/**
* Run the initializer on app.
*/ */
public abstract void run(); public abstract void run();
/**
* Hook executed after the "run()" method.<br>
* Can be overridden during app configuration to "bake-in" extra actions.
*/
@Stub
public void after()
{
//
}
/** /**
* Get name of this initializer (for dependency resolver).<br> * Get name of this initializer (for dependency resolver).<br>
* The name should be short, snake_case and precise. * The name should be short, snake_case and precise.

@ -22,8 +22,16 @@ import mightypork.utils.math.timing.TimerDelta;
*/ */
public class MainLoop extends BusNode implements Destroyable { public class MainLoop extends BusNode implements Destroyable {
private static final double MAX_TIME_TASKS = 1 / 30D; // (avoid queue from hogging timing) /**
private static final double MAX_DELTA = 1 / 20D; // (skip huge gaps caused by loading resources etc) * Max time spent on main loop tasks per cycle (s)
*/
protected double MAX_TIME_TASKS = 1 / 30D;
/**
* Max delta time (s) per frame.<br>
* If delta is larger than this, it's clamped to it.
*/
protected double MAX_DELTA = 1 / 20D;
private final Deque<Runnable> tasks = new ConcurrentLinkedDeque<>(); private final Deque<Runnable> tasks = new ConcurrentLinkedDeque<>();
private TimerDelta timer; private TimerDelta timer;
@ -55,19 +63,23 @@ public class MainLoop extends BusNode implements Destroyable {
double delta = timer.getDelta(); double delta = timer.getDelta();
if (delta > MAX_DELTA) { if (delta > MAX_DELTA) {
Log.f3("(timing) Cropping delta: was " + delta + " , limit " + MAX_DELTA); Log.f3("(timing) Clamping delta: was " + delta + " s, MAX_DELTA = " + MAX_DELTA + " s");
delta = MAX_DELTA; delta = MAX_DELTA;
} }
// dispatch update event
App.bus().sendDirect(new UpdateEvent(delta)); App.bus().sendDirect(new UpdateEvent(delta));
// run main loop tasks
Runnable r; Runnable r;
final long t = Profiler.begin(); final long t = Profiler.begin();
while ((r = tasks.poll()) != null) { while ((r = tasks.poll()) != null) {
Log.f3(" * Main loop task."); Log.f3(" * Main loop task.");
r.run(); r.run();
if (Profiler.end(t) > MAX_TIME_TASKS) { if (Profiler.end(t) > MAX_TIME_TASKS) {
Log.f3("! Postponing main loop tasks to next cycle."); Log.f3("! Time's up, postponing task to next cycle.");
break; break;
} }
} }
@ -113,17 +125,18 @@ public class MainLoop extends BusNode implements Destroyable {
/** /**
* Add a task to queue to be executed in the main loop (OpenGL thread) * Add a task to queue to be executed in the main loop (in rendering
* context)
* *
* @param request task * @param task task
* @param priority if true, skip other tasks * @param skipQueue true to skip the queue
*/ */
public synchronized void queueTask(Runnable request, boolean priority) public synchronized void queueTask(Runnable task, boolean skipQueue)
{ {
if (priority) { if (skipQueue) {
tasks.addFirst(request); tasks.addFirst(task);
} else { } else {
tasks.addLast(request); tasks.addLast(task);
} }
} }

@ -1,91 +0,0 @@
package mightypork.gamecore.core;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import mightypork.utils.logging.Log;
/**
* Static application workdir accessor.
*
* @author Ondřej Hruška (MightyPork)
*/
public class WorkDir {
private static File workdir;
private static Map<String, String> namedPaths = new HashMap<>();
public static void init(File workdir)
{
WorkDir.workdir = workdir;
}
/**
* Add a path alias (dir or file), relative to the workdir.
*
* @param alias path alias
* @param path path relative to workdir
*/
public static void addPath(String alias, String path)
{
namedPaths.put(alias, path);
}
/**
* Get workdir folder, create if not exists.
*
* @param path dir path relative to workdir
* @return dir file
*/
public static File getDir(String path)
{
if (namedPaths.containsKey(path)) path = namedPaths.get(path);
final File f = new File(workdir, path);
if (!f.exists()) {
if (!f.mkdirs()) {
Log.w("Could not create a directory: " + f + " (path: " + path + ")");
}
}
return f;
}
/**
* Get workdir file, create parent if not exists.
*
* @param path dir path relative to workdir
* @return dir file
*/
public static File getFile(String path)
{
if (namedPaths.containsKey(path)) path = namedPaths.get(path);
final File f = new File(workdir, path);
// create the parent dir
if (!f.getParent().equals(workdir)) {
f.getParentFile().mkdirs();
}
return f;
}
/**
* @return the workdir File
*/
public static File getWorkDir()
{
return workdir;
}
}

@ -4,13 +4,13 @@ package mightypork.gamecore.core.config;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import mightypork.gamecore.core.WorkDir;
import mightypork.gamecore.input.Key; import mightypork.gamecore.input.Key;
import mightypork.gamecore.input.KeyStroke; import mightypork.gamecore.input.KeyStroke;
import mightypork.utils.config.propmgr.Property; import mightypork.utils.config.propmgr.Property;
import mightypork.utils.config.propmgr.PropertyManager; import mightypork.utils.config.propmgr.PropertyManager;
import mightypork.utils.config.propmgr.PropertyStore; import mightypork.utils.config.propmgr.PropertyStore;
import mightypork.utils.config.propmgr.store.PropertyFile; import mightypork.utils.config.propmgr.store.PropertyFile;
import mightypork.utils.files.WorkDir;
import mightypork.utils.logging.Log; import mightypork.utils.logging.Log;
@ -21,6 +21,7 @@ import mightypork.utils.logging.Log;
*/ */
public class Config { public class Config {
/** Array of configs registered for the app */
protected static Map<String, Config> configs = new HashMap<>(); protected static Map<String, Config> configs = new HashMap<>();
private final Map<String, KeyStrokeProperty> strokes = new HashMap<>(); private final Map<String, KeyStrokeProperty> strokes = new HashMap<>();
@ -185,8 +186,8 @@ public class Config {
/** /**
* Get an option for key * Get an option for key
* *
* @param key * @param key config key
* @return option value * @return option values
*/ */
public <T> T getValue(String key) public <T> T getValue(String key)
{ {

@ -17,6 +17,13 @@ import mightypork.utils.config.propmgr.Property;
*/ */
public class KeyStrokeProperty extends Property<KeyStroke> { public class KeyStrokeProperty extends Property<KeyStroke> {
/**
* Make a keystroke property
*
* @param key config key
* @param defaultValue default keystroke value
* @param comment property comment
*/
public KeyStrokeProperty(String key, KeyStroke defaultValue, String comment) public KeyStrokeProperty(String key, KeyStroke defaultValue, String comment)
{ {
super(key, defaultValue, comment); super(key, defaultValue, comment);

@ -10,9 +10,7 @@ import mightypork.utils.logging.Log;
* Shutdown event.<br> * Shutdown event.<br>
* This event is dispatched when the <code>App.shutdown()</code> method is * This event is dispatched when the <code>App.shutdown()</code> method is
* called. If no client consumes it, the shutdown will immediately follow.<br> * called. If no client consumes it, the shutdown will immediately follow.<br>
* This is a way to allow clients to abort the shutdown (ie. ask user to save * This is a way to allow clients to abort the shutdown (ie. ask to save game).
* game). After the game is saved, the <code>App.shutdown()</code> method can be
* called again.
* *
* @author Ondřej Hruška (MightyPork) * @author Ondřej Hruška (MightyPork)
*/ */
@ -21,6 +19,11 @@ public class ShutdownEvent extends BusEvent<ShutdownListener> {
private final Runnable shutdownTask; private final Runnable shutdownTask;
/**
* Make a shutdown event
*
* @param doShutdown Task that does the actual shutdown
*/
public ShutdownEvent(Runnable doShutdown) public ShutdownEvent(Runnable doShutdown)
{ {
this.shutdownTask = doShutdown; this.shutdownTask = doShutdown;

@ -5,7 +5,7 @@ import java.io.File;
import java.util.logging.Level; import java.util.logging.Level;
import mightypork.gamecore.core.InitTask; import mightypork.gamecore.core.InitTask;
import mightypork.gamecore.core.WorkDir; import mightypork.utils.files.WorkDir;
import mightypork.utils.logging.Log; import mightypork.utils.logging.Log;
import mightypork.utils.logging.writers.LogWriter; import mightypork.utils.logging.writers.LogWriter;
import mightypork.utils.string.StringUtil; import mightypork.utils.string.StringUtil;

@ -5,7 +5,7 @@ import java.io.IOException;
import mightypork.gamecore.core.InitTask; import mightypork.gamecore.core.InitTask;
import mightypork.gamecore.core.OptionalInitTask; import mightypork.gamecore.core.OptionalInitTask;
import mightypork.gamecore.core.WorkDir; import mightypork.utils.files.WorkDir;
import mightypork.utils.logging.Log; import mightypork.utils.logging.Log;
@ -30,7 +30,7 @@ public class InitTaskLogHeader extends InitTask {
txt += " Launch path ... " + System.getProperty("user.dir") + "\n"; txt += " Launch path ... " + System.getProperty("user.dir") + "\n";
try { try {
txt += " Workdir ....... " + WorkDir.getWorkDir().getCanonicalPath() + "\n"; txt += " Workdir ....... " + WorkDir.getBaseDir().getCanonicalPath() + "\n";
} catch (final IOException e) { } catch (final IOException e) {
Log.e(e); Log.e(e);
} }

@ -10,9 +10,9 @@ import javax.swing.JOptionPane;
import mightypork.gamecore.core.App; import mightypork.gamecore.core.App;
import mightypork.gamecore.core.InitTask; import mightypork.gamecore.core.InitTask;
import mightypork.gamecore.core.WorkDir;
import mightypork.utils.annotations.Stub; import mightypork.utils.annotations.Stub;
import mightypork.utils.files.InstanceLock; import mightypork.utils.files.InstanceLock;
import mightypork.utils.files.WorkDir;
import mightypork.utils.logging.Log; import mightypork.utils.logging.Log;
@ -55,7 +55,7 @@ public class InitTaskWorkdir extends InitTask {
* Set whether the workdir should be locked when the app is running, to * Set whether the workdir should be locked when the app is running, to
* prevent other instances from running simultaneously. * prevent other instances from running simultaneously.
* *
* @param lock * @param lock true to use lock
*/ */
public void setInstanceLock(boolean lock) public void setInstanceLock(boolean lock)
{ {
@ -66,7 +66,7 @@ public class InitTaskWorkdir extends InitTask {
/** /**
* Set name of the lock file. * Set name of the lock file.
* *
* @param lockFile * @param lockFile lock file name
*/ */
public void setLockFileName(String lockFile) public void setLockFileName(String lockFile)
{ {
@ -89,7 +89,7 @@ public class InitTaskWorkdir extends InitTask {
@Override @Override
public void run() public void run()
{ {
WorkDir.init(workdirPath); WorkDir.setBaseDir(workdirPath);
// lock working directory // lock working directory
if (doLock) { if (doLock) {

@ -2,7 +2,7 @@ package mightypork.gamecore.core.plugins.screenshot;
import mightypork.gamecore.core.InitTask; import mightypork.gamecore.core.InitTask;
import mightypork.gamecore.core.WorkDir; import mightypork.utils.files.WorkDir;
/** /**

@ -5,9 +5,9 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import mightypork.gamecore.core.App; import mightypork.gamecore.core.App;
import mightypork.gamecore.core.WorkDir;
import mightypork.gamecore.graphics.Screenshot; import mightypork.gamecore.graphics.Screenshot;
import mightypork.utils.Support; import mightypork.utils.Support;
import mightypork.utils.files.WorkDir;
import mightypork.utils.logging.Log; import mightypork.utils.logging.Log;

@ -5,6 +5,12 @@ import mightypork.utils.eventbus.BusEvent;
import mightypork.utils.eventbus.events.flags.SingleReceiverEvent; import mightypork.utils.eventbus.events.flags.SingleReceiverEvent;
/**
* Event that will request fullscreen toggle in the graphics module.<br>
* FIXME the usefullness of this event is dubious.
*
* @author Ondřej Hruška (MightyPork)
*/
@SingleReceiverEvent @SingleReceiverEvent
public class FullscreenToggleRequest extends BusEvent<GraphicsModule> { public class FullscreenToggleRequest extends BusEvent<GraphicsModule> {

@ -2,6 +2,7 @@ package mightypork.gamecore.graphics;
import mightypork.gamecore.core.BackendModule; import mightypork.gamecore.core.BackendModule;
import mightypork.gamecore.graphics.fonts.DeferredFont;
import mightypork.gamecore.graphics.textures.DeferredTexture; import mightypork.gamecore.graphics.textures.DeferredTexture;
import mightypork.gamecore.graphics.textures.TxQuad; import mightypork.gamecore.graphics.textures.TxQuad;
import mightypork.gamecore.gui.events.ViewportChangeEvent; import mightypork.gamecore.gui.events.ViewportChangeEvent;
@ -22,8 +23,11 @@ import mightypork.utils.math.timing.FpsMeter;
*/ */
public abstract class GraphicsModule extends BackendModule { public abstract class GraphicsModule extends BackendModule {
/** X axis vector */
protected static final VectConst AXIS_X = Vect.make(1, 0, 0); protected static final VectConst AXIS_X = Vect.make(1, 0, 0);
/** Y axis vector */
protected static final VectConst AXIS_Y = Vect.make(0, 1, 0); protected static final VectConst AXIS_Y = Vect.make(0, 1, 0);
/** Z axis vector */
protected static final VectConst AXIS_Z = Vect.make(0, 0, 1); protected static final VectConst AXIS_Z = Vect.make(0, 0, 1);
@ -257,18 +261,27 @@ public abstract class GraphicsModule extends BackendModule {
/** /**
* Setup projection for 2D graphics, using current scren size * Setup projection for 2D graphics, using current screen size
*/ */
public abstract void setupProjection(); public abstract void setupProjection();
/** /**
* Get backend-flavoured lazy texture * Get backend-flavoured deferred texture. This should support PNG images.
* *
* @param path path to texture * @param path path to texture
* @return the lazy texture * @return the deferred font
*/ */
public abstract DeferredTexture getLazyTexture(String path); public abstract DeferredTexture createDeferredTexture(String path);
/**
* Get backend-flavoured deferred font. This should support TTF fonts.
*
* @param path path to font, or font name in the system
* @return the deferred font
*/
public abstract DeferredFont createDeferredFont(String path);
/** /**
@ -378,7 +391,7 @@ public abstract class GraphicsModule extends BackendModule {
/** /**
* Get screen center. Should always return the same Vect instance. * Get screen center. Should always return the same {@link Vect} instance.
* *
* @return screen center. * @return screen center.
*/ */
@ -386,7 +399,7 @@ public abstract class GraphicsModule extends BackendModule {
/** /**
* Get screen size. Should always return the same Vect instance. * Get screen size. Should always return the same {@link Vect} instance.
* *
* @return size * @return size
*/ */

@ -6,16 +6,27 @@ import mightypork.gamecore.resources.BaseDeferredResource;
/** /**
* Abstract deferred font stub. * Deferred font stub.
* *
* @author Ondřej Hruška (MightyPork) * @author Ondřej Hruška (MightyPork)
*/ */
public abstract class DeferredFont extends BaseDeferredResource implements IFont { public abstract class DeferredFont extends BaseDeferredResource implements IFont {
/**
* Font style enum
*/
public static enum FontStyle public static enum FontStyle
{ {
PLAIN(0), BOLD(1), ITALIC(2), BOLD_ITALIC(3); /** Plan style */
PLAIN(0),
/** Bold style */
BOLD(1),
/** Italic style */
ITALIC(2),
/** Bond and italic together */
BOLD_ITALIC(1 + 2);
/** Number associated with the style */
public int numval; public int numval;
@ -31,53 +42,111 @@ public abstract class DeferredFont extends BaseDeferredResource implements IFont
} }
} }
/**
* Requested font size. For bitmap fonts, this should match the actual font
* size (in pixels). The font can be scaled after loaded, but it may be
* cached with this size.
*/
protected double size = 12; protected double size = 12;
/** Requested font style. If not applicable, fall back to PLAIN */
protected FontStyle style = FontStyle.PLAIN; protected FontStyle style = FontStyle.PLAIN;
/**
* Chars that are required to be loaded in the font. A space glyph must be
* also added when loading.
*/
protected String chars = Glyphs.basic; protected String chars = Glyphs.basic;
/** Requested filtering mode */
protected FilterMode filter = FilterMode.NEAREST; protected FilterMode filter = FilterMode.NEAREST;
/** Whether to use anti-aliasing for the font. */
protected boolean antialias = false; protected boolean antialias = false;
/**
* Ratio of the font to discard at the top (how much of the glyphs height is
* blank from top)
*/
protected double discardTop = 0; protected double discardTop = 0;
/**
* Ratio of the font to discard at the bottom (how much of the glyphs height
* is blank from bottom)
*/
protected double discardBottom = 0; protected double discardBottom = 0;
/**
* Make a font from resource
*
* @param resource the font resource
*/
public DeferredFont(String resource) public DeferredFont(String resource)
{ {
super(resource); super(resource);
} }
public void setSize(double size) /**
* Set font size. If the font is backed by a texture, this is the size at
* which the font is rendered to the texture. For bitmap fonts, this should
* match the font height in px.
*
* @param size font size
*/
public final void setSize(double size)
{ {
this.size = size; this.size = size;
} }
public void setStyle(FontStyle style) /**
* Set desired font style
*
* @param style style
*/
public final void setStyle(FontStyle style)
{ {
this.style = style; this.style = style;
} }
public void setChars(String chars) /**
* Set what chars are to be loaded. The space glyph will be loaded always.
*
* @param chars String containing chars to load (duplicates are ignored)
*/
public final void setChars(String chars)
{ {
this.chars = chars; this.chars = chars;
} }
public void setFilter(FilterMode filter) /**
* Set texture filtering mode. For bitmap fonts, set to NEAREST.
*
* @param filter filter mode.
*/
public final void setFilter(FilterMode filter)
{ {
this.filter = filter; this.filter = filter;
} }
public void setAntialias(boolean antialias) /**
* Set whether to use antialiasing.
*
* @param antialias antialias
*/
public final void setAntialias(boolean antialias)
{ {
this.antialias = antialias; this.antialias = antialias;
} }
@Override @Override
public void setDiscardRatio(double top, double bottom) public final void setDiscardRatio(double top, double bottom)
{ {
discardTop = top; discardTop = top;
discardBottom = bottom; discardBottom = bottom;
@ -85,14 +154,14 @@ public abstract class DeferredFont extends BaseDeferredResource implements IFont
@Override @Override
public double getTopDiscardRatio() public final double getTopDiscardRatio()
{ {
return discardTop; return discardTop;
} }
@Override @Override
public double getBottomDiscardRatio() public final double getBottomDiscardRatio()
{ {
return discardBottom; return discardBottom;
} }

@ -20,7 +20,7 @@ public class FontRegistry extends BusNode {
/** /**
* Load a {@link DeferredLwjglFont} * Load a {@link DeferredFont}
* *
* @param key font key * @param key font key
* @param font font instance * @param font font instance
@ -58,7 +58,7 @@ public class FontRegistry extends BusNode {
/** /**
* Get a loaded {@link Texture} * Get a loaded {@link IFont}
* *
* @param key texture key * @param key texture key
* @return the texture * @return the texture

@ -2,22 +2,41 @@ package mightypork.gamecore.graphics.fonts;
/** /**
* Glyph tables, can be used for font loading. * Glyph tables, can be used for font loading.<br>
* The font should also always add a space glyph.
* *
* @author Ondřej Hruška (MightyPork) * @author Ondřej Hruška (MightyPork)
*/ */
public class Glyphs { public class Glyphs {
/** A-Z a-z */
public static final String latin = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; public static final String latin = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
/** Extra variants of latin glyphs */
public static final String latin_extra = "ŒÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜŸÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿĚŠČŘŽŤŇĎŮěščřžťňďůŁłđ"; public static final String latin_extra = "ŒÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜŸÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿĚŠČŘŽŤŇĎŮěščřžťňďůŁłđ";
/** 0-9 */
public static final String numbers = "0123456789"; public static final String numbers = "0123456789";
/** Commonly used punctuation symbols */
public static final String punctuation = ".-,.?!:;\"'"; public static final String punctuation = ".-,.?!:;\"'";
/** Less common punctuation symbols */
public static final String punctuation_extra = "()¿¡»«›‹“”‘’„…"; public static final String punctuation_extra = "()¿¡»«›‹“”‘’„…";
/** Commonly used symbols (that are not included in punctuation) */
public static final String symbols = "[]{}#$%&§*+/<=>@\\^_|~°"; public static final String symbols = "[]{}#$%&§*+/<=>@\\^_|~°";
/** Less common symbols */
public static final String symbols_extra = "¥€£¢`ƒ†‡ˆ‰•¤¦¨ªº¹²³¬­¯±´µ¶·¸¼½¾×÷™©­®→↓←↑"; public static final String symbols_extra = "¥€£¢`ƒ†‡ˆ‰•¤¦¨ªº¹²³¬­¯±´µ¶·¸¼½¾×÷™©­®→↓←↑";
/** Latin, numbers, punctuation and symbols */
public static final String basic = latin + numbers + punctuation + symbols; public static final String basic = latin + numbers + punctuation + symbols;
/** Extra glyphs to accompany "basic" */
public static final String extra = latin_extra + punctuation_extra + symbols_extra; public static final String extra = latin_extra + punctuation_extra + symbols_extra;
/** Basic + Extra */
public static final String all = basic + extra; public static final String all = basic + extra;
} }

@ -16,7 +16,9 @@ import mightypork.utils.math.constraints.rect.Rect;
@MustLoadInRenderingContext @MustLoadInRenderingContext
public abstract class DeferredTexture extends BaseDeferredResource implements ITexture { public abstract class DeferredTexture extends BaseDeferredResource implements ITexture {
/** Used filtering mode */
protected FilterMode filter = FilterMode.NEAREST; protected FilterMode filter = FilterMode.NEAREST;
/** Used wrapping mode */
protected WrapMode wrap = WrapMode.CLAMP; protected WrapMode wrap = WrapMode.CLAMP;

@ -8,5 +8,8 @@ package mightypork.gamecore.graphics.textures;
*/ */
public enum FilterMode public enum FilterMode
{ {
LINEAR, NEAREST; /** Smoothing, useful for photos */
LINEAR,
/** Sharp, useful for pixel art graphics */
NEAREST;
} }

@ -5,7 +5,8 @@ import mightypork.utils.math.constraints.rect.Rect;
/** /**
* {@link TxQuad} and {@link TxSheet} building utility * {@link TxQuad} and {@link TxSheet} building utility, that cuts a texture into
* equally sized quads.
* *
* @author Ondřej Hruška (MightyPork) * @author Ondřej Hruška (MightyPork)
*/ */
@ -18,6 +19,11 @@ public class QuadGrid {
private final double tileH; private final double tileH;
/**
* @param tx backing texture
* @param tilesX number of tile columns
* @param tilesY number of tile rows
*/
public QuadGrid(ITexture tx, int tilesX, int tilesY) public QuadGrid(ITexture tx, int tilesX, int tilesY)
{ {
this.tx = tx; this.tx = tx;

@ -27,8 +27,8 @@ public class TextureRegistry {
* added to the bank. * added to the bank.
* *
* @param resourcePath resource path of the texture * @param resourcePath resource path of the texture
* @param filter * @param filter filtering mode
* @param wrap * @param wrap wrapping mode
* @return texture reference * @return texture reference
*/ */
public ITexture addTexture(String resourcePath, FilterMode filter, WrapMode wrap) public ITexture addTexture(String resourcePath, FilterMode filter, WrapMode wrap)
@ -43,15 +43,15 @@ public class TextureRegistry {
* *
* @param key texture key, can be null. * @param key texture key, can be null.
* @param resourcePath resource path of the texture * @param resourcePath resource path of the texture
* @param filter * @param filter filtering mode
* @param wrap * @param wrap wrapping mode
* @return texture reference * @return texture reference
*/ */
public ITexture addTexture(String key, String resourcePath, FilterMode filter, WrapMode wrap) public ITexture addTexture(String key, String resourcePath, FilterMode filter, WrapMode wrap)
{ {
if (key != null) if (textures.containsKey(key)) throw new KeyAlreadyExistsException(); if (key != null) if (textures.containsKey(key)) throw new KeyAlreadyExistsException();
final DeferredTexture texture = App.gfx().getLazyTexture(resourcePath); final DeferredTexture texture = App.gfx().createDeferredTexture(resourcePath);
texture.setFilter(filter); texture.setFilter(filter);
texture.setWrap(wrap); texture.setWrap(wrap);

@ -142,12 +142,18 @@ public class TxQuad {
} }
/**
* @return true if the quad is to be rendered flipped vertically
*/
public boolean isFlippedY() public boolean isFlippedY()
{ {
return flipY; return flipY;
} }
/**
* @return true if the quad is to be rendered flipped horizontally
*/
public boolean isFlippedX() public boolean isFlippedX()
{ {
return flipX; return flipX;
@ -157,7 +163,7 @@ public class TxQuad {
/** /**
* Use the same flit/other attributes as the original txQuad * Use the same flit/other attributes as the original txQuad
* *
* @param original * @param original quad to copy attributes from
*/ */
public void dupeAttrs(TxQuad original) public void dupeAttrs(TxQuad original)
{ {

@ -7,7 +7,8 @@ import mightypork.utils.logging.Log;
/** /**
* Basic sprite sheet * Basic sprite sheet (cuts a {@link TxQuad} to a number of same-sized
* sub-quads)
* *
* @author Ondřej Hruška (MightyPork) * @author Ondřej Hruška (MightyPork)
*/ */
@ -22,6 +23,13 @@ public class TxSheet {
private final int count; private final int count;
/**
* Make a sprite sheet
*
* @param tx backing texture quad
* @param width number of tiles horizontally
* @param height number of tiles vertically
*/
public TxSheet(TxQuad tx, int width, int height) public TxSheet(TxQuad tx, int width, int height)
{ {
this.original = tx; this.original = tx;

@ -2,11 +2,15 @@ package mightypork.gamecore.graphics.textures;
/** /**
* Texture wrap mode * Texture wrap mode (policy when rendered on larger area than can be covered by
* the texture)
* *
* @author Ondřej Hruška (MightyPork) * @author Ondřej Hruška (MightyPork)
*/ */
public enum WrapMode public enum WrapMode
{ {
CLAMP, REPEAT; /** transparent in the overlap area */
CLAMP,
/** repeat the texture (tiling) */
REPEAT;
} }

@ -5,7 +5,7 @@ import mightypork.utils.interfaces.Enableable;
/** /**
* Triggered action * An {@link Enableable} runnable.
* *
* @author Ondřej Hruška (MightyPork) * @author Ondřej Hruška (MightyPork)
*/ */

@ -7,6 +7,12 @@ import java.util.Set;
import mightypork.utils.interfaces.Enableable; import mightypork.utils.interfaces.Enableable;
/**
* A group of enableable objects that propagates it's "enable" state to them
* all.
*
* @author Ondřej Hruška (MightyPork)
*/
public class ActionGroup implements Enableable { public class ActionGroup implements Enableable {
private boolean enabled = true; private boolean enabled = true;
@ -30,9 +36,25 @@ public class ActionGroup implements Enableable {
} }
public void add(Enableable action) /**
* Add an {@link Enableable} to the group
*
* @param member the object to add
*/
public void add(Enableable member)
{ {
groupMembers.add(action); groupMembers.add(member);
}
/**
* Remove a group member
*
* @param member the object to remove
*/
public void remove(Enableable member)
{
groupMembers.remove(member);
} }
} }

@ -6,7 +6,7 @@ package mightypork.gamecore.gui;
* *
* @author Ondřej Hruška (MightyPork) * @author Ondřej Hruška (MightyPork)
*/ */
public interface ActionTrigger { public interface HasAction {
/** /**
* Assign an action * Assign an action

@ -7,7 +7,6 @@ import mightypork.gamecore.gui.events.LayoutChangeEvent;
import mightypork.gamecore.gui.events.LayoutChangeListener; import mightypork.gamecore.gui.events.LayoutChangeListener;
import mightypork.utils.Support; import mightypork.utils.Support;
import mightypork.utils.annotations.Stub; import mightypork.utils.annotations.Stub;
import mightypork.utils.interfaces.Enableable;
import mightypork.utils.logging.Log; import mightypork.utils.logging.Log;
import mightypork.utils.math.color.Color; import mightypork.utils.math.color.Color;
import mightypork.utils.math.constraints.num.Num; import mightypork.utils.math.constraints.num.Num;
@ -23,7 +22,7 @@ import mightypork.utils.math.constraints.rect.proxy.RectProxy;
* *
* @author Ondřej Hruška (MightyPork) * @author Ondřej Hruška (MightyPork)
*/ */
public abstract class BaseComponent extends AbstractRectCache implements Component, LayoutChangeListener, Enableable { public abstract class BaseComponent extends AbstractRectCache implements Component, LayoutChangeListener {
private Rect source; private Rect source;
private boolean visible = true; private boolean visible = true;
@ -33,6 +32,11 @@ public abstract class BaseComponent extends AbstractRectCache implements Compone
private Num alphaMul = Num.ONE; private Num alphaMul = Num.ONE;
/**
* Create a base component.<br>
* By default, disable caching to avoid problems with updating. Caching can
* be enabled by individual components.
*/
public BaseComponent() public BaseComponent()
{ {
enableCaching(false); enableCaching(false);

@ -1,7 +1,19 @@
package mightypork.gamecore.gui.components; package mightypork.gamecore.gui.components;
/**
* Component whose width is derived from content.<br>
* Used for Linear components.
*
* @author Ondřej Hruška (MightyPork)
*/
public interface DynamicWidthComponent extends Component { public interface DynamicWidthComponent extends Component {
/**
* Get current width, if the element has specified height
*
* @param height current height
* @return current width
*/
double computeWidth(double height); double computeWidth(double height);
} }

@ -2,10 +2,14 @@ package mightypork.gamecore.gui.components;
import mightypork.utils.eventbus.clients.ToggleableClient; import mightypork.utils.eventbus.clients.ToggleableClient;
import mightypork.utils.interfaces.Enableable;
public abstract class InputComponent extends BaseComponent implements Enableable, ToggleableClient { /**
* Component used for user input, such as buttons.
*
* @author Ondřej Hruška (MightyPork)
*/
public abstract class InputComponent extends BaseComponent implements ToggleableClient {
@Override @Override
public boolean isListening() public boolean isListening()

@ -9,12 +9,22 @@ import mightypork.utils.eventbus.clients.DelegatingList;
import mightypork.utils.math.constraints.rect.RectBound; import mightypork.utils.math.constraints.rect.RectBound;
/**
* Component that provides positioning to member components
*
* @author Ondřej Hruška (MightyPork)
*/
public abstract class LayoutComponent extends BaseComponent implements ClientHub { public abstract class LayoutComponent extends BaseComponent implements ClientHub {
private final DelegatingList clientList; private final DelegatingList clientList;
final LinkedList<Component> components = new LinkedList<>(); final LinkedList<Component> components = new LinkedList<>();
/**
* Layout component with the given context (container)
*
* @param context context
*/
public LayoutComponent(RectBound context) public LayoutComponent(RectBound context)
{ {
this.clientList = new DelegatingList(); this.clientList = new DelegatingList();
@ -23,6 +33,10 @@ public abstract class LayoutComponent extends BaseComponent implements ClientHub
} }
/**
* Component without context (can be assigned a context using
* <code>setRect()</code>)
*/
public LayoutComponent() public LayoutComponent()
{ {
this(null); this(null);

@ -8,6 +8,12 @@ import mightypork.utils.math.constraints.vect.Vect;
import mightypork.utils.math.constraints.vect.proxy.VectAdapter; import mightypork.utils.math.constraints.vect.proxy.VectAdapter;
/**
* A linear component, one whose height and origin can be set and it's width is
* adjusted accordingly.
*
* @author Ondřej Hruška (MightyPork)
*/
public abstract class LinearComponent extends BaseComponent implements DynamicWidthComponent { public abstract class LinearComponent extends BaseComponent implements DynamicWidthComponent {
private final Rect rect = new Rect() { private final Rect rect = new Rect() {
@ -52,6 +58,9 @@ public abstract class LinearComponent extends BaseComponent implements DynamicWi
private Num height; private Num height;
/**
* Create a linear component
*/
public LinearComponent() public LinearComponent()
{ {
super.setRect(rect); super.setRect(rect);
@ -65,12 +74,22 @@ public abstract class LinearComponent extends BaseComponent implements DynamicWi
} }
/**
* Set component's height
*
* @param height the height
*/
public void setHeight(Num height) public void setHeight(Num height)
{ {
this.height = height; this.height = height;
} }
/**
* Set component's origin
*
* @param origin origin
*/
public void setOrigin(Vect origin) public void setOrigin(Vect origin)
{ {
this.origin = origin; this.origin = origin;

@ -2,13 +2,13 @@ package mightypork.gamecore.gui.components.input;
import mightypork.gamecore.gui.Action; import mightypork.gamecore.gui.Action;
import mightypork.gamecore.gui.ActionTrigger; import mightypork.gamecore.gui.HasAction;
import mightypork.gamecore.gui.components.InputComponent; import mightypork.gamecore.gui.components.InputComponent;
import mightypork.gamecore.input.events.MouseButtonEvent; import mightypork.gamecore.input.events.MouseButtonEvent;
import mightypork.gamecore.input.events.MouseButtonHandler; import mightypork.gamecore.input.events.MouseButtonHandler;
public abstract class ClickableComponent extends InputComponent implements ActionTrigger, MouseButtonHandler { public abstract class ClickableComponent extends InputComponent implements HasAction, MouseButtonHandler {
protected boolean btnDownOver; protected boolean btnDownOver;
private Action action; private Action action;

@ -40,6 +40,11 @@ public class ImagePainter extends BaseComponent implements DynamicWidthComponent
} }
/**
* Set drawn {@link TxQuad}
*
* @param txQuad the drawn quad
*/
public void setTxQuad(TxQuad txQuad) public void setTxQuad(TxQuad txQuad)
{ {
this.txQuad = txQuad; this.txQuad = txQuad;

@ -9,7 +9,9 @@ import mightypork.utils.eventbus.events.flags.NonRejectableEvent;
/** /**
* Intended use is to notify UI component sub-clients that they should poll * Intended use is to notify UI component sub-clients that they should poll
* their cached constraints. * their cached constraints.<br>
* Is {@link NonRejectableEvent} to force update even of hidden screens and
* layers.
* *
* @author Ondřej Hruška (MightyPork) * @author Ondřej Hruška (MightyPork)
*/ */
@ -18,11 +20,6 @@ import mightypork.utils.eventbus.events.flags.NonRejectableEvent;
@NonRejectableEvent @NonRejectableEvent
public class LayoutChangeEvent extends BusEvent<LayoutChangeListener> { public class LayoutChangeEvent extends BusEvent<LayoutChangeListener> {
public LayoutChangeEvent()
{
}
@Override @Override
public void handleBy(LayoutChangeListener handler) public void handleBy(LayoutChangeListener handler)
{ {

@ -1,7 +1,15 @@
package mightypork.gamecore.gui.events; package mightypork.gamecore.gui.events;
/**
* Receives notifications about layout change
*
* @author Ondřej Hruška (MightyPork)
*/
public interface LayoutChangeListener { public interface LayoutChangeListener {
/**
* Triggered when display size changed and GUI should be recalculated.
*/
public void onLayoutChanged(); public void onLayoutChanged();
} }

@ -1,12 +1,13 @@
package mightypork.gamecore.gui.events; package mightypork.gamecore.gui.events;
import mightypork.gamecore.gui.screens.ScreenRegistry;
import mightypork.utils.eventbus.BusEvent; import mightypork.utils.eventbus.BusEvent;
import mightypork.utils.eventbus.events.flags.SingleReceiverEvent; import mightypork.utils.eventbus.events.flags.SingleReceiverEvent;
/** /**
* Request to change screen * Request to change screen in {@link ScreenRegistry}
* *
* @author Ondřej Hruška (MightyPork) * @author Ondřej Hruška (MightyPork)
*/ */
@ -17,6 +18,8 @@ public class ScreenRequest extends BusEvent<ScreenRequestListener> {
/** /**
* Create a request to change screen
*
* @param screenKey screen name * @param screenKey screen name
*/ */
public ScreenRequest(String screenKey) public ScreenRequest(String screenKey)

@ -11,7 +11,8 @@ import mightypork.utils.eventbus.clients.DelegatingClient;
/** /**
* Screen with multiple instances of {@link ScreenLayer} * Screen with multiple instances of {@link ScreenLayer}. Layers specify their
* rendering and event priority.
* *
* @author Ondřej Hruška (MightyPork) * @author Ondřej Hruška (MightyPork)
*/ */
@ -46,6 +47,9 @@ public abstract class LayeredScreen extends Screen {
private final LayersClient layersClient = new LayersClient(); private final LayersClient layersClient = new LayersClient();
/**
* Create a layered screen
*/
public LayeredScreen() public LayeredScreen()
{ {
addChildClient(layersClient); addChildClient(layersClient);
@ -64,7 +68,7 @@ public abstract class LayeredScreen extends Screen {
/** /**
* Add a layer to the screen. * Add a layer to the screen.
* *
* @param layer * @param layer the layer to add
*/ */
protected void addLayer(ScreenLayer layer) protected void addLayer(ScreenLayer layer)
{ {

@ -44,14 +44,16 @@ public abstract class Overlay extends BusNode implements Comparable<Overlay>, Up
/** Extra rendered items (outside root) */ /** Extra rendered items (outside root) */
protected final Collection<Renderable> rendered = new ArrayList<>(); protected final Collection<Renderable> rendered = new ArrayList<>();
/** Extra updated items (outside root - those can just implement Updateable) */ /** Extra updated items (not members of the component tree) */
protected final Collection<Updateable> updated = new ArrayList<>(); protected final Collection<Updateable> updated = new ArrayList<>();
private Num alphaMul = Num.ONE; private Num alphaMul = Num.ONE;
/**
* Create an overlay over the screen
*/
public Overlay() public Overlay()
{ {
this.mouse = App.input().getMousePos(); this.mouse = App.input().getMousePos();
this.root = new ConstraintLayout(App.gfx().getRect()); this.root = new ConstraintLayout(App.gfx().getRect());
@ -182,18 +184,31 @@ public abstract class Overlay extends BusNode implements Comparable<Overlay>, Up
} }
/**
* Set overlay's alpha multiplier
*
* @param alpha alpha multiplier
*/
public void setAlpha(Num alpha) public void setAlpha(Num alpha)
{ {
this.alphaMul = alpha; this.alphaMul = alpha;
} }
/**
* Set overlay's alpha multiplier
*
* @param alpha alpha multiplier
*/
public void setAlpha(double alpha) public void setAlpha(double alpha)
{ {
this.alphaMul = Num.make(alpha); this.alphaMul = Num.make(alpha);
} }
/**
* Show and set enabled
*/
public void show() public void show()
{ {
setVisible(true); setVisible(true);
@ -201,6 +216,9 @@ public abstract class Overlay extends BusNode implements Comparable<Overlay>, Up
} }
/**
* Hide and set disabled
*/
public void hide() public void hide()
{ {
setVisible(false); setVisible(false);

@ -28,9 +28,12 @@ public abstract class Screen extends BusNode implements Renderable, RectBound, K
private volatile boolean needSetupViewport = false; private volatile boolean needSetupViewport = false;
/**
* Make a screen. The screen will initially not listen to the bus, which is
* changed once the setActive method is set to true.
*/
public Screen() public Screen()
{ {
// disable events initially // disable events initially
setListening(false); setListening(false);
@ -134,6 +137,7 @@ public abstract class Screen extends BusNode implements Renderable, RectBound, K
@Stub @Stub
protected void onScreenEnter() protected void onScreenEnter()
{ {
//
} }
@ -143,6 +147,7 @@ public abstract class Screen extends BusNode implements Renderable, RectBound, K
@Stub @Stub
protected void onScreenLeave() protected void onScreenLeave()
{ {
//
} }

@ -5,6 +5,7 @@ import mightypork.gamecore.core.App;
import mightypork.gamecore.gui.components.painters.QuadPainter; import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.events.ScreenRequest; import mightypork.gamecore.gui.events.ScreenRequest;
import mightypork.gamecore.gui.screens.Overlay; import mightypork.gamecore.gui.screens.Overlay;
import mightypork.gamecore.gui.screens.ScreenRegistry;
import mightypork.utils.math.animation.Easing; import mightypork.utils.math.animation.Easing;
import mightypork.utils.math.animation.NumAnimated; import mightypork.utils.math.animation.NumAnimated;
import mightypork.utils.math.color.pal.RGB; import mightypork.utils.math.color.pal.RGB;
@ -12,7 +13,7 @@ import mightypork.utils.math.timing.TimedTask;
/** /**
* Overlay used for cross-fading between screens * Overlay used for cross-fading between screens in {@link ScreenRegistry}
* *
* @author Ondřej Hruška (MightyPork) * @author Ondřej Hruška (MightyPork)
*/ */
@ -40,6 +41,9 @@ public class CrossfadeOverlay extends Overlay {
}; };
/**
* Create new crossfade overlay
*/
public CrossfadeOverlay() public CrossfadeOverlay()
{ {
final QuadPainter qp = new QuadPainter(RGB.BLACK); // TODO allow custom colors final QuadPainter qp = new QuadPainter(RGB.BLACK); // TODO allow custom colors
@ -60,6 +64,12 @@ public class CrossfadeOverlay extends Overlay {
} }
/**
* Go to specified screen
*
* @param screen screen alias
* @param fromDark true to fade from dark (ie. first screen in application)
*/
public void goToScreen(String screen, boolean fromDark) public void goToScreen(String screen, boolean fromDark)
{ {
requestedScreenName = screen; requestedScreenName = screen;
@ -77,7 +87,6 @@ public class CrossfadeOverlay extends Overlay {
alpha.setEasing(Easing.SINE_IN); alpha.setEasing(Easing.SINE_IN);
alpha.fadeIn(T_IN); alpha.fadeIn(T_IN);
} }
} }

@ -45,7 +45,7 @@ public abstract class FadingLayer extends ScreenLayer {
/** /**
* Create with default fading time and effect * Create with default fading time and effect
* *
* @param screen * @param screen the parent screen
*/ */
public FadingLayer(Screen screen) public FadingLayer(Screen screen)
{ {
@ -54,7 +54,9 @@ public abstract class FadingLayer extends ScreenLayer {
/** /**
* @param screen * Create with custom animator
*
* @param screen the parent screen
* @param easingAnim the animation num * @param easingAnim the animation num
*/ */
public FadingLayer(Screen screen, NumAnimated easingAnim) public FadingLayer(Screen screen, NumAnimated easingAnim)

@ -7,11 +7,23 @@ import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.utils.math.color.Color; import mightypork.utils.math.color.Color;
/**
* Screen overlay with a given color.
*
* @author Ondřej Hruška (MightyPork)
*/
public class LayerColor extends ScreenLayer { public class LayerColor extends ScreenLayer {
private final int zIndex; private final int zIndex;
/**
* Overlay with color
*
* @param screen the parent screen
* @param color the used color
* @param zIndex z-index in the screen
*/
public LayerColor(Screen screen, Color color, int zIndex) public LayerColor(Screen screen, Color color, int zIndex)
{ {
super(screen); super(screen);

Loading…
Cancel
Save