TOASTED. R O A S T E D.

This commit is contained in:
FalsePattern committed 2022-07-30 23:26:25 +02:00
1 parent 6e954f3129
commit d41a460589
27 files changed
+787 -23

No files matched your search

@@ -0,0 +1,49 @@
/**
* Copyright (C) 2022 FalsePattern
* All Rights Reserved
* <p>
* The above copyright notice, this permission notice and the word "SNEED"
* shall be included in all copies or substantial portions of the Software.
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.lib.toasts;
import com.falsepattern.lib.StableAPI;
import com.falsepattern.lib.internal.impl.toast.GuiToastImpl;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import javax.annotation.Nullable;
@SideOnly(Side.CLIENT)
@StableAPI(since = "0.10.0")
public class GuiToast {
@StableAPI(since = "0.10.0")
@Nullable
public static <T extends IToast> T getToast(Class<? extends T> toastClass, Object type) {
return GuiToastImpl.getInstance().getToast(toastClass, type);
}
@StableAPI(since = "0.10.0")
public static void clear() {
GuiToastImpl.getInstance().clear();
}
@StableAPI(since = "0.10.0")
public static void add(IToast toastIn) {
GuiToastImpl.getInstance().add(toastIn);
}
}
@@ -0,0 +1,70 @@
/**
* Copyright (C) 2022 FalsePattern
* All Rights Reserved
* <p>
* The above copyright notice, this permission notice and the word "SNEED"
* shall be included in all copies or substantial portions of the Software.
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.lib.toasts;
import com.falsepattern.lib.StableAPI;
import com.falsepattern.lib.internal.Tags;
import com.falsepattern.lib.internal.impl.toast.GuiToastImpl;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.audio.SoundHandler;
import net.minecraft.util.ResourceLocation;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
@StableAPI(since = "0.10.0")
public interface IToast {
@StableAPI(since = "0.10.0")
Object NO_TOKEN = new Object();
@StableAPI(since = "0.10.0")
Visibility draw(GuiToastImpl toastGui, long delta);
@StableAPI(since = "0.10.0")
int width();
@StableAPI(since = "0.10.0")
int height();
@StableAPI(since = "0.10.0")
default Object getType() {
return NO_TOKEN;
}
@StableAPI(since = "0.10.0")
@SideOnly(Side.CLIENT)
enum Visibility {
SHOW(new ResourceLocation(Tags.MODID, "ui.toast.in")),
HIDE(new ResourceLocation(Tags.MODID, "ui.toast.out"));
private final ResourceLocation sound;
Visibility(ResourceLocation soundIn) {
this.sound = soundIn;
}
@StableAPI(since = "0.10.0")
public void playSound(SoundHandler handler) {
handler.playSound(PositionedSoundRecord.func_147674_a(this.sound, 1.0F));
}
}
}
@@ -0,0 +1,126 @@
/**
* Copyright (C) 2022 FalsePattern
* All Rights Reserved
* <p>
* The above copyright notice, this permission notice and the word "SNEED"
* shall be included in all copies or substantial portions of the Software.
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.lib.toasts;
import com.falsepattern.lib.StableAPI;
import com.falsepattern.lib.internal.impl.toast.GuiToastImpl;
import com.falsepattern.lib.toasts.icon.ToastBG;
import com.falsepattern.lib.toasts.icon.ToastIcon;
import com.falsepattern.lib.util.MathUtil;
import lombok.NonNull;
import lombok.val;
import org.lwjgl.opengl.GL11;
import net.minecraft.client.gui.Gui;
import net.minecraft.util.IChatComponent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import javax.annotation.Nullable;
@SideOnly(Side.CLIENT)
@StableAPI(since = "0.10.0")
public class SimpleToast implements IToast {
private final ToastBG background;
private final ToastIcon icon;
private final String title;
private final String subtitle;
private final boolean hasProgressBar;
private final long timeout;
private IToast.Visibility visibility = IToast.Visibility.SHOW;
private long lastDelta;
private float displayedProgress;
private float currentProgress;
@StableAPI(since = "0.10.0")
public SimpleToast(@NonNull ToastBG background, @Nullable ToastIcon icon,
IChatComponent titleComponent, @Nullable IChatComponent subtitleComponent,
boolean drawProgressBar, long timeout) {
this.background = background;
this.icon = icon;
this.title = titleComponent.getFormattedText();
this.subtitle = subtitleComponent == null ? null : subtitleComponent.getFormattedText();
this.hasProgressBar = drawProgressBar;
this.timeout = timeout;
}
@Override
public IToast.Visibility draw(GuiToastImpl toastGui, long delta) {
GL11.glColor3f(1, 1, 1);
background.draw(toastGui, 0, 0);
if (icon != null) {
icon.draw(toastGui, 6, 6);
}
val x = icon == null ? 5 : 5 + icon.getIcon().getIconWidth();
val bgHeight = background.getIcon().getIconHeight();
val fontRenderer = toastGui.getMinecraft().fontRenderer;
if (subtitle == null) {
fontRenderer.drawString(title, x, bgHeight / 2 - 5, 0xFFFFFFFF);
} else {
fontRenderer.drawString(title, x, 7, 0xFFFFFFFF);
fontRenderer.drawString(subtitle, x, bgHeight - 14, 0xFFFFFFFF);
}
if (hasProgressBar) {
val bgWidth = background.getIcon().getIconWidth();
Gui.drawRect(3, bgHeight - 4, bgWidth - 3, bgHeight - 3, 0xFFFFFFFF);
float f = (float) MathUtil.clampedLerp(displayedProgress, currentProgress, (float) (delta - lastDelta) / 100.0F);
int i;
if (currentProgress >= displayedProgress) {
i = 0xff005500;
} else {
i = 0xff550000;
}
val barLength = bgWidth - 6;
Gui.drawRect(3, bgHeight - 4, (int) (3.0F + barLength * f), bgHeight - 3, i);
displayedProgress = f;
lastDelta = delta;
}
if (timeout > 0) {
if (delta >= timeout) {
hide();
}
}
return visibility;
}
@Override
public int width() {
return background.getIcon().getIconWidth();
}
@Override
public int height() {
return background.getIcon().getIconHeight();
}
@StableAPI(since = "0.10.0")
public void hide() {
visibility = IToast.Visibility.HIDE;
}
@StableAPI(since = "0.10.0")
public void setProgress(float progress) {
this.currentProgress = progress;
}
}
@@ -0,0 +1,70 @@
/**
* Copyright (C) 2022 FalsePattern
* All Rights Reserved
* <p>
* The above copyright notice, this permission notice and the word "SNEED"
* shall be included in all copies or substantial portions of the Software.
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.lib.toasts.icon;
import com.falsepattern.lib.StableAPI;
import com.falsepattern.lib.internal.Tags;
import lombok.NonNull;
import org.lwjgl.opengl.GL11;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
@StableAPI(since = "0.10.0")
public class ToastBG extends ToastTexture {
@StableAPI(since = "0.10.0")
public static final ToastBG TOAST_DARK = new ToastBG(new ResourceLocation(Tags.MODID, "textures/gui/toast_dark.png"), 160, 32, 0xFFFFFFFF);
@StableAPI(since = "0.10.0")
public static final ToastBG TOAST_DARK_ROUNDED = new ToastBG(new ResourceLocation(Tags.MODID, "textures/gui/toast_dark_rounded.png"), 160, 32, 0xFFFFFFFF);
@StableAPI(since = "0.10.0")
public static final ToastBG TOAST_NARRATOR = new ToastBG(new ResourceLocation(Tags.MODID, "textures/gui/toast_narrator.png"), 160, 32, 0xFFAAAA00);
@StableAPI(since = "0.10.0")
public static final ToastBG TOAST_NARRATOR_ROUNDED = new ToastBG(new ResourceLocation(Tags.MODID, "textures/gui/toast_narrator_rounded.png"), 160, 32, 0xFFAAAA00);
@StableAPI(since = "0.10.0")
public static final ToastBG TOAST_WHITE = new ToastBG(new ResourceLocation(Tags.MODID, "textures/gui/toast_white.png"), 160, 32, 0xFF500050);
@StableAPI(since = "0.10.0")
public static final ToastBG TOAST_WHITE_ROUNDED = new ToastBG(new ResourceLocation(Tags.MODID, "textures/gui/toast_white_rounded.png"), 160, 32, 0xFF500050);
@StableAPI(since = "0.10.0")
public final int defaultTextColor;
@StableAPI(since = "0.10.0")
public ToastBG(@NonNull ResourceLocation texture, int width, int height, int defaultTextColor) {
super(texture, width, height);
this.defaultTextColor = defaultTextColor;
}
@StableAPI(since = "0.10.0")
public ToastBG(@NonNull ResourceLocation texture, @NonNull IIcon icon, int defaultTextColor) {
super(texture, icon);
this.defaultTextColor = defaultTextColor;
}
@Override
public void draw(Gui guiIn, int x, int y) {
GL11.glPushAttrib(GL11.GL_TEXTURE_BIT);
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
guiIn.drawTexturedModelRectFromIcon(x, y, icon, icon.getIconWidth(), icon.getIconHeight());
GL11.glPopAttrib();
}
}
@@ -0,0 +1,52 @@
/**
* Copyright (C) 2022 FalsePattern
* All Rights Reserved
* <p>
* The above copyright notice, this permission notice and the word "SNEED"
* shall be included in all copies or substantial portions of the Software.
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.lib.toasts.icon;
import com.falsepattern.lib.StableAPI;
import lombok.NonNull;
import org.lwjgl.opengl.GL11;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
@StableAPI(since = "0.10.0")
public class ToastIcon extends ToastTexture {
@StableAPI(since = "0.10.0")
public ToastIcon(@NonNull ResourceLocation texture, int width, int height) {
super(texture, width, height);
}
@StableAPI(since = "0.10.0")
public ToastIcon(@NonNull ResourceLocation texture, @NonNull IIcon icon) {
super(texture, icon);
}
@Override
public void draw(Gui guiIn, int x, int y) {
GL11.glPushAttrib(GL11.GL_TEXTURE_BIT | GL11.GL_ENABLE_BIT);
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
GL11.glEnable(GL11.GL_BLEND);
guiIn.drawTexturedModelRectFromIcon(x, y, icon, icon.getIconWidth(), icon.getIconHeight());
GL11.glPopAttrib();
}
}
@@ -0,0 +1,55 @@
/**
* Copyright (C) 2022 FalsePattern
* All Rights Reserved
* <p>
* The above copyright notice, this permission notice and the word "SNEED"
* shall be included in all copies or substantial portions of the Software.
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.lib.toasts.icon;
import com.falsepattern.lib.StableAPI;
import com.falsepattern.lib.util.RenderUtil;
import lombok.Getter;
import lombok.NonNull;
import net.minecraft.client.gui.Gui;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
@StableAPI(since = "0.10.0")
public abstract class ToastTexture {
@Getter(onMethod_={@StableAPI(since = "0.10.0")})
protected final IIcon icon;
@Getter(onMethod_={@StableAPI(since = "0.10.0")})
protected final ResourceLocation texture;
@StableAPI(since = "0.10.0")
public ToastTexture(@NonNull ResourceLocation texture, int width, int height) {
this(texture, RenderUtil.getFullTextureIcon(texture.toString(), width, height));
}
@StableAPI(since = "0.10.0")
public ToastTexture(@NonNull ResourceLocation texture, @NonNull IIcon icon) {
this.icon = icon;
this.texture = texture;
}
/**
* Draws the icon at the specified position in the specified Gui
*/
@StableAPI(since = "0.10.0")
public abstract void draw(Gui guiIn, int x, int y);
}