Linear Layout for text/image alignment on row

v5stable
Ondřej Hruška 11 years ago
parent 2699d8d549
commit 2a349f471f
  1. 7
      src/mightypork/gamecore/gui/components/DynamicWidthComponent.java
  2. 78
      src/mightypork/gamecore/gui/components/LinearComponent.java
  3. 3
      src/mightypork/gamecore/gui/components/input/ClickableComponent.java
  4. 3
      src/mightypork/gamecore/gui/components/input/ClickableWrapper.java
  5. 19
      src/mightypork/gamecore/gui/components/input/TextButton.java
  6. 6
      src/mightypork/gamecore/gui/components/layout/FlowColumnLayout.java
  7. 6
      src/mightypork/gamecore/gui/components/layout/FlowRowLayout.java
  8. 63
      src/mightypork/gamecore/gui/components/layout/linear/AbstractLinearWrapper.java
  9. 20
      src/mightypork/gamecore/gui/components/layout/linear/LinearGap.java
  10. 90
      src/mightypork/gamecore/gui/components/layout/linear/LinearLayout.java
  11. 32
      src/mightypork/gamecore/gui/components/layout/linear/LinearRectangle.java
  12. 21
      src/mightypork/gamecore/gui/components/layout/linear/LinearSquare.java
  13. 21
      src/mightypork/gamecore/gui/components/layout/linear/LinearWrapper.java
  14. 18
      src/mightypork/gamecore/gui/components/painters/ImagePainter.java
  15. 60
      src/mightypork/gamecore/gui/components/painters/TextPainter.java
  16. 49
      src/mightypork/gamecore/util/math/constraints/num/NumSum.java
  17. 14
      src/mightypork/rogue/App.java
  18. 2
      src/mightypork/rogue/Res.java
  19. 36
      src/mightypork/rogue/screens/game/AskSaveLayer.java
  20. 32
      src/mightypork/rogue/screens/game/DeathLayer.java
  21. 10
      src/mightypork/rogue/screens/game/IngameNav.java
  22. 2
      src/mightypork/rogue/screens/game/InvSlot.java
  23. 10
      src/mightypork/rogue/screens/game/InventoryLayer.java
  24. 2
      src/mightypork/rogue/screens/game/NavButton.java
  25. 59
      src/mightypork/rogue/screens/layout_testing/LayoutTestScreen.java
  26. 16
      src/mightypork/rogue/screens/menu/ScreenMainMenu.java
  27. 2
      src/mightypork/rogue/screens/select_world/ScreenSelectWorld.java
  28. 18
      src/mightypork/rogue/screens/select_world/WorldSlot.java

@ -0,0 +1,7 @@
package mightypork.gamecore.gui.components;
public interface DynamicWidthComponent extends Component {
double computeWidth(double height);
}

@ -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;
}
}

@ -1,8 +1,9 @@
package mightypork.gamecore.gui.components; package mightypork.gamecore.gui.components.input;
import mightypork.gamecore.gui.Action; import mightypork.gamecore.gui.Action;
import mightypork.gamecore.gui.ActionTrigger; import mightypork.gamecore.gui.ActionTrigger;
import mightypork.gamecore.gui.components.InputComponent;
import mightypork.gamecore.input.events.MouseButtonEvent; import mightypork.gamecore.input.events.MouseButtonEvent;
import mightypork.gamecore.input.events.MouseButtonListener; import mightypork.gamecore.input.events.MouseButtonListener;

@ -1,4 +1,4 @@
package mightypork.gamecore.gui.components.layout; package mightypork.gamecore.gui.components.input;
import java.util.ArrayList; import java.util.ArrayList;
@ -6,7 +6,6 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import mightypork.gamecore.eventbus.clients.DelegatingClient; import mightypork.gamecore.eventbus.clients.DelegatingClient;
import mightypork.gamecore.gui.components.ClickableComponent;
import mightypork.gamecore.gui.components.Component; import mightypork.gamecore.gui.components.Component;

@ -1,8 +1,8 @@
package mightypork.rogue.screens; package mightypork.gamecore.gui.components.input;
import mightypork.gamecore.gui.AlignX; 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.gui.components.painters.TextPainter;
import mightypork.gamecore.input.InputSystem; import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.resources.fonts.GLFont; import mightypork.gamecore.resources.fonts.GLFont;
@ -17,7 +17,7 @@ import mightypork.gamecore.util.math.constraints.vect.mutable.VectVar;
* *
* @author MightyPork * @author MightyPork
*/ */
public class PushButton extends ClickableComponent { public class TextButton extends ClickableComponent implements DynamicWidthComponent {
public final TextPainter textPainter; public final TextPainter textPainter;
@ -32,14 +32,14 @@ public class PushButton extends ClickableComponent {
private boolean hoverMove = true; private boolean hoverMove = true;
public PushButton(GLFont font, String text, Color color) public TextButton(GLFont font, String text, Color color)
{ {
this.color = color; this.color = color;
this.textPainter = new TextPainter(font, AlignX.CENTER, this.color, text); this.textPainter = new TextPainter(font, AlignX.CENTER, this.color, text);
this.textPainter.setRect(this); this.textPainter.setRect(this);
this.textPainter.setShadow(RGB.BLACK_30, offset); 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 * Disable offset change on hover
*/ */
public void disableHover() public void disableHoverEffect()
{ {
hoverMove = false; hoverMove = false;
} }
@Override
public double computeWidth(double height)
{
return textPainter.computeWidth(height);
}
} }

@ -15,7 +15,7 @@ import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound;
* *
* @author MightyPork * @author MightyPork
*/ */
public class HorizontalFixedFlowLayout extends LayoutComponent { public class FlowColumnLayout extends LayoutComponent {
private int col = 0; private int col = 0;
private Num elementWidth; private Num elementWidth;
@ -28,7 +28,7 @@ public class HorizontalFixedFlowLayout extends LayoutComponent {
* @param elementWidth width of all elements * @param elementWidth width of all elements
* @param align component align. Legal values are LEFT and RIGHT. * @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); super(app, context);
this.elementWidth = elementWidth; this.elementWidth = elementWidth;
@ -48,7 +48,7 @@ public class HorizontalFixedFlowLayout extends LayoutComponent {
* @param elementWidth width of all elements * @param elementWidth width of all elements
* @param align component align. Legal values are LEFT and RIGHT. * @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); this(app, null, elementWidth, align);
} }

@ -15,7 +15,7 @@ import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound;
* *
* @author MightyPork * @author MightyPork
*/ */
public class VerticalFixedFlowLayout extends LayoutComponent { public class FlowRowLayout extends LayoutComponent {
private int row = 0; private int row = 0;
private Num elementHeight; private Num elementHeight;
@ -28,7 +28,7 @@ public class VerticalFixedFlowLayout extends LayoutComponent {
* @param elementHeight height of all elements * @param elementHeight height of all elements
* @param align component align. Legal values are TOP and BOTTOM. * @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); super(app, context);
this.elementHeight = elementHeight; this.elementHeight = elementHeight;
@ -48,7 +48,7 @@ public class VerticalFixedFlowLayout extends LayoutComponent {
* @param elementHeight height of all elements * @param elementHeight height of all elements
* @param align component align. Legal values are TOP and BOTTOM. * @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); this(app, null, elementHeight, align);
} }

@ -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<Component> 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;
}
}

@ -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));
}
}

@ -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));
}
}

@ -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();
}
}

@ -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;
}
}

@ -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);
}
}

@ -2,10 +2,9 @@ package mightypork.gamecore.gui.components.painters;
import mightypork.gamecore.gui.components.BaseComponent; import mightypork.gamecore.gui.components.BaseComponent;
import mightypork.gamecore.gui.components.DynamicWidthComponent;
import mightypork.gamecore.render.Render; import mightypork.gamecore.render.Render;
import mightypork.gamecore.resources.textures.TxQuad; 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 * @author MightyPork
*/ */
public class ImagePainter extends BaseComponent { public class ImagePainter extends BaseComponent implements DynamicWidthComponent {
private final TxQuad txQuad; 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) public ImagePainter(TxQuad txQuad)
{ {
this.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 @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();
} }
} }

@ -3,6 +3,7 @@ package mightypork.gamecore.gui.components.painters;
import mightypork.gamecore.gui.AlignX; import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.BaseComponent; import mightypork.gamecore.gui.components.BaseComponent;
import mightypork.gamecore.gui.components.DynamicWidthComponent;
import mightypork.gamecore.render.Render; import mightypork.gamecore.render.Render;
import mightypork.gamecore.resources.fonts.FontRenderer; import mightypork.gamecore.resources.fonts.FontRenderer;
import mightypork.gamecore.resources.fonts.GLFont; import mightypork.gamecore.resources.fonts.GLFont;
@ -17,13 +18,11 @@ import mightypork.rogue.Config;
/** /**
* Text painting component.<br> * Text painting component.
* Drawing values are obtained through getters, so overriding getters can be
* used to change parameters dynamically.
* *
* @author MightyPork * @author MightyPork
*/ */
public class TextPainter extends BaseComponent { public class TextPainter extends BaseComponent implements DynamicWidthComponent {
private final FontRenderer font; private final FontRenderer font;
private Color color; private Color color;
@ -32,7 +31,6 @@ public class TextPainter extends BaseComponent {
private boolean shadow; private boolean shadow;
private double yPaddingPerc = 0; private double yPaddingPerc = 0;
private double xPaddingPerc = 0;
private Color shadowColor = RGB.BLACK; private Color shadowColor = RGB.BLACK;
private Vect shadowOffset = Vect.make(2, 2); private Vect shadowOffset = Vect.make(2, 2);
@ -47,28 +45,30 @@ public class TextPainter extends BaseComponent {
} }
/** public TextPainter(GLFont font, Color color, String text)
* Constructor for fixed text {
* this(font, AlignX.LEFT, color, new StringWrapper(text));
* @param font font to use }
* @param align text align
* @param color default color
* @param text drawn 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) public TextPainter(GLFont font, AlignX align, Color color, String text)
{ {
this(font, align, color, new StringWrapper(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) public TextPainter(GLFont font, AlignX align, Color color, StringProvider text)
{ {
this.font = new FontRenderer(font); 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) public TextPainter(GLFont font, AlignX align, Color color)
{ {
this(font, align, color, (StringProvider) null); this(font, align, color, (StringProvider) null);
@ -96,10 +91,9 @@ public class TextPainter extends BaseComponent {
final String str = text.getString(); final String str = text.getString();
final Num shrX = height().perc(xPaddingPerc);
final Num shrY = height().perc(yPaddingPerc); final Num shrY = height().perc(yPaddingPerc);
final Rect rect = getRect().shrink(shrX, shrY); final Rect rect = getRect().shrink(Num.ZERO, shrY);
if (shadow) { if (shadow) {
font.draw(str, rect.round(), align, shadowColor); 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; yPaddingPerc = percY;
} }
@Override
public double computeWidth(double height)
{
return font.getWidth(this.text.getString(), height * ((100 - yPaddingPerc * 2) / 100D));
}
} }

@ -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<Num> 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));
}
}

@ -6,6 +6,7 @@ import java.util.Locale;
import mightypork.gamecore.app.BaseApp; import mightypork.gamecore.app.BaseApp;
import mightypork.gamecore.app.MainLoop; import mightypork.gamecore.app.MainLoop;
import mightypork.gamecore.app.MainLoopRequest;
import mightypork.gamecore.eventbus.BusEvent; import mightypork.gamecore.eventbus.BusEvent;
import mightypork.gamecore.eventbus.EventBus; import mightypork.gamecore.eventbus.EventBus;
import mightypork.gamecore.gui.screens.ScreenRegistry; import mightypork.gamecore.gui.screens.ScreenRegistry;
@ -24,6 +25,7 @@ import mightypork.rogue.events.GameStateRequest;
import mightypork.rogue.screens.FpsOverlay; import mightypork.rogue.screens.FpsOverlay;
import mightypork.rogue.screens.LoadingOverlay; import mightypork.rogue.screens.LoadingOverlay;
import mightypork.rogue.screens.game.ScreenGame; import mightypork.rogue.screens.game.ScreenGame;
import mightypork.rogue.screens.layout_testing.LayoutTestScreen;
import mightypork.rogue.screens.menu.ScreenMainMenu; import mightypork.rogue.screens.menu.ScreenMainMenu;
import mightypork.rogue.screens.select_world.ScreenSelectWorld; import mightypork.rogue.screens.select_world.ScreenSelectWorld;
import mightypork.rogue.world.Inventory; import mightypork.rogue.world.Inventory;
@ -121,6 +123,7 @@ public final class App extends BaseApp {
screens.addScreen("main_menu", new ScreenMainMenu(this)); screens.addScreen("main_menu", new ScreenMainMenu(this));
screens.addScreen("select_world", new ScreenSelectWorld(this)); screens.addScreen("select_world", new ScreenSelectWorld(this));
screens.addScreen("game", new ScreenGame(this)); screens.addScreen("game", new ScreenGame(this));
screens.addScreen("test.layout", new LayoutTestScreen(this));
screens.addOverlay(new FpsOverlay(this)); screens.addOverlay(new FpsOverlay(this));
screens.addOverlay(new LoadingOverlay(this)); screens.addOverlay(new LoadingOverlay(this));
@ -168,11 +171,14 @@ public final class App extends BaseApp {
@Override @Override
protected void postInit() protected void postInit()
{ {
// TODO tmp getEventBus().send(new MainLoopRequest(new Runnable() {
//WorldProvider.get().createWorld(Double.doubleToLongBits(Math.random()));
//getEventBus().send(new CrossfadeRequest("game", true));
@Override
public void run()
{
getEventBus().send(new GameStateRequest(GameState.MAIN_MENU)); getEventBus().send(new GameStateRequest(GameState.MAIN_MENU));
//getEventBus().send(new CrossfadeRequest("test.layout", true));
}
}));
} }
} }

@ -58,7 +58,7 @@ public final class Res {
font.setDiscardRatio(3 / 16D, 2 / 16D); font.setDiscardRatio(3 / 16D, 2 / 16D);
fonts.loadFont("tinyutf", font = new DeferredFont("/res/font/TinyUnicode2.ttf", Glyphs.basic, 16)); 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 // aliases
fonts.addAlias("thick", "press_start"); fonts.addAlias("thick", "press_start");

@ -5,8 +5,9 @@ import java.io.IOException;
import mightypork.gamecore.gui.Action; import mightypork.gamecore.gui.Action;
import mightypork.gamecore.gui.AlignX; 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.RowLayout;
import mightypork.gamecore.gui.components.layout.linear.LinearLayout;
import mightypork.gamecore.gui.components.painters.QuadPainter; import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.components.painters.TextPainter; import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.screens.ScreenLayer; 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.constraints.num.mutable.NumAnimated;
import mightypork.gamecore.util.math.timing.TimedTask; import mightypork.gamecore.util.math.timing.TimedTask;
import mightypork.rogue.Res; import mightypork.rogue.Res;
import mightypork.rogue.screens.PushButton;
import mightypork.rogue.screens.game.ScreenGame.GScrState; import mightypork.rogue.screens.game.ScreenGame.GScrState;
import mightypork.rogue.world.WorldProvider; 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?"); final TextPainter txp = new TextPainter(thick_font, AlignX.CENTER, RGB.WHITE, "Save the game?");
rl.add(txp, 1); rl.add(txp, 1);
txp.setPaddingHPerc(0, 25); txp.setVPaddingPercent(25);
final ColumnLayout cl = new ColumnLayout(root, 21); final LinearLayout ll = new LinearLayout(root, AlignX.CENTER);
cl.skip(2); rl.add(ll);
rl.add(cl);
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.setAlign(AlignX.RIGHT);
btn1.textPainter.setPaddingHPerc(25, 20); btn1.textPainter.setVPaddingPercent(vPadPerc);
btn1.disableHover(); ll.add(btn1);
cl.add(btn1, 6); 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.setAlign(AlignX.CENTER);
btn2.textPainter.setPaddingHPerc(25, 20); btn2.textPainter.setVPaddingPercent(vPadPerc);
btn2.disableHover(); ll.add(btn2);
cl.add(btn2, 3); 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.setAlign(AlignX.LEFT);
btn3.textPainter.setPaddingHPerc(25, 20); btn3.textPainter.setVPaddingPercent(vPadPerc);
btn3.disableHover(); ll.add(btn3);
cl.add(btn3, 10);
final Action cancel = new Action() { final Action cancel = new Action() {

@ -5,8 +5,10 @@ import java.io.IOException;
import mightypork.gamecore.gui.Action; import mightypork.gamecore.gui.Action;
import mightypork.gamecore.gui.AlignX; 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.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.ImagePainter;
import mightypork.gamecore.gui.components.painters.QuadPainter; import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.components.painters.TextPainter; 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.GameStateManager.GameState;
import mightypork.rogue.Res; import mightypork.rogue.Res;
import mightypork.rogue.events.GameStateRequest; import mightypork.rogue.events.GameStateRequest;
import mightypork.rogue.screens.PushButton;
import mightypork.rogue.screens.game.ScreenGame.GScrState; import mightypork.rogue.screens.game.ScreenGame.GScrState;
import mightypork.rogue.world.WorldProvider; 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!"); final TextPainter txp = new TextPainter(thick_font, AlignX.CENTER, RGB.YELLOW, "You're dead!");
rl.add(txp, 1); rl.add(txp, 1);
txp.setPaddingHPerc(0, 15); txp.setVPaddingPercent(15);
final ImagePainter img = new ImagePainter(Res.getTxQuad("death")); LinearLayout linl = new LinearLayout(root, AlignX.CENTER);
img.keepAspectRatio(); linl.add(new ImagePainter(Res.getTxQuad("death")));
rl.add(img, 3); rl.add(linl, 3);
final ColumnLayout cl = new ColumnLayout(root, 2); linl = new LinearLayout(root, AlignX.CENTER);
rl.add(cl); 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.setAlign(AlignX.RIGHT);
btn1.textPainter.setPaddingHPerc(20, 25); btn1.textPainter.setVPaddingPercent(25);
cl.add(btn1); 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.setAlign(AlignX.LEFT);
btn2.textPainter.setPaddingHPerc(20, 25); btn2.textPainter.setVPaddingPercent(25);
cl.add(btn2); linl.add(btn2);
btn1.setAction(new Action() { btn1.setAction(new Action() {

@ -4,7 +4,7 @@ package mightypork.rogue.screens.game;
import mightypork.gamecore.app.AppAccess; import mightypork.gamecore.app.AppAccess;
import mightypork.gamecore.gui.AlignX; import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.LayoutComponent; 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.render.Render;
import mightypork.gamecore.resources.textures.TxQuad; import mightypork.gamecore.resources.textures.TxQuad;
import mightypork.gamecore.util.math.constraints.rect.Rect; import mightypork.gamecore.util.math.constraints.rect.Rect;
@ -14,8 +14,8 @@ import mightypork.rogue.Res;
public class IngameNav extends LayoutComponent { public class IngameNav extends LayoutComponent {
private final HorizontalFixedFlowLayout leftFlow; private final FlowColumnLayout leftFlow;
private final HorizontalFixedFlowLayout rightFlow; private final FlowColumnLayout rightFlow;
private final Rect paintHelper; private final Rect paintHelper;
private final TxQuad bg; private final TxQuad bg;
@ -32,8 +32,8 @@ public class IngameNav extends LayoutComponent {
super(app, context); super(app, context);
final Rect shr = this.shrink(height().perc(5)); final Rect shr = this.shrink(height().perc(5));
leftFlow = new HorizontalFixedFlowLayout(app, context, shr.height(), AlignX.LEFT); leftFlow = new FlowColumnLayout(app, context, shr.height(), AlignX.LEFT);
rightFlow = new HorizontalFixedFlowLayout(app, context, shr.height(), AlignX.RIGHT); rightFlow = new FlowColumnLayout(app, context, shr.height(), AlignX.RIGHT);
leftFlow.setRect(shr); leftFlow.setRect(shr);

@ -3,7 +3,7 @@ package mightypork.rogue.screens.game;
import mightypork.gamecore.gui.Action; import mightypork.gamecore.gui.Action;
import mightypork.gamecore.gui.AlignX; 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.gui.components.painters.TextPainter;
import mightypork.gamecore.render.Render; import mightypork.gamecore.render.Render;
import mightypork.gamecore.resources.textures.TxQuad; import mightypork.gamecore.resources.textures.TxQuad;

@ -3,8 +3,8 @@ package mightypork.rogue.screens.game;
import mightypork.gamecore.gui.AlignX; import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.layout.ConstraintLayout; 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.GridLayout;
import mightypork.gamecore.gui.components.layout.HorizontalFixedFlowLayout;
import mightypork.gamecore.gui.components.painters.QuadPainter; import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.components.painters.TextPainter; import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.screens.ScreenLayer; 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"); final TextPainter txp = new TextPainter(Res.getFont("thick"), AlignX.CENTER, RGB.YELLOW, "Inventory");
gl.put(txp, pos, 0, 1, 1); gl.put(txp, pos, 0, 1, 1);
txp.setPaddingHPerc(0, 5); txp.setVPaddingPercent(5);
pos += 1; pos += 1;
final HorizontalFixedFlowLayout row1 = new HorizontalFixedFlowLayout(root, null, AlignX.LEFT); final FlowColumnLayout row1 = new FlowColumnLayout(root, null, AlignX.LEFT);
row1.setElementWidth(row1.height()); row1.setElementWidth(row1.height());
final ConstraintLayout cl1 = new ConstraintLayout(root); final ConstraintLayout cl1 = new ConstraintLayout(root);
row1.setRect(cl1.axisV().grow(cl1.height().mul(2), Num.ZERO)); 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[2] = new InvSlot(2, slots));
row1.add(slots[3] = new InvSlot(3, 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()); row2.setElementWidth(row2.height());
final ConstraintLayout cl2 = new ConstraintLayout(root); final ConstraintLayout cl2 = new ConstraintLayout(root);
row2.setRect(cl2.axisV().grow(cl2.height().mul(2), Num.ZERO)); 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); final TextPainter txp2 = new TextPainter(Res.getFont("thick"), AlignX.CENTER, RGB.WHITE, contextStrProv);
gl.put(txp2, pos, 0, 1, 1); gl.put(txp2, pos, 0, 1, 1);
txp2.setPaddingHPerc(0, 25); txp2.setVPaddingPercent(25);
bindKey(new KeyStroke(Keys.ESCAPE), new Runnable() { bindKey(new KeyStroke(Keys.ESCAPE), new Runnable() {

@ -1,7 +1,7 @@
package mightypork.rogue.screens.game; 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.render.Render;
import mightypork.gamecore.resources.textures.TxQuad; import mightypork.gamecore.resources.textures.TxQuad;
import mightypork.rogue.Res; import mightypork.rogue.Res;

@ -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));
}
}

@ -3,7 +3,10 @@ package mightypork.rogue.screens.menu;
import mightypork.gamecore.app.AppAccess; import mightypork.gamecore.app.AppAccess;
import mightypork.gamecore.gui.Action; 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.RowLayout;
import mightypork.gamecore.gui.components.layout.linear.LinearLayout;
import mightypork.gamecore.gui.components.painters.ImagePainter; import mightypork.gamecore.gui.components.painters.ImagePainter;
import mightypork.gamecore.gui.components.painters.QuadPainter; import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.screens.LayeredScreen; 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.GameStateManager.GameState;
import mightypork.rogue.Res; import mightypork.rogue.Res;
import mightypork.rogue.events.GameStateRequest; import mightypork.rogue.events.GameStateRequest;
import mightypork.rogue.screens.PushButton;
/** /**
@ -65,17 +67,17 @@ public class ScreenMainMenu extends LayeredScreen {
rows.enableCaching(true); rows.enableCaching(true);
root.add(rows); root.add(rows);
final ImagePainter ip = new ImagePainter(Res.getTxQuad("logo")); final LinearLayout linlayout = new LinearLayout(root, AlignX.CENTER);
ip.keepAspectRatio(); linlayout.add(new ImagePainter(Res.getTxQuad("logo")));
rows.add(ip, 4); rows.add(linlayout, 4);
rows.skip(1); rows.skip(1);
PushButton btn; TextButton btn;
final GLFont btnFont = Res.getFont("thick"); final GLFont btnFont = Res.getFont("thick");
// world button // world button
btn = new PushButton(btnFont, "Play", PAL16.SLIMEGREEN); btn = new TextButton(btnFont, "Play", PAL16.SLIMEGREEN);
btn.setAction(new Action() { btn.setAction(new Action() {
@Override @Override
@ -103,7 +105,7 @@ public class ScreenMainMenu extends LayeredScreen {
*/ */
// quit button // quit button
btn = new PushButton(btnFont, "Exit", PAL16.BLOODRED); btn = new TextButton(btnFont, "Exit", PAL16.BLOODRED);
btn.setAction(new Action() { btn.setAction(new Action() {
@Override @Override

@ -68,7 +68,7 @@ public class ScreenSelectWorld extends LayeredScreen {
TextPainter tp; TextPainter tp;
rows.add(tp = new TextPainter(Res.getFont("thick"), AlignX.CENTER, RGB.YELLOW, "Save slot:")); 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()); tp.setShadow(RGB.BLACK_50, tp.height().mul(0.6 / 8D).toVectXY());
slot1 = new WorldSlot(root, Paths.SAVE_SLOT_1); slot1 = new WorldSlot(root, Paths.SAVE_SLOT_1);

@ -7,6 +7,7 @@ import java.io.IOException;
import mightypork.gamecore.app.AppAccess; import mightypork.gamecore.app.AppAccess;
import mightypork.gamecore.gui.Action; import mightypork.gamecore.gui.Action;
import mightypork.gamecore.gui.AlignX; 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.ConstraintLayout;
import mightypork.gamecore.gui.components.layout.GridLayout; import mightypork.gamecore.gui.components.layout.GridLayout;
import mightypork.gamecore.gui.components.painters.QuadPainter; 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.gamecore.util.strings.StringProvider;
import mightypork.rogue.Res; import mightypork.rogue.Res;
import mightypork.rogue.events.LoadingOverlayRequest; import mightypork.rogue.events.LoadingOverlayRequest;
import mightypork.rogue.screens.PushButton;
import mightypork.rogue.world.World; import mightypork.rogue.world.World;
import mightypork.rogue.world.WorldProvider; import mightypork.rogue.world.WorldProvider;
@ -42,9 +42,9 @@ public class WorldSlot extends ConstraintLayout {
private IonBundle worldBundle; private IonBundle worldBundle;
private PushButton loadBtn; private TextButton loadBtn;
private PushButton delBtn; private TextButton delBtn;
public WorldSlot(AppAccess app, File worldFile) public WorldSlot(AppAccess app, File worldFile)
@ -75,11 +75,11 @@ public class WorldSlot extends ConstraintLayout {
final GLFont font = Res.getFont("thick"); final GLFont font = Res.getFont("thick");
gridl.put(loadBtn = new PushButton(font, "", RGB.WHITE), 0, 0, 1, 7); gridl.put(loadBtn = new TextButton(font, "", RGB.WHITE), 0, 0, 1, 7);
loadBtn.textPainter.setPaddingHPerc(0, 20); loadBtn.textPainter.setVPaddingPercent(20);
loadBtn.textPainter.setAlign(AlignX.LEFT); loadBtn.textPainter.setAlign(AlignX.LEFT);
loadBtn.textPainter.setText(lblStrp); loadBtn.textPainter.setText(lblStrp);
loadBtn.disableHover(); loadBtn.disableHoverEffect();
loadBtn.setAction(new Action() { 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); gridl.put(delBtn = new TextButton(font, "X", RGB.RED), 0, 7, 1, 1);
delBtn.textPainter.setPaddingHPerc(0, 20); delBtn.textPainter.setVPaddingPercent(20);
delBtn.textPainter.setAlign(AlignX.RIGHT); delBtn.textPainter.setAlign(AlignX.RIGHT);
delBtn.disableHover(); delBtn.disableHoverEffect();
delBtn.setAction(new Action() { delBtn.setAction(new Action() {

Loading…
Cancel
Save