From 845da2342c11348abbecaeed0eafb841dff8d1b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linnea=20Gr=C3=A4f?= Date: Mon, 4 Nov 2024 15:34:36 +0100 Subject: [PATCH] Fix overlapping clases in legacy code --- .github/workflows/build.yml | 2 +- .../editors/GuiOptionEditorDraggableList.java | 423 ------------------ ...bind.java => GuiOptionEditorKeybindL.java} | 4 +- ...lider.java => GuiOptionEditorSliderL.java} | 4 +- ...torText.java => GuiOptionEditorTextL.java} | 4 +- .../moulconfig/internal/ForgeMinecraft.kt | 28 +- 6 files changed, 16 insertions(+), 449 deletions(-) delete mode 100644 legacy/src/main/java/io/github/notenoughupdates/moulconfig/gui/editors/GuiOptionEditorDraggableList.java rename legacy/src/main/java/io/github/notenoughupdates/moulconfig/gui/editors/{GuiOptionEditorKeybind.java => GuiOptionEditorKeybindL.java} (97%) rename legacy/src/main/java/io/github/notenoughupdates/moulconfig/gui/editors/{GuiOptionEditorSlider.java => GuiOptionEditorSliderL.java} (97%) rename legacy/src/main/java/io/github/notenoughupdates/moulconfig/gui/editors/{GuiOptionEditorText.java => GuiOptionEditorTextL.java} (97%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2968a2adb..76910811e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,4 +15,4 @@ jobs: distribution: temurin java-version: 17 - name: Execute Gradle tests - run: ./gradlew test \ No newline at end of file + run: ./gradlew test assemble diff --git a/legacy/src/main/java/io/github/notenoughupdates/moulconfig/gui/editors/GuiOptionEditorDraggableList.java b/legacy/src/main/java/io/github/notenoughupdates/moulconfig/gui/editors/GuiOptionEditorDraggableList.java deleted file mode 100644 index fe0229fab..000000000 --- a/legacy/src/main/java/io/github/notenoughupdates/moulconfig/gui/editors/GuiOptionEditorDraggableList.java +++ /dev/null @@ -1,423 +0,0 @@ -/* - * Copyright (C) 2023 NotEnoughUpdates contributors - * - * This file is part of MoulConfig. - * - * MoulConfig 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. - * - * MoulConfig 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with MoulConfig. If not, see . - * - */ - -package io.github.notenoughupdates.moulconfig.gui.editors; - -import io.github.notenoughupdates.moulconfig.GuiTextures; -import io.github.notenoughupdates.moulconfig.common.IMinecraft; -import io.github.notenoughupdates.moulconfig.common.RenderContext; -import io.github.notenoughupdates.moulconfig.gui.GuiOptionEditor; -import io.github.notenoughupdates.moulconfig.gui.KeyboardEvent; -import io.github.notenoughupdates.moulconfig.gui.MouseEvent; -import io.github.notenoughupdates.moulconfig.internal.LerpUtils; -import io.github.notenoughupdates.moulconfig.internal.RenderUtils; -import io.github.notenoughupdates.moulconfig.internal.TextRenderUtils; -import io.github.notenoughupdates.moulconfig.internal.TypeUtils; -import io.github.notenoughupdates.moulconfig.internal.Warnings; -import io.github.notenoughupdates.moulconfig.processor.ProcessedOption; -import kotlin.Pair; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.util.EnumChatFormatting; -import org.lwjgl.input.Keyboard; -import org.lwjgl.input.Mouse; -import org.lwjgl.opengl.GL11; - -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.util.*; - -public class GuiOptionEditorDraggableList extends GuiOptionEditor { - private Map exampleText = new HashMap<>(); - private boolean enableDeleting; - private List activeText; - private final boolean requireNonEmpty; - private Object currentDragging = null; - private int dragStartIndex = -1; - - private Pair lastMousePosition = null; - - private long trashHoverTime = -1; - - private int dragOffsetX = -1; - private int dragOffsetY = -1; - private boolean dropdownOpen = false; - private Enum[] enumConstants; - private String exampleTextConcat; - - public GuiOptionEditorDraggableList( - ProcessedOption option, - String[] exampleText, - boolean enableDeleting - ) { - this(option, exampleText, enableDeleting, false); - } - - public GuiOptionEditorDraggableList( - ProcessedOption option, - String[] exampleText, - boolean enableDeleting, - boolean requireNonEmpty - ) { - super(option); - - this.enableDeleting = enableDeleting; - this.activeText = (List) option.get(); - this.requireNonEmpty = requireNonEmpty; - - Type elementType = TypeUtils.resolveRawType(((ParameterizedType) option.getType()).getActualTypeArguments()[0]); - - if (Enum.class.isAssignableFrom((Class) elementType)) { - Class> enumType = (Class>) ((ParameterizedType) option.getType()).getActualTypeArguments()[0]; - enumConstants = enumType.getEnumConstants(); - for (int i = 0; i < enumConstants.length; i++) { - this.exampleText.put(enumConstants[i], enumConstants[i].toString()); - } - } else { - for (int i = 0; i < exampleText.length; i++) { - this.exampleText.put(i, exampleText[i]); - } - } - } - - private void saveChanges() { - option.explicitNotifyChange(); - } - - private String getExampleText(Object forObject) { - String str = exampleText.get(forObject); - if (str == null) { - str = ""; - Warnings.warnOnce("Could not find draggable list object for " + forObject + " on option " + option.getCodeLocation(), forObject, option); - } - return str; - } - - @Override - public int getHeight() { - int height = super.getHeight() + 13; - - for (Object object : activeText) { - String str = getExampleText(object); - height += 10 * str.split("\n").length; - } - - return height; - } - - public boolean canDeleteRightNow() { - return enableDeleting && (activeText.size() > 1 || !requireNonEmpty); - } - - @Override - public void render(RenderContext renderContext, int x, int y, int width) { - super.render(renderContext, x, y, width); - int height = getHeight(); - - GlStateManager.color(1, 1, 1, 1); - IMinecraft.instance.bindTexture(GuiTextures.BUTTON); - RenderUtils.drawTexturedRect(x + width / 6 - 24, y + 45 - 7 - 14, 48, 16); - - TextRenderUtils.drawStringCenteredScaledMaxWidth("Add", Minecraft.getMinecraft().fontRendererObj, - x + width / 6, y + 45 - 7 - 6, - false, 44, 0xFF303030 - ); - - long currentTime = System.currentTimeMillis(); - if (trashHoverTime < 0) { - float greenBlue = LerpUtils.clampZeroOne((currentTime + trashHoverTime) / 250f); - GlStateManager.color(1, greenBlue, greenBlue, 1); - } else { - float greenBlue = LerpUtils.clampZeroOne((250 + trashHoverTime - currentTime) / 250f); - GlStateManager.color(1, greenBlue, greenBlue, 1); - } - - if (canDeleteRightNow()) { - int deleteX = x + width / 6 + 27; - int deleteY = y + 45 - 7 - 13; - renderContext.bindTexture(GuiTextures.DELETE); - RenderUtils.drawTexturedRect(deleteX, deleteY, 11, 14, GL11.GL_NEAREST); - // TODO: make use of the mouseX and mouseY from the context when switching this to a proper multi-version component - if (lastMousePosition != null && currentDragging == null && - lastMousePosition.getFirst() >= deleteX && lastMousePosition.getFirst() < deleteX + 11 && - lastMousePosition.getSecond() >= deleteY && lastMousePosition.getSecond() < deleteY + 14) { - renderContext.scheduleDrawTooltip(Collections.singletonList( - "§cDelete Item" - )); - } - } - - Gui.drawRect(x + 5, y + 45, x + width - 5, y + height - 5, 0xffdddddd); - Gui.drawRect(x + 6, y + 46, x + width - 6, y + height - 6, 0xff000000); - - int i = 0; - int yOff = 0; - for (Object indexObject : activeText) { - String str = getExampleText(indexObject); - - String[] multilines = str.split("\n"); - - int ySize = multilines.length * 10; - - if (i++ != dragStartIndex) { - for (int multilineIndex = 0; multilineIndex < multilines.length; multilineIndex++) { - String line = multilines[multilineIndex]; - TextRenderUtils.drawStringScaledMaxWidth(line + EnumChatFormatting.RESET, Minecraft.getMinecraft().fontRendererObj, - x + 20, y + 50 + yOff + multilineIndex * 10, true, width - 20, 0xffffffff - ); - } - Minecraft.getMinecraft().fontRendererObj.drawString( - "≡", - x + 10, - y + 49 + yOff + ySize / 2 - 4, - 0xffffff, - true - ); - } - - yOff += ySize; - } - } - - @Override - public void renderOverlay(int x, int y, int width) { - super.renderOverlay(x, y, width); - if (dropdownOpen) { - List remaining = new ArrayList<>(exampleText.keySet()); - remaining.removeAll(activeText); - - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - int dropdownWidth = Math.min(width / 2 - 10, 150); - int left = dragOffsetX; - int top = dragOffsetY; - - int dropdownHeight = -1 + 12 * remaining.size(); - - int main = 0xff202026; - int outline = 0xff404046; - Gui.drawRect(left, top, left + 1, top + dropdownHeight, outline); //Left - Gui.drawRect(left + 1, top, left + dropdownWidth, top + 1, outline); //Top - Gui.drawRect(left + dropdownWidth - 1, top + 1, left + dropdownWidth, top + dropdownHeight, outline); //Right - Gui.drawRect( - left + 1, - top + dropdownHeight - 1, - left + dropdownWidth - 1, - top + dropdownHeight, - outline - ); //Bottom - Gui.drawRect(left + 1, top + 1, left + dropdownWidth - 1, top + dropdownHeight - 1, main); //Middle - - int dropdownY = -1; - for (Object indexObject : remaining) { - String str = getExampleText(indexObject); - if (str.isEmpty()) { - str = ""; - } - TextRenderUtils.drawStringScaledMaxWidth(str.replaceAll("(\n.*)+", " ..."), - fr, left + 3, top + 3 + dropdownY, false, dropdownWidth - 6, 0xffa0a0a0 - ); - dropdownY += 12; - } - } else if (currentDragging != null) { - int opacity = 0x80; - long currentTime = System.currentTimeMillis(); - if (trashHoverTime < 0) { - float greenBlue = LerpUtils.clampZeroOne((currentTime + trashHoverTime) / 250f); - opacity = (int) (opacity * greenBlue); - } else { - float greenBlue = LerpUtils.clampZeroOne((250 + trashHoverTime - currentTime) / 250f); - opacity = (int) (opacity * greenBlue); - } - - if (opacity < 20) return; - - ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - int mouseX = Mouse.getX() * scaledResolution.getScaledWidth() / Minecraft.getMinecraft().displayWidth; - int mouseY = scaledResolution.getScaledHeight() - - Mouse.getY() * scaledResolution.getScaledHeight() / Minecraft.getMinecraft().displayHeight - 1; - - String str = getExampleText(currentDragging); - String[] multilines = str.split("\n"); - - GlStateManager.enableBlend(); - for (int multilineIndex = 0; multilineIndex < multilines.length; multilineIndex++) { - String line = multilines[multilineIndex]; - TextRenderUtils.drawStringScaledMaxWidth( - line + EnumChatFormatting.RESET, - Minecraft.getMinecraft().fontRendererObj, - dragOffsetX + mouseX + 10, - dragOffsetY + mouseY + multilineIndex * 10, - true, - width - 20, - 0xffffff | (opacity << 24) - ); - } - - int ySize = multilines.length * 10; - - Minecraft.getMinecraft().fontRendererObj.drawString("\u2261", - dragOffsetX + mouseX, - dragOffsetY - 1 + mouseY + ySize / 2 - 4, 0xffffff, true - ); - } - } - - @Override - public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { - lastMousePosition = new Pair<>(mouseX, mouseY); - if (!Mouse.getEventButtonState() && !dropdownOpen && - dragStartIndex >= 0 && Mouse.getEventButton() == 0 && - mouseX >= x + width / 6 + 27 - 3 && mouseX <= x + width / 6 + 27 + 11 + 3 && - mouseY >= y + 45 - 7 - 13 - 3 && mouseY <= y + 45 - 7 - 13 + 14 + 3) { - if (canDeleteRightNow()) { - activeText.remove(dragStartIndex); - saveChanges(); - } - currentDragging = null; - dragStartIndex = -1; - return false; - } - - if (!Mouse.isButtonDown(0) || dropdownOpen) { - currentDragging = null; - dragStartIndex = -1; - if (trashHoverTime > 0 && canDeleteRightNow()) trashHoverTime = -System.currentTimeMillis(); - } else if (currentDragging != null && - mouseX >= x + width / 6 + 27 - 3 && mouseX <= x + width / 6 + 27 + 11 + 3 && - mouseY >= y + 45 - 7 - 13 - 3 && mouseY <= y + 45 - 7 - 13 + 14 + 3) { - if (trashHoverTime < 0 && canDeleteRightNow()) trashHoverTime = System.currentTimeMillis(); - } else if (!canDeleteRightNow()){ - trashHoverTime = Long.MAX_VALUE; - } else if (trashHoverTime > 0) { - trashHoverTime = -System.currentTimeMillis(); - } - - if (Mouse.getEventButtonState()) { - int height = getHeight(); - - if (dropdownOpen) { - List remaining = new ArrayList<>(exampleText.keySet()); - remaining.removeAll(activeText); - - int dropdownWidth = Math.min(width / 2 - 10, 150); - int left = dragOffsetX; - int top = dragOffsetY; - - int dropdownHeight = -1 + 12 * remaining.size(); - - if (mouseX > left && mouseX < left + dropdownWidth && - mouseY > top && mouseY < top + dropdownHeight) { - int dropdownY = -1; - for (Object objectIndex : remaining) { - if (mouseY < top + dropdownY + 12) { - activeText.add(0, objectIndex); - saveChanges(); - if (remaining.size() == 1) dropdownOpen = false; - return true; - } - - dropdownY += 12; - } - } - - dropdownOpen = false; - return true; - } - - if (activeText.size() < exampleText.size() && - mouseX > x + width / 6 - 24 && mouseX < x + width / 6 + 24 && - mouseY > y + 45 - 7 - 14 && mouseY < y + 45 - 7 + 2) { - dropdownOpen = true; - dragOffsetX = mouseX; - dragOffsetY = mouseY; - return true; - } - - if (Mouse.getEventButton() == 0 && - mouseX > x + 5 && mouseX < x + width - 5 && - mouseY > y + 45 && mouseY < y + height - 6) { - int yOff = 0; - int i = 0; - for (Object objectIndex : activeText) { - String str = getExampleText(objectIndex); - int ySize = 10 * str.split("\n").length; - if (mouseY < y + 50 + yOff + ySize) { - dragOffsetX = x + 10 - mouseX; - dragOffsetY = y + 50 + yOff - mouseY; - - currentDragging = objectIndex; - dragStartIndex = i; - break; - } - yOff += ySize; - i++; - } - } - } else if (Mouse.getEventButton() == -1 && currentDragging != null) { - int yOff = 0; - int i = 0; - for (Object objectIndex : activeText) { - if (dragOffsetY + mouseY + 4 < y + 50 + yOff + 10) { - activeText.remove(dragStartIndex); - activeText.add(i, currentDragging); - saveChanges(); - dragStartIndex = i; - break; - } - String str = getExampleText(objectIndex); - yOff += 10 * str.split("\n").length; - i++; - } - } - - return false; - } - - @Override - public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY, MouseEvent mouseEvent) { - if (mouseEvent instanceof MouseEvent.Scroll) { - this.dropdownOpen = false; - return false; - } - return super.mouseInput(x, y, width, mouseX, mouseY, mouseEvent); - } - - @Override - public boolean fulfillsSearch(String word) { - if (exampleTextConcat == null) { - exampleTextConcat = String.join("", exampleText.values()).toLowerCase(Locale.ROOT); - } - return super.fulfillsSearch(word) || exampleTextConcat.contains(word); - } - - @Override - public boolean keyboardInput(KeyboardEvent event) { - if (event instanceof KeyboardEvent.KeyPressed) { - int key = ((KeyboardEvent.KeyPressed) event).getKeycode(); - if (key == Keyboard.KEY_UP || key == Keyboard.KEY_DOWN) { - dropdownOpen = false; - } - } - return super.keyboardInput(event); - } -} diff --git a/legacy/src/main/java/io/github/notenoughupdates/moulconfig/gui/editors/GuiOptionEditorKeybind.java b/legacy/src/main/java/io/github/notenoughupdates/moulconfig/gui/editors/GuiOptionEditorKeybindL.java similarity index 97% rename from legacy/src/main/java/io/github/notenoughupdates/moulconfig/gui/editors/GuiOptionEditorKeybind.java rename to legacy/src/main/java/io/github/notenoughupdates/moulconfig/gui/editors/GuiOptionEditorKeybindL.java index e35090058..22d2a951a 100644 --- a/legacy/src/main/java/io/github/notenoughupdates/moulconfig/gui/editors/GuiOptionEditorKeybind.java +++ b/legacy/src/main/java/io/github/notenoughupdates/moulconfig/gui/editors/GuiOptionEditorKeybindL.java @@ -37,13 +37,13 @@ import java.util.Collections; -public class GuiOptionEditorKeybind extends GuiOptionEditor { +public class GuiOptionEditorKeybindL extends GuiOptionEditor { private final int defaultKeyCode; private boolean editingKeycode; private Pair lastMousePosition = null; - public GuiOptionEditorKeybind(ProcessedOption option, int defaultKeyCode) { + public GuiOptionEditorKeybindL(ProcessedOption option, int defaultKeyCode) { super(option); this.defaultKeyCode = defaultKeyCode; } diff --git a/legacy/src/main/java/io/github/notenoughupdates/moulconfig/gui/editors/GuiOptionEditorSlider.java b/legacy/src/main/java/io/github/notenoughupdates/moulconfig/gui/editors/GuiOptionEditorSliderL.java similarity index 97% rename from legacy/src/main/java/io/github/notenoughupdates/moulconfig/gui/editors/GuiOptionEditorSlider.java rename to legacy/src/main/java/io/github/notenoughupdates/moulconfig/gui/editors/GuiOptionEditorSliderL.java index d12408729..8bad04af3 100644 --- a/legacy/src/main/java/io/github/notenoughupdates/moulconfig/gui/editors/GuiOptionEditorSlider.java +++ b/legacy/src/main/java/io/github/notenoughupdates/moulconfig/gui/editors/GuiOptionEditorSliderL.java @@ -48,11 +48,11 @@ import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; -public class GuiOptionEditorSlider extends GuiOptionEditor { +public class GuiOptionEditorSliderL extends GuiOptionEditor { private final GuiElementSlider slider; private final GuiElementTextField textField; - public GuiOptionEditorSlider(ProcessedOption option, float minValue, float maxValue, float minStep) { + public GuiOptionEditorSliderL(ProcessedOption option, float minValue, float maxValue, float minStep) { super(option); if (minStep < 0) minStep = 0.01f; diff --git a/legacy/src/main/java/io/github/notenoughupdates/moulconfig/gui/editors/GuiOptionEditorText.java b/legacy/src/main/java/io/github/notenoughupdates/moulconfig/gui/editors/GuiOptionEditorTextL.java similarity index 97% rename from legacy/src/main/java/io/github/notenoughupdates/moulconfig/gui/editors/GuiOptionEditorText.java rename to legacy/src/main/java/io/github/notenoughupdates/moulconfig/gui/editors/GuiOptionEditorTextL.java index 4f9b06f17..e615315f2 100644 --- a/legacy/src/main/java/io/github/notenoughupdates/moulconfig/gui/editors/GuiOptionEditorText.java +++ b/legacy/src/main/java/io/github/notenoughupdates/moulconfig/gui/editors/GuiOptionEditorTextL.java @@ -29,10 +29,10 @@ import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; -public class GuiOptionEditorText extends GuiOptionEditor { +public class GuiOptionEditorTextL extends GuiOptionEditor { private final GuiElementTextField textField; - public GuiOptionEditorText(ProcessedOption option) { + public GuiOptionEditorTextL(ProcessedOption option) { super(option); textField = new GuiElementTextField((String) option.get(), 0); diff --git a/legacy/src/main/java/io/github/notenoughupdates/moulconfig/internal/ForgeMinecraft.kt b/legacy/src/main/java/io/github/notenoughupdates/moulconfig/internal/ForgeMinecraft.kt index 8a595c288..cd82dc7a7 100644 --- a/legacy/src/main/java/io/github/notenoughupdates/moulconfig/internal/ForgeMinecraft.kt +++ b/legacy/src/main/java/io/github/notenoughupdates/moulconfig/internal/ForgeMinecraft.kt @@ -15,9 +15,9 @@ import io.github.notenoughupdates.moulconfig.gui.GuiContext import io.github.notenoughupdates.moulconfig.gui.GuiElement import io.github.notenoughupdates.moulconfig.gui.GuiScreenElementWrapper import io.github.notenoughupdates.moulconfig.gui.editors.GuiOptionEditorDraggableList -import io.github.notenoughupdates.moulconfig.gui.editors.GuiOptionEditorKeybind -import io.github.notenoughupdates.moulconfig.gui.editors.GuiOptionEditorSlider -import io.github.notenoughupdates.moulconfig.gui.editors.GuiOptionEditorText +import io.github.notenoughupdates.moulconfig.gui.editors.GuiOptionEditorKeybindL +import io.github.notenoughupdates.moulconfig.gui.editors.GuiOptionEditorSliderL +import io.github.notenoughupdates.moulconfig.gui.editors.GuiOptionEditorTextL import io.github.notenoughupdates.moulconfig.processor.MoulConfigProcessor import net.minecraft.client.Minecraft import net.minecraft.client.gui.GuiScreen @@ -67,32 +67,22 @@ class ForgeMinecraft : IMinecraft { processor.registerConfigEditor( ConfigEditorKeybind::class.java ) { processedOption, keybind: ConfigEditorKeybind -> - GuiOptionEditorKeybind( - processedOption, - keybind.defaultKey - ) - } - processor.registerConfigEditor( - ConfigEditorDraggableList::class.java - ) { processedOption, configEditorDraggableList: ConfigEditorDraggableList -> - GuiOptionEditorDraggableList( - processedOption, - configEditorDraggableList.exampleText, - configEditorDraggableList.allowDeleting, - configEditorDraggableList.requireNonEmpty - ) + GuiOptionEditorKeybindL( + processedOption, + keybind.defaultKey + ) } processor.registerConfigEditor( ConfigEditorText::class.java ) { processedOption, configEditorText: ConfigEditorText? -> - GuiOptionEditorText( + GuiOptionEditorTextL( processedOption ) } processor.registerConfigEditor( ConfigEditorSlider::class.java ) { processedOption, configEditorSlider: ConfigEditorSlider -> - GuiOptionEditorSlider( + GuiOptionEditorSliderL( processedOption, configEditorSlider.minValue, configEditorSlider.maxValue,