From 9cbddbfdadb4c8b062e3298ba91201b66f2a56fb Mon Sep 17 00:00:00 2001 From: Pixaurora Date: Fri, 29 Nov 2024 23:54:15 -0500 Subject: [PATCH] Update Textbox to align itself, and use that for PushableTextLines Signed-off-by: Rina Mary Shaw --- .../pixaurora/kitten_cube/impl/math/Size.java | 2 + .../impl/ui/display/AlignedGuiDisplay.java | 5 + .../impl/ui/display/GuiDisplay.java | 7 +- .../impl/ui/display/WrappedGuiDisplay.java | 6 +- .../impl/ui/screen/WidgetContainer.java | 4 + .../impl/ui/screen/align/Alignment.java | 21 +++- .../impl/ui/screen/align/WidgetAnchor.java | 4 +- .../ui/widget/text/PushableTextLines.java | 100 +++++++++--------- .../impl/ui/widget/text/TextBox.java | 4 + .../impl/ui/screen/music/MusicScreen.java | 20 ++-- .../setup/ScrobblerServerAuthScreen.java | 42 ++++---- .../kitten_heart/impl/ui/widget/Timer.java | 3 +- .../impl/ui/widget/progress/ProgressBar.java | 6 +- .../impl/ui/display/GuiDisplayImpl.java | 24 +++-- .../impl/ui/display/GuiDisplayImpl.java | 24 +++-- .../impl/ui/display/GuiDisplayImpl.java | 24 +++-- .../impl/ui/display/GuiDisplayImpl.java | 24 +++-- .../impl/ui/display/GuiDisplayImpl.java | 24 +++-- .../impl/ui/display/GuiDisplayImpl.java | 23 ++-- .../impl/ui/display/GuiDisplayImpl.java | 23 ++-- .../impl/ui/display/GuiDisplayImpl.java | 24 +++-- 21 files changed, 237 insertions(+), 177 deletions(-) diff --git a/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/math/Size.java b/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/math/Size.java index 20448e3..a0e88bc 100644 --- a/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/math/Size.java +++ b/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/math/Size.java @@ -1,6 +1,8 @@ package net.pixaurora.kitten_cube.impl.math; public interface Size extends Vec2Int { + public static Size ZERO = Size.of(0, 0); + public static Size of(int width, int height) { return new SizeImpl(width, height); } diff --git a/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/display/AlignedGuiDisplay.java b/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/display/AlignedGuiDisplay.java index 5cf323f..71be5fa 100644 --- a/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/display/AlignedGuiDisplay.java +++ b/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/display/AlignedGuiDisplay.java @@ -5,6 +5,7 @@ import net.pixaurora.kitten_cube.impl.text.Color; import net.pixaurora.kitten_cube.impl.text.Component; import net.pixaurora.kitten_cube.impl.ui.screen.align.Alignment; +import net.pixaurora.kitten_cube.impl.ui.widget.text.TextBox; public class AlignedGuiDisplay extends WrappedGuiDisplay { private final Alignment alignment; @@ -41,4 +42,8 @@ public void drawTexture(ResourcePath path, int width, int height, int x, int y) super.drawTexture(path, width, height, this.alignX(x, y), this.alignY(x, y)); } + @Override + public void drawTextBox(TextBox box) { + super.drawTextBox(box, this.alignment, this.window); + } } diff --git a/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/display/GuiDisplay.java b/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/display/GuiDisplay.java index 3995c2b..b57d8f8 100644 --- a/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/display/GuiDisplay.java +++ b/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/display/GuiDisplay.java @@ -5,6 +5,7 @@ import net.pixaurora.kitten_cube.impl.math.Size; import net.pixaurora.kitten_cube.impl.text.Color; import net.pixaurora.kitten_cube.impl.text.Component; +import net.pixaurora.kitten_cube.impl.ui.screen.align.Alignment; import net.pixaurora.kitten_cube.impl.ui.texture.GuiTexture; import net.pixaurora.kitten_cube.impl.ui.texture.Texture; import net.pixaurora.kitten_cube.impl.ui.widget.text.TextBox; @@ -17,7 +18,11 @@ public void drawGuiTextureSubsection(ResourcePath path, int width, int height, i public void drawText(Component text, Color color, int x, int y, boolean shadowed); - public void drawTextBox(TextBox box); + public void drawTextBox(TextBox box, Alignment alignment, Size window); + + public default void drawTextBox(TextBox box) { + this.drawTextBox(box, Alignment.TOP_LEFT, Size.ZERO); + } public default void drawTexture(ResourcePath path, Size size, Point pos) { this.drawTexture(path, size.width(), size.height(), pos.x(), pos.y()); diff --git a/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/display/WrappedGuiDisplay.java b/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/display/WrappedGuiDisplay.java index 91b6007..ea0745f 100644 --- a/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/display/WrappedGuiDisplay.java +++ b/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/display/WrappedGuiDisplay.java @@ -1,8 +1,10 @@ package net.pixaurora.kitten_cube.impl.ui.display; import net.pixaurora.kit_tunes.api.resource.ResourcePath; +import net.pixaurora.kitten_cube.impl.math.Size; import net.pixaurora.kitten_cube.impl.text.Color; import net.pixaurora.kitten_cube.impl.text.Component; +import net.pixaurora.kitten_cube.impl.ui.screen.align.Alignment; import net.pixaurora.kitten_cube.impl.ui.widget.text.TextBox; public class WrappedGuiDisplay implements GuiDisplay { @@ -34,7 +36,7 @@ public void drawText(Component text, Color color, int x, int y, boolean shadowed } @Override - public void drawTextBox(TextBox box) { - this.parent.drawTextBox(box); + public void drawTextBox(TextBox box, Alignment alignment, Size window) { + this.parent.drawTextBox(box, alignment, window); } } diff --git a/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/screen/WidgetContainer.java b/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/screen/WidgetContainer.java index ca8e459..7666fc9 100644 --- a/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/screen/WidgetContainer.java +++ b/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/screen/WidgetContainer.java @@ -51,6 +51,10 @@ public Point pos() { return this.pos; } + public Size size() { + return this.widget.size(); + } + private Optional customizedAlignment() { if (this.baseAlignment.isPresent()) { return this.baseAlignment; diff --git a/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/screen/align/Alignment.java b/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/screen/align/Alignment.java index 763dcf9..de24e20 100644 --- a/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/screen/align/Alignment.java +++ b/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/screen/align/Alignment.java @@ -17,10 +17,23 @@ public interface Alignment { public int inverseAlignY(int x, int y, Size window); - public default Point inverseAlign(Point pos, Size window) { - int x = pos.x(); - int y = pos.y(); + public default int alignX(Point pos, Size window) { + return this.alignX(pos.x(), pos.y(), window); + } - return Point.of(this.inverseAlignX(x, y, window), this.inverseAlignY(x, y, window)); + public default int alignY(Point pos, Size window) { + return this.alignY(pos.x(), pos.y(), window); + } + + public default int inverseAlignX(Point pos, Size window) { + return this.inverseAlignX(pos.x(), pos.y(), window); + } + + public default int inverseAlignY(Point pos, Size window) { + return this.inverseAlignY(pos.x(), pos.y(), window); + } + + public default Point inverseAlign(Point pos, Size window) { + return Point.of(this.inverseAlignX(pos, window), this.inverseAlignY(pos, window)); } } diff --git a/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/screen/align/WidgetAnchor.java b/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/screen/align/WidgetAnchor.java index c1dd908..7b50375 100644 --- a/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/screen/align/WidgetAnchor.java +++ b/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/screen/align/WidgetAnchor.java @@ -55,12 +55,12 @@ public int anchorY(Widget widget) { public static class MiddleLeft implements WidgetAnchor { @Override public int anchorX(Widget widget) { - return widget.size().width(); + return 0; } @Override public int anchorY(Widget widget) { - return 0; + return widget.size().height() / 2; } } diff --git a/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/widget/text/PushableTextLines.java b/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/widget/text/PushableTextLines.java index 55a7990..df07157 100644 --- a/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/widget/text/PushableTextLines.java +++ b/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/widget/text/PushableTextLines.java @@ -1,11 +1,9 @@ package net.pixaurora.kitten_cube.impl.ui.widget.text; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.Optional; -import net.pixaurora.kitten_cube.impl.MinecraftClient; import net.pixaurora.kitten_cube.impl.math.Point; import net.pixaurora.kitten_cube.impl.math.Size; import net.pixaurora.kitten_cube.impl.text.Color; @@ -15,12 +13,11 @@ import net.pixaurora.kitten_cube.impl.ui.texture.GuiTexture; import net.pixaurora.kitten_cube.impl.ui.tile.InnerTileGrid; import net.pixaurora.kitten_cube.impl.ui.tile.PositionedInnerTile; -import net.pixaurora.kitten_cube.impl.ui.widget.IncorporealWidget; +import net.pixaurora.kitten_cube.impl.ui.widget.Widget; import net.pixaurora.kitten_heart.impl.KitTunes; +import net.pixaurora.kitten_heart.impl.util.Pair; -public class PushableTextLines implements IncorporealWidget { - // TODO: render this from (0, 0) like everything else - +public class PushableTextLines implements Widget { private static final TextLinesBackground REGULAR_BACKGROUND = new TextLinesBackground(Point.of(7, 5), new InnerTileGrid( GuiTexture.of(KitTunes.resource("textures/gui/sprites/widget/textbox.png"), Size.of(20, 17)), @@ -28,48 +25,48 @@ public class PushableTextLines implements IncorporealWidget { Size.of(6, 2)); private final Optional backgroundType; + private final List lines; + private Color color; - private final List lines; - private final List backgroundTiles; + private ImmutableTextDisplay display; public PushableTextLines(Optional backgroundType) { this.backgroundType = backgroundType; this.lines = new ArrayList<>(); - this.backgroundTiles = new ArrayList<>(); + this.color = Color.WHITE; + this.resetDisplay(); } public static PushableTextLines regular() { return new PushableTextLines(Optional.of(REGULAR_BACKGROUND)); } - private int height() { - return this.lines.size() * MinecraftClient.textHeight(); - } - - public Point endPos() { - return Point.ZERO.offset(0, this.height()); - } - public void clear() { this.lines.clear(); } - public void push(Component text, Color color) { - Point newLinePos = MinecraftClient.textSize(text).centerHorizontally(Point.ZERO).offset(0, this.height()); - this.lines.add(new PositionedText(text, color, newLinePos)); + public void setColor(Color color) { + this.color = color; + } + + public void push(Component text) { + this.lines.add(text); - this.updateBackground(); + this.resetDisplay(); } @Override public void draw(GuiDisplay gui, Point mousePos) { - for (PositionedInnerTile tile : this.backgroundTiles) { + for (PositionedInnerTile tile : this.display.tiles) { tile.draw(gui); } - for (PositionedText line : this.lines) { - gui.drawText(line.text(), line.color(), line.pos()); - } + gui.drawTextBox(this.display.textBox); + } + + @Override + public Size size() { + return this.display.size; } @Override @@ -81,36 +78,43 @@ public boolean isWithinBounds(Point mousePos) { return false; } - private void updateBackground() { - this.backgroundTiles.clear(); + private void resetDisplay() { + Point textStart; + if (this.backgroundType.isPresent()) { + textStart = this.backgroundType.get().textStart(); + } else { + textStart = Point.ZERO; + } - TextLinesBackground background = this.backgroundType.get(); + TextBox textBox = TextBox.of(this.lines, color, textStart); + Size displaySize = textBox.size().offset(textStart); - InnerTileGrid grid = background.grid(); - Point startPos = this.topLeftLinePoint().offset(background.textStart().scaledBy(-1)); - Size totalSize = this.linesSize().offset(background.textStart()).offset(background.bottomRightPadding()); + List tiles; + if (this.backgroundType.isPresent()) { + TextLinesBackground background = this.backgroundType.get(); - this.backgroundTiles.addAll(grid.tilesAndSize(startPos, totalSize).first()); - } + Pair, Size> tilesAndSize = background + .grid() + .tilesAndSize(Point.ZERO, displaySize.offset(background.bottomRightPadding())); - private Size linesSize() { - return MinecraftClient - .textSize(this.lines.stream().map(PositionedText::text).toArray(size -> new Component[size])); - } - - private Point topLeftLinePoint() { - Iterator lines = this.lines.iterator(); + tiles = tilesAndSize.first(); + displaySize = tilesAndSize.second(); + } else { + tiles = new ArrayList<>(); + } - PositionedText line = lines.next(); - Point topLeftPoint = line.pos(); + this.display = new ImmutableTextDisplay(textBox, tiles, displaySize); + } - while (lines.hasNext()) { - line = lines.next(); + private static class ImmutableTextDisplay { + private final TextBox textBox; + private final List tiles; + private final Size size; - Point linePos = line.pos(); - topLeftPoint = Point.of(Math.min(topLeftPoint.x(), linePos.x()), Math.min(topLeftPoint.y(), linePos.y())); + ImmutableTextDisplay(TextBox textBox, List tiles, Size size) { + this.textBox = textBox; + this.tiles = tiles; + this.size = size; } - - return topLeftPoint; } } diff --git a/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/widget/text/TextBox.java b/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/widget/text/TextBox.java index a179152..3ced239 100644 --- a/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/widget/text/TextBox.java +++ b/projects/kitten-heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/widget/text/TextBox.java @@ -13,5 +13,9 @@ public static TextBox of(List lines, Color color, int maxLineLength, return KitTunes.UI_LAYER.createTextbox(lines, color, maxLineLength, pos); } + public static TextBox of(List lines, Color color, Point pos) { + return of(lines, color, 256, pos); + } + public Size size(); } diff --git a/projects/kitten-heart/src/main/java/net/pixaurora/kitten_heart/impl/ui/screen/music/MusicScreen.java b/projects/kitten-heart/src/main/java/net/pixaurora/kitten_heart/impl/ui/screen/music/MusicScreen.java index 9fc10b2..ab5e906 100644 --- a/projects/kitten-heart/src/main/java/net/pixaurora/kitten_heart/impl/ui/screen/music/MusicScreen.java +++ b/projects/kitten-heart/src/main/java/net/pixaurora/kitten_heart/impl/ui/screen/music/MusicScreen.java @@ -9,7 +9,6 @@ import net.pixaurora.kit_tunes.api.resource.ResourcePath; import net.pixaurora.kitten_cube.impl.math.Point; import net.pixaurora.kitten_cube.impl.math.Size; -import net.pixaurora.kitten_cube.impl.text.Color; import net.pixaurora.kitten_cube.impl.text.Component; import net.pixaurora.kitten_cube.impl.ui.screen.Screen; import net.pixaurora.kitten_cube.impl.ui.screen.WidgetContainer; @@ -104,8 +103,8 @@ public DisplayMode createMusicDisplay(PlayingSong song) { .anchor(WidgetAnchor.TOP_MIDDLE); WidgetContainer timer = this.addWidget(new Timer(song)) - .align(Alignment.CENTER_BOTTOM) - .at(Point.of(0, -13)); + .align(progressBar.relativeTo(WidgetAnchor.BOTTOM_MIDDLE)) + .anchor(WidgetAnchor.TOP_MIDDLE); Optional album = song.track().flatMap(Track::album); @@ -116,20 +115,23 @@ public DisplayMode createMusicDisplay(PlayingSong song) { WidgetContainer albumArt = this .addWidget( new StaticTexture(Texture.of(albumArtTexture, iconSize))) - .at(iconSize.centerOn(Point.of(-70, 0))); + .anchor(WidgetAnchor.MIDDLE_RIGHT) + .at(Point.of(-10, 0)); - WidgetContainer songInfo = this.addWidget(PushableTextLines.regular()).at(Point.of(70, -8)); + WidgetContainer songInfo = this.addWidget(PushableTextLines.regular()) + .anchor(WidgetAnchor.MIDDLE_LEFT) + .at(Point.of(10, 0)); if (song.track().isPresent()) { Track track = song.track().get(); - songInfo.get().push(asComponent(track), Color.WHITE); - songInfo.get().push(asComponent(track.artist()), Color.WHITE); + songInfo.get().push(asComponent(track)); + songInfo.get().push(asComponent(track.artist())); if (album.isPresent()) { - songInfo.get().push(asComponent(track.album().get()), Color.WHITE); + songInfo.get().push(asComponent(track.album().get())); } } else { - songInfo.get().push(Component.literal("No track found :("), Color.RED); + songInfo.get().push(Component.literal("No track found :(")); } WidgetContainer pauseButton = this diff --git a/projects/kitten-heart/src/main/java/net/pixaurora/kitten_heart/impl/ui/screen/scrobbler/setup/ScrobblerServerAuthScreen.java b/projects/kitten-heart/src/main/java/net/pixaurora/kitten_heart/impl/ui/screen/scrobbler/setup/ScrobblerServerAuthScreen.java index 86f117a..418697e 100644 --- a/projects/kitten-heart/src/main/java/net/pixaurora/kitten_heart/impl/ui/screen/scrobbler/setup/ScrobblerServerAuthScreen.java +++ b/projects/kitten-heart/src/main/java/net/pixaurora/kitten_heart/impl/ui/screen/scrobbler/setup/ScrobblerServerAuthScreen.java @@ -9,7 +9,9 @@ import net.pixaurora.kitten_cube.impl.text.Color; import net.pixaurora.kitten_cube.impl.text.Component; import net.pixaurora.kitten_cube.impl.ui.screen.Screen; +import net.pixaurora.kitten_cube.impl.ui.screen.WidgetContainer; import net.pixaurora.kitten_cube.impl.ui.screen.align.Alignment; +import net.pixaurora.kitten_cube.impl.ui.screen.align.WidgetAnchor; import net.pixaurora.kitten_cube.impl.ui.widget.button.Button; import net.pixaurora.kitten_cube.impl.ui.widget.button.RectangularButton; import net.pixaurora.kitten_cube.impl.ui.widget.text.PushableTextLines; @@ -50,44 +52,48 @@ private void setMessage(Component message) { PushableTextLines output = this.setupStatus.orElseThrow(RuntimeException::new); output.clear(); - output.push(message, Color.WHITE); + output.push(message); } private void sendError(KitTunesException exception) { PushableTextLines output = this.setupStatus.orElseThrow(RuntimeException::new); - output.push(exception.userMessage(), Color.RED); + output.setColor(Color.RED); + + output.push(exception.userMessage()); if (exception.isPrinted()) { KitTunes.LOGGER.error("Unhandled exception during scrobbler setup!", exception); - output.push(UNUSUAL_ERROR_ENCOUNTERED, Color.RED); + output.push(UNUSUAL_ERROR_ENCOUNTERED); } } @Override protected void firstInit() { - Point widgetPos = Point.of(0, 10); - PushableTextLines title = this.addWidget(PushableTextLines.regular()) - .at(widgetPos) - .get(); - title.push(TITLE, Color.WHITE); + Point widgetOffset = Point.of(0, 10); + + WidgetContainer title = this.addWidget(PushableTextLines.regular()) + .anchor(WidgetAnchor.TOP_MIDDLE) + .at(widgetOffset); + title.get().push(TITLE); String setupUrl = this.setup.url(); - widgetPos = title.endPos().offset(0, 10); - Button setupInBrowser = this + WidgetContainer setupInBrowser = this .addWidget( RectangularButton.vanillaButton(SETUP_IN_BROWSER, button -> MinecraftClient.openURL(setupUrl))) - .at(RectangularButton.DEFAULT_SIZE.centerHorizontally(widgetPos)) - .get(); - this.setupInBrowser = Optional.of(setupInBrowser); + .align(title.relativeTo(WidgetAnchor.BOTTOM_MIDDLE)) + .anchor(WidgetAnchor.TOP_MIDDLE) + .at(widgetOffset); + this.setupInBrowser = Optional.of(setupInBrowser.get()); MinecraftClient.openURL(setupUrl); - widgetPos = widgetPos.offset(0, RectangularButton.DEFAULT_SIZE.y() + 10); - this.setupStatus = Optional.of( - this.addWidget(PushableTextLines.regular()) - .at(widgetPos) - .get()); + WidgetContainer setupStatus = this.addWidget(PushableTextLines.regular()) + .align(setupInBrowser.relativeTo(WidgetAnchor.BOTTOM_MIDDLE)) + .anchor(WidgetAnchor.TOP_MIDDLE) + .at(widgetOffset); + + this.setupStatus = Optional.of(setupStatus.get()); try { this.awaitedScrobbler = Optional.of(this.setup.run()); diff --git a/projects/kitten-heart/src/main/java/net/pixaurora/kitten_heart/impl/ui/widget/Timer.java b/projects/kitten-heart/src/main/java/net/pixaurora/kitten_heart/impl/ui/widget/Timer.java index afab34c..d212d0d 100644 --- a/projects/kitten-heart/src/main/java/net/pixaurora/kitten_heart/impl/ui/widget/Timer.java +++ b/projects/kitten-heart/src/main/java/net/pixaurora/kitten_heart/impl/ui/widget/Timer.java @@ -1,7 +1,6 @@ package net.pixaurora.kitten_heart.impl.ui.widget; import net.pixaurora.kitten_cube.impl.math.Point; -import net.pixaurora.kitten_cube.impl.text.Color; import net.pixaurora.kitten_cube.impl.text.Component; import net.pixaurora.kitten_cube.impl.ui.controls.MouseButton; import net.pixaurora.kitten_cube.impl.ui.display.GuiDisplay; @@ -36,7 +35,7 @@ public void tick() { this.playedSeconds = newPlayedSeconds; this.text.clear(); - this.text.push(Component.literal(this.display()), Color.WHITE); + this.text.push(Component.literal(this.display())); } } diff --git a/projects/kitten-heart/src/main/java/net/pixaurora/kitten_heart/impl/ui/widget/progress/ProgressBar.java b/projects/kitten-heart/src/main/java/net/pixaurora/kitten_heart/impl/ui/widget/progress/ProgressBar.java index f9e3761..34a08c2 100644 --- a/projects/kitten-heart/src/main/java/net/pixaurora/kitten_heart/impl/ui/widget/progress/ProgressBar.java +++ b/projects/kitten-heart/src/main/java/net/pixaurora/kitten_heart/impl/ui/widget/progress/ProgressBar.java @@ -98,11 +98,11 @@ private void createTiles(int progressWidth, int barWidth) { private void createTiles0(int progressWidth, int barWidth, ProgressBarTileSet tileSet, TilePlacementMethod tileMethod) { - int middleTileCount = (barWidth - (tileSet.left().size().width() + tileSet.right().size().width())) - / tileSet.middle().size().width(); + int middleTileCount = (barWidth - (tileSet.left().width() + tileSet.right().width())) + / tileSet.middle().width(); this.size = Size.of( - tileSet.left().height() + middleTileCount * tileSet.middle().height() + tileSet.right().width(), + tileSet.left().width() + middleTileCount * tileSet.middle().width() + tileSet.right().width(), tileSet.left().height()); Point placement = Point.ZERO; diff --git a/projects/kitten-square/r1.17.0/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java b/projects/kitten-square/r1.17.0/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java index 0ff707d..f1fd8ad 100644 --- a/projects/kitten-square/r1.17.0/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java +++ b/projects/kitten-square/r1.17.0/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java @@ -7,9 +7,11 @@ import net.minecraft.util.FormattedCharSequence; import net.pixaurora.kit_tunes.api.resource.ResourcePath; import net.pixaurora.kitten_cube.impl.MinecraftClient; +import net.pixaurora.kitten_cube.impl.math.Size; import net.pixaurora.kitten_cube.impl.text.Color; import net.pixaurora.kitten_cube.impl.text.Component; import net.pixaurora.kitten_cube.impl.ui.display.GuiDisplay; +import net.pixaurora.kitten_cube.impl.ui.screen.align.Alignment; import net.pixaurora.kitten_cube.impl.ui.widget.text.TextBox; import net.pixaurora.kitten_square.impl.ui.ConversionCacheImpl; import net.pixaurora.kitten_square.impl.ui.widget.TextBoxImpl; @@ -44,20 +46,20 @@ public void drawText(Component text, Color color, int x, int y, boolean shadowed @SuppressWarnings("resource") @Override - public void drawTextBox(TextBox textBox) { - if (textBox instanceof TextBoxImpl) { - TextBoxImpl impl = (TextBoxImpl) textBox; + public void drawTextBox(TextBox textBox, Alignment alignment, Size window) { + if (!(textBox instanceof TextBoxImpl)) { + throw new UnsupportedOperationException("Unsupported instance of textbox"); + } - int y = impl.startPos.y(); + TextBoxImpl impl = (TextBoxImpl) textBox; - for (FormattedCharSequence line : impl.lines) { - GuiComponent.drawString(poseStack, Minecraft.getInstance().font, line, impl.startPos.x(), y, - impl.color.hex()); + int x = alignment.alignX(impl.startPos, window); + int y = alignment.alignY(impl.startPos, window); - y += MinecraftClient.textHeight(); - } - } else { - throw new UnsupportedOperationException("Unsupported instance of textbox"); + for (FormattedCharSequence line : impl.lines) { + GuiComponent.drawString(poseStack, Minecraft.getInstance().font, line, x, y, impl.color.hex()); + + y += MinecraftClient.textHeight(); } } } diff --git a/projects/kitten-square/r1.19.0/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java b/projects/kitten-square/r1.19.0/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java index 0ff707d..f1fd8ad 100644 --- a/projects/kitten-square/r1.19.0/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java +++ b/projects/kitten-square/r1.19.0/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java @@ -7,9 +7,11 @@ import net.minecraft.util.FormattedCharSequence; import net.pixaurora.kit_tunes.api.resource.ResourcePath; import net.pixaurora.kitten_cube.impl.MinecraftClient; +import net.pixaurora.kitten_cube.impl.math.Size; import net.pixaurora.kitten_cube.impl.text.Color; import net.pixaurora.kitten_cube.impl.text.Component; import net.pixaurora.kitten_cube.impl.ui.display.GuiDisplay; +import net.pixaurora.kitten_cube.impl.ui.screen.align.Alignment; import net.pixaurora.kitten_cube.impl.ui.widget.text.TextBox; import net.pixaurora.kitten_square.impl.ui.ConversionCacheImpl; import net.pixaurora.kitten_square.impl.ui.widget.TextBoxImpl; @@ -44,20 +46,20 @@ public void drawText(Component text, Color color, int x, int y, boolean shadowed @SuppressWarnings("resource") @Override - public void drawTextBox(TextBox textBox) { - if (textBox instanceof TextBoxImpl) { - TextBoxImpl impl = (TextBoxImpl) textBox; + public void drawTextBox(TextBox textBox, Alignment alignment, Size window) { + if (!(textBox instanceof TextBoxImpl)) { + throw new UnsupportedOperationException("Unsupported instance of textbox"); + } - int y = impl.startPos.y(); + TextBoxImpl impl = (TextBoxImpl) textBox; - for (FormattedCharSequence line : impl.lines) { - GuiComponent.drawString(poseStack, Minecraft.getInstance().font, line, impl.startPos.x(), y, - impl.color.hex()); + int x = alignment.alignX(impl.startPos, window); + int y = alignment.alignY(impl.startPos, window); - y += MinecraftClient.textHeight(); - } - } else { - throw new UnsupportedOperationException("Unsupported instance of textbox"); + for (FormattedCharSequence line : impl.lines) { + GuiComponent.drawString(poseStack, Minecraft.getInstance().font, line, x, y, impl.color.hex()); + + y += MinecraftClient.textHeight(); } } } diff --git a/projects/kitten-square/r1.19.3/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java b/projects/kitten-square/r1.19.3/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java index 0ff707d..f1fd8ad 100644 --- a/projects/kitten-square/r1.19.3/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java +++ b/projects/kitten-square/r1.19.3/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java @@ -7,9 +7,11 @@ import net.minecraft.util.FormattedCharSequence; import net.pixaurora.kit_tunes.api.resource.ResourcePath; import net.pixaurora.kitten_cube.impl.MinecraftClient; +import net.pixaurora.kitten_cube.impl.math.Size; import net.pixaurora.kitten_cube.impl.text.Color; import net.pixaurora.kitten_cube.impl.text.Component; import net.pixaurora.kitten_cube.impl.ui.display.GuiDisplay; +import net.pixaurora.kitten_cube.impl.ui.screen.align.Alignment; import net.pixaurora.kitten_cube.impl.ui.widget.text.TextBox; import net.pixaurora.kitten_square.impl.ui.ConversionCacheImpl; import net.pixaurora.kitten_square.impl.ui.widget.TextBoxImpl; @@ -44,20 +46,20 @@ public void drawText(Component text, Color color, int x, int y, boolean shadowed @SuppressWarnings("resource") @Override - public void drawTextBox(TextBox textBox) { - if (textBox instanceof TextBoxImpl) { - TextBoxImpl impl = (TextBoxImpl) textBox; + public void drawTextBox(TextBox textBox, Alignment alignment, Size window) { + if (!(textBox instanceof TextBoxImpl)) { + throw new UnsupportedOperationException("Unsupported instance of textbox"); + } - int y = impl.startPos.y(); + TextBoxImpl impl = (TextBoxImpl) textBox; - for (FormattedCharSequence line : impl.lines) { - GuiComponent.drawString(poseStack, Minecraft.getInstance().font, line, impl.startPos.x(), y, - impl.color.hex()); + int x = alignment.alignX(impl.startPos, window); + int y = alignment.alignY(impl.startPos, window); - y += MinecraftClient.textHeight(); - } - } else { - throw new UnsupportedOperationException("Unsupported instance of textbox"); + for (FormattedCharSequence line : impl.lines) { + GuiComponent.drawString(poseStack, Minecraft.getInstance().font, line, x, y, impl.color.hex()); + + y += MinecraftClient.textHeight(); } } } diff --git a/projects/kitten-square/r1.19.4/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java b/projects/kitten-square/r1.19.4/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java index 0ff707d..f1fd8ad 100644 --- a/projects/kitten-square/r1.19.4/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java +++ b/projects/kitten-square/r1.19.4/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java @@ -7,9 +7,11 @@ import net.minecraft.util.FormattedCharSequence; import net.pixaurora.kit_tunes.api.resource.ResourcePath; import net.pixaurora.kitten_cube.impl.MinecraftClient; +import net.pixaurora.kitten_cube.impl.math.Size; import net.pixaurora.kitten_cube.impl.text.Color; import net.pixaurora.kitten_cube.impl.text.Component; import net.pixaurora.kitten_cube.impl.ui.display.GuiDisplay; +import net.pixaurora.kitten_cube.impl.ui.screen.align.Alignment; import net.pixaurora.kitten_cube.impl.ui.widget.text.TextBox; import net.pixaurora.kitten_square.impl.ui.ConversionCacheImpl; import net.pixaurora.kitten_square.impl.ui.widget.TextBoxImpl; @@ -44,20 +46,20 @@ public void drawText(Component text, Color color, int x, int y, boolean shadowed @SuppressWarnings("resource") @Override - public void drawTextBox(TextBox textBox) { - if (textBox instanceof TextBoxImpl) { - TextBoxImpl impl = (TextBoxImpl) textBox; + public void drawTextBox(TextBox textBox, Alignment alignment, Size window) { + if (!(textBox instanceof TextBoxImpl)) { + throw new UnsupportedOperationException("Unsupported instance of textbox"); + } - int y = impl.startPos.y(); + TextBoxImpl impl = (TextBoxImpl) textBox; - for (FormattedCharSequence line : impl.lines) { - GuiComponent.drawString(poseStack, Minecraft.getInstance().font, line, impl.startPos.x(), y, - impl.color.hex()); + int x = alignment.alignX(impl.startPos, window); + int y = alignment.alignY(impl.startPos, window); - y += MinecraftClient.textHeight(); - } - } else { - throw new UnsupportedOperationException("Unsupported instance of textbox"); + for (FormattedCharSequence line : impl.lines) { + GuiComponent.drawString(poseStack, Minecraft.getInstance().font, line, x, y, impl.color.hex()); + + y += MinecraftClient.textHeight(); } } } diff --git a/projects/kitten-square/r1.20.0/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java b/projects/kitten-square/r1.20.0/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java index a09ed02..e04d036 100644 --- a/projects/kitten-square/r1.20.0/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java +++ b/projects/kitten-square/r1.20.0/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java @@ -5,9 +5,11 @@ import net.minecraft.util.FormattedCharSequence; import net.pixaurora.kit_tunes.api.resource.ResourcePath; import net.pixaurora.kitten_cube.impl.MinecraftClient; +import net.pixaurora.kitten_cube.impl.math.Size; import net.pixaurora.kitten_cube.impl.text.Color; import net.pixaurora.kitten_cube.impl.text.Component; import net.pixaurora.kitten_cube.impl.ui.display.GuiDisplay; +import net.pixaurora.kitten_cube.impl.ui.screen.align.Alignment; import net.pixaurora.kitten_cube.impl.ui.widget.text.TextBox; import net.pixaurora.kitten_square.impl.ui.ConversionCacheImpl; import net.pixaurora.kitten_square.impl.ui.widget.TextBoxImpl; @@ -42,20 +44,20 @@ public void drawText(Component text, Color color, int x, int y, boolean shadowed @SuppressWarnings("resource") @Override - public void drawTextBox(TextBox textBox) { - if (textBox instanceof TextBoxImpl) { - TextBoxImpl impl = (TextBoxImpl) textBox; + public void drawTextBox(TextBox textBox, Alignment alignment, Size window) { + if (!(textBox instanceof TextBoxImpl)) { + throw new UnsupportedOperationException("Unsupported instance of textbox"); + } - int y = impl.startPos.y(); + TextBoxImpl impl = (TextBoxImpl) textBox; - for (FormattedCharSequence line : impl.lines) { - this.graphics.drawString(Minecraft.getInstance().font, line, impl.startPos.x(), y, impl.color.hex(), - false); + int x = alignment.alignX(impl.startPos, window); + int y = alignment.alignY(impl.startPos, window); - y += MinecraftClient.textHeight(); - } - } else { - throw new UnsupportedOperationException("Unsupported instance of textbox"); + for (FormattedCharSequence line : impl.lines) { + this.graphics.drawString(Minecraft.getInstance().font, line, x, y, impl.color.hex(), false); + + y += MinecraftClient.textHeight(); } } } diff --git a/projects/kitten-square/r1.20.3/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java b/projects/kitten-square/r1.20.3/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java index 1b043d2..95a57c9 100644 --- a/projects/kitten-square/r1.20.3/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java +++ b/projects/kitten-square/r1.20.3/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java @@ -5,9 +5,11 @@ import net.minecraft.util.FormattedCharSequence; import net.pixaurora.kit_tunes.api.resource.ResourcePath; import net.pixaurora.kitten_cube.impl.MinecraftClient; +import net.pixaurora.kitten_cube.impl.math.Size; import net.pixaurora.kitten_cube.impl.text.Color; import net.pixaurora.kitten_cube.impl.text.Component; import net.pixaurora.kitten_cube.impl.ui.display.GuiDisplay; +import net.pixaurora.kitten_cube.impl.ui.screen.align.Alignment; import net.pixaurora.kitten_cube.impl.ui.widget.text.TextBox; import net.pixaurora.kitten_square.impl.ui.ConversionCacheImpl; import net.pixaurora.kitten_square.impl.ui.widget.TextBoxImpl; @@ -42,20 +44,19 @@ public void drawText(Component text, Color color, int x, int y, boolean shadowed @SuppressWarnings("resource") @Override - public void drawTextBox(TextBox textBox) { - if (textBox instanceof TextBoxImpl) { - TextBoxImpl impl = (TextBoxImpl) textBox; + public void drawTextBox(TextBox textBox, Alignment alignment, Size window) { + if (!(textBox instanceof TextBoxImpl)) { + throw new UnsupportedOperationException("Unsupported instance of textbox"); + } + TextBoxImpl impl = (TextBoxImpl) textBox; - int y = impl.startPos.y(); + int x = alignment.alignX(impl.startPos, window); + int y = alignment.alignY(impl.startPos, window); - for (FormattedCharSequence line : impl.lines) { - this.graphics.drawString(Minecraft.getInstance().font, line, impl.startPos.x(), y, impl.color.hex(), - false); + for (FormattedCharSequence line : impl.lines) { + this.graphics.drawString(Minecraft.getInstance().font, line, x, y, impl.color.hex(), false); - y += MinecraftClient.textHeight(); - } - } else { - throw new UnsupportedOperationException("Unsupported instance of textbox"); + y += MinecraftClient.textHeight(); } } } diff --git a/projects/kitten-square/r1.21.0/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java b/projects/kitten-square/r1.21.0/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java index b476ec8..f337840 100644 --- a/projects/kitten-square/r1.21.0/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java +++ b/projects/kitten-square/r1.21.0/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java @@ -5,9 +5,11 @@ import net.minecraft.util.FormattedCharSequence; import net.pixaurora.kit_tunes.api.resource.ResourcePath; import net.pixaurora.kitten_cube.impl.MinecraftClient; +import net.pixaurora.kitten_cube.impl.math.Size; import net.pixaurora.kitten_cube.impl.text.Color; import net.pixaurora.kitten_cube.impl.text.Component; import net.pixaurora.kitten_cube.impl.ui.display.GuiDisplay; +import net.pixaurora.kitten_cube.impl.ui.screen.align.Alignment; import net.pixaurora.kitten_cube.impl.ui.widget.text.TextBox; import net.pixaurora.kitten_square.impl.ui.ConversionCacheImpl; import net.pixaurora.kitten_square.impl.ui.widget.TextBoxImpl; @@ -42,20 +44,19 @@ public void drawText(Component text, Color color, int x, int y, boolean shadowed @SuppressWarnings("resource") @Override - public void drawTextBox(TextBox textBox) { - if (textBox instanceof TextBoxImpl) { - TextBoxImpl impl = (TextBoxImpl) textBox; + public void drawTextBox(TextBox textBox, Alignment alignment, Size window) { + if (!(textBox instanceof TextBoxImpl)) { + throw new UnsupportedOperationException("Unsupported instance of textbox"); + } + TextBoxImpl impl = (TextBoxImpl) textBox; - int y = impl.startPos.y(); + int x = alignment.alignX(impl.startPos, window); + int y = alignment.alignY(impl.startPos, window); - for (FormattedCharSequence line : impl.lines) { - this.graphics.drawString(Minecraft.getInstance().font, line, impl.startPos.x(), y, impl.color.hex(), - false); + for (FormattedCharSequence line : impl.lines) { + this.graphics.drawString(Minecraft.getInstance().font, line, x, y, impl.color.hex(), false); - y += MinecraftClient.textHeight(); - } - } else { - throw new UnsupportedOperationException("Unsupported instance of textbox"); + y += MinecraftClient.textHeight(); } } } diff --git a/projects/kitten-square/r1.21.2/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java b/projects/kitten-square/r1.21.2/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java index 2afbbad..1666e31 100644 --- a/projects/kitten-square/r1.21.2/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java +++ b/projects/kitten-square/r1.21.2/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.java @@ -7,9 +7,11 @@ import net.minecraft.util.FormattedCharSequence; import net.pixaurora.kit_tunes.api.resource.ResourcePath; import net.pixaurora.kitten_cube.impl.MinecraftClient; +import net.pixaurora.kitten_cube.impl.math.Size; import net.pixaurora.kitten_cube.impl.text.Color; import net.pixaurora.kitten_cube.impl.text.Component; import net.pixaurora.kitten_cube.impl.ui.display.GuiDisplay; +import net.pixaurora.kitten_cube.impl.ui.screen.align.Alignment; import net.pixaurora.kitten_cube.impl.ui.widget.text.TextBox; import net.pixaurora.kitten_square.impl.ui.ConversionCacheImpl; import net.pixaurora.kitten_square.impl.ui.widget.TextBoxImpl; @@ -47,20 +49,20 @@ public void drawText(Component text, Color color, int x, int y, boolean shadowed @SuppressWarnings("resource") @Override - public void drawTextBox(TextBox textBox) { - if (textBox instanceof TextBoxImpl) { - TextBoxImpl impl = (TextBoxImpl) textBox; + public void drawTextBox(TextBox textBox, Alignment alignment, Size window) { + if (!(textBox instanceof TextBoxImpl)) { + throw new UnsupportedOperationException("Unsupported instance of textbox"); + } - int y = impl.startPos.y(); + TextBoxImpl impl = (TextBoxImpl) textBox; - for (FormattedCharSequence line : impl.lines) { - this.graphics.drawString(Minecraft.getInstance().font, line, impl.startPos.x(), y, impl.color.hex(), - false); + int x = alignment.alignX(impl.startPos, window); + int y = alignment.alignY(impl.startPos, window); - y += MinecraftClient.textHeight(); - } - } else { - throw new UnsupportedOperationException("Unsupported instance of textbox"); + for (FormattedCharSequence line : impl.lines) { + this.graphics.drawString(Minecraft.getInstance().font, line, x, y, impl.color.hex(), false); + + y += MinecraftClient.textHeight(); } } }