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. 2
      src/mightypork/gamecore/core/events/UserQuitRequestListener.java
  6. 8
      src/mightypork/gamecore/eventbus/clients/ClientList.java
  7. 4
      src/mightypork/gamecore/eventbus/clients/DelegatingList.java
  8. 4
      src/mightypork/gamecore/gui/components/input/ClickableWrapper.java
  9. 5
      src/mightypork/gamecore/gui/components/layout/linear/AbstractLinearWrapper.java
  10. 2
      src/mightypork/gamecore/gui/screens/ScreenLayer.java
  11. 3
      src/mightypork/gamecore/gui/screens/ScreenRegistry.java
  12. 5
      src/mightypork/gamecore/input/KeyBinding.java
  13. 6
      src/mightypork/gamecore/input/KeyStroke.java
  14. 2
      src/mightypork/gamecore/util/files/config/PropertyManager.java
  15. 2
      src/mightypork/gamecore/util/files/config/SortedProperties.java
  16. 21
      src/mightypork/rogue/RogueApp.java
  17. 4
      src/mightypork/rogue/RogueConfig.java
  18. 9
      src/mightypork/rogue/screens/RogueScreen.java
  19. 4
      src/mightypork/rogue/screens/game/AskSaveLayer.java
  20. 4
      src/mightypork/rogue/screens/game/DeathLayer.java
  21. 12
      src/mightypork/rogue/screens/game/InventoryLayer.java
  22. 1
      src/mightypork/rogue/screens/game/ScreenGame.java
  23. 2
      src/mightypork/rogue/world/WorldProvider.java
  24. 2
      src/mightypork/rogue/world/events/PlayerKilledEvent.java
  25. 16
      src/mightypork/rogue/world/gen/WorldCreator.java
  26. 7
      src/mightypork/rogue/world/gui/interaction/MIPKeyboard.java

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

@ -47,6 +47,7 @@ public class WorkDir {
/** /**
* Add a path alias (dir or file) * Add a path alias (dir or file)
*
* @param alias path alias * @param alias path alias
* @param path path relative to workdir * @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); WorkDir.init(workdir);
Log.i("Using workdir: " + WorkDir.getWorkDir()); Log.i("Using workdir: " + WorkDir.getWorkDir());
@ -303,7 +304,6 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
} }
@DefaultImpl
protected void registerIonizables() protected void registerIonizables()
{ {
Ion.registerType(Coord.ION_MARK, Coord.class); Ion.registerType(Coord.ION_MARK, Coord.class);
@ -359,7 +359,6 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
* *
* @param screens * @param screens
*/ */
@DefaultImpl
protected void initScreens(ScreenRegistry screens) protected void initScreens(ScreenRegistry screens)
{ {
screens.addOverlay(new CrossfadeOverlay(this)); 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 * Shutdown request, non-interactive. Shutdown needs to execute on GL thread for
* deinit properly. * display to deinit properly.
* *
* @author MightyPork * @author MightyPork
*/ */

@ -7,7 +7,7 @@ package mightypork.gamecore.core.events;
* @author MightyPork * @author MightyPork
*/ */
public interface UserQuitRequestListener { public interface UserQuitRequestListener {
/** /**
* Intercept quit request.<br> * Intercept quit request.<br>
* Consume the event to abort shutdown (ie. ask user to save) * Consume the event to abort shutdown (ie. ask user to save)

@ -2,9 +2,6 @@ package mightypork.gamecore.eventbus.clients;
import java.util.ArrayList; 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 class ClientList extends ArrayList<Object> {
public ClientList(Object... clients) { public ClientList(Object... clients)
for (Object c : clients) { {
for (final Object c : clients) {
super.add(c); super.add(c);
} }
} }

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

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

@ -1,9 +1,7 @@
package mightypork.gamecore.gui.components.layout.linear; package mightypork.gamecore.gui.components.layout.linear;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import mightypork.gamecore.eventbus.clients.ClientList; import mightypork.gamecore.eventbus.clients.ClientList;
import mightypork.gamecore.eventbus.clients.DelegatingClient; 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. * @param wrapped wrapped component. Can be null.
*/ */
public AbstractLinearWrapper(Component wrapped) { public AbstractLinearWrapper(Component wrapped)
{
this.wrapped = wrapped; this.wrapped = wrapped;
if (wrapped != null) { if (wrapped != null) {
if (wrapped instanceof LinearComponent) { if (wrapped instanceof LinearComponent) {

@ -50,7 +50,7 @@ public abstract class ScreenLayer extends Overlay {
protected void onScreenLeave() protected void onScreenLeave()
{ {
} }
@Override @Override
public boolean isListening() public boolean isListening()

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

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

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

@ -139,7 +139,7 @@ public class PropertyManager {
props.setProperty(entry.getValue(), pr); props.setProperty(entry.getValue(), pr);
} }
for (final Property<?> entry : entries.values()) { for (final Property<?> entry : entries.values()) {
entry.parse(props.getProperty(entry.getKey())); entry.parse(props.getProperty(entry.getKey()));
} }

@ -292,7 +292,7 @@ public class SortedProperties extends java.util.Properties {
sb.append(c); 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 String inputString = escapifyStr(read);
final byte[] bs = inputString.getBytes("ISO-8859-1"); final byte[] bs = inputString.getBytes("ISO-8859-1");

@ -63,7 +63,12 @@ public final class RogueApp extends BaseApp implements ViewportChangeListener {
@Override @Override
protected void initDisplay(DisplaySystem display) 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); display.setTargetFps(Const.FPS_RENDER);
} }
@ -124,11 +129,19 @@ public final class RogueApp extends BaseApp implements ViewportChangeListener {
} }
})); }));
} }
@Override @Override
public void onViewportChanged(ViewportChangeEvent event) 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 @Override
public void addOptions(PropertyManager prop) 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; package mightypork.rogue.screens;
import mightypork.gamecore.core.AppAccess; import mightypork.gamecore.core.AppAccess;
import mightypork.gamecore.core.events.UserQuitRequest; import mightypork.gamecore.core.events.UserQuitRequest;
import mightypork.gamecore.core.events.UserQuitRequestListener; import mightypork.gamecore.core.events.UserQuitRequestListener;
@ -10,11 +11,13 @@ import mightypork.rogue.events.RogueStateRequest;
public class RogueScreen extends LayeredScreen implements UserQuitRequestListener { public class RogueScreen extends LayeredScreen implements UserQuitRequestListener {
public RogueScreen(AppAccess app) { public RogueScreen(AppAccess app)
{
super(app); super(app);
} }
@Override @Override
@DefaultImpl @DefaultImpl
public void onQuitRequest(UserQuitRequest event) public void onQuitRequest(UserQuitRequest event)

@ -125,8 +125,8 @@ public class AskSaveLayer extends ScreenLayer {
} }
}; };
btn1.setAction(save); btn1.setAction(save);
btn2.setAction(discard); btn2.setAction(discard);
btn3.setAction(cancel); btn3.setAction(cancel);
bindKey(Config.getKey("general.close"), Edge.RISING, cancel); bindKey(Config.getKey("general.close"), Edge.RISING, cancel);

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

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

@ -306,6 +306,7 @@ public class ScreenGame extends RogueScreen implements PlayerDeathHandler {
setState(GScrState.DEATH); setState(GScrState.DEATH);
} }
@Override @Override
public void onQuitRequest(UserQuitRequest event) 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."); 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."); throw new IllegalStateException("Cannot save, player is dead.");
} }

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

@ -26,7 +26,7 @@ public class WorldCreator {
public static World createWorld(long seed) public static World createWorld(long seed)
{ {
synchronized (rand) { synchronized (rand) {
Log.f2("Generating a new world..."); Log.f2("Generating a new world...");
rand.setSeed(seed); rand.setSeed(seed);
@ -39,7 +39,7 @@ public class WorldCreator {
// build the level rooms // build the level rooms
for (int floor = 1; floor <= 7; floor++) { for (int floor = 1; floor <= 7; floor++) {
Log.f3("Placing rooms for level: " + floor); Log.f3("Placing rooms for level: " + floor);
final LevelBuilder lb = prepareFloor(rand.nextLong(), floor, theme, floor == 7); final LevelBuilder lb = prepareFloor(rand.nextLong(), floor, theme, floor == 7);
@ -91,7 +91,7 @@ public class WorldCreator {
randomFood.add(Items.CHEESE); randomFood.add(Items.CHEESE);
randomFood.add(Items.MEAT); randomFood.add(Items.MEAT);
for (int level = 1; level <= 7; level++) { for (int level = 1; level <= 7; level++) {
final LevelBuilder lb = levelBuilders[level - 1]; final LevelBuilder lb = levelBuilders[level - 1];
final Range amount = Range.make(1, level); final Range amount = Range.make(1, level);
@ -102,7 +102,7 @@ public class WorldCreator {
// place monsters // place monsters
Log.f3("Placing monsters..."); Log.f3("Placing monsters...");
for (int level = 1; level <= 7; level++) { for (int level = 1; level <= 7; level++) {
@ -126,12 +126,12 @@ public class WorldCreator {
// compile levels // compile levels
Log.f3("Building levels..."); Log.f3("Building levels...");
int i=1; int i = 1;
for (final LevelBuilder lb : levelBuilders) { for (final LevelBuilder lb : levelBuilders) {
Log.f3("Building level "+i); Log.f3("Building level " + i);
w.addLevel(lb.build(w)); w.addLevel(lb.build(w));
i++; i++;
} }
w.createPlayer(); w.createPlayer();
@ -143,7 +143,7 @@ public class WorldCreator {
public static LevelBuilder prepareFloor(long seed, int floor, MapTheme theme, boolean lastLevel) throws WorldGenError public static LevelBuilder prepareFloor(long seed, int floor, MapTheme theme, boolean lastLevel) throws WorldGenError
{ {
final LevelBuilder lb = new LevelBuilder(128, theme, seed); final LevelBuilder lb = new LevelBuilder(128, theme, seed);
lb.addRoom(Rooms.ENTRANCE, BuildOrder.FIRST, true); lb.addRoom(Rooms.ENTRANCE, BuildOrder.FIRST, true);

@ -11,10 +11,8 @@ import mightypork.gamecore.eventbus.events.Updateable;
import mightypork.gamecore.input.InputSystem; import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.input.KeyBindingPool; import mightypork.gamecore.input.KeyBindingPool;
import mightypork.gamecore.input.KeyStroke; import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.Keys;
import mightypork.gamecore.input.KeyStroke.Edge; import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.input.events.KeyEvent; import mightypork.gamecore.input.Keys;
import mightypork.gamecore.input.events.KeyEventHandler;
import mightypork.gamecore.util.math.algo.Move; import mightypork.gamecore.util.math.algo.Move;
import mightypork.gamecore.util.math.algo.Moves; import mightypork.gamecore.util.math.algo.Moves;
import mightypork.gamecore.util.math.constraints.vect.Vect; 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); super(mapView);
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {

Loading…
Cancel
Save