Fixed bug in layouts & enabling; added force quit command CS-Q
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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<Component> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@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;
|
||||
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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 = "<empty>";
|
||||
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 = "<corrupt>";
|
||||
|
||||
Reference in New Issue
Block a user