Cleanup; Remembers last window size / FS and restores on next startup

v5stable
Ondřej Hruška 11 years ago
parent c7dfe5b39b
commit 4e1d89d3ca
  1. 26
      src/mightypork/gamecore/Config.java
  2. 1
      src/mightypork/gamecore/WorkDir.java
  3. 5
      src/mightypork/gamecore/core/BaseApp.java
  4. 4
      src/mightypork/gamecore/core/events/ShudownRequest.java
  5. 8
      src/mightypork/gamecore/eventbus/clients/ClientList.java
  6. 4
      src/mightypork/gamecore/eventbus/clients/DelegatingList.java
  7. 4
      src/mightypork/gamecore/gui/components/input/ClickableWrapper.java
  8. 5
      src/mightypork/gamecore/gui/components/layout/linear/AbstractLinearWrapper.java
  9. 3
      src/mightypork/gamecore/gui/screens/ScreenRegistry.java
  10. 5
      src/mightypork/gamecore/input/KeyBinding.java
  11. 6
      src/mightypork/gamecore/input/KeyStroke.java
  12. 2
      src/mightypork/gamecore/util/files/config/SortedProperties.java
  13. 17
      src/mightypork/rogue/RogueApp.java
  14. 4
      src/mightypork/rogue/RogueConfig.java
  15. 5
      src/mightypork/rogue/screens/RogueScreen.java
  16. 4
      src/mightypork/rogue/screens/game/DeathLayer.java
  17. 8
      src/mightypork/rogue/screens/game/InventoryLayer.java
  18. 1
      src/mightypork/rogue/screens/game/ScreenGame.java
  19. 2
      src/mightypork/rogue/world/WorldProvider.java
  20. 2
      src/mightypork/rogue/world/events/PlayerKilledEvent.java
  21. 4
      src/mightypork/rogue/world/gen/WorldCreator.java
  22. 7
      src/mightypork/rogue/world/gui/interaction/MIPKeyboard.java

@ -32,7 +32,8 @@ public class Config {
*/
public static class KeyOpts {
private KeyOpts() {
private KeyOpts()
{
}
@ -44,7 +45,7 @@ public class Config {
public void add(String cfgKey, String dataString, String comment)
{
KeyProperty kprop = new KeyProperty(prefixKey(cfgKey), KeyStroke.createFromDataString(dataString), comment);
final KeyProperty kprop = new KeyProperty(prefixKey(cfgKey), KeyStroke.createFromDataString(dataString), comment);
strokes.put(prefixKey(cfgKey), kprop);
cfg.putProperty(kprop);
}
@ -66,7 +67,8 @@ public class Config {
*/
public static class KeyProperty extends Property<KeyStroke> {
public KeyProperty(String key, KeyStroke defaultValue, String comment) {
public KeyProperty(String key, KeyStroke defaultValue, String comment)
{
super(key, defaultValue, comment);
}
@ -172,13 +174,17 @@ public class Config {
* @param key
* @return option value
*/
public static <T> T getOption(String key)
public static <T> T getValue(String key)
{
if (cfg.getProperty(key) == null) {
throw new IllegalArgumentException("No such property: " + key);
}
try {
if (cfg.getProperty(key) == null) {
throw new IllegalArgumentException("No such property: " + key);
}
return cfg.getValue(key);
return cfg.getValue(key);
} catch (final ClassCastException cce) {
throw new RuntimeException("Property of incompatible type: " + key);
}
}
@ -188,15 +194,13 @@ public class Config {
* @param key option key
* @param value value to set
*/
public static <T> void setOption(String key, T value)
public static <T> void setValue(String key, T value)
{
if (cfg.getProperty(key) == null) {
throw new IllegalArgumentException("No such property: " + key);
}
cfg.setValue(key, value);
Log.f3("Setting option: " + key + " = " + value);
}

@ -47,6 +47,7 @@ public class WorkDir {
/**
* Add a path alias (dir or file)
*
* @param alias path alias
* @param path path relative to workdir
*/

@ -164,7 +164,8 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
}
public BaseApp(File workdir, boolean singleInstance) {
public BaseApp(File workdir, boolean singleInstance)
{
WorkDir.init(workdir);
Log.i("Using workdir: " + WorkDir.getWorkDir());
@ -303,7 +304,6 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
}
@DefaultImpl
protected void registerIonizables()
{
Ion.registerType(Coord.ION_MARK, Coord.class);
@ -359,7 +359,6 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
*
* @param screens
*/
@DefaultImpl
protected void initScreens(ScreenRegistry screens)
{
screens.addOverlay(new CrossfadeOverlay(this));

@ -8,8 +8,8 @@ import mightypork.gamecore.eventbus.event_flags.SingleReceiverEvent;
/**
* Shutdown request, non-interactive. Shutdown needs to execute on GL thread for display to
* deinit properly.
* Shutdown request, non-interactive. Shutdown needs to execute on GL thread for
* display to deinit properly.
*
* @author MightyPork
*/

@ -2,9 +2,6 @@ package mightypork.gamecore.eventbus.clients;
import java.util.ArrayList;
import java.util.Collection;
import mightypork.gamecore.gui.Enableable;
/**
@ -14,8 +11,9 @@ import mightypork.gamecore.gui.Enableable;
*/
public class ClientList extends ArrayList<Object> {
public ClientList(Object... clients) {
for (Object c : clients) {
public ClientList(Object... clients)
{
for (final Object c : clients) {
super.add(c);
}
}

@ -1,7 +1,6 @@
package mightypork.gamecore.eventbus.clients;
import java.util.ArrayList;
import java.util.Collection;
import mightypork.gamecore.gui.Enableable;
@ -17,7 +16,8 @@ public class DelegatingList extends ClientList implements DelegatingClient, Enab
private boolean enabled = true;
public DelegatingList(Object... clients) {
public DelegatingList(Object... clients)
{
super(clients);
}

@ -5,7 +5,6 @@ import java.util.Collection;
import mightypork.gamecore.eventbus.clients.ClientList;
import mightypork.gamecore.eventbus.clients.DelegatingClient;
import mightypork.gamecore.eventbus.clients.DelegatingList;
import mightypork.gamecore.gui.components.Component;
@ -15,7 +14,8 @@ public class ClickableWrapper extends ClickableComponent implements DelegatingCl
private final ClientList list;
public ClickableWrapper(Component wrapped) {
public ClickableWrapper(Component wrapped)
{
this.wrapped = wrapped;
wrapped.setRect(this);

@ -1,9 +1,7 @@
package mightypork.gamecore.gui.components.layout.linear;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import mightypork.gamecore.eventbus.clients.ClientList;
import mightypork.gamecore.eventbus.clients.DelegatingClient;
@ -25,7 +23,8 @@ public abstract class AbstractLinearWrapper extends LinearComponent implements D
/**
* @param wrapped wrapped component. Can be null.
*/
public AbstractLinearWrapper(Component wrapped) {
public AbstractLinearWrapper(Component wrapped)
{
this.wrapped = wrapped;
if (wrapped != null) {
if (wrapped instanceof LinearComponent) {

@ -32,7 +32,8 @@ public class ScreenRegistry extends AppModule implements ScreenRequestListener,
/**
* @param app app access
*/
public ScreenRegistry(AppAccess app) {
public ScreenRegistry(AppAccess app)
{
super(app);
}

@ -25,7 +25,8 @@ public class KeyBinding implements KeyEventHandler, InputReadyListener {
* @param stroke trigger keystroke
* @param handler action
*/
public KeyBinding(KeyStroke stroke, Edge edge, Runnable handler) {
public KeyBinding(KeyStroke stroke, Edge edge, Runnable handler)
{
this.keystroke = stroke;
this.handler = handler;
this.edge = edge;
@ -58,7 +59,7 @@ public class KeyBinding implements KeyEventHandler, InputReadyListener {
@Override
public void receive(KeyEvent event)
{
boolean nowDown = keystroke.isDown();
final boolean nowDown = keystroke.isDown();
boolean trigger = false;
trigger |= (edge == Edge.FALLING && (!wasDown && nowDown));

@ -28,7 +28,8 @@ public class KeyStroke { //implements Pollable
* @param key key code
* @param mod_mask mods mask
*/
public KeyStroke(int key, int mod_mask) {
public KeyStroke(int key, int mod_mask)
{
setTo(key, mod_mask);
}
@ -38,7 +39,8 @@ public class KeyStroke { //implements Pollable
*
* @param key key code
*/
public KeyStroke(int key) {
public KeyStroke(int key)
{
this(key, Keys.MOD_NONE);
}

@ -292,7 +292,7 @@ public class SortedProperties extends java.util.Properties {
sb.append(c);
}
String read = sb.toString().replaceAll("(#|;|//|--)[^\n]*\n", "\n");
final String read = sb.toString().replaceAll("(#|;|//|--)[^\n]*\n", "\n");
final String inputString = escapifyStr(read);
final byte[] bs = inputString.getBytes("ISO-8859-1");

@ -63,7 +63,12 @@ public final class RogueApp extends BaseApp implements ViewportChangeListener {
@Override
protected void initDisplay(DisplaySystem display)
{
display.createMainWindow(Const.WINDOW_W, Const.WINDOW_H, true, Config.<Boolean> getOption("opt.fullscreen"), Const.TITLEBAR);
// init based on config
final int w = Config.getValue("display.width");
final int h = Config.getValue("display.height");
final boolean fs = Config.getValue("display.fullscreen");
display.createMainWindow(w, h, true, fs, Const.TITLEBAR);
display.setTargetFps(Const.FPS_RENDER);
}
@ -129,6 +134,14 @@ public final class RogueApp extends BaseApp implements ViewportChangeListener {
@Override
public void onViewportChanged(ViewportChangeEvent event)
{
Config.setOption("opt.fullscreen", DisplaySystem.isFullscreen());
// save viewport size to config file
final boolean fs = DisplaySystem.isFullscreen();
Config.setValue("display.fullscreen", fs);
if (!fs) {
Config.setValue("display.width", DisplaySystem.getWidth());
Config.setValue("display.height", DisplaySystem.getHeight());
}
}
}

@ -10,7 +10,9 @@ public class RogueConfig implements ConfigSetup {
@Override
public void addOptions(PropertyManager prop)
{
prop.putBoolean("opt.fullscreen", false, "Start in fullscreen (remembers state at exit)");
prop.putBoolean("display.fullscreen", false, "Start in fullscreen (remembers state at exit)");
prop.putInteger("display.width", 1024, "Initial width (remembers from last time)");
prop.putInteger("display.height", 768, "Initial height (remembers from last time)");
}
}

@ -1,5 +1,6 @@
package mightypork.rogue.screens;
import mightypork.gamecore.core.AppAccess;
import mightypork.gamecore.core.events.UserQuitRequest;
import mightypork.gamecore.core.events.UserQuitRequestListener;
@ -11,10 +12,12 @@ import mightypork.rogue.events.RogueStateRequest;
public class RogueScreen extends LayeredScreen implements UserQuitRequestListener {
public RogueScreen(AppAccess app) {
public RogueScreen(AppAccess app)
{
super(app);
}
@Override
@DefaultImpl
public void onQuitRequest(UserQuitRequest event)

@ -67,7 +67,7 @@ public class DeathLayer extends ScreenLayer {
btn2.textPainter.setVPaddingPercent(25);
linl.add(btn2);
Action load = new Action() {
final Action load = new Action() {
@Override
protected void execute()
@ -81,7 +81,7 @@ public class DeathLayer extends ScreenLayer {
}
};
Action quit = new Action() {
final Action quit = new Action() {
@Override
protected void execute()

@ -37,7 +37,7 @@ public class InventoryLayer extends ScreenLayer {
@Override
public String getString()
{
String s = keyClose+"-close";
String s = keyClose + "-close";
final int selected = getSelectedSlot();
if (selected != -1) {
@ -46,14 +46,14 @@ public class InventoryLayer extends ScreenLayer {
final Item itm = pl.getInventory().getItem(selected);
if (itm != null && !itm.isEmpty()) {
s = keyDrop+"-drop," + s;
s = keyDrop + "-drop," + s;
if (itm.getType() == ItemType.FOOD) {
s = keyUse+"-eat," + s;
s = keyUse + "-eat," + s;
}
if (itm.getType() == ItemType.WEAPON) {
s = keyUse+"-equip," + s;
s = keyUse + "-equip," + s;
}
}
} else {

@ -306,6 +306,7 @@ public class ScreenGame extends RogueScreen implements PlayerDeathHandler {
setState(GScrState.DEATH);
}
@Override
public void onQuitRequest(UserQuitRequest event)
{

@ -112,7 +112,7 @@ public class WorldProvider extends RootBusNode {
throw new IllegalStateException("Trying to save world to a NULL file.");
}
if(world.getPlayer().isDead()) {
if (world.getPlayer().isDead()) {
throw new IllegalStateException("Cannot save, player is dead.");
}

@ -11,7 +11,7 @@ public class PlayerKilledEvent extends BusEvent<PlayerDeathHandler> {
protected void handleBy(PlayerDeathHandler handler)
{
// not dead, discard event.
if(!WorldProvider.get().getPlayer().isDead()) return;
if (!WorldProvider.get().getPlayer().isDead()) return;
handler.onPlayerKilled();
}

@ -126,9 +126,9 @@ public class WorldCreator {
// compile levels
Log.f3("Building levels...");
int i=1;
int i = 1;
for (final LevelBuilder lb : levelBuilders) {
Log.f3("Building level "+i);
Log.f3("Building level " + i);
w.addLevel(lb.build(w));
i++;
}

@ -11,10 +11,8 @@ import mightypork.gamecore.eventbus.events.Updateable;
import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.input.KeyBindingPool;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.Keys;
import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.input.events.KeyEvent;
import mightypork.gamecore.input.events.KeyEventHandler;
import mightypork.gamecore.input.Keys;
import mightypork.gamecore.util.math.algo.Move;
import mightypork.gamecore.util.math.algo.Moves;
import mightypork.gamecore.util.math.constraints.vect.Vect;
@ -58,7 +56,8 @@ public class MIPKeyboard extends MapInteractionPlugin implements DelegatingClien
}
public MIPKeyboard(MapView mapView) {
public MIPKeyboard(MapView mapView)
{
super(mapView);
for (int i = 0; i < 4; i++) {

Loading…
Cancel
Save