Fixed bug in layouts & enabling; added force quit command CS-Q

v5stable
Ondřej Hruška 11 years ago
parent d2d5809c80
commit 47e8cf419a
  1. 2
      src/mightypork/gamecore/core/BaseApp.java
  2. 45
      src/mightypork/gamecore/gui/components/BaseComponent.java
  3. 19
      src/mightypork/gamecore/gui/components/Component.java
  4. 17
      src/mightypork/gamecore/gui/components/LayoutComponent.java
  5. 13
      src/mightypork/gamecore/gui/components/input/ClickableWrapper.java
  6. 18
      src/mightypork/gamecore/gui/components/layout/NullComponent.java
  7. 18
      src/mightypork/gamecore/gui/components/layout/linear/AbstractLinearWrapper.java
  8. 10
      src/mightypork/gamecore/gui/components/layout/linear/LinearGap.java
  9. 2
      src/mightypork/gamecore/resources/AsyncResourceLoader.java
  10. 2
      src/mightypork/rogue/RogueApp.java
  11. 2
      src/mightypork/rogue/RogueKeys.java
  12. 2
      src/mightypork/rogue/screens/select_world/ScreenSelectWorld.java
  13. 12
      src/mightypork/rogue/screens/select_world/WorldSlot.java

@ -326,7 +326,7 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
try { try {
txt += " Workdir ....... " + WorkDir.getWorkDir().getCanonicalPath() + "\n"; txt += " Workdir ....... " + WorkDir.getWorkDir().getCanonicalPath() + "\n";
} catch (IOException e) { } catch (final IOException e) {
Log.e(e); Log.e(e);
} }

@ -26,8 +26,9 @@ public abstract class BaseComponent extends AbstractRectCache implements Compone
private Rect source; private Rect source;
private boolean visible = true; private boolean visible = true;
private boolean enabled = true;
private int indirectDisableLevel = 0;
private int disableLevel = 0;
private Num alphaMul = Num.ONE; private Num alphaMul = Num.ONE;
@ -94,7 +95,8 @@ public abstract class BaseComponent extends AbstractRectCache implements Compone
} }
protected boolean isMouseOver() @Override
public final boolean isMouseOver()
{ {
return InputSystem.getMousePos().isInside(this); return InputSystem.getMousePos().isInside(this);
} }
@ -116,29 +118,52 @@ public abstract class BaseComponent extends AbstractRectCache implements Compone
@Override @Override
public void setEnabled(boolean yes) public void setEnabled(boolean yes)
{ {
if (yes) { enabled = yes;
if (disableLevel > 0) disableLevel--;
} else {
disableLevel++;
}
} }
@Override @Override
public boolean isEnabled() public boolean isEnabled()
{ {
return disableLevel == 0; return enabled && isIndirectlyEnabled();
} }
public void setAlpha(Num alpha) @Override
public final void setAlpha(Num alpha)
{ {
this.alphaMul = alpha; this.alphaMul = alpha;
} }
public void setAlpha(double alpha) @Override
public final void setAlpha(double alpha)
{ {
this.alphaMul = Num.make(alpha); this.alphaMul = Num.make(alpha);
} }
@Override
public void setIndirectlyEnabled(boolean yes)
{
if (!yes) {
indirectDisableLevel++;
} else {
if (indirectDisableLevel > 0) indirectDisableLevel--;
}
}
@Override
public boolean isIndirectlyEnabled()
{
return indirectDisableLevel == 0;
}
@Override
public boolean isDirectlyEnabled()
{
return enabled;
}
} }

@ -3,6 +3,7 @@ package mightypork.gamecore.gui.components;
import mightypork.gamecore.gui.Enableable; import mightypork.gamecore.gui.Enableable;
import mightypork.gamecore.gui.Hideable; import mightypork.gamecore.gui.Hideable;
import mightypork.gamecore.util.math.constraints.num.Num;
/** /**
@ -24,4 +25,22 @@ public interface Component extends Enableable, Hideable, PluggableRenderable {
* constraints derived from it. * constraints derived from it.
*/ */
void updateLayout(); void updateLayout();
boolean isMouseOver();
void setAlpha(Num alpha);
void setAlpha(double alpha);
void setIndirectlyEnabled(boolean yes);
boolean isIndirectlyEnabled();
boolean isDirectlyEnabled();
} }

@ -16,8 +16,6 @@ import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound;
public abstract class LayoutComponent extends BaseComponent implements ClientHub, AppAccess { public abstract class LayoutComponent extends BaseComponent implements ClientHub, AppAccess {
private boolean enabled;
private final AppSubModule subModule; private final AppSubModule subModule;
final LinkedList<Component> components = new LinkedList<>(); final LinkedList<Component> components = new LinkedList<>();
@ -109,9 +107,12 @@ public abstract class LayoutComponent extends BaseComponent implements ClientHub
@Override @Override
public void setEnabled(boolean yes) public void setEnabled(boolean yes)
{ {
if (isDirectlyEnabled() != yes) {
super.setEnabled(yes); super.setEnabled(yes);
for (final Component c : components) { for (final Component c : components) {
c.setEnabled(yes); c.setIndirectlyEnabled(yes);
}
} }
} }
@ -148,4 +149,14 @@ public abstract class LayoutComponent extends BaseComponent implements ClientHub
} }
} }
@Override
public void setIndirectlyEnabled(boolean yes)
{
super.setIndirectlyEnabled(yes);
for (final Component cmp : components) {
cmp.setIndirectlyEnabled(yes);
}
}
} }

@ -38,24 +38,27 @@ public class ClickableWrapper extends ClickableComponent implements DelegatingCl
@Override @Override
public boolean isEnabled() protected void renderComponent()
{ {
return super.isEnabled() && wrapped.isEnabled(); wrapped.render();
} }
@Override @Override
public void setEnabled(boolean yes) public void setEnabled(boolean yes)
{ {
if (yes != super.isDirectlyEnabled()) {
super.setEnabled(yes); super.setEnabled(yes);
wrapped.setEnabled(yes); wrapped.setIndirectlyEnabled(yes);
}
} }
@Override @Override
protected void renderComponent() public void setIndirectlyEnabled(boolean yes)
{ {
wrapped.render(); super.setIndirectlyEnabled(yes);
wrapped.setIndirectlyEnabled(yes);
} }
} }

@ -0,0 +1,18 @@
package mightypork.gamecore.gui.components.layout;
import mightypork.gamecore.gui.components.BaseComponent;
/**
* Invisible component that does nothing at all; Null object pattern
*
* @author MightyPork
*/
public class NullComponent extends BaseComponent {
@Override
protected void renderComponent()
{
}
}

@ -58,4 +58,22 @@ public abstract class AbstractLinearWrapper extends LinearComponent implements D
{ {
return true; return true;
} }
@Override
public void setEnabled(boolean yes)
{
if (yes != super.isDirectlyEnabled()) {
super.setEnabled(yes);
wrapped.setIndirectlyEnabled(yes);
}
}
@Override
public void setIndirectlyEnabled(boolean yes)
{
super.setIndirectlyEnabled(yes);
wrapped.setIndirectlyEnabled(yes);
}
} }

@ -1,20 +1,26 @@
package mightypork.gamecore.gui.components.layout.linear; package mightypork.gamecore.gui.components.layout.linear;
import mightypork.gamecore.gui.components.layout.NullComponent;
import mightypork.gamecore.util.math.constraints.num.Num; import mightypork.gamecore.util.math.constraints.num.Num;
/**
* Gap in linear layout
*
* @author MightyPork
*/
public class LinearGap extends LinearRectangle { public class LinearGap extends LinearRectangle {
public LinearGap(Num width) public LinearGap(Num width)
{ {
super(null, width); super(new NullComponent(), width);
} }
public LinearGap(double heightPercent) public LinearGap(double heightPercent)
{ {
super(null, Num.ZERO); this(Num.ZERO);
setWidth(height().perc(heightPercent)); setWidth(height().perc(heightPercent));
} }
} }

@ -116,7 +116,7 @@ public class AsyncResourceLoader extends Thread implements ResourceLoader, Destr
@Override @Override
public void destroy() public void destroy()
{ {
Log.i("Stopping resource loader thread."); Log.f3("Stopping resource loader thread.");
stopped = true; stopped = true;
exs.shutdownNow(); exs.shutdownNow();
} }

@ -6,6 +6,7 @@ import java.io.File;
import mightypork.gamecore.Config; import mightypork.gamecore.Config;
import mightypork.gamecore.core.BaseApp; import mightypork.gamecore.core.BaseApp;
import mightypork.gamecore.core.events.MainLoopRequest; import mightypork.gamecore.core.events.MainLoopRequest;
import mightypork.gamecore.core.events.ShudownRequest;
import mightypork.gamecore.core.events.UserQuitRequest; import mightypork.gamecore.core.events.UserQuitRequest;
import mightypork.gamecore.eventbus.BusEvent; import mightypork.gamecore.eventbus.BusEvent;
import mightypork.gamecore.gui.screens.ScreenRegistry; import mightypork.gamecore.gui.screens.ScreenRegistry;
@ -105,6 +106,7 @@ public final class RogueApp extends BaseApp implements ViewportChangeListener, S
bindEventToKey(new ScreenshotRequest(), "global.screenshot"); bindEventToKey(new ScreenshotRequest(), "global.screenshot");
bindEventToKey(new UserQuitRequest(), "global.quit"); bindEventToKey(new UserQuitRequest(), "global.quit");
bindEventToKey(new ShudownRequest(), "global.quit_force");
} }

@ -11,6 +11,8 @@ public class RogueKeys implements Config.KeySetup {
public void addKeys(KeyOpts keys) public void addKeys(KeyOpts keys)
{ {
keys.add("global.quit", "CTRL+Q", "Quit the game"); keys.add("global.quit", "CTRL+Q", "Quit the game");
keys.add("global.quit_force", "CTRL+SHIFT+Q", "Quit the game without asking, low-level");
keys.add("global.screenshot", "F2", "Take screenshot (save into working directory)"); keys.add("global.screenshot", "F2", "Take screenshot (save into working directory)");
keys.add("global.fullscreen", "F11", "Toggle fullscreen"); keys.add("global.fullscreen", "F11", "Toggle fullscreen");
keys.add("global.fps_meter", "F3", "Toggle FPS meter overlay"); keys.add("global.fps_meter", "F3", "Toggle FPS meter overlay");

@ -11,6 +11,7 @@ import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.screens.Screen; import mightypork.gamecore.gui.screens.Screen;
import mightypork.gamecore.gui.screens.ScreenLayer; import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.input.KeyStroke.Edge; import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.logging.Log;
import mightypork.gamecore.resources.Res; import mightypork.gamecore.resources.Res;
import mightypork.gamecore.util.math.color.Color; import mightypork.gamecore.util.math.color.Color;
import mightypork.gamecore.util.math.color.pal.PAL16; import mightypork.gamecore.util.math.color.pal.PAL16;
@ -104,6 +105,7 @@ public class ScreenSelectWorld extends RogueScreen {
{ {
super.onScreenEnter(); super.onScreenEnter();
Log.f3("Refreshing save slots");
slot1.refresh(); slot1.refresh();
slot2.refresh(); slot2.refresh();
slot3.refresh(); slot3.refresh();

@ -146,7 +146,8 @@ public class WorldSlot extends ConstraintLayout {
@Override @Override
protected void execute() protected void execute()
{ {
file.delete(); Log.f3("Trying to delete: " + file);
if (!file.delete()) Log.w("Could not delete save file: " + file);
refresh(); refresh();
} }
}); });
@ -164,16 +165,17 @@ public class WorldSlot extends ConstraintLayout {
label = "<empty>"; label = "<empty>";
worldBundle = null; worldBundle = null;
} else { } else {
delBtn.setVisible(true);
delBtn.setEnabled(true);
try { try {
worldBundle = Ion.fromFile(file); worldBundle = Ion.fromFile(file);
final int lvl = worldBundle.get("meta.last_level", -1); final int lvl = worldBundle.get("meta.last_level", -1);
if (lvl == -1) throw new RuntimeException(); // let the catch block handle it if (lvl == -1) throw new RuntimeException("Invalid save format."); // let the catch block handle it
label = "Level " + (lvl + 1); label = "Level " + (lvl + 1);
delBtn.setVisible(true);
delBtn.setEnabled(true);
} catch (final Exception e) { } catch (final Exception e) {
Log.w("Error loading world save.", e); Log.w("Error loading world save.", e);
label = "<corrupt>"; label = "<corrupt>";

Loading…
Cancel
Save