Cleanup; Remembers last window size / FS and restores on next startup
This commit is contained in:
@@ -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);
|
||||
} 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 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
|
||||
*/
|
||||
|
||||
@@ -7,7 +7,7 @@ package mightypork.gamecore.core.events;
|
||||
* @author MightyPork
|
||||
*/
|
||||
public interface UserQuitRequestListener {
|
||||
|
||||
|
||||
/**
|
||||
* Intercept quit request.<br>
|
||||
* 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.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) {
|
||||
|
||||
@@ -50,7 +50,7 @@ public abstract class ScreenLayer extends Overlay {
|
||||
protected void onScreenLeave()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isListening()
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@ public class PropertyManager {
|
||||
props.setProperty(entry.getValue(), pr);
|
||||
}
|
||||
|
||||
for (final Property<?> entry : entries.values()) {
|
||||
for (final Property<?> entry : entries.values()) {
|
||||
entry.parse(props.getProperty(entry.getKey()));
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -124,11 +129,19 @@ 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;
|
||||
@@ -10,11 +11,13 @@ 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)
|
||||
|
||||
@@ -125,8 +125,8 @@ public class AskSaveLayer extends ScreenLayer {
|
||||
}
|
||||
};
|
||||
|
||||
btn1.setAction(save);
|
||||
btn2.setAction(discard);
|
||||
btn1.setAction(save);
|
||||
btn2.setAction(discard);
|
||||
btn3.setAction(cancel);
|
||||
|
||||
bindKey(Config.getKey("general.close"), Edge.RISING, cancel);
|
||||
|
||||
@@ -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 {
|
||||
@@ -218,8 +218,8 @@ public class InventoryLayer extends ScreenLayer {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void setupGridWalkKeys()
|
||||
{
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class WorldCreator {
|
||||
public static World createWorld(long seed)
|
||||
{
|
||||
synchronized (rand) {
|
||||
|
||||
|
||||
Log.f2("Generating a new world...");
|
||||
|
||||
rand.setSeed(seed);
|
||||
@@ -39,7 +39,7 @@ public class WorldCreator {
|
||||
|
||||
// build the level rooms
|
||||
for (int floor = 1; floor <= 7; floor++) {
|
||||
|
||||
|
||||
Log.f3("Placing rooms for level: " + floor);
|
||||
|
||||
final LevelBuilder lb = prepareFloor(rand.nextLong(), floor, theme, floor == 7);
|
||||
@@ -91,7 +91,7 @@ public class WorldCreator {
|
||||
randomFood.add(Items.CHEESE);
|
||||
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 Range amount = Range.make(1, level);
|
||||
|
||||
@@ -102,7 +102,7 @@ public class WorldCreator {
|
||||
|
||||
|
||||
// place monsters
|
||||
|
||||
|
||||
Log.f3("Placing monsters...");
|
||||
for (int level = 1; level <= 7; level++) {
|
||||
|
||||
@@ -126,12 +126,12 @@ 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++;
|
||||
}
|
||||
}
|
||||
|
||||
w.createPlayer();
|
||||
|
||||
@@ -143,7 +143,7 @@ public class WorldCreator {
|
||||
|
||||
|
||||
public static LevelBuilder prepareFloor(long seed, int floor, MapTheme theme, boolean lastLevel) throws WorldGenError
|
||||
{
|
||||
{
|
||||
final LevelBuilder lb = new LevelBuilder(128, theme, seed);
|
||||
|
||||
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.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++) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user