diff options
author | Lorenz <lo.scherf@gmail.com> | 2022-09-08 18:11:29 +0200 |
---|---|---|
committer | Lorenz <lo.scherf@gmail.com> | 2022-09-08 18:11:29 +0200 |
commit | 133f6a9bef6317bb9e6c2b54a7b17e0907c30f6a (patch) | |
tree | 55a4d8c73484a71657f9ea1e6dfa8f08fbbad43f /src/main/java/at/hannibal2/skyhanni/config | |
parent | f0407686615a430f19c57cb4ffe12ebd6235cc2b (diff) | |
download | skyhanni-133f6a9bef6317bb9e6c2b54a7b17e0907c30f6a.tar.gz skyhanni-133f6a9bef6317bb9e6c2b54a7b17e0907c30f6a.tar.bz2 skyhanni-133f6a9bef6317bb9e6c2b54a7b17e0907c30f6a.zip |
updated config structure from neu
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/config')
116 files changed, 6855 insertions, 4495 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/config/ConfigEditor.java b/src/main/java/at/hannibal2/skyhanni/config/ConfigEditor.java index 39fd02780..407a0bf82 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/config/ConfigEditor.java +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigEditor.java @@ -1,22 +1,37 @@ -package at.hannibal2.skyhanni.config.gui.config; +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config; import at.hannibal2.skyhanni.SkyHanniMod; -import at.hannibal2.skyhanni.config.Features; -import at.hannibal2.skyhanni.config.gui.GuiTextures; -import at.hannibal2.skyhanni.config.gui.core.GlScissorStack; -import at.hannibal2.skyhanni.config.gui.core.GuiElement; -import at.hannibal2.skyhanni.config.gui.core.config.gui.GuiOptionEditor; -import at.hannibal2.skyhanni.config.gui.core.config.gui.GuiOptionEditorAccordion; -import at.hannibal2.skyhanni.config.gui.core.config.struct.ConfigProcessor; -import at.hannibal2.skyhanni.config.gui.core.util.lerp.LerpUtils; -import at.hannibal2.skyhanni.config.gui.core.util.lerp.LerpingInteger; -import at.hannibal2.skyhanni.config.gui.core.util.render.RenderUtils; -import at.hannibal2.skyhanni.config.gui.core.util.render.TextRenderUtils; +import at.hannibal2.skyhanni.config.core.GlScissorStack; +import at.hannibal2.skyhanni.config.core.GuiElement; +import at.hannibal2.skyhanni.config.core.GuiElementTextField; +import at.hannibal2.skyhanni.config.core.config.gui.GuiOptionEditor; +import at.hannibal2.skyhanni.config.core.config.gui.GuiOptionEditorAccordion; +import at.hannibal2.skyhanni.config.core.config.struct.ConfigProcessor; +import at.hannibal2.skyhanni.config.core.util.lerp.LerpUtils; +import at.hannibal2.skyhanni.config.core.util.lerp.LerpingInteger; +import at.hannibal2.skyhanni.config.core.util.render.GuiRenderUtils; +import at.hannibal2.skyhanni.config.core.util.render.TextRenderUtils; +import at.hannibal2.skyhanni.utils.StringUtils; import com.google.common.collect.Lists; -import java.awt.*; -import java.net.URI; -import java.util.*; -import java.util.List; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; @@ -24,24 +39,45 @@ import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ResourceLocation; +import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; -public class ConfigEditor extends GuiElement { +import java.awt.*; +import java.net.URI; +import java.util.List; +import java.util.*; - private static final ResourceLocation[] socialsIco = new ResourceLocation[] { GuiTextures.DISCORD }; - private static final String[] socialsLink = new String[] { "https://discord.gg/8DXVN4BJz3" }; +import static at.hannibal2.skyhanni.config.GuiTextures.DISCORD; +import static at.hannibal2.skyhanni.config.GuiTextures.GITHUB; +public class ConfigEditor extends GuiElement { + private static final ResourceLocation[] socialsIco = new ResourceLocation[]{ + DISCORD, GITHUB + }; + private static final String[] socialsLink = new String[]{ + "https://discord.gg/8DXVN4BJz3", + "https://github.com/hannibal00212/SkyHanni" + }; + private static final ResourceLocation SEARCH_ICON = new ResourceLocation("notenoughupdates:core/search.png"); + public static ConfigEditor editor = new ConfigEditor(SkyHanniMod.feature); private final long openedMillis; - - private String selectedCategory = null; - private final LerpingInteger optionsScroll = new LerpingInteger(0, 150); private final LerpingInteger categoryScroll = new LerpingInteger(0, 150); - private final LinkedHashMap<String, ConfigProcessor.ProcessedCategory> processedConfig; private final TreeMap<String, Set<ConfigProcessor.ProcessedOption>> searchOptionMap = new TreeMap<>(); - private final HashMap<ConfigProcessor.ProcessedOption, ConfigProcessor.ProcessedCategory> categoryForOption = new HashMap<>(); + private final HashMap<ConfigProcessor.ProcessedOption, ConfigProcessor.ProcessedCategory> categoryForOption = + new HashMap<>(); + private final LerpingInteger minimumSearchSize = new LerpingInteger(0, 150); + private final GuiElementTextField searchField = new GuiElementTextField("", 0, 20, 0); + private String selectedCategory = null; + private Set<ConfigProcessor.ProcessedCategory> searchedCategories = null; + private Map<ConfigProcessor.ProcessedCategory, Set<Integer>> searchedAccordions = null; + private Set<ConfigProcessor.ProcessedOption> searchedOptions = null; + private float optionsBarStart; + private float optionsBarend; + private int lastMouseX = 0; + private int keyboardScrollXCutoff = 0; public ConfigEditor(Features config) { this(config, null); @@ -54,6 +90,12 @@ public class ConfigEditor extends GuiElement { for (ConfigProcessor.ProcessedCategory category : processedConfig.values()) { for (ConfigProcessor.ProcessedOption option : category.options.values()) { categoryForOption.put(option, category); + + String combined = category.name + " " + category.desc + " " + option.name + " " + option.desc; + combined = combined.replaceAll("[^a-zA-Z_ ]", "").toLowerCase(); + for (String word : combined.split("[ _]")) { + searchOptionMap.computeIfAbsent(word, k -> new HashSet<>()).add(option); + } } } @@ -81,32 +123,104 @@ public class ConfigEditor extends GuiElement { } } } + + editor = this; } private LinkedHashMap<String, ConfigProcessor.ProcessedCategory> getCurrentConfigEditing() { - return new LinkedHashMap<>(processedConfig); + LinkedHashMap<String, ConfigProcessor.ProcessedCategory> newMap = new LinkedHashMap<>(processedConfig); + if (searchedCategories != null) newMap.values().retainAll(searchedCategories); + return newMap; } private LinkedHashMap<String, ConfigProcessor.ProcessedOption> getOptionsInCategory(ConfigProcessor.ProcessedCategory cat) { - return new LinkedHashMap<>(cat.options); + LinkedHashMap<String, ConfigProcessor.ProcessedOption> newMap = new LinkedHashMap<>(cat.options); + + if (searchedOptions != null) { + Set<ConfigProcessor.ProcessedOption> retain = new HashSet<>(); + retain.addAll(searchedOptions); + + if (searchedAccordions != null) { + Set<Integer> visibleAccordions = searchedAccordions.get(cat); + + if (visibleAccordions != null && !visibleAccordions.isEmpty()) { + for (ConfigProcessor.ProcessedOption option : newMap.values()) { + if (option.editor instanceof GuiOptionEditorAccordion) { + int accordionId = ((GuiOptionEditorAccordion) option.editor).getAccordionId(); + + if (visibleAccordions.contains(accordionId)) { + retain.add(option); + } + } + } + } + + } + + newMap.values().retainAll(retain); + } + return newMap; } public String getSelectedCategory() { return selectedCategory; } + private void setSelectedCategory(String category) { + selectedCategory = category; + optionsScroll.setValue(0); + } + public String getSelectedCategoryName() { return processedConfig.get(selectedCategory).name; } - private void setSelectedCategory(String category) { - selectedCategory = category; - optionsScroll.setValue(0); + public void search() { + String search = searchField.getText().trim().replaceAll("[^a-zA-Z_ ]", "").toLowerCase(); + searchedCategories = null; + searchedOptions = null; + searchedAccordions = null; + + if (!search.isEmpty()) { + searchedCategories = new HashSet<>(); + searchedAccordions = new HashMap<>(); + + for (String word : search.split(" ")) { + if (word.trim().isEmpty()) continue; + + Set<ConfigProcessor.ProcessedOption> options = new HashSet<>(); + + Map<String, Set<ConfigProcessor.ProcessedOption>> map = StringUtils.INSTANCE.subMapWithKeysThatAreSuffixes(word, searchOptionMap); + + map.values().forEach(options::addAll); + + if (!options.isEmpty()) { + if (searchedOptions == null) { + searchedOptions = new HashSet<>(options); + } else { + searchedOptions.retainAll(options); + } + } + } + + if (searchedOptions == null) { + searchedOptions = new HashSet<>(); + } else { + for (ConfigProcessor.ProcessedOption option : searchedOptions) { + ConfigProcessor.ProcessedCategory cat = categoryForOption.get(option); + if (cat == null) continue; + + searchedCategories.add(cat); + searchedAccordions.computeIfAbsent(cat, k -> new HashSet<>()).add(option.accordionId); + } + } + } } public void render() { optionsScroll.tick(); categoryScroll.tick(); + handleKeyboardPresses(); List<String> tooltipToDisplay = null; @@ -120,7 +234,10 @@ public class ConfigEditor extends GuiElement { int mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; float opacityFactor = LerpUtils.sigmoidZeroOne(delta / 500f); - RenderUtils.drawGradientRect(0, 0, 0, width, height, (int) (0x80 * opacityFactor) << 24 | 0x101010, (int) (0x90 * opacityFactor) << 24 | 0x101010); + GuiRenderUtils.drawGradientRect(0, 0, 0, width, height, + (int) (0x80 * opacityFactor) << 24 | 0x101010, + (int) (0x90 * opacityFactor) << 24 | 0x101010 + ); int xSize = Math.min(scaledResolution.getScaledWidth() - 100 / scaledResolution.getScaleFactor(), 500); int ySize = Math.min(scaledResolution.getScaledHeight() - 100 / scaledResolution.getScaleFactor(), 400); @@ -138,16 +255,25 @@ public class ConfigEditor extends GuiElement { } else if (delta < 300) { openingYSize = 5 + (int) (delta - 150) * (ySize - 5) / 150; } - RenderUtils.drawFloatingRectDark((scaledResolution.getScaledWidth() - openingXSize) / 2, (scaledResolution.getScaledHeight() - openingYSize) / 2, openingXSize, openingYSize); + GuiRenderUtils.drawFloatingRectDark( + (scaledResolution.getScaledWidth() - openingXSize) / 2, + (scaledResolution.getScaledHeight() - openingYSize) / 2, + openingXSize, openingYSize + ); GlScissorStack.clear(); - GlScissorStack.push((scaledResolution.getScaledWidth() - openingXSize) / 2, (scaledResolution.getScaledHeight() - openingYSize) / 2, (scaledResolution.getScaledWidth() + openingXSize) / 2, (scaledResolution.getScaledHeight() + openingYSize) / 2, scaledResolution); + GlScissorStack.push((scaledResolution.getScaledWidth() - openingXSize) / 2, + (scaledResolution.getScaledHeight() - openingYSize) / 2, + (scaledResolution.getScaledWidth() + openingXSize) / 2, + (scaledResolution.getScaledHeight() + openingYSize) / 2, scaledResolution + ); - RenderUtils.drawFloatingRectDark(x + 5, y + 5, xSize - 10, 20, false); + GuiRenderUtils.drawFloatingRectDark(x + 5, y + 5, xSize - 10, 20, false); FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; TextRenderUtils.drawStringCenteredScaledMaxWidth("SkyHanni " + SkyHanniMod.VERSION + " by " + EnumChatFormatting.RED + "hannibal2" + EnumChatFormatting.RESET + ", config by " + EnumChatFormatting.DARK_PURPLE + "Moulberry", fr, x + xSize / 2f, y + 15, false, 200, 0xa0a0a0); - - RenderUtils.drawFloatingRectDark(x + 4, y + 49 - 20, 140, ySize - 54 + 20, false); + GuiRenderUtils.drawFloatingRectDark(x + 4, y + 49 - 20, + 140, ySize - 54 + 20, false + ); int innerPadding = 20 / adjScaleFactor; int innerLeft = x + 4 + innerPadding; @@ -160,7 +286,9 @@ public class ConfigEditor extends GuiElement { Gui.drawRect(innerLeft + 1, innerBottom - 1, innerRight - 1, innerBottom, 0xff28282E); //Bottom Gui.drawRect(innerLeft + 1, innerTop + 1, innerRight - 1, innerBottom - 1, 0x6008080E); //Middle - GlScissorStack.push(0, innerTop + 1, scaledResolution.getScaledWidth(), innerBottom - 1, scaledResolution); + GlScissorStack.push(0, innerTop + 1, scaledResolution.getScaledWidth(), + innerBottom - 1, scaledResolution + ); float catBarSize = 1; int catY = -categoryScroll.getValue(); @@ -177,10 +305,13 @@ public class ConfigEditor extends GuiElement { } else { catName = EnumChatFormatting.GRAY + catName; } - TextRenderUtils.drawStringCenteredScaledMaxWidth(catName, fr, x + 75, y + 70 + catY, false, 100, -1); + TextRenderUtils.drawStringCenteredScaledMaxWidth(catName, + fr, x + 75, y + 70 + catY, false, 100, -1 + ); catY += 15; if (catY > 0) { - catBarSize = LerpUtils.clampZeroOne((float) (innerBottom - innerTop - 2) / (catY + 5 + categoryScroll.getValue())); + catBarSize = + LerpUtils.clampZeroOne((float) (innerBottom - innerTop - 2) / (catY + 5 + categoryScroll.getValue())); } } @@ -190,33 +321,64 @@ public class ConfigEditor extends GuiElement { catBarEnd = 1; if (categoryScroll.getTarget() / (float) (catY + categoryScroll.getValue()) + catBarSize < 1) { int target = optionsScroll.getTarget(); - categoryScroll.setValue((int) Math.ceil((catY + 5 + categoryScroll.getValue()) - catBarSize * (catY + 5 + categoryScroll.getValue()))); + categoryScroll.setValue((int) Math.ceil( + (catY + 5 + categoryScroll.getValue()) - catBarSize * (catY + 5 + categoryScroll.getValue()))); categoryScroll.setTarget(target); } else { - categoryScroll.setValue((int) Math.ceil((catY + 5 + categoryScroll.getValue()) - catBarSize * (catY + 5 + categoryScroll.getValue()))); + categoryScroll.setValue((int) Math.ceil( + (catY + 5 + categoryScroll.getValue()) - catBarSize * (catY + 5 + categoryScroll.getValue()))); } } int catDist = innerBottom - innerTop - 12; Gui.drawRect(innerLeft + 2, innerTop + 5, innerLeft + 7, innerBottom - 5, 0xff101010); - Gui.drawRect(innerLeft + 3, innerTop + 6 + (int) (catDist * catBarStart), innerLeft + 6, innerTop + 6 + (int) (catDist * catBarEnd), 0xff303030); + Gui.drawRect(innerLeft + 3, innerTop + 6 + (int) (catDist * catBarStart), innerLeft + 6, + innerTop + 6 + (int) (catDist * catBarEnd), 0xff303030 + ); GlScissorStack.pop(scaledResolution); - TextRenderUtils.drawStringCenteredScaledMaxWidth("Categories", fr, x + 75, y + 44, false, 120, 0xa368ef); + TextRenderUtils.drawStringCenteredScaledMaxWidth("Categories", + fr, x + 75, y + 44, false, 120, 0xa368ef + ); - RenderUtils.drawFloatingRectDark(x + 149, y + 29, xSize - 154, ySize - 34, false); + GuiRenderUtils.drawFloatingRectDark(x + 149, y + 29, xSize - 154, ySize - 34, false); innerLeft = x + 149 + innerPadding; innerRight = x + xSize - 5 - innerPadding; innerBottom = y + ySize - 5 - innerPadding; + Minecraft.getMinecraft().getTextureManager().bindTexture(SEARCH_ICON); GlStateManager.color(1, 1, 1, 1); + GuiRenderUtils.drawTexturedRect(innerRight - 20, innerTop - (20 + innerPadding) / 2 - 9, 18, 18, GL11.GL_NEAREST); + + minimumSearchSize.tick(); + boolean shouldShow = !searchField.getText().trim().isEmpty() || searchField.getFocus(); + if (shouldShow && minimumSearchSize.getTarget() < 30) { + minimumSearchSize.setTarget(30); + minimumSearchSize.resetTimer(); + } else if (!shouldShow && minimumSearchSize.getTarget() > 0) { + minimumSearchSize.setTarget(0); + minimumSearchSize.resetTimer(); + } + int rightStuffLen = 20; + if (minimumSearchSize.getValue() > 1) { + int strLen = Minecraft.getMinecraft().fontRendererObj.getStringWidth(searchField.getText()) + 10; + if (!shouldShow) strLen = 0; + + int len = Math.max(strLen, minimumSearchSize.getValue()); + searchField.setSize(len, 18); + searchField.render(innerRight - 25 - len, innerTop - (20 + innerPadding) / 2 - 9); + + rightStuffLen += 5 + len; + } if (getSelectedCategory() != null && currentConfigEditing.containsKey(getSelectedCategory())) { ConfigProcessor.ProcessedCategory cat = currentConfigEditing.get(getSelectedCategory()); - TextRenderUtils.drawStringScaledMaxWidth(cat.desc, fr, innerLeft + 5, y + 40, true, innerRight - innerLeft - rightStuffLen - 10, 0xb0b0b0); + TextRenderUtils.drawStringScaledMaxWidth(cat.desc, + fr, innerLeft + 5, y + 40, true, innerRight - innerLeft - rightStuffLen - 10, 0xb0b0b0 + ); } Gui.drawRect(innerLeft, innerTop, innerLeft + 1, innerBottom, 0xff08080E); //Left @@ -265,7 +427,8 @@ public class ConfigEditor extends GuiElement { } GlStateManager.disableDepth(); if (optionY > 0) { - barSize = LerpUtils.clampZeroOne((float) (innerBottom - innerTop - 2) / (optionY + 5 + optionsScroll.getValue())); + barSize = + LerpUtils.clampZeroOne((float) (innerBottom - innerTop - 2) / (optionY + 5 + optionsScroll.getValue())); } } @@ -305,8 +468,13 @@ public class ConfigEditor extends GuiElement { } } int optionHeight = editor.getHeight(); - if (innerTop + 5 + optionYOverlay + optionHeight > innerTop + 1 && innerTop + 5 + optionYOverlay < innerBottom - 1) { - editor.renderOverlay((innerLeft + innerRight - optionWidth) / 2 - 5, innerTop + 5 + optionYOverlay, optionWidth); + if (innerTop + 5 + optionYOverlay + optionHeight > innerTop + 1 && + innerTop + 5 + optionYOverlay < innerBottom - 1) { + editor.renderOverlay( + (innerLeft + innerRight - optionWidth) / 2 - 5, + innerTop + 5 + optionYOverlay, + optionWidth + ); } optionYOverlay += optionHeight + 5; } @@ -315,30 +483,40 @@ public class ConfigEditor extends GuiElement { } GL11.glEnable(GL11.GL_SCISSOR_TEST); - float barStart = optionsScroll.getValue() / (float) (optionY + optionsScroll.getValue()); - float barEnd = barStart + barSize; - if (barEnd > 1) { - barEnd = 1; + optionsBarStart = optionsScroll.getValue() / (float) (optionY + optionsScroll.getValue()); + optionsBarend = optionsBarStart + barSize; + if (optionsBarend > 1) { + optionsBarend = 1; if (optionsScroll.getTarget() / (float) (optionY + optionsScroll.getValue()) + barSize < 1) { int target = optionsScroll.getTarget(); - optionsScroll.setValue((int) Math.ceil((optionY + 5 + optionsScroll.getValue()) - barSize * (optionY + 5 + optionsScroll.getValue()))); + optionsScroll.setValue((int) Math.ceil( + (optionY + 5 + optionsScroll.getValue()) - barSize * (optionY + 5 + optionsScroll.getValue()))); optionsScroll.setTarget(target); } else { - optionsScroll.setValue((int) Math.ceil((optionY + 5 + optionsScroll.getValue()) - barSize * (optionY + 5 + optionsScroll.getValue()))); + optionsScroll.setValue((int) Math.ceil( + (optionY + 5 + optionsScroll.getValue()) - barSize * (optionY + 5 + optionsScroll.getValue()))); } } int dist = innerBottom - innerTop - 12; Gui.drawRect(innerRight - 10, innerTop + 5, innerRight - 5, innerBottom - 5, 0xff101010); - Gui.drawRect(innerRight - 9, innerTop + 6 + (int) (dist * barStart), innerRight - 6, innerTop + 6 + (int) (dist * barEnd), 0xff303030); + Gui.drawRect( + innerRight - 9, + innerTop + 6 + (int) (dist * optionsBarStart), + innerRight - 6, + innerTop + 6 + (int) (dist * optionsBarend), + 0xff303030 + ); for (int socialIndex = 0; socialIndex < socialsIco.length; socialIndex++) { Minecraft.getMinecraft().getTextureManager().bindTexture(socialsIco[socialIndex]); GlStateManager.color(1, 1, 1, 1); int socialLeft = x + xSize - 23 - 18 * socialIndex; - RenderUtils.drawTexturedRect(socialLeft, y + 7, 16, 16, GL11.GL_LINEAR); + GuiRenderUtils.drawTexturedRect(socialLeft, y + 7, 16, 16, GL11.GL_LINEAR); - if (mouseX >= socialLeft && mouseX <= socialLeft + 16 && mouseY >= y + 6 && mouseY <= y + 23) { - tooltipToDisplay = Lists.newArrayList(EnumChatFormatting.YELLOW + "Go to: " + EnumChatFormatting.RESET + socialsLink[socialIndex]); + if (mouseX >= socialLeft && mouseX <= socialLeft + 16 && + mouseY >= y + 6 && mouseY <= y + 23) { + tooltipToDisplay = Lists.newArrayList( + EnumChatFormatting.YELLOW + "Go to: " + EnumChatFormatting.RESET + socialsLink[socialIndex]); } } @@ -352,6 +530,7 @@ public class ConfigEditor extends GuiElement { } public boolean mouseInput(int mouseX, int mouseY) { + lastMouseX = mouseX; ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); int width = scaledResolution.getScaledWidth(); int height = scaledResolution.getScaledHeight(); @@ -370,6 +549,57 @@ public class ConfigEditor extends GuiElement { int innerLeft = x + 149 + innerPadding; int innerRight = x + xSize - 5 - innerPadding; + int dist = innerBottom - innerTop - 12; + int optionsBarStartY = innerTop + 6 + (int) (dist * optionsBarStart); + int optionsBarEndY = innerTop + 6 + (int) (dist * optionsBarend); + int optionsBarStartX = innerRight - 12; + int optionsBarEndX = innerRight - 3; + + int categoryY = -categoryScroll.getValue(); + categoryY += 15 * getCurrentConfigEditing().size(); + int catDist = innerBottom - innerTop - 12; + float catBarStart = categoryScroll.getValue() / (float) (categoryY + categoryScroll.getValue()); + float categoryBarSize = LerpUtils.clampZeroOne( + (float) (innerBottom - innerTop - 2) / (categoryY + 5 + categoryScroll.getValue())); + float catBarEnd = catBarStart + categoryBarSize; + int categoryBarStartY = innerTop + 6 + (int) (catDist * catBarStart); + int categoryBarEndY = innerTop + 6 + (int) (catDist * catBarEnd); + int categoryBarStartX = x + innerPadding + 7; + int categoryBarEndX = x + innerPadding + 12; + keyboardScrollXCutoff = innerLeft - 10; + if (Mouse.getEventButtonState()) { + if ((mouseY < optionsBarStartY || mouseY > optionsBarEndY) && + (mouseX >= optionsBarStartX && mouseX <= optionsBarEndX) && mouseY > innerTop + 6 && mouseY < innerBottom - 6) { + optionsScroll.setTimeToReachTarget(200); + optionsScroll.resetTimer(); + optionsScroll.setTarget(mouseY - innerTop); + return true; + } else if ((mouseY < categoryBarStartY || mouseY > categoryBarEndY) && + (mouseX >= categoryBarStartX && mouseX <= categoryBarEndX) && mouseY > innerTop + 6 && + mouseY < innerBottom - 6) { + categoryScroll.setTimeToReachTarget(200); + categoryScroll.resetTimer(); + categoryScroll.setTarget(mouseY - innerTop); + return true; + } + + searchField.setFocus(mouseX >= innerRight - 20 && mouseX <= innerRight - 2 && + mouseY >= innerTop - (20 + innerPadding) / 2 - 9 && mouseY <= innerTop - (20 + innerPadding) / 2 + 9); + + if (minimumSearchSize.getValue() > 1) { + int strLen = Minecraft.getMinecraft().fontRendererObj.getStringWidth(searchField.getText()) + 10; + int len = Math.max(strLen, minimumSearchSize.getValue()); + + if (mouseX >= innerRight - 25 - len && mouseX <= innerRight - 25 && + mouseY >= innerTop - (20 + innerPadding) / 2 - 9 && mouseY <= innerTop - (20 + innerPadding) / 2 + 9) { + String old = searchField.getText(); + searchField.mouseClicked(mouseX, mouseY, Mouse.getEventButton()); + + if (!searchField.getText().equals(old)) search(); + } + } + } + int dWheel = Mouse.getEventDWheel(); if (mouseY > innerTop && mouseY < innerBottom && dWheel != 0) { if (dWheel < 0) { @@ -411,7 +641,8 @@ public class ConfigEditor extends GuiElement { float barSize = 1; int optionY = -newTarget; - if (getSelectedCategory() != null && getCurrentConfigEditing() != null && getCurrentConfigEditing().containsKey(getSelectedCategory())) { + if (getSelectedCategory() != null && getCurrentConfigEditing() != null && + getCurrentConfigEditing().containsKey(getSelectedCategory())) { ConfigProcessor.ProcessedCategory cat = getCurrentConfigEditing().get(getSelectedCategory()); HashMap<Integer, Integer> activeAccordions = new HashMap<>(); for (ConfigProcessor.ProcessedOption option : getOptionsInCategory(cat).values()) { @@ -447,7 +678,10 @@ public class ConfigEditor extends GuiElement { if (newTarget > barMax) { newTarget = barMax; } - optionsScroll.setTimeToReachTarget(Math.min(150, Math.max(10, 5 * Math.abs(newTarget - optionsScroll.getValue())))); + optionsScroll.setTimeToReachTarget(Math.min( + 150, + Math.max(10, 5 * Math.abs(newTarget - optionsScroll.getValue())) + )); optionsScroll.resetTimer(); optionsScroll.setTarget(newTarget); } @@ -458,7 +692,8 @@ public class ConfigEditor extends GuiElement { if (getSelectedCategory() == null) { setSelectedCategory(entry.getKey()); } - if (mouseX >= x + 5 && mouseX <= x + 145 && mouseY >= y + 70 + catY - 7 && mouseY <= y + 70 + catY + 7) { + if (mouseX >= x + 5 && mouseX <= x + 145 && + mouseY >= y + 70 + catY - 7 && mouseY <= y + 70 + catY + 7) { setSelectedCategory(entry.getKey()); return true; } @@ -469,17 +704,20 @@ public class ConfigEditor extends GuiElement { for (int socialIndex = 0; socialIndex < socialsLink.length; socialIndex++) { int socialLeft = x + xSize - 23 - 18 * socialIndex; - if (mouseX >= socialLeft && mouseX <= socialLeft + 16 && mouseY >= y + 6 && mouseY <= y + 23) { + if (mouseX >= socialLeft && mouseX <= socialLeft + 16 && + mouseY >= y + 6 && mouseY <= y + 23) { try { Desktop.getDesktop().browse(new URI(socialsLink[socialIndex])); - } catch (Exception ignored) {} + } catch (Exception ignored) { + } return true; } } } int optionY = -optionsScroll.getValue(); - if (getSelectedCategory() != null && getCurrentConfigEditing() != null && getCurrentConfigEditing().containsKey(getSelectedCategory())) { + if (getSelectedCategory() != null && getCurrentConfigEditing() != null && + getCurrentConfigEditing().containsKey(getSelectedCategory())) { int optionWidthDefault = innerRight - innerLeft - 20; ConfigProcessor.ProcessedCategory cat = getCurrentConfigEditing().get(getSelectedCategory()); HashMap<Integer, Integer> activeAccordions = new HashMap<>(); @@ -507,16 +745,24 @@ public class ConfigEditor extends GuiElement { activeAccordions.put(accordion.getAccordionId(), accordionDepth); } } - if (editor.mouseInputOverlay((innerLeft + innerRight - optionWidth) / 2 - 5, innerTop + 5 + optionY, optionWidth, mouseX, mouseY)) { + if (editor.mouseInputOverlay( + (innerLeft + innerRight - optionWidth) / 2 - 5, + innerTop + 5 + optionY, + optionWidth, + mouseX, + mouseY + )) { return true; } optionY += editor.getHeight() + 5; } } - if (mouseX > innerLeft && mouseX < innerRight && mouseY > innerTop && mouseY < innerBottom) { + if (mouseX > innerLeft && mouseX < innerRight && + mouseY > innerTop && mouseY < innerBottom) { optionY = -optionsScroll.getValue(); - if (getSelectedCategory() != null && getCurrentConfigEditing() != null && getCurrentConfigEditing().containsKey(getSelectedCategory())) { + if (getSelectedCategory() != null && getCurrentConfigEditing() != null && + getCurrentConfigEditing().containsKey(getSelectedCategory())) { int optionWidthDefault = innerRight - innerLeft - 20; ConfigProcessor.ProcessedCategory cat = getCurrentConfigEditing().get(getSelectedCategory()); HashMap<Integer, Integer> activeAccordions = new HashMap<>(); @@ -544,7 +790,13 @@ public class ConfigEditor extends GuiElement { activeAccordions.put(accordion.getAccordionId(), accordionDepth); } } - if (editor.mouseInput((innerLeft + innerRight - optionWidth) / 2 - 5, innerTop + 5 + optionY, optionWidth, mouseX, mouseY)) { + if (editor.mouseInput( + (innerLeft + innerRight - optionWidth) / 2 - 5, + innerTop + 5 + optionY, + optionWidth, + mouseX, + mouseY + )) { return true; } optionY += editor.getHeight() + 5; @@ -566,7 +818,19 @@ public class ConfigEditor extends GuiElement { int innerPadding = 20 / adjScaleFactor; int innerWidth = xSize - 154 - innerPadding * 2; - if (getSelectedCategory() != null && getCurrentConfigEditing() != null && getCurrentConfigEditing().containsKey(getSelectedCategory())) { + if (Keyboard.getEventKeyState()) { + String old = searchField.getText(); + searchField.keyTyped(Keyboard.getEventCharacter(), Keyboard.getEventKey()); + searchField.setText(Minecraft.getMinecraft().fontRendererObj.trimStringToWidth( + searchField.getText(), + innerWidth / 2 - 20 + )); + + if (!searchField.getText().equals(old)) search(); + } + + if (getSelectedCategory() != null && getCurrentConfigEditing() != null && + getCurrentConfigEditing().containsKey(getSelectedCategory())) { ConfigProcessor.ProcessedCategory cat = getCurrentConfigEditing().get(getSelectedCategory()); HashMap<Integer, Integer> activeAccordions = new HashMap<>(); for (ConfigProcessor.ProcessedOption option : getOptionsInCategory(cat).values()) { @@ -598,4 +862,22 @@ public class ConfigEditor extends GuiElement { return true; } + + private void handleKeyboardPresses() { + LerpingInteger target = lastMouseX < keyboardScrollXCutoff ? categoryScroll : optionsScroll; + if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) { + target.setTimeToReachTarget(50); + target.resetTimer(); + target.setTarget(target.getTarget() + 5); + } else if (Keyboard.isKeyDown(Keyboard.KEY_UP)) { + target.setTimeToReachTarget(50); + target.resetTimer(); + if (target.getTarget() >= 0) { + target.setTarget(target.getTarget() - 5); + } + } + if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) { + SkyHanniMod.configManager.saveConfig(); + } + } } diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt index 66a9f67c6..90573542f 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt @@ -6,7 +6,7 @@ import com.google.gson.GsonBuilder import java.io.* import java.nio.charset.StandardCharsets -class ConfigManager(val mod: SkyHanniMod) { +class ConfigManager { companion object { val gson = GsonBuilder().setPrettyPrinting().excludeFieldsWithoutExposeAnnotation().create() } diff --git a/src/main/java/at/hannibal2/skyhanni/config/Features.java b/src/main/java/at/hannibal2/skyhanni/config/Features.java index 854ef91bc..d4803d679 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/Features.java +++ b/src/main/java/at/hannibal2/skyhanni/config/Features.java @@ -1,22 +1,25 @@ package at.hannibal2.skyhanni.config; import at.hannibal2.skyhanni.SkyHanniMod; +import at.hannibal2.skyhanni.config.core.GuiElement; +import at.hannibal2.skyhanni.config.core.GuiScreenElementWrapper; +import at.hannibal2.skyhanni.config.core.config.Config; +import at.hannibal2.skyhanni.config.core.config.Position; +import at.hannibal2.skyhanni.config.core.config.annotations.Category; +import at.hannibal2.skyhanni.config.core.config.gui.GuiPositionEditor; import at.hannibal2.skyhanni.config.features.*; -import at.hannibal2.skyhanni.config.gui.config.ConfigEditor; -import at.hannibal2.skyhanni.config.gui.core.GuiElement; -import at.hannibal2.skyhanni.config.gui.core.GuiScreenElementWrapper; -import at.hannibal2.skyhanni.config.gui.core.config.Position; -import at.hannibal2.skyhanni.config.gui.core.config.annotations.Category; -import at.hannibal2.skyhanni.config.gui.core.config.gui.GuiPositionEditor; import com.google.gson.annotations.Expose; import net.minecraft.client.Minecraft; -public class Features { +public class Features extends Config { private void editOverlay(String activeConfig, int width, int height, Position position) { - Minecraft.getMinecraft().displayGuiScreen(new GuiPositionEditor(position, width, height, () -> {}, () -> {}, () -> SkyHanniMod.screenToOpen = new GuiScreenElementWrapper(new ConfigEditor(SkyHanniMod.feature, activeConfig)))); + Minecraft.getMinecraft().displayGuiScreen(new GuiPositionEditor(position, width, height, () -> { + }, () -> { + }, () -> SkyHanniMod.screenToOpen = new GuiScreenElementWrapper(new ConfigEditor(SkyHanniMod.feature, activeConfig)))); } + @Override public void executeRunnable(String runnableId) { String activeConfigCategory = null; if (Minecraft.getMinecraft().currentScreen instanceof GuiScreenElementWrapper) { diff --git a/src/main/java/at/hannibal2/skyhanni/config/GuiTextures.java b/src/main/java/at/hannibal2/skyhanni/config/GuiTextures.java new file mode 100644 index 000000000..92f886497 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/GuiTextures.java @@ -0,0 +1,106 @@ +package at.hannibal2.skyhanni.config; + +import net.minecraft.util.ResourceLocation; + +public class GuiTextures { + private GuiTextures() { + } // Not instantiable. Use import static to access class members. + + public static final ResourceLocation itemPaneTabArrow = + new ResourceLocation("notenoughupdates:item_pane_tab_arrow.png"); + public static final ResourceLocation rightarrow_overlay = + new ResourceLocation("notenoughupdates:rightarrow_overlay.png"); + public static final ResourceLocation rightarrow = new ResourceLocation("notenoughupdates:rightarrow.png"); + public static final ResourceLocation close = new ResourceLocation("notenoughupdates:close.png"); + public static final ResourceLocation settings = new ResourceLocation("notenoughupdates:settings.png"); + + public static final ResourceLocation off = new ResourceLocation("notenoughupdates:off.png"); + public static final ResourceLocation on = new ResourceLocation("notenoughupdates:on.png"); + public static final ResourceLocation help = new ResourceLocation("notenoughupdates:help.png"); + public static final ResourceLocation slider_off_large = new ResourceLocation("notenoughupdates:slider_off_large.png"); + public static final ResourceLocation slider_on_large = new ResourceLocation("notenoughupdates:slider_on_large.png"); + public static final ResourceLocation slider_button = new ResourceLocation("notenoughupdates:slider_button.png"); + + public static final ResourceLocation DISCORD = new ResourceLocation("notenoughupdates:social/discord.png"); + public static final ResourceLocation GITHUB = new ResourceLocation("notenoughupdates:social/github.png"); + + public static final ResourceLocation item_mask = new ResourceLocation("notenoughupdates:item_mask.png"); + public static final ResourceLocation item_haschild = new ResourceLocation("notenoughupdates:item_haschild.png"); + public static final ResourceLocation button_white = new ResourceLocation("notenoughupdates:button_white.png"); + public static final ResourceLocation button_tex = new ResourceLocation("notenoughupdates:button.png"); + public static final ResourceLocation button_fsr = + new ResourceLocation("notenoughupdates:FSR_do_not_texture_this_please.png"); + + public static final ResourceLocation accessory_bag_overlay = + new ResourceLocation("notenoughupdates:accessory_bag_overlay.png"); + + public static final ResourceLocation quickcommand_background = + new ResourceLocation("notenoughupdates:quickcommand_background.png"); + + public static final ResourceLocation dungeon_chest_worth = + new ResourceLocation("notenoughupdates:dungeon_chest_worth.png"); + + public static final ResourceLocation auction_view = new ResourceLocation("notenoughupdates:auction_view.png"); + public static final ResourceLocation auction_accept = new ResourceLocation("notenoughupdates:auction_accept.png"); + public static final ResourceLocation auction_price = new ResourceLocation("notenoughupdates:auction_price.png"); + public static final ResourceLocation auction_view_buttons = + new ResourceLocation("notenoughupdates:auction_view_buttons.png"); + + public static final ResourceLocation sort_all = new ResourceLocation("notenoughupdates:sort_all.png"); + public static final ResourceLocation sort_mob = new ResourceLocation("notenoughupdates:sort_mob.png"); + public static final ResourceLocation sort_pet = new ResourceLocation("notenoughupdates:sort_pet.png"); + public static final ResourceLocation sort_tool = new ResourceLocation("notenoughupdates:sort_weapon.png"); + public static final ResourceLocation sort_armor = new ResourceLocation("notenoughupdates:sort_armor.png"); + public static final ResourceLocation sort_accessory = new ResourceLocation("notenoughupdates:sort_accessory.png"); + public static final ResourceLocation sort_all_active = new ResourceLocation("notenoughupdates:sort_all_active.png"); + public static final ResourceLocation sort_mob_active = new ResourceLocation("notenoughupdates:sort_mob_active.png"); + public static final ResourceLocation sort_pet_active = new ResourceLocation("notenoughupdates:sort_pet_active.png"); + public static final ResourceLocation sort_tool_active = + new ResourceLocation("notenoughupdates:sort_weapon_active.png"); + public static final ResourceLocation sort_armor_active = + new ResourceLocation("notenoughupdates:sort_armor_active.png"); + public static final ResourceLocation sort_accessory_active = + new ResourceLocation("notenoughupdates:sort_accessory_active.png"); + + public static final ResourceLocation order_alphabetical = + new ResourceLocation("notenoughupdates:order_alphabetical.png"); + public static final ResourceLocation order_rarity = new ResourceLocation("notenoughupdates:order_rarity.png"); + public static final ResourceLocation order_value = new ResourceLocation("notenoughupdates:order_value.png"); + public static final ResourceLocation order_alphabetical_active = + new ResourceLocation("notenoughupdates:order_alphabetical_active.png"); + public static final ResourceLocation order_rarity_active = + new ResourceLocation("notenoughupdates:order_rarity_active.png"); + public static final ResourceLocation order_value_active = + new ResourceLocation("notenoughupdates:order_value_active.png"); + public static final ResourceLocation ascending_overlay = + new ResourceLocation("notenoughupdates:ascending_overlay.png"); + public static final ResourceLocation descending_overlay = + new ResourceLocation("notenoughupdates:descending_overlay.png"); + + public static final ResourceLocation BAR = new ResourceLocation("notenoughupdates:core/bar.png"); + public static final ResourceLocation BAR_ONE = new ResourceLocation("notenoughupdates:core/bar_1.png"); + public static final ResourceLocation BAR_TWO = new ResourceLocation("notenoughupdates:core/bar_2.png"); + public static final ResourceLocation BAR_THREE = new ResourceLocation("notenoughupdates:core/bar_3.png"); + public static final ResourceLocation BAR_ON = new ResourceLocation("notenoughupdates:core/bar_on.png"); + public static final ResourceLocation OFF = new ResourceLocation("notenoughupdates:core/toggle_off.png"); + public static final ResourceLocation ONE = new ResourceLocation("notenoughupdates:core/toggle_1.png"); + public static final ResourceLocation TWO = new ResourceLocation("notenoughupdates:core/toggle_2.png"); + public static final ResourceLocation THREE = new ResourceLocation("notenoughupdates:core/toggle_3.png"); + public static final ResourceLocation ON = new ResourceLocation("notenoughupdates:core/toggle_on.png"); + + public static final ResourceLocation slider_off_cap = + new ResourceLocation("notenoughupdates:core/slider/slider_off_cap.png"); + public static final ResourceLocation slider_off_notch = + new ResourceLocation("notenoughupdates:core/slider/slider_off_notch.png"); + public static final ResourceLocation slider_off_segment = + new ResourceLocation("notenoughupdates:core/slider/slider_off_segment.png"); + public static final ResourceLocation slider_on_cap = + new ResourceLocation("notenoughupdates:core/slider/slider_on_cap.png"); + public static final ResourceLocation slider_on_notch = + new ResourceLocation("notenoughupdates:core/slider/slider_on_notch.png"); + public static final ResourceLocation slider_on_segment = + new ResourceLocation("notenoughupdates:core/slider/slider_on_segment.png"); + public static final ResourceLocation slider_button_new = + new ResourceLocation("notenoughupdates:core/slider/slider_button.png"); + +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/commands/Commands.java b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.java index e2bfad8f2..3dd4a5262 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/commands/Commands.java +++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.java @@ -1,8 +1,8 @@ -package at.hannibal2.skyhanni.config.gui.commands; +package at.hannibal2.skyhanni.config.commands; import at.hannibal2.skyhanni.SkyHanniMod; -import at.hannibal2.skyhanni.config.gui.config.ConfigEditor; -import at.hannibal2.skyhanni.config.gui.core.GuiScreenElementWrapper; +import at.hannibal2.skyhanni.config.ConfigEditor; +import at.hannibal2.skyhanni.config.core.GuiScreenElementWrapper; import at.hannibal2.skyhanni.features.PlayerMarker; import at.hannibal2.skyhanni.test.LorenzTest; import at.hannibal2.skyhanni.test.command.CopyItemCommand; diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/commands/SimpleCommand.java b/src/main/java/at/hannibal2/skyhanni/config/commands/SimpleCommand.java index fe0e4fb55..25e3ba97b 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/commands/SimpleCommand.java +++ b/src/main/java/at/hannibal2/skyhanni/config/commands/SimpleCommand.java @@ -1,10 +1,11 @@ -package at.hannibal2.skyhanni.config.gui.commands; +package at.hannibal2.skyhanni.config.commands; -import java.util.List; import net.minecraft.command.CommandBase; import net.minecraft.command.ICommandSender; import net.minecraft.util.BlockPos; +import java.util.List; + /** @author Moulberry **/ diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/BackgroundBlur.java b/src/main/java/at/hannibal2/skyhanni/config/core/BackgroundBlur.java new file mode 100644 index 000000000..f71718f0b --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/BackgroundBlur.java @@ -0,0 +1,289 @@ +///* +// * Copyright (C) 2022 NotEnoughUpdates contributors +// * +// * This file is part of NotEnoughUpdates. +// * +// * NotEnoughUpdates 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. +// * +// * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. +// */ +// +//package at.hannibal2.skyhanni.config.core; +// +//import at.hannibal2.skyhanni.config.core.util.render.GuiRenderUtils; +//import net.minecraft.client.Minecraft; +//import net.minecraft.client.gui.Gui; +//import net.minecraft.client.renderer.GlStateManager; +//import net.minecraft.client.renderer.OpenGlHelper; +//import net.minecraft.client.shader.Framebuffer; +//import net.minecraft.client.shader.Shader; +//import net.minecraft.util.Matrix4f; +//import net.minecraftforge.client.event.EntityViewRenderEvent; +//import net.minecraftforge.client.event.RenderGameOverlayEvent; +//import net.minecraftforge.common.MinecraftForge; +//import net.minecraftforge.fml.common.eventhandler.EventPriority; +//import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +//import org.lwjgl.opengl.GL11; +//import org.lwjgl.opengl.GL30; +// +//import java.util.HashMap; +//import java.util.HashSet; +//import java.util.Map; +//import java.util.Set; +// +//public class BackgroundBlur { +// private static class OutputStuff { +// public Framebuffer framebuffer; +// public Shader blurShaderHorz = null; +// public Shader blurShaderVert = null; +// +// public OutputStuff(Framebuffer framebuffer, Shader blurShaderHorz, Shader blurShaderVert) { +// this.framebuffer = framebuffer; +// this.blurShaderHorz = blurShaderHorz; +// this.blurShaderVert = blurShaderVert; +// } +// } +// +// private static final HashMap<Float, OutputStuff> blurOutput = new HashMap<>(); +// private static final HashMap<Float, Long> lastBlurUse = new HashMap<>(); +// private static long lastBlur = 0; +// private static final HashSet<Float> requestedBlurs = new HashSet<>(); +// +// private static int fogColour = 0; +// private static boolean registered = false; +// +// public static void registerListener() { +// if (!registered) { +// registered = true; +// MinecraftForge.EVENT_BUS.register(new BackgroundBlur()); +// } +// } +// +// private static boolean shouldBlur = true; +// +// public static void markDirty() { +// if (Minecraft.getMinecraft().theWorld != null) { +// shouldBlur = true; +// } +// } +// +// public static void processBlurs() { +// if (shouldBlur) { +// shouldBlur = false; +// +// long currentTime = System.currentTimeMillis(); +// +// for (float blur : requestedBlurs) { +// lastBlur = currentTime; +// lastBlurUse.put(blur, currentTime); +// +// int width = Minecraft.getMinecraft().displayWidth; +// int height = Minecraft.getMinecraft().displayHeight; +// +// OutputStuff output = blurOutput.computeIfAbsent(blur, k -> { +// Framebuffer fb = new Framebuffer(width, height, false); +// fb.setFramebufferFilter(GL11.GL_NEAREST); +// return new OutputStuff(fb, null, null); +// }); +// +// if (output.framebuffer.framebufferWidth != width || output.framebuffer.framebufferHeight != height) { +// output.framebuffer.createBindFramebuffer(width, height); +// if (output.blurShaderHorz != null) { +// output.blurShaderHorz.setProjectionMatrix(createProjectionMatrix(width, height)); +// } +// if (output.blurShaderVert != null) { +// output.blurShaderVert.setProjectionMatrix(createProjectionMatrix(width, height)); +// } +// } +// +// blurBackground(output, blur); +// } +// +// Set<Float> remove = new HashSet<>(); +// for (Map.Entry<Float, Long> entry : lastBlurUse.entrySet()) { +// if (currentTime - entry.getValue() > 30 * 1000) { +// remove.add(entry.getKey()); +// } +// } +// remove.remove((float) NotEnoughUpdates.INSTANCE.config.itemlist.bgBlurFactor); +// +// for (Map.Entry<Float, OutputStuff> entry : blurOutput.entrySet()) { +// if (remove.contains(entry.getKey())) { +// entry.getValue().framebuffer.deleteFramebuffer(); +// entry.getValue().blurShaderHorz.deleteShader(); +// entry.getValue().blurShaderVert.deleteShader(); +// } +// } +// +// lastBlurUse.keySet().removeAll(remove); +// blurOutput.keySet().removeAll(remove); +// +// requestedBlurs.clear(); +// } +// } +// +// @SubscribeEvent(priority = EventPriority.HIGHEST) +// public void onScreenRender(RenderGameOverlayEvent.Pre event) { +// if (event.type == RenderGameOverlayEvent.ElementType.ALL) { +// processBlurs(); +// } +// Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false); +// } +// +// @SubscribeEvent +// public void onFogColour(EntityViewRenderEvent.FogColors event) { +// fogColour = 0xff000000; +// fogColour |= ((int) (event.red * 255) & 0xFF) << 16; +// fogColour |= ((int) (event.green * 255) & 0xFF) << 8; +// fogColour |= (int) (event.blue * 255) & 0xFF; +// } +// +// private static Framebuffer blurOutputHorz = null; +// +// /** +// * Creates a projection matrix that projects from our coordinate space [0->width; 0->height] to OpenGL coordinate +// * space [-1 -> 1; 1 -> -1] (Note: flipped y-axis). +// * <p> +// * This is so that we can render to and from the framebuffer in a way that is familiar to us, instead of needing to +// * apply scales and translations manually. +// */ +// private static Matrix4f createProjectionMatrix(int width, int height) { +// Matrix4f projMatrix = new Matrix4f(); +// projMatrix.setIdentity(); +// projMatrix.m00 = 2.0F / (float) width; +// projMatrix.m11 = 2.0F / (float) (-height); +// projMatrix.m22 = -0.0020001999F; +// projMatrix.m33 = 1.0F; +// projMatrix.m03 = -1.0F; +// projMatrix.m13 = 1.0F; +// projMatrix.m23 = -1.0001999F; +// return projMatrix; +// } +// +// private static final double lastBgBlurFactor = -1; +// +// private static void blurBackground(OutputStuff output, float blurFactor) { +// if (!OpenGlHelper.isFramebufferEnabled() || !OpenGlHelper.areShadersSupported()) return; +// +// int width = Minecraft.getMinecraft().displayWidth; +// int height = Minecraft.getMinecraft().displayHeight; +// +// GlStateManager.matrixMode(GL11.GL_PROJECTION); +// GlStateManager.loadIdentity(); +// GlStateManager.ortho(0.0D, width, height, 0.0D, 1000.0D, 3000.0D); +// GlStateManager.matrixMode(GL11.GL_MODELVIEW); +// GlStateManager.loadIdentity(); +// GlStateManager.translate(0.0F, 0.0F, -2000.0F); +// +// if (blurOutputHorz == null) { +// blurOutputHorz = new Framebuffer(width, height, false); +// blurOutputHorz.setFramebufferFilter(GL11.GL_NEAREST); +// } +// if (blurOutputHorz == null || output == null) { +// return; +// } +// if (blurOutputHorz.framebufferWidth != width || blurOutputHorz.framebufferHeight != height) { +// blurOutputHorz.createBindFramebuffer(width, height); +// Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false); +// } +// +// if (output.blurShaderHorz == null) { +// try { +// output.blurShaderHorz = new Shader(Minecraft.getMinecraft().getResourceManager(), "blur", +// output.framebuffer, blurOutputHorz +// ); +// output.blurShaderHorz.getShaderManager().getShaderUniform("BlurDir").set(1, 0); +// output.blurShaderHorz.setProjectionMatrix(createProjectionMatrix(width, height)); +// } catch (Exception ignored) { +// } +// } +// if (output.blurShaderVert == null) { +// try { +// output.blurShaderVert = new Shader(Minecraft.getMinecraft().getResourceManager(), "blur", +// blurOutputHorz, output.framebuffer +// ); +// output.blurShaderVert.getShaderManager().getShaderUniform("BlurDir").set(0, 1); +// output.blurShaderVert.setProjectionMatrix(createProjectionMatrix(width, height)); +// } catch (Exception ignored) { +// } +// } +// if (output.blurShaderHorz != null && output.blurShaderVert != null) { +// if (output.blurShaderHorz.getShaderManager().getShaderUniform("Radius") == null) { +// //Corrupted shader? +// return; +// } +// +// output.blurShaderHorz.getShaderManager().getShaderUniform("Radius").set(blurFactor); +// output.blurShaderVert.getShaderManager().getShaderUniform("Radius").set(blurFactor); +// +// GL11.glPushMatrix(); +// GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, Minecraft.getMinecraft().getFramebuffer().framebufferObject); +// GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, output.framebuffer.framebufferObject); +// GL30.glBlitFramebuffer(0, 0, width, height, +// 0, 0, output.framebuffer.framebufferWidth, output.framebuffer.framebufferHeight, +// GL11.GL_COLOR_BUFFER_BIT, GL11.GL_NEAREST +// ); +// +// output.blurShaderHorz.loadShader(0); +// output.blurShaderVert.loadShader(0); +// GlStateManager.enableDepth(); +// GL11.glPopMatrix(); +// } +// Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false); +// } +// +// public static void renderBlurredBackground( +// float blurStrength, int screenWidth, int screenHeight, +// int x, int y, int blurWidth, int blurHeight +// ) { +// renderBlurredBackground(blurStrength, screenWidth, screenHeight, x, y, blurWidth, blurHeight, false); +// } +// +// /** +// * Renders a subsection of the blurred framebuffer on to the corresponding section of the screen. +// * Essentially, this method will "blur" the background inside the bounds specified by [x->x+blurWidth, y->y+blurHeight] +// */ +// public static void renderBlurredBackground( +// float blurStrength, int screenWidth, int screenHeight, +// int x, int y, int blurWidth, int blurHeight, boolean forcedUpdate +// ) { +// if (!OpenGlHelper.isFramebufferEnabled() || !OpenGlHelper.areShadersSupported()) return; +// if (blurStrength < 0.5) return; +// requestedBlurs.add(blurStrength); +// +// long currentTime = System.currentTimeMillis(); +// if (currentTime - lastBlur > 300) { +// shouldBlur = true; +// if (currentTime - lastBlur > 400 && forcedUpdate) return; +// } +// +// if (blurOutput.isEmpty()) return; +// +// OutputStuff out = blurOutput.get(blurStrength); +// if (out == null) { +// out = blurOutput.values().iterator().next(); +// } +// +// float uMin = x / (float) screenWidth; +// float uMax = (x + blurWidth) / (float) screenWidth; +// float vMin = (screenHeight - y) / (float) screenHeight; +// float vMax = (screenHeight - y - blurHeight) / (float) screenHeight; +// +// GlStateManager.depthMask(false); +// Gui.drawRect(x, y, x + blurWidth, y + blurHeight, fogColour); +// out.framebuffer.bindFramebufferTexture(); +// GlStateManager.color(1f, 1f, 1f, 1f); +// GuiRenderUtils.drawTexturedRect(x, y, blurWidth, blurHeight, uMin, uMax, vMin, vMax); +// out.framebuffer.unbindFramebufferTexture(); +// GlStateManager.depthMask(true); +// } +//} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/ChromaColour.java b/src/main/java/at/hannibal2/skyhanni/config/core/ChromaColour.java new file mode 100644 index 000000000..e67c5ff10 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/ChromaColour.java @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core; + +import java.awt.*; + +public class ChromaColour { + public static String special(int chromaSpeed, int alpha, int rgb) { + return special(chromaSpeed, alpha, (rgb & 0xFF0000) >> 16, (rgb & 0x00FF00) >> 8, (rgb & 0x0000FF)); + } + + private static final int RADIX = 10; + + public static String special(int chromaSpeed, int alpha, int r, int g, int b) { + StringBuilder sb = new StringBuilder(); + sb.append(Integer.toString(chromaSpeed, RADIX)).append(":"); + sb.append(Integer.toString(alpha, RADIX)).append(":"); + sb.append(Integer.toString(r, RADIX)).append(":"); + sb.append(Integer.toString(g, RADIX)).append(":"); + sb.append(Integer.toString(b, RADIX)); + return sb.toString(); + } + + private static int[] decompose(String csv) { + String[] split = csv.split(":"); + + int[] arr = new int[split.length]; + + for (int i = 0; i < split.length; i++) { + arr[i] = Integer.parseInt(split[split.length - 1 - i], RADIX); + } + return arr; + } + + public static int specialToSimpleRGB(String special) { + int[] d = decompose(special); + int r = d[2]; + int g = d[1]; + int b = d[0]; + int a = d[3]; + int chr = d[4]; + + return (a & 0xFF) << 24 | (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF); + } + + public static int getSpeed(String special) { + return decompose(special)[4]; + } + + public static float getSecondsForSpeed(int speed) { + return (255 - speed) / 254f * (MAX_CHROMA_SECS - MIN_CHROMA_SECS) + MIN_CHROMA_SECS; + } + + private static final int MIN_CHROMA_SECS = 1; + private static final int MAX_CHROMA_SECS = 60; + + public static long startTime = -1; + + public static int specialToChromaRGB(String special) { + if (startTime < 0) startTime = System.currentTimeMillis(); + + int[] d = decompose(special); + int chr = d[4]; + int a = d[3]; + int r = d[2]; + int g = d[1]; + int b = d[0]; + + float[] hsv = Color.RGBtoHSB(r, g, b, null); + + if (chr > 0) { + float seconds = getSecondsForSpeed(chr); + hsv[0] += (System.currentTimeMillis() - startTime) / 1000f / seconds; + hsv[0] %= 1; + if (hsv[0] < 0) hsv[0] += 1; + } + + return (a & 0xFF) << 24 | (Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]) & 0x00FFFFFF); + } + + public static int rotateHue(int argb, int degrees) { + int a = (argb >> 24) & 0xFF; + int r = (argb >> 16) & 0xFF; + int g = (argb >> 8) & 0xFF; + int b = (argb) & 0xFF; + + float[] hsv = Color.RGBtoHSB(r, g, b, null); + + hsv[0] += degrees / 360f; + hsv[0] %= 1; + + return (a & 0xFF) << 24 | (Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]) & 0x00FFFFFF); + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/GlScissorStack.java b/src/main/java/at/hannibal2/skyhanni/config/core/GlScissorStack.java new file mode 100644 index 000000000..5aae4cf28 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/GlScissorStack.java @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ScaledResolution; +import org.lwjgl.opengl.GL11; + +import java.util.LinkedList; + +public class GlScissorStack { + private static class Bounds { + int left; + int top; + int right; + int bottom; + + public Bounds(int left, int top, int right, int bottom) { + this.left = left; + this.top = top; + this.right = right; + this.bottom = bottom; + } + + public Bounds createSubBound(int left, int top, int right, int bottom) { + left = Math.max(left, this.left); + top = Math.max(top, this.top); + right = Math.min(right, this.right); + bottom = Math.min(bottom, this.bottom); + + if (top > bottom) { + top = bottom; + } + if (left > right) { + left = right; + } + + return new Bounds(left, top, right, bottom); + } + + public void set(ScaledResolution scaledResolution) { + int height = Minecraft.getMinecraft().displayHeight; + int scale = scaledResolution.getScaleFactor(); + GL11.glScissor(left * scale, height - bottom * scale, (right - left) * scale, (bottom - top) * scale); + } + } + + private static final LinkedList<Bounds> boundsStack = new LinkedList<>(); + + public static void push(int left, int top, int right, int bottom, ScaledResolution scaledResolution) { + if (right < left) { + int temp = right; + right = left; + left = temp; + } + if (bottom < top) { + int temp = bottom; + bottom = top; + top = temp; + } + if (boundsStack.isEmpty()) { + boundsStack.push(new Bounds(left, top, right, bottom)); + } else { + boundsStack.push(boundsStack.peek().createSubBound(left, top, right, bottom)); + } + if (!boundsStack.isEmpty()) { + boundsStack.peek().set(scaledResolution); + } + GL11.glEnable(GL11.GL_SCISSOR_TEST); + } + + public static void pop(ScaledResolution scaledResolution) { + if (!boundsStack.isEmpty()) { + boundsStack.pop(); + } + if (boundsStack.isEmpty()) { + GL11.glDisable(GL11.GL_SCISSOR_TEST); + } else { + boundsStack.peek().set(scaledResolution); + } + } + + public static void clear() { + boundsStack.clear(); + GL11.glDisable(GL11.GL_SCISSOR_TEST); + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/GuiElement.java b/src/main/java/at/hannibal2/skyhanni/config/core/GuiElement.java new file mode 100644 index 000000000..8a36e203f --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/GuiElement.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core; + +import net.minecraft.client.gui.Gui; + +public abstract class GuiElement extends Gui { + public abstract void render(); + + public abstract boolean mouseInput(int mouseX, int mouseY); + + public abstract boolean keyboardInput(); +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/GuiElementBoolean.java b/src/main/java/at/hannibal2/skyhanni/config/core/GuiElementBoolean.java new file mode 100644 index 000000000..146a3a480 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/GuiElementBoolean.java @@ -0,0 +1,147 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core; + +import at.hannibal2.skyhanni.config.GuiTextures; +import at.hannibal2.skyhanni.config.core.util.lerp.LerpUtils; +import at.hannibal2.skyhanni.config.core.util.render.GuiRenderUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; + +import java.util.function.Consumer; + +public class GuiElementBoolean extends GuiElement { + public int x; + public int y; + private boolean value; + private final int clickRadius; + private final Consumer<Boolean> toggleCallback; + + private boolean previewValue; + private int animation = 0; + private long lastMillis = 0; + + private static final int xSize = 48; + private static final int ySize = 14; + + public GuiElementBoolean(int x, int y, boolean value, Consumer<Boolean> toggleCallback) { + this(x, y, value, 0, toggleCallback); + } + + public GuiElementBoolean(int x, int y, boolean value, int clickRadius, Consumer<Boolean> toggleCallback) { + this.x = x; + this.y = y; + this.value = value; + this.previewValue = value; + this.clickRadius = clickRadius; + this.toggleCallback = toggleCallback; + this.lastMillis = System.currentTimeMillis(); + + if (value) animation = 36; + } + + @Override + public void render() { + GlStateManager.color(1, 1, 1, 1); + ResourceLocation buttonLoc = GuiTextures.ON; + ResourceLocation barLoc = GuiTextures.BAR_ON; + long currentMillis = System.currentTimeMillis(); + long deltaMillis = currentMillis - lastMillis; + lastMillis = currentMillis; + boolean passedLimit = false; + if (previewValue != value) { + if ((previewValue && animation > 12) || + (!previewValue && animation < 24)) { + passedLimit = true; + } + } + if (previewValue != passedLimit) { + animation += deltaMillis / 10; + } else { + animation -= deltaMillis / 10; + } + lastMillis -= deltaMillis % 10; + + if (previewValue == value) { + animation = Math.max(0, Math.min(36, animation)); + } else if (!passedLimit) { + if (previewValue) { + animation = Math.max(0, Math.min(12, animation)); + } else { + animation = Math.max(24, Math.min(36, animation)); + } + } else { + if (previewValue) { + animation = Math.max(12, animation); + } else { + animation = Math.min(24, animation); + } + } + + int animation = (int) (LerpUtils.sigmoidZeroOne(this.animation / 36f) * 36); + if (animation < 3) { + buttonLoc = GuiTextures.OFF; + barLoc = GuiTextures.BAR; + } else if (animation < 13) { + buttonLoc = GuiTextures.ONE; + barLoc = GuiTextures.BAR_ONE; + } else if (animation < 23) { + buttonLoc = GuiTextures.TWO; + barLoc = GuiTextures.BAR_TWO; + } else if (animation < 33) { + buttonLoc = GuiTextures.THREE; + barLoc = GuiTextures.BAR_THREE; + } + + GL11.glTranslatef(0, 0, 100); + Minecraft.getMinecraft().getTextureManager().bindTexture(buttonLoc); + GuiRenderUtils.drawTexturedRect(x + animation, y, 12, 14); + GL11.glTranslatef(0, 0, -100); + + Minecraft.getMinecraft().getTextureManager().bindTexture(barLoc); + GuiRenderUtils.drawTexturedRect(x, y, xSize, ySize); + } + + @Override + public boolean mouseInput(int mouseX, int mouseY) { + if (mouseX > x - clickRadius && mouseX < x + xSize + clickRadius && + mouseY > y - clickRadius && mouseY < y + ySize + clickRadius) { + if (Mouse.getEventButton() == 0) { + if (Mouse.getEventButtonState()) { + previewValue = !value; + } else if (previewValue == !value) { + value = !value; + toggleCallback.accept(value); + } + } + } else { + previewValue = value; + } + return false; + } + + @Override + public boolean keyboardInput() { + return false; + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/GuiElementColour.java b/src/main/java/at/hannibal2/skyhanni/config/core/GuiElementColour.java new file mode 100644 index 000000000..f43ea4a0e --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/GuiElementColour.java @@ -0,0 +1,449 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core; + +import at.hannibal2.skyhanni.config.core.util.render.GuiRenderUtils; +import at.hannibal2.skyhanni.config.core.util.render.TextRenderUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.texture.DynamicTexture; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; + +import java.awt.*; +import java.awt.image.BufferedImage; +import java.util.function.Consumer; + +public class GuiElementColour extends GuiElement { + public static final ResourceLocation colour_selector_dot = new ResourceLocation( + "notenoughupdates:core/colour_selector_dot.png"); + public static final ResourceLocation colour_selector_bar = new ResourceLocation( + "notenoughupdates:core/colour_selector_bar.png"); + public static final ResourceLocation colour_selector_bar_alpha = new ResourceLocation( + "notenoughupdates:core/colour_selector_bar_alpha.png"); + public static final ResourceLocation colour_selector_chroma = new ResourceLocation( + "notenoughupdates:core/colour_selector_chroma.png"); + + private static final ResourceLocation colourPickerLocation = new ResourceLocation("mbcore:dynamic/colourpicker"); + private static final ResourceLocation colourPickerBarValueLocation = new ResourceLocation( + "mbcore:dynamic/colourpickervalue"); + private static final ResourceLocation colourPickerBarOpacityLocation = new ResourceLocation( + "mbcore:dynamic/colourpickeropacity"); + private final GuiElementTextField hexField = new GuiElementTextField( + "", + GuiElementTextField.SCALE_TEXT | GuiElementTextField.FORCE_CAPS | GuiElementTextField.NO_SPACE + ); + + private final int x; + private final int y; + private int xSize = 119; + private final int ySize = 89; + + private float wheelAngle = 0; + private float wheelRadius = 0; + + private int clickedComponent = -1; + + private final Consumer<String> colourChangedCallback; + private final Runnable closeCallback; + private String colour; + + private final boolean opacitySlider; + private final boolean valueSlider; + + public GuiElementColour( + int x, int y, String initialColour, Consumer<String> colourChangedCallback, + Runnable closeCallback + ) { + this(x, y, initialColour, colourChangedCallback, closeCallback, true, true); + } + + public GuiElementColour( + int x, int y, String initialColour, Consumer<String> colourChangedCallback, + Runnable closeCallback, boolean opacitySlider, boolean valueSlider + ) { + final ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + + this.y = Math.max(10, Math.min(scaledResolution.getScaledHeight() - ySize - 10, y)); + this.x = Math.max(10, Math.min(scaledResolution.getScaledWidth() - xSize - 10, x)); + + this.colour = initialColour; + this.colourChangedCallback = colourChangedCallback; + this.closeCallback = closeCallback; + + int colour = ChromaColour.specialToSimpleRGB(initialColour); + Color c = new Color(colour); + float[] hsv = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); + updateAngleAndRadius(hsv); + + this.opacitySlider = opacitySlider; + this.valueSlider = valueSlider; + + if (!valueSlider) xSize -= 15; + if (!opacitySlider) xSize -= 15; + } + + public void updateAngleAndRadius(float[] hsv) { + this.wheelRadius = hsv[1]; + this.wheelAngle = hsv[0] * 360; + } + + public void render() { + GuiRenderUtils.drawFloatingRectDark(x, y, xSize, ySize); + + int currentColour = ChromaColour.specialToSimpleRGB(colour); + Color c = new Color(currentColour, true); + float[] hsv = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); + + BufferedImage bufferedImage = new BufferedImage(288, 288, BufferedImage.TYPE_INT_ARGB); + float borderRadius = 0.05f; + if (Keyboard.isKeyDown(Keyboard.KEY_N)) borderRadius = 0; + for (int x = -16; x < 272; x++) { + for (int y = -16; y < 272; y++) { + float radius = (float) Math.sqrt(((x - 128) * (x - 128) + (y - 128) * (y - 128)) / 16384f); + float angle = (float) Math.toDegrees(Math.atan((128 - x) / (y - 128 + 1E-5)) + Math.PI / 2); + if (y < 128) angle += 180; + if (radius <= 1) { + int rgb = Color.getHSBColor(angle / 360f, (float) Math.pow(radius, 1.5f), hsv[2]).getRGB(); + bufferedImage.setRGB(x + 16, y + 16, rgb); + } else if (radius <= 1 + borderRadius) { + float invBlackAlpha = Math.abs(radius - 1 - borderRadius / 2) / borderRadius * 2; + float blackAlpha = 1 - invBlackAlpha; + + if (radius > 1 + borderRadius / 2) { + bufferedImage.setRGB(x + 16, y + 16, (int) (blackAlpha * 255) << 24); + } else { + Color col = Color.getHSBColor(angle / 360f, 1, hsv[2]); + int rgb = (int) (col.getRed() * invBlackAlpha) << 16 | + (int) (col.getGreen() * invBlackAlpha) << 8 | + (int) (col.getBlue() * invBlackAlpha); + bufferedImage.setRGB(x + 16, y + 16, 0xff000000 | rgb); + } + + } + } + } + + BufferedImage bufferedImageValue = new BufferedImage(10, 64, BufferedImage.TYPE_INT_ARGB); + for (int x = 0; x < 10; x++) { + for (int y = 0; y < 64; y++) { + if ((x == 0 || x == 9) && (y == 0 || y == 63)) continue; + + int rgb = Color.getHSBColor(wheelAngle / 360, wheelRadius, (64 - y) / 64f).getRGB(); + bufferedImageValue.setRGB(x, y, rgb); + } + } + + BufferedImage bufferedImageOpacity = new BufferedImage(10, 64, BufferedImage.TYPE_INT_ARGB); + for (int x = 0; x < 10; x++) { + for (int y = 0; y < 64; y++) { + if ((x == 0 || x == 9) && (y == 0 || y == 63)) continue; + + int rgb = (currentColour & 0x00FFFFFF) | (Math.min(255, (64 - y) * 4) << 24); + bufferedImageOpacity.setRGB(x, y, rgb); + } + } + + float selradius = (float) Math.pow(wheelRadius, 1 / 1.5f) * 32; + int selx = (int) (Math.cos(Math.toRadians(wheelAngle)) * selradius); + int sely = (int) (Math.sin(Math.toRadians(wheelAngle)) * selradius); + + int valueOffset = 0; + if (valueSlider) { + valueOffset = 15; + + Minecraft.getMinecraft().getTextureManager().loadTexture( + colourPickerBarValueLocation, + new DynamicTexture(bufferedImageValue) + ); + Minecraft.getMinecraft().getTextureManager().bindTexture(colourPickerBarValueLocation); + GlStateManager.color(1, 1, 1, 1); + GuiRenderUtils.drawTexturedRect(x + 5 + 64 + 5, y + 5, 10, 64, GL11.GL_NEAREST); + } + + int opacityOffset = 0; + if (opacitySlider) { + opacityOffset = 15; + + Minecraft.getMinecraft().getTextureManager().bindTexture(colour_selector_bar_alpha); + GlStateManager.color(1, 1, 1, 1); + GuiRenderUtils.drawTexturedRect(x + 5 + 64 + 5 + valueOffset, y + 5, 10, 64, GL11.GL_NEAREST); + + Minecraft.getMinecraft().getTextureManager().loadTexture( + colourPickerBarOpacityLocation, + new DynamicTexture(bufferedImageOpacity) + ); + Minecraft.getMinecraft().getTextureManager().bindTexture(colourPickerBarOpacityLocation); + GlStateManager.color(1, 1, 1, 1); + GuiRenderUtils.drawTexturedRect(x + 5 + 64 + 5 + valueOffset, y + 5, 10, 64, GL11.GL_NEAREST); + } + + int chromaSpeed = ChromaColour.getSpeed(colour); + int currentColourChroma = ChromaColour.specialToChromaRGB(colour); + Color cChroma = new Color(currentColourChroma, true); + float[] hsvChroma = Color.RGBtoHSB(cChroma.getRed(), cChroma.getGreen(), cChroma.getBlue(), null); + + if (chromaSpeed > 0) { + Gui.drawRect(x + 5 + 64 + valueOffset + opacityOffset + 5 + 1, y + 5 + 1, + x + 5 + 64 + valueOffset + opacityOffset + 5 + 10 - 1, y + 5 + 64 - 1, + Color.HSBtoRGB(hsvChroma[0], 0.8f, 0.8f) + ); + } else { + Gui.drawRect(x + 5 + 64 + valueOffset + opacityOffset + 5 + 1, y + 5 + 27 + 1, + x + 5 + 64 + valueOffset + opacityOffset + 5 + 10 - 1, y + 5 + 37 - 1, + Color.HSBtoRGB((hsvChroma[0] + (System.currentTimeMillis() - ChromaColour.startTime) / 1000f) % 1, 0.8f, 0.8f) + ); + } + + Minecraft.getMinecraft().getTextureManager().bindTexture(colour_selector_bar); + GlStateManager.color(1, 1, 1, 1); + if (valueSlider) GuiRenderUtils.drawTexturedRect(x + 5 + 64 + 5, y + 5, 10, 64, GL11.GL_NEAREST); + if (opacitySlider) GuiRenderUtils.drawTexturedRect(x + 5 + 64 + 5 + valueOffset, y + 5, 10, 64, GL11.GL_NEAREST); + + if (chromaSpeed > 0) { + GuiRenderUtils.drawTexturedRect(x + 5 + 64 + valueOffset + opacityOffset + 5, y + 5, 10, 64, GL11.GL_NEAREST); + } else { + Minecraft.getMinecraft().getTextureManager().bindTexture(colour_selector_chroma); + GuiRenderUtils.drawTexturedRect(x + 5 + 64 + valueOffset + opacityOffset + 5, y + 5 + 27, 10, 10, GL11.GL_NEAREST); + } + + if (valueSlider) Gui.drawRect(x + 5 + 64 + 5, y + 5 + 64 - (int) (64 * hsv[2]), + x + 5 + 64 + valueOffset, y + 5 + 64 - (int) (64 * hsv[2]) + 1, 0xFF000000 + ); + if (opacitySlider) Gui.drawRect(x + 5 + 64 + 5 + valueOffset, y + 5 + 64 - c.getAlpha() / 4, + x + 5 + 64 + valueOffset + opacityOffset, y + 5 + 64 - c.getAlpha() / 4 - 1, 0xFF000000 + ); + if (chromaSpeed > 0) { + Gui.drawRect(x + 5 + 64 + valueOffset + opacityOffset + 5, + y + 5 + 64 - (int) (chromaSpeed / 255f * 64), + x + 5 + 64 + valueOffset + opacityOffset + 5 + 10, + y + 5 + 64 - (int) (chromaSpeed / 255f * 64) + 1, 0xFF000000 + ); + } + + Minecraft.getMinecraft().getTextureManager().loadTexture(colourPickerLocation, new DynamicTexture(bufferedImage)); + Minecraft.getMinecraft().getTextureManager().bindTexture(colourPickerLocation); + GlStateManager.color(1, 1, 1, 1); + GuiRenderUtils.drawTexturedRect(x + 1, y + 1, 72, 72, GL11.GL_LINEAR); + + Minecraft.getMinecraft().getTextureManager().bindTexture(colour_selector_dot); + GlStateManager.color(1, 1, 1, 1); + GuiRenderUtils.drawTexturedRect(x + 5 + 32 + selx - 4, y + 5 + 32 + sely - 4, 8, 8, GL11.GL_NEAREST); + + TextRenderUtils.drawStringCenteredScaledMaxWidth(EnumChatFormatting.GRAY.toString() + Math.round(hsv[2] * 100) + "", + Minecraft.getMinecraft().fontRendererObj, + x + 5 + 64 + 5 + 5 - (Math.round(hsv[2] * 100) == 100 ? 1 : 0), y + 5 + 64 + 5 + 5, true, 13, -1 + ); + if (opacitySlider) { + TextRenderUtils.drawStringCenteredScaledMaxWidth( + EnumChatFormatting.GRAY.toString() + Math.round(c.getAlpha() / 255f * 100) + "", + Minecraft.getMinecraft().fontRendererObj, + x + 5 + 64 + 5 + valueOffset + 5, + y + 5 + 64 + 5 + 5, + true, + 13, + -1 + ); + } + if (chromaSpeed > 0) { + TextRenderUtils.drawStringCenteredScaledMaxWidth(EnumChatFormatting.GRAY.toString() + + (int) ChromaColour.getSecondsForSpeed(chromaSpeed) + "s", + Minecraft.getMinecraft().fontRendererObj, + x + 5 + 64 + 5 + valueOffset + opacityOffset + 6, y + 5 + 64 + 5 + 5, true, 13, -1 + ); + } + + hexField.setSize(48, 10); + if (!hexField.getFocus()) hexField.setText(Integer.toHexString(c.getRGB() & 0xFFFFFF).toUpperCase()); + + StringBuilder sb = new StringBuilder(EnumChatFormatting.GRAY + "#"); + for (int i = 0; i < 6 - hexField.getText().length(); i++) { + sb.append("0"); + } + sb.append(EnumChatFormatting.WHITE); + + hexField.setPrependText(sb.toString()); + hexField.render(x + 5 + 8, y + 5 + 64 + 5); + } + + public boolean mouseInput(int mouseX, int mouseY) { + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + float mouseXF = (float) (Mouse.getX() * scaledResolution.getScaledWidth_double() / + Minecraft.getMinecraft().displayWidth); + float mouseYF = (float) (scaledResolution.getScaledHeight_double() - Mouse.getY() * + scaledResolution.getScaledHeight_double() / Minecraft.getMinecraft().displayHeight - 1); + + if ((Mouse.getEventButton() == 0 || Mouse.getEventButton() == 1) && Mouse.getEventButtonState()) { + if (mouseX > x + 5 + 8 && mouseX < x + 5 + 8 + 48) { + if (mouseY > y + 5 + 64 + 5 && mouseY < y + 5 + 64 + 5 + 10) { + hexField.mouseClicked(mouseX, mouseY, Mouse.getEventButton()); + clickedComponent = -1; + return true; + } + } + } + if (!Mouse.getEventButtonState() && Mouse.getEventButton() == 0) { + clickedComponent = -1; + } + if (Mouse.getEventButtonState() && Mouse.getEventButton() == 0) { + if (mouseX >= x && mouseX <= x + 119 && + mouseY >= y && mouseY <= y + 89) { + hexField.unfocus(); + + int xWheel = mouseX - x - 5; + int yWheel = mouseY - y - 5; + + if (xWheel > 0 && xWheel < 64) { + if (yWheel > 0 && yWheel < 64) { + clickedComponent = 0; + } + } + + int xValue = mouseX - (x + 5 + 64 + 5); + int y = mouseY - this.y - 5; + + int opacityOffset = opacitySlider ? 15 : 0; + int valueOffset = valueSlider ? 15 : 0; + + if (y > -5 && y <= 69) { + if (valueSlider) { + if (xValue > 0 && xValue < 10) { + clickedComponent = 1; + } + } + + if (opacitySlider) { + int xOpacity = mouseX - (x + 5 + 64 + 5 + valueOffset); + + if (xOpacity > 0 && xOpacity < 10) { + clickedComponent = 2; + } + } + } + + int chromaSpeed = ChromaColour.getSpeed(colour); + int xChroma = mouseX - (x + 5 + 64 + valueOffset + opacityOffset + 5); + if (xChroma > 0 && xChroma < 10) { + if (chromaSpeed > 0) { + if (y > -5 && y <= 69) { + clickedComponent = 3; + } + } else if (mouseY > this.y + 5 + 27 && mouseY < this.y + 5 + 37) { + int currentColour = ChromaColour.specialToSimpleRGB(colour); + Color c = new Color(currentColour, true); + colour = ChromaColour.special(200, c.getAlpha(), currentColour); + colourChangedCallback.accept(colour); + } + } + } else { + hexField.unfocus(); + closeCallback.run(); + return false; + } + } + if (Mouse.isButtonDown(0) && clickedComponent >= 0) { + int currentColour = ChromaColour.specialToSimpleRGB(colour); + Color c = new Color(currentColour, true); + float[] hsv = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); + + float xWheel = mouseXF - x - 5; + float yWheel = mouseYF - y - 5; + + if (clickedComponent == 0) { + float angle = (float) Math.toDegrees(Math.atan((32 - xWheel) / (yWheel - 32 + 1E-5)) + Math.PI / 2); + xWheel = Math.max(0, Math.min(64, xWheel)); + yWheel = Math.max(0, Math.min(64, yWheel)); + float radius = (float) Math.sqrt(((xWheel - 32) * (xWheel - 32) + (yWheel - 32) * (yWheel - 32)) / 1024f); + if (yWheel < 32) angle += 180; + + this.wheelAngle = angle; + this.wheelRadius = (float) Math.pow(Math.min(1, radius), 1.5f); + int rgb = Color.getHSBColor(angle / 360f, wheelRadius, hsv[2]).getRGB(); + colour = ChromaColour.special(ChromaColour.getSpeed(colour), c.getAlpha(), rgb); + colourChangedCallback.accept(colour); + return true; + } + + float y = mouseYF - this.y - 5; + y = Math.max(0, Math.min(64, y)); + System.out.println(y); + + if (clickedComponent == 1) { + int rgb = Color.getHSBColor(wheelAngle / 360, wheelRadius, 1 - y / 64f).getRGB(); + colour = ChromaColour.special(ChromaColour.getSpeed(colour), c.getAlpha(), rgb); + colourChangedCallback.accept(colour); + return true; + } + + if (clickedComponent == 2) { + colour = ChromaColour.special(ChromaColour.getSpeed(colour), + 255 - Math.round(y / 64f * 255), currentColour + ); + colourChangedCallback.accept(colour); + return true; + } + + if (clickedComponent == 3) { + colour = ChromaColour.special(255 - Math.round(y / 64f * 255), c.getAlpha(), currentColour); + colourChangedCallback.accept(colour); + } + return true; + } + return false; + } + + public boolean keyboardInput() { + if (Keyboard.getEventKeyState() && hexField.getFocus()) { + if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) { + hexField.unfocus(); + return true; + } + String old = hexField.getText(); + + hexField.keyTyped(Keyboard.getEventCharacter(), Keyboard.getEventKey()); + + if (hexField.getText().length() > 6) { + hexField.setText(old); + } else { + try { + String text = hexField.getText().toLowerCase(); + + int rgb = Integer.parseInt(text, 16); + int alpha = (ChromaColour.specialToSimpleRGB(colour) >> 24) & 0xFF; + colour = ChromaColour.special(ChromaColour.getSpeed(colour), alpha, rgb); + colourChangedCallback.accept(colour); + + Color c = new Color(rgb); + float[] hsv = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); + updateAngleAndRadius(hsv); + } catch (Exception ignored) { + } + } + + return true; + } + return false; + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/GuiElementTextField.java b/src/main/java/at/hannibal2/skyhanni/config/core/GuiElementTextField.java new file mode 100644 index 000000000..3652f76f5 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/GuiElementTextField.java @@ -0,0 +1,685 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core; + +import at.hannibal2.skyhanni.config.core.util.render.TextRenderUtils; +import at.hannibal2.skyhanni.utils.StringUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.GuiTextField; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.GlStateManager; + +import java.awt.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class GuiElementTextField { + public static final int SCISSOR_TEXT = 0b10000000; + public static final int DISABLE_BG = 0b1000000; + public static final int SCALE_TEXT = 0b100000; + public static final int NUM_ONLY = 0b10000; + public static final int NO_SPACE = 0b01000; + public static final int FORCE_CAPS = 0b00100; + public static final int COLOUR = 0b00010; + public static final int MULTILINE = 0b00001; + + private int searchBarYSize; + private int searchBarXSize; + private static final int searchBarPadding = 2; + + private int options; + + private boolean focus = false; + + private int x; + private int y; + + private String prependText = ""; + private String masterStarUnicode = ""; + private int customTextColour = 0xffffffff; + + private final GuiTextField textField = new GuiTextField(0, Minecraft.getMinecraft().fontRendererObj, + 0, 0, 0, 0 + ); + + private int customBorderColour = -1; + + public GuiElementTextField(String initialText, int options) { + this(initialText, 100, 20, options); + } + + public GuiElementTextField(String initialText, int sizeX, int sizeY, int options) { + textField.setFocused(true); + textField.setCanLoseFocus(false); + textField.setMaxStringLength(999); + textField.setText(initialText); + this.searchBarXSize = sizeX; + this.searchBarYSize = sizeY; + this.options = options; + } + + public void setMaxStringLength(int len) { + textField.setMaxStringLength(len); + } + + public void setCustomBorderColour(int colour) { + this.customBorderColour = colour; + } + + public void setCustomTextColour(int colour) { + this.customTextColour = colour; + } + + public String getText() { + return textField.getText(); + } + + public String getTextDisplay() { + String textNoColour = getText(); + while (true) { + Matcher matcher = PATTERN_CONTROL_CODE.matcher(textNoColour); + if (!matcher.find()) break; + String code = matcher.group(1); + textNoColour = matcher.replaceFirst("\u00B6" + code); + } + + return textNoColour; + } + + public void setPrependText(String text) { + this.prependText = text; + } + + public void setText(String text) { + if (textField.getText() == null || !textField.getText().equals(text)) { + textField.setText(text); + } + } + + public void setSize(int searchBarXSize, int searchBarYSize) { + this.searchBarXSize = searchBarXSize; + this.searchBarYSize = searchBarYSize; + } + + public void setOptions(int options) { + this.options = options; + } + + @Override + public String toString() { + return textField.getText(); + } + + public void setFocus(boolean focus) { + this.focus = focus; + if (!focus) { + textField.setCursorPosition(textField.getCursorPosition()); + } + } + + public boolean getFocus() { + return focus; + } + + public int getHeight() { + ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); + int paddingUnscaled = searchBarPadding / scaledresolution.getScaleFactor(); + + int numLines = org.apache.commons.lang3.StringUtils.countMatches(textField.getText(), "\n") + 1; + int extraSize = (searchBarYSize - 8) / 2 + 8; + int bottomTextBox = searchBarYSize + extraSize * (numLines - 1); + + return bottomTextBox + paddingUnscaled * 2; + } + + public int getWidth() { + ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); + int paddingUnscaled = searchBarPadding / scaledresolution.getScaleFactor(); + + return searchBarXSize + paddingUnscaled * 2; + } + + private float getScaleFactor(String str) { + return Math.min(1, (searchBarXSize - 2) / (float) Minecraft.getMinecraft().fontRendererObj.getStringWidth(str)); + } + + private boolean isScaling() { + return (options & SCALE_TEXT) != 0; + } + + private static final Pattern PATTERN_CONTROL_CODE = Pattern.compile("(?i)\\u00A7([^\\u00B6]|$)(?!\\u00B6)"); + + public int getCursorPos(int mouseX, int mouseY) { + int xComp = mouseX - x; + int yComp = mouseY - y; + + int extraSize = (searchBarYSize - 8) / 2 + 8; + + String renderText = prependText + textField.getText(); + + int lineNum = Math.round(((yComp - (searchBarYSize - 8) / 2)) / extraSize); + + String text = renderText; + String textNoColour = renderText; + if ((options & COLOUR) != 0) { + while (true) { + Matcher matcher = PATTERN_CONTROL_CODE.matcher(text); + if (!matcher.find() || matcher.groupCount() < 1) break; + String code = matcher.group(1); + if (code.isEmpty()) { + text = matcher.replaceFirst("\u00A7r\u00B6"); + } else { + text = matcher.replaceFirst("\u00A7" + code + "\u00B6" + code); + } + } + } + while (true) { + Matcher matcher = PATTERN_CONTROL_CODE.matcher(textNoColour); + if (!matcher.find() || matcher.groupCount() < 1) break; + String code = matcher.group(1); + textNoColour = matcher.replaceFirst("\u00B6" + code); + } + + int currentLine = 0; + int cursorIndex = 0; + for (; cursorIndex < textNoColour.length(); cursorIndex++) { + if (currentLine == lineNum) break; + if (textNoColour.charAt(cursorIndex) == '\n') { + currentLine++; + } + } + + String textNC = textNoColour.substring(0, cursorIndex); + int colorCodes = org.apache.commons.lang3.StringUtils.countMatches(textNC, "\u00B6"); + String line = text.substring(cursorIndex + (((options & COLOUR) != 0) ? colorCodes * 2 : 0)).split("\n")[0]; + int padding = Math.min(5, searchBarXSize - strLenNoColor(line)) / 2; + String trimmed = Minecraft.getMinecraft().fontRendererObj.trimStringToWidth(line, xComp - padding); + int linePos = strLenNoColor(trimmed); + if (linePos != strLenNoColor(line)) { + char after = line.charAt(linePos); + int trimmedWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(trimmed); + int charWidth = Minecraft.getMinecraft().fontRendererObj.getCharWidth(after); + if (trimmedWidth + charWidth / 2 < xComp - padding) { + linePos++; + } + } + cursorIndex += linePos; + + int pre = StringUtils.INSTANCE.removeColor(prependText).length(); + if (cursorIndex < pre) { + cursorIndex = 0; + } else { + cursorIndex -= pre; + } + + return cursorIndex; + } + + public void mouseClicked(int mouseX, int mouseY, int mouseButton) { + if (mouseButton == 1) { + textField.setText(""); + } else { + textField.setCursorPosition(getCursorPos(mouseX, mouseY)); + } + focus = true; + } + + public void unfocus() { + focus = false; + textField.setSelectionPos(textField.getCursorPosition()); + } + + public int strLenNoColor(String str) { + return str.replaceAll("(?i)\\u00A7.", "").length(); + } + + public void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { + if (focus) { + textField.setSelectionPos(getCursorPos(mouseX, mouseY)); + } + } + + public void keyTyped(char typedChar, int keyCode) { + if (focus) { + if ((options & MULTILINE) != 0) { //Carriage return + Pattern patternControlCode = Pattern.compile("(?i)\\u00A7([^\\u00B6\n]|$)(?!\\u00B6)"); + + String text = textField.getText(); + String textNoColour = textField.getText(); + while (true) { + Matcher matcher = patternControlCode.matcher(text); + if (!matcher.find() || matcher.groupCount() < 1) break; + String code = matcher.group(1); + if (code.isEmpty()) { + text = matcher.replaceFirst("\u00A7r\u00B6"); + } else { + text = matcher.replaceFirst("\u00A7" + code + "\u00B6" + code); + } + } + while (true) { + Matcher matcher = patternControlCode.matcher(textNoColour); + if (!matcher.find() || matcher.groupCount() < 1) break; + String code = matcher.group(1); + textNoColour = matcher.replaceFirst("\u00B6" + code); + } + + if (keyCode == 28) { + String before = textField.getText().substring(0, textField.getCursorPosition()); + String after = textField.getText().substring(textField.getCursorPosition()); + int pos = textField.getCursorPosition(); + textField.setText(before + "\n" + after); + textField.setCursorPosition(pos + 1); + return; + } else if (keyCode == 200) { //Up + String textNCBeforeCursor = textNoColour.substring(0, textField.getSelectionEnd()); + int colorCodes = org.apache.commons.lang3.StringUtils.countMatches(textNCBeforeCursor, "\u00B6"); + String textBeforeCursor = text.substring(0, textField.getSelectionEnd() + colorCodes * 2); + + int numLinesBeforeCursor = org.apache.commons.lang3.StringUtils.countMatches(textBeforeCursor, "\n"); + + String[] split = textBeforeCursor.split("\n"); + int textBeforeCursorWidth; + String lineBefore; + String thisLineBeforeCursor; + if (split.length == numLinesBeforeCursor && split.length > 0) { + textBeforeCursorWidth = 0; + lineBefore = split[split.length - 1]; + thisLineBeforeCursor = ""; + } else if (split.length > 1) { + thisLineBeforeCursor = split[split.length - 1]; + lineBefore = split[split.length - 2]; + textBeforeCursorWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(thisLineBeforeCursor); + } else { + return; + } + String trimmed = Minecraft.getMinecraft().fontRendererObj + .trimStringToWidth(lineBefore, textBeforeCursorWidth); + int linePos = strLenNoColor(trimmed); + if (linePos != strLenNoColor(lineBefore)) { + char after = lineBefore.charAt(linePos); + int trimmedWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(trimmed); + int charWidth = Minecraft.getMinecraft().fontRendererObj.getCharWidth(after); + if (trimmedWidth + charWidth / 2 < textBeforeCursorWidth) { + linePos++; + } + } + int newPos = textField.getSelectionEnd() - strLenNoColor(thisLineBeforeCursor) + - strLenNoColor(lineBefore) - 1 + linePos; + + if (GuiScreen.isShiftKeyDown()) { + textField.setSelectionPos(newPos); + } else { + textField.setCursorPosition(newPos); + } + } else if (keyCode == 208) { //Down + String textNCBeforeCursor = textNoColour.substring(0, textField.getSelectionEnd()); + int colorCodes = org.apache.commons.lang3.StringUtils.countMatches(textNCBeforeCursor, "\u00B6"); + String textBeforeCursor = text.substring(0, textField.getSelectionEnd() + colorCodes * 2); + + int numLinesBeforeCursor = org.apache.commons.lang3.StringUtils.countMatches(textBeforeCursor, "\n"); + + String[] split = textBeforeCursor.split("\n"); + String thisLineBeforeCursor; + int textBeforeCursorWidth; + if (split.length == numLinesBeforeCursor) { + thisLineBeforeCursor = ""; + textBeforeCursorWidth = 0; + } else if (split.length > 0) { + thisLineBeforeCursor = split[split.length - 1]; + textBeforeCursorWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(thisLineBeforeCursor); + } else { + return; + } + + String[] split2 = textNoColour.split("\n"); + if (split2.length > numLinesBeforeCursor + 1) { + String lineAfter = split2[numLinesBeforeCursor + 1]; + String trimmed = Minecraft.getMinecraft().fontRendererObj + .trimStringToWidth(lineAfter, textBeforeCursorWidth); + int linePos = strLenNoColor(trimmed); + if (linePos != strLenNoColor(lineAfter)) { + char after = lineAfter.charAt(linePos); + int trimmedWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(trimmed); + int charWidth = Minecraft.getMinecraft().fontRendererObj.getCharWidth(after); + if (trimmedWidth + charWidth / 2 < textBeforeCursorWidth) { + linePos++; + } + } + int newPos = textField.getSelectionEnd() - strLenNoColor(thisLineBeforeCursor) + + strLenNoColor(split2[numLinesBeforeCursor]) + 1 + linePos; + + if (GuiScreen.isShiftKeyDown()) { + textField.setSelectionPos(newPos); + } else { + textField.setCursorPosition(newPos); + } + } + } + } + + String old = textField.getText(); + if ((options & FORCE_CAPS) != 0) typedChar = Character.toUpperCase(typedChar); + if ((options & NO_SPACE) != 0 && typedChar == ' ') return; + + if (typedChar == '\u00B6') { + typedChar = '\u00A7'; + } + + textField.setFocused(true); + textField.textboxKeyTyped(typedChar, keyCode); + + if ((options & COLOUR) != 0) { + if (typedChar == '&') { + int pos = textField.getCursorPosition() - 2; + if (pos >= 0 && pos < textField.getText().length()) { + if (textField.getText().charAt(pos) == '&') { + String before = textField.getText().substring(0, pos); + String after = ""; + if (pos + 2 < textField.getText().length()) { + after = textField.getText().substring(pos + 2); + } + textField.setText(before + "\u00A7" + after); + textField.setCursorPosition(pos + 1); + } + } + } else if (typedChar == '*') { + int pos = textField.getCursorPosition() - 2; + if (pos >= 0 && pos < textField.getText().length()) { + if (textField.getText().charAt(pos) == '*') { + String before = textField.getText().substring(0, pos); + String after = ""; + if (pos + 2 < textField.getText().length()) { + after = textField.getText().substring(pos + 2); + } + textField.setText(before + "\u272A" + after); + textField.setCursorPosition(pos + 1); + } + } + } else { + for (int i = 0; i < 10; i++) { + if (typedChar == Integer.toString(i + 1).charAt(0)) { + int pos = textField.getCursorPosition() - 2; + if (pos >= 0 && pos < textField.getText().length()) { + if (textField.getText().charAt(pos) == '*') { + switch (i) { + case 0: + masterStarUnicode = "\u278A"; + break; + case 1: + masterStarUnicode = "\u278B"; + break; + case 2: + masterStarUnicode = "\u278C"; + break; + case 3: + masterStarUnicode = "\u278D"; + break; + case 4: + masterStarUnicode = "\u278E"; + break; + case 5: + masterStarUnicode = "\u278F"; + break; + case 6: + masterStarUnicode = "\u2790"; + break; + case 7: + masterStarUnicode = "\u2791"; + break; + case 8: + masterStarUnicode = "\u2792"; + break; + case 9: + masterStarUnicode = "\u2793"; + break; + } + String before = textField.getText().substring(0, pos); + String after = ""; + if (pos + 2 < textField.getText().length()) { + after = textField.getText().substring(pos + 2); + } + textField.setText(before + masterStarUnicode + after); + textField.setCursorPosition(pos + 1); + } + } + } + } + } + } + + if ((options & NUM_ONLY) != 0 && textField.getText().matches("[^0-9.]")) textField.setText(old); + } + } + + public void render(int x, int y) { + this.x = x; + this.y = y; + drawTextbox(x, y, searchBarXSize, searchBarYSize, searchBarPadding, textField, focus); + } + + private void drawTextbox( + int x, int y, int searchBarXSize, int searchBarYSize, int searchBarPadding, + GuiTextField textField, boolean focus + ) { + ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); + String renderText = prependText + textField.getText(); + + GlStateManager.disableLighting(); + + /* + * Search bar + */ + int paddingUnscaled = searchBarPadding / scaledresolution.getScaleFactor(); + if (paddingUnscaled < 1) paddingUnscaled = 1; + + int numLines = org.apache.commons.lang3.StringUtils.countMatches(renderText, "\n") + 1; + int extraSize = (searchBarYSize - 8) / 2 + 8; + int bottomTextBox = y + searchBarYSize + extraSize * (numLines - 1); + + int borderColour = focus ? Color.GREEN.getRGB() : Color.WHITE.getRGB(); + if (customBorderColour != -1) { + borderColour = customBorderColour; + } + if ((options & DISABLE_BG) == 0) { + //bar background + Gui.drawRect(x - paddingUnscaled, + y - paddingUnscaled, + x + searchBarXSize + paddingUnscaled, + bottomTextBox + paddingUnscaled, borderColour + ); + Gui.drawRect(x, + y, + x + searchBarXSize, + bottomTextBox, Color.BLACK.getRGB() + ); + } + + //bar text + String text = renderText; + String textNoColor = renderText; + if ((options & COLOUR) != 0) { + while (true) { + Matcher matcher = PATTERN_CONTROL_CODE.matcher(text); + if (!matcher.find() || matcher.groupCount() < 1) break; + String code = matcher.group(1); + if (code.isEmpty()) { + text = matcher.replaceFirst("\u00A7r\u00B6"); + } else { + text = matcher.replaceFirst("\u00A7" + code + "\u00B6" + code); + } + } + } + while (true) { + Matcher matcher = PATTERN_CONTROL_CODE.matcher(textNoColor); + if (!matcher.find() || matcher.groupCount() < 1) break; + String code = matcher.group(1); + textNoColor = matcher.replaceFirst("\u00B6" + code); + } + + int xStartOffset = 5; + float scale = 1; + String[] texts = text.split("\n"); + for (int yOffI = 0; yOffI < texts.length; yOffI++) { + int yOff = yOffI * extraSize; + + if (isScaling() && Minecraft.getMinecraft().fontRendererObj.getStringWidth(texts[yOffI]) > searchBarXSize - 10) { + scale = (searchBarXSize - 2) / (float) Minecraft.getMinecraft().fontRendererObj.getStringWidth(texts[yOffI]); + if (scale > 1) scale = 1; + float newLen = Minecraft.getMinecraft().fontRendererObj.getStringWidth(texts[yOffI]) * scale; + xStartOffset = (int) ((searchBarXSize - newLen) / 2f); + + TextRenderUtils.drawStringCenteredScaledMaxWidth( +// ChromaUtils.INSTANCE.chromaStringByColourCode(texts[yOffI]), + texts[yOffI], + Minecraft.getMinecraft().fontRendererObj, + x + searchBarXSize / 2f, + y + searchBarYSize / 2f + yOff, + false, + searchBarXSize - 2, + customTextColour + ); + } else { + if ((options & SCISSOR_TEXT) != 0) { + GlScissorStack.push(x + 5, 0, x + searchBarXSize, scaledresolution.getScaledHeight(), scaledresolution); +// Minecraft.getMinecraft().fontRendererObj.drawString(ChromaUtils.INSTANCE.chromaStringByColourCode(texts[yOffI]), x + 5, + Minecraft.getMinecraft().fontRendererObj.drawString(texts[yOffI], x + 5, + y + (searchBarYSize - 8) / 2 + yOff, customTextColour + ); + GlScissorStack.pop(scaledresolution); + } else { +// String toRender = Minecraft.getMinecraft().fontRendererObj.trimStringToWidth(ChromaUtils.INSTANCE.chromaStringByColourCode( + String toRender = Minecraft.getMinecraft().fontRendererObj.trimStringToWidth(texts[yOffI], searchBarXSize - 10); + Minecraft.getMinecraft().fontRendererObj.drawString(toRender, x + 5, + y + (searchBarYSize - 8) / 2 + yOff, customTextColour + ); + } + + } + } + + if (focus && System.currentTimeMillis() % 1000 > 500) { + String textNCBeforeCursor = textNoColor.substring(0, textField.getCursorPosition() + prependText.length()); + int colorCodes = org.apache.commons.lang3.StringUtils.countMatches(textNCBeforeCursor, "\u00B6"); + String textBeforeCursor = text.substring( + 0, + Math.min( + text.length(), + textField.getCursorPosition() + prependText.length() + (((options & COLOUR) != 0) ? colorCodes * 2 : 0) + ) + ); + + int numLinesBeforeCursor = org.apache.commons.lang3.StringUtils.countMatches(textBeforeCursor, "\n"); + int yOff = numLinesBeforeCursor * extraSize; + + String[] split = textBeforeCursor.split("\n"); + int textBeforeCursorWidth; + if (split.length <= numLinesBeforeCursor || split.length == 0) { + textBeforeCursorWidth = 0; + } else { + textBeforeCursorWidth = (int) (Minecraft.getMinecraft().fontRendererObj.getStringWidth(split[split.length - + 1]) * scale); + } + Gui.drawRect(x + xStartOffset + textBeforeCursorWidth, + y + (searchBarYSize - 8) / 2 - 1 + yOff, + x + xStartOffset + textBeforeCursorWidth + 1, + y + (searchBarYSize - 8) / 2 + 9 + yOff, Color.WHITE.getRGB() + ); + } + + String selectedText = textField.getSelectedText(); + if (!selectedText.isEmpty()) { + int leftIndex = Math.min( + textField.getCursorPosition() + prependText.length(), + textField.getSelectionEnd() + prependText.length() + ); + int rightIndex = Math.max( + textField.getCursorPosition() + prependText.length(), + textField.getSelectionEnd() + prependText.length() + ); + + float texX = 0; + int texY = 0; + boolean sectionSignPrev = false; + boolean ignoreNext = false; + boolean bold = false; + for (int i = 0; i < textNoColor.length(); i++) { + if (ignoreNext) { + ignoreNext = false; + continue; + } + + char c = textNoColor.charAt(i); + if (sectionSignPrev) { + if (c != 'k' && c != 'K' + && c != 'm' && c != 'M' + && c != 'n' && c != 'N' + && c != 'o' && c != 'O') { + bold = c == 'l' || c == 'L'; + } + sectionSignPrev = false; + if (i < prependText.length()) continue; + } + if (c == '\u00B6') { + sectionSignPrev = true; + if (i < prependText.length()) continue; + } + + if (c == '\n') { + if (i >= leftIndex && i < rightIndex) { + Gui.drawRect(x + xStartOffset + (int) texX, + y + (searchBarYSize - 8) / 2 - 1 + texY, + x + xStartOffset + (int) texX + 3, + y + (searchBarYSize - 8) / 2 + 9 + texY, Color.LIGHT_GRAY.getRGB() + ); + } + + texX = 0; + texY += extraSize; + continue; + } + + int len = Minecraft.getMinecraft().fontRendererObj.getStringWidth(String.valueOf(c)); + if (bold) len++; + if (i >= leftIndex && i < rightIndex) { + Gui.drawRect(x + xStartOffset + (int) texX, + y + (searchBarYSize - 8) / 2 - 1 + texY, + x + xStartOffset + (int) (texX + len * scale), + y + (searchBarYSize - 8) / 2 + 9 + texY, Color.LIGHT_GRAY.getRGB() + ); + + TextRenderUtils.drawStringScaled(String.valueOf(c), Minecraft.getMinecraft().fontRendererObj, + x + xStartOffset + texX, + y + searchBarYSize / 2f - scale * 8 / 2f + texY, false, Color.BLACK.getRGB(), scale + ); + if (bold) { + TextRenderUtils.drawStringScaled(String.valueOf(c), Minecraft.getMinecraft().fontRendererObj, + x + xStartOffset + texX + 1, + y + searchBarYSize / 2f - scale * 8 / 2f + texY, false, Color.BLACK.getRGB(), scale + ); + } + } + + texX += len * scale; + } + } + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/GuiScreenElementWrapper.java b/src/main/java/at/hannibal2/skyhanni/config/core/GuiScreenElementWrapper.java new file mode 100644 index 000000000..beef55c70 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/GuiScreenElementWrapper.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core; + +import net.minecraft.client.gui.GuiScreen; +import org.lwjgl.input.Mouse; + +import java.io.IOException; + +public class GuiScreenElementWrapper extends GuiScreen { + public final GuiElement element; + + public GuiScreenElementWrapper(GuiElement element) { + this.element = element; + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + super.drawScreen(mouseX, mouseY, partialTicks); + element.render(); + } + + @Override + public void handleMouseInput() throws IOException { + super.handleMouseInput(); + int i = Mouse.getEventX() * this.width / this.mc.displayWidth; + int j = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1; + element.mouseInput(i, j); + } + + @Override + public void handleKeyboardInput() throws IOException { + super.handleKeyboardInput(); + element.keyboardInput(); + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/Config.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/Config.java new file mode 100644 index 000000000..4c9ff0d9c --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/Config.java @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.config; + +public class Config { + public void executeRunnable(String runnableId) {} +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/GuiPositionEditor.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/GuiPositionEditor.java new file mode 100644 index 000000000..abbb60646 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/GuiPositionEditor.java @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.config; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.ScaledResolution; + +import java.io.IOException; + +public class GuiPositionEditor extends GuiScreen { + public PositionNew position = new PositionNew(); + + public int clickedX; + public int clickedY; + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + super.drawDefaultBackground(); + + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + int width = scaledResolution.getScaledWidth(); + int height = scaledResolution.getScaledHeight(); + + int x = position.resolveX(scaledResolution, 200); + int y = position.resolveY(scaledResolution, 100); + + int centerWidth = 176; + int centerHeight = 166; + + float centerWF = centerWidth / 2f / (float) width; + float centerHF = centerHeight / 2f / (float) height; + + float left = 0; + float top = 0; + float right = 0; + float bottom = 0; + + switch (position.getAnchorX()) { + case MIN: { + left = 0; + right = 0.5f - centerWF; + break; + } + case MID: { + left = 0.5f - centerWF; + right = 0.5f + centerWF; + break; + } + case MAX: { + left = 0.5f + centerWF; + right = 1; + break; + } + } + switch (position.getAnchorY()) { + case MIN: { + top = 0; + bottom = 0.5f - centerHF; + break; + } + case MID: { + top = 0.5f - centerHF; + bottom = 0.5f + centerHF; + break; + } + case MAX: { + top = 0.5f + centerHF; + bottom = 1; + break; + } + } + + Gui.drawRect( + (int) (left * width), + (int) (top * height), + (int) (right * width), + (int) (bottom * height), + 0x40404040 + ); + Gui.drawRect(x, y, x + 200, y + 100, 0x80404040); + } + + @Override + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + int x = position.resolveX(scaledResolution, 200); + int y = position.resolveY(scaledResolution, 100); + + if (mouseX > x && mouseX < x + 200 && + mouseY > y && mouseY < y + 100) { + clickedX = mouseX; + clickedY = mouseY; + } else { + clickedX = -1; + clickedY = -1; + } + } + + @Override + protected void mouseReleased(int mouseX, int mouseY, int state) { + clickedX = -1; + clickedY = -1; + } + + @Override + protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { + if (clickedX >= 0 && clickedY >= 0) { + int deltaX = mouseX - clickedX; + int deltaY = mouseY - clickedY; + + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + + deltaX = position.moveX(scaledResolution, deltaX, 200); + deltaY = position.moveY(scaledResolution, deltaY, 100); + + clickedX += deltaX; + clickedY += deltaY; + } + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/KeybindHelper.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/KeybindHelper.java new file mode 100644 index 000000000..0253f360a --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/KeybindHelper.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.config; + +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; + +public class KeybindHelper { + public static String getKeyName(int keyCode) { + if (keyCode == 0) { + return "NONE"; + } else if (keyCode < 0) { + return "Button " + (keyCode + 101); + } else { + String keyName = Keyboard.getKeyName(keyCode); + if (keyName == null) { + keyName = "???"; + } else if (keyName.equalsIgnoreCase("LMENU")) { + keyName = "LALT"; + } else if (keyName.equalsIgnoreCase("RMENU")) { + keyName = "RALT"; + } + return keyName; + } + } + + public static boolean isKeyValid(int keyCode) { + return keyCode != 0; + } + + public static boolean isKeyDown(int keyCode) { + if (!isKeyValid(keyCode)) { + return false; + } else if (keyCode < 0) { + return Mouse.isButtonDown(keyCode + 100); + } else { + return Keyboard.isKeyDown(keyCode); + } + } + + public static boolean isKeyPressed(int keyCode) { + if (!isKeyValid(keyCode)) { + return false; + } else if (keyCode < 0) { + return Mouse.getEventButtonState() && Mouse.getEventButton() == keyCode + 100; + } else { + return Keyboard.getEventKeyState() && Keyboard.getEventKey() == keyCode; + } + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/Position.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/Position.java new file mode 100644 index 000000000..91032ff1f --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/Position.java @@ -0,0 +1,208 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.config; + +import com.google.gson.annotations.Expose; +import net.minecraft.client.gui.ScaledResolution; + +public class Position { + @Expose + private int x; + @Expose + private int y; + @Expose + private boolean centerX; + @Expose + private boolean centerY; + + private static final int EDGE_OFFSET = 0; + + public Position(int x, int y) { + this(x, y, false, false); + } + + public Position(int x, int y, boolean centerX, boolean centerY) { + this.x = x; + this.y = y; + this.centerX = centerX; + this.centerY = centerY; + } + + public void set(Position other) { + this.x = other.x; + this.y = other.y; + this.centerX = other.centerX; + this.centerY = other.centerY; + } + + public Position clone() { + return new Position(x, y, centerX, centerY); + } + + public boolean isCenterX() { + return centerX; + } + + public boolean isCenterY() { + return centerY; + } + + public int getRawX() { + return x; + } + + public int getRawY() { + return y; + } + + public int getAbsX(ScaledResolution scaledResolution, int objWidth) { + int width = scaledResolution.getScaledWidth(); + + if (centerX) { + return width / 2 + x; + } + + int ret = x; + if (x < 0) { + ret = width + x - objWidth; + } + + if (ret < 0) ret = 0; + if (ret > width - objWidth) ret = width - objWidth; + + return ret; + } + + public int getAbsY(ScaledResolution scaledResolution, int objHeight) { + int height = scaledResolution.getScaledHeight(); + + if (centerY) { + return height / 2 + y; + } + + int ret = y; + if (y < 0) { + ret = height + y - objHeight; + } + + if (ret < 0) ret = 0; + if (ret > height - objHeight) ret = height - objHeight; + + return ret; + } + + public int moveX(int deltaX, int objWidth, ScaledResolution scaledResolution) { + int screenWidth = scaledResolution.getScaledWidth(); + boolean wasPositiveX = this.x >= 0; + this.x += deltaX; + + if (centerX) { + if (wasPositiveX) { + if (this.x > screenWidth / 2 - objWidth / 2) { + deltaX += screenWidth / 2 - objWidth / 2 - this.x; + this.x = screenWidth / 2 - objWidth / 2; + } + } else { + if (this.x < -screenWidth / 2 + objWidth / 2) { + deltaX += -screenWidth / 2 + objWidth / 2 - this.x; + this.x = -screenWidth / 2 + objWidth / 2; + } + } + return deltaX; + } + + if (wasPositiveX) { + if (this.x < EDGE_OFFSET) { + deltaX += EDGE_OFFSET - this.x; + this.x = EDGE_OFFSET; + } + if (this.x > screenWidth - EDGE_OFFSET) { + deltaX += screenWidth - EDGE_OFFSET - this.x; + this.x = screenWidth - EDGE_OFFSET; + } + } else { + if (this.x + 1 > -EDGE_OFFSET) { + deltaX += -EDGE_OFFSET - 1 - this.x; + this.x = -EDGE_OFFSET - 1; + } + if (this.x + screenWidth < EDGE_OFFSET) { + deltaX += EDGE_OFFSET - screenWidth - this.x; + this.x = EDGE_OFFSET - screenWidth; + } + } + + if (this.x >= 0 && this.x + objWidth / 2 > screenWidth / 2) { + this.x -= screenWidth - objWidth; + } + if (this.x < 0 && this.x + objWidth / 2 <= -screenWidth / 2) { + this.x += screenWidth - objWidth; + } + return deltaX; + } + + public int moveY(int deltaY, int objHeight, ScaledResolution scaledResolution) { + int screenHeight = scaledResolution.getScaledHeight(); + boolean wasPositiveY = this.y >= 0; + this.y += deltaY; + + if (centerY) { + if (wasPositiveY) { + if (this.y > screenHeight / 2 - objHeight / 2) { + deltaY += screenHeight / 2 - objHeight / 2 - this.y; + this.y = screenHeight / 2 - objHeight / 2; + } + } else { + if (this.y < -screenHeight / 2 + objHeight / 2) { + deltaY += -screenHeight / 2 + objHeight / 2 - this.y; + this.y = -screenHeight / 2 + objHeight / 2; + } + } + return deltaY; + } + + if (wasPositiveY) { + if (this.y < EDGE_OFFSET) { + deltaY += EDGE_OFFSET - this.y; + this.y = EDGE_OFFSET; + } + if (this.y > screenHeight - EDGE_OFFSET) { + deltaY += screenHeight - EDGE_OFFSET - this.y; + this.y = screenHeight - EDGE_OFFSET; + } + } else { + if (this.y + 1 > -EDGE_OFFSET) { + deltaY += -EDGE_OFFSET - 1 - this.y; + this.y = -EDGE_OFFSET - 1; + } + if (this.y + screenHeight < EDGE_OFFSET) { + deltaY += EDGE_OFFSET - screenHeight - this.y; + this.y = EDGE_OFFSET - screenHeight; + } + } + + if (this.y >= 0 && this.y - objHeight / 2 > screenHeight / 2) { + this.y -= screenHeight - objHeight; + } + if (this.y < 0 && this.y - objHeight / 2 <= -screenHeight / 2) { + this.y += screenHeight - objHeight; + } + return deltaY; + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/PositionNew.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/PositionNew.java new file mode 100644 index 000000000..fb7127058 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/PositionNew.java @@ -0,0 +1,211 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.config; + +import com.google.gson.annotations.Expose; +import net.minecraft.client.gui.ScaledResolution; + +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; + +public class PositionNew { + public enum Anchor { + MIN(0, 0, 0), + MID(0.5f, -0.5f, 0), + MAX(1f, -1f, 0), + GUI_MIN(0.5f, -1f, -0.5f), + GUI_MAX(0.5f, 0, 0.5f); + + float screenMult; + float elementMult; + float guiMult; + + Anchor(float screenMult, float elementMult, float guiMult) { + this.screenMult = screenMult; + this.elementMult = elementMult; + this.guiMult = guiMult; + } + } + + @Expose + private int x = 0; + @Expose + private int y = 0; + @Expose + private float scaleX = 1; + @Expose + private float scaleY = 1; + + @Expose + private Anchor anchorX = Anchor.MIN; + @Expose + private Anchor anchorY = Anchor.MIN; + + @Expose + private boolean pinned = false; + @Expose + private boolean allowPinToggle = true; + @Expose + private boolean allowResize = true; + + public PositionNew( + int x, + int y, + int scaleX, + int scaleY, + Anchor anchorX, + Anchor anchorY, + boolean pinned, + boolean allowPinToggle, + boolean allowResize + ) { + this.x = x; + this.y = y; + this.scaleX = scaleX; + this.scaleY = scaleY; + this.anchorX = anchorX; + this.anchorY = anchorY; + this.pinned = pinned; + this.allowPinToggle = allowPinToggle; + this.allowResize = allowResize; + } + + protected PositionNew() {} + + public int moveX(ScaledResolution scaledResolution, int deltaX, int sizeX) { + int originalX = resolveX(scaledResolution, sizeX); + AtomicInteger atomicInteger = new AtomicInteger(x + deltaX); + AtomicReference<Anchor> atomicReference = new AtomicReference<>(anchorX); + move( + atomicInteger, + atomicReference, + anchorY, + (int) Math.ceil(sizeX * scaleX), + scaledResolution.getScaledWidth(), + 176 + ); + x = atomicInteger.get(); + anchorX = atomicReference.get(); + return resolveX(scaledResolution, sizeX) - originalX; + } + + public int moveY(ScaledResolution scaledResolution, int deltaY, int sizeY) { + int originalY = resolveY(scaledResolution, sizeY); + AtomicInteger atomicInteger = new AtomicInteger(y + deltaY); + AtomicReference<Anchor> atomicReference = new AtomicReference<>(anchorY); + move( + atomicInteger, + atomicReference, + anchorY, + (int) Math.ceil(sizeY * scaleY), + scaledResolution.getScaledHeight(), + 166 + ); + y = atomicInteger.get(); + anchorY = atomicReference.get(); + return resolveY(scaledResolution, sizeY) - originalY; + } + + private void move( + AtomicInteger coord, + AtomicReference<Anchor> anchor, + Anchor oppositeAnchor, + int elementSize, + int screenSize, + int guiSize + ) { + int centerCoord = resolve(coord.get(), anchor.get(), elementSize, screenSize, guiSize) + elementSize / 2; + + if (centerCoord < screenSize / 2 - guiSize / 2) { + if (pinned && centerCoord > screenSize / 4 - guiSize / 4 && oppositeAnchor == Anchor.MID) { + anchor.set(Anchor.GUI_MIN); + } else { + anchor.set(Anchor.MIN); + } + } else if (centerCoord > screenSize / 2 + guiSize / 2) { + if (pinned && centerCoord < screenSize - (screenSize / 4 - guiSize / 4) && oppositeAnchor == Anchor.MID) { + anchor.set(Anchor.GUI_MAX); + } else { + anchor.set(Anchor.MAX); + } + } else { + anchor.set(Anchor.MID); + } + + if (centerCoord - elementSize / 2 < 0) centerCoord = elementSize / 2; + if (centerCoord + elementSize / 2 > screenSize) centerCoord = screenSize - elementSize / 2; + + Anchor newAnchor = anchor.get(); + coord.set(Math.round( + centerCoord - (elementSize * (newAnchor.elementMult + 0.5f)) - screenSize * newAnchor.screenMult - + guiSize * newAnchor.guiMult)); + } + + public int resolveX(ScaledResolution scaledResolution, int sizeX) { + return resolve(x, anchorX, (int) Math.ceil(sizeX * scaleX), scaledResolution.getScaledWidth(), 176); + } + + public int resolveY(ScaledResolution scaledResolution, int sizeY) { + return resolve(y, anchorY, (int) Math.ceil(sizeY * scaleY), scaledResolution.getScaledHeight(), 166); + } + + private int resolve(int coord, Anchor anchor, int elementSize, int screenSize, int guiSize) { + return Math.round( + screenSize * anchor.screenMult + elementSize * anchor.elementMult + guiSize * anchor.guiMult + coord); + } + + public void setScaleX(float scaleX) { + if (allowResize) { + this.scaleX = scaleX; + } + } + + public void setScaleY(float scaleY) { + if (allowResize) { + this.scaleY = scaleY; + } + } + + public float getScaleX() { + return scaleX; + } + + public float getScaleY() { + return scaleY; + } + + public void setPinned(boolean pinned) { + if (allowPinToggle) { + this.pinned = pinned; + } + } + + public boolean isPinned() { + return pinned; + } + + public Anchor getAnchorX() { + return anchorX; + } + + public Anchor getAnchorY() { + return anchorY; + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/Category.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/Category.java new file mode 100644 index 000000000..5f9ce4b14 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/Category.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.config.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface Category { + String name(); + + String desc(); +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigAccordionId.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigAccordionId.java new file mode 100644 index 000000000..8948238c8 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigAccordionId.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.config.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface ConfigAccordionId { + int id(); +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigEditorAccordion.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigEditorAccordion.java new file mode 100644 index 000000000..36d73ad2c --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigEditorAccordion.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.config.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface ConfigEditorAccordion { + int id(); +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigEditorBoolean.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigEditorBoolean.java new file mode 100644 index 000000000..aae6e4063 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigEditorBoolean.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.config.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface ConfigEditorBoolean { + String runnableId() default ""; +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigEditorButton.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigEditorButton.java new file mode 100644 index 000000000..439844616 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigEditorButton.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.config.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface ConfigEditorButton { + String runnableId(); + + String buttonText() default ""; +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigEditorColour.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigEditorColour.java new file mode 100644 index 000000000..3811cf9df --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigEditorColour.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.config.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface ConfigEditorColour {} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigEditorDraggableList.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigEditorDraggableList.java new file mode 100644 index 000000000..f4870a2de --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigEditorDraggableList.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.config.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface ConfigEditorDraggableList { + String[] exampleText(); + + boolean allowDeleting() default true; +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigEditorDropdown.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigEditorDropdown.java new file mode 100644 index 000000000..383a65332 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigEditorDropdown.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.config.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface ConfigEditorDropdown { + String[] values(); + + int initialIndex() default 0; +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigEditorFSR.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigEditorFSR.java new file mode 100644 index 000000000..ab3932a13 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigEditorFSR.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.config.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface ConfigEditorFSR { + String runnableId(); + + String buttonText() default ""; +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigEditorKeybind.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigEditorKeybind.java new file mode 100644 index 000000000..6fff86daa --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigEditorKeybind.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.config.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface ConfigEditorKeybind { + int defaultKey(); +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigEditorSlider.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigEditorSlider.java new file mode 100644 index 000000000..ad49493b7 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigEditorSlider.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.config.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface ConfigEditorSlider { + float minValue(); + + float maxValue(); + + float minStep(); +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigEditorText.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigEditorText.java new file mode 100644 index 000000000..bf4b0283b --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigEditorText.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.config.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface ConfigEditorText {} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigOption.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigOption.java new file mode 100644 index 000000000..a37265685 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/annotations/ConfigOption.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.config.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface ConfigOption { + String name(); + + String desc(); + + int subcategoryId() default -1; +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditor.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditor.java new file mode 100644 index 000000000..2c0d1a0c7 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditor.java @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.config.gui; + +import at.hannibal2.skyhanni.config.core.config.struct.ConfigProcessor; +import at.hannibal2.skyhanni.config.core.util.render.GuiRenderUtils; +import at.hannibal2.skyhanni.config.core.util.render.TextRenderUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.renderer.GlStateManager; + +public abstract class GuiOptionEditor { + protected final ConfigProcessor.ProcessedOption option; + private static final int HEIGHT = 45; + + public GuiOptionEditor(ConfigProcessor.ProcessedOption option) { + this.option = option; + } + + public void render(int x, int y, int width) { + int height = getHeight(); + + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + GuiRenderUtils.drawFloatingRectDark(x, y, width, height, true); + TextRenderUtils.drawStringCenteredScaledMaxWidth(option.name, + fr, x + width / 6, y + 13, true, width / 3 - 10, 0xc0c0c0 + ); + + int maxLines = 5; + float scale = 1; + int lineCount = fr.listFormattedStringToWidth(option.desc, width * 2 / 3 - 10).size(); + + if (lineCount <= 0) return; + + float paraHeight = 9 * lineCount - 1; + + while (paraHeight >= HEIGHT - 10) { + scale -= 1 / 8f; + lineCount = fr.listFormattedStringToWidth(option.desc, (int) (width * 2 / 3 / scale - 10)).size(); + paraHeight = (int) (9 * scale * lineCount - 1 * scale); + } + + GlStateManager.pushMatrix(); + GlStateManager.translate(x + 5 + width / 3f, y + HEIGHT / 2f - paraHeight / 2, 0); + GlStateManager.scale(scale, scale, 1); + + fr.drawSplitString(option.desc, 0, 0, (int) (width * 2 / 3 / scale - 10), 0xc0c0c0); + + GlStateManager.popMatrix(); + } + + public int getHeight() { + return HEIGHT; + } + + public abstract boolean mouseInput(int x, int y, int width, int mouseX, int mouseY); + + public abstract boolean keyboardInput(); + + public boolean mouseInputOverlay(int x, int y, int width, int mouseX, int mouseY) { + return false; + } + + public void renderOverlay(int x, int y, int width) {} +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditorAccordion.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditorAccordion.java new file mode 100644 index 000000000..e99c7fd8c --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditorAccordion.java @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.config.gui; + +import at.hannibal2.skyhanni.config.core.config.struct.ConfigProcessor; +import at.hannibal2.skyhanni.config.core.util.render.GuiRenderUtils; +import at.hannibal2.skyhanni.config.core.util.render.TextRenderUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; + +public class GuiOptionEditorAccordion extends GuiOptionEditor { + private final int accordionId; + private boolean accordionToggled; + + public GuiOptionEditorAccordion(ConfigProcessor.ProcessedOption option, int accordionId) { + super(option); + this.accordionToggled = (boolean) option.get(); + this.accordionId = accordionId; + } + + @Override + public int getHeight() { + return 20; + } + + public int getAccordionId() { + return accordionId; + } + + public boolean getToggled() { + return accordionToggled; + } + + @Override + public void render(int x, int y, int width) { + int height = getHeight(); + GuiRenderUtils.drawFloatingRectDark(x, y, width, height, true); + + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + GlStateManager.enableBlend(); + GlStateManager.disableTexture2D(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + GlStateManager.color(1, 1, 1, 1); + worldrenderer.begin(GL11.GL_TRIANGLES, DefaultVertexFormats.POSITION); + if (accordionToggled) { + worldrenderer.pos((double) x + 6, (double) y + 6, 0.0D).endVertex(); + worldrenderer.pos((double) x + 9.75f, (double) y + 13.5f, 0.0D).endVertex(); + worldrenderer.pos((double) x + 13.5f, (double) y + 6, 0.0D).endVertex(); + } else { + worldrenderer.pos((double) x + 6, (double) y + 13.5f, 0.0D).endVertex(); + worldrenderer.pos((double) x + 13.5f, (double) y + 9.75f, 0.0D).endVertex(); + worldrenderer.pos((double) x + 6, (double) y + 6, 0.0D).endVertex(); + } + tessellator.draw(); + GlStateManager.enableTexture2D(); + GlStateManager.disableBlend(); + + TextRenderUtils.drawStringScaledMaxWidth(option.name, Minecraft.getMinecraft().fontRendererObj, + x + 18, y + 6, false, width - 10, 0xc0c0c0 + ); + } + + @Override + public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { + if (Mouse.getEventButtonState() && mouseX > x && mouseX < x + width && + mouseY > y && mouseY < y + getHeight()) { + accordionToggled = !accordionToggled; + return true; + } + + return false; + } + + @Override + public boolean keyboardInput() { + return false; + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditorBoolean.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditorBoolean.java new file mode 100644 index 000000000..bb2464ee3 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditorBoolean.java @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.config.gui; + +import at.hannibal2.skyhanni.config.Features; +import at.hannibal2.skyhanni.config.core.GuiElementBoolean; +import at.hannibal2.skyhanni.config.core.config.struct.ConfigProcessor; + +public class GuiOptionEditorBoolean extends GuiOptionEditor { + + private final GuiElementBoolean bool; + private final Features config; + private final String runnableId; + + public GuiOptionEditorBoolean( + ConfigProcessor.ProcessedOption option, + String runnableId, + Features config + ) { + super(option); + this.config = config; + this.runnableId = runnableId; + bool = new GuiElementBoolean(0, 0, (boolean) option.get(), 10, (value) -> onUpdate(option, value)); + } + + @Override + public void render(int x, int y, int width) { + super.render(x, y, width); + int height = getHeight(); + + bool.x = x + width / 6 - 24; + bool.y = y + height - 7 - 14; + bool.render(); + } + + @Override + public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { + int height = getHeight(); + bool.x = x + width / 6 - 24; + bool.y = y + height - 7 - 14; + return bool.mouseInput(mouseX, mouseY); + } + + @Override + public boolean keyboardInput() { + return false; + } + + private void onUpdate(ConfigProcessor.ProcessedOption option, boolean value) { + if (option.set(value)) { + config.executeRunnable(runnableId); + } + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditorButton.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditorButton.java new file mode 100644 index 000000000..fc9005e7c --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditorButton.java @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.config.gui; + +import at.hannibal2.skyhanni.config.Features; +import at.hannibal2.skyhanni.config.core.config.struct.ConfigProcessor; +import at.hannibal2.skyhanni.config.core.util.render.GuiRenderUtils; +import at.hannibal2.skyhanni.config.core.util.render.TextRenderUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; +import org.lwjgl.input.Mouse; + +import static at.hannibal2.skyhanni.config.GuiTextures.button_tex; + +public class GuiOptionEditorButton extends GuiOptionEditor { + private final String runnableId; + private String buttonText; + private final Features config; + + public GuiOptionEditorButton( + ConfigProcessor.ProcessedOption option, + String runnableId, + String buttonText, + Features config + ) { + super(option); + this.runnableId = runnableId; + this.config = config; + + this.buttonText = buttonText; + if (this.buttonText != null && this.buttonText.isEmpty()) this.buttonText = null; + } + + @Override + public void render(int x, int y, int width) { + super.render(x, y, width); + + int height = getHeight(); + + GlStateManager.color(1, 1, 1, 1); + Minecraft.getMinecraft().getTextureManager().bindTexture(button_tex); + GuiRenderUtils.drawTexturedRect(x + width / 6 - 24, y + height - 7 - 14, 48, 16); + + if (buttonText != null) { + TextRenderUtils.drawStringCenteredScaledMaxWidth(buttonText, Minecraft.getMinecraft().fontRendererObj, + x + width / 6, y + height - 7 - 6, + false, 44, 0xFF303030 + ); + } + } + + @Override + public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { + if (Mouse.getEventButtonState()) { + int height = getHeight(); + if (mouseX > x + width / 6 - 24 && mouseX < x + width / 6 + 24 && + mouseY > y + height - 7 - 14 && mouseY < y + height - 7 + 2) { + config.executeRunnable(runnableId); + return true; + } + } + + return false; + } + + @Override + public boolean keyboardInput() { + return false; + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditorColour.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditorColour.java new file mode 100644 index 000000000..721b85176 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditorColour.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.config.gui; + +import at.hannibal2.skyhanni.config.core.ChromaColour; +import at.hannibal2.skyhanni.config.core.GuiElementColour; +import at.hannibal2.skyhanni.config.core.config.struct.ConfigProcessor; +import at.hannibal2.skyhanni.config.core.util.render.GuiRenderUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; +import org.lwjgl.input.Mouse; + +import static at.hannibal2.skyhanni.config.GuiTextures.button_white; + +public class GuiOptionEditorColour extends GuiOptionEditor { + private String chromaColour; + private GuiElementColour colourElement = null; + + public GuiOptionEditorColour(ConfigProcessor.ProcessedOption option) { + super(option); + + this.chromaColour = (String) option.get(); + } + + @Override + public void render(int x, int y, int width) { + super.render(x, y, width); + int height = getHeight(); + + int argb = ChromaColour.specialToChromaRGB(chromaColour); + int r = (argb >> 16) & 0xFF; + int g = (argb >> 8) & 0xFF; + int b = argb & 0xFF; + GlStateManager.color(r / 255f, g / 255f, b / 255f, 1); + Minecraft.getMinecraft().getTextureManager().bindTexture(button_white); + GuiRenderUtils.drawTexturedRect(x + width / 6 - 24, y + height - 7 - 14, 48, 16); + } + + @Override + public void renderOverlay(int x, int y, int width) { + if (colourElement != null) { + colourElement.render(); + } + } + + @Override + public boolean mouseInputOverlay(int x, int y, int width, int mouseX, int mouseY) { + return colourElement != null && colourElement.mouseInput(mouseX, mouseY); + } + + @Override + public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { + int height = getHeight(); + + if (Mouse.getEventButtonState() && Mouse.getEventButton() == 0 && + mouseX > x + width / 6 - 24 && mouseX < x + width / 6 + 24 && + mouseY > y + height - 7 - 14 && mouseY < y + height - 7 + 2) { + colourElement = new GuiElementColour(mouseX, mouseY, (String) option.get(), (val) -> { + option.set(val); + chromaColour = val; + }, () -> colourElement = null); + } + + return false; + } + + @Override + public boolean keyboardInput() { + return colourElement != null && colourElement.keyboardInput(); + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditorDraggableList.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditorDraggableList.java new file mode 100644 index 000000000..fb2405ce9 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditorDraggableList.java @@ -0,0 +1,342 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.config.gui; + +import at.hannibal2.skyhanni.config.core.config.struct.ConfigProcessor; +import at.hannibal2.skyhanni.config.core.util.lerp.LerpUtils; +import at.hannibal2.skyhanni.config.core.util.render.GuiRenderUtils; +import at.hannibal2.skyhanni.config.core.util.render.TextRenderUtils; +import at.hannibal2.skyhanni.utils.RenderUtils; +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 net.minecraft.util.ResourceLocation; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; + +import java.util.ArrayList; +import java.util.List; + +import static at.hannibal2.skyhanni.config.GuiTextures.button_tex; + +public class GuiOptionEditorDraggableList extends GuiOptionEditor { + private static final ResourceLocation DELETE = new ResourceLocation("notenoughupdates:core/delete.png"); + + private final String[] exampleText; + private final boolean enableDeleting; + private final List<Integer> activeText; + private int currentDragging = -1; + private int dragStartIndex = -1; + + private long trashHoverTime = -1; + + private int dragOffsetX = -1; + private int dragOffsetY = -1; + + private boolean dropdownOpen = false; + + public GuiOptionEditorDraggableList( + ConfigProcessor.ProcessedOption option, + String[] exampleText, + boolean disableDeleting + ) { + super(option); + + this.enableDeleting = disableDeleting; + this.exampleText = exampleText; + this.activeText = (List<Integer>) option.get(); + } + + @Override + public int getHeight() { + int height = super.getHeight() + 13; + + for (int strIndex : activeText) { + String str = exampleText[strIndex]; + height += 10 * str.split("\n").length; + } + + return height; + } + + @Override + public void render(int x, int y, int width) { + super.render(x, y, width); + + int height = getHeight(); + + GlStateManager.color(1, 1, 1, 1); + Minecraft.getMinecraft().getTextureManager().bindTexture(button_tex); + GuiRenderUtils.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 (enableDeleting) { + Minecraft.getMinecraft().getTextureManager().bindTexture(DELETE); + GuiRenderUtils.drawTexturedRect(x + width / 6 + 27, y + 45 - 7 - 13, 11, 14, GL11.GL_NEAREST); + } + + 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 (int strIndex : activeText) { + String str = exampleText[strIndex]; + + 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]; + RenderUtils.INSTANCE.drawStringScaledMaxWidth(line + EnumChatFormatting.RESET, Minecraft.getMinecraft().fontRendererObj, + x + 20, y + 50 + yOff + multilineIndex * 10, true, width - 20, 0xffffffff + ); + } + Minecraft.getMinecraft().fontRendererObj.drawString( + "\u2261", + x + 10, + y + 50 + 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<Integer> remaining = new ArrayList<>(); + for (int i = 0; i < exampleText.length; i++) { + remaining.add(i); + } + 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 (int strIndex : remaining) { + String str = exampleText[strIndex]; + if (str.isEmpty()) { + str = "<NONE>"; + } + TextRenderUtils.drawStringScaledMaxWidth(str.replaceAll("(\n.*)+", " ..."), + fr, left + 3, top + 3 + dropdownY, false, dropdownWidth - 6, 0xffa0a0a0 + ); + dropdownY += 12; + } + } else if (currentDragging >= 0) { + 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 = exampleText[currentDragging]; + + String[] multilines = str.split("\n"); + + GlStateManager.enableBlend(); + for (int multilineIndex = 0; multilineIndex < multilines.length; multilineIndex++) { + String line = multilines[multilineIndex]; + RenderUtils.INSTANCE.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 + mouseY + ySize / 2 - 4, 0xffffff, true + ); + } + } + + @Override + public boolean mouseInput(int x, int y, int width, int mouseX, int 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 (enableDeleting) { + activeText.remove(dragStartIndex); + } + currentDragging = -1; + dragStartIndex = -1; + return false; + } + + if (!Mouse.isButtonDown(0) || dropdownOpen) { + currentDragging = -1; + dragStartIndex = -1; + if (trashHoverTime > 0 && enableDeleting) trashHoverTime = -System.currentTimeMillis(); + } else if (currentDragging >= 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 (trashHoverTime < 0 && enableDeleting) trashHoverTime = System.currentTimeMillis(); + } else { + if (trashHoverTime > 0 && enableDeleting) trashHoverTime = -System.currentTimeMillis(); + } + + if (Mouse.getEventButtonState()) { + int height = getHeight(); + + if (dropdownOpen) { + List<Integer> remaining = new ArrayList<>(); + for (int i = 0; i < exampleText.length; i++) { + remaining.add(i); + } + 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 (int strIndex : remaining) { + if (mouseY < top + dropdownY + 12) { + activeText.add(0, strIndex); + if (remaining.size() == 1) dropdownOpen = false; + return true; + } + + dropdownY += 12; + } + } + + dropdownOpen = false; + return true; + } + + if (activeText.size() < exampleText.length && + mouseX > x + width / 6 - 24 && mouseX < x + width / 6 + 24 && + mouseY > y + 45 - 7 - 14 && mouseY < y + 45 - 7 + 2) { + dropdownOpen = !dropdownOpen; + 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 (int strIndex : activeText) { + int ySize = 10 * exampleText[strIndex].split("\n").length; + if (mouseY < y + 50 + yOff + ySize) { + dragOffsetX = x + 10 - mouseX; + dragOffsetY = y + 50 + yOff - mouseY; + + currentDragging = strIndex; + dragStartIndex = i; + break; + } + yOff += ySize; + i++; + } + } + } else if (Mouse.getEventButton() == -1 && currentDragging >= 0) { + int yOff = 0; + int i = 0; + for (int strIndex : activeText) { + if (dragOffsetY + mouseY + 4 < y + 50 + yOff + 10) { + activeText.remove(dragStartIndex); + activeText.add(i, currentDragging); + + dragStartIndex = i; + break; + } + yOff += 10 * exampleText[strIndex].split("\n").length; + i++; + } + } + + return false; + } + + @Override + public boolean keyboardInput() { + return false; + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditorDropdown.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditorDropdown.java new file mode 100644 index 000000000..f64e5d708 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditorDropdown.java @@ -0,0 +1,202 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.config.gui; + +import at.hannibal2.skyhanni.config.core.config.struct.ConfigProcessor; +import at.hannibal2.skyhanni.config.core.util.render.GuiRenderUtils; +import at.hannibal2.skyhanni.config.core.util.render.TextRenderUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.renderer.GlStateManager; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; + +public class GuiOptionEditorDropdown extends GuiOptionEditor { + private final String[] values; + private final boolean useOrdinal; + private int selected; + private boolean open = false; + + public GuiOptionEditorDropdown( + ConfigProcessor.ProcessedOption option, + String[] values, + int selected, + boolean useOrdinal + ) { + super(option); + if (selected >= values.length) selected = values.length; + this.values = values; + this.selected = selected; + this.useOrdinal = useOrdinal; + } + + @Override + public void render(int x, int y, int width) { + super.render(x, y, width); + if (!open) { + int height = getHeight(); + + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + int dropdownWidth = Math.min(width / 3 - 10, 80); + int left = x + width / 6 - dropdownWidth / 2; + int top = y + height - 7 - 14; + + String selectedString = " - Select - "; + if (selected >= 0 && selected < values.length) { + selectedString = values[selected]; + } + + GuiRenderUtils.drawFloatingRectDark(left, top, dropdownWidth, 14, false); + TextRenderUtils.drawStringScaled( + "\u25BC", + fr, + left + dropdownWidth - 10, + y + height - 7 - 15, + false, + 0xffa0a0a0, + 2 + ); + + TextRenderUtils.drawStringScaledMaxWidth(selectedString, fr, left + 3, top + 3, false, + dropdownWidth - 16, 0xffa0a0a0 + ); + } + } + + @Override + public void renderOverlay(int x, int y, int width) { + if (open) { + String selectedString = " - Select - "; + if (selected >= 0 && selected < values.length) { + selectedString = values[selected]; + } + + int height = getHeight(); + + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + int dropdownWidth = Math.min(width / 3 - 10, 80); + int left = x + width / 6 - dropdownWidth / 2; + int top = y + height - 7 - 14; + + int dropdownHeight = 13 + 12 * values.length; + + int main = 0xff202026; + int blue = 0xff2355ad; + + GlStateManager.pushMatrix(); + GL11.glTranslated(0, 0, 100); + Gui.drawRect(left, top, left + 1, top + dropdownHeight, blue); //Left + Gui.drawRect(left + 1, top, left + dropdownWidth, top + 1, blue); //Top + Gui.drawRect(left + dropdownWidth - 1, top + 1, left + dropdownWidth, top + dropdownHeight, blue); //Right + Gui.drawRect(left + 1, top + dropdownHeight - 1, left + dropdownWidth - 1, top + dropdownHeight, blue); //Bottom + Gui.drawRect(left + 1, top + 1, left + dropdownWidth - 1, top + dropdownHeight - 1, main); //Middle + + Gui.drawRect(left + 1, top + 14 - 1, left + dropdownWidth - 1, top + 14, blue); //Bar + int dropdownY = 13; + for (String option : values) { + if (option.isEmpty()) { + option = "<NONE>"; + } + TextRenderUtils.drawStringScaledMaxWidth( + option, + fr, + left + 3, + top + 3 + dropdownY, + false, + dropdownWidth - 6, + 0xffa0a0a0 + ); + dropdownY += 12; + } + + TextRenderUtils.drawStringScaled( + "\u25B2", + fr, + left + dropdownWidth - 10, + y + height - 7 - 15, + false, + 0xffa0a0a0, + 2 + ); + + TextRenderUtils.drawStringScaledMaxWidth(selectedString, fr, left + 3, top + 3, false, + dropdownWidth - 16, 0xffa0a0a0 + ); + GlStateManager.popMatrix(); + } + } + + @Override + public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { + int height = getHeight(); + + int left = x + width / 6 - 40; + int top = y + height - 7 - 14; + + if (Mouse.getEventButtonState() && Mouse.getEventButton() == 0) { + if (mouseX >= left && mouseX <= left + 80 && + mouseY >= top && mouseY <= top + 14) { + open = !open; + return true; + } + } + + return false; + } + + @Override + public boolean mouseInputOverlay(int x, int y, int width, int mouseX, int mouseY) { + int height = getHeight(); + + int left = x + width / 6 - 40; + int top = y + height - 7 - 14; + + if (Mouse.getEventButtonState() && Mouse.getEventButton() == 0) { + if (!(mouseX >= left && mouseX <= left + 80 && + mouseY >= top && mouseY <= top + 14) && open) { + open = false; + if (mouseX >= left && mouseX <= left + 80) { + int dropdownY = 13; + for (int ordinal = 0; ordinal < values.length; ordinal++) { + if (mouseY >= top + 3 + dropdownY && mouseY <= top + 3 + dropdownY + 12) { + selected = ordinal; + if (useOrdinal) { + option.set(selected); + } else { + option.set(values[selected]); + } + return true; + } + dropdownY += 12; + } + } + return true; + } + } + + return false; + } + + @Override + public boolean keyboardInput() { + return false; + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditorFSR.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditorFSR.java new file mode 100644 index 000000000..3ab485780 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditorFSR.java @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.config.gui; + +import at.hannibal2.skyhanni.config.Features; +import at.hannibal2.skyhanni.config.core.config.struct.ConfigProcessor; +import at.hannibal2.skyhanni.config.core.util.render.GuiRenderUtils; +import at.hannibal2.skyhanni.config.core.util.render.TextRenderUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; +import org.lwjgl.input.Mouse; + +import static at.hannibal2.skyhanni.config.GuiTextures.button_fsr; + +public class GuiOptionEditorFSR extends GuiOptionEditor { + private final String runnableId; + private String buttonText; + private final Features config; + + public GuiOptionEditorFSR(ConfigProcessor.ProcessedOption option, String runnableId, String buttonText, Features config) { + super(option); + this.runnableId = runnableId; + this.config = config; + + this.buttonText = buttonText; + if (this.buttonText != null && this.buttonText.isEmpty()) this.buttonText = null; + } + + @Override + public void render(int x, int y, int width) { + super.render(x, y, width); + + int height = getHeight(); + + GlStateManager.color(1, 1, 1, 1); + Minecraft.getMinecraft().getTextureManager().bindTexture(button_fsr); + GuiRenderUtils.drawTexturedRect(x + width / 6 - 24, y + height - 7 - 14, 48, 16); + + if (buttonText != null) { + TextRenderUtils.drawStringCenteredScaledMaxWidth(buttonText, Minecraft.getMinecraft().fontRendererObj, + x + width / 6, y + height - 7 - 6, + false, 44, 0xFF303030 + ); + } + } + + @Override + public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { + if (Mouse.getEventButtonState()) { + int height = getHeight(); + if (mouseX > x + width / 6 - 24 && mouseX < x + width / 6 + 24 && + mouseY > y + height - 7 - 14 && mouseY < y + height - 7 + 2) { + config.executeRunnable(runnableId); + return true; + } + } + + return false; + } + + @Override + public boolean keyboardInput() { + return false; + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditorKeybind.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditorKeybind.java new file mode 100644 index 000000000..4fa0ee822 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditorKeybind.java @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.config.gui; + +import at.hannibal2.skyhanni.config.core.config.KeybindHelper; +import at.hannibal2.skyhanni.config.core.config.struct.ConfigProcessor; +import at.hannibal2.skyhanni.config.core.util.render.GuiRenderUtils; +import at.hannibal2.skyhanni.config.core.util.render.TextRenderUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; + +import static at.hannibal2.skyhanni.config.GuiTextures.button_tex; + +public class GuiOptionEditorKeybind extends GuiOptionEditor { + private static final ResourceLocation RESET = new ResourceLocation("notenoughupdates:itemcustomize/reset.png"); + + private int keyCode; + private final int defaultKeyCode; + private boolean editingKeycode; + + public GuiOptionEditorKeybind(ConfigProcessor.ProcessedOption option, int keyCode, int defaultKeyCode) { + super(option); + this.keyCode = keyCode; + this.defaultKeyCode = defaultKeyCode; + } + + @Override + public void render(int x, int y, int width) { + super.render(x, y, width); + + int height = getHeight(); + + GlStateManager.color(1, 1, 1, 1); + Minecraft.getMinecraft().getTextureManager().bindTexture(button_tex); + GuiRenderUtils.drawTexturedRect(x + width / 6 - 24, y + height - 7 - 14, 48, 16); + + String keyName = KeybindHelper.getKeyName(keyCode); + String text = editingKeycode ? "> " + keyName + " <" : keyName; + TextRenderUtils.drawStringCenteredScaledMaxWidth(text, + Minecraft.getMinecraft().fontRendererObj, + x + width / 6, y + height - 7 - 6, + false, 40, 0xFF303030 + ); + + Minecraft.getMinecraft().getTextureManager().bindTexture(RESET); + GlStateManager.color(1, 1, 1, 1); + GuiRenderUtils.drawTexturedRect(x + width / 6 - 24 + 48 + 3, y + height - 7 - 14 + 3, 10, 11, GL11.GL_NEAREST); + } + + @Override + public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { + if (Mouse.getEventButtonState() && Mouse.getEventButton() != -1 && editingKeycode) { + editingKeycode = false; + keyCode = Mouse.getEventButton() - 100; + option.set(keyCode); + return true; + } + + if (Mouse.getEventButtonState() && Mouse.getEventButton() == 0) { + int height = getHeight(); + if (mouseX > x + width / 6 - 24 && mouseX < x + width / 6 + 24 && + mouseY > y + height - 7 - 14 && mouseY < y + height - 7 + 2) { + editingKeycode = true; + return true; + } + if (mouseX > x + width / 6 - 24 + 48 + 3 && mouseX < x + width / 6 - 24 + 48 + 13 && + mouseY > y + height - 7 - 14 + 3 && mouseY < y + height - 7 - 14 + 3 + 11) { + keyCode = defaultKeyCode; + option.set(keyCode); + return true; + } + } + + return false; + } + + @Override + public boolean keyboardInput() { + if (editingKeycode) { + editingKeycode = false; + if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) { + keyCode = 0; + } else if (Keyboard.getEventKey() != 0) { + keyCode = Keyboard.getEventKey(); + } + if (keyCode > 256) keyCode = 0; + option.set(keyCode); + return true; + } + return false; + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditorSlider.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditorSlider.java new file mode 100644 index 000000000..4441bced9 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditorSlider.java @@ -0,0 +1,152 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.config.gui; + +import at.hannibal2.skyhanni.config.core.GuiElementTextField; +import at.hannibal2.skyhanni.config.core.config.struct.ConfigProcessor; +import at.hannibal2.skyhanni.config.core.util.GuiElementSlider; +import net.minecraft.client.Minecraft; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; + +public class GuiOptionEditorSlider extends GuiOptionEditor { + private final GuiElementSlider slider; + private final GuiElementTextField textField; + + public GuiOptionEditorSlider(ConfigProcessor.ProcessedOption option, float minValue, float maxValue, float minStep) { + super(option); + if (minStep < 0) minStep = 0.01f; + + float floatVal = ((Number) option.get()).floatValue(); + { + String strVal; + if (floatVal % 1 == 0) { + strVal = Integer.toString((int) floatVal); + } else { + strVal = Float.toString(floatVal); + } + textField = new GuiElementTextField( + strVal, + GuiElementTextField.NO_SPACE | GuiElementTextField.NUM_ONLY | GuiElementTextField.SCALE_TEXT + ); + } + + slider = new GuiElementSlider(0, 0, 80, minValue, maxValue, minStep, floatVal, (val) -> { + option.set(val); + + String strVal; + if (val % 1 == 0) { + strVal = Integer.toString(val.intValue()); + } else { + strVal = Float.toString(val); + strVal = strVal.replaceAll("(\\.\\d\\d\\d)(?:\\d)+", "$1"); + strVal = strVal.replaceAll("0+$", ""); + } + textField.setText(strVal); + }); + } + + @Override + public void render(int x, int y, int width) { + super.render(x, y, width); + int height = getHeight(); + + int fullWidth = Math.min(width / 3 - 10, 80); + int sliderWidth = (fullWidth - 5) * 3 / 4; + int textFieldWidth = (fullWidth - 5) / 4; + + slider.x = x + width / 6 - fullWidth / 2; + slider.y = y + height - 7 - 14; + slider.width = sliderWidth; + slider.render(); + + if (textField.getFocus()) { + textField.setOptions(GuiElementTextField.NO_SPACE | GuiElementTextField.NUM_ONLY); + textField.setSize( + Minecraft.getMinecraft().fontRendererObj.getStringWidth(textField.getText()) + 10, + 16 + ); + } else { + textField.setSize(textFieldWidth, 16); + textField.setOptions( + GuiElementTextField.NO_SPACE | GuiElementTextField.NUM_ONLY | GuiElementTextField.SCALE_TEXT); + } + + textField.render(x + width / 6 - fullWidth / 2 + sliderWidth + 5, y + height - 7 - 14); + } + + @Override + public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { + int height = getHeight(); + + int fullWidth = Math.min(width / 3 - 10, 80); + int sliderWidth = (fullWidth - 5) * 3 / 4; + int textFieldWidth = (fullWidth - 5) / 4; + + slider.x = x + width / 6 - fullWidth / 2; + slider.y = y + height - 7 - 14; + slider.width = sliderWidth; + if (slider.mouseInput(mouseX, mouseY)) { + textField.unfocus(); + return true; + } + + if (textField.getFocus()) { + textFieldWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(textField.getText()) + 10; + } + + int textFieldX = x + width / 6 - fullWidth / 2 + sliderWidth + 5; + int textFieldY = y + height - 7 - 14; + textField.setSize(textFieldWidth, 16); + + if (Mouse.getEventButtonState() && (Mouse.getEventButton() == 0 || Mouse.getEventButton() == 1)) { + if (mouseX > textFieldX && mouseX < textFieldX + textFieldWidth && + mouseY > textFieldY && mouseY < textFieldY + 16) { + textField.mouseClicked(mouseX, mouseY, Mouse.getEventButton()); + return true; + } + textField.unfocus(); + } + + return false; + } + + @Override + public boolean keyboardInput() { + if (Keyboard.getEventKeyState() && textField.getFocus()) { + textField.keyTyped(Keyboard.getEventCharacter(), Keyboard.getEventKey()); + + try { + textField.setCustomBorderColour(0xffffffff); + float f = Float.parseFloat(textField.getText()); + if (option.set(f)) { + slider.setValue(f); + } else { + textField.setCustomBorderColour(0xff0000ff); + } + } catch (Exception e) { + textField.setCustomBorderColour(0xffff0000); + } + + return true; + } + return false; + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditorText.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditorText.java new file mode 100644 index 000000000..98274ed49 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiOptionEditorText.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.config.gui; + +import at.hannibal2.skyhanni.config.core.GuiElementTextField; +import at.hannibal2.skyhanni.config.core.config.struct.ConfigProcessor; +import net.minecraft.client.Minecraft; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; + +public class GuiOptionEditorText extends GuiOptionEditor { + private final GuiElementTextField textField; + + public GuiOptionEditorText(ConfigProcessor.ProcessedOption option) { + super(option); + + textField = new GuiElementTextField((String) option.get(), 0); + } + + @Override + public void render(int x, int y, int width) { + super.render(x, y, width); + int height = getHeight(); + + int fullWidth = Math.min(width / 3 - 10, 80); + + int textFieldX = x + width / 6 - fullWidth / 2; + if (textField.getFocus()) { + fullWidth = Math.max( + fullWidth, + Minecraft.getMinecraft().fontRendererObj.getStringWidth(textField.getText()) + 10 + ); + } + + textField.setSize(fullWidth, 16); + + textField.render(textFieldX, y + height - 7 - 14); + } + + @Override + public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { + int height = getHeight(); + + int fullWidth = Math.min(width / 3 - 10, 80); + + int textFieldX = x + width / 6 - fullWidth / 2; + + if (textField.getFocus()) { + fullWidth = Math.max( + fullWidth, + Minecraft.getMinecraft().fontRendererObj.getStringWidth(textField.getText()) + 10 + ); + } + + int textFieldY = y + height - 7 - 14; + textField.setSize(fullWidth, 16); + + if (Mouse.getEventButtonState() && (Mouse.getEventButton() == 0 || Mouse.getEventButton() == 1)) { + if (mouseX > textFieldX && mouseX < textFieldX + fullWidth && + mouseY > textFieldY && mouseY < textFieldY + 16) { + textField.mouseClicked(mouseX, mouseY, Mouse.getEventButton()); + return true; + } + textField.unfocus(); + } + + return false; + } + + @Override + public boolean keyboardInput() { + if (Keyboard.getEventKeyState() && textField.getFocus()) { + textField.keyTyped(Keyboard.getEventCharacter(), Keyboard.getEventKey()); + + try { + textField.setCustomBorderColour(0xffffffff); + option.set(textField.getText()); + } catch (Exception e) { + textField.setCustomBorderColour(0xffff0000); + } + + return true; + } + return false; + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiPositionEditor.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiPositionEditor.java new file mode 100644 index 000000000..1bb404599 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiPositionEditor.java @@ -0,0 +1,198 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.config.gui; + +import at.hannibal2.skyhanni.config.core.config.Position; +import at.hannibal2.skyhanni.config.core.util.render.TextRenderUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.ScaledResolution; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; + +import java.io.IOException; + +public class GuiPositionEditor extends GuiScreen { + private final Position position; + private final Position originalPosition; + private final int elementWidth; + private final int elementHeight; + private final Runnable renderCallback; + private final Runnable positionChangedCallback; + private final Runnable closedCallback; + private boolean clicked = false; + private int grabbedX = 0; + private int grabbedY = 0; + +// private int guiScaleOverride = -1; + + public GuiPositionEditor( + Position position, int elementWidth, int elementHeight, + Runnable renderCallback, + Runnable positionChangedCallback, + Runnable closedCallback + ) { + this.position = position; + this.originalPosition = position.clone(); + this.elementWidth = elementWidth; + this.elementHeight = elementHeight; + this.renderCallback = renderCallback; + this.positionChangedCallback = positionChangedCallback; + this.closedCallback = closedCallback; + } + +// public GuiPositionEditor withScale(int scale) { +// this.guiScaleOverride = scale; +// return this; +// } + + @Override + public void onGuiClosed() { + super.onGuiClosed(); + closedCallback.run(); + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + super.drawScreen(mouseX, mouseY, partialTicks); + ScaledResolution scaledResolution; +// if (guiScaleOverride >= 0) { +// scaledResolution = GuiRenderUtils.pushGuiScale(guiScaleOverride); +// } else { + scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); +// } + + this.width = scaledResolution.getScaledWidth(); + this.height = scaledResolution.getScaledHeight(); + mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth; + mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; + + drawDefaultBackground(); + + if (clicked) { + grabbedX += position.moveX(mouseX - grabbedX, elementWidth, scaledResolution); + grabbedY += position.moveY(mouseY - grabbedY, elementHeight, scaledResolution); + } + + renderCallback.run(); + + int x = position.getAbsX(scaledResolution, elementWidth); + int y = position.getAbsY(scaledResolution, elementHeight); + + if (position.isCenterX()) x -= elementWidth / 2; + if (position.isCenterY()) y -= elementHeight / 2; + Gui.drawRect(x, y, x + elementWidth, y + elementHeight, 0x80404040); + +// if (guiScaleOverride >= 0) { +// Utils.pushGuiScale(-1); +// } + + scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + TextRenderUtils.drawStringCentered("Position Editor", Minecraft.getMinecraft().fontRendererObj, + scaledResolution.getScaledWidth() / 2, 8, true, 0xffffff + ); + TextRenderUtils.drawStringCentered("R to Reset - Arrow keys/mouse to move", Minecraft.getMinecraft().fontRendererObj, + scaledResolution.getScaledWidth() / 2, 18, true, 0xffffff + ); + } + + @Override + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { + super.mouseClicked(mouseX, mouseY, mouseButton); + + if (mouseButton == 0) { + ScaledResolution scaledResolution; +// if (guiScaleOverride >= 0) { +// scaledResolution = Utils.pushGuiScale(guiScaleOverride); +// } else { + scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); +// } + mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth; + mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; + + int x = position.getAbsX(scaledResolution, elementWidth); + int y = position.getAbsY(scaledResolution, elementHeight); + if (position.isCenterX()) x -= elementWidth / 2; + if (position.isCenterY()) y -= elementHeight / 2; + + if (mouseX >= x && mouseY >= y && + mouseX <= x + elementWidth && mouseY <= y + elementHeight) { + clicked = true; + grabbedX = mouseX; + grabbedY = mouseY; + } + +// if (guiScaleOverride >= 0) { +// Utils.pushGuiScale(-1); +// } + } + } + + @Override + protected void keyTyped(char typedChar, int keyCode) throws IOException { + if (keyCode == Keyboard.KEY_R) { + position.set(originalPosition); + } else if (!clicked) { + boolean shiftHeld = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT); + int dist = shiftHeld ? 10 : 1; + if (keyCode == Keyboard.KEY_DOWN) { + position.moveY(dist, elementHeight, new ScaledResolution(Minecraft.getMinecraft())); + } else if (keyCode == Keyboard.KEY_UP) { + position.moveY(-dist, elementHeight, new ScaledResolution(Minecraft.getMinecraft())); + } else if (keyCode == Keyboard.KEY_LEFT) { + position.moveX(-dist, elementWidth, new ScaledResolution(Minecraft.getMinecraft())); + } else if (keyCode == Keyboard.KEY_RIGHT) { + position.moveX(dist, elementWidth, new ScaledResolution(Minecraft.getMinecraft())); + } + } + super.keyTyped(typedChar, keyCode); + } + + @Override + protected void mouseReleased(int mouseX, int mouseY, int state) { + super.mouseReleased(mouseX, mouseY, state); + clicked = false; + } + + @Override + protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { + super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick); + + if (clicked) { + ScaledResolution scaledResolution; +// if (guiScaleOverride >= 0) { +// scaledResolution = Utils.pushGuiScale(guiScaleOverride); +// } else { + scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); +// } + mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth; + mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; + + grabbedX += position.moveX(mouseX - grabbedX, elementWidth, scaledResolution); + grabbedY += position.moveY(mouseY - grabbedY, elementHeight, scaledResolution); + positionChangedCallback.run(); + +// if (guiScaleOverride >= 0) { +// Utils.pushGuiScale(-1); +// } + } + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/struct/ConfigProcessor.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/struct/ConfigProcessor.java new file mode 100644 index 000000000..5e25b55c0 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/struct/ConfigProcessor.java @@ -0,0 +1,219 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.config.struct; + +import at.hannibal2.skyhanni.config.Features; +import at.hannibal2.skyhanni.config.core.config.annotations.*; +import at.hannibal2.skyhanni.config.core.config.gui.*; +import com.google.gson.annotations.Expose; + +import java.lang.reflect.Field; +import java.util.LinkedHashMap; +import java.util.List; + +public class ConfigProcessor { + public static class ProcessedCategory { + public final String name; + public final String desc; + public final LinkedHashMap<String, ProcessedOption> options = new LinkedHashMap<>(); + + public ProcessedCategory(String name, String desc) { + this.name = name; + this.desc = desc; + } + } + + public static class ProcessedOption { + public final String name; + public final String desc; + public final int subcategoryId; + public GuiOptionEditor editor; + + public int accordionId = -1; + + private final Field field; + private final Object container; + + public ProcessedOption(String name, String desc, int subcategoryId, Field field, Object container) { + this.name = name; + this.desc = desc; + this.subcategoryId = subcategoryId; + + this.field = field; + this.container = container; + } + + public Object get() { + try { + return field.get(container); + } catch (Exception e) { + return null; + } + } + + public boolean set(Object value) { + try { + if (field.getType() == int.class && value instanceof Number) { + field.set(container, ((Number) value).intValue()); + } else { + field.set(container, value); + } + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + } + + public static LinkedHashMap<String, ProcessedCategory> create(Features features) { + LinkedHashMap<String, ProcessedCategory> processedConfig = new LinkedHashMap<>(); + for (Field categoryField : features.getClass().getDeclaredFields()) { + boolean exposePresent = categoryField.isAnnotationPresent(Expose.class); + boolean categoryPresent = categoryField.isAnnotationPresent(Category.class); + + if (exposePresent && categoryPresent) { + Object categoryObj; + try { + categoryObj = categoryField.get(features); + } catch (Exception e) { + //System.err.printf("Failed to load config category %s. Field was not accessible.\n", categoryField.getName()); + continue; + } + + Category categoryAnnotation = categoryField.getAnnotation(Category.class); + ProcessedCategory cat = new ProcessedCategory( + categoryAnnotation.name(), + categoryAnnotation.desc() + ); + processedConfig.put(categoryField.getName(), cat); + + for (Field optionField : categoryObj.getClass().getDeclaredFields()) { + boolean optionPresent = optionField.isAnnotationPresent(ConfigOption.class); + + if (optionPresent) { + ConfigOption optionAnnotation = optionField.getAnnotation(ConfigOption.class); + ProcessedOption option = new ProcessedOption( + optionAnnotation.name(), + optionAnnotation.desc(), + optionAnnotation.subcategoryId(), + optionField, + categoryObj + ); + if (optionField.isAnnotationPresent(ConfigAccordionId.class)) { + ConfigAccordionId annotation = optionField.getAnnotation(ConfigAccordionId.class); + option.accordionId = annotation.id(); + } + + GuiOptionEditor editor = null; + Class<?> optionType = optionField.getType(); + if (optionType.isAssignableFrom(int.class) && + optionField.isAnnotationPresent(ConfigEditorKeybind.class)) { + ConfigEditorKeybind configEditorAnnotation = optionField.getAnnotation(ConfigEditorKeybind.class); + editor = new GuiOptionEditorKeybind(option, (int) option.get(), configEditorAnnotation.defaultKey()); + } + if (optionField.isAnnotationPresent(ConfigEditorButton.class)) { + ConfigEditorButton configEditorAnnotation = optionField.getAnnotation(ConfigEditorButton.class); + editor = new GuiOptionEditorButton( + option, + configEditorAnnotation.runnableId(), + configEditorAnnotation.buttonText(), + features + ); + } + if (optionField.isAnnotationPresent(ConfigEditorFSR.class)) { + ConfigEditorFSR configEditorAnnotation = optionField.getAnnotation(ConfigEditorFSR.class); + editor = new GuiOptionEditorFSR( + option, + configEditorAnnotation.runnableId(), + configEditorAnnotation.buttonText(), + features + ); + } + if (optionType.isAssignableFrom(boolean.class) && + optionField.isAnnotationPresent(ConfigEditorBoolean.class)) { + ConfigEditorBoolean configEditorAnnotation = optionField.getAnnotation(ConfigEditorBoolean.class); + editor = new GuiOptionEditorBoolean(option, configEditorAnnotation.runnableId(), features); + } + if (optionType.isAssignableFrom(boolean.class) && + optionField.isAnnotationPresent(ConfigEditorAccordion.class)) { + ConfigEditorAccordion configEditorAnnotation = optionField.getAnnotation(ConfigEditorAccordion.class); + editor = new GuiOptionEditorAccordion(option, configEditorAnnotation.id()); + } + if (optionType.isAssignableFrom(int.class)) { + if (optionField.isAnnotationPresent(ConfigEditorDropdown.class)) { + ConfigEditorDropdown configEditorAnnotation = optionField.getAnnotation(ConfigEditorDropdown.class); + editor = new GuiOptionEditorDropdown(option, configEditorAnnotation.values(), (int) option.get(), true); + } + } + if (optionType.isAssignableFrom(List.class)) { + if (optionField.isAnnotationPresent(ConfigEditorDraggableList.class)) { + ConfigEditorDraggableList configEditorAnnotation = + optionField.getAnnotation(ConfigEditorDraggableList.class); + editor = new GuiOptionEditorDraggableList( + option, + configEditorAnnotation.exampleText(), + configEditorAnnotation.allowDeleting() + ); + } + } + if (optionType.isAssignableFrom(String.class)) { + if (optionField.isAnnotationPresent(ConfigEditorDropdown.class)) { + ConfigEditorDropdown configEditorAnnotation = optionField.getAnnotation(ConfigEditorDropdown.class); + editor = new GuiOptionEditorDropdown(option, configEditorAnnotation.values(), + configEditorAnnotation.initialIndex(), false + ); + } else if (optionField.isAnnotationPresent(ConfigEditorColour.class)) { + editor = new GuiOptionEditorColour(option); + } else if (optionField.isAnnotationPresent(ConfigEditorText.class)) { + editor = new GuiOptionEditorText(option); + } + } + if (optionType.isAssignableFrom(int.class) || + optionType.isAssignableFrom(float.class) || + optionType.isAssignableFrom(double.class)) { + if (optionField.isAnnotationPresent(ConfigEditorSlider.class)) { + ConfigEditorSlider configEditorAnnotation = optionField.getAnnotation(ConfigEditorSlider.class); + editor = new GuiOptionEditorSlider(option, configEditorAnnotation.minValue(), + configEditorAnnotation.maxValue(), configEditorAnnotation.minStep() + ); + } + } + if (optionType.isAssignableFrom(String.class)) { + if (optionField.isAnnotationPresent(ConfigEditorDropdown.class)) { + ConfigEditorDropdown configEditorAnnotation = optionField.getAnnotation(ConfigEditorDropdown.class); + editor = new GuiOptionEditorDropdown(option, configEditorAnnotation.values(), 0, false); + } + } + if (editor == null) { + //System.err.printf("Failed to load config option %s. Could not find suitable editor.\n", optionField.getName()); + continue; + } + option.editor = editor; + cat.options.put(optionField.getName(), option); + } + } + } else if (exposePresent || categoryPresent) { + //System.err.printf("Failed to load config category %s. Both @Expose and @Category must be present.\n", categoryField.getName()); + } + } + return processedConfig; + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/util/GuiElementSlider.java b/src/main/java/at/hannibal2/skyhanni/config/core/util/GuiElementSlider.java new file mode 100644 index 000000000..f519f5945 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/util/GuiElementSlider.java @@ -0,0 +1,124 @@ +package at.hannibal2.skyhanni.config.core.util; + +import at.hannibal2.skyhanni.config.core.GuiElement; +import at.hannibal2.skyhanni.config.core.util.render.GuiRenderUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.GlStateManager; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; + +import java.util.function.Consumer; + +import static at.hannibal2.skyhanni.config.GuiTextures.*; + +public class GuiElementSlider extends GuiElement { + public int x; + public int y; + public int width; + private static final int HEIGHT = 16; + + private final float minValue; + private final float maxValue; + private final float minStep; + + private float value; + private final Consumer<Float> setCallback; + + private boolean clicked = false; + + public GuiElementSlider( + int x, int y, int width, float minValue, float maxValue, float minStep, + float value, Consumer<Float> setCallback + ) { + if (minStep < 0) minStep = 0.01f; + + this.x = x; + this.y = y; + this.width = width; + this.minValue = minValue; + this.maxValue = maxValue; + this.minStep = minStep; + this.value = value; + this.setCallback = setCallback; + } + + public void setValue(float value) { + this.value = value; + } + + @Override + public void render() { + final ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + int mouseX = Mouse.getX() * scaledResolution.getScaledWidth() / Minecraft.getMinecraft().displayWidth; + + float value = this.value; + if (clicked) { + value = (mouseX - x) * (maxValue - minValue) / width + minValue; + value = Math.max(minValue, Math.min(maxValue, value)); + value = Math.round(value / minStep) * minStep; + } + + float sliderAmount = Math.max(0, Math.min(1, (value - minValue) / (maxValue - minValue))); + int sliderAmountI = (int) (width * sliderAmount); + + GlStateManager.color(1f, 1f, 1f, 1f); + Minecraft.getMinecraft().getTextureManager().bindTexture(slider_on_cap); + GuiRenderUtils.drawTexturedRect(x, y, 4, HEIGHT, GL11.GL_NEAREST); + Minecraft.getMinecraft().getTextureManager().bindTexture(slider_off_cap); + GuiRenderUtils.drawTexturedRect(x + width - 4, y, 4, HEIGHT, GL11.GL_NEAREST); + + if (sliderAmountI > 5) { + Minecraft.getMinecraft().getTextureManager().bindTexture(slider_on_segment); + GuiRenderUtils.drawTexturedRect(x + 4, y, sliderAmountI - 4, HEIGHT, GL11.GL_NEAREST); + } + + if (sliderAmountI < width - 5) { + Minecraft.getMinecraft().getTextureManager().bindTexture(slider_off_segment); + GuiRenderUtils.drawTexturedRect(x + sliderAmountI, y, width - 4 - sliderAmountI, HEIGHT, GL11.GL_NEAREST); + } + + for (int i = 1; i < 4; i++) { + int notchX = x + width * i / 4 - 1; + Minecraft.getMinecraft().getTextureManager().bindTexture( + notchX > x + sliderAmountI ? slider_off_notch : slider_on_notch); + GuiRenderUtils.drawTexturedRect(notchX, y + (HEIGHT - 4) / 2, 2, 4, GL11.GL_NEAREST); + } + + Minecraft.getMinecraft().getTextureManager().bindTexture(slider_button_new); + GuiRenderUtils.drawTexturedRect(x + sliderAmountI - 4, y, 8, HEIGHT, GL11.GL_NEAREST); + } + + @Override + public boolean mouseInput(int mouseX, int mouseY) { + if (!Mouse.isButtonDown(0)) { + clicked = false; + } + + if (Mouse.getEventButton() == 0) { + clicked = Mouse.getEventButtonState() && mouseX > x && mouseX < x + width && mouseY > y && mouseY < y + HEIGHT; + if (clicked) { + value = (mouseX - x) * (maxValue - minValue) / width + minValue; + value = Math.max(minValue, Math.min(maxValue, value)); + value = (float) (Math.round(value / minStep) * (double) minStep); + setCallback.accept(value); + return true; + } + } + + if (!Mouse.getEventButtonState() && Mouse.getEventButton() == -1 && clicked) { + value = (mouseX - x) * (maxValue - minValue) / width + minValue; + value = Math.max(minValue, Math.min(maxValue, value)); + value = Math.round(value / minStep) * minStep; + setCallback.accept(value); + return true; + } + + return false; + } + + @Override + public boolean keyboardInput() { + return false; + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/util/Line.java b/src/main/java/at/hannibal2/skyhanni/config/core/util/Line.java new file mode 100644 index 000000000..bab3175ee --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/util/Line.java @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.util; + +import net.minecraft.util.Vec3; + +/** + * Represents a line using two points along the line or a segment with endpoints. + */ +public class Line { + private static final double DOUBLE_EPSILON = 4.94065645841247E-324; + public Vec3 point1; + public Vec3 point2; + + public Line(Vec3 first, Vec3 second) { + point1 = first; + point2 = second; + } + + public Vec3 getMidpoint() { + return new Vec3( + (point1.xCoord + point2.xCoord) / 2.0, + (point1.yCoord + point2.yCoord) / 2.0, + (point1.zCoord + point2.zCoord) / 2.0 + ); + } + + /** + * Calculates the intersection line segment between 2 lines + * Based on http://paulbourke.net/geometry/pointlineplane/calclineline.cs + * + * @return The intersection {@link Line} or {@code null} if no solution found + */ + public Line getIntersectionLineSegment(Line other) { + Vec3 p1 = this.point1; + Vec3 p2 = this.point2; + Vec3 p3 = other.point1; + Vec3 p4 = other.point2; + Vec3 p13 = p1.subtract(p3); + Vec3 p43 = p4.subtract(p3); + + if (lengthSquared(p43) < DOUBLE_EPSILON) { + return null; + } + + Vec3 p21 = p2.subtract(p1); + if (lengthSquared(p21) < DOUBLE_EPSILON) { + return null; + } + + double d1343 = p13.xCoord * p43.xCoord + p13.yCoord * p43.yCoord + p13.zCoord * p43.zCoord; + double d4321 = p43.xCoord * p21.xCoord + p43.yCoord * p21.yCoord + p43.zCoord * p21.zCoord; + double d1321 = p13.xCoord * p21.xCoord + p13.yCoord * p21.yCoord + p13.zCoord * p21.zCoord; + double d4343 = p43.xCoord * p43.xCoord + p43.yCoord * p43.yCoord + p43.zCoord * p43.zCoord; + double d2121 = p21.xCoord * p21.xCoord + p21.yCoord * p21.yCoord + p21.zCoord * p21.zCoord; + + double denom = d2121 * d4343 - d4321 * d4321; + if (Math.abs(denom) < DOUBLE_EPSILON) { + return null; + } + double numer = d1343 * d4321 - d1321 * d4343; + + double mua = numer / denom; + double mub = (d1343 + d4321 * (mua)) / d4343; + + Line resultSegment = new Line( + new Vec3( + (float) (p1.xCoord + mua * p21.xCoord), + (float) (p1.yCoord + mua * p21.yCoord), + (float) (p1.zCoord + mua * p21.zCoord) + ), + new Vec3( + (float) (p3.xCoord + mub * p43.xCoord), + (float) (p3.yCoord + mub * p43.yCoord), + (float) (p3.zCoord + mub * p43.zCoord) + ) + ); + + return resultSegment; + } + + public Line getImmutable() { + return new Line(point1, point2); + } + + private static double lengthSquared(Vec3 vec) { + return vec.dotProduct(vec); + } + + public String toString() { + return String.format( + "point1 = %s, point2 = %s, midpoint = %s", + point1 == null ? "NULL" : point1.toString(), + point2 == null ? "NULL" : point2.toString(), + (point1 == null || point2 == null) ? "NULL" : getMidpoint() + ); + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/util/MiscUtils.java b/src/main/java/at/hannibal2/skyhanni/config/core/util/MiscUtils.java new file mode 100644 index 000000000..e90beb581 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/util/MiscUtils.java @@ -0,0 +1,127 @@ +///* +// * Copyright (C) 2022 NotEnoughUpdates contributors +// * +// * This file is part of NotEnoughUpdates. +// * +// * NotEnoughUpdates 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. +// * +// * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. +// */ +// +//package at.hannibal2.skyhanni.config.core.util; +// +//import net.minecraft.client.Minecraft; +//import net.minecraft.util.ResourceLocation; +//import org.lwjgl.BufferUtils; +//import org.lwjgl.input.Cursor; +//import org.lwjgl.input.Mouse; +// +//import javax.imageio.ImageIO; +//import java.awt.*; +//import java.awt.datatransfer.StringSelection; +//import java.awt.image.BufferedImage; +//import java.io.File; +//import java.io.FileOutputStream; +//import java.io.IOException; +//import java.io.InputStream; +//import java.nio.IntBuffer; +//import java.nio.file.Files; +//import java.util.zip.ZipEntry; +//import java.util.zip.ZipInputStream; +// +//public class MiscUtils { +// public static void copyToClipboard(String str) { +// Toolkit.getDefaultToolkit().getSystemClipboard() +// .setContents(new StringSelection(str), null); +// } +// +// private static void unzip(InputStream src, File dest) { +// //buffer for read and write data to file +// byte[] buffer = new byte[1024]; +// try { +// ZipInputStream zis = new ZipInputStream(src); +// ZipEntry ze = zis.getNextEntry(); +// while (ze != null) { +// if (!ze.isDirectory()) { +// String fileName = ze.getName(); +// File newFile = new File(dest, fileName); +// //create directories for sub directories in zip +// new File(newFile.getParent()).mkdirs(); +// FileOutputStream fos = new FileOutputStream(newFile); +// int len; +// while ((len = zis.read(buffer)) > 0) { +// fos.write(buffer, 0, len); +// } +// fos.close(); +// } +// //close this ZipEntry +// zis.closeEntry(); +// ze = zis.getNextEntry(); +// } +// //close last ZipEntry +// zis.closeEntry(); +// zis.close(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } +// +// public static void recursiveDelete(File file) { +// if (file.isDirectory() && !Files.isSymbolicLink(file.toPath())) { +// for (File child : file.listFiles()) { +// recursiveDelete(child); +// } +// } +// file.delete(); +// } +// +// private static String currentCursor = null; +// +// public static void resetCursor() { +// if (currentCursor == null) { +// return; +// } +// currentCursor = null; +// try { +// Mouse.setNativeCursor(null); +// } catch (Exception ignored) { +// } +// } +// +// public static void setCursor(ResourceLocation loc, int hotspotX, int hotspotY) { +// if (currentCursor != null && loc.getResourcePath().equals(currentCursor)) { +// return; +// } +// currentCursor = loc.getResourcePath(); +// try { +// BufferedImage image = ImageIO.read(Minecraft.getMinecraft() +// .getResourceManager().getResource(loc).getInputStream()); +// int maxSize = Cursor.getMaxCursorSize(); +// IntBuffer buffer = BufferUtils.createIntBuffer(maxSize * maxSize); +// for (int i = 0; i < maxSize * maxSize; i++) { +// int cursorX = i % maxSize; +// int cursorY = i / maxSize; +// if (cursorX >= image.getWidth() || cursorY >= image.getHeight()) { +// buffer.put(0x00000000); +// } else { +// buffer.put(image.getRGB(cursorX, image.getHeight() - 1 - cursorY)); +// } +// } +// buffer.flip(); +// Mouse.setNativeCursor(new Cursor(maxSize, maxSize, hotspotX, hotspotY, 1, +// buffer, null +// )); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } +//} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/util/Splitters.java b/src/main/java/at/hannibal2/skyhanni/config/core/util/Splitters.java new file mode 100644 index 000000000..25b3bd316 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/util/Splitters.java @@ -0,0 +1,26 @@ +///* +// * Copyright (C) 2022 NotEnoughUpdates contributors +// * +// * This file is part of NotEnoughUpdates. +// * +// * NotEnoughUpdates 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. +// * +// * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. +// */ +// +//package at.hannibal2.skyhanni.config.core.util; +// +//import com.google.common.base.Splitter; +// +//public class Splitters { +// public static final Splitter NEWLINE_SPLITTER = Splitter.on('\n'); +//} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/util/StringUtils.java b/src/main/java/at/hannibal2/skyhanni/config/core/util/StringUtils.java new file mode 100644 index 000000000..999786518 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/util/StringUtils.java @@ -0,0 +1,77 @@ +///* +// * Copyright (C) 2022 NotEnoughUpdates contributors +// * +// * This file is part of NotEnoughUpdates. +// * +// * NotEnoughUpdates 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. +// * +// * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. +// */ +// +//package at.hannibal2.skyhanni.config.core.util; +// +//import com.google.common.collect.Sets; +//import net.minecraft.client.Minecraft; +//import net.minecraft.client.gui.FontRenderer; +// +//import java.io.UnsupportedEncodingException; +//import java.net.URLEncoder; +//import java.nio.charset.StandardCharsets; +//import java.util.Set; +// +//public class StringUtils { +// public static final Set<String> PROTOCOLS = Sets.newHashSet("http", "https"); +// +// public static String cleanColour(String in) { +// return in.replaceAll("(?i)\\u00A7.", ""); +// } +// +// public static String cleanColourNotModifiers(String in) { +// return in.replaceAll("(?i)\\u00A7[0-9a-f]", "\u00A7r"); +// } +// +// public static String trimToWidth(String str, int len) { +// FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; +// String trim = fr.trimStringToWidth(str, len); +// +// if (str.length() != trim.length() && !trim.endsWith(" ")) { +// char next = str.charAt(trim.length()); +// if (next != ' ') { +// String[] split = trim.split(" "); +// String last = split[split.length - 1]; +// if (last.length() < 8) { +// trim = trim.substring(0, trim.length() - last.length()); +// } +// } +// } +// +// return trim; +// } +// +// public static String substringBetween(String str, String open, String close) { +// return org.apache.commons.lang3.StringUtils.substringBetween(str, open, close); +// } +// +// public static int cleanAndParseInt(String str) { +// str = cleanColour(str); +// str = str.replace(",", ""); +// return Integer.parseInt(str); +// } +// +// public static String urlEncode(String something) { +// try { +// return URLEncoder.encode(something, StandardCharsets.UTF_8.name()); +// } catch (UnsupportedEncodingException e) { +// throw new RuntimeException(e); // UTF 8 should always be present +// } +// } +//} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/util/Vec3Comparable.java b/src/main/java/at/hannibal2/skyhanni/config/core/util/Vec3Comparable.java new file mode 100644 index 000000000..72d99ed23 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/util/Vec3Comparable.java @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.util; + +import net.minecraft.util.BlockPos; +import net.minecraft.util.Vec3; +import net.minecraft.util.Vec3i; + +public class Vec3Comparable extends Vec3 implements Comparable<Vec3Comparable> { + public static final Vec3Comparable NULL_VECTOR = new Vec3Comparable(0.0, 0.0, 0.0); + + public Vec3Comparable(double x, double y, double z) { + super(x, y, z); + } + + public Vec3Comparable(Vec3i sourceVec) { + super(sourceVec); + } + + public Vec3Comparable(Vec3 source) { + super(source.xCoord, source.yCoord, source.zCoord); + } + + public Vec3Comparable(BlockPos source) { + + super(source.getX(), source.getY(), source.getZ()); + } + + public Vec3Comparable(Vec3Comparable source) { + super(source.xCoord, source.yCoord, source.zCoord); + } + + @Override + public Vec3Comparable subtractReverse(Vec3 vec) { + return new Vec3Comparable(super.subtractReverse(vec)); + } + + @Override + public Vec3Comparable normalize() { + return new Vec3Comparable(super.normalize()); + } + + @Override + public Vec3Comparable crossProduct(Vec3 vec) { + return new Vec3Comparable(super.crossProduct(vec)); + } + + @Override + public Vec3Comparable subtract(Vec3 vec) { + return new Vec3Comparable(super.subtract(vec)); + } + + @Override + public Vec3Comparable subtract(double x, double y, double z) { + return new Vec3Comparable(super.subtract(x, y, z)); + } + + @Override + public Vec3Comparable add(Vec3 other) { + return new Vec3Comparable(super.add(other)); + } + + @Override + public Vec3Comparable addVector(double x, double y, double z) { + return new Vec3Comparable(super.addVector(x, y, z)); + } + + @Override + public Vec3Comparable getIntermediateWithXValue(Vec3 vec, double x) { + return new Vec3Comparable(super.getIntermediateWithXValue(vec, x)); + } + + @Override + public Vec3Comparable getIntermediateWithYValue(Vec3 vec, double y) { + return new Vec3Comparable(super.getIntermediateWithYValue(vec, y)); + } + + @Override + public Vec3Comparable getIntermediateWithZValue(Vec3 vec, double z) { + return new Vec3Comparable(super.getIntermediateWithZValue(vec, z)); + } + + @Override + public Vec3Comparable rotatePitch(float pitch) { + return new Vec3Comparable(super.rotatePitch(pitch)); + } + + @Override + public Vec3Comparable rotateYaw(float yaw) { + return new Vec3Comparable(super.rotateYaw(yaw)); + } + + @Override + public boolean equals(Object other) { + if (this == other) { + return true; + } else if (!(other instanceof Vec3Comparable)) { + return false; + } else { + Vec3Comparable vec3c = (Vec3Comparable) other; + return this.xCoord == vec3c.xCoord && this.yCoord == vec3c.yCoord && this.zCoord == vec3c.zCoord; + } + } + + @Override + public int hashCode() { + long bits = 1L; + bits = 31L * bits + doubleToLongBits(xCoord); + bits = 31L * bits + doubleToLongBits(yCoord); + bits = 31L * bits + doubleToLongBits(zCoord); + return (int) (bits ^ (bits >> 32)); + } + + public int compareTo(Vec3Comparable other) { + return this.yCoord == other.yCoord ? + (this.zCoord == other.zCoord ? + (int) (this.xCoord - other.xCoord) + : (int) (this.zCoord - other.zCoord)) + : (int) (this.yCoord - other.yCoord); + } + + public boolean signumEquals(Vec3 other) { + return Math.signum(xCoord) == Math.signum(other.xCoord) && + Math.signum(yCoord) == Math.signum(other.yCoord) && + Math.signum(zCoord) == Math.signum(other.zCoord); + } + + private static long doubleToLongBits(double d) { + return d == 0.0 ? 0L : Double.doubleToLongBits(d); + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/util/lerp/LerpUtils.java b/src/main/java/at/hannibal2/skyhanni/config/core/util/lerp/LerpUtils.java new file mode 100644 index 000000000..8b6cbbc35 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/util/lerp/LerpUtils.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.util.lerp; + +public class LerpUtils { + public static float clampZeroOne(float f) { + return Math.max(0, Math.min(1, f)); + } + + public static float sigmoid(float val) { + return (float) (1 / (1 + Math.exp(-val))); + } + + private static final float sigmoidStr = 8; + private static final float sigmoidA = -1 / (sigmoid(-0.5f * sigmoidStr) - sigmoid(0.5f * sigmoidStr)); + private static final float sigmoidB = sigmoidA * sigmoid(-0.5f * sigmoidStr); + + public static float sigmoidZeroOne(float f) { + f = clampZeroOne(f); + return sigmoidA * sigmoid(sigmoidStr * (f - 0.5f)) - sigmoidB; + } + + public static float lerp(float a, float b, float amount) { + return b + (a - b) * clampZeroOne(amount); + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/util/lerp/LerpingFloat.java b/src/main/java/at/hannibal2/skyhanni/config/core/util/lerp/LerpingFloat.java new file mode 100644 index 000000000..4f9c699a2 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/util/lerp/LerpingFloat.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.util.lerp; + +public class LerpingFloat { + private int timeSpent; + private long lastMillis; + private final int timeToReachTarget; + + private float targetValue; + private float lerpValue; + + public LerpingFloat(float initialValue, int timeToReachTarget) { + this.targetValue = this.lerpValue = initialValue; + this.timeToReachTarget = timeToReachTarget; + } + + public LerpingFloat(int initialValue) { + this(initialValue, 200); + } + + public void tick() { + int lastTimeSpent = timeSpent; + this.timeSpent += System.currentTimeMillis() - lastMillis; + + float lastDistPercentToTarget = lastTimeSpent / (float) timeToReachTarget; + float distPercentToTarget = timeSpent / (float) timeToReachTarget; + float fac = (1 - lastDistPercentToTarget) / lastDistPercentToTarget; + + float startValue = lerpValue - (targetValue - lerpValue) / fac; + + float dist = targetValue - startValue; + if (dist == 0) return; + + float oldLerpValue = lerpValue; + if (distPercentToTarget >= 1) { + lerpValue = targetValue; + } else { + lerpValue = startValue + dist * distPercentToTarget; + } + + if (lerpValue == oldLerpValue) { + timeSpent = lastTimeSpent; + } else { + this.lastMillis = System.currentTimeMillis(); + } + } + + public void resetTimer() { + this.timeSpent = 0; + this.lastMillis = System.currentTimeMillis(); + } + + public void setTarget(float targetValue) { + this.targetValue = targetValue; + } + + public void setValue(float value) { + this.targetValue = this.lerpValue = value; + } + + public float getValue() { + return lerpValue; + } + + public float getTarget() { + return targetValue; + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/util/lerp/LerpingInteger.java b/src/main/java/at/hannibal2/skyhanni/config/core/util/lerp/LerpingInteger.java new file mode 100644 index 000000000..e97b2dc1c --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/util/lerp/LerpingInteger.java @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.util.lerp; + +public class LerpingInteger { + private int timeSpent; + private long lastMillis; + private int timeToReachTarget; + + private int targetValue; + private int lerpValue; + + public LerpingInteger(int initialValue, int timeToReachTarget) { + this.targetValue = this.lerpValue = initialValue; + this.timeToReachTarget = timeToReachTarget; + } + + public LerpingInteger(int initialValue) { + this(initialValue, 200); + } + + public void tick() { + int lastTimeSpent = timeSpent; + this.timeSpent += System.currentTimeMillis() - lastMillis; + + float lastDistPercentToTarget = lastTimeSpent / (float) timeToReachTarget; + float distPercentToTarget = timeSpent / (float) timeToReachTarget; + float fac = (1 - lastDistPercentToTarget) / lastDistPercentToTarget; + + int startValue = lerpValue - (int) ((targetValue - lerpValue) / fac); + + int dist = targetValue - startValue; + if (dist == 0) return; + + int oldLerpValue = lerpValue; + if (distPercentToTarget >= 1) { + lerpValue = targetValue; + } else { + lerpValue = startValue + (int) (dist * distPercentToTarget); + } + + if (lerpValue == oldLerpValue) { + timeSpent = lastTimeSpent; + } else { + this.lastMillis = System.currentTimeMillis(); + } + } + + public int getTimeSpent() { + return timeSpent; + } + + public void resetTimer() { + this.timeSpent = 0; + this.lastMillis = System.currentTimeMillis(); + } + + public void setTimeToReachTarget(int timeToReachTarget) { + this.timeToReachTarget = timeToReachTarget; + } + + public void setTarget(int targetValue) { + this.targetValue = targetValue; + } + + public void setValue(int value) { + this.targetValue = this.lerpValue = value; + } + + public int getValue() { + return lerpValue; + } + + public int getTarget() { + return targetValue; + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/util/render/GuiRenderUtils.java b/src/main/java/at/hannibal2/skyhanni/config/core/util/render/GuiRenderUtils.java new file mode 100644 index 000000000..69c7b90b6 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/util/render/GuiRenderUtils.java @@ -0,0 +1,391 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.util.render; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.entity.Entity; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.MathHelper; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.Vec3i; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL14; +import org.lwjgl.util.vector.Vector3f; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class GuiRenderUtils { + public static void drawFloatingRectDark(int x, int y, int width, int height) { + drawFloatingRectDark(x, y, width, height, true); + } + + public static void drawFloatingRectDark(int x, int y, int width, int height, boolean shadow) { + int alpha = 0xf0000000; + + if (OpenGlHelper.isFramebufferEnabled()) { +// ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); +// BackgroundBlur.renderBlurredBackground(15, scaledResolution.getScaledWidth(), +// scaledResolution.getScaledHeight(), x, y, width, height, true +// ); + } else { + alpha = 0xff000000; + } + + int main = alpha | 0x202026; + int light = 0xff303036; + int dark = 0xff101016; + Gui.drawRect(x, y, x + 1, y + height, light); //Left + Gui.drawRect(x + 1, y, x + width, y + 1, light); //Top + Gui.drawRect(x + width - 1, y + 1, x + width, y + height, dark); //Right + Gui.drawRect(x + 1, y + height - 1, x + width - 1, y + height, dark); //Bottom + Gui.drawRect(x + 1, y + 1, x + width - 1, y + height - 1, main); //Middle + if (shadow) { + Gui.drawRect(x + width, y + 2, x + width + 2, y + height + 2, 0x70000000); //Right shadow + Gui.drawRect(x + 2, y + height, x + width, y + height + 2, 0x70000000); //Bottom shadow + } + } + + public static void drawFloatingRect(int x, int y, int width, int height) { + drawFloatingRectWithAlpha(x, y, width, height, 0xFF, true); + } + + public static void drawFloatingRectWithAlpha(int x, int y, int width, int height, int alpha, boolean shadow) { + int main = (alpha << 24) | 0xc0c0c0; + int light = (alpha << 24) | 0xf0f0f0; + int dark = (alpha << 24) | 0x909090; + Gui.drawRect(x, y, x + 1, y + height, light); //Left + Gui.drawRect(x + 1, y, x + width, y + 1, light); //Top + Gui.drawRect(x + width - 1, y + 1, x + width, y + height, dark); //Right + Gui.drawRect(x + 1, y + height - 1, x + width - 1, y + height, dark); //Bottom + Gui.drawRect(x + 1, y + 1, x + width - 1, y + height - 1, main); //Middle + if (shadow) { + Gui.drawRect(x + width, y + 2, x + width + 2, y + height + 2, (alpha * 3 / 5) << 24); //Right shadow + Gui.drawRect(x + 2, y + height, x + width, y + height + 2, (alpha * 3 / 5) << 24); //Bottom shadow + } + } + + public static void drawTexturedRect(float x, float y, float width, float height) { + drawTexturedRect(x, y, width, height, 0, 1, 0, 1); + } + + public static void drawTexturedRect(float x, float y, float width, float height, int filter) { + drawTexturedRect(x, y, width, height, 0, 1, 0, 1, filter); + } + + public static void drawTexturedRect( + float x, + float y, + float width, + float height, + float uMin, + float uMax, + float vMin, + float vMax + ) { + drawTexturedRect(x, y, width, height, uMin, uMax, vMin, vMax, GL11.GL_NEAREST); + } + + public static void drawTexturedRect( + float x, + float y, + float width, + float height, + float uMin, + float uMax, + float vMin, + float vMax, + int filter + ) { + GlStateManager.enableBlend(); + GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); + + drawTexturedRectNoBlend(x, y, width, height, uMin, uMax, vMin, vMax, filter); + + GlStateManager.disableBlend(); + } + + public static void drawTexturedRectNoBlend( + float x, + float y, + float width, + float height, + float uMin, + float uMax, + float vMin, + float vMax, + int filter + ) { + GlStateManager.enableTexture2D(); + + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, filter); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, filter); + + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX); + worldrenderer + .pos(x, y + height, 0.0D) + .tex(uMin, vMax).endVertex(); + worldrenderer + .pos(x + width, y + height, 0.0D) + .tex(uMax, vMax).endVertex(); + worldrenderer + .pos(x + width, y, 0.0D) + .tex(uMax, vMin).endVertex(); + worldrenderer + .pos(x, y, 0.0D) + .tex(uMin, vMin).endVertex(); + tessellator.draw(); + + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); + } + + public static void drawGradientRect( + int zLevel, + int left, + int top, + int right, + int bottom, + int startColor, + int endColor + ) { + float startAlpha = (float) (startColor >> 24 & 255) / 255.0F; + float startRed = (float) (startColor >> 16 & 255) / 255.0F; + float startGreen = (float) (startColor >> 8 & 255) / 255.0F; + float startBlue = (float) (startColor & 255) / 255.0F; + float endAlpha = (float) (endColor >> 24 & 255) / 255.0F; + float endRed = (float) (endColor >> 16 & 255) / 255.0F; + float endGreen = (float) (endColor >> 8 & 255) / 255.0F; + float endBlue = (float) (endColor & 255) / 255.0F; + + GlStateManager.disableTexture2D(); + GlStateManager.enableBlend(); + GlStateManager.disableAlpha(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + GlStateManager.shadeModel(7425); + + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR); + worldrenderer.pos(right, top, zLevel).color(startRed, startGreen, startBlue, startAlpha).endVertex(); + worldrenderer.pos(left, top, zLevel).color(startRed, startGreen, startBlue, startAlpha).endVertex(); + worldrenderer.pos(left, bottom, zLevel).color(endRed, endGreen, endBlue, endAlpha).endVertex(); + worldrenderer.pos(right, bottom, zLevel).color(endRed, endGreen, endBlue, endAlpha).endVertex(); + tessellator.draw(); + + GlStateManager.shadeModel(7424); + GlStateManager.disableBlend(); + GlStateManager.enableAlpha(); + GlStateManager.enableTexture2D(); + } + + private static final ResourceLocation beaconBeam = new ResourceLocation("textures/entity/beacon_beam.png"); + + private static void renderBeaconBeam( + double x, double y, double z, int rgb, float alphaMult, + float partialTicks, Boolean disableDepth + ) { + int height = 300; + int bottomOffset = 0; + int topOffset = bottomOffset + height; + + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + + if (disableDepth) { + GlStateManager.disableDepth(); + } + + Minecraft.getMinecraft().getTextureManager().bindTexture(beaconBeam); + GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT); + GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT); + GlStateManager.disableLighting(); + GlStateManager.enableCull(); + GlStateManager.enableTexture2D(); + GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE, GL11.GL_ZERO); + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO); + + double time = Minecraft.getMinecraft().theWorld.getTotalWorldTime() + (double) partialTicks; + double d1 = MathHelper.func_181162_h(-time * 0.2D - (double) MathHelper.floor_double(-time * 0.1D)); + + float r = ((rgb >> 16) & 0xFF) / 255f; + float g = ((rgb >> 8) & 0xFF) / 255f; + float b = (rgb & 0xFF) / 255f; + double d2 = time * 0.025D * -1.5D; + double d4 = 0.5D + Math.cos(d2 + 2.356194490192345D) * 0.2D; + double d5 = 0.5D + Math.sin(d2 + 2.356194490192345D) * 0.2D; + double d6 = 0.5D + Math.cos(d2 + (Math.PI / 4D)) * 0.2D; + double d7 = 0.5D + Math.sin(d2 + (Math.PI / 4D)) * 0.2D; + double d8 = 0.5D + Math.cos(d2 + 3.9269908169872414D) * 0.2D; + double d9 = 0.5D + Math.sin(d2 + 3.9269908169872414D) * 0.2D; + double d10 = 0.5D + Math.cos(d2 + 5.497787143782138D) * 0.2D; + double d11 = 0.5D + Math.sin(d2 + 5.497787143782138D) * 0.2D; + double d14 = -1.0D + d1; + double d15 = (double) (height) * 2.5D + d14; + worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR); + worldrenderer.pos(x + d4, y + topOffset, z + d5).tex(1.0D, d15).color(r, g, b, 1.0F * alphaMult).endVertex(); + worldrenderer.pos(x + d4, y + bottomOffset, z + d5).tex(1.0D, d14).color(r, g, b, 1.0F).endVertex(); + worldrenderer.pos(x + d6, y + bottomOffset, z + d7).tex(0.0D, d14).color(r, g, b, 1.0F).endVertex(); + worldrenderer.pos(x + d6, y + topOffset, z + d7).tex(0.0D, d15).color(r, g, b, 1.0F * alphaMult).endVertex(); + worldrenderer.pos(x + d10, y + topOffset, z + d11).tex(1.0D, d15).color(r, g, b, 1.0F * alphaMult).endVertex(); + worldrenderer.pos(x + d10, y + bottomOffset, z + d11).tex(1.0D, d14).color(r, g, b, 1.0F).endVertex(); + worldrenderer.pos(x + d8, y + bottomOffset, z + d9).tex(0.0D, d14).color(r, g, b, 1.0F).endVertex(); + worldrenderer.pos(x + d8, y + topOffset, z + d9).tex(0.0D, d15).color(r, g, b, 1.0F * alphaMult).endVertex(); + worldrenderer.pos(x + d6, y + topOffset, z + d7).tex(1.0D, d15).color(r, g, b, 1.0F * alphaMult).endVertex(); + worldrenderer.pos(x + d6, y + bottomOffset, z + d7).tex(1.0D, d14).color(r, g, b, 1.0F).endVertex(); + worldrenderer.pos(x + d10, y + bottomOffset, z + d11).tex(0.0D, d14).color(r, g, b, 1.0F).endVertex(); + worldrenderer.pos(x + d10, y + topOffset, z + d11).tex(0.0D, d15).color(r, g, b, 1.0F * alphaMult).endVertex(); + worldrenderer.pos(x + d8, y + topOffset, z + d9).tex(1.0D, d15).color(r, g, b, 1.0F * alphaMult).endVertex(); + worldrenderer.pos(x + d8, y + bottomOffset, z + d9).tex(1.0D, d14).color(r, g, b, 1.0F).endVertex(); + worldrenderer.pos(x + d4, y + bottomOffset, z + d5).tex(0.0D, d14).color(r, g, b, 1.0F).endVertex(); + worldrenderer.pos(x + d4, y + topOffset, z + d5).tex(0.0D, d15).color(r, g, b, 1.0F * alphaMult).endVertex(); + tessellator.draw(); + + GlStateManager.disableCull(); + double d12 = -1.0D + d1; + double d13 = height + d12; + + worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR); + worldrenderer.pos(x + 0.2D, y + topOffset, z + 0.2D).tex(1.0D, d13).color(r, g, b, 0.25F * alphaMult).endVertex(); + worldrenderer.pos(x + 0.2D, y + bottomOffset, z + 0.2D).tex(1.0D, d12).color(r, g, b, 0.25F).endVertex(); + worldrenderer.pos(x + 0.8D, y + bottomOffset, z + 0.2D).tex(0.0D, d12).color(r, g, b, 0.25F).endVertex(); + worldrenderer.pos(x + 0.8D, y + topOffset, z + 0.2D).tex(0.0D, d13).color(r, g, b, 0.25F * alphaMult).endVertex(); + worldrenderer.pos(x + 0.8D, y + topOffset, z + 0.8D).tex(1.0D, d13).color(r, g, b, 0.25F * alphaMult).endVertex(); + worldrenderer.pos(x + 0.8D, y + bottomOffset, z + 0.8D).tex(1.0D, d12).color(r, g, b, 0.25F).endVertex(); + worldrenderer.pos(x + 0.2D, y + bottomOffset, z + 0.8D).tex(0.0D, d12).color(r, g, b, 0.25F).endVertex(); + worldrenderer.pos(x + 0.2D, y + topOffset, z + 0.8D).tex(0.0D, d13).color(r, g, b, 0.25F * alphaMult).endVertex(); + worldrenderer.pos(x + 0.8D, y + topOffset, z + 0.2D).tex(1.0D, d13).color(r, g, b, 0.25F * alphaMult).endVertex(); + worldrenderer.pos(x + 0.8D, y + bottomOffset, z + 0.2D).tex(1.0D, d12).color(r, g, b, 0.25F).endVertex(); + worldrenderer.pos(x + 0.8D, y + bottomOffset, z + 0.8D).tex(0.0D, d12).color(r, g, b, 0.25F).endVertex(); + worldrenderer.pos(x + 0.8D, y + topOffset, z + 0.8D).tex(0.0D, d13).color(r, g, b, 0.25F * alphaMult).endVertex(); + worldrenderer.pos(x + 0.2D, y + topOffset, z + 0.8D).tex(1.0D, d13).color(r, g, b, 0.25F * alphaMult).endVertex(); + worldrenderer.pos(x + 0.2D, y + bottomOffset, z + 0.8D).tex(1.0D, d12).color(r, g, b, 0.25F).endVertex(); + worldrenderer.pos(x + 0.2D, y + bottomOffset, z + 0.2D).tex(0.0D, d12).color(r, g, b, 0.25F).endVertex(); + worldrenderer.pos(x + 0.2D, y + topOffset, z + 0.2D).tex(0.0D, d13).color(r, g, b, 0.25F * alphaMult).endVertex(); + tessellator.draw(); + + GlStateManager.disableLighting(); + GlStateManager.enableTexture2D(); + if (disableDepth) { + GlStateManager.enableDepth(); + } + } + + public static void renderWayPoint(String str, Vec3i loc, float partialTicks) { + renderWayPoint(str, new Vector3f(loc.getX(), loc.getY(), loc.getZ()), partialTicks); + } + + public static void renderWayPoint(List<String> str, Vec3i loc, float partialTicks) { + renderWayPoint(str, new Vector3f(loc.getX(), loc.getY(), loc.getZ()), partialTicks); + } + + public static void renderWayPoint(String str, Vector3f loc, float partialTicks) { + renderWayPoint(Arrays.asList(str), loc, partialTicks); + } + + public static void renderWayPoint(List<String> lines, Vector3f loc, float partialTicks) { + GlStateManager.alphaFunc(516, 0.1F); + + GlStateManager.pushMatrix(); + + Entity viewer = Minecraft.getMinecraft().getRenderViewEntity(); + double viewerX = viewer.lastTickPosX + (viewer.posX - viewer.lastTickPosX) * partialTicks; + double viewerY = viewer.lastTickPosY + (viewer.posY - viewer.lastTickPosY) * partialTicks; + double viewerZ = viewer.lastTickPosZ + (viewer.posZ - viewer.lastTickPosZ) * partialTicks; + + double x = loc.x - viewerX + 0.5f; + double y = loc.y - viewerY - viewer.getEyeHeight(); + double z = loc.z - viewerZ + 0.5f; + + double distSq = x * x + y * y + z * z; + double dist = Math.sqrt(distSq); + if (distSq > 144) { + x *= 12 / dist; + y *= 12 / dist; + z *= 12 / dist; + } + GlStateManager.translate(x, y, z); + GlStateManager.translate(0, viewer.getEyeHeight(), 0); + + lines = new ArrayList<>(lines); + lines.add(EnumChatFormatting.YELLOW.toString() + Math.round(dist) + "m"); + renderNametag(lines); + + GlStateManager.popMatrix(); + + GlStateManager.disableLighting(); + } + + public static void renderNametag(String str) { + renderNametag(Arrays.asList(str)); + } + + public static void renderNametag(List<String> lines) { + FontRenderer fontrenderer = Minecraft.getMinecraft().fontRendererObj; + float f = 1.6F; + float f1 = 0.016666668F * f; + GlStateManager.pushMatrix(); + GL11.glNormal3f(0.0F, 1.0F, 0.0F); + GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F); + GlStateManager.rotate(Minecraft.getMinecraft().getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F); + GlStateManager.scale(-f1, -f1, f1); + GlStateManager.disableLighting(); + GlStateManager.depthMask(false); + GlStateManager.disableDepth(); + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + int i = 0; + + for (String str : lines) { + int j = fontrenderer.getStringWidth(str) / 2; + + GlStateManager.disableTexture2D(); + worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR); + worldrenderer.pos(-j - 1, -1 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); + worldrenderer.pos(-j - 1, 8 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); + worldrenderer.pos(j + 1, 8 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); + worldrenderer.pos(j + 1, -1 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); + tessellator.draw(); + GlStateManager.enableTexture2D(); + fontrenderer.drawString(str, -fontrenderer.getStringWidth(str) / 2, i, 553648127); + GlStateManager.depthMask(true); + + fontrenderer.drawString(str, -fontrenderer.getStringWidth(str) / 2, i, -1); + GlStateManager.translate(0, 10f, 0); + } + GlStateManager.enableDepth(); + GlStateManager.enableBlend(); + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + GlStateManager.popMatrix(); + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/util/render/TextRenderUtils.java b/src/main/java/at/hannibal2/skyhanni/config/core/util/render/TextRenderUtils.java new file mode 100644 index 000000000..bc1208e4d --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/util/render/TextRenderUtils.java @@ -0,0 +1,345 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates 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. + * + * NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package at.hannibal2.skyhanni.config.core.util.render; + +import at.hannibal2.skyhanni.utils.StringUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import org.lwjgl.opengl.GL11; + +import java.util.ArrayList; +import java.util.List; + +public class TextRenderUtils { + public static int getCharVertLen(char c) { + if ("acegmnopqrsuvwxyz".indexOf(c) >= 0) { + return 5; + } else { + return 7; + } + } + + public static float getVerticalHeight(String str) { + str = StringUtils.INSTANCE.removeColor(str); + float height = 0; + for (int i = 0; i < str.length(); i++) { + char c = str.charAt(i); + int charHeight = getCharVertLen(c); + height += charHeight + 1.5f; + } + return height; + } + + public static void drawStringVertical(String str, FontRenderer fr, float x, float y, boolean shadow, int colour) { + String format = FontRenderer.getFormatFromString(str); + str = StringUtils.INSTANCE.removeColor(str); + for (int i = 0; i < str.length(); i++) { + char c = str.charAt(i); + + int charHeight = getCharVertLen(c); + int charWidth = fr.getCharWidth(c); + fr.drawString(format + c, x + (5 - charWidth) / 2f, y - 7 + charHeight, colour, shadow); + + y += charHeight + 1.5f; + } + } + + public static void drawStringScaledMaxWidth( + String str, + FontRenderer fr, + float x, + float y, + boolean shadow, + int len, + int colour + ) { + int strLen = fr.getStringWidth(str); + float factor = len / (float) strLen; + factor = Math.min(1, factor); + + drawStringScaled(str, fr, x, y, shadow, colour, factor); + } + + public static void drawStringCentered(String str, FontRenderer fr, float x, float y, boolean shadow, int colour) { + int strLen = fr.getStringWidth(str); + + float x2 = x - strLen / 2f; + float y2 = y - fr.FONT_HEIGHT / 2f; + + GL11.glTranslatef(x2, y2, 0); + fr.drawString(str, 0, 0, colour, shadow); + GL11.glTranslatef(-x2, -y2, 0); + } + + public static void drawStringScaled( + String str, + FontRenderer fr, + float x, + float y, + boolean shadow, + int colour, + float factor + ) { + GlStateManager.scale(factor, factor, 1); + fr.drawString(str, x / factor, y / factor, colour, shadow); + GlStateManager.scale(1 / factor, 1 / factor, 1); + } + + public static void drawStringCenteredScaledMaxWidth( + String str, + FontRenderer fr, + float x, + float y, + boolean shadow, + int len, + int colour + ) { + int strLen = fr.getStringWidth(str); + float factor = len / (float) strLen; + factor = Math.min(1, factor); + int newLen = Math.min(strLen, len); + + float fontHeight = 8 * factor; + + drawStringScaled(str, fr, x - newLen / 2, y - fontHeight / 2, shadow, colour, factor); + } + + public static void renderToolTip( + ItemStack stack, + int mouseX, + int mouseY, + int screenWidth, + int screenHeight, + FontRenderer fontStd + ) { + List<String> list = stack.getTooltip( + Minecraft.getMinecraft().thePlayer, + Minecraft.getMinecraft().gameSettings.advancedItemTooltips + ); + + for (int i = 0; i < list.size(); ++i) { + if (i == 0) { + list.set(i, stack.getRarity().rarityColor + list.get(i)); + } else { + list.set(i, EnumChatFormatting.GRAY + list.get(i)); + } + } + + FontRenderer font = stack.getItem().getFontRenderer(stack); + drawHoveringText(list, mouseX, mouseY, screenWidth, screenHeight, -1, font == null ? fontStd : font); + } + + public static void drawHoveringText( + List<String> textLines, + final int mouseX, + final int mouseY, + final int screenWidth, + final int screenHeight, + final int maxTextWidth, + FontRenderer font + ) { + if (!textLines.isEmpty()) { + GlStateManager.disableRescaleNormal(); + RenderHelper.disableStandardItemLighting(); + GlStateManager.disableLighting(); + GlStateManager.disableDepth(); + int tooltipTextWidth = 0; + + for (String textLine : textLines) { + int textLineWidth = font.getStringWidth(textLine); + + if (textLineWidth > tooltipTextWidth) { + tooltipTextWidth = textLineWidth; + } + } + + boolean needsWrap = false; + + int titleLinesCount = 1; + int tooltipX = mouseX + 12; + if (tooltipX + tooltipTextWidth + 4 > screenWidth) { + tooltipX = mouseX - 16 - tooltipTextWidth; + if (tooltipX < 4) // if the tooltip doesn't fit on the screen + { + if (mouseX > screenWidth / 2) { + tooltipTextWidth = mouseX - 12 - 8; + } else { + tooltipTextWidth = screenWidth - 16 - mouseX; + } + needsWrap = true; + } + } + + if (maxTextWidth > 0 && tooltipTextWidth > maxTextWidth) { + tooltipTextWidth = maxTextWidth; + needsWrap = true; + } + + if (needsWrap) { + int wrappedTooltipWidth = 0; + List<String> wrappedTextLines = new ArrayList<>(); + for (int i = 0; i < textLines.size(); i++) { + String textLine = textLines.get(i); + List<String> wrappedLine = font.listFormattedStringToWidth(textLine, tooltipTextWidth); + if (i == 0) { + titleLinesCount = wrappedLine.size(); + } + + for (String line : wrappedLine) { + int lineWidth = font.getStringWidth(line); + if (lineWidth > wrappedTooltipWidth) { + wrappedTooltipWidth = lineWidth; + } + wrappedTextLines.add(line); + } + } + tooltipTextWidth = wrappedTooltipWidth; + textLines = wrappedTextLines; + + if (mouseX > screenWidth / 2) { + tooltipX = mouseX - 16 - tooltipTextWidth; + } else { + tooltipX = mouseX + 12; + } + } + + int tooltipY = mouseY - 12; + int tooltipHeight = 8; + + if (textLines.size() > 1) { + tooltipHeight += (textLines.size() - 1) * 10; + if (textLines.size() > titleLinesCount) { + tooltipHeight += 2; // gap between title lines and next lines + } + } + + if (tooltipY + tooltipHeight + 6 > screenHeight) { + tooltipY = screenHeight - tooltipHeight - 6; + } + + final int zLevel = 300; + final int backgroundColor = 0xF0100010; + GuiRenderUtils.drawGradientRect( + zLevel, + tooltipX - 3, + tooltipY - 4, + tooltipX + tooltipTextWidth + 3, + tooltipY - 3, + backgroundColor, + backgroundColor + ); + GuiRenderUtils.drawGradientRect( + zLevel, + tooltipX - 3, + tooltipY + tooltipHeight + 3, + tooltipX + tooltipTextWidth + 3, + tooltipY + tooltipHeight + 4, + backgroundColor, + backgroundColor + ); + GuiRenderUtils.drawGradientRect( + zLevel, + tooltipX - 3, + tooltipY - 3, + tooltipX + tooltipTextWidth + 3, + tooltipY + tooltipHeight + 3, + backgroundColor, + backgroundColor + ); + GuiRenderUtils.drawGradientRect( + zLevel, + tooltipX - 4, + tooltipY - 3, + tooltipX - 3, + tooltipY + tooltipHeight + 3, + backgroundColor, + backgroundColor + ); + GuiRenderUtils.drawGradientRect( + zLevel, + tooltipX + tooltipTextWidth + 3, + tooltipY - 3, + tooltipX + tooltipTextWidth + 4, + tooltipY + tooltipHeight + 3, + backgroundColor, + backgroundColor + ); + final int borderColorStart = 0x505000FF; + final int borderColorEnd = (borderColorStart & 0xFEFEFE) >> 1 | borderColorStart & 0xFF000000; + GuiRenderUtils.drawGradientRect( + zLevel, + tooltipX - 3, + tooltipY - 3 + 1, + tooltipX - 3 + 1, + tooltipY + tooltipHeight + 3 - 1, + borderColorStart, + borderColorEnd + ); + GuiRenderUtils.drawGradientRect( + zLevel, + tooltipX + tooltipTextWidth + 2, + tooltipY - 3 + 1, + tooltipX + tooltipTextWidth + 3, + tooltipY + tooltipHeight + 3 - 1, + borderColorStart, + borderColorEnd + ); + GuiRenderUtils.drawGradientRect( + zLevel, + tooltipX - 3, + tooltipY - 3, + tooltipX + tooltipTextWidth + 3, + tooltipY - 3 + 1, + borderColorStart, + borderColorStart + ); + GuiRenderUtils.drawGradientRect( + zLevel, + tooltipX - 3, + tooltipY + tooltipHeight + 2, + tooltipX + tooltipTextWidth + 3, + tooltipY + tooltipHeight + 3, + borderColorEnd, + borderColorEnd + ); + + for (int lineNumber = 0; lineNumber < textLines.size(); ++lineNumber) { + String line = textLines.get(lineNumber); + font.drawStringWithShadow(line, (float) tooltipX, (float) tooltipY, -1); + + if (lineNumber + 1 == titleLinesCount) { + tooltipY += 2; + } + + tooltipY += 10; + } + + GlStateManager.enableLighting(); + GlStateManager.enableDepth(); + RenderHelper.enableStandardItemLighting(); + GlStateManager.enableRescaleNormal(); + } + GlStateManager.disableLighting(); + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Abilities.java b/src/main/java/at/hannibal2/skyhanni/config/features/Abilities.java index 4ba58da70..feaf50a60 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Abilities.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Abilities.java @@ -1,7 +1,7 @@ package at.hannibal2.skyhanni.config.features; -import at.hannibal2.skyhanni.config.gui.core.config.Position; -import at.hannibal2.skyhanni.config.gui.core.config.annotations.*; +import at.hannibal2.skyhanni.config.core.config.Position; +import at.hannibal2.skyhanni.config.core.config.annotations.*; import com.google.gson.annotations.Expose; public class Abilities { diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Ashfang.java b/src/main/java/at/hannibal2/skyhanni/config/features/Ashfang.java index 4ddae7a05..75204f144 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Ashfang.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Ashfang.java @@ -1,10 +1,10 @@ package at.hannibal2.skyhanni.config.features; -import at.hannibal2.skyhanni.config.gui.core.config.Position; -import at.hannibal2.skyhanni.config.gui.core.config.annotations.ConfigEditorBoolean; -import at.hannibal2.skyhanni.config.gui.core.config.annotations.ConfigEditorButton; -import at.hannibal2.skyhanni.config.gui.core.config.annotations.ConfigEditorColour; -import at.hannibal2.skyhanni.config.gui.core.config.annotations.ConfigOption; +import at.hannibal2.skyhanni.config.core.config.Position; +import at.hannibal2.skyhanni.config.core.config.annotations.ConfigEditorBoolean; +import at.hannibal2.skyhanni.config.core.config.annotations.ConfigEditorButton; +import at.hannibal2.skyhanni.config.core.config.annotations.ConfigEditorColour; +import at.hannibal2.skyhanni.config.core.config.annotations.ConfigOption; import com.google.gson.annotations.Expose; public class Ashfang { diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Bazaar.java b/src/main/java/at/hannibal2/skyhanni/config/features/Bazaar.java index 2dbc8af68..614568903 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Bazaar.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Bazaar.java @@ -1,9 +1,9 @@ package at.hannibal2.skyhanni.config.features; -import at.hannibal2.skyhanni.config.gui.core.config.Position; -import at.hannibal2.skyhanni.config.gui.core.config.annotations.ConfigEditorBoolean; -import at.hannibal2.skyhanni.config.gui.core.config.annotations.ConfigEditorButton; -import at.hannibal2.skyhanni.config.gui.core.config.annotations.ConfigOption; +import at.hannibal2.skyhanni.config.core.config.Position; +import at.hannibal2.skyhanni.config.core.config.annotations.ConfigEditorBoolean; +import at.hannibal2.skyhanni.config.core.config.annotations.ConfigEditorButton; +import at.hannibal2.skyhanni.config.core.config.annotations.ConfigOption; import com.google.gson.annotations.Expose; public class Bazaar { diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Chat.java b/src/main/java/at/hannibal2/skyhanni/config/features/Chat.java index ec6d7482f..a0d61e86a 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Chat.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Chat.java @@ -1,6 +1,6 @@ package at.hannibal2.skyhanni.config.features; -import at.hannibal2.skyhanni.config.gui.core.config.annotations.*; +import at.hannibal2.skyhanni.config.core.config.annotations.*; import com.google.gson.annotations.Expose; public class Chat { diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/CommandsFeatures.java b/src/main/java/at/hannibal2/skyhanni/config/features/CommandsFeatures.java index 2e1c5ea8f..ed1ea7f56 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/CommandsFeatures.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/CommandsFeatures.java @@ -1,7 +1,7 @@ package at.hannibal2.skyhanni.config.features; -import at.hannibal2.skyhanni.config.gui.core.config.annotations.ConfigEditorBoolean; -import at.hannibal2.skyhanni.config.gui.core.config.annotations.ConfigOption; +import at.hannibal2.skyhanni.config.core.config.annotations.ConfigEditorBoolean; +import at.hannibal2.skyhanni.config.core.config.annotations.ConfigOption; import com.google.gson.annotations.Expose; public class CommandsFeatures { diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/DamageIndicator.java b/src/main/java/at/hannibal2/skyhanni/config/features/DamageIndicator.java index 78421680b..839bde981 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/DamageIndicator.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/DamageIndicator.java @@ -1,9 +1,9 @@ package at.hannibal2.skyhanni.config.features; -import at.hannibal2.skyhanni.config.gui.core.config.annotations.ConfigEditorBoolean; -import at.hannibal2.skyhanni.config.gui.core.config.annotations.ConfigEditorDraggableList; -import at.hannibal2.skyhanni.config.gui.core.config.annotations.ConfigEditorDropdown; -import at.hannibal2.skyhanni.config.gui.core.config.annotations.ConfigOption; +import at.hannibal2.skyhanni.config.core.config.annotations.ConfigEditorBoolean; +import at.hannibal2.skyhanni.config.core.config.annotations.ConfigEditorDraggableList; +import at.hannibal2.skyhanni.config.core.config.annotations.ConfigEditorDropdown; +import at.hannibal2.skyhanni.config.core.config.annotations.ConfigOption; import com.google.gson.annotations.Expose; import java.util.ArrayList; diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/DevData.java b/src/main/java/at/hannibal2/skyhanni/config/features/DevData.java index 794fb6d8d..7fa3dc609 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/DevData.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/DevData.java @@ -1,7 +1,7 @@ package at.hannibal2.skyhanni.config.features; -import at.hannibal2.skyhanni.config.gui.core.config.Position; -import at.hannibal2.skyhanni.config.gui.core.config.annotations.*; +import at.hannibal2.skyhanni.config.core.config.Position; +import at.hannibal2.skyhanni.config.core.config.annotations.*; import com.google.gson.annotations.Expose; public class DevData { diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Dungeon.java b/src/main/java/at/hannibal2/skyhanni/config/features/Dungeon.java index 75fd777fc..e32fefdcb 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Dungeon.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Dungeon.java @@ -1,7 +1,7 @@ package at.hannibal2.skyhanni.config.features; -import at.hannibal2.skyhanni.config.gui.core.config.Position; -import at.hannibal2.skyhanni.config.gui.core.config.annotations.*; +import at.hannibal2.skyhanni.config.core.config.Position; +import at.hannibal2.skyhanni.config.core.config.annotations.*; import com.google.gson.annotations.Expose; public class Dungeon { diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Fishing.java b/src/main/java/at/hannibal2/skyhanni/config/features/Fishing.java index 384a28075..ce882e3dd 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Fishing.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Fishing.java @@ -1,7 +1,7 @@ package at.hannibal2.skyhanni.config.features; -import at.hannibal2.skyhanni.config.gui.core.config.annotations.ConfigEditorBoolean; -import at.hannibal2.skyhanni.config.gui.core.config.annotations.ConfigOption; +import at.hannibal2.skyhanni.config.core.config.annotations.ConfigEditorBoolean; +import at.hannibal2.skyhanni.config.core.config.annotations.ConfigOption; import com.google.gson.annotations.Expose; public class Fishing { diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Inventory.java b/src/main/java/at/hannibal2/skyhanni/config/features/Inventory.java index 75b0831ab..0aa24cb28 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Inventory.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Inventory.java @@ -1,6 +1,6 @@ package at.hannibal2.skyhanni.config.features; -import at.hannibal2.skyhanni.config.gui.core.config.annotations.*; +import at.hannibal2.skyhanni.config.core.config.annotations.*; import com.google.gson.annotations.Expose; import java.util.ArrayList; diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Minions.java b/src/main/java/at/hannibal2/skyhanni/config/features/Minions.java index ce5f68e4c..718c46576 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Minions.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Minions.java @@ -1,7 +1,7 @@ package at.hannibal2.skyhanni.config.features; -import at.hannibal2.skyhanni.config.gui.core.config.Position; -import at.hannibal2.skyhanni.config.gui.core.config.annotations.*; +import at.hannibal2.skyhanni.config.core.config.Position; +import at.hannibal2.skyhanni.config.core.config.annotations.*; import com.google.gson.annotations.Expose; public class Minions { diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java b/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java index 4c58a5118..cb9071510 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java @@ -1,9 +1,9 @@ package at.hannibal2.skyhanni.config.features; -import at.hannibal2.skyhanni.config.gui.core.config.Position; -import at.hannibal2.skyhanni.config.gui.core.config.annotations.ConfigEditorBoolean; -import at.hannibal2.skyhanni.config.gui.core.config.annotations.ConfigEditorButton; -import at.hannibal2.skyhanni.config.gui.core.config.annotations.ConfigOption; +import at.hannibal2.skyhanni.config.core.config.Position; +import at.hannibal2.skyhanni.config.core.config.annotations.ConfigEditorBoolean; +import at.hannibal2.skyhanni.config.core.config.annotations.ConfigEditorButton; +import at.hannibal2.skyhanni.config.core.config.annotations.ConfigOption; import com.google.gson.annotations.Expose; public class Misc { diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/GuiTextures.java b/src/main/java/at/hannibal2/skyhanni/config/gui/GuiTextures.java deleted file mode 100644 index 3bcf08e47..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/GuiTextures.java +++ /dev/null @@ -1,32 +0,0 @@ -package at.hannibal2.skyhanni.config.gui; - -import net.minecraft.util.ResourceLocation; - -public class GuiTextures { - - private GuiTextures() {} - - public static final ResourceLocation DISCORD = new ResourceLocation("skyhanni:discord.png"); - - public static final ResourceLocation button_tex = new ResourceLocation("skyhanni:button.png"); - - public static final ResourceLocation button_white = new ResourceLocation("skyhanni:button_white.png"); - - public static final ResourceLocation BAR = new ResourceLocation("skyhanni:core/bar.png"); - public static final ResourceLocation OFF = new ResourceLocation("skyhanni:core/toggle_off.png"); - public static final ResourceLocation ONE = new ResourceLocation("skyhanni:core/toggle_1.png"); - public static final ResourceLocation TWO = new ResourceLocation("skyhanni:core/toggle_2.png"); - public static final ResourceLocation THREE = new ResourceLocation("skyhanni:core/toggle_3.png"); - public static final ResourceLocation ON = new ResourceLocation("skyhanni:core/toggle_on.png"); - public static final ResourceLocation DELETE = new ResourceLocation("skyhanni:core/delete.png"); - - public static final ResourceLocation slider_off_cap = new ResourceLocation("skyhanni:core/slider/slider_off_cap.png"); - public static final ResourceLocation slider_off_notch = new ResourceLocation("skyhanni:core/slider/slider_off_notch.png"); - public static final ResourceLocation slider_off_segment = new ResourceLocation("skyhanni:core/slider/slider_off_segment.png"); - public static final ResourceLocation slider_on_cap = new ResourceLocation("skyhanni:core/slider/slider_on_cap.png"); - public static final ResourceLocation slider_on_notch = new ResourceLocation("skyhanni:core/slider/slider_on_notch.png"); - public static final ResourceLocation slider_on_segment = new ResourceLocation("skyhanni:core/slider/slider_on_segment.png"); - public static final ResourceLocation slider_button_new = new ResourceLocation("skyhanni:core/slider/slider_button.png"); - - public static final ResourceLocation mapOverlay = new ResourceLocation("skyhanni", "maps/map_overlay.png"); -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/BackgroundBlur.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/BackgroundBlur.java deleted file mode 100644 index 97ba6af54..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/BackgroundBlur.java +++ /dev/null @@ -1,249 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core; - -import at.hannibal2.skyhanni.config.gui.core.util.render.RenderUtils; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Gui; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.OpenGlHelper; -import net.minecraft.client.shader.Framebuffer; -import net.minecraft.client.shader.Shader; -import net.minecraft.util.Matrix4f; -import net.minecraftforge.client.event.EntityViewRenderEvent; -import net.minecraftforge.client.event.RenderGameOverlayEvent; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.common.eventhandler.EventPriority; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL30; - -public class BackgroundBlur { - - private static class OutputStuff { - - public Framebuffer framebuffer; - public Shader blurShaderHorz = null; - public Shader blurShaderVert = null; - - public OutputStuff(Framebuffer framebuffer, Shader blurShaderHorz, Shader blurShaderVert) { - this.framebuffer = framebuffer; - this.blurShaderHorz = blurShaderHorz; - this.blurShaderVert = blurShaderVert; - } - } - - private static final HashMap<Float, OutputStuff> blurOutput = new HashMap<>(); - private static final HashMap<Float, Long> lastBlurUse = new HashMap<>(); - private static long lastBlur = 0; - private static final HashSet<Float> requestedBlurs = new HashSet<>(); - - private static int fogColour = 0; - private static boolean registered = false; - - public static void registerListener() { - if (!registered) { - registered = true; - MinecraftForge.EVENT_BUS.register(new BackgroundBlur()); - } - } - - private static boolean shouldBlur = true; - - public static void markDirty() { - if (Minecraft.getMinecraft().theWorld != null) { - shouldBlur = true; - } - } - - public static void processBlurs() { - if (shouldBlur) { - shouldBlur = false; - - long currentTime = System.currentTimeMillis(); - - for (float blur : requestedBlurs) { - lastBlur = currentTime; - lastBlurUse.put(blur, currentTime); - - int width = Minecraft.getMinecraft().displayWidth; - int height = Minecraft.getMinecraft().displayHeight; - - OutputStuff output = blurOutput.computeIfAbsent( - blur, - k -> { - Framebuffer fb = new Framebuffer(width, height, false); - fb.setFramebufferFilter(GL11.GL_NEAREST); - return new OutputStuff(fb, null, null); - } - ); - - if (output.framebuffer.framebufferWidth != width || output.framebuffer.framebufferHeight != height) { - output.framebuffer.createBindFramebuffer(width, height); - if (output.blurShaderHorz != null) { - output.blurShaderHorz.setProjectionMatrix(createProjectionMatrix(width, height)); - } - if (output.blurShaderVert != null) { - output.blurShaderVert.setProjectionMatrix(createProjectionMatrix(width, height)); - } - } - - blurBackground(output, blur); - } - - Set<Float> remove = new HashSet<>(); - for (Map.Entry<Float, Long> entry : lastBlurUse.entrySet()) { - if (currentTime - entry.getValue() > 30 * 1000) { - remove.add(entry.getKey()); - } - } - remove.remove(5f); - - lastBlurUse.keySet().removeAll(remove); - blurOutput.keySet().removeAll(remove); - - requestedBlurs.clear(); - } - } - - @SubscribeEvent(priority = EventPriority.HIGHEST) - public void onScreenRender(RenderGameOverlayEvent.Pre event) { - if (event.type == RenderGameOverlayEvent.ElementType.ALL) { - processBlurs(); - } - } - - @SubscribeEvent - public void onFogColour(EntityViewRenderEvent.FogColors event) { - fogColour = 0xff000000; - fogColour |= ((int) (event.red * 255) & 0xFF) << 16; - fogColour |= ((int) (event.green * 255) & 0xFF) << 8; - fogColour |= (int) (event.blue * 255) & 0xFF; - } - - private static Framebuffer blurOutputHorz = null; - - /** - * Creates a projection matrix that projects from our coordinate space [0->width; 0->height] to OpenGL coordinate - * space [-1 -> 1; 1 -> -1] (Note: flipped y-axis). - * - * This is so that we can render to and from the framebuffer in a way that is familiar to us, instead of needing to - * apply scales and translations manually. - */ - private static Matrix4f createProjectionMatrix(int width, int height) { - Matrix4f projMatrix = new Matrix4f(); - projMatrix.setIdentity(); - projMatrix.m00 = 2.0F / (float) width; - projMatrix.m11 = 2.0F / (float) (-height); - projMatrix.m22 = -0.0020001999F; - projMatrix.m33 = 1.0F; - projMatrix.m03 = -1.0F; - projMatrix.m13 = 1.0F; - projMatrix.m23 = -1.0001999F; - return projMatrix; - } - - private static void blurBackground(OutputStuff output, float blurFactor) { - if (!OpenGlHelper.isFramebufferEnabled() || !OpenGlHelper.areShadersSupported()) return; - - int width = Minecraft.getMinecraft().displayWidth; - int height = Minecraft.getMinecraft().displayHeight; - - GlStateManager.matrixMode(GL11.GL_PROJECTION); - GlStateManager.loadIdentity(); - GlStateManager.ortho(0.0D, width, height, 0.0D, 1000.0D, 3000.0D); - GlStateManager.matrixMode(GL11.GL_MODELVIEW); - GlStateManager.loadIdentity(); - GlStateManager.translate(0.0F, 0.0F, -2000.0F); - - if (blurOutputHorz == null) { - blurOutputHorz = new Framebuffer(width, height, false); - blurOutputHorz.setFramebufferFilter(GL11.GL_NEAREST); - } - if (blurOutputHorz == null || output == null) { - return; - } - if (blurOutputHorz.framebufferWidth != width || blurOutputHorz.framebufferHeight != height) { - blurOutputHorz.createBindFramebuffer(width, height); - Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false); - } - - if (output.blurShaderHorz == null) { - try { - output.blurShaderHorz = new Shader(Minecraft.getMinecraft().getResourceManager(), "blur", output.framebuffer, blurOutputHorz); - output.blurShaderHorz.getShaderManager().getShaderUniform("BlurDir").set(1, 0); - output.blurShaderHorz.setProjectionMatrix(createProjectionMatrix(width, height)); - } catch (Exception ignored) {} - } - if (output.blurShaderVert == null) { - try { - output.blurShaderVert = new Shader(Minecraft.getMinecraft().getResourceManager(), "blur", blurOutputHorz, output.framebuffer); - output.blurShaderVert.getShaderManager().getShaderUniform("BlurDir").set(0, 1); - output.blurShaderVert.setProjectionMatrix(createProjectionMatrix(width, height)); - } catch (Exception ignored) {} - } - if (output.blurShaderHorz != null && output.blurShaderVert != null) { - if (output.blurShaderHorz.getShaderManager().getShaderUniform("Radius") == null) { - //Corrupted shader? - return; - } - - output.blurShaderHorz.getShaderManager().getShaderUniform("Radius").set(blurFactor); - output.blurShaderVert.getShaderManager().getShaderUniform("Radius").set(blurFactor); - - GL11.glPushMatrix(); - GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, Minecraft.getMinecraft().getFramebuffer().framebufferObject); - GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, output.framebuffer.framebufferObject); - GL30.glBlitFramebuffer(0, 0, width, height, 0, 0, output.framebuffer.framebufferWidth, output.framebuffer.framebufferHeight, GL11.GL_COLOR_BUFFER_BIT, GL11.GL_NEAREST); - - output.blurShaderHorz.loadShader(0); - output.blurShaderVert.loadShader(0); - GlStateManager.enableDepth(); - GL11.glPopMatrix(); - - Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false); - } - } - - public static void renderBlurredBackground(float blurStrength, int screenWidth, int screenHeight, int x, int y, int blurWidth, int blurHeight) { - renderBlurredBackground(blurStrength, screenWidth, screenHeight, x, y, blurWidth, blurHeight, false); - } - - /** - * Renders a subsection of the blurred framebuffer on to the corresponding section of the screen. - * Essentially, this method will "blur" the background inside the bounds specified by [x->x+blurWidth, y->y+blurHeight] - */ - public static void renderBlurredBackground(float blurStrength, int screenWidth, int screenHeight, int x, int y, int blurWidth, int blurHeight, boolean forcedUpdate) { - if (!OpenGlHelper.isFramebufferEnabled() || !OpenGlHelper.areShadersSupported()) return; - if (blurStrength < 0.5) return; - requestedBlurs.add(blurStrength); - - long currentTime = System.currentTimeMillis(); - if (currentTime - lastBlur > 300) { - shouldBlur = true; - if (currentTime - lastBlur > 400 && forcedUpdate) return; - } - - if (blurOutput.isEmpty()) return; - - OutputStuff out = blurOutput.get(blurStrength); - if (out == null) { - out = blurOutput.values().iterator().next(); - } - - float uMin = x / (float) screenWidth; - float uMax = (x + blurWidth) / (float) screenWidth; - float vMin = (screenHeight - y) / (float) screenHeight; - float vMax = (screenHeight - y - blurHeight) / (float) screenHeight; - - GlStateManager.depthMask(false); - Gui.drawRect(x, y, x + blurWidth, y + blurHeight, fogColour); - out.framebuffer.bindFramebufferTexture(); - GlStateManager.color(1f, 1f, 1f, 1f); - RenderUtils.drawTexturedRect(x, y, blurWidth, blurHeight, uMin, uMax, vMin, vMax); - out.framebuffer.unbindFramebufferTexture(); - GlStateManager.depthMask(true); - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/ChromaColour.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/ChromaColour.java deleted file mode 100644 index 8f1936c20..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/ChromaColour.java +++ /dev/null @@ -1,93 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core; - -import java.awt.*; - -public class ChromaColour { - - public static String special(int chromaSpeed, int alpha, int rgb) { - return special(chromaSpeed, alpha, (rgb & 0xFF0000) >> 16, (rgb & 0x00FF00) >> 8, (rgb & 0x0000FF)); - } - - private static final int RADIX = 10; - - public static String special(int chromaSpeed, int alpha, int r, int g, int b) { - StringBuilder sb = new StringBuilder(); - sb.append(Integer.toString(chromaSpeed, RADIX)).append(":"); - sb.append(Integer.toString(alpha, RADIX)).append(":"); - sb.append(Integer.toString(r, RADIX)).append(":"); - sb.append(Integer.toString(g, RADIX)).append(":"); - sb.append(Integer.toString(b, RADIX)); - return sb.toString(); - } - - private static int[] decompose(String csv) { - String[] split = csv.split(":"); - - int[] arr = new int[split.length]; - - for (int i = 0; i < split.length; i++) { - arr[i] = Integer.parseInt(split[split.length - 1 - i], RADIX); - } - return arr; - } - - public static int specialToSimpleRGB(String special) { - int[] d = decompose(special); - int r = d[2]; - int g = d[1]; - int b = d[0]; - int a = d[3]; - int chr = d[4]; - - return (a & 0xFF) << 24 | (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF); - } - - public static int getSpeed(String special) { - return decompose(special)[4]; - } - - public static float getSecondsForSpeed(int speed) { - return (255 - speed) / 254f * (MAX_CHROMA_SECS - MIN_CHROMA_SECS) + MIN_CHROMA_SECS; - } - - private static final int MIN_CHROMA_SECS = 1; - private static final int MAX_CHROMA_SECS = 60; - - public static long startTime = -1; - - public static int specialToChromaRGB(String special) { - if (startTime < 0) startTime = System.currentTimeMillis(); - - int[] d = decompose(special); - int chr = d[4]; - int a = d[3]; - int r = d[2]; - int g = d[1]; - int b = d[0]; - - float[] hsv = Color.RGBtoHSB(r, g, b, null); - - if (chr > 0) { - float seconds = getSecondsForSpeed(chr); - hsv[0] += (System.currentTimeMillis() - startTime) / 1000f / seconds; - hsv[0] %= 1; - if (hsv[0] < 0) hsv[0] += 1; - } - - return (a & 0xFF) << 24 | (Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]) & 0x00FFFFFF); - } - - public static int rotateHue(int argb, int degrees) { - int a = (argb >> 24) & 0xFF; - int r = (argb >> 16) & 0xFF; - int g = (argb >> 8) & 0xFF; - int b = (argb) & 0xFF; - - float[] hsv = Color.RGBtoHSB(r, g, b, null); - - hsv[0] += degrees / 360f; - hsv[0] %= 1; - - return (a & 0xFF) << 24 | (Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]) & 0x00FFFFFF); - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/GlScissorStack.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/GlScissorStack.java deleted file mode 100644 index 446cc995c..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/GlScissorStack.java +++ /dev/null @@ -1,86 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core; - -import java.util.LinkedList; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.ScaledResolution; -import org.lwjgl.opengl.GL11; - -public class GlScissorStack { - - private static class Bounds { - - int left; - int top; - int right; - int bottom; - - public Bounds(int left, int top, int right, int bottom) { - this.left = left; - this.top = top; - this.right = right; - this.bottom = bottom; - } - - public Bounds createSubBound(int left, int top, int right, int bottom) { - left = Math.max(left, this.left); - top = Math.max(top, this.top); - right = Math.min(right, this.right); - bottom = Math.min(bottom, this.bottom); - - if (top > bottom) { - top = bottom; - } - if (left > right) { - left = right; - } - - return new Bounds(left, top, right, bottom); - } - - public void set(ScaledResolution scaledResolution) { - int height = Minecraft.getMinecraft().displayHeight; - int scale = scaledResolution.getScaleFactor(); - GL11.glScissor(left * scale, height - bottom * scale, (right - left) * scale, (bottom - top) * scale); - } - } - - private static final LinkedList<Bounds> boundsStack = new LinkedList<>(); - - public static void push(int left, int top, int right, int bottom, ScaledResolution scaledResolution) { - if (right < left) { - int temp = right; - right = left; - left = temp; - } - if (bottom < top) { - int temp = bottom; - bottom = top; - top = temp; - } - if (boundsStack.isEmpty()) { - boundsStack.push(new Bounds(left, top, right, bottom)); - } else { - boundsStack.push(boundsStack.peek().createSubBound(left, top, right, bottom)); - } - if (!boundsStack.isEmpty()) { - boundsStack.peek().set(scaledResolution); - } - GL11.glEnable(GL11.GL_SCISSOR_TEST); - } - - public static void pop(ScaledResolution scaledResolution) { - if (!boundsStack.isEmpty()) { - boundsStack.pop(); - } - if (boundsStack.isEmpty()) { - GL11.glDisable(GL11.GL_SCISSOR_TEST); - } else { - boundsStack.peek().set(scaledResolution); - } - } - - public static void clear() { - boundsStack.clear(); - GL11.glDisable(GL11.GL_SCISSOR_TEST); - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/GuiElement.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/GuiElement.java deleted file mode 100644 index 3e17e5f0d..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/GuiElement.java +++ /dev/null @@ -1,12 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core; - -import net.minecraft.client.gui.Gui; - -public abstract class GuiElement extends Gui { - - public abstract void render(); - - public abstract boolean mouseInput(int mouseX, int mouseY); - - public abstract boolean keyboardInput(); -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/GuiElementBoolean.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/GuiElementBoolean.java deleted file mode 100644 index 07673d433..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/GuiElementBoolean.java +++ /dev/null @@ -1,118 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core; - -import at.hannibal2.skyhanni.config.gui.GuiTextures; -import at.hannibal2.skyhanni.config.gui.core.util.lerp.LerpUtils; -import at.hannibal2.skyhanni.config.gui.core.util.render.RenderUtils; -import java.util.function.Consumer; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.util.ResourceLocation; -import org.lwjgl.input.Mouse; - -public class GuiElementBoolean extends GuiElement { - - public int x; - public int y; - private boolean value; - private final int clickRadius; - private final Consumer<Boolean> toggleCallback; - - private boolean previewValue; - private int animation = 0; - private long lastMillis = 0; - - private static final int xSize = 48; - private static final int ySize = 14; - - public GuiElementBoolean(int x, int y, boolean value, Consumer<Boolean> toggleCallback) { - this(x, y, value, 0, toggleCallback); - } - - public GuiElementBoolean(int x, int y, boolean value, int clickRadius, Consumer<Boolean> toggleCallback) { - this.x = x; - this.y = y; - this.value = value; - this.previewValue = value; - this.clickRadius = clickRadius; - this.toggleCallback = toggleCallback; - this.lastMillis = System.currentTimeMillis(); - - if (value) animation = 36; - } - - @Override - public void render() { - GlStateManager.color(1, 1, 1, 1); - Minecraft.getMinecraft().getTextureManager().bindTexture(GuiTextures.BAR); - RenderUtils.drawTexturedRect(x, y, xSize, ySize); - - ResourceLocation buttonLoc = GuiTextures.ON; - long currentMillis = System.currentTimeMillis(); - long deltaMillis = currentMillis - lastMillis; - lastMillis = currentMillis; - boolean passedLimit = false; - if (previewValue != value) { - if ((previewValue && animation > 12) || (!previewValue && animation < 24)) { - passedLimit = true; - } - } - if (previewValue != passedLimit) { - animation += deltaMillis / 10; - } else { - animation -= deltaMillis / 10; - } - lastMillis -= deltaMillis % 10; - - if (previewValue == value) { - animation = Math.max(0, Math.min(36, animation)); - } else if (!passedLimit) { - if (previewValue) { - animation = Math.max(0, Math.min(12, animation)); - } else { - animation = Math.max(24, Math.min(36, animation)); - } - } else { - if (previewValue) { - animation = Math.max(12, animation); - } else { - animation = Math.min(24, animation); - } - } - - int animation = (int) (LerpUtils.sigmoidZeroOne(this.animation / 36f) * 36); - if (animation < 3) { - buttonLoc = GuiTextures.OFF; - } else if (animation < 13) { - buttonLoc = GuiTextures.ONE; - } else if (animation < 23) { - buttonLoc = GuiTextures.TWO; - } else if (animation < 33) { - buttonLoc = GuiTextures.THREE; - } - - Minecraft.getMinecraft().getTextureManager().bindTexture(buttonLoc); - RenderUtils.drawTexturedRect(x + animation, y, 12, 14); - } - - @Override - public boolean mouseInput(int mouseX, int mouseY) { - if (mouseX > x - clickRadius && mouseX < x + xSize + clickRadius && mouseY > y - clickRadius && mouseY < y + ySize + clickRadius) { - if (Mouse.getEventButton() == 0) { - if (Mouse.getEventButtonState()) { - previewValue = !value; - } else if (previewValue == !value) { - value = !value; - toggleCallback.accept(value); - } - } - } else { - previewValue = value; - } - return false; - } - - @Override - public boolean keyboardInput() { - return false; - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/GuiElementColour.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/GuiElementColour.java deleted file mode 100644 index b685ee8fc..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/GuiElementColour.java +++ /dev/null @@ -1,370 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core; - -import at.hannibal2.skyhanni.config.gui.core.util.render.RenderUtils; -import at.hannibal2.skyhanni.config.gui.core.util.render.TextRenderUtils; -import java.awt.*; -import java.awt.image.BufferedImage; -import java.util.function.Consumer; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.texture.DynamicTexture; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.ResourceLocation; -import org.lwjgl.input.Keyboard; -import org.lwjgl.input.Mouse; -import org.lwjgl.opengl.GL11; - -public class GuiElementColour extends GuiElement { - - public static final ResourceLocation colour_selector_dot = new ResourceLocation("notenoughupdates:core/colour_selector_dot.png"); - public static final ResourceLocation colour_selector_bar = new ResourceLocation("notenoughupdates:core/colour_selector_bar.png"); - public static final ResourceLocation colour_selector_bar_alpha = new ResourceLocation("notenoughupdates:core/colour_selector_bar_alpha.png"); - public static final ResourceLocation colour_selector_chroma = new ResourceLocation("notenoughupdates:core/colour_selector_chroma.png"); - - private static final ResourceLocation colourPickerLocation = new ResourceLocation("mbcore:dynamic/colourpicker"); - private static final ResourceLocation colourPickerBarValueLocation = new ResourceLocation("mbcore:dynamic/colourpickervalue"); - private static final ResourceLocation colourPickerBarOpacityLocation = new ResourceLocation("mbcore:dynamic/colourpickeropacity"); - private final GuiElementTextField hexField = new GuiElementTextField("", GuiElementTextField.SCALE_TEXT | GuiElementTextField.FORCE_CAPS | GuiElementTextField.NO_SPACE); - - private final int x; - private final int y; - private int xSize = 119; - private final int ySize = 89; - - private float wheelAngle = 0; - private float wheelRadius = 0; - - private int clickedComponent = -1; - - private final Consumer<String> colourChangedCallback; - private final Runnable closeCallback; - private String colour; - - private final boolean opacitySlider; - private final boolean valueSlider; - - public GuiElementColour(int x, int y, String initialColour, Consumer<String> colourChangedCallback, Runnable closeCallback) { - this(x, y, initialColour, colourChangedCallback, closeCallback, true, true); - } - - public GuiElementColour(int x, int y, String initialColour, Consumer<String> colourChangedCallback, Runnable closeCallback, boolean opacitySlider, boolean valueSlider) { - final ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - - this.y = Math.max(10, Math.min(scaledResolution.getScaledHeight() - ySize - 10, y)); - this.x = Math.max(10, Math.min(scaledResolution.getScaledWidth() - xSize - 10, x)); - - this.colour = initialColour; - this.colourChangedCallback = colourChangedCallback; - this.closeCallback = closeCallback; - - int colour = ChromaColour.specialToSimpleRGB(initialColour); - Color c = new Color(colour); - float[] hsv = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); - updateAngleAndRadius(hsv); - - this.opacitySlider = opacitySlider; - this.valueSlider = valueSlider; - - if (!valueSlider) xSize -= 15; - if (!opacitySlider) xSize -= 15; - } - - public void updateAngleAndRadius(float[] hsv) { - this.wheelRadius = hsv[1]; - this.wheelAngle = hsv[0] * 360; - } - - public void render() { - RenderUtils.drawFloatingRectDark(x, y, xSize, ySize); - - int currentColour = ChromaColour.specialToSimpleRGB(colour); - Color c = new Color(currentColour, true); - float[] hsv = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); - - BufferedImage bufferedImage = new BufferedImage(288, 288, BufferedImage.TYPE_INT_ARGB); - float borderRadius = 0.05f; - if (Keyboard.isKeyDown(Keyboard.KEY_N)) borderRadius = 0; - for (int x = -16; x < 272; x++) { - for (int y = -16; y < 272; y++) { - float radius = (float) Math.sqrt(((x - 128) * (x - 128) + (y - 128) * (y - 128)) / 16384f); - float angle = (float) Math.toDegrees(Math.atan((128 - x) / (y - 128 + 1E-5)) + Math.PI / 2); - if (y < 128) angle += 180; - if (radius <= 1) { - int rgb = Color.getHSBColor(angle / 360f, (float) Math.pow(radius, 1.5f), hsv[2]).getRGB(); - bufferedImage.setRGB(x + 16, y + 16, rgb); - } else if (radius <= 1 + borderRadius) { - float invBlackAlpha = Math.abs(radius - 1 - borderRadius / 2) / borderRadius * 2; - float blackAlpha = 1 - invBlackAlpha; - - if (radius > 1 + borderRadius / 2) { - bufferedImage.setRGB(x + 16, y + 16, (int) (blackAlpha * 255) << 24); - } else { - Color col = Color.getHSBColor(angle / 360f, 1, hsv[2]); - int rgb = (int) (col.getRed() * invBlackAlpha) << 16 | (int) (col.getGreen() * invBlackAlpha) << 8 | (int) (col.getBlue() * invBlackAlpha); - bufferedImage.setRGB(x + 16, y + 16, 0xff000000 | rgb); - } - } - } - } - - BufferedImage bufferedImageValue = new BufferedImage(10, 64, BufferedImage.TYPE_INT_ARGB); - for (int x = 0; x < 10; x++) { - for (int y = 0; y < 64; y++) { - if ((x == 0 || x == 9) && (y == 0 || y == 63)) continue; - - int rgb = Color.getHSBColor(wheelAngle / 360, wheelRadius, (64 - y) / 64f).getRGB(); - bufferedImageValue.setRGB(x, y, rgb); - } - } - - BufferedImage bufferedImageOpacity = new BufferedImage(10, 64, BufferedImage.TYPE_INT_ARGB); - for (int x = 0; x < 10; x++) { - for (int y = 0; y < 64; y++) { - if ((x == 0 || x == 9) && (y == 0 || y == 63)) continue; - - int rgb = (currentColour & 0x00FFFFFF) | (Math.min(255, (64 - y) * 4) << 24); - bufferedImageOpacity.setRGB(x, y, rgb); - } - } - - float selradius = (float) Math.pow(wheelRadius, 1 / 1.5f) * 32; - int selx = (int) (Math.cos(Math.toRadians(wheelAngle)) * selradius); - int sely = (int) (Math.sin(Math.toRadians(wheelAngle)) * selradius); - - int valueOffset = 0; - if (valueSlider) { - valueOffset = 15; - - Minecraft.getMinecraft().getTextureManager().loadTexture(colourPickerBarValueLocation, new DynamicTexture(bufferedImageValue)); - Minecraft.getMinecraft().getTextureManager().bindTexture(colourPickerBarValueLocation); - GlStateManager.color(1, 1, 1, 1); - RenderUtils.drawTexturedRect(x + 5 + 64 + 5, y + 5, 10, 64, GL11.GL_NEAREST); - } - - int opacityOffset = 0; - if (opacitySlider) { - opacityOffset = 15; - - Minecraft.getMinecraft().getTextureManager().bindTexture(colour_selector_bar_alpha); - GlStateManager.color(1, 1, 1, 1); - RenderUtils.drawTexturedRect(x + 5 + 64 + 5 + valueOffset, y + 5, 10, 64, GL11.GL_NEAREST); - - Minecraft.getMinecraft().getTextureManager().loadTexture(colourPickerBarOpacityLocation, new DynamicTexture(bufferedImageOpacity)); - Minecraft.getMinecraft().getTextureManager().bindTexture(colourPickerBarOpacityLocation); - GlStateManager.color(1, 1, 1, 1); - RenderUtils.drawTexturedRect(x + 5 + 64 + 5 + valueOffset, y + 5, 10, 64, GL11.GL_NEAREST); - } - - int chromaSpeed = ChromaColour.getSpeed(colour); - int currentColourChroma = ChromaColour.specialToChromaRGB(colour); - Color cChroma = new Color(currentColourChroma, true); - float[] hsvChroma = Color.RGBtoHSB(cChroma.getRed(), cChroma.getGreen(), cChroma.getBlue(), null); - - if (chromaSpeed > 0) { - Gui.drawRect(x + 5 + 64 + valueOffset + opacityOffset + 5 + 1, y + 5 + 1, x + 5 + 64 + valueOffset + opacityOffset + 5 + 10 - 1, y + 5 + 64 - 1, Color.HSBtoRGB(hsvChroma[0], 0.8f, 0.8f)); - } else { - Gui.drawRect(x + 5 + 64 + valueOffset + opacityOffset + 5 + 1, y + 5 + 27 + 1, x + 5 + 64 + valueOffset + opacityOffset + 5 + 10 - 1, y + 5 + 37 - 1, Color.HSBtoRGB((hsvChroma[0] + (System.currentTimeMillis() - ChromaColour.startTime) / 1000f) % 1, 0.8f, 0.8f)); - } - - Minecraft.getMinecraft().getTextureManager().bindTexture(colour_selector_bar); - GlStateManager.color(1, 1, 1, 1); - if (valueSlider) RenderUtils.drawTexturedRect(x + 5 + 64 + 5, y + 5, 10, 64, GL11.GL_NEAREST); - if (opacitySlider) RenderUtils.drawTexturedRect(x + 5 + 64 + 5 + valueOffset, y + 5, 10, 64, GL11.GL_NEAREST); - - if (chromaSpeed > 0) { - RenderUtils.drawTexturedRect(x + 5 + 64 + valueOffset + opacityOffset + 5, y + 5, 10, 64, GL11.GL_NEAREST); - } else { - Minecraft.getMinecraft().getTextureManager().bindTexture(colour_selector_chroma); - RenderUtils.drawTexturedRect(x + 5 + 64 + valueOffset + opacityOffset + 5, y + 5 + 27, 10, 10, GL11.GL_NEAREST); - } - - if (valueSlider) Gui.drawRect(x + 5 + 64 + 5, y + 5 + 64 - (int) (64 * hsv[2]), x + 5 + 64 + valueOffset, y + 5 + 64 - (int) (64 * hsv[2]) + 1, 0xFF000000); - if (opacitySlider) Gui.drawRect(x + 5 + 64 + 5 + valueOffset, y + 5 + 64 - c.getAlpha() / 4, x + 5 + 64 + valueOffset + opacityOffset, y + 5 + 64 - c.getAlpha() / 4 - 1, 0xFF000000); - if (chromaSpeed > 0) { - Gui.drawRect(x + 5 + 64 + valueOffset + opacityOffset + 5, y + 5 + 64 - (int) (chromaSpeed / 255f * 64), x + 5 + 64 + valueOffset + opacityOffset + 5 + 10, y + 5 + 64 - (int) (chromaSpeed / 255f * 64) + 1, 0xFF000000); - } - - Minecraft.getMinecraft().getTextureManager().loadTexture(colourPickerLocation, new DynamicTexture(bufferedImage)); - Minecraft.getMinecraft().getTextureManager().bindTexture(colourPickerLocation); - GlStateManager.color(1, 1, 1, 1); - RenderUtils.drawTexturedRect(x + 1, y + 1, 72, 72, GL11.GL_LINEAR); - - Minecraft.getMinecraft().getTextureManager().bindTexture(colour_selector_dot); - GlStateManager.color(1, 1, 1, 1); - RenderUtils.drawTexturedRect(x + 5 + 32 + selx - 4, y + 5 + 32 + sely - 4, 8, 8, GL11.GL_NEAREST); - - TextRenderUtils.drawStringCenteredScaledMaxWidth(EnumChatFormatting.GRAY.toString() + Math.round(hsv[2] * 100) + "", Minecraft.getMinecraft().fontRendererObj, x + 5 + 64 + 5 + 5 - (Math.round(hsv[2] * 100) == 100 ? 1 : 0), y + 5 + 64 + 5 + 5, true, 13, -1); - if (opacitySlider) { - TextRenderUtils.drawStringCenteredScaledMaxWidth(EnumChatFormatting.GRAY.toString() + Math.round(c.getAlpha() / 255f * 100) + "", Minecraft.getMinecraft().fontRendererObj, x + 5 + 64 + 5 + valueOffset + 5, y + 5 + 64 + 5 + 5, true, 13, -1); - } - if (chromaSpeed > 0) { - TextRenderUtils.drawStringCenteredScaledMaxWidth(EnumChatFormatting.GRAY.toString() + (int) ChromaColour.getSecondsForSpeed(chromaSpeed) + "s", Minecraft.getMinecraft().fontRendererObj, x + 5 + 64 + 5 + valueOffset + opacityOffset + 6, y + 5 + 64 + 5 + 5, true, 13, -1); - } - - hexField.setSize(48, 10); - if (!hexField.getFocus()) hexField.setText(Integer.toHexString(c.getRGB() & 0xFFFFFF).toUpperCase()); - - StringBuilder sb = new StringBuilder(EnumChatFormatting.GRAY + "#"); - for (int i = 0; i < 6 - hexField.getText().length(); i++) { - sb.append("0"); - } - sb.append(EnumChatFormatting.WHITE); - - hexField.setPrependText(sb.toString()); - hexField.render(x + 5 + 8, y + 5 + 64 + 5); - } - - public boolean mouseInput(int mouseX, int mouseY) { - ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - float mouseXF = (float) (Mouse.getX() * scaledResolution.getScaledWidth_double() / Minecraft.getMinecraft().displayWidth); - float mouseYF = (float) (scaledResolution.getScaledHeight_double() - Mouse.getY() * scaledResolution.getScaledHeight_double() / Minecraft.getMinecraft().displayHeight - 1); - - if ((Mouse.getEventButton() == 0 || Mouse.getEventButton() == 1) && Mouse.getEventButtonState()) { - if (mouseX > x + 5 + 8 && mouseX < x + 5 + 8 + 48) { - if (mouseY > y + 5 + 64 + 5 && mouseY < y + 5 + 64 + 5 + 10) { - hexField.mouseClicked(mouseX, mouseY, Mouse.getEventButton()); - clickedComponent = -1; - return true; - } - } - } - if (!Mouse.getEventButtonState() && Mouse.getEventButton() == 0) { - clickedComponent = -1; - } - if (Mouse.getEventButtonState() && Mouse.getEventButton() == 0) { - if (mouseX >= x && mouseX <= x + 119 && mouseY >= y && mouseY <= y + 89) { - hexField.unfocus(); - - int xWheel = mouseX - x - 5; - int yWheel = mouseY - y - 5; - - if (xWheel > 0 && xWheel < 64) { - if (yWheel > 0 && yWheel < 64) { - clickedComponent = 0; - } - } - - int xValue = mouseX - (x + 5 + 64 + 5); - int y = mouseY - this.y - 5; - - int opacityOffset = opacitySlider ? 15 : 0; - int valueOffset = valueSlider ? 15 : 0; - - if (y > -5 && y <= 69) { - if (valueSlider) { - if (xValue > 0 && xValue < 10) { - clickedComponent = 1; - } - } - - if (opacitySlider) { - int xOpacity = mouseX - (x + 5 + 64 + 5 + valueOffset); - - if (xOpacity > 0 && xOpacity < 10) { - clickedComponent = 2; - } - } - } - - int chromaSpeed = ChromaColour.getSpeed(colour); - int xChroma = mouseX - (x + 5 + 64 + valueOffset + opacityOffset + 5); - if (xChroma > 0 && xChroma < 10) { - if (chromaSpeed > 0) { - if (y > -5 && y <= 69) { - clickedComponent = 3; - } - } else if (mouseY > this.y + 5 + 27 && mouseY < this.y + 5 + 37) { - int currentColour = ChromaColour.specialToSimpleRGB(colour); - Color c = new Color(currentColour, true); - colour = ChromaColour.special(200, c.getAlpha(), currentColour); - colourChangedCallback.accept(colour); - } - } - } else { - hexField.unfocus(); - closeCallback.run(); - return false; - } - } - if (Mouse.isButtonDown(0) && clickedComponent >= 0) { - int currentColour = ChromaColour.specialToSimpleRGB(colour); - Color c = new Color(currentColour, true); - float[] hsv = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); - - float xWheel = mouseXF - x - 5; - float yWheel = mouseYF - y - 5; - - if (clickedComponent == 0) { - float angle = (float) Math.toDegrees(Math.atan((32 - xWheel) / (yWheel - 32 + 1E-5)) + Math.PI / 2); - xWheel = Math.max(0, Math.min(64, xWheel)); - yWheel = Math.max(0, Math.min(64, yWheel)); - float radius = (float) Math.sqrt(((xWheel - 32) * (xWheel - 32) + (yWheel - 32) * (yWheel - 32)) / 1024f); - if (yWheel < 32) angle += 180; - - this.wheelAngle = angle; - this.wheelRadius = (float) Math.pow(Math.min(1, radius), 1.5f); - int rgb = Color.getHSBColor(angle / 360f, wheelRadius, hsv[2]).getRGB(); - colour = ChromaColour.special(ChromaColour.getSpeed(colour), c.getAlpha(), rgb); - colourChangedCallback.accept(colour); - return true; - } - - float y = mouseYF - this.y - 5; - y = Math.max(0, Math.min(64, y)); - - if (clickedComponent == 1) { - int rgb = Color.getHSBColor(wheelAngle / 360, wheelRadius, 1 - y / 64f).getRGB(); - colour = ChromaColour.special(ChromaColour.getSpeed(colour), c.getAlpha(), rgb); - colourChangedCallback.accept(colour); - return true; - } - - if (clickedComponent == 2) { - colour = ChromaColour.special(ChromaColour.getSpeed(colour), 255 - Math.round(y / 64f * 255), currentColour); - colourChangedCallback.accept(colour); - return true; - } - - if (clickedComponent == 3) { - colour = ChromaColour.special(255 - Math.round(y / 64f * 255), c.getAlpha(), currentColour); - colourChangedCallback.accept(colour); - } - return true; - } - return false; - } - - public boolean keyboardInput() { - if (Keyboard.getEventKeyState() && hexField.getFocus()) { - if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) { - hexField.unfocus(); - return true; - } - String old = hexField.getText(); - - hexField.keyTyped(Keyboard.getEventCharacter(), Keyboard.getEventKey()); - - if (hexField.getText().length() > 6) { - hexField.setText(old); - } else { - try { - String text = hexField.getText().toLowerCase(); - - int rgb = Integer.parseInt(text, 16); - int alpha = (ChromaColour.specialToSimpleRGB(colour) >> 24) & 0xFF; - colour = ChromaColour.special(ChromaColour.getSpeed(colour), alpha, rgb); - colourChangedCallback.accept(colour); - - Color c = new Color(rgb); - float[] hsv = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); - updateAngleAndRadius(hsv); - } catch (Exception e) {} - } - - return true; - } - return false; - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/GuiElementTextField.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/GuiElementTextField.java deleted file mode 100644 index e3c64c3d1..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/GuiElementTextField.java +++ /dev/null @@ -1,549 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core; - -import at.hannibal2.skyhanni.config.gui.core.util.StringUtils; -import at.hannibal2.skyhanni.config.gui.core.util.render.TextRenderUtils; -import java.awt.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.gui.GuiTextField; -import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.client.renderer.GlStateManager; - -public class GuiElementTextField { - - public static final int SCISSOR_TEXT = 0b10000000; - public static final int DISABLE_BG = 0b1000000; - public static final int SCALE_TEXT = 0b100000; - public static final int NUM_ONLY = 0b10000; - public static final int NO_SPACE = 0b01000; - public static final int FORCE_CAPS = 0b00100; - public static final int COLOUR = 0b00010; - public static final int MULTILINE = 0b00001; - - private int searchBarYSize; - private int searchBarXSize; - private static final int searchBarPadding = 2; - - private int options; - - private boolean focus = false; - - private int x; - private int y; - - private String prependText = ""; - private int customTextColour = 0xffffffff; - - private final GuiTextField textField = new GuiTextField(0, Minecraft.getMinecraft().fontRendererObj, 0, 0, 0, 0); - - private int customBorderColour = -1; - - public GuiElementTextField(String initialText, int options) { - this(initialText, 100, 20, options); - } - - public GuiElementTextField(String initialText, int sizeX, int sizeY, int options) { - textField.setFocused(true); - textField.setCanLoseFocus(false); - textField.setMaxStringLength(999); - textField.setText(initialText); - this.searchBarXSize = sizeX; - this.searchBarYSize = sizeY; - this.options = options; - } - - public void setMaxStringLength(int len) { - textField.setMaxStringLength(len); - } - - public void setCustomBorderColour(int colour) { - this.customBorderColour = colour; - } - - public void setCustomTextColour(int colour) { - this.customTextColour = colour; - } - - public String getText() { - return textField.getText(); - } - - public String getTextDisplay() { - String textNoColour = getText(); - while (true) { - Matcher matcher = PATTERN_CONTROL_CODE.matcher(textNoColour); - if (!matcher.find()) break; - String code = matcher.group(1); - textNoColour = matcher.replaceFirst("\u00B6" + code); - } - - return textNoColour; - } - - public void setPrependText(String text) { - this.prependText = text; - } - - public void setText(String text) { - if (textField.getText() == null || !textField.getText().equals(text)) { - textField.setText(text); - } - } - - public void setSize(int searchBarXSize, int searchBarYSize) { - this.searchBarXSize = searchBarXSize; - this.searchBarYSize = searchBarYSize; - } - - public void setOptions(int options) { - this.options = options; - } - - @Override - public String toString() { - return textField.getText(); - } - - public void setFocus(boolean focus) { - this.focus = focus; - if (!focus) { - textField.setCursorPosition(textField.getCursorPosition()); - } - } - - public boolean getFocus() { - return focus; - } - - public int getHeight() { - ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); - int paddingUnscaled = searchBarPadding / scaledresolution.getScaleFactor(); - - int numLines = org.apache.commons.lang3.StringUtils.countMatches(textField.getText(), "\n") + 1; - int extraSize = (searchBarYSize - 8) / 2 + 8; - int bottomTextBox = searchBarYSize + extraSize * (numLines - 1); - - return bottomTextBox + paddingUnscaled * 2; - } - - public int getWidth() { - ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); - int paddingUnscaled = searchBarPadding / scaledresolution.getScaleFactor(); - - return searchBarXSize + paddingUnscaled * 2; - } - - private float getScaleFactor(String str) { - return Math.min(1, (searchBarXSize - 2) / (float) Minecraft.getMinecraft().fontRendererObj.getStringWidth(str)); - } - - private boolean isScaling() { - return (options & SCALE_TEXT) != 0; - } - - private static final Pattern PATTERN_CONTROL_CODE = Pattern.compile("(?i)\\u00A7([^\\u00B6]|$)(?!\\u00B6)"); - - public int getCursorPos(int mouseX, int mouseY) { - int xComp = mouseX - x; - int yComp = mouseY - y; - - int extraSize = (searchBarYSize - 8) / 2 + 8; - - String renderText = prependText + textField.getText(); - - int lineNum = Math.round(((yComp - (searchBarYSize - 8) / 2)) / extraSize); - - String text = renderText; - String textNoColour = renderText; - if ((options & COLOUR) != 0) { - while (true) { - Matcher matcher = PATTERN_CONTROL_CODE.matcher(text); - if (!matcher.find() || matcher.groupCount() < 1) break; - String code = matcher.group(1); - if (code.isEmpty()) { - text = matcher.replaceFirst("\u00A7r\u00B6"); - } else { - text = matcher.replaceFirst("\u00A7" + code + "\u00B6" + code); - } - } - } - while (true) { - Matcher matcher = PATTERN_CONTROL_CODE.matcher(textNoColour); - if (!matcher.find() || matcher.groupCount() < 1) break; - String code = matcher.group(1); - textNoColour = matcher.replaceFirst("\u00B6" + code); - } - - int currentLine = 0; - int cursorIndex = 0; - for (; cursorIndex < textNoColour.length(); cursorIndex++) { - if (currentLine == lineNum) break; - if (textNoColour.charAt(cursorIndex) == '\n') { - currentLine++; - } - } - - String textNC = textNoColour.substring(0, cursorIndex); - int colorCodes = org.apache.commons.lang3.StringUtils.countMatches(textNC, "\u00B6"); - String line = text.substring(cursorIndex + (((options & COLOUR) != 0) ? colorCodes * 2 : 0)).split("\n")[0]; - int padding = Math.min(5, searchBarXSize - strLenNoColor(line)) / 2; - String trimmed = Minecraft.getMinecraft().fontRendererObj.trimStringToWidth(line, xComp - padding); - int linePos = strLenNoColor(trimmed); - if (linePos != strLenNoColor(line)) { - char after = line.charAt(linePos); - int trimmedWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(trimmed); - int charWidth = Minecraft.getMinecraft().fontRendererObj.getCharWidth(after); - if (trimmedWidth + charWidth / 2 < xComp - padding) { - linePos++; - } - } - cursorIndex += linePos; - - int pre = StringUtils.cleanColour(prependText).length(); - if (cursorIndex < pre) { - cursorIndex = 0; - } else { - cursorIndex -= pre; - } - - return cursorIndex; - } - - public void mouseClicked(int mouseX, int mouseY, int mouseButton) { - if (mouseButton == 1) { - textField.setText(""); - } else { - textField.setCursorPosition(getCursorPos(mouseX, mouseY)); - } - focus = true; - } - - public void unfocus() { - focus = false; - textField.setSelectionPos(textField.getCursorPosition()); - } - - public int strLenNoColor(String str) { - return str.replaceAll("(?i)\\u00A7.", "").length(); - } - - public void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { - if (focus) { - textField.setSelectionPos(getCursorPos(mouseX, mouseY)); - } - } - - public void keyTyped(char typedChar, int keyCode) { - if (focus) { - if ((options & MULTILINE) != 0) { //Carriage return - Pattern patternControlCode = Pattern.compile("(?i)\\u00A7([^\\u00B6\n]|$)(?!\\u00B6)"); - - String text = textField.getText(); - String textNoColour = textField.getText(); - while (true) { - Matcher matcher = patternControlCode.matcher(text); - if (!matcher.find() || matcher.groupCount() < 1) break; - String code = matcher.group(1); - if (code.isEmpty()) { - text = matcher.replaceFirst("\u00A7r\u00B6"); - } else { - text = matcher.replaceFirst("\u00A7" + code + "\u00B6" + code); - } - } - while (true) { - Matcher matcher = patternControlCode.matcher(textNoColour); - if (!matcher.find() || matcher.groupCount() < 1) break; - String code = matcher.group(1); - textNoColour = matcher.replaceFirst("\u00B6" + code); - } - - if (keyCode == 28) { - String before = textField.getText().substring(0, textField.getCursorPosition()); - String after = textField.getText().substring(textField.getCursorPosition()); - int pos = textField.getCursorPosition(); - textField.setText(before + "\n" + after); - textField.setCursorPosition(pos + 1); - return; - } else if (keyCode == 200) { //Up - String textNCBeforeCursor = textNoColour.substring(0, textField.getSelectionEnd()); - int colorCodes = org.apache.commons.lang3.StringUtils.countMatches(textNCBeforeCursor, "\u00B6"); - String textBeforeCursor = text.substring(0, textField.getSelectionEnd() + colorCodes * 2); - - int numLinesBeforeCursor = org.apache.commons.lang3.StringUtils.countMatches(textBeforeCursor, "\n"); - - String[] split = textBeforeCursor.split("\n"); - int textBeforeCursorWidth; - String lineBefore; - String thisLineBeforeCursor; - if (split.length == numLinesBeforeCursor && split.length > 0) { - textBeforeCursorWidth = 0; - lineBefore = split[split.length - 1]; - thisLineBeforeCursor = ""; - } else if (split.length > 1) { - thisLineBeforeCursor = split[split.length - 1]; - lineBefore = split[split.length - 2]; - textBeforeCursorWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(thisLineBeforeCursor); - } else { - return; - } - String trimmed = Minecraft.getMinecraft().fontRendererObj.trimStringToWidth(lineBefore, textBeforeCursorWidth); - int linePos = strLenNoColor(trimmed); - if (linePos != strLenNoColor(lineBefore)) { - char after = lineBefore.charAt(linePos); - int trimmedWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(trimmed); - int charWidth = Minecraft.getMinecraft().fontRendererObj.getCharWidth(after); - if (trimmedWidth + charWidth / 2 < textBeforeCursorWidth) { - linePos++; - } - } - int newPos = textField.getSelectionEnd() - strLenNoColor(thisLineBeforeCursor) - strLenNoColor(lineBefore) - 1 + linePos; - - if (GuiScreen.isShiftKeyDown()) { - textField.setSelectionPos(newPos); - } else { - textField.setCursorPosition(newPos); - } - } else if (keyCode == 208) { //Down - String textNCBeforeCursor = textNoColour.substring(0, textField.getSelectionEnd()); - int colorCodes = org.apache.commons.lang3.StringUtils.countMatches(textNCBeforeCursor, "\u00B6"); - String textBeforeCursor = text.substring(0, textField.getSelectionEnd() + colorCodes * 2); - - int numLinesBeforeCursor = org.apache.commons.lang3.StringUtils.countMatches(textBeforeCursor, "\n"); - - String[] split = textBeforeCursor.split("\n"); - String thisLineBeforeCursor; - int textBeforeCursorWidth; - if (split.length == numLinesBeforeCursor) { - thisLineBeforeCursor = ""; - textBeforeCursorWidth = 0; - } else if (split.length > 0) { - thisLineBeforeCursor = split[split.length - 1]; - textBeforeCursorWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(thisLineBeforeCursor); - } else { - return; - } - - String[] split2 = textNoColour.split("\n"); - if (split2.length > numLinesBeforeCursor + 1) { - String lineAfter = split2[numLinesBeforeCursor + 1]; - String trimmed = Minecraft.getMinecraft().fontRendererObj.trimStringToWidth(lineAfter, textBeforeCursorWidth); - int linePos = strLenNoColor(trimmed); - if (linePos != strLenNoColor(lineAfter)) { - char after = lineAfter.charAt(linePos); - int trimmedWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(trimmed); - int charWidth = Minecraft.getMinecraft().fontRendererObj.getCharWidth(after); - if (trimmedWidth + charWidth / 2 < textBeforeCursorWidth) { - linePos++; - } - } - int newPos = textField.getSelectionEnd() - strLenNoColor(thisLineBeforeCursor) + strLenNoColor(split2[numLinesBeforeCursor]) + 1 + linePos; - - if (GuiScreen.isShiftKeyDown()) { - textField.setSelectionPos(newPos); - } else { - textField.setCursorPosition(newPos); - } - } - } - } - - String old = textField.getText(); - if ((options & FORCE_CAPS) != 0) typedChar = Character.toUpperCase(typedChar); - if ((options & NO_SPACE) != 0 && typedChar == ' ') return; - - if (typedChar == '\u00B6') { - typedChar = '\u00A7'; - } - - textField.setFocused(true); - textField.textboxKeyTyped(typedChar, keyCode); - - if ((options & COLOUR) != 0) { - if (typedChar == '&') { - int pos = textField.getCursorPosition() - 2; - if (pos >= 0 && pos < textField.getText().length()) { - if (textField.getText().charAt(pos) == '&') { - String before = textField.getText().substring(0, pos); - String after = ""; - if (pos + 2 < textField.getText().length()) { - after = textField.getText().substring(pos + 2); - } - textField.setText(before + "\u00A7" + after); - textField.setCursorPosition(pos + 1); - } - } - } else if (typedChar == '*') { - int pos = textField.getCursorPosition() - 2; - if (pos >= 0 && pos < textField.getText().length()) { - if (textField.getText().charAt(pos) == '*') { - String before = textField.getText().substring(0, pos); - String after = ""; - if (pos + 2 < textField.getText().length()) { - after = textField.getText().substring(pos + 2); - } - textField.setText(before + "\u272A" + after); - textField.setCursorPosition(pos + 1); - } - } - } - } - - if ((options & NUM_ONLY) != 0 && textField.getText().matches("[^0-9.]")) textField.setText(old); - } - } - - public void render(int x, int y) { - this.x = x; - this.y = y; - drawTextbox(x, y, searchBarXSize, searchBarYSize, searchBarPadding, textField, focus); - } - - private void drawTextbox(int x, int y, int searchBarXSize, int searchBarYSize, int searchBarPadding, GuiTextField textField, boolean focus) { - ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); - String renderText = prependText + textField.getText(); - - GlStateManager.disableLighting(); - - /** - * Search bar - */ - int paddingUnscaled = searchBarPadding / scaledresolution.getScaleFactor(); - if (paddingUnscaled < 1) paddingUnscaled = 1; - - int numLines = org.apache.commons.lang3.StringUtils.countMatches(renderText, "\n") + 1; - int extraSize = (searchBarYSize - 8) / 2 + 8; - int bottomTextBox = y + searchBarYSize + extraSize * (numLines - 1); - - int borderColour = focus ? Color.GREEN.getRGB() : Color.WHITE.getRGB(); - if (customBorderColour != -1) { - borderColour = customBorderColour; - } - if ((options & DISABLE_BG) == 0) { - //bar background - Gui.drawRect(x - paddingUnscaled, y - paddingUnscaled, x + searchBarXSize + paddingUnscaled, bottomTextBox + paddingUnscaled, borderColour); - Gui.drawRect(x, y, x + searchBarXSize, bottomTextBox, Color.BLACK.getRGB()); - } - - //bar text - String text = renderText; - String textNoColor = renderText; - if ((options & COLOUR) != 0) { - while (true) { - Matcher matcher = PATTERN_CONTROL_CODE.matcher(text); - if (!matcher.find() || matcher.groupCount() < 1) break; - String code = matcher.group(1); - if (code.isEmpty()) { - text = matcher.replaceFirst("\u00A7r\u00B6"); - } else { - text = matcher.replaceFirst("\u00A7" + code + "\u00B6" + code); - } - } - } - while (true) { - Matcher matcher = PATTERN_CONTROL_CODE.matcher(textNoColor); - if (!matcher.find() || matcher.groupCount() < 1) break; - String code = matcher.group(1); - textNoColor = matcher.replaceFirst("\u00B6" + code); - } - - int xStartOffset = 5; - float scale = 1; - String[] texts = text.split("\n"); - for (int yOffI = 0; yOffI < texts.length; yOffI++) { - int yOff = yOffI * extraSize; - - if (isScaling() && Minecraft.getMinecraft().fontRendererObj.getStringWidth(texts[yOffI]) > searchBarXSize - 10) { - scale = (searchBarXSize - 2) / (float) Minecraft.getMinecraft().fontRendererObj.getStringWidth(texts[yOffI]); - if (scale > 1) scale = 1; - float newLen = Minecraft.getMinecraft().fontRendererObj.getStringWidth(texts[yOffI]) * scale; - xStartOffset = (int) ((searchBarXSize - newLen) / 2f); - - TextRenderUtils.drawStringCenteredScaledMaxWidth(texts[yOffI], Minecraft.getMinecraft().fontRendererObj, x + searchBarXSize / 2f, y + searchBarYSize / 2f + yOff, false, searchBarXSize - 2, customTextColour); - } else { - if ((options & SCISSOR_TEXT) != 0) { - GlScissorStack.push(x + 5, 0, x + searchBarXSize, scaledresolution.getScaledHeight(), scaledresolution); - Minecraft.getMinecraft().fontRendererObj.drawString(texts[yOffI], x + 5, y + (searchBarYSize - 8) / 2 + yOff, customTextColour); - GlScissorStack.pop(scaledresolution); - } else { - String toRender = Minecraft.getMinecraft().fontRendererObj.trimStringToWidth(texts[yOffI], searchBarXSize - 10); - Minecraft.getMinecraft().fontRendererObj.drawString(toRender, x + 5, y + (searchBarYSize - 8) / 2 + yOff, customTextColour); - } - } - } - - if (focus && System.currentTimeMillis() % 1000 > 500) { - String textNCBeforeCursor = textNoColor.substring(0, textField.getCursorPosition() + prependText.length()); - int colorCodes = org.apache.commons.lang3.StringUtils.countMatches(textNCBeforeCursor, "\u00B6"); - String textBeforeCursor = text.substring(0, textField.getCursorPosition() + prependText.length() + (((options & COLOUR) != 0) ? colorCodes * 2 : 0)); - - int numLinesBeforeCursor = org.apache.commons.lang3.StringUtils.countMatches(textBeforeCursor, "\n"); - int yOff = numLinesBeforeCursor * extraSize; - - String[] split = textBeforeCursor.split("\n"); - int textBeforeCursorWidth; - if (split.length <= numLinesBeforeCursor || split.length == 0) { - textBeforeCursorWidth = 0; - } else { - textBeforeCursorWidth = (int) (Minecraft.getMinecraft().fontRendererObj.getStringWidth(split[split.length - 1]) * scale); - } - Gui.drawRect(x + xStartOffset + textBeforeCursorWidth, y + (searchBarYSize - 8) / 2 - 1 + yOff, x + xStartOffset + textBeforeCursorWidth + 1, y + (searchBarYSize - 8) / 2 + 9 + yOff, Color.WHITE.getRGB()); - } - - String selectedText = textField.getSelectedText(); - if (!selectedText.isEmpty()) { - int leftIndex = Math.min(textField.getCursorPosition() + prependText.length(), textField.getSelectionEnd() + prependText.length()); - int rightIndex = Math.max(textField.getCursorPosition() + prependText.length(), textField.getSelectionEnd() + prependText.length()); - - float texX = 0; - int texY = 0; - boolean sectionSignPrev = false; - boolean ignoreNext = false; - boolean bold = false; - for (int i = 0; i < textNoColor.length(); i++) { - if (ignoreNext) { - ignoreNext = false; - continue; - } - - char c = textNoColor.charAt(i); - if (sectionSignPrev) { - if (c != 'k' && c != 'K' && c != 'm' && c != 'M' && c != 'n' && c != 'N' && c != 'o' && c != 'O') { - bold = c == 'l' || c == 'L'; - } - sectionSignPrev = false; - if (i < prependText.length()) continue; - } - if (c == '\u00B6') { - sectionSignPrev = true; - if (i < prependText.length()) continue; - } - - if (c == '\n') { - if (i >= leftIndex && i < rightIndex) { - Gui.drawRect(x + xStartOffset + (int) texX, y + (searchBarYSize - 8) / 2 - 1 + texY, x + xStartOffset + (int) texX + 3, y + (searchBarYSize - 8) / 2 + 9 + texY, Color.LIGHT_GRAY.getRGB()); - } - - texX = 0; - texY += extraSize; - continue; - } - - int len = Minecraft.getMinecraft().fontRendererObj.getStringWidth(String.valueOf(c)); - if (bold) len++; - if (i >= leftIndex && i < rightIndex) { - Gui.drawRect(x + xStartOffset + (int) texX, y + (searchBarYSize - 8) / 2 - 1 + texY, x + xStartOffset + (int) (texX + len * scale), y + (searchBarYSize - 8) / 2 + 9 + texY, Color.LIGHT_GRAY.getRGB()); - - TextRenderUtils.drawStringScaled(String.valueOf(c), Minecraft.getMinecraft().fontRendererObj, x + xStartOffset + texX, y + searchBarYSize / 2f - scale * 8 / 2f + texY, false, Color.BLACK.getRGB(), scale); - if (bold) { - TextRenderUtils.drawStringScaled(String.valueOf(c), Minecraft.getMinecraft().fontRendererObj, x + xStartOffset + texX + 1, y + searchBarYSize / 2f - scale * 8 / 2f + texY, false, Color.BLACK.getRGB(), scale); - } - } - - texX += len * scale; - } - } - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/GuiScreenElementWrapper.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/GuiScreenElementWrapper.java deleted file mode 100644 index bf3b53302..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/GuiScreenElementWrapper.java +++ /dev/null @@ -1,34 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core; - -import java.io.IOException; -import net.minecraft.client.gui.GuiScreen; -import org.lwjgl.input.Mouse; - -public class GuiScreenElementWrapper extends GuiScreen { - - public final GuiElement element; - - public GuiScreenElementWrapper(GuiElement element) { - this.element = element; - } - - @Override - public void drawScreen(int mouseX, int mouseY, float partialTicks) { - super.drawScreen(mouseX, mouseY, partialTicks); - element.render(); - } - - @Override - public void handleMouseInput() throws IOException { - super.handleMouseInput(); - int i = Mouse.getEventX() * this.width / this.mc.displayWidth; - int j = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1; - element.mouseInput(i, j); - } - - @Override - public void handleKeyboardInput() throws IOException { - super.handleKeyboardInput(); - element.keyboardInput(); - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/Config.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/Config.java deleted file mode 100644 index ce2aee6a8..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/Config.java +++ /dev/null @@ -1,5 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.config; -//public class Config { -// -// public void executeRunnable(String runnableId) {} -//} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/KeybindHelper.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/KeybindHelper.java deleted file mode 100644 index aaaf5e430..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/KeybindHelper.java +++ /dev/null @@ -1,49 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.config; - -import org.lwjgl.input.Keyboard; -import org.lwjgl.input.Mouse; - -public class KeybindHelper { - - public static String getKeyName(int keyCode) { - if (keyCode == 0) { - return "NONE"; - } else if (keyCode < 0) { - return "Button " + (keyCode + 101); - } else { - String keyName = Keyboard.getKeyName(keyCode); - if (keyName == null) { - keyName = "???"; - } else if (keyName.equalsIgnoreCase("LMENU")) { - keyName = "LALT"; - } else if (keyName.equalsIgnoreCase("RMENU")) { - keyName = "RALT"; - } - return keyName; - } - } - - public static boolean isKeyValid(int keyCode) { - return keyCode != 0; - } - - public static boolean isKeyDown(int keyCode) { - if (!isKeyValid(keyCode)) { - return false; - } else if (keyCode < 0) { - return Mouse.isButtonDown(keyCode + 100); - } else { - return Keyboard.isKeyDown(keyCode); - } - } - - public static boolean isKeyPressed(int keyCode) { - if (!isKeyValid(keyCode)) { - return false; - } else if (keyCode < 0) { - return Mouse.getEventButtonState() && Mouse.getEventButton() == keyCode + 100; - } else { - return Keyboard.getEventKeyState() && Keyboard.getEventKey() == keyCode; - } - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/Position.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/Position.java deleted file mode 100644 index d89a950e3..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/Position.java +++ /dev/null @@ -1,197 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.config; - -import com.google.gson.annotations.Expose; -import net.minecraft.client.gui.ScaledResolution; - -public class Position { - - @Expose - private int x; - - @Expose - private int y; - - @Expose - private boolean centerX; - - @Expose - private boolean centerY; - - private static final int EDGE_OFFSET = 0; - - public Position(int x, int y) { - this(x, y, false, false); - } - - public Position(int x, int y, boolean centerX, boolean centerY) { - this.x = x; - this.y = y; - this.centerX = centerX; - this.centerY = centerY; - } - - public void set(Position other) { - this.x = other.x; - this.y = other.y; - this.centerX = other.centerX; - this.centerY = other.centerY; - } - - public Position clone() { - return new Position(x, y, centerX, centerY); - } - - public boolean isCenterX() { - return centerX; - } - - public boolean isCenterY() { - return centerY; - } - - public int getRawX() { - return x; - } - - public int getRawY() { - return y; - } - - public int getAbsX(ScaledResolution scaledResolution, int objWidth) { - int width = scaledResolution.getScaledWidth(); - - if (centerX) { - return width / 2 + x; - } - - int ret = x; - if (x < 0) { - ret = width + x - objWidth; - } - - if (ret < 0) ret = 0; - if (ret > width - objWidth) ret = width - objWidth; - - return ret; - } - - public int getAbsY(ScaledResolution scaledResolution, int objHeight) { - int height = scaledResolution.getScaledHeight(); - - if (centerY) { - return height / 2 + y; - } - - int ret = y; - if (y < 0) { - ret = height + y - objHeight; - } - - if (ret < 0) ret = 0; - if (ret > height - objHeight) ret = height - objHeight; - - return ret; - } - - public int moveX(int deltaX, int objWidth, ScaledResolution scaledResolution) { - int screenWidth = scaledResolution.getScaledWidth(); - boolean wasPositiveX = this.x >= 0; - this.x += deltaX; - - if (centerX) { - if (wasPositiveX) { - if (this.x > screenWidth / 2 - objWidth / 2) { - deltaX += screenWidth / 2 - objWidth / 2 - this.x; - this.x = screenWidth / 2 - objWidth / 2; - } - } else { - if (this.x < -screenWidth / 2 + objWidth / 2) { - deltaX += -screenWidth / 2 + objWidth / 2 - this.x; - this.x = -screenWidth / 2 + objWidth / 2; - } - } - return deltaX; - } - - if (wasPositiveX) { - if (this.x < EDGE_OFFSET) { - deltaX += EDGE_OFFSET - this.x; - this.x = EDGE_OFFSET; - } - if (this.x > screenWidth - EDGE_OFFSET) { - deltaX += screenWidth - EDGE_OFFSET - this.x; - this.x = screenWidth - EDGE_OFFSET; - } - } else { - if (this.x + 1 > -EDGE_OFFSET) { - deltaX += -EDGE_OFFSET - 1 - this.x; - this.x = -EDGE_OFFSET - 1; - } - if (this.x + screenWidth < EDGE_OFFSET) { - deltaX += EDGE_OFFSET - screenWidth - this.x; - this.x = EDGE_OFFSET - screenWidth; - } - } - - if (this.x >= 0 && this.x + objWidth / 2 > screenWidth / 2) { - this.x -= screenWidth - objWidth; - } - if (this.x < 0 && this.x + objWidth / 2 <= -screenWidth / 2) { - this.x += screenWidth - objWidth; - } - return deltaX; - } - - public int moveY(int deltaY, int objHeight, ScaledResolution scaledResolution) { - int screenHeight = scaledResolution.getScaledHeight(); - boolean wasPositiveY = this.y >= 0; - this.y += deltaY; - - if (centerY) { - if (wasPositiveY) { - if (this.y > screenHeight / 2 - objHeight / 2) { - deltaY += screenHeight / 2 - objHeight / 2 - this.y; - this.y = screenHeight / 2 - objHeight / 2; - } - } else { - if (this.y < -screenHeight / 2 + objHeight / 2) { - deltaY += -screenHeight / 2 + objHeight / 2 - this.y; - this.y = -screenHeight / 2 + objHeight / 2; - } - } - return deltaY; - } - - if (wasPositiveY) { - if (this.y < EDGE_OFFSET) { - deltaY += EDGE_OFFSET - this.y; - this.y = EDGE_OFFSET; - } - if (this.y > screenHeight - EDGE_OFFSET) { - deltaY += screenHeight - EDGE_OFFSET - this.y; - this.y = screenHeight - EDGE_OFFSET; - } - } else { - if (this.y + 1 > -EDGE_OFFSET) { - deltaY += -EDGE_OFFSET - 1 - this.y; - this.y = -EDGE_OFFSET - 1; - } - if (this.y + screenHeight < EDGE_OFFSET) { - deltaY += EDGE_OFFSET - screenHeight - this.y; - this.y = EDGE_OFFSET - screenHeight; - } - } - - if (this.y >= 0 && this.y - objHeight / 2 > screenHeight / 2) { - this.y -= screenHeight - objHeight; - } - if (this.y < 0 && this.y - objHeight / 2 <= -screenHeight / 2) { - this.y += screenHeight - objHeight; - } - return deltaY; - } - - public boolean rightAligned(ScaledResolution scaledResolution, int objWidth) { - return (this.getAbsX(scaledResolution, objWidth) > (scaledResolution.getScaledWidth() / 2)); - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/Category.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/Category.java deleted file mode 100644 index 0564bd8db..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/Category.java +++ /dev/null @@ -1,14 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.config.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface Category { - String name(); - - String desc(); -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigAccordionId.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigAccordionId.java deleted file mode 100644 index 504078bd1..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigAccordionId.java +++ /dev/null @@ -1,12 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.config.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface ConfigAccordionId { - int id(); -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigEditorAccordion.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigEditorAccordion.java deleted file mode 100644 index 48d2b31a0..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigEditorAccordion.java +++ /dev/null @@ -1,12 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.config.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface ConfigEditorAccordion { - int id(); -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigEditorBoolean.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigEditorBoolean.java deleted file mode 100644 index 0ef0bd6d3..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigEditorBoolean.java +++ /dev/null @@ -1,11 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.config.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface ConfigEditorBoolean { -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigEditorButton.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigEditorButton.java deleted file mode 100644 index c453f1f1b..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigEditorButton.java +++ /dev/null @@ -1,14 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.config.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface ConfigEditorButton { - String runnableId(); - - String buttonText() default ""; -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigEditorColour.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigEditorColour.java deleted file mode 100644 index 0ee2f580a..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigEditorColour.java +++ /dev/null @@ -1,11 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.config.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface ConfigEditorColour { -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigEditorDraggableList.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigEditorDraggableList.java deleted file mode 100644 index 5c15da156..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigEditorDraggableList.java +++ /dev/null @@ -1,12 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.config.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface ConfigEditorDraggableList { - String[] exampleText(); -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigEditorDropdown.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigEditorDropdown.java deleted file mode 100644 index 7deee74ad..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigEditorDropdown.java +++ /dev/null @@ -1,14 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.config.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface ConfigEditorDropdown { - String[] values(); - - int initialIndex() default 0; -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigEditorKeybind.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigEditorKeybind.java deleted file mode 100644 index 4fb77b922..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigEditorKeybind.java +++ /dev/null @@ -1,12 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.config.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface ConfigEditorKeybind { - int defaultKey(); -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigEditorSlider.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigEditorSlider.java deleted file mode 100644 index bd636ffc0..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigEditorSlider.java +++ /dev/null @@ -1,16 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.config.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface ConfigEditorSlider { - float minValue(); - - float maxValue(); - - float minStep(); -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigEditorStyle.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigEditorStyle.java deleted file mode 100644 index b28d00bb6..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigEditorStyle.java +++ /dev/null @@ -1,11 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.config.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface ConfigEditorStyle { -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigEditorText.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigEditorText.java deleted file mode 100644 index 56175995f..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigEditorText.java +++ /dev/null @@ -1,11 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.config.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface ConfigEditorText { -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigOption.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigOption.java deleted file mode 100644 index 5dbb5ce67..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/annotations/ConfigOption.java +++ /dev/null @@ -1,16 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.config.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface ConfigOption { - String name(); - - String desc(); - - int subcategoryId() default -1; -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditor.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditor.java deleted file mode 100644 index 1c4deb331..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditor.java +++ /dev/null @@ -1,62 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.config.gui; - -import at.hannibal2.skyhanni.config.gui.core.config.struct.ConfigProcessor; -import at.hannibal2.skyhanni.config.gui.core.util.render.RenderUtils; -import at.hannibal2.skyhanni.config.gui.core.util.render.TextRenderUtils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.renderer.GlStateManager; - -public abstract class GuiOptionEditor { - - protected final ConfigProcessor.ProcessedOption option; - private static final int HEIGHT = 45; - - public GuiOptionEditor(ConfigProcessor.ProcessedOption option) { - this.option = option; - } - - public void render(int x, int y, int width) { - int height = getHeight(); - - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - RenderUtils.drawFloatingRectDark(x, y, width, height, true); - TextRenderUtils.drawStringCenteredScaledMaxWidth(option.name, fr, x + width / 6, y + 13, true, width / 3 - 10, 0xc0c0c0); - - int maxLines = 5; - float scale = 1; - int lineCount = fr.listFormattedStringToWidth(option.desc, width * 2 / 3 - 10).size(); - - if (lineCount <= 0) return; - - float paraHeight = 9 * lineCount - 1; - - while (paraHeight >= HEIGHT - 10) { - scale -= 1 / 8f; - lineCount = fr.listFormattedStringToWidth(option.desc, (int) (width * 2 / 3 / scale - 10)).size(); - paraHeight = (int) (9 * scale * lineCount - 1 * scale); - } - - GlStateManager.pushMatrix(); - GlStateManager.translate(x + 5 + width / 3f, y + HEIGHT / 2f - paraHeight / 2, 0); - GlStateManager.scale(scale, scale, 1); - - fr.drawSplitString(option.desc, 0, 0, (int) (width * 2 / 3 / scale - 10), 0xc0c0c0); - - GlStateManager.popMatrix(); - } - - public int getHeight() { - return HEIGHT; - } - - public abstract boolean mouseInput(int x, int y, int width, int mouseX, int mouseY); - - public abstract boolean keyboardInput(); - - public boolean mouseInputOverlay(int x, int y, int width, int mouseX, int mouseY) { - return false; - } - - public void renderOverlay(int x, int y, int width) {} -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorAccordion.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorAccordion.java deleted file mode 100644 index df473eeb5..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorAccordion.java +++ /dev/null @@ -1,80 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.config.gui; - -import at.hannibal2.skyhanni.config.gui.core.config.struct.ConfigProcessor; -import at.hannibal2.skyhanni.config.gui.core.util.render.RenderUtils; -import at.hannibal2.skyhanni.config.gui.core.util.render.TextRenderUtils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.WorldRenderer; -import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import org.lwjgl.input.Mouse; -import org.lwjgl.opengl.GL11; - -public class GuiOptionEditorAccordion extends GuiOptionEditor { - - private final int accordionId; - private boolean accordionToggled; - - public GuiOptionEditorAccordion(ConfigProcessor.ProcessedOption option, int accordionId) { - super(option); - this.accordionToggled = (boolean) option.get(); - this.accordionId = accordionId; - } - - @Override - public int getHeight() { - return 20; - } - - public int getAccordionId() { - return accordionId; - } - - public boolean getToggled() { - return accordionToggled; - } - - @Override - public void render(int x, int y, int width) { - int height = getHeight(); - RenderUtils.drawFloatingRectDark(x, y, width, height, true); - - Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldrenderer = tessellator.getWorldRenderer(); - GlStateManager.enableBlend(); - GlStateManager.disableTexture2D(); - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); - GlStateManager.color(1, 1, 1, 1); - worldrenderer.begin(GL11.GL_TRIANGLES, DefaultVertexFormats.POSITION); - if (accordionToggled) { - worldrenderer.pos((double) x + 6, (double) y + 6, 0.0D).endVertex(); - worldrenderer.pos((double) x + 9.75f, (double) y + 13.5f, 0.0D).endVertex(); - worldrenderer.pos((double) x + 13.5f, (double) y + 6, 0.0D).endVertex(); - } else { - worldrenderer.pos((double) x + 6, (double) y + 13.5f, 0.0D).endVertex(); - worldrenderer.pos((double) x + 13.5f, (double) y + 9.75f, 0.0D).endVertex(); - worldrenderer.pos((double) x + 6, (double) y + 6, 0.0D).endVertex(); - } - tessellator.draw(); - GlStateManager.enableTexture2D(); - GlStateManager.disableBlend(); - - TextRenderUtils.drawStringScaledMaxWidth(option.name, Minecraft.getMinecraft().fontRendererObj, x + 18, y + 6, false, width - 10, 0xc0c0c0); - } - - @Override - public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { - if (Mouse.getEventButtonState() && mouseX > x && mouseX < x + width && mouseY > y && mouseY < y + getHeight()) { - accordionToggled = !accordionToggled; - return true; - } - - return false; - } - - @Override - public boolean keyboardInput() { - return false; - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorBoolean.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorBoolean.java deleted file mode 100644 index 23bec2ad7..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorBoolean.java +++ /dev/null @@ -1,37 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.config.gui; - -import at.hannibal2.skyhanni.config.gui.core.GuiElementBoolean; -import at.hannibal2.skyhanni.config.gui.core.config.struct.ConfigProcessor; - -public class GuiOptionEditorBoolean extends GuiOptionEditor { - - private final GuiElementBoolean bool; - - public GuiOptionEditorBoolean(ConfigProcessor.ProcessedOption option) { - super(option); - bool = new GuiElementBoolean(0, 0, (boolean) option.get(), 10, option::set); - } - - @Override - public void render(int x, int y, int width) { - super.render(x, y, width); - int height = getHeight(); - - bool.x = x + width / 6 - 24; - bool.y = y + height - 7 - 14; - bool.render(); - } - - @Override - public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { - int height = getHeight(); - bool.x = x + width / 6 - 24; - bool.y = y + height - 7 - 14; - return bool.mouseInput(mouseX, mouseY); - } - - @Override - public boolean keyboardInput() { - return false; - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorButton.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorButton.java deleted file mode 100644 index 05db7d216..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorButton.java +++ /dev/null @@ -1,60 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.config.gui; - -import static at.hannibal2.skyhanni.config.gui.GuiTextures.button_tex; - -import at.hannibal2.skyhanni.config.Features; -import at.hannibal2.skyhanni.config.gui.core.config.struct.ConfigProcessor; -import at.hannibal2.skyhanni.config.gui.core.util.render.RenderUtils; -import at.hannibal2.skyhanni.config.gui.core.util.render.TextRenderUtils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.GlStateManager; -import org.lwjgl.input.Mouse; - -public class GuiOptionEditorButton extends GuiOptionEditor { - - private final String runnableId; - private String buttonText; - private final Features config; - - public GuiOptionEditorButton(ConfigProcessor.ProcessedOption option, String runnableId, String buttonText, Features config) { - super(option); - this.runnableId = runnableId; - this.config = config; - - this.buttonText = buttonText; - if (this.buttonText != null && this.buttonText.isEmpty()) this.buttonText = null; - } - - @Override - public void render(int x, int y, int width) { - super.render(x, y, width); - - int height = getHeight(); - - GlStateManager.color(1, 1, 1, 1); - Minecraft.getMinecraft().getTextureManager().bindTexture(button_tex); - RenderUtils.drawTexturedRect(x + width / 6 - 24, y + height - 7 - 14, 48, 16); - - if (buttonText != null) { - TextRenderUtils.drawStringCenteredScaledMaxWidth(buttonText, Minecraft.getMinecraft().fontRendererObj, x + width / 6, y + height - 7 - 6, false, 44, 0xFF303030); - } - } - - @Override - public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { - if (Mouse.getEventButtonState()) { - int height = getHeight(); - if (mouseX > x + width / 6 - 24 && mouseX < x + width / 6 + 24 && mouseY > y + height - 7 - 14 && mouseY < y + height - 7 + 2) { - config.executeRunnable(runnableId); - return true; - } - } - - return false; - } - - @Override - public boolean keyboardInput() { - return false; - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorColour.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorColour.java deleted file mode 100644 index 716df0dca..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorColour.java +++ /dev/null @@ -1,74 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.config.gui; - -import static at.hannibal2.skyhanni.config.gui.GuiTextures.*; - -import at.hannibal2.skyhanni.config.gui.core.ChromaColour; -import at.hannibal2.skyhanni.config.gui.core.GuiElementColour; -import at.hannibal2.skyhanni.config.gui.core.config.struct.ConfigProcessor; -import at.hannibal2.skyhanni.config.gui.core.util.render.RenderUtils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.GlStateManager; -import org.lwjgl.input.Mouse; - -public class GuiOptionEditorColour extends GuiOptionEditor { - - private String chromaColour; - private GuiElementColour colourElement = null; - - public GuiOptionEditorColour(ConfigProcessor.ProcessedOption option) { - super(option); - this.chromaColour = (String) option.get(); - } - - @Override - public void render(int x, int y, int width) { - super.render(x, y, width); - int height = getHeight(); - - int argb = ChromaColour.specialToChromaRGB(chromaColour); - int r = (argb >> 16) & 0xFF; - int g = (argb >> 8) & 0xFF; - int b = argb & 0xFF; - GlStateManager.color(r / 255f, g / 255f, b / 255f, 1); - Minecraft.getMinecraft().getTextureManager().bindTexture(button_white); - RenderUtils.drawTexturedRect(x + width / 6 - 24, y + height - 7 - 14, 48, 16); - } - - @Override - public void renderOverlay(int x, int y, int width) { - if (colourElement != null) { - colourElement.render(); - } - } - - @Override - public boolean mouseInputOverlay(int x, int y, int width, int mouseX, int mouseY) { - return colourElement != null && colourElement.mouseInput(mouseX, mouseY); - } - - @Override - public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { - int height = getHeight(); - - if (Mouse.getEventButtonState() && Mouse.getEventButton() == 0 && mouseX > x + width / 6 - 24 && mouseX < x + width / 6 + 24 && mouseY > y + height - 7 - 14 && mouseY < y + height - 7 + 2) { - colourElement = - new GuiElementColour( - mouseX, - mouseY, - (String) option.get(), - val -> { - option.set(val); - chromaColour = val; - }, - () -> colourElement = null - ); - } - - return false; - } - - @Override - public boolean keyboardInput() { - return colourElement != null && colourElement.keyboardInput(); - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorDraggableList.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorDraggableList.java deleted file mode 100644 index ba72f34b9..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorDraggableList.java +++ /dev/null @@ -1,269 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.config.gui; - -import at.hannibal2.skyhanni.config.gui.core.config.struct.ConfigProcessor; -import at.hannibal2.skyhanni.config.gui.core.util.lerp.LerpUtils; -import at.hannibal2.skyhanni.config.gui.core.util.render.RenderUtils; -import at.hannibal2.skyhanni.config.gui.core.util.render.TextRenderUtils; -import at.hannibal2.skyhanni.config.gui.utils.ConfigUtils; -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.Mouse; -import org.lwjgl.opengl.GL11; - -import java.util.ArrayList; -import java.util.List; - -import static at.hannibal2.skyhanni.config.gui.GuiTextures.DELETE; -import static at.hannibal2.skyhanni.config.gui.GuiTextures.button_tex; - -public class GuiOptionEditorDraggableList extends GuiOptionEditor { - - private final String[] exampleText; - private final List<Integer> activeText; - private int currentDragging = -1; - private int dragStartIndex = -1; - - private long trashHoverTime = -1; - - private int dragOffsetX = -1; - private int dragOffsetY = -1; - - private boolean dropdownOpen = false; - - public GuiOptionEditorDraggableList(ConfigProcessor.ProcessedOption option, String[] exampleText) { - super(option); - this.exampleText = exampleText; - this.activeText = (List<Integer>) option.get(); - } - - @Override - public int getHeight() { - int height = super.getHeight() + 13; - - for (int strIndex : activeText) { - String str = exampleText[strIndex]; - height += 10 * str.split("\n").length; - } - - return height; - } - - @Override - public void render(int x, int y, int width) { - super.render(x, y, width); - - int height = getHeight(); - - GlStateManager.color(1, 1, 1, 1); - Minecraft.getMinecraft().getTextureManager().bindTexture(button_tex); - 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); - } - Minecraft.getMinecraft().getTextureManager().bindTexture(DELETE); - ConfigUtils.drawTexturedRect(x + width / 6 + 27, y + 45 - 7 - 13, 11, 14, GL11.GL_NEAREST); - - 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 (int strIndex : activeText) { - String str = exampleText[strIndex]; - - 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]; - ConfigUtils.drawStringScaledMaxWidth(line + EnumChatFormatting.RESET, Minecraft.getMinecraft().fontRendererObj, x + 20, y + 50 + yOff + multilineIndex * 10, true, width - 20, 0xffffffff); - } - Minecraft.getMinecraft().fontRendererObj.drawString("\u2261", x + 10, y + 50 + 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<Integer> remaining = new ArrayList<>(); - for (int i = 0; i < exampleText.length; i++) { - remaining.add(i); - } - 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 (int strIndex : remaining) { - String str = exampleText[strIndex]; - if (str.isEmpty()) { - str = "<NONE>"; - } - TextRenderUtils.drawStringScaledMaxWidth(str.replaceAll("(\n.*)+", " ..."), fr, left + 3, top + 3 + dropdownY, false, dropdownWidth - 6, 0xffa0a0a0); - dropdownY += 12; - } - } else if (currentDragging >= 0) { - 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 = exampleText[currentDragging]; - - String[] multilines = str.split("\n"); - - GlStateManager.enableBlend(); - for (int multilineIndex = 0; multilineIndex < multilines.length; multilineIndex++) { - String line = multilines[multilineIndex]; - ConfigUtils.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 + mouseY + ySize / 2 - 4, 0xffffff, true); - } - } - - @Override - public boolean mouseInput(int x, int y, int width, int mouseX, int 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) { - activeText.remove(dragStartIndex); - currentDragging = -1; - dragStartIndex = -1; - return false; - } - - if (!Mouse.isButtonDown(0) || dropdownOpen) { - currentDragging = -1; - dragStartIndex = -1; - if (trashHoverTime > 0) trashHoverTime = -System.currentTimeMillis(); - } else if (currentDragging >= 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 (trashHoverTime < 0) trashHoverTime = System.currentTimeMillis(); - } else { - if (trashHoverTime > 0) trashHoverTime = -System.currentTimeMillis(); - } - - if (Mouse.getEventButtonState()) { - int height = getHeight(); - - if (dropdownOpen) { - List<Integer> remaining = new ArrayList<>(); - for (int i = 0; i < exampleText.length; i++) { - remaining.add(i); - } - 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 (int strIndex : remaining) { - if (mouseY < top + dropdownY + 12) { - activeText.add(0, strIndex); - if (remaining.size() == 1) dropdownOpen = false; - return true; - } - - dropdownY += 12; - } - } - - dropdownOpen = false; - return true; - } - - if (activeText.size() < exampleText.length && mouseX > x + width / 6 - 24 && mouseX < x + width / 6 + 24 && mouseY > y + 45 - 7 - 14 && mouseY < y + 45 - 7 + 2) { - dropdownOpen = !dropdownOpen; - 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 (int strIndex : activeText) { - int ySize = 10 * exampleText[strIndex].split("\n").length; - if (mouseY < y + 50 + yOff + ySize) { - dragOffsetX = x + 10 - mouseX; - dragOffsetY = y + 50 + yOff - mouseY; - - currentDragging = strIndex; - dragStartIndex = i; - break; - } - yOff += ySize; - i++; - } - } - } else if (Mouse.getEventButton() == -1 && currentDragging >= 0) { - int yOff = 0; - int i = 0; - for (int strIndex : activeText) { - if (dragOffsetY + mouseY + 4 < y + 50 + yOff + 10) { - activeText.remove(dragStartIndex); - activeText.add(i, currentDragging); - - dragStartIndex = i; - break; - } - yOff += 10 * exampleText[strIndex].split("\n").length; - i++; - } - } - - return false; - } - - @Override - public boolean keyboardInput() { - return false; - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorDropdown.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorDropdown.java deleted file mode 100644 index c171a5754..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorDropdown.java +++ /dev/null @@ -1,145 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.config.gui; - -import at.hannibal2.skyhanni.config.gui.core.config.struct.ConfigProcessor; -import at.hannibal2.skyhanni.config.gui.core.util.render.RenderUtils; -import at.hannibal2.skyhanni.config.gui.core.util.render.TextRenderUtils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.Gui; -import org.lwjgl.input.Mouse; - -public class GuiOptionEditorDropdown extends GuiOptionEditor { - - protected final String[] values; - private final boolean useOrdinal; - protected int selected; - protected boolean open = false; - - public GuiOptionEditorDropdown(ConfigProcessor.ProcessedOption option, String[] values, int selected, boolean useOrdinal) { - super(option); - if (selected >= values.length) selected = values.length; - this.values = values; - this.selected = selected; - this.useOrdinal = useOrdinal; - } - - @Override - public void render(int x, int y, int width) { - super.render(x, y, width); - - if (!open) { - int height = getHeight(); - - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - int dropdownWidth = Math.min(width / 3 - 10, 80); - int left = x + width / 6 - dropdownWidth / 2; - int top = y + height - 7 - 14; - - String selectedString = " - Select - "; - if (selected >= 0 && selected < values.length) { - selectedString = values[selected]; - } - - RenderUtils.drawFloatingRectDark(left, top, dropdownWidth, 14, false); - TextRenderUtils.drawStringScaled("\u25BC", fr, left + dropdownWidth - 10, y + height - 7 - 15, false, 0xffa0a0a0, 2); - - TextRenderUtils.drawStringScaledMaxWidth(selectedString, fr, left + 3, top + 3, false, dropdownWidth - 16, 0xffa0a0a0); - } - } - - @Override - public void renderOverlay(int x, int y, int width) { - if (open) { - String selectedString = " - Select - "; - if (selected >= 0 && selected < values.length) { - selectedString = values[selected]; - } - - int height = getHeight(); - - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - int dropdownWidth = Math.min(width / 3 - 10, 80); - int left = x + width / 6 - dropdownWidth / 2; - int top = y + height - 7 - 14; - - int dropdownHeight = 13 + 12 * values.length; - - int main = 0xff202026; - int blue = 0xff2355ad; - Gui.drawRect(left, top, left + 1, top + dropdownHeight, blue); //Left - Gui.drawRect(left + 1, top, left + dropdownWidth, top + 1, blue); //Top - Gui.drawRect(left + dropdownWidth - 1, top + 1, left + dropdownWidth, top + dropdownHeight, blue); //Right - Gui.drawRect(left + 1, top + dropdownHeight - 1, left + dropdownWidth - 1, top + dropdownHeight, blue); //Bottom - Gui.drawRect(left + 1, top + 1, left + dropdownWidth - 1, top + dropdownHeight - 1, main); //Middle - - Gui.drawRect(left + 1, top + 14 - 1, left + dropdownWidth - 1, top + 14, blue); //Bar - - int dropdownY = 13; - for (String option : values) { - if (option.isEmpty()) { - option = "<NONE>"; - } - TextRenderUtils.drawStringScaledMaxWidth(option, fr, left + 3, top + 3 + dropdownY, false, dropdownWidth - 6, 0xffa0a0a0); - dropdownY += 12; - } - - TextRenderUtils.drawStringScaled("\u25B2", fr, left + dropdownWidth - 10, y + height - 7 - 15, false, 0xffa0a0a0, 2); - - TextRenderUtils.drawStringScaledMaxWidth(selectedString, fr, left + 3, top + 3, false, dropdownWidth - 16, 0xffa0a0a0); - } - } - - @Override - public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { - int height = getHeight(); - - int left = x + width / 6 - 40; - int top = y + height - 7 - 14; - - if (Mouse.getEventButtonState() && Mouse.getEventButton() == 0) { - if (mouseX >= left && mouseX <= left + 80 && mouseY >= top && mouseY <= top + 14) { - open = !open; - return true; - } - } - - return false; - } - - @Override - public boolean mouseInputOverlay(int x, int y, int width, int mouseX, int mouseY) { - int height = getHeight(); - - int left = x + width / 6 - 40; - int top = y + height - 7 - 14; - - if (Mouse.getEventButtonState() && Mouse.getEventButton() == 0) { - if (!(mouseX >= left && mouseX <= left + 80 && mouseY >= top && mouseY <= top + 14) && open) { - open = false; - if (mouseX >= left && mouseX <= left + 80) { - int dropdownY = 13; - for (int ordinal = 0; ordinal < values.length; ordinal++) { - if (mouseY >= top + 3 + dropdownY && mouseY <= top + 3 + dropdownY + 12) { - selected = ordinal; - if (useOrdinal) { - option.set(selected); - } else { - option.set(values[selected]); - } - return true; - } - dropdownY += 12; - } - } - return true; - } - } - - return false; - } - - @Override - public boolean keyboardInput() { - return false; - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorKeybind.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorKeybind.java deleted file mode 100644 index 2d737352c..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorKeybind.java +++ /dev/null @@ -1,88 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.config.gui; - -import static at.hannibal2.skyhanni.config.gui.GuiTextures.*; - -import at.hannibal2.skyhanni.config.gui.core.config.KeybindHelper; -import at.hannibal2.skyhanni.config.gui.core.config.struct.ConfigProcessor; -import at.hannibal2.skyhanni.config.gui.core.util.render.RenderUtils; -import at.hannibal2.skyhanni.config.gui.core.util.render.TextRenderUtils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.util.ResourceLocation; -import org.lwjgl.input.Keyboard; -import org.lwjgl.input.Mouse; -import org.lwjgl.opengl.GL11; - -public class GuiOptionEditorKeybind extends GuiOptionEditor { - - private static final ResourceLocation RESET = new ResourceLocation("notenoughupdates:itemcustomize/reset.png"); - - private int keyCode; - private final int defaultKeyCode; - private boolean editingKeycode; - - public GuiOptionEditorKeybind(ConfigProcessor.ProcessedOption option, int keyCode, int defaultKeyCode) { - super(option); - this.keyCode = keyCode; - this.defaultKeyCode = defaultKeyCode; - } - - @Override - public void render(int x, int y, int width) { - super.render(x, y, width); - - int height = getHeight(); - - GlStateManager.color(1, 1, 1, 1); - Minecraft.getMinecraft().getTextureManager().bindTexture(button_tex); - RenderUtils.drawTexturedRect(x + width / 6 - 24, y + height - 7 - 14, 48, 16); - - String keyName = KeybindHelper.getKeyName(keyCode); - String text = editingKeycode ? "> " + keyName + " <" : keyName; - TextRenderUtils.drawStringCenteredScaledMaxWidth(text, Minecraft.getMinecraft().fontRendererObj, x + width / 6, y + height - 7 - 6, false, 40, 0xFF303030); - - Minecraft.getMinecraft().getTextureManager().bindTexture(RESET); - GlStateManager.color(1, 1, 1, 1); - RenderUtils.drawTexturedRect(x + width / 6 - 24 + 48 + 3, y + height - 7 - 14 + 3, 10, 11, GL11.GL_NEAREST); - } - - @Override - public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { - if (Mouse.getEventButtonState() && Mouse.getEventButton() != -1 && editingKeycode) { - editingKeycode = false; - keyCode = Mouse.getEventButton() - 100; - option.set(keyCode); - return true; - } - - if (Mouse.getEventButtonState() && Mouse.getEventButton() == 0) { - int height = getHeight(); - if (mouseX > x + width / 6 - 24 && mouseX < x + width / 6 + 24 && mouseY > y + height - 7 - 14 && mouseY < y + height - 7 + 2) { - editingKeycode = true; - return true; - } - if (mouseX > x + width / 6 - 24 + 48 + 3 && mouseX < x + width / 6 - 24 + 48 + 13 && mouseY > y + height - 7 - 14 + 3 && mouseY < y + height - 7 - 14 + 3 + 11) { - keyCode = defaultKeyCode; - option.set(keyCode); - return true; - } - } - - return false; - } - - @Override - public boolean keyboardInput() { - if (editingKeycode) { - editingKeycode = false; - if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) { - keyCode = 0; - } else { - keyCode = Keyboard.getEventKey() == 0 ? Keyboard.getEventCharacter() + 256 : Keyboard.getEventKey(); - } - option.set(keyCode); - return true; - } - return false; - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorSlider.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorSlider.java deleted file mode 100644 index b321d66a3..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorSlider.java +++ /dev/null @@ -1,136 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.config.gui; - -import at.hannibal2.skyhanni.config.gui.core.GuiElementTextField; -import at.hannibal2.skyhanni.config.gui.core.config.struct.ConfigProcessor; -import at.hannibal2.skyhanni.config.gui.core.util.GuiElementSlider; -import net.minecraft.client.Minecraft; -import org.lwjgl.input.Keyboard; -import org.lwjgl.input.Mouse; - -public class GuiOptionEditorSlider extends GuiOptionEditor { - - private final GuiElementSlider slider; - private final GuiElementTextField textField; - - public GuiOptionEditorSlider(ConfigProcessor.ProcessedOption option, float minValue, float maxValue, float minStep) { - super(option); - if (minStep < 0) minStep = 0.01f; - - float floatVal = ((Number) option.get()).floatValue(); - { - String strVal; - if (floatVal % 1 == 0) { - strVal = Integer.toString((int) floatVal); - } else { - strVal = Float.toString(floatVal); - } - textField = new GuiElementTextField(strVal, GuiElementTextField.NO_SPACE | GuiElementTextField.NUM_ONLY | GuiElementTextField.SCALE_TEXT); - } - - slider = - new GuiElementSlider( - 0, - 0, - 80, - minValue, - maxValue, - minStep, - floatVal, - val -> { - option.set(val); - - String strVal; - if (val % 1 == 0) { - strVal = Integer.toString(val.intValue()); - } else { - strVal = Float.toString(val); - strVal = strVal.replaceAll("(\\.\\d\\d\\d)(?:\\d)+", "$1"); - strVal = strVal.replaceAll("0+$", ""); - } - textField.setText(strVal); - } - ); - } - - @Override - public void render(int x, int y, int width) { - super.render(x, y, width); - int height = getHeight(); - - int fullWidth = Math.min(width / 3 - 10, 80); - int sliderWidth = (fullWidth - 5) * 3 / 4; - int textFieldWidth = (fullWidth - 5) / 4; - - slider.x = x + width / 6 - fullWidth / 2; - slider.y = y + height - 7 - 14; - slider.width = sliderWidth; - slider.render(); - - if (textField.getFocus()) { - textField.setOptions(GuiElementTextField.NO_SPACE | GuiElementTextField.NUM_ONLY); - textField.setSize(Minecraft.getMinecraft().fontRendererObj.getStringWidth(textField.getText()) + 10, 16); - } else { - textField.setSize(textFieldWidth, 16); - textField.setOptions(GuiElementTextField.NO_SPACE | GuiElementTextField.NUM_ONLY | GuiElementTextField.SCALE_TEXT); - } - - textField.render(x + width / 6 - fullWidth / 2 + sliderWidth + 5, y + height - 7 - 14); - } - - @Override - public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { - int height = getHeight(); - - int fullWidth = Math.min(width / 3 - 10, 80); - int sliderWidth = (fullWidth - 5) * 3 / 4; - int textFieldWidth = (fullWidth - 5) / 4; - - slider.x = x + width / 6 - fullWidth / 2; - slider.y = y + height - 7 - 14; - slider.width = sliderWidth; - if (slider.mouseInput(mouseX, mouseY)) { - textField.unfocus(); - return true; - } - - if (textField.getFocus()) { - textFieldWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(textField.getText()) + 10; - } - - int textFieldX = x + width / 6 - fullWidth / 2 + sliderWidth + 5; - int textFieldY = y + height - 7 - 14; - textField.setSize(textFieldWidth, 16); - - if (Mouse.getEventButtonState() && (Mouse.getEventButton() == 0 || Mouse.getEventButton() == 1)) { - if (mouseX > textFieldX && mouseX < textFieldX + textFieldWidth && mouseY > textFieldY && mouseY < textFieldY + 16) { - textField.mouseClicked(mouseX, mouseY, Mouse.getEventButton()); - return true; - } - textField.unfocus(); - } - - return false; - } - - @Override - public boolean keyboardInput() { - if (Keyboard.getEventKeyState() && textField.getFocus()) { - textField.keyTyped(Keyboard.getEventCharacter(), Keyboard.getEventKey()); - - try { - textField.setCustomBorderColour(0xffffffff); - float f = Float.parseFloat(textField.getText()); - if (option.set(f)) { - slider.setValue(f); - } else { - textField.setCustomBorderColour(0xff0000ff); - } - } catch (Exception e) { - textField.setCustomBorderColour(0xffff0000); - } - - return true; - } - return false; - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorStyle.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorStyle.java deleted file mode 100644 index e495f2080..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorStyle.java +++ /dev/null @@ -1,42 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.config.gui; - -import at.hannibal2.skyhanni.config.gui.core.config.struct.ConfigProcessor; -import at.hannibal2.skyhanni.config.gui.textures.Textures; -import java.util.stream.Collectors; -import org.lwjgl.input.Mouse; - -public class GuiOptionEditorStyle extends GuiOptionEditorDropdown { - - public GuiOptionEditorStyle(ConfigProcessor.ProcessedOption option, int selected) { - super(option, Textures.styles.stream().map(t -> t.displayName).collect(Collectors.toList()).toArray(new String[] {}), selected, true); - } - - @Override - public boolean mouseInputOverlay(int x, int y, int width, int mouseX, int mouseY) { - int height = getHeight(); - - int left = x + width / 6 - 40; - int top = y + height - 7 - 14; - - if (Mouse.getEventButtonState() && Mouse.getEventButton() == 0) { - if (!(mouseX >= left && mouseX <= left + 80 && mouseY >= top && mouseY <= top + 14) && open) { - this.open = false; - if (mouseX >= left && mouseX <= left + 80) { - int dropdownY = 13; - for (int ordinal = 0; ordinal < values.length; ordinal++) { - if (mouseY >= top + 3 + dropdownY && mouseY <= top + 3 + dropdownY + 12) { - selected = ordinal; - option.set(selected); - Textures.setTexture(selected); - return true; - } - dropdownY += 12; - } - } - return true; - } - } - - return false; - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorText.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorText.java deleted file mode 100644 index 05d9e3445..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorText.java +++ /dev/null @@ -1,78 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.config.gui; - -import at.hannibal2.skyhanni.config.gui.core.GuiElementTextField; -import at.hannibal2.skyhanni.config.gui.core.config.struct.ConfigProcessor; -import net.minecraft.client.Minecraft; -import org.lwjgl.input.Keyboard; -import org.lwjgl.input.Mouse; - -public class GuiOptionEditorText extends GuiOptionEditor { - - private final GuiElementTextField textField; - - public GuiOptionEditorText(ConfigProcessor.ProcessedOption option) { - super(option); - textField = new GuiElementTextField((String) option.get(), 0); - } - - @Override - public void render(int x, int y, int width) { - super.render(x, y, width); - int height = getHeight(); - - int fullWidth = Math.min(width / 3 - 10, 80); - - int textFieldX = x + width / 6 - fullWidth / 2; - if (textField.getFocus()) { - fullWidth = Math.max(fullWidth, Minecraft.getMinecraft().fontRendererObj.getStringWidth(textField.getText()) + 10); - } - - textField.setSize(fullWidth, 16); - - textField.render(textFieldX, y + height - 7 - 14); - } - - @Override - public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { - int height = getHeight(); - - int fullWidth = Math.min(width / 3 - 10, 80); - - int textFieldX = x + width / 6 - fullWidth / 2; - - if (textField.getFocus()) { - fullWidth = Math.max(fullWidth, Minecraft.getMinecraft().fontRendererObj.getStringWidth(textField.getText()) + 10); - } - - int textFieldY = y + height - 7 - 14; - textField.setSize(fullWidth, 16); - - if (Mouse.getEventButtonState() && (Mouse.getEventButton() == 0 || Mouse.getEventButton() == 1)) { - if (mouseX > textFieldX && mouseX < textFieldX + fullWidth && mouseY > textFieldY && mouseY < textFieldY + 16) { - textField.mouseClicked(mouseX, mouseY, Mouse.getEventButton()); - return true; - } - textField.unfocus(); - } - - return false; - } - - @Override - public boolean keyboardInput() { - if (Keyboard.getEventKeyState() && textField.getFocus()) { - Keyboard.enableRepeatEvents(true); - textField.keyTyped(Keyboard.getEventCharacter(), Keyboard.getEventKey()); - - try { - textField.setCustomBorderColour(0xffffffff); - option.set(textField.getText()); - } catch (Exception e) { - textField.setCustomBorderColour(0xffff0000); - } - - return true; - } - return false; - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiPositionEditor.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiPositionEditor.java deleted file mode 100644 index efb04043f..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiPositionEditor.java +++ /dev/null @@ -1,172 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.config.gui; - -import at.hannibal2.skyhanni.config.gui.core.config.Position; -import at.hannibal2.skyhanni.config.gui.utils.ConfigUtils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.gui.ScaledResolution; -import org.lwjgl.input.Keyboard; -import org.lwjgl.input.Mouse; - -import java.io.IOException; - -public class GuiPositionEditor extends GuiScreen { - - private final Position position; - private final Position originalPosition; - private final int elementWidth; - private final int elementHeight; - private final Runnable renderCallback; - private final Runnable positionChangedCallback; - private final Runnable closedCallback; - private boolean clicked = false; - private int grabbedX = 0; - private int grabbedY = 0; - - private int guiScaleOverride = -1; - - public GuiPositionEditor(Position position, int elementWidth, int elementHeight, Runnable renderCallback, Runnable positionChangedCallback, Runnable closedCallback) { - this.position = position; - this.originalPosition = position.clone(); - this.elementWidth = elementWidth; - this.elementHeight = elementHeight; - this.renderCallback = renderCallback; - this.positionChangedCallback = positionChangedCallback; - this.closedCallback = closedCallback; - } - - public GuiPositionEditor withScale(int scale) { - this.guiScaleOverride = scale; - return this; - } - - @Override - public void onGuiClosed() { - super.onGuiClosed(); - closedCallback.run(); - } - - @Override - public void drawScreen(int mouseX, int mouseY, float partialTicks) { - super.drawScreen(mouseX, mouseY, partialTicks); - ScaledResolution scaledResolution; - if (guiScaleOverride >= 0) { - scaledResolution = ConfigUtils.pushGuiScale(guiScaleOverride); - } else { - scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - } - - this.width = scaledResolution.getScaledWidth(); - this.height = scaledResolution.getScaledHeight(); - mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth; - mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; - - drawDefaultBackground(); - - if (clicked) { - grabbedX += position.moveX(mouseX - grabbedX, elementWidth, scaledResolution); - grabbedY += position.moveY(mouseY - grabbedY, elementHeight, scaledResolution); - } - - renderCallback.run(); - - int x = position.getAbsX(scaledResolution, elementWidth); - int y = position.getAbsY(scaledResolution, elementHeight); - - if (position.isCenterX()) x -= elementWidth / 2; - if (position.isCenterY()) y -= elementHeight / 2; - Gui.drawRect(x, y, x + elementWidth, y + elementHeight, 0x80404040); - - if (guiScaleOverride >= 0) { - ConfigUtils.pushGuiScale(-1); - } - - scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - ConfigUtils.drawStringCentered("Position Editor", Minecraft.getMinecraft().fontRendererObj, scaledResolution.getScaledWidth() / 2, 8, true, 0xffffff); - ConfigUtils.drawStringCentered("R to Reset - Arrow keys/mouse to move", Minecraft.getMinecraft().fontRendererObj, scaledResolution.getScaledWidth() / 2, 18, true, 0xffffff); - } - - @Override - protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { - super.mouseClicked(mouseX, mouseY, mouseButton); - - if (mouseButton == 0) { - ScaledResolution scaledResolution; - if (guiScaleOverride >= 0) { - scaledResolution = ConfigUtils.pushGuiScale(guiScaleOverride); - } else { - scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - } - mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth; - mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; - - int x = position.getAbsX(scaledResolution, elementWidth); - int y = position.getAbsY(scaledResolution, elementHeight); - if (position.isCenterX()) x -= elementWidth / 2; - if (position.isCenterY()) y -= elementHeight / 2; - - if (mouseX >= x && mouseY >= y && mouseX <= x + elementWidth && mouseY <= y + elementHeight) { - clicked = true; - grabbedX = mouseX; - grabbedY = mouseY; - } - - if (guiScaleOverride >= 0) { - ConfigUtils.pushGuiScale(-1); - } - } - } - - @Override - protected void keyTyped(char typedChar, int keyCode) throws IOException { - Keyboard.enableRepeatEvents(true); - - if (keyCode == Keyboard.KEY_R) { - position.set(originalPosition); - } else if (!clicked) { - boolean shiftHeld = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT); - int dist = shiftHeld ? 10 : 1; - if (keyCode == Keyboard.KEY_DOWN) { - position.moveY(dist, elementHeight, new ScaledResolution(Minecraft.getMinecraft())); - } else if (keyCode == Keyboard.KEY_UP) { - position.moveY(-dist, elementHeight, new ScaledResolution(Minecraft.getMinecraft())); - } else if (keyCode == Keyboard.KEY_LEFT) { - position.moveX(-dist, elementWidth, new ScaledResolution(Minecraft.getMinecraft())); - } else if (keyCode == Keyboard.KEY_RIGHT) { - position.moveX(dist, elementWidth, new ScaledResolution(Minecraft.getMinecraft())); - } - } - super.keyTyped(typedChar, keyCode); - } - - @Override - protected void mouseReleased(int mouseX, int mouseY, int state) { - super.mouseReleased(mouseX, mouseY, state); - clicked = false; - } - - @Override - protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { - super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick); - - if (clicked) { - ScaledResolution scaledResolution; - if (guiScaleOverride >= 0) { - scaledResolution = ConfigUtils.pushGuiScale(guiScaleOverride); - } else { - scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - } - mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth; - mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; - - grabbedX += position.moveX(mouseX - grabbedX, elementWidth, scaledResolution); - grabbedY += position.moveY(mouseY - grabbedY, elementHeight, scaledResolution); - positionChangedCallback.run(); - - if (guiScaleOverride >= 0) { - ConfigUtils.pushGuiScale(-1); - } - } - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/struct/ConfigProcessor.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/struct/ConfigProcessor.java deleted file mode 100644 index 2ba554a8b..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/struct/ConfigProcessor.java +++ /dev/null @@ -1,166 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.config.struct; - -import at.hannibal2.skyhanni.config.Features; -import at.hannibal2.skyhanni.config.gui.core.config.annotations.*; -import at.hannibal2.skyhanni.config.gui.core.config.gui.*; -import com.google.gson.annotations.Expose; -import java.lang.reflect.Field; -import java.util.LinkedHashMap; -import java.util.List; - -public class ConfigProcessor { - - public static class ProcessedCategory { - - public final String name; - public final String desc; - public final LinkedHashMap<String, ProcessedOption> options = new LinkedHashMap<>(); - - public ProcessedCategory(String name, String desc) { - this.name = name; - this.desc = desc; - } - } - - public static class ProcessedOption { - - public final String name; - public final String desc; - public final int subcategoryId; - public GuiOptionEditor editor; - - public int accordionId = -1; - - private final Field field; - private final Object container; - - public ProcessedOption(String name, String desc, int subcategoryId, Field field, Object container) { - this.name = name; - this.desc = desc; - this.subcategoryId = subcategoryId; - - this.field = field; - this.container = container; - } - - public Object get() { - try { - return field.get(container); - } catch (Exception e) { - return null; - } - } - - public boolean set(Object value) { - try { - if (field.getType() == int.class && value instanceof Number) { - field.set(container, ((Number) value).intValue()); - } else { - field.set(container, value); - } - return true; - } catch (Exception e) { - e.printStackTrace(); - return false; - } - } - } - - public static LinkedHashMap<String, ProcessedCategory> create(Features config) { - LinkedHashMap<String, ProcessedCategory> processedConfig = new LinkedHashMap<>(); - for (Field categoryField : config.getClass().getDeclaredFields()) { - boolean exposePresent = categoryField.isAnnotationPresent(Expose.class); - boolean categoryPresent = categoryField.isAnnotationPresent(Category.class); - - if (exposePresent && categoryPresent) { - Object categoryObj; - try { - categoryObj = categoryField.get(config); - } catch (Exception e) { - //System.err.printf("Failed to load config category %s. Field was not accessible.\n", categoryField.getName()); - continue; - } - - Category categoryAnnotation = categoryField.getAnnotation(Category.class); - ProcessedCategory cat = new ProcessedCategory(categoryAnnotation.name(), categoryAnnotation.desc()); - processedConfig.put(categoryField.getName(), cat); - - for (Field optionField : categoryObj.getClass().getDeclaredFields()) { - boolean optionPresent = optionField.isAnnotationPresent(ConfigOption.class); - - if (optionPresent) { - ConfigOption optionAnnotation = optionField.getAnnotation(ConfigOption.class); - ProcessedOption option = new ProcessedOption(optionAnnotation.name(), optionAnnotation.desc(), optionAnnotation.subcategoryId(), optionField, categoryObj); - if (optionField.isAnnotationPresent(ConfigAccordionId.class)) { - ConfigAccordionId annotation = optionField.getAnnotation(ConfigAccordionId.class); - option.accordionId = annotation.id(); - } - - GuiOptionEditor editor = null; - Class<?> optionType = optionField.getType(); - if (optionType.isAssignableFrom(int.class) && optionField.isAnnotationPresent(ConfigEditorKeybind.class)) { - ConfigEditorKeybind configEditorAnnotation = optionField.getAnnotation(ConfigEditorKeybind.class); - editor = new GuiOptionEditorKeybind(option, (int) option.get(), configEditorAnnotation.defaultKey()); - } - if (optionField.isAnnotationPresent(ConfigEditorButton.class)) { - ConfigEditorButton configEditorAnnotation = optionField.getAnnotation(ConfigEditorButton.class); - editor = new GuiOptionEditorButton(option, configEditorAnnotation.runnableId(), configEditorAnnotation.buttonText(), config); - } - if (optionType.isAssignableFrom(boolean.class) && optionField.isAnnotationPresent(ConfigEditorBoolean.class)) { - editor = new GuiOptionEditorBoolean(option); - } - if (optionType.isAssignableFrom(boolean.class) && optionField.isAnnotationPresent(ConfigEditorAccordion.class)) { - ConfigEditorAccordion configEditorAnnotation = optionField.getAnnotation(ConfigEditorAccordion.class); - editor = new GuiOptionEditorAccordion(option, configEditorAnnotation.id()); - } - if (optionType.isAssignableFrom(int.class)) { - if (optionField.isAnnotationPresent(ConfigEditorDropdown.class)) { - ConfigEditorDropdown configEditorAnnotation = optionField.getAnnotation(ConfigEditorDropdown.class); - editor = new GuiOptionEditorDropdown(option, configEditorAnnotation.values(), (int) option.get(), true); - } else if (optionField.isAnnotationPresent(ConfigEditorStyle.class)) { - editor = new GuiOptionEditorStyle(option, (int) option.get()); - } - } - if (optionType.isAssignableFrom(List.class)) { - if (optionField.isAnnotationPresent(ConfigEditorDraggableList.class)) { - ConfigEditorDraggableList configEditorAnnotation = optionField.getAnnotation(ConfigEditorDraggableList.class); - editor = new GuiOptionEditorDraggableList(option, configEditorAnnotation.exampleText()); - } - } - if (optionType.isAssignableFrom(String.class)) { - if (optionField.isAnnotationPresent(ConfigEditorDropdown.class)) { - ConfigEditorDropdown configEditorAnnotation = optionField.getAnnotation(ConfigEditorDropdown.class); - editor = new GuiOptionEditorDropdown(option, configEditorAnnotation.values(), configEditorAnnotation.initialIndex(), false); - } else if (optionField.isAnnotationPresent(ConfigEditorColour.class)) { - editor = new GuiOptionEditorColour(option); - } else if (optionField.isAnnotationPresent(ConfigEditorText.class)) { - editor = new GuiOptionEditorText(option); - } - } - if (optionType.isAssignableFrom(int.class) || optionType.isAssignableFrom(float.class) || optionType.isAssignableFrom(double.class)) { - if (optionField.isAnnotationPresent(ConfigEditorSlider.class)) { - ConfigEditorSlider configEditorAnnotation = optionField.getAnnotation(ConfigEditorSlider.class); - editor = new GuiOptionEditorSlider(option, configEditorAnnotation.minValue(), configEditorAnnotation.maxValue(), configEditorAnnotation.minStep()); - } - } - if (optionType.isAssignableFrom(String.class)) { - if (optionField.isAnnotationPresent(ConfigEditorDropdown.class)) { - ConfigEditorDropdown configEditorAnnotation = optionField.getAnnotation(ConfigEditorDropdown.class); - editor = new GuiOptionEditorDropdown(option, configEditorAnnotation.values(), 0, false); - } - } - if (editor == null) { - //System.err.printf("Failed to load config option %s. Could not find suitable editor.\n", optionField.getName()); - continue; - } - option.editor = editor; - cat.options.put(optionField.getName(), option); - } - } - } else if (exposePresent || categoryPresent) { - //System.err.printf("Failed to load config category %s. Both @Expose and @Category must be present.\n", categoryField.getName()); - } - } - return processedConfig; - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/util/GuiElementSlider.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/util/GuiElementSlider.java deleted file mode 100644 index d55c9ed23..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/util/GuiElementSlider.java +++ /dev/null @@ -1,121 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.util; - -import at.hannibal2.skyhanni.config.gui.core.GuiElement; -import at.hannibal2.skyhanni.config.gui.utils.ConfigUtils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.client.renderer.GlStateManager; -import org.lwjgl.input.Mouse; -import org.lwjgl.opengl.GL11; - -import java.util.function.Consumer; - -import static at.hannibal2.skyhanni.config.gui.GuiTextures.*; - -public class GuiElementSlider extends GuiElement { - - public int x; - public int y; - public int width; - private static final int HEIGHT = 16; - - private final float minValue; - private final float maxValue; - private final float minStep; - - private float value; - private final Consumer<Float> setCallback; - - private boolean clicked = false; - - public GuiElementSlider(int x, int y, int width, float minValue, float maxValue, float minStep, float value, Consumer<Float> setCallback) { - if (minStep < 0) minStep = 0.01f; - - this.x = x; - this.y = y; - this.width = width; - this.minValue = minValue; - this.maxValue = maxValue; - this.minStep = minStep; - this.value = value; - this.setCallback = setCallback; - } - - public void setValue(float value) { - this.value = value; - } - - @Override - public void render() { - final ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - int mouseX = Mouse.getX() * scaledResolution.getScaledWidth() / Minecraft.getMinecraft().displayWidth; - - float value = this.value; - if (clicked) { - value = (mouseX - x) * (maxValue - minValue) / width + minValue; - value = Math.max(minValue, Math.min(maxValue, value)); - value = Math.round(value / minStep) * minStep; - } - - float sliderAmount = Math.max(0, Math.min(1, (value - minValue) / (maxValue - minValue))); - int sliderAmountI = (int) (width * sliderAmount); - - GlStateManager.color(1f, 1f, 1f, 1f); - Minecraft.getMinecraft().getTextureManager().bindTexture(slider_on_cap); - ConfigUtils.drawTexturedRect(x, y, 4, HEIGHT, GL11.GL_NEAREST); - Minecraft.getMinecraft().getTextureManager().bindTexture(slider_off_cap); - ConfigUtils.drawTexturedRect(x + width - 4, y, 4, HEIGHT, GL11.GL_NEAREST); - - if (sliderAmountI > 5) { - Minecraft.getMinecraft().getTextureManager().bindTexture(slider_on_segment); - ConfigUtils.drawTexturedRect(x + 4, y, sliderAmountI - 4, HEIGHT, GL11.GL_NEAREST); - } - - if (sliderAmountI < width - 5) { - Minecraft.getMinecraft().getTextureManager().bindTexture(slider_off_segment); - ConfigUtils.drawTexturedRect(x + sliderAmountI, y, width - 4 - sliderAmountI, HEIGHT, GL11.GL_NEAREST); - } - - for (int i = 1; i < 4; i++) { - int notchX = x + width * i / 4 - 1; - Minecraft.getMinecraft().getTextureManager().bindTexture(notchX > x + sliderAmountI ? slider_off_notch : slider_on_notch); - ConfigUtils.drawTexturedRect(notchX, y + (HEIGHT - 4f) / 2, 2, 4, GL11.GL_NEAREST); - } - - Minecraft.getMinecraft().getTextureManager().bindTexture(slider_button_new); - ConfigUtils.drawTexturedRect(x + sliderAmountI - 4, y, 8, HEIGHT, GL11.GL_NEAREST); - } - - @Override - public boolean mouseInput(int mouseX, int mouseY) { - if (!Mouse.isButtonDown(0)) { - clicked = false; - } - - if (Mouse.getEventButton() == 0) { - clicked = Mouse.getEventButtonState() && mouseX > x && mouseX < x + width && mouseY > y && mouseY < y + HEIGHT; - if (clicked) { - value = (mouseX - x) * (maxValue - minValue) / width + minValue; - value = Math.max(minValue, Math.min(maxValue, value)); - value = (float) (Math.round(value / minStep) * (double) minStep); - setCallback.accept(value); - return true; - } - } - - if (!Mouse.getEventButtonState() && Mouse.getEventButton() == -1 && clicked) { - value = (mouseX - x) * (maxValue - minValue) / width + minValue; - value = Math.max(minValue, Math.min(maxValue, value)); - value = Math.round(value / minStep) * minStep; - setCallback.accept(value); - return true; - } - - return false; - } - - @Override - public boolean keyboardInput() { - return false; - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/util/StringUtils.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/util/StringUtils.java deleted file mode 100644 index ef3940dab..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/util/StringUtils.java +++ /dev/null @@ -1,8 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.util; - -public class StringUtils { - - public static String cleanColour(String in) { - return in.replaceAll("(?i)\\u00A7.", ""); - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/util/lerp/LerpUtils.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/util/lerp/LerpUtils.java deleted file mode 100644 index 33eed5222..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/util/lerp/LerpUtils.java +++ /dev/null @@ -1,25 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.util.lerp; - -public class LerpUtils { - - public static float clampZeroOne(float f) { - return Math.max(0, Math.min(1, f)); - } - - public static float sigmoid(float val) { - return (float) (1 / (1 + Math.exp(-val))); - } - - private static final float sigmoidStr = 8; - private static final float sigmoidA = -1 / (sigmoid(-0.5f * sigmoidStr) - sigmoid(0.5f * sigmoidStr)); - private static final float sigmoidB = sigmoidA * sigmoid(-0.5f * sigmoidStr); - - public static float sigmoidZeroOne(float f) { - f = clampZeroOne(f); - return sigmoidA * sigmoid(sigmoidStr * (f - 0.5f)) - sigmoidB; - } - - public static float lerp(float a, float b, float amount) { - return b + (a - b) * clampZeroOne(amount); - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/util/lerp/LerpingFloat.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/util/lerp/LerpingFloat.java deleted file mode 100644 index cd8873c59..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/util/lerp/LerpingFloat.java +++ /dev/null @@ -1,68 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.util.lerp; - -public class LerpingFloat { - - private int timeSpent; - private long lastMillis; - private final int timeToReachTarget; - - private float targetValue; - private float lerpValue; - - public LerpingFloat(float initialValue, int timeToReachTarget) { - this.targetValue = this.lerpValue = initialValue; - this.timeToReachTarget = timeToReachTarget; - } - - public LerpingFloat(int initialValue) { - this(initialValue, 200); - } - - public void tick() { - int lastTimeSpent = timeSpent; - this.timeSpent += System.currentTimeMillis() - lastMillis; - - float lastDistPercentToTarget = lastTimeSpent / (float) timeToReachTarget; - float distPercentToTarget = timeSpent / (float) timeToReachTarget; - float fac = (1 - lastDistPercentToTarget) / lastDistPercentToTarget; - - float startValue = lerpValue - (targetValue - lerpValue) / fac; - - float dist = targetValue - startValue; - if (dist == 0) return; - - float oldLerpValue = lerpValue; - if (distPercentToTarget >= 1) { - lerpValue = targetValue; - } else { - lerpValue = startValue + dist * distPercentToTarget; - } - - if (lerpValue == oldLerpValue) { - timeSpent = lastTimeSpent; - } else { - this.lastMillis = System.currentTimeMillis(); - } - } - - public void resetTimer() { - this.timeSpent = 0; - this.lastMillis = System.currentTimeMillis(); - } - - public void setTarget(float targetValue) { - this.targetValue = targetValue; - } - - public void setValue(float value) { - this.targetValue = this.lerpValue = value; - } - - public float getValue() { - return lerpValue; - } - - public float getTarget() { - return targetValue; - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/util/lerp/LerpingInteger.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/util/lerp/LerpingInteger.java deleted file mode 100644 index 22a57b4d1..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/util/lerp/LerpingInteger.java +++ /dev/null @@ -1,76 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.util.lerp; - -public class LerpingInteger { - - private int timeSpent; - private long lastMillis; - private int timeToReachTarget; - - private int targetValue; - private int lerpValue; - - public LerpingInteger(int initialValue, int timeToReachTarget) { - this.targetValue = this.lerpValue = initialValue; - this.timeToReachTarget = timeToReachTarget; - } - - public LerpingInteger(int initialValue) { - this(initialValue, 200); - } - - public void tick() { - int lastTimeSpent = timeSpent; - this.timeSpent += System.currentTimeMillis() - lastMillis; - - float lastDistPercentToTarget = lastTimeSpent / (float) timeToReachTarget; - float distPercentToTarget = timeSpent / (float) timeToReachTarget; - float fac = (1 - lastDistPercentToTarget) / lastDistPercentToTarget; - - int startValue = lerpValue - (int) ((targetValue - lerpValue) / fac); - - int dist = targetValue - startValue; - if (dist == 0) return; - - int oldLerpValue = lerpValue; - if (distPercentToTarget >= 1) { - lerpValue = targetValue; - } else { - lerpValue = startValue + (int) (dist * distPercentToTarget); - } - - if (lerpValue == oldLerpValue) { - timeSpent = lastTimeSpent; - } else { - this.lastMillis = System.currentTimeMillis(); - } - } - - public int getTimeSpent() { - return timeSpent; - } - - public void resetTimer() { - this.timeSpent = 0; - this.lastMillis = System.currentTimeMillis(); - } - - public void setTimeToReachTarget(int timeToReachTarget) { - this.timeToReachTarget = timeToReachTarget; - } - - public void setTarget(int targetValue) { - this.targetValue = targetValue; - } - - public void setValue(int value) { - this.targetValue = this.lerpValue = value; - } - - public int getValue() { - return lerpValue; - } - - public int getTarget() { - return targetValue; - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/util/render/RenderUtils.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/util/render/RenderUtils.java deleted file mode 100644 index 7e466cd99..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/util/render/RenderUtils.java +++ /dev/null @@ -1,155 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.util.render; - -import at.hannibal2.skyhanni.config.gui.core.BackgroundBlur; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.OpenGlHelper; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.WorldRenderer; -import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL14; - -public class RenderUtils { - - public static void drawFloatingRectDark(int x, int y, int width, int height) { - drawFloatingRectDark(x, y, width, height, true); - } - - public static void drawFloatingRectDark(int x, int y, int width, int height, boolean shadow) { - int alpha = 0xf0000000; - - if (OpenGlHelper.isFramebufferEnabled()) { - ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - BackgroundBlur.renderBlurredBackground(15, scaledResolution.getScaledWidth(), scaledResolution.getScaledHeight(), x, y, width, height, true); - } else { - alpha = 0xff000000; - } - - int main = alpha | 0x202026; - int light = 0xff303036; - int dark = 0xff101016; - Gui.drawRect(x, y, x + 1, y + height, light); //Left - Gui.drawRect(x + 1, y, x + width, y + 1, light); //Top - Gui.drawRect(x + width - 1, y + 1, x + width, y + height, dark); //Right - Gui.drawRect(x + 1, y + height - 1, x + width - 1, y + height, dark); //Bottom - Gui.drawRect(x + 1, y + 1, x + width - 1, y + height - 1, main); //Middle - if (shadow) { - Gui.drawRect(x + width, y + 2, x + width + 2, y + height + 2, 0x70000000); //Right shadow - Gui.drawRect(x + 2, y + height, x + width, y + height + 2, 0x70000000); //Bottom shadow - } - } - - public static void drawFloatingRect(int x, int y, int width, int height) { - drawFloatingRectWithAlpha(x, y, width, height, 0xFF, true); - } - - public static void drawFloatingRectWithAlpha(int x, int y, int width, int height, int alpha, boolean shadow) { - int main = (alpha << 24) | 0xc0c0c0; - int light = (alpha << 24) | 0xf0f0f0; - int dark = (alpha << 24) | 0x909090; - Gui.drawRect(x, y, x + 1, y + height, light); //Left - Gui.drawRect(x + 1, y, x + width, y + 1, light); //Top - Gui.drawRect(x + width - 1, y + 1, x + width, y + height, dark); //Right - Gui.drawRect(x + 1, y + height - 1, x + width - 1, y + height, dark); //Bottom - Gui.drawRect(x + 1, y + 1, x + width - 1, y + height - 1, main); //Middle - if (shadow) { - Gui.drawRect(x + width, y + 2, x + width + 2, y + height + 2, (alpha * 3 / 5) << 24); //Right shadow - Gui.drawRect(x + 2, y + height, x + width, y + height + 2, (alpha * 3 / 5) << 24); //Bottom shadow - } - } - - public static void drawTexturedModalRect(int x, int y, int textureX, int textureY, int width, int height) { - double f = 0.00390625; - double f1 = 0.00390625; - Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldrenderer = tessellator.getWorldRenderer(); - worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX); - worldrenderer.pos(x + 0.0, y + height, 0.0).tex((textureX + 0.0) * f, (textureY + height) * f1).endVertex(); - worldrenderer.pos(x + width, y + height, 0.0).tex((textureX + width) * f, (textureY + height) * f1).endVertex(); - worldrenderer.pos(x + width, y + 0.0, 0.0).tex((textureX + width) * f, (textureY + 0.0) * f1).endVertex(); - worldrenderer.pos(x + 0.0, y + 0.0, 0.0).tex((textureX + 0.0) * f, (textureY + 0.0) * f1).endVertex(); - tessellator.draw(); - } - - public static void drawTexturedRect(float x, float y, float width, float height) { - drawTexturedRect(x, y, width, height, 0, 1, 0, 1); - } - - public static void drawTexturedRect(float x, float y, float width, float height, int filter) { - drawTexturedRect(x, y, width, height, 0, 1, 0, 1, filter); - } - - public static void drawTexturedRect(float x, float y, float width, float height, float uMin, float uMax, float vMin, float vMax) { - drawTexturedRect(x, y, width, height, uMin, uMax, vMin, vMax, GL11.GL_NEAREST); - } - - public static void drawTexturedRect(float x, float y, float width, float height, float uMin, float uMax, float vMin, float vMax, int filter) { - GlStateManager.enableBlend(); - GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); - - drawTexturedRectNoBlend(x, y, width, height, uMin, uMax, vMin, vMax, filter); - - GlStateManager.disableBlend(); - } - - public static void drawTexturedRectNoBlend(float x, float y, float width, float height, float uMin, float uMax, float vMin, float vMax, int filter) { - GlStateManager.enableTexture2D(); - - GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, filter); - GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, filter); - - Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldrenderer = tessellator.getWorldRenderer(); - worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX); - worldrenderer.pos(x, y + height, 0.0D).tex(uMin, vMax).endVertex(); - worldrenderer.pos(x + width, y + height, 0.0D).tex(uMax, vMax).endVertex(); - worldrenderer.pos(x + width, y, 0.0D).tex(uMax, vMin).endVertex(); - worldrenderer.pos(x, y, 0.0D).tex(uMin, vMin).endVertex(); - tessellator.draw(); - - GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); - GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); - } - - public static void drawGradientRect(int zLevel, int left, int top, int right, int bottom, int startColor, int endColor) { - float startAlpha = (float) (startColor >> 24 & 255) / 255.0F; - float startRed = (float) (startColor >> 16 & 255) / 255.0F; - float startGreen = (float) (startColor >> 8 & 255) / 255.0F; - float startBlue = (float) (startColor & 255) / 255.0F; - float endAlpha = (float) (endColor >> 24 & 255) / 255.0F; - float endRed = (float) (endColor >> 16 & 255) / 255.0F; - float endGreen = (float) (endColor >> 8 & 255) / 255.0F; - float endBlue = (float) (endColor & 255) / 255.0F; - - GlStateManager.disableTexture2D(); - GlStateManager.enableBlend(); - GlStateManager.disableAlpha(); - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); - GlStateManager.shadeModel(7425); - - Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldrenderer = tessellator.getWorldRenderer(); - worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR); - worldrenderer.pos(right, top, zLevel).color(startRed, startGreen, startBlue, startAlpha).endVertex(); - worldrenderer.pos(left, top, zLevel).color(startRed, startGreen, startBlue, startAlpha).endVertex(); - worldrenderer.pos(left, bottom, zLevel).color(endRed, endGreen, endBlue, endAlpha).endVertex(); - worldrenderer.pos(right, bottom, zLevel).color(endRed, endGreen, endBlue, endAlpha).endVertex(); - tessellator.draw(); - - GlStateManager.shadeModel(7424); - GlStateManager.disableBlend(); - GlStateManager.enableAlpha(); - GlStateManager.enableTexture2D(); - } - - public static void drawInnerBox(int left, int top, int width, int height) { - Gui.drawRect(left, top, left + width, top + height, 0x6008080E); //Middle - Gui.drawRect(left, top, left + 1, top + height, 0xff08080E); //Left - Gui.drawRect(left, top, left + width, top + 1, 0xff08080E); //Top - Gui.drawRect(left + width - 1, top, left + width, top + height, 0xff28282E); //Right - Gui.drawRect(left, top + height - 1, left + width, top + height, 0xff28282E); //Bottom - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/util/render/TextRenderUtils.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/util/render/TextRenderUtils.java deleted file mode 100644 index c40db66b4..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/util/render/TextRenderUtils.java +++ /dev/null @@ -1,155 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.core.util.render; - -import java.util.ArrayList; -import java.util.List; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.RenderHelper; - -public class TextRenderUtils { - - public static int getCharVertLen(char c) { - if ("acegmnopqrsuvwxyz".indexOf(c) >= 0) { - return 5; - } else { - return 7; - } - } - - public static void drawStringScaledMaxWidth(String str, FontRenderer fr, float x, float y, boolean shadow, int len, int colour) { - int strLen = fr.getStringWidth(str); - float factor = len / (float) strLen; - factor = Math.min(1, factor); - - drawStringScaled(str, fr, x, y, shadow, colour, factor); - } - - public static void drawStringScaled(String str, FontRenderer fr, float x, float y, boolean shadow, int colour, float factor) { - GlStateManager.scale(factor, factor, 1); - fr.drawString(str, x / factor, y / factor, colour, shadow); - GlStateManager.scale(1 / factor, 1 / factor, 1); - } - - public static void drawStringCenteredScaledMaxWidth(String str, FontRenderer fr, float x, float y, boolean shadow, int len, int colour) { - int strLen = fr.getStringWidth(str); - float factor = len / (float) strLen; - factor = Math.min(1, factor); - int newLen = Math.min(strLen, len); - - float fontHeight = 8 * factor; - - drawStringScaled(str, fr, x - newLen / 2, y - fontHeight / 2, shadow, colour, factor); - } - - public static void drawHoveringText(List<String> textLines, final int mouseX, final int mouseY, final int screenWidth, final int screenHeight, final int maxTextWidth, FontRenderer font) { - if (!textLines.isEmpty()) { - GlStateManager.disableRescaleNormal(); - RenderHelper.disableStandardItemLighting(); - GlStateManager.disableLighting(); - GlStateManager.disableDepth(); - int tooltipTextWidth = 0; - - for (String textLine : textLines) { - int textLineWidth = font.getStringWidth(textLine); - - if (textLineWidth > tooltipTextWidth) { - tooltipTextWidth = textLineWidth; - } - } - - boolean needsWrap = false; - - int titleLinesCount = 1; - int tooltipX = mouseX + 12; - if (tooltipX + tooltipTextWidth + 4 > screenWidth) { - tooltipX = mouseX - 16 - tooltipTextWidth; - if (tooltipX < 4) { // if the tooltip doesn't fit on the screen - if (mouseX > screenWidth / 2) { - tooltipTextWidth = mouseX - 12 - 8; - } else { - tooltipTextWidth = screenWidth - 16 - mouseX; - } - needsWrap = true; - } - } - - if (maxTextWidth > 0 && tooltipTextWidth > maxTextWidth) { - tooltipTextWidth = maxTextWidth; - needsWrap = true; - } - - if (needsWrap) { - int wrappedTooltipWidth = 0; - List<String> wrappedTextLines = new ArrayList<String>(); - for (int i = 0; i < textLines.size(); i++) { - String textLine = textLines.get(i); - List<String> wrappedLine = font.listFormattedStringToWidth(textLine, tooltipTextWidth); - if (i == 0) { - titleLinesCount = wrappedLine.size(); - } - - for (String line : wrappedLine) { - int lineWidth = font.getStringWidth(line); - if (lineWidth > wrappedTooltipWidth) { - wrappedTooltipWidth = lineWidth; - } - wrappedTextLines.add(line); - } - } - tooltipTextWidth = wrappedTooltipWidth; - textLines = wrappedTextLines; - - if (mouseX > screenWidth / 2) { - tooltipX = mouseX - 16 - tooltipTextWidth; - } else { - tooltipX = mouseX + 12; - } - } - - int tooltipY = mouseY - 12; - int tooltipHeight = 8; - - if (textLines.size() > 1) { - tooltipHeight += (textLines.size() - 1) * 10; - if (textLines.size() > titleLinesCount) { - tooltipHeight += 2; // gap between title lines and next lines - } - } - - if (tooltipY + tooltipHeight + 6 > screenHeight) { - tooltipY = screenHeight - tooltipHeight - 6; - } - - final int zLevel = 300; - final int backgroundColor = 0xF0100010; - RenderUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY - 4, tooltipX + tooltipTextWidth + 3, tooltipY - 3, backgroundColor, backgroundColor); - RenderUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY + tooltipHeight + 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 4, backgroundColor, backgroundColor); - RenderUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor); - RenderUtils.drawGradientRect(zLevel, tooltipX - 4, tooltipY - 3, tooltipX - 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor); - RenderUtils.drawGradientRect(zLevel, tooltipX + tooltipTextWidth + 3, tooltipY - 3, tooltipX + tooltipTextWidth + 4, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor); - final int borderColorStart = 0x505000FF; - final int borderColorEnd = (borderColorStart & 0xFEFEFE) >> 1 | borderColorStart & 0xFF000000; - RenderUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3 + 1, tooltipX - 3 + 1, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd); - RenderUtils.drawGradientRect(zLevel, tooltipX + tooltipTextWidth + 2, tooltipY - 3 + 1, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd); - RenderUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY - 3 + 1, borderColorStart, borderColorStart); - RenderUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY + tooltipHeight + 2, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, borderColorEnd, borderColorEnd); - - for (int lineNumber = 0; lineNumber < textLines.size(); ++lineNumber) { - String line = textLines.get(lineNumber); - font.drawStringWithShadow(line, (float) tooltipX, (float) tooltipY, -1); - - if (lineNumber + 1 == titleLinesCount) { - tooltipY += 2; - } - - tooltipY += 10; - } - - GlStateManager.enableLighting(); - GlStateManager.enableDepth(); - RenderHelper.enableStandardItemLighting(); - GlStateManager.enableRescaleNormal(); - } - GlStateManager.disableLighting(); - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/textures/TextureObject.java b/src/main/java/at/hannibal2/skyhanni/config/gui/textures/TextureObject.java deleted file mode 100644 index 8d7832da3..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/textures/TextureObject.java +++ /dev/null @@ -1,37 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.textures; - -import com.google.gson.JsonObject; -import java.util.Arrays; -import net.minecraft.util.ResourceLocation; - -public class TextureObject { - - public String displayName; - public ResourceLocation bars = resource("bars.png"); - public ResourceLocation mines = resource("mines.png"); - public ResourceLocation playerStats = resource("playerstats.png"); - public ResourceLocation stats = resource("stats.png"); - public ResourceLocation dungeon = resource("dungeon.png"); - public ResourceLocation dialogue = resource("dialogue.png"); - - public TextureObject(String displayName) { - this.displayName = displayName; - } - - public static TextureObject decode(JsonObject json) { - TextureObject textureObject = new TextureObject(json.get("displayName").getAsString()); - Arrays - .stream(textureObject.getClass().getDeclaredFields()) - .filter(field -> field.getType().equals(ResourceLocation.class)) - .forEach(field -> { - try { - field.set(textureObject, new ResourceLocation(json.get(field.getName()).getAsString())); - } catch (Exception ignored) {} - }); - return textureObject; - } - - private static ResourceLocation resource(String path) { - return new ResourceLocation("skyhanni", path); - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/textures/Textures.java b/src/main/java/at/hannibal2/skyhanni/config/gui/textures/Textures.java deleted file mode 100644 index 9f34b435c..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/textures/Textures.java +++ /dev/null @@ -1,54 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.textures; - -import com.google.common.collect.Lists; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.List; -import net.minecraft.client.resources.IResource; -import net.minecraft.client.resources.IResourceManager; -import net.minecraft.client.resources.IResourceManagerReloadListener; -import net.minecraft.util.ResourceLocation; - -public class Textures implements IResourceManagerReloadListener { - - private static final TextureObject DEFAULT_TEXTURE = new TextureObject("Default"); - - private static final Gson gson = new GsonBuilder().create(); - public static final List<TextureObject> styles = Lists.newArrayList(DEFAULT_TEXTURE); - public static TextureObject texture = DEFAULT_TEXTURE; - - public static void setTexture(int selected) { - if (selected >= styles.size() || selected < 0) { - texture = DEFAULT_TEXTURE; - } else { - texture = styles.get(selected); - } - } - - @Override - public void onResourceManagerReload(IResourceManager resourceManager) { - styles.clear(); - styles.add(DEFAULT_TEXTURE); - DEFAULT_TEXTURE.displayName = "Default"; - try { - ResourceLocation stylesData = new ResourceLocation("skyhanni:data/styles.json"); - - for (IResource resource : resourceManager.getAllResources(stylesData)) { - try (BufferedReader reader = new BufferedReader(new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8))) { - JsonObject jsonObject = gson.fromJson(reader, JsonObject.class); - for (JsonElement json : jsonObject.getAsJsonArray("styles")) { - styles.add(TextureObject.decode((JsonObject) json)); - } - if (DEFAULT_TEXTURE.displayName.equals("Default") && jsonObject.has("defaultDisplayName") && jsonObject.get("defaultDisplayName").isJsonPrimitive()) { - DEFAULT_TEXTURE.displayName = jsonObject.get("defaultDisplayName").getAsString(); - } - } - } - } catch (Exception ignored) {} - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/utils/ConfigUtils.java b/src/main/java/at/hannibal2/skyhanni/config/gui/utils/ConfigUtils.java deleted file mode 100644 index 4d733b3da..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/utils/ConfigUtils.java +++ /dev/null @@ -1,314 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.utils; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.WorldRenderer; -import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import net.minecraft.entity.Entity; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.BlockPos; -import net.minecraft.util.EnumChatFormatting; -import net.minecraftforge.client.event.RenderGameOverlayEvent; -import net.minecraftforge.fml.common.Loader; -import org.lwjgl.BufferUtils; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL14; - -import java.math.RoundingMode; -import java.nio.FloatBuffer; -import java.text.DecimalFormat; -import java.text.DecimalFormatSymbols; -import java.util.LinkedList; -import java.util.Locale; - -public class ConfigUtils { - - private static final LinkedList<Integer> guiScales = new LinkedList<>(); - private static ScaledResolution lastScale = new ScaledResolution(Minecraft.getMinecraft()); - //Labymod compatibility - private static final FloatBuffer projectionMatrixOld = BufferUtils.createFloatBuffer(16); - private static final FloatBuffer modelviewMatrixOld = BufferUtils.createFloatBuffer(16); - - public static String removeColor(String input) { - return input.replaceAll("(?i)\\u00A7.", ""); - } - - public static String removeWhiteSpaceAndRemoveWord(String input, String replace) { - return input.toLowerCase().replace(" ", "").replace(replace, ""); - } - - public static boolean inRangeInclusive(int value, int min, int max) { - return value <= max && value >= min; - } - - public static float lerp(float f, float g, float h) { - return g + f * (h - g); - } - - public static double lerp(double d, double e, double f) { - return e + d * (f - e); - } - - public static int lerp(float f, int g, int h) { - return (int) (g + f * (h - g)); - } - - public static NBTTagCompound getSkyBlockTag(ItemStack stack) { - if (stack == null) return null; - if (!stack.hasTagCompound()) return null; - if (!stack.getTagCompound().hasKey("ExtraAttributes")) return null; - return stack.getTagCompound().getCompoundTag("ExtraAttributes"); - } - - public static boolean isDrill(ItemStack stack) { - NBTTagCompound tag = getSkyBlockTag(stack); - return tag != null && tag.hasKey("drill_fuel"); - } - - public static boolean overlayShouldRender(RenderGameOverlayEvent.ElementType type, boolean... booleans) { - return overlayShouldRender(false, type, RenderGameOverlayEvent.ElementType.HOTBAR, booleans); - } - - public static boolean overlayShouldRender(boolean hideOnf3, RenderGameOverlayEvent.ElementType type, RenderGameOverlayEvent.ElementType checkType, boolean... booleans) { - Minecraft mc = Minecraft.getMinecraft(); - for (boolean aBoolean : booleans) if (!aBoolean) return false; - if (hideOnf3) { - if (mc.gameSettings.showDebugInfo || (mc.gameSettings.keyBindPlayerList.isKeyDown() && (!mc.isIntegratedServerRunning() || mc.thePlayer.sendQueue.getPlayerInfoMap().size() > 1))) { - return false; - } - } - return ((type == null && Loader.isModLoaded("labymod")) || type == checkType); - } - - public static void drawStringScaledMaxWidth(String str, FontRenderer fr, float x, float y, boolean shadow, int len, int colour) { - int strLen = fr.getStringWidth(str); - float factor = len / (float) strLen; - factor = Math.min(1, factor); - - drawStringScaled(str, fr, x, y, shadow, colour, factor); - } - - public static void drawStringScaled(String str, FontRenderer fr, float x, float y, boolean shadow, int colour, float factor) { - GlStateManager.scale(factor, factor, 1); - fr.drawString(str, x / factor, y / factor, colour, shadow); - GlStateManager.scale(1 / factor, 1 / factor, 1); - } - - public static void drawStringCenteredScaled(String str, FontRenderer fr, float x, float y, boolean shadow, int len, int colour) { - int strLen = fr.getStringWidth(str); - float factor = len / (float) strLen; - float fontHeight = 8 * factor; - - drawStringScaled(str, fr, x - len / 2f, y - fontHeight / 2f, shadow, colour, factor); - } - - public static void drawTexturedRect(float x, float y, float width, float height, float uMin, float uMax, float vMin, float vMax, int filter) { - GlStateManager.enableTexture2D(); - GlStateManager.enableBlend(); - GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); - - GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, filter); - GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, filter); - - Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldrenderer = tessellator.getWorldRenderer(); - worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX); - worldrenderer.pos(x, y + height, 0.0D).tex(uMin, vMax).endVertex(); - worldrenderer.pos(x + width, y + height, 0.0D).tex(uMax, vMax).endVertex(); - worldrenderer.pos(x + width, y, 0.0D).tex(uMax, vMin).endVertex(); - worldrenderer.pos(x, y, 0.0D).tex(uMin, vMin).endVertex(); - tessellator.draw(); - - GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); - GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); - - GlStateManager.disableBlend(); - } - - public static void drawTexturedRect(float x, float y, float width, float height) { - drawTexturedRect(x, y, width, height, 0, 1, 0, 1); - } - - public static void drawTexturedRect(float x, float y, float width, float height, int filter) { - drawTexturedRect(x, y, width, height, 0, 1, 0, 1, filter); - } - - public static void drawTexturedRect(float x, float y, float width, float height, float uMin, float uMax, float vMin, float vMax) { - drawTexturedRect(x, y, width, height, uMin, uMax, vMin, vMax, GL11.GL_LINEAR); - } - - public static void resetGuiScale() { - guiScales.clear(); - } - - public static ScaledResolution peekGuiScale() { - return lastScale; - } - - public static ScaledResolution pushGuiScale(int scale) { - if (guiScales.size() == 0) { - if (Loader.isModLoaded("labymod")) { - GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, projectionMatrixOld); - GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modelviewMatrixOld); - } - } - - if (scale < 0) { - if (guiScales.size() > 0) { - guiScales.pop(); - } - } else { - if (scale == 0) { - guiScales.push(Minecraft.getMinecraft().gameSettings.guiScale); - } else { - guiScales.push(scale); - } - } - - int newScale = guiScales.size() > 0 ? Math.max(0, Math.min(4, guiScales.peek())) : Minecraft.getMinecraft().gameSettings.guiScale; - if (newScale == 0) newScale = Minecraft.getMinecraft().gameSettings.guiScale; - - int oldScale = Minecraft.getMinecraft().gameSettings.guiScale; - Minecraft.getMinecraft().gameSettings.guiScale = newScale; - ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); - Minecraft.getMinecraft().gameSettings.guiScale = oldScale; - - if (guiScales.size() > 0) { - GlStateManager.viewport(0, 0, Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight); - GlStateManager.matrixMode(GL11.GL_PROJECTION); - GlStateManager.loadIdentity(); - GlStateManager.ortho(0.0D, scaledresolution.getScaledWidth_double(), scaledresolution.getScaledHeight_double(), 0.0D, 1000.0D, 3000.0D); - GlStateManager.matrixMode(GL11.GL_MODELVIEW); - GlStateManager.loadIdentity(); - GlStateManager.translate(0.0F, 0.0F, -2000.0F); - } else { - if (Loader.isModLoaded("labymod") && projectionMatrixOld.limit() > 0 && modelviewMatrixOld.limit() > 0) { - GlStateManager.matrixMode(GL11.GL_PROJECTION); - GL11.glLoadMatrix(projectionMatrixOld); - GlStateManager.matrixMode(GL11.GL_MODELVIEW); - GL11.glLoadMatrix(modelviewMatrixOld); - } else { - GlStateManager.matrixMode(GL11.GL_PROJECTION); - GlStateManager.loadIdentity(); - GlStateManager.ortho(0.0D, scaledresolution.getScaledWidth_double(), scaledresolution.getScaledHeight_double(), 0.0D, 1000.0D, 3000.0D); - GlStateManager.matrixMode(GL11.GL_MODELVIEW); - GlStateManager.loadIdentity(); - GlStateManager.translate(0.0F, 0.0F, -2000.0F); - } - } - - lastScale = scaledresolution; - return scaledresolution; - } - - public static void drawStringCentered(String str, FontRenderer fr, float x, float y, boolean shadow, int colour) { - int strLen = fr.getStringWidth(str); - - float x2 = x - strLen / 2f; - float y2 = y - fr.FONT_HEIGHT / 2f; - - GL11.glTranslatef(x2, y2, 0); - fr.drawString(str, 0, 0, colour, shadow); - GL11.glTranslatef(-x2, -y2, 0); - } - - public static void renderWaypointText(String str, BlockPos loc, float partialTicks) { - GlStateManager.alphaFunc(516, 0.1F); - - GlStateManager.pushMatrix(); - - Entity viewer = Minecraft.getMinecraft().getRenderViewEntity(); - double viewerX = viewer.lastTickPosX + (viewer.posX - viewer.lastTickPosX) * partialTicks; - double viewerY = viewer.lastTickPosY + (viewer.posY - viewer.lastTickPosY) * partialTicks; - double viewerZ = viewer.lastTickPosZ + (viewer.posZ - viewer.lastTickPosZ) * partialTicks; - - double x = loc.getX() - viewerX; - double y = loc.getY() - viewerY - viewer.getEyeHeight(); - double z = loc.getZ() - viewerZ; - - double distSq = x * x + y * y + z * z; - double dist = Math.sqrt(distSq); - if (distSq > 144) { - x *= 12 / dist; - y *= 12 / dist; - z *= 12 / dist; - } - GlStateManager.translate(x, y, z); - GlStateManager.translate(0, viewer.getEyeHeight(), 0); - - drawNametag(str); - - GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F); - GlStateManager.rotate(Minecraft.getMinecraft().getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F); - GlStateManager.translate(0, -0.25f, 0); - GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F); - GlStateManager.rotate(Minecraft.getMinecraft().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F); - - drawNametag(EnumChatFormatting.YELLOW.toString() + Math.round(dist) + "m"); - - GlStateManager.popMatrix(); - - GlStateManager.disableLighting(); - } - - public static void drawNametag(String str) { - FontRenderer fontrenderer = Minecraft.getMinecraft().fontRendererObj; - float f = 1.6F; - float f1 = 0.016666668F * f; - GlStateManager.pushMatrix(); - GL11.glNormal3f(0.0F, 1.0F, 0.0F); - GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F); - GlStateManager.rotate(Minecraft.getMinecraft().getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F); - GlStateManager.scale(-f1, -f1, f1); - GlStateManager.disableLighting(); - GlStateManager.depthMask(false); - GlStateManager.disableDepth(); - GlStateManager.enableBlend(); - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); - Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldrenderer = tessellator.getWorldRenderer(); - int i = 0; - - int j = fontrenderer.getStringWidth(str) / 2; - GlStateManager.disableTexture2D(); - worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR); - worldrenderer.pos(-j - 1, -1 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); - worldrenderer.pos(-j - 1, 8 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); - worldrenderer.pos(j + 1, 8 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); - worldrenderer.pos(j + 1, -1 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); - tessellator.draw(); - GlStateManager.enableTexture2D(); - fontrenderer.drawString(str, -fontrenderer.getStringWidth(str) / 2, i, 553648127); - GlStateManager.depthMask(true); - - fontrenderer.drawString(str, -fontrenderer.getStringWidth(str) / 2, i, -1); - - GlStateManager.enableDepth(); - GlStateManager.enableBlend(); - GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - GlStateManager.popMatrix(); - } - - public static String formattedNumber(int number, int numberToFormatAt) { - DecimalFormat formatter = new DecimalFormat("#.#", DecimalFormatSymbols.getInstance(Locale.CANADA)); - formatter.setRoundingMode(RoundingMode.FLOOR); - return number > numberToFormatAt - 1 ? formatter.format((double) number / 1000) + "k" : String.valueOf(number); - } - - public static boolean equalsIgnoreCaseAnyOf(String string, String... strings) { - for (String o : strings) if (string.equalsIgnoreCase(o)) return true; - return false; - } - - public static String getItemCustomId(ItemStack stack) { - if (stack == null) return null; - if (!stack.hasTagCompound()) return null; - if (!stack.getTagCompound().hasKey("ExtraAttributes")) return null; - if (!stack.getTagCompound().getCompoundTag("ExtraAttributes").hasKey("id")) return null; - return stack.getTagCompound().getCompoundTag("ExtraAttributes").getString("id"); - } -} |