generated from QuiltMC/quilt-template-mod
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move the toast logic to the core of the mod
- Loading branch information
Showing
24 changed files
with
312 additions
and
330 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
subprojects/core/src/main/java/net/pixaurora/kit_tunes/impl/ui/text/TextProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
subprojects/core/src/main/java/net/pixaurora/kit_tunes/impl/ui/tile/InnerTile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package net.pixaurora.kit_tunes.impl.ui.tile; | ||
|
||
import net.pixaurora.kit_tunes.impl.ui.math.Point; | ||
import net.pixaurora.kit_tunes.impl.ui.math.Size; | ||
import net.pixaurora.kit_tunes.impl.ui.texture.GuiTexture; | ||
|
||
public class InnerTile { | ||
private final GuiTexture texture; | ||
private final Point textureOffset; | ||
private final Size size; | ||
|
||
public InnerTile(GuiTexture texture, Point textureOffset, Size size) { | ||
this.texture = texture; | ||
this.textureOffset = textureOffset; | ||
this.size = size; | ||
} | ||
|
||
public GuiTexture texture() { | ||
return this.texture; | ||
} | ||
|
||
public Point textureOffset() { | ||
return this.textureOffset; | ||
} | ||
|
||
public Size size() { | ||
return this.size; | ||
} | ||
|
||
public PositionedInnerTile atPos(Point pos) { | ||
return new PositionedInnerTile(pos, this); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
subprojects/core/src/main/java/net/pixaurora/kit_tunes/impl/ui/tile/PositionedInnerTile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package net.pixaurora.kit_tunes.impl.ui.tile; | ||
|
||
import net.pixaurora.kit_tunes.impl.ui.GuiDisplay; | ||
import net.pixaurora.kit_tunes.impl.ui.math.Point; | ||
import net.pixaurora.kit_tunes.impl.ui.math.Size; | ||
|
||
public class PositionedInnerTile { | ||
private final Point pos; | ||
private final InnerTile tile; | ||
|
||
public PositionedInnerTile(Point pos, InnerTile tile) { | ||
this.pos = pos; | ||
this.tile = tile; | ||
} | ||
|
||
public Size size() { | ||
return this.tile.size(); | ||
} | ||
|
||
public void draw(GuiDisplay gui) { | ||
gui.drawGui(tile.texture(), this.pos, tile.size(), tile.textureOffset()); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
subprojects/core/src/main/java/net/pixaurora/kit_tunes/impl/ui/toast/DrawableToast.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package net.pixaurora.kit_tunes.impl.ui.toast; | ||
|
||
import java.time.Duration; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import net.pixaurora.kit_tunes.impl.ui.GuiDisplay; | ||
import net.pixaurora.kit_tunes.impl.ui.MinecraftClient; | ||
import net.pixaurora.kit_tunes.impl.ui.math.Point; | ||
import net.pixaurora.kit_tunes.impl.ui.math.Size; | ||
import net.pixaurora.kit_tunes.impl.ui.text.Component; | ||
import net.pixaurora.kit_tunes.impl.ui.texture.Texture; | ||
import net.pixaurora.kit_tunes.impl.ui.tile.PositionedInnerTile; | ||
import net.pixaurora.kit_tunes.impl.ui.widget.text.PositionedText; | ||
import net.pixaurora.kit_tunes.impl.util.Pair; | ||
|
||
public class DrawableToast implements Toast { | ||
private final Texture icon; | ||
private final Point iconPos; | ||
|
||
private final List<PositionedInnerTile> tiles; | ||
|
||
private final List<PositionedText> text; | ||
|
||
private final Size size; | ||
|
||
public DrawableToast(KitTunesToastData data) { | ||
ToastBackground background = data.background(); | ||
|
||
this.icon = data.icon(); | ||
this.iconPos = background.iconPos(); | ||
|
||
this.text = new ArrayList<>(); | ||
this.text.add(new PositionedText(data.title(), data.titleColor(), background.titlePos())); | ||
|
||
Point textPos = background.bodyTextStartPos(); | ||
for (Component line : data.messageLines()) { | ||
for (Component splitLine : MinecraftClient.splitText(line, background.maxLineLength())) { | ||
this.text.add(new PositionedText(splitLine, data.messageColor(), textPos)); | ||
textPos = textPos.offset(0, MinecraftClient.textHeight()); | ||
} | ||
} | ||
|
||
Pair<List<PositionedInnerTile>, Size> tilesAndSize = background.tilesAndSize(this.text); | ||
|
||
this.tiles = tilesAndSize.first(); | ||
this.size = tilesAndSize.second(); | ||
} | ||
|
||
@Override | ||
public Duration timeShown() { | ||
return Duration.ofSeconds(5); | ||
} | ||
|
||
@Override | ||
public void draw(GuiDisplay gui) { | ||
this.drawBackground(gui); | ||
|
||
gui.draw(icon, iconPos); | ||
|
||
for (PositionedText line : this.text) { | ||
gui.drawText(line.text(), line.color(), line.pos(), false); | ||
} | ||
} | ||
|
||
private void drawBackground(GuiDisplay gui) { | ||
for (PositionedInnerTile tile : this.tiles) { | ||
tile.draw(gui); | ||
} | ||
} | ||
|
||
@Override | ||
public Size size() { | ||
return this.size; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
subprojects/core/src/main/java/net/pixaurora/kit_tunes/impl/ui/toast/Toast.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package net.pixaurora.kit_tunes.impl.ui.toast; | ||
|
||
import java.time.Duration; | ||
|
||
import net.pixaurora.kit_tunes.impl.ui.GuiDisplay; | ||
import net.pixaurora.kit_tunes.impl.ui.math.Size; | ||
|
||
public interface Toast { | ||
public Duration timeShown(); | ||
|
||
public void draw(GuiDisplay gui); | ||
|
||
public Size size(); | ||
|
||
public static Toast fromData(KitTunesToastData data) { | ||
return new DrawableToast(data); | ||
} | ||
} |
Oops, something went wrong.