diff options
Diffstat (limited to 'common/src/main/java/dev/isxander/yacl3/gui')
62 files changed, 0 insertions, 6671 deletions
diff --git a/common/src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java b/common/src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java deleted file mode 100644 index 0c3afdd..0000000 --- a/common/src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java +++ /dev/null @@ -1,108 +0,0 @@ -package dev.isxander.yacl3.gui; - -import dev.isxander.yacl3.api.utils.Dimension; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Font; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.components.Renderable; -import net.minecraft.client.gui.components.WidgetSprites; -import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.client.gui.narration.NarratableEntry; -import net.minecraft.client.gui.narration.NarrationElementOutput; -import net.minecraft.client.resources.sounds.SimpleSoundInstance; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.sounds.SoundEvents; - -import java.awt.*; - -public abstract class AbstractWidget implements GuiEventListener, Renderable, NarratableEntry { - private static final WidgetSprites SPRITES = new WidgetSprites( - new ResourceLocation("widget/button"), // normal - new ResourceLocation("widget/button_disabled"), // disabled & !focused - new ResourceLocation("widget/button_highlighted"), // !disabled & focused - new ResourceLocation("widget/slider_highlighted") // disabled & focused - ); - - protected final Minecraft client = Minecraft.getInstance(); - protected final Font textRenderer = client.font; - protected final int inactiveColor = 0xFFA0A0A0; - - private Dimension<Integer> dim; - - public AbstractWidget(Dimension<Integer> dim) { - this.dim = dim; - } - - public boolean canReset() { - return false; - } - - @Override - public boolean isMouseOver(double mouseX, double mouseY) { - if (dim == null) return false; - return this.dim.isPointInside((int) mouseX, (int) mouseY); - } - - public void setDimension(Dimension<Integer> dim) { - this.dim = dim; - } - - public Dimension<Integer> getDimension() { - return dim; - } - - @Override - public NarrationPriority narrationPriority() { - return NarrationPriority.NONE; - } - - public void unfocus() { - - } - - public boolean matchesSearch(String query) { - return true; - } - - @Override - public void updateNarration(NarrationElementOutput builder) { - - } - - protected void drawButtonRect(GuiGraphics graphics, int x1, int y1, int x2, int y2, boolean hovered, boolean enabled) { - if (x1 > x2) { - int xx1 = x1; - x1 = x2; - x2 = xx1; - } - if (y1 > y2) { - int yy1 = y1; - y1 = y2; - y2 = yy1; - } - int width = x2 - x1; - int height = y2 - y1; - - graphics.blitSprite(SPRITES.get(enabled, hovered), x1, y1, width, height); - } - - protected void drawOutline(GuiGraphics graphics, int x1, int y1, int x2, int y2, int width, int color) { - graphics.fill(x1, y1, x2, y1 + width, color); - graphics.fill(x2, y1, x2 - width, y2, color); - graphics.fill(x1, y2, x2, y2 - width, color); - graphics.fill(x1, y1, x1 + width, y2, color); - } - - protected int multiplyColor(int hex, float amount) { - Color color = new Color(hex, true); - - return new Color(Math.max((int)(color.getRed() * amount), 0), - Math.max((int)(color.getGreen() * amount), 0), - Math.max((int)(color.getBlue() * amount), 0), - color.getAlpha()).getRGB(); - } - - public void playDownSound() { - Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F)); - } -} diff --git a/common/src/main/java/dev/isxander/yacl3/gui/DescriptionWithName.java b/common/src/main/java/dev/isxander/yacl3/gui/DescriptionWithName.java deleted file mode 100644 index 6ad72e8..0000000 --- a/common/src/main/java/dev/isxander/yacl3/gui/DescriptionWithName.java +++ /dev/null @@ -1,11 +0,0 @@ -package dev.isxander.yacl3.gui; - -import dev.isxander.yacl3.api.OptionDescription; -import net.minecraft.ChatFormatting; -import net.minecraft.network.chat.Component; - -public record DescriptionWithName(Component name, OptionDescription description) { - public static DescriptionWithName of(Component name, OptionDescription description) { - return new DescriptionWithName(name.copy().withStyle(ChatFormatting.BOLD), description); - } -} diff --git a/common/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java b/common/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java deleted file mode 100644 index 02fc6ad..0000000 --- a/common/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java +++ /dev/null @@ -1,216 +0,0 @@ -package dev.isxander.yacl3.gui; - -import com.mojang.blaze3d.platform.InputConstants; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.components.AbstractWidget; -import net.minecraft.client.gui.components.ContainerObjectSelectionList; -import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.client.gui.layouts.LayoutElement; -import net.minecraft.client.gui.navigation.ScreenRectangle; -import net.minecraft.util.Mth; -import org.jetbrains.annotations.Nullable; - -import java.util.function.Consumer; - -public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> extends ContainerObjectSelectionList<E> implements LayoutElement { - protected static final int SCROLLBAR_WIDTH = 6; - - private double smoothScrollAmount = getScrollAmount(); - private boolean returnSmoothAmount = false; - private final boolean doSmoothScrolling; - private boolean usingScrollbar; - - public ElementListWidgetExt(Minecraft client, int x, int y, int width, int height, boolean smoothScrolling) { - super(client, x, y, width, height); - this.doSmoothScrolling = smoothScrolling; - setRenderHeader(false, 0); - } - - @Override - public boolean mouseScrolled(double mouseX, double mouseY, double horizontal, double vertical) { - // default implementation bases scroll step from total height of entries, this is constant - this.setScrollAmount(this.getScrollAmount() - (vertical + horizontal) * 20); - return true; - } - - @Override - protected int getScrollbarPosition() { - // default implementation does not respect left/right - return this.getRight() - SCROLLBAR_WIDTH; - } - - @Override - public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float delta) { - if (usingScrollbar) { - resetSmoothScrolling(); - } - - smoothScrollAmount = Mth.lerp(Minecraft.getInstance().getDeltaFrameTime() * 0.5, smoothScrollAmount, getScrollAmount()); - returnSmoothAmount = true; - - graphics.enableScissor(this.getX(), this.getY(), this.getX() + this.getWidth(), this.getY() + this.getHeight()); - - super.renderWidget(graphics, mouseX, mouseY, delta); - - graphics.disableScissor(); - - returnSmoothAmount = false; - } - - @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) { - if (button == 0 && mouseX >= getScrollbarPosition() && mouseX < getScrollbarPosition() + SCROLLBAR_WIDTH) { - usingScrollbar = true; - } - - return super.mouseClicked(mouseX, mouseY, button); - } - - @Override - public boolean mouseReleased(double mouseX, double mouseY, int button) { - if (button == 0) { - usingScrollbar = false; - } - - return super.mouseReleased(mouseX, mouseY, button); - } - - public void updateDimensions(ScreenRectangle rectangle) { - this.setX(rectangle.left()); - this.setY(rectangle.top()); - this.setWidth(rectangle.width()); - this.setHeight(rectangle.height()); - } - - /** - * awful code to only use smooth scroll state when rendering, - * not other code that needs target scroll amount - */ - @Override - public double getScrollAmount() { - if (returnSmoothAmount && doSmoothScrolling) - return smoothScrollAmount; - - return super.getScrollAmount(); - } - - protected void resetSmoothScrolling() { - this.smoothScrollAmount = super.getScrollAmount(); - } - - @Nullable - @Override - protected E getEntryAtPosition(double x, double y) { - y += getScrollAmount(); - - if (x < this.getX() || x > this.getX() + this.getWidth()) - return null; - - int currentY = this.getY() - headerHeight + 4; - for (E entry : children()) { - if (y >= currentY && y <= currentY + entry.getItemHeight()) { - return entry; - } - - currentY += entry.getItemHeight(); - } - - return null; - } - - /* - below code is licensed from cloth-config under LGPL3 - modified to inherit vanilla's EntryListWidget and use yarn mappings - - code is responsible for having dynamic item heights - */ - - @Override - protected int getMaxPosition() { - return children().stream().map(E::getItemHeight).reduce(0, Integer::sum) + headerHeight; - } - - @Override - protected void centerScrollOn(E entry) { - double d = (this.height) / -2d; - for (int i = 0; i < this.children().indexOf(entry) && i < this.getItemCount(); i++) - d += children().get(i).getItemHeight(); - this.setScrollAmount(d); - } - - @Override - protected int getRowTop(int index) { - int integer = getY() + 4 - (int) this.getScrollAmount() + headerHeight; - for (int i = 0; i < children().size() && i < index; i++) - integer += children().get(i).getItemHeight(); - return integer; - } - - @Override - protected void ensureVisible(E entry) { - int i = this.getRowTop(this.children().indexOf(entry)); - int j = i - this.getY() - 4 - entry.getItemHeight(); - if (j < 0) { - this.setScrollAmount(this.getScrollAmount() + j); - } - - int k = this.getBottom() - i - entry.getItemHeight() * 2; - if (k < 0) { - this.setScrollAmount(this.getScrollAmount() - k); - } - } - - @Override - protected void renderListItems(GuiGraphics graphics, int mouseX, int mouseY, float delta) { - int left = this.getRowLeft(); - int right = this.getRowWidth(); - int count = this.getItemCount(); - - for(int i = 0; i < count; ++i) { - E entry = children().get(i); - int top = this.getRowTop(i); - int bottom = top + entry.getItemHeight(); - int entryHeight = entry.getItemHeight() - 4; - if (bottom >= this.getY() && top <= this.getY() + this.getHeight()) { - this.renderItem(graphics, mouseX, mouseY, delta, i, left, top, right, entryHeight); - } - } - } - - /* END cloth config code */ - - @Override - public void visitWidgets(Consumer<AbstractWidget> consumer) { - } - - public abstract static class Entry<E extends Entry<E>> extends ContainerObjectSelectionList.Entry<E> { - @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) { - for (GuiEventListener child : this.children()) { - if (child.mouseClicked(mouseX, mouseY, button)) { - if (button == InputConstants.MOUSE_BUTTON_LEFT) - this.setDragging(true); - return true; - } - } - - return false; - } - - @Override - public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { - if (isDragging() && button == InputConstants.MOUSE_BUTTON_LEFT) { - for (GuiEventListener child : this.children()) { - if (child.mouseDragged(mouseX, mouseY, button, deltaX, deltaY)) - return true; - } - } - return false; - } - - public int getItemHeight() { - return 22; - } - } -} diff --git a/common/src/main/java/dev/isxander/yacl3/gui/LowProfileButtonWidget.java b/common/src/main/java/dev/isxander/yacl3/gui/LowProfileButtonWidget.java deleted file mode 100644 index 3f5822f..0000000 --- a/common/src/main/java/dev/isxander/yacl3/gui/LowProfileButtonWidget.java +++ /dev/null @@ -1,28 +0,0 @@ -package dev.isxander.yacl3.gui; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.components.Button; -import net.minecraft.client.gui.components.Tooltip; -import net.minecraft.network.chat.Component; - -public class LowProfileButtonWidget extends Button { - public LowProfileButtonWidget(int x, int y, int width, int height, Component message, OnPress onPress) { - super(x, y, width, height, message, onPress, DEFAULT_NARRATION); - } - - public LowProfileButtonWidget(int x, int y, int width, int height, Component message, OnPress onPress, Tooltip tooltip) { - this(x, y, width, height, message, onPress); - setTooltip(tooltip); - } - - @Override - public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float deltaTicks) { - if (!isHoveredOrFocused() || !active) { - int j = this.active ? 0xFFFFFF : 0xA0A0A0; - this.renderString(graphics, Minecraft.getInstance().font, j); - } else { - super.renderWidget(graphics, mouseX, mouseY, deltaTicks); - } - } -} diff --git a/common/src/main/java/dev/isxander/yacl3/gui/OptionDescriptionWidget.java b/common/src/main/java/dev/isxander/yacl3/gui/OptionDescriptionWidget.java deleted file mode 100644 index 7aa3715..0000000 --- a/common/src/main/java/dev/isxander/yacl3/gui/OptionDescriptionWidget.java +++ /dev/null @@ -1,222 +0,0 @@ -package dev.isxander.yacl3.gui; - -import com.mojang.blaze3d.Blaze3D; -import com.mojang.blaze3d.platform.InputConstants; -import dev.isxander.yacl3.gui.image.ImageRenderer; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.ComponentPath; -import net.minecraft.client.gui.Font; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.components.AbstractWidget; -import net.minecraft.client.gui.narration.NarratedElementType; -import net.minecraft.client.gui.narration.NarrationElementOutput; -import net.minecraft.client.gui.navigation.FocusNavigationEvent; -import net.minecraft.client.gui.navigation.ScreenRectangle; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.Style; -import net.minecraft.util.FormattedCharSequence; -import net.minecraft.util.Mth; -import org.jetbrains.annotations.Nullable; - -import java.util.List; -import java.util.Optional; -import java.util.function.Supplier; - -public class OptionDescriptionWidget extends AbstractWidget { - private static final int AUTO_SCROLL_TIMER = 1500; - private static final float AUTO_SCROLL_SPEED = 1; // lines per second - - private @Nullable DescriptionWithName description; - private List<FormattedCharSequence> wrappedText; - - private static final Minecraft minecraft = Minecraft.getInstance(); - private static final Font font = minecraft.font; - - private Supplier<ScreenRectangle> dimensions; - - |
