Remembers fullscreen on exit; fixed bug PropertyManager

v5stable
ondra 11 years ago
parent f082608852
commit 20bb7e56df
  1. 4
      src/mightypork/gamecore/Config.java
  2. 4
      src/mightypork/gamecore/gui/screens/ScreenRegistry.java
  3. 2
      src/mightypork/gamecore/render/DisplaySystem.java
  4. 2
      src/mightypork/gamecore/render/events/ViewportChangeEvent.java
  5. 2
      src/mightypork/gamecore/render/events/ViewportChangeListener.java
  6. 46
      src/mightypork/gamecore/util/files/config/PropertyManager.java
  7. 11
      src/mightypork/rogue/RogueApp.java
  8. 2
      src/mightypork/rogue/RogueConfig.java

@ -7,6 +7,7 @@ import java.util.Map;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.Keys;
import mightypork.gamecore.logging.Log;
import mightypork.gamecore.util.files.config.Property;
import mightypork.gamecore.util.files.config.PropertyManager;
@ -160,6 +161,7 @@ public class Config {
*/
public static void save()
{
Log.f3("Saving config.");
cfg.save();
}
@ -193,6 +195,8 @@ public class Config {
}
cfg.setValue(key, value);
Log.f3("Setting option: " + key + " = " + value);
}

@ -10,10 +10,10 @@ import mightypork.gamecore.core.AppAccess;
import mightypork.gamecore.core.AppModule;
import mightypork.gamecore.gui.events.LayoutChangeEvent;
import mightypork.gamecore.gui.events.ScreenRequestListener;
import mightypork.gamecore.gui.events.ViewportChangeEvent;
import mightypork.gamecore.gui.events.ViewportChangeListener;
import mightypork.gamecore.logging.Log;
import mightypork.gamecore.render.Renderable;
import mightypork.gamecore.render.events.ViewportChangeEvent;
import mightypork.gamecore.render.events.ViewportChangeListener;
import mightypork.gamecore.util.annot.DefaultImpl;

@ -7,9 +7,9 @@ import java.nio.ByteBuffer;
import mightypork.gamecore.core.AppAccess;
import mightypork.gamecore.core.AppModule;
import mightypork.gamecore.gui.events.ViewportChangeEvent;
import mightypork.gamecore.logging.Log;
import mightypork.gamecore.render.events.DisplayReadyEvent;
import mightypork.gamecore.render.events.ViewportChangeEvent;
import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound;
import mightypork.gamecore.util.math.constraints.vect.Vect;

@ -1,4 +1,4 @@
package mightypork.gamecore.gui.events;
package mightypork.gamecore.render.events;
import mightypork.gamecore.eventbus.BusEvent;

@ -1,4 +1,4 @@
package mightypork.gamecore.gui.events;
package mightypork.gamecore.render.events;
/**

@ -128,8 +128,6 @@ public class PropertyManager {
props.cfgBlankRowBetweenSections = cfgSeparateSections;
props.cfgBlankRowBeforeComment = cfgNewlineBeforeComments;
final ArrayList<String> keyList = new ArrayList<>();
// rename keys
for (final Entry<String, String> entry : renameTable.entrySet()) {
@ -141,28 +139,8 @@ public class PropertyManager {
props.setProperty(entry.getValue(), pr);
}
// validate entries one by one, replace with default when needed
for (final Property<?> entry : entries.values()) {
keyList.add(entry.getKey());
final String propOrig = props.getProperty(entry.getKey());
entry.parse(propOrig);
if (entry.getComment() != null) {
props.setKeyComment(entry.getKey(), entry.getComment());
}
if (propOrig == null || !entry.toString().equals(propOrig)) {
props.setProperty(entry.getKey(), entry.toString());
}
}
// removed unused props
for (final String propname : props.keySet().toArray(new String[props.size()])) {
if (!keyList.contains(propname)) {
props.remove(propname);
}
for (final Property<?> entry : entries.values()) {
entry.parse(props.getProperty(entry.getKey()));
}
renameTable.clear();
@ -172,6 +150,26 @@ public class PropertyManager {
public void save()
{
try {
final ArrayList<String> keyList = new ArrayList<>();
// validate entries one by one, replace with default when needed
for (final Property<?> entry : entries.values()) {
keyList.add(entry.getKey());
if (entry.getComment() != null) {
props.setKeyComment(entry.getKey(), entry.getComment());
}
props.setProperty(entry.getKey(), entry.toString());
}
// removed unused props
for (final String propname : props.keySet().toArray(new String[props.size()])) {
if (!keyList.contains(propname)) {
props.remove(propname);
}
}
props.store(new FileOutputStream(file), fileComment);
} catch (final IOException ioe) {
ioe.printStackTrace();

@ -14,6 +14,8 @@ import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.render.DisplaySystem;
import mightypork.gamecore.render.events.FullscreenToggleRequest;
import mightypork.gamecore.render.events.ScreenshotRequest;
import mightypork.gamecore.render.events.ViewportChangeEvent;
import mightypork.gamecore.render.events.ViewportChangeListener;
import mightypork.gamecore.util.ion.Ion;
import mightypork.rogue.RogueStateManager.RogueState;
import mightypork.rogue.events.RogueStateRequest;
@ -32,7 +34,7 @@ import mightypork.rogue.world.level.Level;
*
* @author MightyPork
*/
public final class RogueApp extends BaseApp {
public final class RogueApp extends BaseApp implements ViewportChangeListener {
public RogueApp(File workdir, boolean singleInstance)
{
@ -122,4 +124,11 @@ public final class RogueApp extends BaseApp {
}
}));
}
@Override
public void onViewportChanged(ViewportChangeEvent event)
{
Config.setOption("opt.fullscreen", DisplaySystem.isFullscreen());
}
}

@ -10,7 +10,7 @@ public class RogueConfig implements ConfigSetup {
@Override
public void addOptions(PropertyManager prop)
{
prop.putBoolean("opt.fullscreen", false, "Start in fullscreen");
prop.putBoolean("opt.fullscreen", false, "Start in fullscreen (remembers state at exit)");
}
}

Loading…
Cancel
Save