diff options
| author | Lorenz <ESs95s3P5z8Pheb> | 2022-07-14 11:28:50 +0200 |
|---|---|---|
| committer | Lorenz <ESs95s3P5z8Pheb> | 2022-07-14 11:28:50 +0200 |
| commit | 360d67f1f1d6c66f9b3a1f90b463b27a250908f3 (patch) | |
| tree | 92f5f8aff5bbbde1a98bfaa6ab794ec91965cc1e /src/main/java/at | |
| parent | a2758997c387735a4e852cb9f25d651244b8bc75 (diff) | |
| download | SkyHanni-360d67f1f1d6c66f9b3a1f90b463b27a250908f3.tar.gz SkyHanni-360d67f1f1d6c66f9b3a1f90b463b27a250908f3.tar.bz2 SkyHanni-360d67f1f1d6c66f9b3a1f90b463b27a250908f3.zip | |
changed packages
Diffstat (limited to 'src/main/java/at')
55 files changed, 5144 insertions, 10 deletions
diff --git a/src/main/java/at/lorenz/mod/LorenzMod.java b/src/main/java/at/lorenz/mod/LorenzMod.java index c9a8486db..9e840f9e8 100644 --- a/src/main/java/at/lorenz/mod/LorenzMod.java +++ b/src/main/java/at/lorenz/mod/LorenzMod.java @@ -15,7 +15,7 @@ import at.lorenz.mod.misc.*; import at.lorenz.mod.test.LorenzTest; import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import com.thatgravyboat.amod.commands.Commands; +import at.lorenz.mod.config.commands.Commands; import java.io.*; import java.nio.charset.StandardCharsets; import net.minecraft.client.Minecraft; diff --git a/src/main/java/at/lorenz/mod/config/Features.java b/src/main/java/at/lorenz/mod/config/Features.java index 9cb5d9450..4dc65baa7 100644 --- a/src/main/java/at/lorenz/mod/config/Features.java +++ b/src/main/java/at/lorenz/mod/config/Features.java @@ -2,12 +2,12 @@ package at.lorenz.mod.config; import at.lorenz.mod.LorenzMod; import com.google.gson.annotations.Expose; -import com.thatgravyboat.amod.config.ConfigEditor; -import com.thatgravyboat.amod.core.GuiElement; -import com.thatgravyboat.amod.core.GuiScreenElementWrapper; -import com.thatgravyboat.amod.core.config.Position; -import com.thatgravyboat.amod.core.config.annotations.*; -import com.thatgravyboat.amod.core.config.gui.GuiPositionEditor; +import at.lorenz.mod.config.config.ConfigEditor; +import at.lorenz.mod.config.core.GuiElement; +import at.lorenz.mod.config.core.GuiScreenElementWrapper; +import at.lorenz.mod.config.core.config.Position; +import at.lorenz.mod.config.core.config.annotations.*; +import at.lorenz.mod.config.core.config.gui.GuiPositionEditor; import net.minecraft.client.Minecraft; public class Features { diff --git a/src/main/java/at/lorenz/mod/config/GuiTextures.java b/src/main/java/at/lorenz/mod/config/GuiTextures.java new file mode 100644 index 000000000..e24f1879d --- /dev/null +++ b/src/main/java/at/lorenz/mod/config/GuiTextures.java @@ -0,0 +1,32 @@ +package at.lorenz.mod.config; + +import net.minecraft.util.ResourceLocation; + +public class GuiTextures { + + private GuiTextures() {} + + public static final ResourceLocation DISCORD = new ResourceLocation("lorenzmod:discord.png"); + + public static final ResourceLocation button_tex = new ResourceLocation("lorenzmod:button.png"); + + public static final ResourceLocation button_white = new ResourceLocation("lorenzmod:button_white.png"); + + public static final ResourceLocation BAR = new ResourceLocation("lorenzmod:core/bar.png"); + public static final ResourceLocation OFF = new ResourceLocation("lorenzmod:core/toggle_off.png"); + public static final ResourceLocation ONE = new ResourceLocation("lorenzmod:core/toggle_1.png"); + public static final ResourceLocation TWO = new ResourceLocation("lorenzmod:core/toggle_2.png"); + public static final ResourceLocation THREE = new ResourceLocation("lorenzmod:core/toggle_3.png"); + public static final ResourceLocation ON = new ResourceLocation("lorenzmod:core/toggle_on.png"); + public static final ResourceLocation DELETE = new ResourceLocation("lorenzmod:core/delete.png"); + + public static final ResourceLocation slider_off_cap = new ResourceLocation("lorenzmod:core/slider/slider_off_cap.png"); + public static final ResourceLocation slider_off_notch = new ResourceLocation("lorenzmod:core/slider/slider_off_notch.png"); + public static final ResourceLocation slider_off_segment = new ResourceLocation("lorenzmod:core/slider/slider_off_segment.png"); + public static final ResourceLocation slider_on_cap = new ResourceLocation("lorenzmod:core/slider/slider_on_cap.png"); + public static final ResourceLocation slider_on_notch = new ResourceLocation("lorenzmod:core/slider/slider_on_notch.png"); + public static final ResourceLocation slider_on_segment = new ResourceLocation("lorenzmod:core/slider/slider_on_segment.png"); + public static final ResourceLocation slider_button_new = new ResourceLocation("lorenzmod:core/slider/slider_button.png"); + + public static final ResourceLocation mapOverlay = new ResourceLocation("lorenzmod", "maps/map_overlay.png"); +} diff --git a/src/main/java/at/lorenz/mod/config/commands/Commands.java b/src/main/java/at/lorenz/mod/config/commands/Commands.java new file mode 100644 index 000000000..05963ead6 --- /dev/null +++ b/src/main/java/at/lorenz/mod/config/commands/Commands.java @@ -0,0 +1,31 @@ +package at.lorenz.mod.config.commands; + +import at.lorenz.mod.LorenzMod; +import at.lorenz.mod.config.config.ConfigEditor; +import at.lorenz.mod.config.core.GuiScreenElementWrapper; +import net.minecraft.command.ICommandSender; +import net.minecraftforge.client.ClientCommandHandler; +import org.apache.commons.lang3.StringUtils; + +public class Commands { + + private static final boolean devMode = false; + + private static final SimpleCommand.ProcessCommandRunnable settingsRunnable = new SimpleCommand.ProcessCommandRunnable() { + public void processCommand(ICommandSender sender, String[] args) { + if (args.length > 0) { + LorenzMod.screenToOpen = new GuiScreenElementWrapper(new ConfigEditor(LorenzMod.feature, StringUtils.join(args, " "))); + } else { + LorenzMod.screenToOpen = new GuiScreenElementWrapper(new ConfigEditor(LorenzMod.feature)); + } + } + }; + + private static final SimpleCommand settingsCommand = new SimpleCommand("lm", settingsRunnable); + private static final SimpleCommand settingsCommand2 = new SimpleCommand("lorenzmod", settingsRunnable); + + public static void init() { + ClientCommandHandler.instance.registerCommand(settingsCommand); + ClientCommandHandler.instance.registerCommand(settingsCommand2); + } +} diff --git a/src/main/java/at/lorenz/mod/config/commands/SimpleCommand.java b/src/main/java/at/lorenz/mod/config/commands/SimpleCommand.java new file mode 100644 index 000000000..170080a59 --- /dev/null +++ b/src/main/java/at/lorenz/mod/config/commands/SimpleCommand.java @@ -0,0 +1,60 @@ +package at.lorenz.mod.config.commands; + +import java.util.List; +import net.minecraft.command.CommandBase; +import net.minecraft.command.ICommandSender; +import net.minecraft.util.BlockPos; + +/** + @author Moulberry + **/ +public class SimpleCommand extends CommandBase { + + private final String commandName; + private final ProcessCommandRunnable runnable; + private TabCompleteRunnable tabRunnable; + + public SimpleCommand(String commandName, ProcessCommandRunnable runnable) { + this.commandName = commandName; + this.runnable = runnable; + } + + public SimpleCommand(String commandName, ProcessCommandRunnable runnable, TabCompleteRunnable tabRunnable) { + this.commandName = commandName; + this.runnable = runnable; + this.tabRunnable = tabRunnable; + } + + public abstract static class ProcessCommandRunnable { + + public abstract void processCommand(ICommandSender sender, String[] args); + } + + public abstract static class TabCompleteRunnable { + + public abstract List<String> tabComplete(ICommandSender sender, String[] args, BlockPos pos); + } + + public boolean canCommandSenderUseCommand(ICommandSender sender) { + return true; + } + + public String getCommandName() { + return commandName; + } + + public String getCommandUsage(ICommandSender sender) { + return "/" + commandName; + } + + @Override + public void processCommand(ICommandSender sender, String[] args) { + runnable.processCommand(sender, args); + } + + @Override + public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos) { + if (tabRunnable != null) return tabRunnable.tabComplete(sender, args, pos); + return null; + } +} diff --git a/src/main/java/at/lorenz/mod/config/config/ConfigEditor.java b/src/main/java/at/lorenz/mod/config/config/ConfigEditor.java new file mode 100644 index 000000000..cee1846b5 --- /dev/null +++ b/src/main/java/at/lorenz/mod/config/config/ConfigEditor.java @@ -0,0 +1,602 @@ +package at.lorenz.mod.config.config; + +import static at.lorenz.mod.config.GuiTextures.DISCORD; + +import at.lorenz.mod.LorenzMod; +import at.lorenz.mod.config.Features; +import com.google.common.collect.Lists; +import at.lorenz.mod.config.core.GlScissorStack; +import at.lorenz.mod.config.core.GuiElement; +import at.lorenz.mod.config.core.config.gui.GuiOptionEditor; +import at.lorenz.mod.config.core.config.gui.GuiOptionEditorAccordion; +import at.lorenz.mod.config.core.config.struct.ConfigProcessor; +import at.lorenz.mod.config.core.util.lerp.LerpUtils; +import at.lorenz.mod.config.core.util.lerp.LerpingInteger; +import at.lorenz.mod.config.core.util.render.RenderUtils; +import at.lorenz.mod.config.core.util.render.TextRenderUtils; +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; +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; + +public class ConfigEditor extends GuiElement { + + private static final ResourceLocation[] socialsIco = new ResourceLocation[] { DISCORD }; + private static final String[] socialsLink = new String[] { "https://discord.gg/NcvkPDBA6Y" }; + + 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<>(); + + public ConfigEditor(Features config) { + this(config, null); + } + + public ConfigEditor(Features config, String categoryOpen) { + this.openedMillis = System.currentTimeMillis(); + this.processedConfig = ConfigProcessor.create(config); + + for (ConfigProcessor.ProcessedCategory category : processedConfig.values()) { + for (ConfigProcessor.ProcessedOption option : category.options.values()) { + categoryForOption.put(option, category); + } + } + + if (categoryOpen != null) { + for (Map.Entry<String, ConfigProcessor.ProcessedCategory> category : processedConfig.entrySet()) { + if (category.getValue().name.equalsIgnoreCase(categoryOpen)) { + selectedCategory = category.getKey(); + break; + } + } + if (selectedCategory == null) { + for (Map.Entry<String, ConfigProcessor.ProcessedCategory> category : processedConfig.entrySet()) { + if (category.getValue().name.toLowerCase().startsWith(categoryOpen.toLowerCase())) { + selectedCategory = category.getKey(); + break; + } + } + } + if (selectedCategory == null) { + for (Map.Entry<String, ConfigProcessor.ProcessedCategory> category : processedConfig.entrySet()) { + if (category.getValue().name.toLowerCase().contains(categoryOpen.toLowerCase())) { + selectedCategory = category.getKey(); + break; + } + } + } + } + } + + private LinkedHashMap<String, ConfigProcessor.ProcessedCategory> getCurrentConfigEditing() { + return new LinkedHashMap<>(processedConfig); + } + + private LinkedHashMap<String, ConfigProcessor.ProcessedOption> getOptionsInCategory(ConfigProcessor.ProcessedCategory cat) { + return new LinkedHashMap<>(cat.options); + } + + public String getSelectedCategory() { + return selectedCategory; + } + + public String getSelectedCategoryName() { + return processedConfig.get(selectedCategory).name; + } + + private void setSelectedCategory(String category) { + selectedCategory = category; + optionsScroll.setValue(0); + } + + public void render() { + optionsScroll.tick(); + categoryScroll.tick(); + + List<String> tooltipToDisplay = null; + + long currentTime = System.currentTimeMillis(); + long delta = currentTime - openedMillis; + + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + int width = scaledResolution.getScaledWidth(); + int height = scaledResolution.getScaledHeight(); + int mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth; + 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); + + int xSize = Math.min(scaledResolution.getScaledWidth() - 100 / scaledResolution.getScaleFactor(), 500); + int ySize = Math.min(scaledResolution.getScaledHeight() - 100 / scaledResolution.getScaleFactor(), 400); + + int x = (scaledResolution.getScaledWidth() - xSize) / 2; + int y = (scaledResolution.getScaledHeight() - ySize) / 2; + + int adjScaleFactor = Math.max(2, scaledResolution.getScaleFactor()); + + int openingXSize = xSize; + int openingYSize = ySize; + if (delta < 150) { + openingXSize = (int) (delta * xSize / 150); + openingYSize = 5; + } else if (delta < 300) { + openingYSize = 5 + (int) (delta - 150) * (ySize - 5) / 150; + } + RenderUtils.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); + + RenderUtils.drawFloatingRectDark(x + 5, y + 5, xSize - 10, 20, false); + + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + TextRenderUtils.drawStringCenteredScaledMaxWidth("LorenzMod " + LorenzMod.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); + + int innerPadding = 20 / adjScaleFactor; + int innerLeft = x + 4 + innerPadding; + int innerRight = x + 144 - innerPadding; + int innerTop = y + 49 + innerPadding; + int innerBottom = y + ySize - 5 - innerPadding; + Gui.drawRect(innerLeft, innerTop, innerLeft + 1, innerBottom, 0xff08080E); //Left + Gui.drawRect(innerLeft + 1, innerTop, innerRight, innerTop + 1, 0xff08080E); //Top + Gui.drawRect(innerRight - 1, innerTop + 1, innerRight, innerBottom, 0xff28282E); //Right + 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); + + float catBarSize = 1; + int catY = -categoryScroll.getValue(); + + LinkedHashMap<String, ConfigProcessor.ProcessedCategory> currentConfigEditing = getCurrentConfigEditing(); + for (Map.Entry<String, ConfigProcessor.ProcessedCategory> entry : currentConfigEditing.entrySet()) { + String selectedCategory = getSelectedCategory(); + if (selectedCategory == null || !currentConfigEditing.containsKey(selectedCategory)) { + setSelectedCategory(entry.getKey()); + } + String catName = entry.getValue().name; + if (entry.getKey().equals(getSelectedCategory())) { + catName = EnumChatFormatting.DARK_AQUA.toString() + EnumChatFormatting.UNDERLINE + catName; + } else { + catName = EnumChatFormatting.GRAY + catName; + } + 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())); + } + } + + float catBarStart = categoryScroll.getValue() / (float) (catY + categoryScroll.getValue()); + float catBarEnd = catBarStart + catBarSize; + if (catBarEnd > 1) { |
