diff options
Diffstat (limited to 'src/main/java/io')
4 files changed, 83 insertions, 2 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/help/SettingsCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/help/SettingsCommand.java index 9964b739..1855a2b5 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/help/SettingsCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/help/SettingsCommand.java @@ -47,7 +47,7 @@ public class SettingsCommand extends ClientCommandBase { NotEnoughUpdates.INSTANCE.openGui = new GuiScreenElementWrapper(new NEUConfigEditor(NotEnoughUpdates.INSTANCE.config, StringUtils.join(args, " "))); } else { - NotEnoughUpdates.INSTANCE.openGui = new GuiScreenElementWrapper(NEUConfigEditor.editor); + NotEnoughUpdates.INSTANCE.openGui = new GuiScreenElementWrapper(new NEUConfigEditor(NotEnoughUpdates.INSTANCE.config)); } } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditor.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditor.java index c3969e35..9edad918 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditor.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditor.java @@ -27,7 +27,7 @@ import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.renderer.GlStateManager; public abstract class GuiOptionEditor { - protected final ConfigProcessor.ProcessedOption option; + public final ConfigProcessor.ProcessedOption option; private static final int HEIGHT = 45; public GuiOptionEditor(ConfigProcessor.ProcessedOption option) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/struct/ConfigProcessor.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/struct/ConfigProcessor.java index 9a75ec19..62b9b8e2 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/struct/ConfigProcessor.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/struct/ConfigProcessor.java @@ -45,6 +45,7 @@ import io.github.moulberry.notenoughupdates.core.config.gui.GuiOptionEditorFSR; import io.github.moulberry.notenoughupdates.core.config.gui.GuiOptionEditorKeybind; import io.github.moulberry.notenoughupdates.core.config.gui.GuiOptionEditorSlider; import io.github.moulberry.notenoughupdates.core.config.gui.GuiOptionEditorText; +import io.github.moulberry.notenoughupdates.miscfeatures.EnforcedConfigValues; import java.lang.reflect.Field; import java.util.LinkedHashMap; @@ -133,6 +134,7 @@ public class ConfigProcessor { boolean optionPresent = optionField.isAnnotationPresent(ConfigOption.class); if (optionPresent) { + String optionPath = categoryField.getName() + "." + optionField.getName(); ConfigOption optionAnnotation = optionField.getAnnotation(ConfigOption.class); ProcessedOption option = new ProcessedOption( optionAnnotation.name(), @@ -231,6 +233,10 @@ public class ConfigProcessor { //System.err.printf("Failed to load config option %s. Could not find suitable editor.\n", optionField.getName()); continue; } + if (EnforcedConfigValues.INSTANCE.isBlockedFromEditing(optionPath)) { + editor = new GuiOptionEditorBlocked(editor); + } + option.editor = editor; cat.options.put(optionField.getName(), option); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/struct/GuiOptionEditorBlocked.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/struct/GuiOptionEditorBlocked.java new file mode 100644 index 00000000..8415cf72 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/struct/GuiOptionEditorBlocked.java @@ -0,0 +1,75 @@ +/* + * 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 io.github.moulberry.notenoughupdates.core.config.struct; + +import io.github.moulberry.notenoughupdates.core.config.gui.GuiOptionEditor; +import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; +import io.github.moulberry.notenoughupdates.core.util.render.TextRenderUtils; +import lombok.var; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.util.ResourceLocation; + +public class GuiOptionEditorBlocked extends GuiOptionEditor { + public static final ResourceLocation blockedTexture = new ResourceLocation( + "notenoughupdates:textures/gui/config_blocked.png"); + private final GuiOptionEditor base; + + public GuiOptionEditorBlocked(GuiOptionEditor base) { + super(base.option); + this.base = base; + } + + @Override + public void render(int x, int y, int width) { + // No super. We delegate and overlay ourselves instead. + base.render(x, y, width); + + var mc = Minecraft.getMinecraft(); + + // Depress original option + Gui.drawRect(x, y, x + width, y + getHeight(), 0x80000000); + + GlStateManager.color(1, 1, 1, 1); + mc.getTextureManager().bindTexture(blockedTexture); + + float iconWidth = getHeight() * 96F / 64; + RenderUtils.drawTexturedRect(x, y, iconWidth, getHeight()); + + TextRenderUtils.drawStringScaledMaxWidth( + "This option is currently not available.", + mc.fontRendererObj, + x + iconWidth,y + getHeight() / 2F - mc.fontRendererObj.FONT_HEIGHT / 2F, + true, (int) (width - iconWidth), 0xFFFF4444 + ); + GlStateManager.color(1, 1, 1, 1); + } + + @Override + public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { + return false; + } + + @Override + public boolean keyboardInput() { + return false; + } +} |