Skip to content

Commit

Permalink
Omega Commit: This makes a lot of things work on 1.20 too, but breaks
Browse files Browse the repository at this point in the history
sooo much
  • Loading branch information
nea89o committed Apr 17, 2024
1 parent a6f62ba commit 86146b4
Show file tree
Hide file tree
Showing 40 changed files with 337 additions and 495 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import io.github.notenoughupdates.moulconfig.gui.HorizontalAlign;
import io.github.notenoughupdates.moulconfig.processor.ProcessedCategory;
import io.github.notenoughupdates.moulconfig.processor.ProcessedOption;
import net.minecraft.util.EnumChatFormatting;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -38,11 +37,11 @@ public HorizontalAlign alignCategory(ProcessedCategory category, boolean isSelec

public String formatCategoryName(ProcessedCategory category, boolean isSelected) {
if (isSelected) {
return EnumChatFormatting.DARK_AQUA.toString() + EnumChatFormatting.UNDERLINE + category.name;
return "§b§n" + category.name;
} else if (category.parent == null) {
return EnumChatFormatting.GRAY + category.name;
return "§7" + category.name;
} else {
return EnumChatFormatting.DARK_GRAY + category.name;
return "§8" + category.name;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@

package io.github.notenoughupdates.moulconfig;

import net.minecraft.client.Minecraft;
import net.minecraft.event.ClickEvent;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatStyle;
import net.minecraft.util.ResourceLocation;
import io.github.notenoughupdates.moulconfig.common.ClickType;
import io.github.notenoughupdates.moulconfig.common.IMinecraft;
import io.github.notenoughupdates.moulconfig.common.MyResourceLocation;

import java.awt.*;
import java.net.URI;
Expand All @@ -34,7 +32,7 @@

public abstract class Social {

public static Social forLink(String name, ResourceLocation icon, String link) {
public static Social forLink(String name, MyResourceLocation icon, String link) {
try {
return new URLSocial(name, new URI(link), icon);
} catch (URISyntaxException e) {
Expand All @@ -46,14 +44,14 @@ public static Social forLink(String name, ResourceLocation icon, String link) {

public abstract List<String> getTooltip();

public abstract ResourceLocation getIcon();
public abstract MyResourceLocation getIcon();

private static class URLSocial extends Social {
private final String name;
private final URI url;
private final ResourceLocation icon;
private final MyResourceLocation icon;

private URLSocial(String name, URI url, ResourceLocation icon) {
private URLSocial(String name, URI url, MyResourceLocation icon) {
this.name = name;
this.url = url;
this.icon = icon;
Expand All @@ -64,9 +62,7 @@ public void onClick() {
try {
Desktop.getDesktop().browse(url);
} catch (Exception e) {
ChatComponentText text = new ChatComponentText("Click here to open " + name);
text.setChatStyle(new ChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url.toString())));
Minecraft.getMinecraft().thePlayer.addChatMessage(text);
IMinecraft.instance.sendClickableChatMessage("Click here to open " + name, url.toString(), ClickType.OPEN_LINK);
}
}

Expand All @@ -76,7 +72,7 @@ public List<String> getTooltip() {
}

@Override
public ResourceLocation getIcon() {
public MyResourceLocation getIcon() {
return icon;
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.github.notenoughupdates.moulconfig.common

enum class ClickType {
OPEN_LINK, RUN_COMMAND
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface IKeyboardConstants {
val ctrlRight: Int
val shiftLeft: Int
val shiftRight: Int
val escape: Int
val enter: Int
val delete: Int
val up: Int
Expand All @@ -24,4 +25,5 @@ interface IKeyboardConstants {
val keyX: Int
val keyV: Int
val keyN: Int
val keyF: Int
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.notenoughupdates.moulconfig.common

import io.github.notenoughupdates.moulconfig.internal.MCLogger
import io.github.notenoughupdates.moulconfig.processor.MoulConfigProcessor
import org.jetbrains.annotations.ApiStatus
import java.io.InputStream
import java.util.*
Expand All @@ -26,6 +27,21 @@ interface IMinecraft {
val scaledWidth: Int
val scaledHeight: Int
val scaleFactor: Int
fun isMouseButtonDown(mouseButton: Int): Boolean
fun isKeyboardKeyDown(keyboardKey: Int): Boolean

fun addExtraBuiltinConfigProcessors(processor: MoulConfigProcessor<*>)

fun sendClickableChatMessage(message: String, action: String, type: ClickType)

/**
* This is a method to provide a render context. Note that constructing this context directly will potentially give
* you an incorrect render state, leading to visual glitches. Depending on your platform, this might also require
* additional platform specific cleanup / post rendering work to be done. Use only if you know exactly that none
* of your rendering requires this extra functionality.
*/
@Deprecated("This context will be at the top level, not providing any of the useful translations and scalings that might be needed to render properly. Use with care.")
fun provideTopLevelRenderContext(): RenderContext

companion object {
@JvmField
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.github.notenoughupdates.moulconfig.gui

import io.github.notenoughupdates.moulconfig.gui.component.TextFieldComponent
import io.github.notenoughupdates.moulconfig.observer.GetSetter

class ClassResizableTextField(text: GetSetter<String>) : TextFieldComponent(
text,
20,
) {
private var width = 20

fun setWidth(width: Int) {
this.width = width
}

override fun getWidth(): Int {
return width
}

override fun render(context: GuiImmediateContext) {
super.render(context.translated(0, 0, width, 18))
}

override fun mouseEvent(mouseEvent: MouseEvent, context: GuiImmediateContext): Boolean {
return super.mouseEvent(mouseEvent, context.translated(0, 0, width, 18))
}

override fun keyboardEvent(event: KeyboardEvent, context: GuiImmediateContext): Boolean {
return super.keyboardEvent(event, context.translated(0, 0, width, 18))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,25 @@ public void requestFocus() {
context.setFocusedElement(this);
}

/**
* Unfocus this element only if this element is selected.
*/
public void blur() {
if (context.getFocusedElement() == this)
context.setFocusedElement(null);
}

/**
* {@link #requestFocus Focuses} or {@link #blur blurs} this element depending on {@code shouldFocus}
*/
public void setFocus(boolean shouldFocus) {
if (shouldFocus) {
requestFocus();
} else {
blur();
}
}

/**
* Test if this element is focused.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@

package io.github.notenoughupdates.moulconfig.gui;

import net.minecraft.client.gui.Gui;

public abstract class GuiElement extends Gui {
public abstract class GuiElement {
public abstract void render();

public abstract boolean mouseInput(int mouseX, int mouseY);
public abstract boolean mouseInput(int mouseX, int mouseY, MouseEvent event);

public abstract boolean keyboardInput();
public abstract boolean keyboardInput(KeyboardEvent event);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@
package io.github.notenoughupdates.moulconfig.gui;

import io.github.notenoughupdates.moulconfig.annotations.SearchTag;
import io.github.notenoughupdates.moulconfig.internal.RenderUtils;
import io.github.notenoughupdates.moulconfig.internal.TextRenderUtils;
import io.github.notenoughupdates.moulconfig.common.RenderContext;
import io.github.notenoughupdates.moulconfig.processor.ProcessedOption;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.GlStateManager;
import lombok.var;
import org.jetbrains.annotations.ApiStatus;

import java.util.List;
import java.util.Locale;

public abstract class GuiOptionEditor {
Expand All @@ -54,47 +52,64 @@ public GuiOptionEditor(ProcessedOption option) {
}
}

public void render(int x, int y, int width) {
@Deprecated
protected void render(int x, int y, int width) {
}

public void render(RenderContext context, 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,
var minecraft = context.getMinecraft();
var fr = minecraft.getDefaultFontRenderer();

context.drawDarkRect(x, y, width, height, true);
context.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) {
List<String> lines;
while (true) {
lines = fr.splitText(option.desc, (int) (width * 2 / 3 / scale - 10));
if (lines.size() * scale * (fr.getHeight() + 1) + 10 < getHeight())
break;
scale -= 1 / 8f;
lineCount = fr.listFormattedStringToWidth(option.desc, (int) (width * 2 / 3 / scale - 10)).size();
paraHeight = (int) (9 * scale * lineCount - 1 * scale);
if (scale < 1 / 16f) break;
}

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();
context.pushMatrix();
context.translate(5 + width / 3, 5, 0);
context.scale(scale, scale, 1);
context.translate(0, ((getHeight() - 10) - (fr.getHeight() + 1) * (lines.size() - 1) * scale) / 2F, 0);
for (String line : lines) {
context.drawString(fr, line, 0, 0, 0xc0c0c0, false);
context.translate(0, fr.getHeight() + 1, 0);
}
context.popMatrix();
}

public int getHeight() {
return HEIGHT;
}

public abstract boolean mouseInput(int x, int y, int width, int mouseX, int mouseY);
@Deprecated
protected boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) {
return false;
}

public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY, MouseEvent mouseEvent) {
return this.mouseInput(x, y, width, mouseX, mouseY);
}

public abstract boolean keyboardInput();
@Deprecated
protected boolean keyboardInput() {
return false;
}

public boolean keyboardInput(KeyboardEvent event) {
return keyboardInput();
}

public boolean mouseInputOverlay(int x, int y, int width, int mouseX, int mouseY) {
public boolean mouseInputOverlay(int x, int y, int width, int mouseX, int mouseY, MouseEvent mouseEvent) {
return false;
}

Expand Down
Loading

0 comments on commit 86146b4

Please sign in to comment.