diff --git a/src/main/java/org/orecruncher/dsurround/gui/sound/SoundToast.java b/src/main/java/org/orecruncher/dsurround/gui/sound/SoundToast.java index 3020adb9..75bfa56b 100644 --- a/src/main/java/org/orecruncher/dsurround/gui/sound/SoundToast.java +++ b/src/main/java/org/orecruncher/dsurround/gui/sound/SoundToast.java @@ -1,14 +1,18 @@ package org.orecruncher.dsurround.gui.sound; import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.Music; import org.orecruncher.dsurround.config.libraries.ISoundLibrary; import org.orecruncher.dsurround.lib.GameUtils; import org.orecruncher.dsurround.lib.di.ContainerManager; +import org.orecruncher.dsurround.lib.gui.ColorPalette; import org.orecruncher.dsurround.lib.gui.WarmToast; public class SoundToast { + private static final WarmToast.Profile SOUND_TOAST_PROFILE = new WarmToast.Profile(new ResourceLocation("toast/advancement"), 5000, ColorPalette.PUMPKIN_ORANGE, ColorPalette.WHEAT); + public static void create(Music music) { var soundLibrary = ContainerManager.resolve(ISoundLibrary.class); var metadata = soundLibrary.getSoundMetadata(music.getEvent().value().getLocation()); @@ -18,7 +22,7 @@ public static void create(Music music) { var author = metadata.getCredits().get(0).author(); var titleLine = Component.translatable("dsurround.text.toast.music.title", title); var authorLine = Component.translatable("dsurround.text.toast.music.author", author); - var toast = WarmToast.multiline(GameUtils.getMC(), titleLine, authorLine); + var toast = WarmToast.multiline(GameUtils.getMC(), SOUND_TOAST_PROFILE, titleLine, authorLine); GameUtils.getMC().getToasts().addToast(toast); } } diff --git a/src/main/java/org/orecruncher/dsurround/lib/gui/WarmToast.java b/src/main/java/org/orecruncher/dsurround/lib/gui/WarmToast.java index f8f9875e..d28784e8 100644 --- a/src/main/java/org/orecruncher/dsurround/lib/gui/WarmToast.java +++ b/src/main/java/org/orecruncher/dsurround/lib/gui/WarmToast.java @@ -6,6 +6,7 @@ import net.minecraft.client.gui.components.toasts.Toast; import net.minecraft.client.gui.components.toasts.ToastComponent; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextColor; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.FormattedCharSequence; import org.jetbrains.annotations.NotNull; @@ -13,17 +14,16 @@ import java.util.List; +@SuppressWarnings("unused") public class WarmToast implements Toast { - private static final ResourceLocation BACKGROUND_SPRITE = new ResourceLocation("toast/advancement"); - private static final int DISPLAY_TIME = 5000; + private static final Profile DEFAULT_PROFILE = new Profile(new ResourceLocation("toast/advancement"), 5000, ColorPalette.GOLD, ColorPalette.WHITE); private static final int MAX_LINE_SIZE = 200; private static final int MIN_LINE_SIZE = 100; private static final int LINE_SPACING = 12; private static final int MARGIN = 10; - private final ResourceLocation backgroundSprite; - private final int displayTime; + private final Profile profile; private Component title; private List messageLines; @@ -32,21 +32,20 @@ public class WarmToast implements Toast { private final int width; public static WarmToast multiline(Minecraft minecraft, Component title, Component body) { - return multiline(minecraft, BACKGROUND_SPRITE, DISPLAY_TIME, title, body); + return multiline(minecraft, DEFAULT_PROFILE, title, body); } - public static WarmToast multiline(Minecraft minecraft, ResourceLocation backgroundSprite, int displayTime, Component title, Component body) { + public static WarmToast multiline(Minecraft minecraft, Profile profile, Component title, Component body) { var font = minecraft.font; var list = font.split(body, MAX_LINE_SIZE); var titleSize = Math.min(MAX_LINE_SIZE, Math.max(MIN_LINE_SIZE, font.width(title))); var lineSize = list.stream().mapToInt(font::width).max().orElse(MIN_LINE_SIZE); int width = Math.max(titleSize, lineSize) + MARGIN * 3; - return new WarmToast(backgroundSprite, displayTime, title, list, width); + return new WarmToast(profile, title, list, width); } - private WarmToast(ResourceLocation background, int displayTime, Component title, List body, int width) { - this.backgroundSprite = background; - this.displayTime = displayTime; + private WarmToast(Profile profile, Component title, List body, int width) { + this.profile = profile; this.title = title; this.messageLines = body; this.width = width; @@ -74,7 +73,7 @@ public void reset(Component component, @Nullable Component component2) { int i = this.width(); if (i == 160 && this.messageLines.size() <= 1) { - guiGraphics.blitSprite(this.backgroundSprite, 0, 0, i, this.height()); + guiGraphics.blitSprite(this.profile.sprite, 0, 0, i, this.height()); } else { int renderHeight = this.height(); int lineRenderCount = Math.min(4, renderHeight - 28); @@ -88,16 +87,16 @@ public void reset(Component component, @Nullable Component component2) { } if (this.messageLines.isEmpty()) { - guiGraphics.drawString(toastComponent.getMinecraft().font, this.title, 18, LINE_SPACING, -256, false); + guiGraphics.drawString(toastComponent.getMinecraft().font, this.title, 18, LINE_SPACING, this.profile.titleColor.getValue(), false); } else { - guiGraphics.drawString(toastComponent.getMinecraft().font, this.title, 18, 7, -256, false); + guiGraphics.drawString(toastComponent.getMinecraft().font, this.title, 18, 7, this.profile.titleColor.getValue(), false); for(int j = 0; j < this.messageLines.size(); ++j) { - guiGraphics.drawString(toastComponent.getMinecraft().font, this.messageLines.get(j), 18, 18 + j * LINE_SPACING, -1, false); + guiGraphics.drawString(toastComponent.getMinecraft().font, this.messageLines.get(j), 18, 18 + j * LINE_SPACING, this.profile.bodyColor.getValue(), false); } } - double d = (double)this.displayTime * toastComponent.getNotificationDisplayTimeMultiplier(); + double d = (double)this.profile.displayTime * toastComponent.getNotificationDisplayTimeMultiplier(); long o = lastChanged - this.lastChanged; return (double)o < d ? Visibility.SHOW : Visibility.HIDE; } @@ -105,16 +104,20 @@ public void reset(Component component, @Nullable Component component2) { private void renderBackgroundRow(GuiGraphics guiGraphics, int i, int j, int k, int l) { int m = j == 0 ? 20 : 5; int n = Math.min(60, i - m); - guiGraphics.blitSprite(this.backgroundSprite, 160, 32, 0, j, 0, k, m, l); + guiGraphics.blitSprite(this.profile.sprite, 160, 32, 0, j, 0, k, m, l); for(int o = m; o < i - n; o += 64) { - guiGraphics.blitSprite(this.backgroundSprite, 160, 32, 32, j, o, k, Math.min(64, i - o - n), l); + guiGraphics.blitSprite(this.profile.sprite, 160, 32, 32, j, o, k, Math.min(64, i - o - n), l); } - guiGraphics.blitSprite(this.backgroundSprite, 160, 32, 160 - n, j, i - n, k, n, l); + guiGraphics.blitSprite(this.profile.sprite, 160, 32, 160 - n, j, i - n, k, n, l); } private static ImmutableList nullToEmpty(@Nullable Component component) { return component == null ? ImmutableList.of() : ImmutableList.of(component.getVisualOrderText()); } + + public record Profile(ResourceLocation sprite, int displayTime, TextColor titleColor, TextColor bodyColor) { + + } }