diff --git a/src/mightypork/gamecore/gui/components/DynamicWidthComponent.java b/src/mightypork/gamecore/gui/components/DynamicWidthComponent.java new file mode 100644 index 0000000..06e51b4 --- /dev/null +++ b/src/mightypork/gamecore/gui/components/DynamicWidthComponent.java @@ -0,0 +1,7 @@ +package mightypork.gamecore.gui.components; + + +public interface DynamicWidthComponent extends Component { + + double computeWidth(double height); +} diff --git a/src/mightypork/gamecore/gui/components/LinearComponent.java b/src/mightypork/gamecore/gui/components/LinearComponent.java new file mode 100644 index 0000000..63e55f5 --- /dev/null +++ b/src/mightypork/gamecore/gui/components/LinearComponent.java @@ -0,0 +1,78 @@ +package mightypork.gamecore.gui.components; + + +import mightypork.gamecore.util.math.constraints.num.Num; +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; +import mightypork.gamecore.util.math.constraints.vect.proxy.VectAdapter; + + +public abstract class LinearComponent extends BaseComponent implements DynamicWidthComponent { + + private final Rect rect = new Rect() { + + @Override + public Vect size() + { + return new Vect() { + + @Override + public double x() + { + return computeWidth(y()); + } + + + @Override + public double y() + { + return height.value(); + } + + }; + } + + + @Override + public Vect origin() + { + return new VectAdapter() { + + @Override + protected Vect getSource() + { + return origin; + } + }; + } + }; + + private Vect origin; + private Num height; + + + public LinearComponent() + { + super.setRect(rect); + } + + + @Override + public void setRect(RectBound rect) + { + throw new RuntimeException("Cannot assign a rect to a linear component. Set origin and height instead."); + } + + + public void setHeight(Num height) + { + this.height = height; + } + + + public void setOrigin(Vect origin) + { + this.origin = origin; + } +} diff --git a/src/mightypork/gamecore/gui/components/ClickableComponent.java b/src/mightypork/gamecore/gui/components/input/ClickableComponent.java similarity index 89% rename from src/mightypork/gamecore/gui/components/ClickableComponent.java rename to src/mightypork/gamecore/gui/components/input/ClickableComponent.java index 9e65368..6dd2991 100644 --- a/src/mightypork/gamecore/gui/components/ClickableComponent.java +++ b/src/mightypork/gamecore/gui/components/input/ClickableComponent.java @@ -1,8 +1,9 @@ -package mightypork.gamecore.gui.components; +package mightypork.gamecore.gui.components.input; import mightypork.gamecore.gui.Action; import mightypork.gamecore.gui.ActionTrigger; +import mightypork.gamecore.gui.components.InputComponent; import mightypork.gamecore.input.events.MouseButtonEvent; import mightypork.gamecore.input.events.MouseButtonListener; diff --git a/src/mightypork/gamecore/gui/components/layout/ClickableWrapper.java b/src/mightypork/gamecore/gui/components/input/ClickableWrapper.java similarity index 89% rename from src/mightypork/gamecore/gui/components/layout/ClickableWrapper.java rename to src/mightypork/gamecore/gui/components/input/ClickableWrapper.java index 3c285d5..dd47183 100644 --- a/src/mightypork/gamecore/gui/components/layout/ClickableWrapper.java +++ b/src/mightypork/gamecore/gui/components/input/ClickableWrapper.java @@ -1,4 +1,4 @@ -package mightypork.gamecore.gui.components.layout; +package mightypork.gamecore.gui.components.input; import java.util.ArrayList; @@ -6,7 +6,6 @@ import java.util.Collection; import java.util.List; import mightypork.gamecore.eventbus.clients.DelegatingClient; -import mightypork.gamecore.gui.components.ClickableComponent; import mightypork.gamecore.gui.components.Component; diff --git a/src/mightypork/rogue/screens/PushButton.java b/src/mightypork/gamecore/gui/components/input/TextButton.java similarity index 76% rename from src/mightypork/rogue/screens/PushButton.java rename to src/mightypork/gamecore/gui/components/input/TextButton.java index 2a3bc01..9988709 100644 --- a/src/mightypork/rogue/screens/PushButton.java +++ b/src/mightypork/gamecore/gui/components/input/TextButton.java @@ -1,8 +1,8 @@ -package mightypork.rogue.screens; +package mightypork.gamecore.gui.components.input; import mightypork.gamecore.gui.AlignX; -import mightypork.gamecore.gui.components.ClickableComponent; +import mightypork.gamecore.gui.components.DynamicWidthComponent; import mightypork.gamecore.gui.components.painters.TextPainter; import mightypork.gamecore.input.InputSystem; import mightypork.gamecore.resources.fonts.GLFont; @@ -17,7 +17,7 @@ import mightypork.gamecore.util.math.constraints.vect.mutable.VectVar; * * @author MightyPork */ -public class PushButton extends ClickableComponent { +public class TextButton extends ClickableComponent implements DynamicWidthComponent { public final TextPainter textPainter; @@ -32,14 +32,14 @@ public class PushButton extends ClickableComponent { private boolean hoverMove = true; - public PushButton(GLFont font, String text, Color color) + public TextButton(GLFont font, String text, Color color) { this.color = color; this.textPainter = new TextPainter(font, AlignX.CENTER, this.color, text); this.textPainter.setRect(this); this.textPainter.setShadow(RGB.BLACK_30, offset); - textPainter.setPaddingHPerc(0, 5); + textPainter.setVPaddingPercent(5); } @@ -63,9 +63,16 @@ public class PushButton extends ClickableComponent { /** * Disable offset change on hover */ - public void disableHover() + public void disableHoverEffect() { hoverMove = false; } + + @Override + public double computeWidth(double height) + { + return textPainter.computeWidth(height); + } + } diff --git a/src/mightypork/gamecore/gui/components/layout/HorizontalFixedFlowLayout.java b/src/mightypork/gamecore/gui/components/layout/FlowColumnLayout.java similarity index 88% rename from src/mightypork/gamecore/gui/components/layout/HorizontalFixedFlowLayout.java rename to src/mightypork/gamecore/gui/components/layout/FlowColumnLayout.java index cde7ea2..fc76762 100644 --- a/src/mightypork/gamecore/gui/components/layout/HorizontalFixedFlowLayout.java +++ b/src/mightypork/gamecore/gui/components/layout/FlowColumnLayout.java @@ -15,7 +15,7 @@ import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound; * * @author MightyPork */ -public class HorizontalFixedFlowLayout extends LayoutComponent { +public class FlowColumnLayout extends LayoutComponent { private int col = 0; private Num elementWidth; @@ -28,7 +28,7 @@ public class HorizontalFixedFlowLayout extends LayoutComponent { * @param elementWidth width of all elements * @param align component align. Legal values are LEFT and RIGHT. */ - public HorizontalFixedFlowLayout(AppAccess app, RectBound context, Num elementWidth, AlignX align) + public FlowColumnLayout(AppAccess app, RectBound context, Num elementWidth, AlignX align) { super(app, context); this.elementWidth = elementWidth; @@ -48,7 +48,7 @@ public class HorizontalFixedFlowLayout extends LayoutComponent { * @param elementWidth width of all elements * @param align component align. Legal values are LEFT and RIGHT. */ - public HorizontalFixedFlowLayout(AppAccess app, Num elementWidth, AlignX align) + public FlowColumnLayout(AppAccess app, Num elementWidth, AlignX align) { this(app, null, elementWidth, align); } diff --git a/src/mightypork/gamecore/gui/components/layout/VerticalFixedFlowLayout.java b/src/mightypork/gamecore/gui/components/layout/FlowRowLayout.java similarity index 88% rename from src/mightypork/gamecore/gui/components/layout/VerticalFixedFlowLayout.java rename to src/mightypork/gamecore/gui/components/layout/FlowRowLayout.java index daf955f..65a52ef 100644 --- a/src/mightypork/gamecore/gui/components/layout/VerticalFixedFlowLayout.java +++ b/src/mightypork/gamecore/gui/components/layout/FlowRowLayout.java @@ -15,7 +15,7 @@ import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound; * * @author MightyPork */ -public class VerticalFixedFlowLayout extends LayoutComponent { +public class FlowRowLayout extends LayoutComponent { private int row = 0; private Num elementHeight; @@ -28,7 +28,7 @@ public class VerticalFixedFlowLayout extends LayoutComponent { * @param elementHeight height of all elements * @param align component align. Legal values are TOP and BOTTOM. */ - public VerticalFixedFlowLayout(AppAccess app, RectBound context, Num elementHeight, AlignY align) + public FlowRowLayout(AppAccess app, RectBound context, Num elementHeight, AlignY align) { super(app, context); this.elementHeight = elementHeight; @@ -48,7 +48,7 @@ public class VerticalFixedFlowLayout extends LayoutComponent { * @param elementHeight height of all elements * @param align component align. Legal values are TOP and BOTTOM. */ - public VerticalFixedFlowLayout(AppAccess app, Num elementHeight, AlignY align) + public FlowRowLayout(AppAccess app, Num elementHeight, AlignY align) { this(app, null, elementHeight, align); } diff --git a/src/mightypork/gamecore/gui/components/layout/linear/AbstractLinearWrapper.java b/src/mightypork/gamecore/gui/components/layout/linear/AbstractLinearWrapper.java new file mode 100644 index 0000000..69bcde2 --- /dev/null +++ b/src/mightypork/gamecore/gui/components/layout/linear/AbstractLinearWrapper.java @@ -0,0 +1,63 @@ +package mightypork.gamecore.gui.components.layout.linear; + + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import mightypork.gamecore.eventbus.clients.DelegatingClient; +import mightypork.gamecore.gui.components.Component; +import mightypork.gamecore.gui.components.LinearComponent; + + +/** + * Converts a component into a linear component + * + * @author MightyPork + */ +public abstract class AbstractLinearWrapper extends LinearComponent implements DelegatingClient { + + protected final Component wrapped; + private final List list; + + + /** + * @param wrapped wrapped component. Can be null. + */ + public AbstractLinearWrapper(Component wrapped) + { + this.wrapped = wrapped; + if (wrapped != null) { + if (wrapped instanceof LinearComponent) { + ((LinearComponent) wrapped).setHeight(height()); + ((LinearComponent) wrapped).setOrigin(origin()); + } else { + wrapped.setRect(this); + } + } + + list = new ArrayList<>(1); + list.add(wrapped); + } + + + @Override + protected void renderComponent() + { + if (wrapped != null) wrapped.render(); + } + + + @Override + public Collection getChildClients() + { + return list; + } + + + @Override + public boolean doesDelegate() + { + return true; + } +} diff --git a/src/mightypork/gamecore/gui/components/layout/linear/LinearGap.java b/src/mightypork/gamecore/gui/components/layout/linear/LinearGap.java new file mode 100644 index 0000000..4ca4697 --- /dev/null +++ b/src/mightypork/gamecore/gui/components/layout/linear/LinearGap.java @@ -0,0 +1,20 @@ +package mightypork.gamecore.gui.components.layout.linear; + + +import mightypork.gamecore.util.math.constraints.num.Num; + + +public class LinearGap extends LinearRectangle { + + public LinearGap(Num width) + { + super(null, width); + } + + + public LinearGap(double heightPercent) + { + super(null, Num.ZERO); + setWidth(height().perc(heightPercent)); + } +} diff --git a/src/mightypork/gamecore/gui/components/layout/linear/LinearLayout.java b/src/mightypork/gamecore/gui/components/layout/linear/LinearLayout.java new file mode 100644 index 0000000..4c4225e --- /dev/null +++ b/src/mightypork/gamecore/gui/components/layout/linear/LinearLayout.java @@ -0,0 +1,90 @@ +package mightypork.gamecore.gui.components.layout.linear; + + +import mightypork.gamecore.app.AppAccess; +import mightypork.gamecore.gui.AlignX; +import mightypork.gamecore.gui.components.DynamicWidthComponent; +import mightypork.gamecore.gui.components.LayoutComponent; +import mightypork.gamecore.gui.components.LinearComponent; +import mightypork.gamecore.util.math.constraints.num.Num; +import mightypork.gamecore.util.math.constraints.num.NumSum; +import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound; +import mightypork.gamecore.util.math.constraints.vect.Vect; +import mightypork.gamecore.util.math.constraints.vect.proxy.VectAdapter; + + +public class LinearLayout extends LayoutComponent { + + public LinearLayout(AppAccess app, AlignX align) + { + super(app); + this.align = align; + } + + + public LinearLayout(AppAccess app, RectBound context, AlignX align) + { + super(app, context); + this.align = align; + } + + private final NumSum totalWidth = new NumSum(); + + private final Vect leftAlignOrigin = LinearLayout.this.origin(); + private final Vect centerAlignOrigin = LinearLayout.this.topCenter().sub(totalWidth.half(), Num.ZERO); + private final Vect rightAlignOrigin = LinearLayout.this.topRight().sub(totalWidth, Num.ZERO); + + private final Vect leftMostOrigin = new VectAdapter() { + + @Override + protected Vect getSource() + { + switch (align) { + default: + case LEFT: + return leftAlignOrigin; + case CENTER: + return centerAlignOrigin; + case RIGHT: + return rightAlignOrigin; + } + } + }; + + private Vect nextOrigin = leftMostOrigin; + + private AlignX align = AlignX.LEFT; + + + public void add(DynamicWidthComponent dwcomp) + { + add(new LinearWrapper(dwcomp)); + } + + + public void add(LinearComponent lincomp) + { + lincomp.setHeight(height()); + lincomp.setOrigin(nextOrigin); + nextOrigin = nextOrigin.add(lincomp.width(), Num.ZERO); + totalWidth.addSummand(lincomp.width()); + attach(lincomp); + } + + + public void setAlign(AlignX align) + { + this.align = align; + } + + + /** + * Add a gap. + * + * @param heightPercent percent of height for gap width + */ + public void gap(double heightPercent) + { + add(new LinearGap(heightPercent)); + } +} diff --git a/src/mightypork/gamecore/gui/components/layout/linear/LinearRectangle.java b/src/mightypork/gamecore/gui/components/layout/linear/LinearRectangle.java new file mode 100644 index 0000000..35a7311 --- /dev/null +++ b/src/mightypork/gamecore/gui/components/layout/linear/LinearRectangle.java @@ -0,0 +1,32 @@ +package mightypork.gamecore.gui.components.layout.linear; + + +import mightypork.gamecore.gui.components.Component; +import mightypork.gamecore.util.math.constraints.num.Num; + + +public class LinearRectangle extends AbstractLinearWrapper { + + private Num width; + + + public LinearRectangle(Component wrapped, Num width) + { + super(wrapped); + this.width = width; + } + + + public void setWidth(Num width) + { + this.width = width; + } + + + @Override + public double computeWidth(double height) + { + return this.width.value(); + } + +} diff --git a/src/mightypork/gamecore/gui/components/layout/linear/LinearSquare.java b/src/mightypork/gamecore/gui/components/layout/linear/LinearSquare.java new file mode 100644 index 0000000..a3c37ee --- /dev/null +++ b/src/mightypork/gamecore/gui/components/layout/linear/LinearSquare.java @@ -0,0 +1,21 @@ +package mightypork.gamecore.gui.components.layout.linear; + + +import mightypork.gamecore.gui.components.Component; + + +public class LinearSquare extends AbstractLinearWrapper { + + public LinearSquare(Component wrapped) + { + super(wrapped); + } + + + @Override + public double computeWidth(double height) + { + return height; + } + +} diff --git a/src/mightypork/gamecore/gui/components/layout/linear/LinearWrapper.java b/src/mightypork/gamecore/gui/components/layout/linear/LinearWrapper.java new file mode 100644 index 0000000..2fe8896 --- /dev/null +++ b/src/mightypork/gamecore/gui/components/layout/linear/LinearWrapper.java @@ -0,0 +1,21 @@ +package mightypork.gamecore.gui.components.layout.linear; + + +import mightypork.gamecore.gui.components.DynamicWidthComponent; + + +public class LinearWrapper extends AbstractLinearWrapper { + + public LinearWrapper(DynamicWidthComponent wrapped) + { + super(wrapped); + } + + + @Override + public double computeWidth(double height) + { + return ((DynamicWidthComponent) wrapped).computeWidth(height); + } + +} diff --git a/src/mightypork/gamecore/gui/components/painters/ImagePainter.java b/src/mightypork/gamecore/gui/components/painters/ImagePainter.java index 95733cb..de90fa7 100644 --- a/src/mightypork/gamecore/gui/components/painters/ImagePainter.java +++ b/src/mightypork/gamecore/gui/components/painters/ImagePainter.java @@ -2,10 +2,9 @@ package mightypork.gamecore.gui.components.painters; import mightypork.gamecore.gui.components.BaseComponent; +import mightypork.gamecore.gui.components.DynamicWidthComponent; import mightypork.gamecore.render.Render; import mightypork.gamecore.resources.textures.TxQuad; -import mightypork.gamecore.util.math.constraints.num.Num; -import mightypork.gamecore.util.math.constraints.rect.Rect; /** @@ -13,11 +12,9 @@ import mightypork.gamecore.util.math.constraints.rect.Rect; * * @author MightyPork */ -public class ImagePainter extends BaseComponent { +public class ImagePainter extends BaseComponent implements DynamicWidthComponent { private final TxQuad txQuad; - private boolean aspratio = false; - private final Rect asprRect; /** @@ -26,20 +23,19 @@ public class ImagePainter extends BaseComponent { public ImagePainter(TxQuad txQuad) { this.txQuad = txQuad; - this.asprRect = ((Rect) this).axisV().grow(height().div(txQuad.uvs.height()).mul(txQuad.uvs.width()).half(), Num.ZERO);; } - public void keepAspectRatio() + @Override + public void renderComponent() { - aspratio = true; + Render.quadTextured(this, txQuad); } @Override - public void renderComponent() + public double computeWidth(double height) { - Render.quadTextured(aspratio ? asprRect : this, txQuad); + return (height / txQuad.uvs.height().value()) * txQuad.uvs.width().value(); } - } diff --git a/src/mightypork/gamecore/gui/components/painters/TextPainter.java b/src/mightypork/gamecore/gui/components/painters/TextPainter.java index dea4a26..920c410 100644 --- a/src/mightypork/gamecore/gui/components/painters/TextPainter.java +++ b/src/mightypork/gamecore/gui/components/painters/TextPainter.java @@ -3,6 +3,7 @@ package mightypork.gamecore.gui.components.painters; import mightypork.gamecore.gui.AlignX; import mightypork.gamecore.gui.components.BaseComponent; +import mightypork.gamecore.gui.components.DynamicWidthComponent; import mightypork.gamecore.render.Render; import mightypork.gamecore.resources.fonts.FontRenderer; import mightypork.gamecore.resources.fonts.GLFont; @@ -17,13 +18,11 @@ import mightypork.rogue.Config; /** - * Text painting component.
- * Drawing values are obtained through getters, so overriding getters can be - * used to change parameters dynamically. + * Text painting component. * * @author MightyPork */ -public class TextPainter extends BaseComponent { +public class TextPainter extends BaseComponent implements DynamicWidthComponent { private final FontRenderer font; private Color color; @@ -32,7 +31,6 @@ public class TextPainter extends BaseComponent { private boolean shadow; private double yPaddingPerc = 0; - private double xPaddingPerc = 0; private Color shadowColor = RGB.BLACK; private Vect shadowOffset = Vect.make(2, 2); @@ -47,28 +45,30 @@ public class TextPainter extends BaseComponent { } - /** - * Constructor for fixed text - * - * @param font font to use - * @param align text align - * @param color default color - * @param text drawn text - */ + public TextPainter(GLFont font, Color color, String text) + { + this(font, AlignX.LEFT, color, new StringWrapper(text)); + } + + + public TextPainter(GLFont font, Color color, StringProvider text) + { + this(font, AlignX.LEFT, color, text); + } + + + public TextPainter(GLFont font, Color color) + { + this(font, AlignX.LEFT, color, (StringProvider) null); + } + + public TextPainter(GLFont font, AlignX align, Color color, String text) { this(font, align, color, new StringWrapper(text)); } - /** - * COnstructor for changeable text. - * - * @param font font to use - * @param align text align - * @param color default color - * @param text text provider - */ public TextPainter(GLFont font, AlignX align, Color color, StringProvider text) { this.font = new FontRenderer(font); @@ -78,11 +78,6 @@ public class TextPainter extends BaseComponent { } - /** - * @param font font to use - * @param align text align - * @param color default color - */ public TextPainter(GLFont font, AlignX align, Color color) { this(font, align, color, (StringProvider) null); @@ -96,10 +91,9 @@ public class TextPainter extends BaseComponent { final String str = text.getString(); - final Num shrX = height().perc(xPaddingPerc); final Num shrY = height().perc(yPaddingPerc); - final Rect rect = getRect().shrink(shrX, shrY); + final Rect rect = getRect().shrink(Num.ZERO, shrY); if (shadow) { font.draw(str, rect.round(), align, shadowColor); @@ -162,9 +156,15 @@ public class TextPainter extends BaseComponent { } - public void setPaddingHPerc(double percX, double percY) + public void setVPaddingPercent(double percY) { - xPaddingPerc = percX; yPaddingPerc = percY; } + + + @Override + public double computeWidth(double height) + { + return font.getWidth(this.text.getString(), height * ((100 - yPaddingPerc * 2) / 100D)); + } } diff --git a/src/mightypork/gamecore/util/math/constraints/num/NumSum.java b/src/mightypork/gamecore/util/math/constraints/num/NumSum.java new file mode 100644 index 0000000..2262896 --- /dev/null +++ b/src/mightypork/gamecore/util/math/constraints/num/NumSum.java @@ -0,0 +1,49 @@ +package mightypork.gamecore.util.math.constraints.num; + + +import java.util.ArrayList; +import java.util.List; + + +/** + * Expandable sum of multiple numbers + * + * @author MightyPork + */ +public class NumSum extends Num { + + private final List summands = new ArrayList<>(); + + + @Override + public double value() + { + double v = 0; + for (final Num n : summands) { + if (n != null) v += n.value(); + } + return v; + } + + + /** + * Add a number to the sum + * + * @param summand added number + */ + public void addSummand(Num summand) + { + summands.add(summand); + } + + + /** + * Add a number to the sum + * + * @param summand added number + */ + public void addSummand(double summand) + { + summands.add(Num.make(summand)); + } +} diff --git a/src/mightypork/rogue/App.java b/src/mightypork/rogue/App.java index 0d518b6..6a22148 100644 --- a/src/mightypork/rogue/App.java +++ b/src/mightypork/rogue/App.java @@ -6,6 +6,7 @@ import java.util.Locale; import mightypork.gamecore.app.BaseApp; import mightypork.gamecore.app.MainLoop; +import mightypork.gamecore.app.MainLoopRequest; import mightypork.gamecore.eventbus.BusEvent; import mightypork.gamecore.eventbus.EventBus; import mightypork.gamecore.gui.screens.ScreenRegistry; @@ -24,6 +25,7 @@ import mightypork.rogue.events.GameStateRequest; import mightypork.rogue.screens.FpsOverlay; import mightypork.rogue.screens.LoadingOverlay; import mightypork.rogue.screens.game.ScreenGame; +import mightypork.rogue.screens.layout_testing.LayoutTestScreen; import mightypork.rogue.screens.menu.ScreenMainMenu; import mightypork.rogue.screens.select_world.ScreenSelectWorld; import mightypork.rogue.world.Inventory; @@ -121,6 +123,7 @@ public final class App extends BaseApp { screens.addScreen("main_menu", new ScreenMainMenu(this)); screens.addScreen("select_world", new ScreenSelectWorld(this)); screens.addScreen("game", new ScreenGame(this)); + screens.addScreen("test.layout", new LayoutTestScreen(this)); screens.addOverlay(new FpsOverlay(this)); screens.addOverlay(new LoadingOverlay(this)); @@ -168,11 +171,14 @@ public final class App extends BaseApp { @Override protected void postInit() { - // TODO tmp - //WorldProvider.get().createWorld(Double.doubleToLongBits(Math.random())); - - //getEventBus().send(new CrossfadeRequest("game", true)); - - getEventBus().send(new GameStateRequest(GameState.MAIN_MENU)); + getEventBus().send(new MainLoopRequest(new Runnable() { + + @Override + public void run() + { + getEventBus().send(new GameStateRequest(GameState.MAIN_MENU)); + //getEventBus().send(new CrossfadeRequest("test.layout", true)); + } + })); } } diff --git a/src/mightypork/rogue/Res.java b/src/mightypork/rogue/Res.java index 5e3c232..bc1d6ff 100644 --- a/src/mightypork/rogue/Res.java +++ b/src/mightypork/rogue/Res.java @@ -58,7 +58,7 @@ public final class Res { font.setDiscardRatio(3 / 16D, 2 / 16D); fonts.loadFont("tinyutf", font = new DeferredFont("/res/font/TinyUnicode2.ttf", Glyphs.basic, 16)); - font.setDiscardRatio(6 / 16D, 2 / 16D); + font.setDiscardRatio(5 / 16D, 3 / 16D); // aliases fonts.addAlias("thick", "press_start"); diff --git a/src/mightypork/rogue/screens/game/AskSaveLayer.java b/src/mightypork/rogue/screens/game/AskSaveLayer.java index c74c12a..77b234e 100644 --- a/src/mightypork/rogue/screens/game/AskSaveLayer.java +++ b/src/mightypork/rogue/screens/game/AskSaveLayer.java @@ -5,8 +5,9 @@ import java.io.IOException; import mightypork.gamecore.gui.Action; import mightypork.gamecore.gui.AlignX; -import mightypork.gamecore.gui.components.layout.ColumnLayout; +import mightypork.gamecore.gui.components.input.TextButton; import mightypork.gamecore.gui.components.layout.RowLayout; +import mightypork.gamecore.gui.components.layout.linear.LinearLayout; import mightypork.gamecore.gui.components.painters.QuadPainter; import mightypork.gamecore.gui.components.painters.TextPainter; import mightypork.gamecore.gui.screens.ScreenLayer; @@ -20,7 +21,6 @@ import mightypork.gamecore.util.math.constraints.num.Num; import mightypork.gamecore.util.math.constraints.num.mutable.NumAnimated; import mightypork.gamecore.util.math.timing.TimedTask; import mightypork.rogue.Res; -import mightypork.rogue.screens.PushButton; import mightypork.rogue.screens.game.ScreenGame.GScrState; import mightypork.rogue.world.WorldProvider; @@ -66,29 +66,29 @@ public class AskSaveLayer extends ScreenLayer { final TextPainter txp = new TextPainter(thick_font, AlignX.CENTER, RGB.WHITE, "Save the game?"); rl.add(txp, 1); - txp.setPaddingHPerc(0, 25); + txp.setVPaddingPercent(25); - final ColumnLayout cl = new ColumnLayout(root, 21); - cl.skip(2); - rl.add(cl); + final LinearLayout ll = new LinearLayout(root, AlignX.CENTER); + rl.add(ll); - final PushButton btn1 = new PushButton(thick_font, "Yes", ScreenGame.COLOR_BTN_GOOD); + final double vPadPerc = 20; + + final TextButton btn1 = new TextButton(thick_font, "Yes", ScreenGame.COLOR_BTN_GOOD); btn1.textPainter.setAlign(AlignX.RIGHT); - btn1.textPainter.setPaddingHPerc(25, 20); - btn1.disableHover(); - cl.add(btn1, 6); + btn1.textPainter.setVPaddingPercent(vPadPerc); + ll.add(btn1); + ll.gap(50); - final PushButton btn2 = new PushButton(thick_font, "No", ScreenGame.COLOR_BTN_BAD); + final TextButton btn2 = new TextButton(thick_font, "No", ScreenGame.COLOR_BTN_BAD); btn2.textPainter.setAlign(AlignX.CENTER); - btn2.textPainter.setPaddingHPerc(25, 20); - btn2.disableHover(); - cl.add(btn2, 3); + btn2.textPainter.setVPaddingPercent(vPadPerc); + ll.add(btn2); + ll.gap(50); - final PushButton btn3 = new PushButton(thick_font, "Cancel", ScreenGame.COLOR_BTN_CANCEL); + final TextButton btn3 = new TextButton(thick_font, "Cancel", ScreenGame.COLOR_BTN_CANCEL); btn3.textPainter.setAlign(AlignX.LEFT); - btn3.textPainter.setPaddingHPerc(25, 20); - btn3.disableHover(); - cl.add(btn3, 10); + btn3.textPainter.setVPaddingPercent(vPadPerc); + ll.add(btn3); final Action cancel = new Action() { diff --git a/src/mightypork/rogue/screens/game/DeathLayer.java b/src/mightypork/rogue/screens/game/DeathLayer.java index 11527a8..4af4149 100644 --- a/src/mightypork/rogue/screens/game/DeathLayer.java +++ b/src/mightypork/rogue/screens/game/DeathLayer.java @@ -5,8 +5,10 @@ import java.io.IOException; import mightypork.gamecore.gui.Action; import mightypork.gamecore.gui.AlignX; -import mightypork.gamecore.gui.components.layout.ColumnLayout; +import mightypork.gamecore.gui.components.input.TextButton; import mightypork.gamecore.gui.components.layout.RowLayout; +import mightypork.gamecore.gui.components.layout.linear.LinearGap; +import mightypork.gamecore.gui.components.layout.linear.LinearLayout; import mightypork.gamecore.gui.components.painters.ImagePainter; import mightypork.gamecore.gui.components.painters.QuadPainter; import mightypork.gamecore.gui.components.painters.TextPainter; @@ -18,7 +20,6 @@ import mightypork.gamecore.util.math.constraints.num.Num; import mightypork.rogue.GameStateManager.GameState; import mightypork.rogue.Res; import mightypork.rogue.events.GameStateRequest; -import mightypork.rogue.screens.PushButton; import mightypork.rogue.screens.game.ScreenGame.GScrState; import mightypork.rogue.world.WorldProvider; @@ -42,24 +43,27 @@ public class DeathLayer extends ScreenLayer { final TextPainter txp = new TextPainter(thick_font, AlignX.CENTER, RGB.YELLOW, "You're dead!"); rl.add(txp, 1); - txp.setPaddingHPerc(0, 15); + txp.setVPaddingPercent(15); - final ImagePainter img = new ImagePainter(Res.getTxQuad("death")); - img.keepAspectRatio(); - rl.add(img, 3); + LinearLayout linl = new LinearLayout(root, AlignX.CENTER); + linl.add(new ImagePainter(Res.getTxQuad("death"))); + rl.add(linl, 3); - final ColumnLayout cl = new ColumnLayout(root, 2); - rl.add(cl); + linl = new LinearLayout(root, AlignX.CENTER); + rl.add(linl); - final PushButton btn1 = new PushButton(thick_font, "Retry", ScreenGame.COLOR_BTN_GOOD); + + final TextButton btn1 = new TextButton(thick_font, "Retry", ScreenGame.COLOR_BTN_GOOD); btn1.textPainter.setAlign(AlignX.RIGHT); - btn1.textPainter.setPaddingHPerc(20, 25); - cl.add(btn1); + btn1.textPainter.setVPaddingPercent(25); + linl.add(btn1); + + linl.add(new LinearGap(50)); - final PushButton btn2 = new PushButton(thick_font, "Quit", ScreenGame.COLOR_BTN_BAD); + final TextButton btn2 = new TextButton(thick_font, "Quit", ScreenGame.COLOR_BTN_BAD); btn2.textPainter.setAlign(AlignX.LEFT); - btn2.textPainter.setPaddingHPerc(20, 25); - cl.add(btn2); + btn2.textPainter.setVPaddingPercent(25); + linl.add(btn2); btn1.setAction(new Action() { diff --git a/src/mightypork/rogue/screens/game/IngameNav.java b/src/mightypork/rogue/screens/game/IngameNav.java index d512344..02b6488 100644 --- a/src/mightypork/rogue/screens/game/IngameNav.java +++ b/src/mightypork/rogue/screens/game/IngameNav.java @@ -4,7 +4,7 @@ package mightypork.rogue.screens.game; import mightypork.gamecore.app.AppAccess; import mightypork.gamecore.gui.AlignX; import mightypork.gamecore.gui.components.LayoutComponent; -import mightypork.gamecore.gui.components.layout.HorizontalFixedFlowLayout; +import mightypork.gamecore.gui.components.layout.FlowColumnLayout; import mightypork.gamecore.render.Render; import mightypork.gamecore.resources.textures.TxQuad; import mightypork.gamecore.util.math.constraints.rect.Rect; @@ -14,8 +14,8 @@ import mightypork.rogue.Res; public class IngameNav extends LayoutComponent { - private final HorizontalFixedFlowLayout leftFlow; - private final HorizontalFixedFlowLayout rightFlow; + private final FlowColumnLayout leftFlow; + private final FlowColumnLayout rightFlow; private final Rect paintHelper; private final TxQuad bg; @@ -32,8 +32,8 @@ public class IngameNav extends LayoutComponent { super(app, context); final Rect shr = this.shrink(height().perc(5)); - leftFlow = new HorizontalFixedFlowLayout(app, context, shr.height(), AlignX.LEFT); - rightFlow = new HorizontalFixedFlowLayout(app, context, shr.height(), AlignX.RIGHT); + leftFlow = new FlowColumnLayout(app, context, shr.height(), AlignX.LEFT); + rightFlow = new FlowColumnLayout(app, context, shr.height(), AlignX.RIGHT); leftFlow.setRect(shr); diff --git a/src/mightypork/rogue/screens/game/InvSlot.java b/src/mightypork/rogue/screens/game/InvSlot.java index 1002a94..7006fb9 100644 --- a/src/mightypork/rogue/screens/game/InvSlot.java +++ b/src/mightypork/rogue/screens/game/InvSlot.java @@ -3,7 +3,7 @@ package mightypork.rogue.screens.game; import mightypork.gamecore.gui.Action; import mightypork.gamecore.gui.AlignX; -import mightypork.gamecore.gui.components.ClickableComponent; +import mightypork.gamecore.gui.components.input.ClickableComponent; import mightypork.gamecore.gui.components.painters.TextPainter; import mightypork.gamecore.render.Render; import mightypork.gamecore.resources.textures.TxQuad; diff --git a/src/mightypork/rogue/screens/game/InventoryLayer.java b/src/mightypork/rogue/screens/game/InventoryLayer.java index 72b17ee..6198976 100644 --- a/src/mightypork/rogue/screens/game/InventoryLayer.java +++ b/src/mightypork/rogue/screens/game/InventoryLayer.java @@ -3,8 +3,8 @@ package mightypork.rogue.screens.game; import mightypork.gamecore.gui.AlignX; import mightypork.gamecore.gui.components.layout.ConstraintLayout; +import mightypork.gamecore.gui.components.layout.FlowColumnLayout; import mightypork.gamecore.gui.components.layout.GridLayout; -import mightypork.gamecore.gui.components.layout.HorizontalFixedFlowLayout; import mightypork.gamecore.gui.components.painters.QuadPainter; import mightypork.gamecore.gui.components.painters.TextPainter; import mightypork.gamecore.gui.screens.ScreenLayer; @@ -105,10 +105,10 @@ public class InventoryLayer extends ScreenLayer { final TextPainter txp = new TextPainter(Res.getFont("thick"), AlignX.CENTER, RGB.YELLOW, "Inventory"); gl.put(txp, pos, 0, 1, 1); - txp.setPaddingHPerc(0, 5); + txp.setVPaddingPercent(5); pos += 1; - final HorizontalFixedFlowLayout row1 = new HorizontalFixedFlowLayout(root, null, AlignX.LEFT); + final FlowColumnLayout row1 = new FlowColumnLayout(root, null, AlignX.LEFT); row1.setElementWidth(row1.height()); final ConstraintLayout cl1 = new ConstraintLayout(root); row1.setRect(cl1.axisV().grow(cl1.height().mul(2), Num.ZERO)); @@ -122,7 +122,7 @@ public class InventoryLayer extends ScreenLayer { row1.add(slots[2] = new InvSlot(2, slots)); row1.add(slots[3] = new InvSlot(3, slots)); - final HorizontalFixedFlowLayout row2 = new HorizontalFixedFlowLayout(root, null, AlignX.LEFT); + final FlowColumnLayout row2 = new FlowColumnLayout(root, null, AlignX.LEFT); row2.setElementWidth(row2.height()); final ConstraintLayout cl2 = new ConstraintLayout(root); row2.setRect(cl2.axisV().grow(cl2.height().mul(2), Num.ZERO)); @@ -137,7 +137,7 @@ public class InventoryLayer extends ScreenLayer { final TextPainter txp2 = new TextPainter(Res.getFont("thick"), AlignX.CENTER, RGB.WHITE, contextStrProv); gl.put(txp2, pos, 0, 1, 1); - txp2.setPaddingHPerc(0, 25); + txp2.setVPaddingPercent(25); bindKey(new KeyStroke(Keys.ESCAPE), new Runnable() { diff --git a/src/mightypork/rogue/screens/game/NavButton.java b/src/mightypork/rogue/screens/game/NavButton.java index cd14946..8645c57 100644 --- a/src/mightypork/rogue/screens/game/NavButton.java +++ b/src/mightypork/rogue/screens/game/NavButton.java @@ -1,7 +1,7 @@ package mightypork.rogue.screens.game; -import mightypork.gamecore.gui.components.ClickableComponent; +import mightypork.gamecore.gui.components.input.ClickableComponent; import mightypork.gamecore.render.Render; import mightypork.gamecore.resources.textures.TxQuad; import mightypork.rogue.Res; diff --git a/src/mightypork/rogue/screens/layout_testing/LayoutTestScreen.java b/src/mightypork/rogue/screens/layout_testing/LayoutTestScreen.java new file mode 100644 index 0000000..69dc311 --- /dev/null +++ b/src/mightypork/rogue/screens/layout_testing/LayoutTestScreen.java @@ -0,0 +1,59 @@ +package mightypork.rogue.screens.layout_testing; + + +import mightypork.gamecore.app.AppAccess; +import mightypork.gamecore.gui.AlignX; +import mightypork.gamecore.gui.components.layout.linear.LinearGap; +import mightypork.gamecore.gui.components.layout.linear.LinearLayout; +import mightypork.gamecore.gui.components.layout.linear.LinearSquare; +import mightypork.gamecore.gui.components.painters.QuadPainter; +import mightypork.gamecore.gui.components.painters.TextPainter; +import mightypork.gamecore.gui.screens.LayeredScreen; +import mightypork.gamecore.gui.screens.Screen; +import mightypork.gamecore.gui.screens.ScreenLayer; +import mightypork.gamecore.util.math.color.pal.RGB; +import mightypork.gamecore.util.math.constraints.rect.Rect; +import mightypork.rogue.Res; + + +public class LayoutTestScreen extends LayeredScreen { + + class Layer1 extends ScreenLayer { + + public Layer1(Screen screen) + { + super(screen); + + final Rect testRect = root.shrink(root.width().perc(10), root.height().perc(45)); + + final LinearLayout ll = new LinearLayout(root, AlignX.CENTER); + ll.setRect(testRect); + root.add(ll); + + ll.add(new LinearSquare(new QuadPainter(RGB.RED))); + ll.add(new LinearGap(50)); + ll.add(new LinearSquare(new QuadPainter(RGB.ORANGE))); + ll.add(new LinearGap(100)); + ll.add(new LinearSquare(new QuadPainter(RGB.YELLOW))); + ll.add(new TextPainter(Res.getFont("tiny"), RGB.WHITE, "Text qjf'\"^")); + ll.add(new LinearSquare(new QuadPainter(RGB.GREEN))); + } + + + @Override + public int getZIndex() + { + return 10; + } + + } + + + public LayoutTestScreen(AppAccess app) + { + super(app); + + addLayer(new Layer1(this)); + } + +} diff --git a/src/mightypork/rogue/screens/menu/ScreenMainMenu.java b/src/mightypork/rogue/screens/menu/ScreenMainMenu.java index 0cd40c6..3f1c5c2 100644 --- a/src/mightypork/rogue/screens/menu/ScreenMainMenu.java +++ b/src/mightypork/rogue/screens/menu/ScreenMainMenu.java @@ -3,7 +3,10 @@ package mightypork.rogue.screens.menu; import mightypork.gamecore.app.AppAccess; import mightypork.gamecore.gui.Action; +import mightypork.gamecore.gui.AlignX; +import mightypork.gamecore.gui.components.input.TextButton; import mightypork.gamecore.gui.components.layout.RowLayout; +import mightypork.gamecore.gui.components.layout.linear.LinearLayout; import mightypork.gamecore.gui.components.painters.ImagePainter; import mightypork.gamecore.gui.components.painters.QuadPainter; import mightypork.gamecore.gui.screens.LayeredScreen; @@ -19,7 +22,6 @@ import mightypork.gamecore.util.math.constraints.rect.Rect; import mightypork.rogue.GameStateManager.GameState; import mightypork.rogue.Res; import mightypork.rogue.events.GameStateRequest; -import mightypork.rogue.screens.PushButton; /** @@ -65,17 +67,17 @@ public class ScreenMainMenu extends LayeredScreen { rows.enableCaching(true); root.add(rows); - final ImagePainter ip = new ImagePainter(Res.getTxQuad("logo")); - ip.keepAspectRatio(); - rows.add(ip, 4); + final LinearLayout linlayout = new LinearLayout(root, AlignX.CENTER); + linlayout.add(new ImagePainter(Res.getTxQuad("logo"))); + rows.add(linlayout, 4); rows.skip(1); - PushButton btn; + TextButton btn; final GLFont btnFont = Res.getFont("thick"); // world button - btn = new PushButton(btnFont, "Play", PAL16.SLIMEGREEN); + btn = new TextButton(btnFont, "Play", PAL16.SLIMEGREEN); btn.setAction(new Action() { @Override @@ -103,7 +105,7 @@ public class ScreenMainMenu extends LayeredScreen { */ // quit button - btn = new PushButton(btnFont, "Exit", PAL16.BLOODRED); + btn = new TextButton(btnFont, "Exit", PAL16.BLOODRED); btn.setAction(new Action() { @Override diff --git a/src/mightypork/rogue/screens/select_world/ScreenSelectWorld.java b/src/mightypork/rogue/screens/select_world/ScreenSelectWorld.java index 4b4b223..c06dc09 100644 --- a/src/mightypork/rogue/screens/select_world/ScreenSelectWorld.java +++ b/src/mightypork/rogue/screens/select_world/ScreenSelectWorld.java @@ -68,7 +68,7 @@ public class ScreenSelectWorld extends LayeredScreen { TextPainter tp; rows.add(tp = new TextPainter(Res.getFont("thick"), AlignX.CENTER, RGB.YELLOW, "Save slot:")); - tp.setPaddingHPerc(0, 20); + tp.setVPaddingPercent(20); tp.setShadow(RGB.BLACK_50, tp.height().mul(0.6 / 8D).toVectXY()); slot1 = new WorldSlot(root, Paths.SAVE_SLOT_1); diff --git a/src/mightypork/rogue/screens/select_world/WorldSlot.java b/src/mightypork/rogue/screens/select_world/WorldSlot.java index 9d62ad2..82837e8 100644 --- a/src/mightypork/rogue/screens/select_world/WorldSlot.java +++ b/src/mightypork/rogue/screens/select_world/WorldSlot.java @@ -7,6 +7,7 @@ import java.io.IOException; import mightypork.gamecore.app.AppAccess; import mightypork.gamecore.gui.Action; import mightypork.gamecore.gui.AlignX; +import mightypork.gamecore.gui.components.input.TextButton; import mightypork.gamecore.gui.components.layout.ConstraintLayout; import mightypork.gamecore.gui.components.layout.GridLayout; import mightypork.gamecore.gui.components.painters.QuadPainter; @@ -21,7 +22,6 @@ import mightypork.gamecore.util.math.constraints.rect.Rect; import mightypork.gamecore.util.strings.StringProvider; import mightypork.rogue.Res; import mightypork.rogue.events.LoadingOverlayRequest; -import mightypork.rogue.screens.PushButton; import mightypork.rogue.world.World; import mightypork.rogue.world.WorldProvider; @@ -42,9 +42,9 @@ public class WorldSlot extends ConstraintLayout { private IonBundle worldBundle; - private PushButton loadBtn; + private TextButton loadBtn; - private PushButton delBtn; + private TextButton delBtn; public WorldSlot(AppAccess app, File worldFile) @@ -75,11 +75,11 @@ public class WorldSlot extends ConstraintLayout { final GLFont font = Res.getFont("thick"); - gridl.put(loadBtn = new PushButton(font, "", RGB.WHITE), 0, 0, 1, 7); - loadBtn.textPainter.setPaddingHPerc(0, 20); + gridl.put(loadBtn = new TextButton(font, "", RGB.WHITE), 0, 0, 1, 7); + loadBtn.textPainter.setVPaddingPercent(20); loadBtn.textPainter.setAlign(AlignX.LEFT); loadBtn.textPainter.setText(lblStrp); - loadBtn.disableHover(); + loadBtn.disableHoverEffect(); loadBtn.setAction(new Action() { @@ -136,10 +136,10 @@ public class WorldSlot extends ConstraintLayout { } }); - gridl.put(delBtn = new PushButton(font, "X", RGB.RED), 0, 7, 1, 1); - delBtn.textPainter.setPaddingHPerc(0, 20); + gridl.put(delBtn = new TextButton(font, "X", RGB.RED), 0, 7, 1, 1); + delBtn.textPainter.setVPaddingPercent(20); delBtn.textPainter.setAlign(AlignX.RIGHT); - delBtn.disableHover(); + delBtn.disableHoverEffect(); delBtn.setAction(new Action() {