diff --git a/src/mightypork/gamecore/core/BaseApp.java b/src/mightypork/gamecore/core/BaseApp.java index 750bc5a..853eea1 100644 --- a/src/mightypork/gamecore/core/BaseApp.java +++ b/src/mightypork/gamecore/core/BaseApp.java @@ -326,7 +326,7 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler { try { txt += " Workdir ....... " + WorkDir.getWorkDir().getCanonicalPath() + "\n"; - } catch (IOException e) { + } catch (final IOException e) { Log.e(e); } diff --git a/src/mightypork/gamecore/gui/components/BaseComponent.java b/src/mightypork/gamecore/gui/components/BaseComponent.java index 43c28b3..690af5e 100644 --- a/src/mightypork/gamecore/gui/components/BaseComponent.java +++ b/src/mightypork/gamecore/gui/components/BaseComponent.java @@ -26,8 +26,9 @@ public abstract class BaseComponent extends AbstractRectCache implements Compone private Rect source; private boolean visible = true; + private boolean enabled = true; + private int indirectDisableLevel = 0; - private int disableLevel = 0; 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); } @@ -116,29 +118,52 @@ public abstract class BaseComponent extends AbstractRectCache implements Compone @Override public void setEnabled(boolean yes) { - if (yes) { - if (disableLevel > 0) disableLevel--; - } else { - disableLevel++; - } + enabled = yes; } @Override public boolean isEnabled() { - return disableLevel == 0; + return enabled && isIndirectlyEnabled(); } - public void setAlpha(Num alpha) + @Override + public final void setAlpha(Num alpha) { this.alphaMul = alpha; } - public void setAlpha(double alpha) + @Override + public final void setAlpha(double 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; + } } diff --git a/src/mightypork/gamecore/gui/components/Component.java b/src/mightypork/gamecore/gui/components/Component.java index 2e3f9a6..5dbc6c2 100644 --- a/src/mightypork/gamecore/gui/components/Component.java +++ b/src/mightypork/gamecore/gui/components/Component.java @@ -3,6 +3,7 @@ package mightypork.gamecore.gui.components; import mightypork.gamecore.gui.Enableable; 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. */ void updateLayout(); + + + boolean isMouseOver(); + + + void setAlpha(Num alpha); + + + void setAlpha(double alpha); + + + void setIndirectlyEnabled(boolean yes); + + + boolean isIndirectlyEnabled(); + + + boolean isDirectlyEnabled(); } diff --git a/src/mightypork/gamecore/gui/components/LayoutComponent.java b/src/mightypork/gamecore/gui/components/LayoutComponent.java index ad4c6b9..47da70b 100644 --- a/src/mightypork/gamecore/gui/components/LayoutComponent.java +++ b/src/mightypork/gamecore/gui/components/LayoutComponent.java @@ -16,8 +16,6 @@ import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound; public abstract class LayoutComponent extends BaseComponent implements ClientHub, AppAccess { - private boolean enabled; - private final AppSubModule subModule; final LinkedList components = new LinkedList<>(); @@ -109,9 +107,12 @@ public abstract class LayoutComponent extends BaseComponent implements ClientHub @Override public void setEnabled(boolean yes) { - super.setEnabled(yes); - for (final Component c : components) { - c.setEnabled(yes); + if (isDirectlyEnabled() != yes) { + super.setEnabled(yes); + + for (final Component c : components) { + 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); + } + } } diff --git a/src/mightypork/gamecore/gui/components/input/ClickableWrapper.java b/src/mightypork/gamecore/gui/components/input/ClickableWrapper.java index fad4ac3..437d10c 100644 --- a/src/mightypork/gamecore/gui/components/input/ClickableWrapper.java +++ b/src/mightypork/gamecore/gui/components/input/ClickableWrapper.java @@ -38,24 +38,27 @@ public class ClickableWrapper extends ClickableComponent implements DelegatingCl @Override - public boolean isEnabled() + protected void renderComponent() { - return super.isEnabled() && wrapped.isEnabled(); + wrapped.render(); } @Override public void setEnabled(boolean yes) { - super.setEnabled(yes); - wrapped.setEnabled(yes); + if (yes != super.isDirectlyEnabled()) { + super.setEnabled(yes); + wrapped.setIndirectlyEnabled(yes); + } } @Override - protected void renderComponent() + public void setIndirectlyEnabled(boolean yes) { - wrapped.render(); + super.setIndirectlyEnabled(yes); + wrapped.setIndirectlyEnabled(yes); } } diff --git a/src/mightypork/gamecore/gui/components/layout/NullComponent.java b/src/mightypork/gamecore/gui/components/layout/NullComponent.java new file mode 100644 index 0000000..3aa753f --- /dev/null +++ b/src/mightypork/gamecore/gui/components/layout/NullComponent.java @@ -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() + { + } +} diff --git a/src/mightypork/gamecore/gui/components/layout/linear/AbstractLinearWrapper.java b/src/mightypork/gamecore/gui/components/layout/linear/AbstractLinearWrapper.java index bbd81a2..9c19418 100644 --- a/src/mightypork/gamecore/gui/components/layout/linear/AbstractLinearWrapper.java +++ b/src/mightypork/gamecore/gui/components/layout/linear/AbstractLinearWrapper.java @@ -58,4 +58,22 @@ public abstract class AbstractLinearWrapper extends LinearComponent implements D { 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); + } } diff --git a/src/mightypork/gamecore/gui/components/layout/linear/LinearGap.java b/src/mightypork/gamecore/gui/components/layout/linear/LinearGap.java index 4ca4697..520856f 100644 --- a/src/mightypork/gamecore/gui/components/layout/linear/LinearGap.java +++ b/src/mightypork/gamecore/gui/components/layout/linear/LinearGap.java @@ -1,20 +1,26 @@ package mightypork.gamecore.gui.components.layout.linear; +import mightypork.gamecore.gui.components.layout.NullComponent; import mightypork.gamecore.util.math.constraints.num.Num; +/** + * Gap in linear layout + * + * @author MightyPork + */ public class LinearGap extends LinearRectangle { public LinearGap(Num width) { - super(null, width); + super(new NullComponent(), width); } public LinearGap(double heightPercent) { - super(null, Num.ZERO); + this(Num.ZERO); setWidth(height().perc(heightPercent)); } } diff --git a/src/mightypork/gamecore/resources/AsyncResourceLoader.java b/src/mightypork/gamecore/resources/AsyncResourceLoader.java index 81a9dab..5dcc5c5 100644 --- a/src/mightypork/gamecore/resources/AsyncResourceLoader.java +++ b/src/mightypork/gamecore/resources/AsyncResourceLoader.java @@ -116,7 +116,7 @@ public class AsyncResourceLoader extends Thread implements ResourceLoader, Destr @Override public void destroy() { - Log.i("Stopping resource loader thread."); + Log.f3("Stopping resource loader thread."); stopped = true; exs.shutdownNow(); } diff --git a/src/mightypork/rogue/RogueApp.java b/src/mightypork/rogue/RogueApp.java index dd3aff1..b1d7eaa 100644 --- a/src/mightypork/rogue/RogueApp.java +++ b/src/mightypork/rogue/RogueApp.java @@ -6,6 +6,7 @@ import java.io.File; import mightypork.gamecore.Config; import mightypork.gamecore.core.BaseApp; import mightypork.gamecore.core.events.MainLoopRequest; +import mightypork.gamecore.core.events.ShudownRequest; import mightypork.gamecore.core.events.UserQuitRequest; import mightypork.gamecore.eventbus.BusEvent; 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 UserQuitRequest(), "global.quit"); + bindEventToKey(new ShudownRequest(), "global.quit_force"); } diff --git a/src/mightypork/rogue/RogueKeys.java b/src/mightypork/rogue/RogueKeys.java index ea05edd..023244b 100644 --- a/src/mightypork/rogue/RogueKeys.java +++ b/src/mightypork/rogue/RogueKeys.java @@ -11,6 +11,8 @@ public class RogueKeys implements Config.KeySetup { public void addKeys(KeyOpts keys) { 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.fullscreen", "F11", "Toggle fullscreen"); keys.add("global.fps_meter", "F3", "Toggle FPS meter overlay"); diff --git a/src/mightypork/rogue/screens/select_world/ScreenSelectWorld.java b/src/mightypork/rogue/screens/select_world/ScreenSelectWorld.java index c486817..689192d 100644 --- a/src/mightypork/rogue/screens/select_world/ScreenSelectWorld.java +++ b/src/mightypork/rogue/screens/select_world/ScreenSelectWorld.java @@ -11,6 +11,7 @@ import mightypork.gamecore.gui.components.painters.TextPainter; import mightypork.gamecore.gui.screens.Screen; import mightypork.gamecore.gui.screens.ScreenLayer; import mightypork.gamecore.input.KeyStroke.Edge; +import mightypork.gamecore.logging.Log; import mightypork.gamecore.resources.Res; import mightypork.gamecore.util.math.color.Color; import mightypork.gamecore.util.math.color.pal.PAL16; @@ -104,6 +105,7 @@ public class ScreenSelectWorld extends RogueScreen { { super.onScreenEnter(); + Log.f3("Refreshing save slots"); slot1.refresh(); slot2.refresh(); slot3.refresh(); diff --git a/src/mightypork/rogue/screens/select_world/WorldSlot.java b/src/mightypork/rogue/screens/select_world/WorldSlot.java index a4716ad..cbc3898 100644 --- a/src/mightypork/rogue/screens/select_world/WorldSlot.java +++ b/src/mightypork/rogue/screens/select_world/WorldSlot.java @@ -146,7 +146,8 @@ public class WorldSlot extends ConstraintLayout { @Override protected void execute() { - file.delete(); + Log.f3("Trying to delete: " + file); + if (!file.delete()) Log.w("Could not delete save file: " + file); refresh(); } }); @@ -164,16 +165,17 @@ public class WorldSlot extends ConstraintLayout { label = ""; worldBundle = null; } else { + + delBtn.setVisible(true); + delBtn.setEnabled(true); + try { worldBundle = Ion.fromFile(file); 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); - delBtn.setVisible(true); - delBtn.setEnabled(true); - } catch (final Exception e) { Log.w("Error loading world save.", e); label = "";