mirror of
https://github.com/TeamMidnightDust/MidnightLib.git
synced 2025-12-16 09:15:10 +01:00
Compare commits
28 Commits
6693580cfa
...
architectu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ba128f322 | ||
|
|
cf58bd3637 | ||
|
|
61e9ca96fa | ||
|
|
b963764afe | ||
|
|
fefbaa1947 | ||
|
|
9602736335 | ||
|
|
30d213b92c | ||
|
|
b61b2cdf12 | ||
|
|
bcde119f23 | ||
|
|
b08e38ae11 | ||
|
|
a1ad6dd1f0 | ||
|
|
7ddfadd4ec | ||
|
|
6bbaf1ab5d | ||
|
|
f1fe868192 | ||
|
|
74d8800fa5 | ||
|
|
3e2ceb09c6 | ||
|
|
f1a3b2c634 | ||
|
|
f9fc657695 | ||
|
|
7a15f1fb8d | ||
|
|
b2c24010da | ||
|
|
302728192f | ||
|
|
3eb345ce3c | ||
|
|
f986d10e1f | ||
|
|
03223b8d9b | ||
|
|
daec2a3187 | ||
|
|
a4d801ddf7 | ||
|
|
fd858bd468 | ||
|
|
02374253fd |
@@ -3,7 +3,7 @@ import groovy.json.JsonOutput
|
||||
|
||||
plugins {
|
||||
id "architectury-plugin" version "3.4-SNAPSHOT"
|
||||
id "dev.architectury.loom" version "1.7-SNAPSHOT" apply false
|
||||
id "dev.architectury.loom" version "1.10-SNAPSHOT" apply false
|
||||
id "me.shedaniel.unified-publishing" version "0.1.+" apply false
|
||||
id 'com.github.johnrengelman.shadow' version '8.1.1' apply false
|
||||
}
|
||||
|
||||
@@ -37,11 +37,14 @@ public abstract class MixinOptionsScreen extends Screen {
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(at = @At("TAIL"), method = "refreshWidgetPositions")
|
||||
|
||||
|
||||
@Inject(at = @At("TAIL"), method = "initTabNavigation")
|
||||
public void midnightlib$onResize(CallbackInfo ci) {
|
||||
if (shouldShowButton()) this.midnightlib$setButtonPos();
|
||||
}
|
||||
|
||||
|
||||
@Unique
|
||||
public void midnightlib$setButtonPos() {
|
||||
midnightlib$button.setPosition(layout.getWidth() / 2 + 158, layout.getY() + layout.getFooterHeight() - 4);
|
||||
|
||||
@@ -45,6 +45,6 @@ public class MidnightConfigOverviewScreen extends Screen {
|
||||
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||
super.render(context, mouseX, mouseY, delta);
|
||||
this.list.render(context, mouseX, mouseY, delta);
|
||||
context.drawCenteredTextWithShadow(textRenderer, title, width / 2, 10, 0xFFFFFF);
|
||||
context.drawCenteredTextWithShadow(textRenderer, title, width / 2, 10, 0xFFFFFFFF);
|
||||
}
|
||||
}
|
||||
@@ -2,24 +2,26 @@ package eu.midnightdust.lib.config;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gson.*; import com.google.gson.stream.*;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import eu.midnightdust.lib.util.PlatformFunctions;
|
||||
import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.Element; import net.minecraft.client.gui.Selectable;
|
||||
import net.minecraft.client.gui.screen.ConfirmLinkScreen; import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.tab.GridScreenTab; import net.minecraft.client.gui.tab.Tab; import net.minecraft.client.gui.tab.TabManager;
|
||||
import net.minecraft.client.gui.tooltip.Tooltip; import net.minecraft.client.gui.widget.*;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.screen.ScreenTexts;
|
||||
import net.minecraft.text.Style; import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableTextContent;
|
||||
import net.minecraft.util.Formatting; import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.TranslatableOption;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
import java.awt.Color;
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.*;
|
||||
import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.lang.reflect.ParameterizedType;
|
||||
import java.nio.file.Files; import java.nio.file.Path;
|
||||
@@ -106,6 +108,10 @@ public abstract class MidnightConfig {
|
||||
if (index >= list.size()) list.add(value);
|
||||
else list.set(index, value);
|
||||
}
|
||||
public Tooltip getTooltip(boolean isButton) {
|
||||
String key = this.modid + ".midnightconfig."+this.fieldName+(!isButton ? ".label" : "" )+".tooltip";
|
||||
return Tooltip.of(isButton && this.error != null ? this.error : I18n.hasTranslation(key) ? Text.translatable(key) : Text.empty());
|
||||
}
|
||||
}
|
||||
|
||||
public static final Map<String, Class<? extends MidnightConfig>> configClass = new HashMap<>();
|
||||
@@ -114,16 +120,8 @@ public abstract class MidnightConfig {
|
||||
private static final Gson gson = new GsonBuilder()
|
||||
.excludeFieldsWithModifiers(Modifier.TRANSIENT).excludeFieldsWithModifiers(Modifier.PRIVATE)
|
||||
.addSerializationExclusionStrategy(new NonEntryExclusionStrategy())
|
||||
.registerTypeAdapter(Identifier.class, new TypeAdapter<Identifier>() {
|
||||
public void write(JsonWriter out, Identifier id) throws IOException { out.value(id.toString()); }
|
||||
public Identifier read(JsonReader in) throws IOException { return Identifier.of(in.nextString()); }
|
||||
}).setPrettyPrinting().create();
|
||||
.registerTypeAdapter(Identifier.class, new Identifier.Serializer()).setPrettyPrinting().create();
|
||||
|
||||
@SuppressWarnings("unused") // Utility for mod authors
|
||||
public static @Nullable Object getDefaultValue(String modid, String entry) {
|
||||
String key = modid + ":" + entry;
|
||||
return entries.containsKey(key) ? entries.get(key).defaultValue : null;
|
||||
}
|
||||
public static void loadValuesFromJson(String modid) {
|
||||
try { gson.fromJson(Files.newBufferedReader(path), configClass.get(modid)); }
|
||||
catch (Exception e) { write(modid); }
|
||||
@@ -163,17 +161,11 @@ public abstract class MidnightConfig {
|
||||
else if (info.dataType == boolean.class) {
|
||||
Function<Object, Text> func = value -> Text.translatable((Boolean) value ? "gui.yes" : "gui.no").formatted((Boolean) value ? Formatting.GREEN : Formatting.RED);
|
||||
info.function = new AbstractMap.SimpleEntry<ButtonWidget.PressAction, Function<Object, Text>>(button -> {
|
||||
if (info.actionButton instanceof CheckboxWidget checkbox && checkbox.isChecked() == (Boolean) info.value) {
|
||||
checkbox.onPress(); return;
|
||||
}
|
||||
info.setValue(!(Boolean) info.value); button.setMessage(func.apply(info.value));
|
||||
}, func);
|
||||
} else if (info.dataType.isEnum()) {
|
||||
List<?> values = Arrays.asList(field.getType().getEnumConstants());
|
||||
Function<Object, Text> func = value -> {
|
||||
String translationKey = modid + ".midnightconfig.enum." + info.dataType.getSimpleName() + "." + info.toTemporaryValue();
|
||||
return I18n.hasTranslation(translationKey) ? Text.translatable(translationKey) : Text.literal(info.toTemporaryValue());
|
||||
};
|
||||
Function<Object, Text> func = value -> getEnumTranslatableText(value, modid, info);
|
||||
info.function = new AbstractMap.SimpleEntry<ButtonWidget.PressAction, Function<Object, Text>>(button -> {
|
||||
int index = values.indexOf(info.value) + 1;
|
||||
info.setValue(values.get(index >= values.size() ? 0 : index));
|
||||
@@ -190,9 +182,12 @@ public abstract class MidnightConfig {
|
||||
try { return (Class<?>) rawType.getField("TYPE").get(null); // Tries to get primitive types from non-primitives (e.g. Boolean -> boolean)
|
||||
} catch (NoSuchFieldException | IllegalAccessException ignored) { return rawType; }
|
||||
}
|
||||
public static Tooltip getTooltip(EntryInfo info, boolean isButton) {
|
||||
String key = info.modid + ".midnightconfig."+info.fieldName+(!isButton ? ".label" : "" )+".tooltip";
|
||||
return Tooltip.of(isButton && info.error != null ? info.error : I18n.hasTranslation(key) ? Text.translatable(key) : Text.empty());
|
||||
|
||||
private static Text getEnumTranslatableText(Object value, String modid, EntryInfo info) {
|
||||
if (value instanceof TranslatableOption translatableOption) return translatableOption.getText();
|
||||
|
||||
String translationKey = "%s.midnightconfig.enum.%s.%s".formatted(modid, info.dataType.getSimpleName(), info.toTemporaryValue());
|
||||
return I18n.hasTranslation(translationKey) ? Text.translatable(translationKey) : Text.literal(info.toTemporaryValue());
|
||||
}
|
||||
|
||||
private static void textField(EntryInfo info, Function<String,Number> f, Pattern pattern, double min, double max, boolean cast) {
|
||||
@@ -209,7 +204,7 @@ public abstract class MidnightConfig {
|
||||
info.error = inLimits? null : Text.literal(value.doubleValue() < min ?
|
||||
"§cMinimum " + (isNumber? "value" : "length") + (cast? " is " + (int)min : " is " + min) :
|
||||
"§cMaximum " + (isNumber? "value" : "length") + (cast? " is " + (int)max : " is " + max)).formatted(Formatting.RED);
|
||||
t.setTooltip(getTooltip(info, true));
|
||||
t.setTooltip(info.getTooltip(true));
|
||||
}
|
||||
|
||||
info.tempValue = s;
|
||||
@@ -241,6 +236,15 @@ public abstract class MidnightConfig {
|
||||
Files.write(path, gson.toJson(getClass(modid)).getBytes());
|
||||
} catch (Exception e) { e.fillInStackTrace(); }
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused") // Utility for mod authors
|
||||
public static @Nullable Object getDefaultValue(String modid, String entry) {
|
||||
String key = modid + ":" + entry;
|
||||
return entries.containsKey(key) ? entries.get(key).defaultValue : null;
|
||||
}
|
||||
|
||||
public void onTabInit(String tabName, MidnightConfigListWidget list, MidnightConfigScreen screen) {}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public static Screen getScreen(Screen parent, String modid) {
|
||||
return new MidnightConfigScreen(parent, modid);
|
||||
@@ -248,7 +252,7 @@ public abstract class MidnightConfig {
|
||||
@Environment(EnvType.CLIENT)
|
||||
public static class MidnightConfigScreen extends Screen {
|
||||
protected MidnightConfigScreen(Screen parent, String modid) {
|
||||
super(Text.translatable(modid + ".midnightconfig." + "title"));
|
||||
super(Text.translatable(modid + ".midnightconfig.title"));
|
||||
this.parent = parent; this.modid = modid;
|
||||
this.translationPrefix = modid + ".midnightconfig.";
|
||||
loadValuesFromJson(modid);
|
||||
@@ -285,9 +289,9 @@ public abstract class MidnightConfig {
|
||||
super.tick();
|
||||
if (prevTab != null && prevTab != tabManager.getCurrentTab()) {
|
||||
prevTab = tabManager.getCurrentTab();
|
||||
updateList(); list.setScrollY(0);
|
||||
updateList(); list.setScrollAmount(0);
|
||||
}
|
||||
scrollProgress = list.getScrollY();
|
||||
scrollProgress = list.getScrollAmount();
|
||||
for (EntryInfo info : entries.values()) info.updateFieldValue();
|
||||
updateButtons();
|
||||
if (reloadScreen) { updateList(); reloadScreen = false; }
|
||||
@@ -295,9 +299,9 @@ public abstract class MidnightConfig {
|
||||
public void updateButtons() {
|
||||
if (this.list != null) {
|
||||
for (ButtonEntry entry : this.list.children()) {
|
||||
if (entry.buttons != null && entry.buttons.size() > 1) {
|
||||
if (entry.buttons != null && entry.buttons.size() > 1 && entry.info.field != null) {
|
||||
if (entry.buttons.get(0) instanceof ClickableWidget widget)
|
||||
if (widget.isFocused() || widget.isHovered()) widget.setTooltip(getTooltip(entry.info, true));
|
||||
if (widget.isFocused() || widget.isHovered()) widget.setTooltip(entry.info.getTooltip(true));
|
||||
if (entry.buttons.get(1) instanceof ButtonWidget button)
|
||||
button.active = !Objects.equals(String.valueOf(entry.info.value), String.valueOf(entry.info.defaultValue)) && entry.info.conditionsMet;
|
||||
}}}}
|
||||
@@ -337,7 +341,9 @@ public abstract class MidnightConfig {
|
||||
this.list.clear(); fillList();
|
||||
}
|
||||
public void fillList() {
|
||||
MidnightConfig.getClass(modid).onTabInit(prevTab.getTitle().getContent() instanceof TranslatableTextContent translatable ? translatable.getKey().replace("%s.midnightconfig.category.".formatted(modid), "") : prevTab.getTitle().toString(), list, this);
|
||||
for (EntryInfo info : entries.values()) {
|
||||
info.updateConditions();
|
||||
if (!info.conditionsMet) {
|
||||
boolean visibleButLocked = false;
|
||||
for (Condition condition : info.conditions) {
|
||||
@@ -359,10 +365,10 @@ public abstract class MidnightConfig {
|
||||
Entry e = info.entry;
|
||||
if (info.function instanceof Map.Entry) { // Enums & booleans
|
||||
var values = (Map.Entry<ButtonWidget.PressAction, Function<Object, Text>>) info.function;
|
||||
if (info.dataType.isEnum())
|
||||
values.setValue(value -> Text.translatable(translationPrefix + "enum." + info.dataType.getSimpleName() + "." + info.value.toString()));
|
||||
widget = ButtonWidget.builder(values.getValue().apply(info.value), values.getKey()).dimensions(width - 185, 0, 150, 20).tooltip(getTooltip(info, true)).build();
|
||||
if (info.dataType == boolean.class) info.actionButton = CheckboxWidget.builder(Text.empty(), textRenderer).callback((checkbox, checked) -> values.getKey().onPress((ButtonWidget) widget)).checked((Boolean) info.value).pos(widget.getX(), 1).build();
|
||||
if (info.dataType.isEnum()) {
|
||||
values.setValue(value -> getEnumTranslatableText(value, modid, info));
|
||||
}
|
||||
widget = ButtonWidget.builder(values.getValue().apply(info.value), values.getKey()).dimensions(width - 185, 0, 150, 20).tooltip(info.getTooltip(true)).build();
|
||||
} else if (e.isSlider())
|
||||
widget = new MidnightSliderWidget(width - 185, 0, 150, 20, Text.of(info.tempValue), (Double.parseDouble(info.tempValue) - e.min()) / (e.max() - e.min()), info);
|
||||
else widget = new TextFieldWidget(textRenderer, width - 185, 0, 150, 20, Text.empty());
|
||||
@@ -371,7 +377,7 @@ public abstract class MidnightConfig {
|
||||
Predicate<String> processor = ((BiFunction<TextFieldWidget, ButtonWidget, Predicate<String>>) info.function).apply(textField, done);
|
||||
textField.setTextPredicate(processor);
|
||||
}
|
||||
widget.setTooltip(getTooltip(info, true));
|
||||
widget.setTooltip(info.getTooltip(true));
|
||||
|
||||
ButtonWidget cycleButton = null;
|
||||
if (info.field.getType() == List.class) {
|
||||
@@ -429,7 +435,7 @@ public abstract class MidnightConfig {
|
||||
if (!info.conditionsMet) widgets.forEach(w -> w.active = false);
|
||||
this.list.addButton(widgets, name, info);
|
||||
} else this.list.addButton(List.of(), name, info);
|
||||
} list.setScrollY(scrollProgress);
|
||||
} list.setScrollAmount(scrollProgress);
|
||||
updateButtons();
|
||||
}
|
||||
}
|
||||
@@ -437,7 +443,7 @@ public abstract class MidnightConfig {
|
||||
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||
super.render(context, mouseX, mouseY, delta);
|
||||
this.list.render(context, mouseX, mouseY, delta);
|
||||
if (tabs.size() < 2) context.drawCenteredTextWithShadow(textRenderer, title, width / 2, 10, 0xFFFFFF);
|
||||
if (tabs.size() < 2) context.drawCenteredTextWithShadow(textRenderer, title, width / 2, 10, 0xFFFFFFFF);
|
||||
}
|
||||
}
|
||||
@Environment(EnvType.CLIENT)
|
||||
@@ -449,7 +455,9 @@ public abstract class MidnightConfig {
|
||||
@Override
|
||||
protected void drawHeaderAndFooterSeparators(DrawContext context) {
|
||||
if (renderHeaderSeparator) super.drawHeaderAndFooterSeparators(context);
|
||||
else context.drawTexture(RenderLayer::getGuiTextured, this.client.world == null ? Screen.FOOTER_SEPARATOR_TEXTURE : Screen.INWORLD_FOOTER_SEPARATOR_TEXTURE, this.getX(), this.getBottom(), 0, 0, this.getWidth(), 2, 32, 2);
|
||||
else { RenderSystem.enableBlend();
|
||||
context.drawTexture(this.client.world == null ? Screen.FOOTER_SEPARATOR_TEXTURE : Screen.INWORLD_FOOTER_SEPARATOR_TEXTURE, this.getX(), this.getBottom(), 0.0F, 0.0F, this.getWidth(), 2, 32, 2);
|
||||
RenderSystem.disableBlend(); }
|
||||
}
|
||||
public void addButton(List<ClickableWidget> buttons, Text text, EntryInfo info) { this.addEntry(new ButtonEntry(buttons, text, info)); }
|
||||
public void clear() { this.clearEntries(); }
|
||||
@@ -469,17 +477,17 @@ public abstract class MidnightConfig {
|
||||
int scaledWidth = MinecraftClient.getInstance().getWindow().getScaledWidth();
|
||||
|
||||
if (text != null && (!text.getString().contains("spacer") || !buttons.isEmpty())) {
|
||||
title = new MultilineTextWidget((centered) ? (scaledWidth / 2 - (textRenderer.getWidth(text) / 2)) : 12, 0, Text.of(text), textRenderer);
|
||||
if (info != null) title.setTooltip(getTooltip(info, false));
|
||||
title.setMaxWidth(buttons.size() > 1 ? buttons.get(1).getX() - 24 : scaledWidth - 24);
|
||||
title = new MultilineTextWidget((centered) ? (scaledWidth / 2 - (textRenderer.getWidth(text) / 2)) : 12, 0, text, textRenderer);
|
||||
title.setCentered(centered);
|
||||
if (info != null) title.setTooltip(info.getTooltip(false));
|
||||
title.setMaxWidth(!buttons.isEmpty() ? buttons.get(buttons.size() > 2 ? buttons.size()-1 : 0).getX() - 16 : scaledWidth - 24);
|
||||
}
|
||||
}
|
||||
public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
|
||||
buttons.forEach(b -> { b.setY(y + (b instanceof CheckboxWidget ? 1 : 0)); b.render(context, mouseX, mouseY, tickDelta);});
|
||||
buttons.forEach(b -> { b.setY(y); b.render(context, mouseX, mouseY, tickDelta);});
|
||||
if (title != null) {
|
||||
title.setY(y + 9);
|
||||
title.renderWidget(context, mouseX, mouseY, tickDelta);
|
||||
|
||||
title.setY(y+5);
|
||||
title.render(context, mouseX, mouseY, tickDelta);
|
||||
boolean tooltipVisible = mouseX >= title.getX() && mouseX < title.getWidth() + title.getX() && mouseY >= title.getY() && mouseY < title.getHeight() + title.getY();
|
||||
if (tooltipVisible && title.getTooltip() != null) context.drawOrderedTooltip(textRenderer, title.getTooltip().getLines(MinecraftClient.getInstance()), mouseX, mouseY);
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"midnightlib.overview.title": "Visión general de MidnightConfig",
|
||||
"midnightlib.midnightconfig.title": "Configuración de MidnightLib",
|
||||
"midnightlib.midnightconfig.config_screen_list": "Habilitar lista de pantallas de configuración",
|
||||
"midnightlib.midnightconfig.enum.ConfigButton.TRUE": "§aSí",
|
||||
"modmenu.summaryTranslation.midnightlib": "Librería común para facilitar la configuración.",
|
||||
"midnightconfig.colorChooser.title": "Elegí un color"
|
||||
}
|
||||
@@ -1,21 +1,21 @@
|
||||
org.gradle.jvmargs=-Xmx4096M
|
||||
|
||||
minecraft_version=1.21.4
|
||||
supported_versions=1.21.5
|
||||
yarn_mappings=1.21.4+build.1
|
||||
minecraft_version=1.21.1
|
||||
supported_versions=1.21
|
||||
yarn_mappings=1.21.1+build.3
|
||||
enabled_platforms=fabric,neoforge
|
||||
|
||||
archives_base_name=midnightlib
|
||||
mod_version=1.7.2
|
||||
mod_version=1.7.5
|
||||
maven_group=eu.midnightdust
|
||||
release_type=release
|
||||
curseforge_id=488090
|
||||
modrinth_id=codAaoxh
|
||||
|
||||
fabric_loader_version=0.16.9
|
||||
fabric_api_version=0.110.5+1.21.4
|
||||
fabric_loader_version=0.16.14
|
||||
fabric_api_version=0.116.4+1.21.1
|
||||
|
||||
neoforge_version=21.4.3-beta
|
||||
neoforge_version=21.1.192
|
||||
yarn_mappings_patch_neoforge_version = 1.21+build.4
|
||||
|
||||
mod_menu_version = 9.0.0
|
||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
@@ -26,7 +26,7 @@ public class MidnightLibNeoForge {
|
||||
if (FMLEnvironment.dist == Dist.CLIENT) MidnightLib.onInitializeClient();
|
||||
}
|
||||
|
||||
@EventBusSubscriber(modid = "midnightlib", bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
|
||||
@EventBusSubscriber(modid = "midnightlib", value = Dist.CLIENT)
|
||||
public static class MidnightLibBusEvents {
|
||||
@SubscribeEvent
|
||||
public static void onPostInit(FMLClientSetupEvent event) {
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
package eu.midnightdust.fabric.example;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import eu.midnightdust.lib.config.MidnightConfig;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.tooltip.Tooltip;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||
import net.minecraft.client.gui.widget.TextIconButtonWidget;
|
||||
import net.minecraft.client.option.KeyBinding;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
import net.minecraft.text.MutableText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
/*
|
||||
Pre-made additional (niche) functionality that is not included in MidnightLib to keep the file size small.
|
||||
Feel free to copy the parts you need :)
|
||||
*/
|
||||
public class MidnightLibExtras {
|
||||
public static class KeybindButton extends ButtonWidget {
|
||||
public static ButtonWidget focusedButton;
|
||||
|
||||
public static void add(KeyBinding binding, MidnightConfig.MidnightConfigListWidget list, MidnightConfig.MidnightConfigScreen screen) {
|
||||
KeybindButton editButton = new KeybindButton(screen.width - 185, 0, 150, 20, binding);
|
||||
TextIconButtonWidget resetButton = TextIconButtonWidget.builder(Text.translatable("controls.reset"), (button -> {
|
||||
binding.setBoundKey(binding.getDefaultKey());
|
||||
screen.updateList();
|
||||
}), true).texture(Identifier.of("midnightlib","icon/reset"), 12, 12).dimension(20, 20).build();
|
||||
resetButton.setPosition(screen.width - 205 + 150 + 25, 0);
|
||||
editButton.resetButton = resetButton;
|
||||
editButton.updateMessage(false);
|
||||
MidnightConfig.EntryInfo info = new MidnightConfig.EntryInfo(null, screen.modid);
|
||||
|
||||
list.addButton(Lists.newArrayList(editButton, resetButton), Text.translatable(binding.getTranslationKey()), info);
|
||||
}
|
||||
|
||||
private final KeyBinding binding;
|
||||
private @Nullable ClickableWidget resetButton;
|
||||
public KeybindButton(int x, int y, int width, int height, KeyBinding binding) {
|
||||
super(x, y, width, height, binding.getBoundKeyLocalizedText(), (button) -> {
|
||||
((KeybindButton) button).updateMessage(true);
|
||||
focusedButton = button;
|
||||
}, (textSupplier) -> binding.isUnbound() ? Text.translatable("narrator.controls.unbound", binding.getTranslationKey()) : Text.translatable("narrator.controls.bound", binding.getTranslationKey(), textSupplier.get()));
|
||||
this.binding = binding;
|
||||
updateMessage(false);
|
||||
}
|
||||
@Override
|
||||
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||
if (focusedButton == this) {
|
||||
if (keyCode == GLFW.GLFW_KEY_ESCAPE) {
|
||||
this.binding.setBoundKey(InputUtil.UNKNOWN_KEY);
|
||||
} else {
|
||||
this.binding.setBoundKey(InputUtil.fromKeyCode(keyCode, scanCode));
|
||||
}
|
||||
updateMessage(false);
|
||||
|
||||
focusedButton = null;
|
||||
return true;
|
||||
}
|
||||
return super.keyPressed(keyCode, scanCode, modifiers);
|
||||
}
|
||||
|
||||
public void updateMessage(boolean focused) {
|
||||
boolean hasConflicts = false;
|
||||
MutableText conflictingBindings = Text.empty();
|
||||
if (focused) this.setMessage(Text.literal("> ").append(this.binding.getBoundKeyLocalizedText().copy().formatted(Formatting.WHITE, Formatting.UNDERLINE)).append(" <").formatted(Formatting.YELLOW));
|
||||
else {
|
||||
this.setMessage(this.binding.getBoundKeyLocalizedText());
|
||||
|
||||
if (!this.binding.isUnbound()) {
|
||||
for(KeyBinding keyBinding : MinecraftClient.getInstance().options.allKeys) {
|
||||
if (keyBinding != this.binding && this.binding.equals(keyBinding)) {
|
||||
if (hasConflicts) conflictingBindings.append(", ");
|
||||
|
||||
hasConflicts = true;
|
||||
conflictingBindings.append(Text.translatable(keyBinding.getTranslationKey()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.resetButton != null) this.resetButton.active = !this.binding.isDefault();
|
||||
|
||||
if (hasConflicts) {
|
||||
this.setMessage(Text.literal("[ ").append(this.getMessage().copy().formatted(Formatting.WHITE)).append(" ]").formatted(Formatting.RED));
|
||||
this.setTooltip(Tooltip.of(Text.translatable("controls.keybinds.duplicateKeybinds", conflictingBindings)));
|
||||
} else {
|
||||
this.setTooltip(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,19 @@
|
||||
package eu.midnightdust.fabric.example.config;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import eu.midnightdust.fabric.example.MidnightLibExtras;
|
||||
import eu.midnightdust.lib.config.MidnightConfig;
|
||||
import net.minecraft.text.MutableText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.TranslatableOption;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/** Every option in a MidnightConfig class has to be public and static, so we can access it from other classes.
|
||||
* The config class also has to extend MidnightConfig*/
|
||||
@@ -18,6 +25,7 @@ public class MidnightConfigExample extends MidnightConfig {
|
||||
public static final String LISTS = "lists";
|
||||
public static final String FILES = "files";
|
||||
public static final String CONDITIONS = "conditions";
|
||||
public static final String EXTRAS = "extras";
|
||||
|
||||
@Comment(category = TEXT) public static Comment text1; // Comments are rendered like an option without a button and are excluded from the config file
|
||||
@Comment(category = TEXT, centered = true) public static Comment text2; // Centered comments are the same as normal ones - just centered!
|
||||
@@ -31,6 +39,8 @@ public class MidnightConfigExample extends MidnightConfig {
|
||||
public enum ModPlatform { // Enums allow the user to cycle through predefined options
|
||||
QUILT, FABRIC, FORGE, NEOFORGE, VANILLA
|
||||
}
|
||||
@Entry(category = TEXT) public static GraphicsSteps graphicsSteps = GraphicsSteps.FABULOUS; // Example for an enum option with TranslatableOption
|
||||
|
||||
@Comment(category = TEXT, name = "§nMidnightLib Wiki", centered = true, url = "https://www.midnightdust.eu/wiki/midnightlib/") public static Comment wiki; // Example for a comment with a url
|
||||
|
||||
@Entry(category = NUMBERS) public static int fabric = 16777215; // Example for an int option
|
||||
@@ -115,4 +125,46 @@ public class MidnightConfigExample extends MidnightConfig {
|
||||
@Comment(category = CONDITIONS, name="You disabled MidnightLib's config screen list. Why? :(", centered = true) public static Comment why;
|
||||
|
||||
public static int imposter = 16777215; // - Entries without an @Entry or @Comment annotation are ignored
|
||||
|
||||
public enum GraphicsSteps implements TranslatableOption {
|
||||
FAST(0, "options.graphics.fast"),
|
||||
FANCY(1, "options.graphics.fancy"),
|
||||
FABULOUS(2, "options.graphics.fabulous");
|
||||
|
||||
private final int id;
|
||||
private final String translationKey;
|
||||
|
||||
GraphicsSteps(int id, String translationKey) {
|
||||
this.id = id;
|
||||
this.translationKey = translationKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getText() {
|
||||
MutableText mutableText = Text.translatable(this.getTranslationKey());
|
||||
return this == GraphicsSteps.FABULOUS ? mutableText.formatted(Formatting.ITALIC).formatted(Formatting.AQUA) : mutableText;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTranslationKey() {
|
||||
return this.translationKey;
|
||||
}
|
||||
}
|
||||
|
||||
@Condition(requiredModId = "thismoddoesnotexist")
|
||||
@Comment(category = EXTRAS) public static Comment iAmJustADummy; // We only have this to initialize an empty tab for the keybinds below
|
||||
|
||||
@Override
|
||||
public void onTabInit(String tabName, MidnightConfigListWidget list, MidnightConfigScreen screen) {
|
||||
if (Objects.equals(tabName, EXTRAS)) {
|
||||
MidnightLibExtras.KeybindButton.add(MinecraftClient.getInstance().options.advancementsKey, list, screen);
|
||||
MidnightLibExtras.KeybindButton.add(MinecraftClient.getInstance().options.dropKey, list, screen);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
"modid.midnightconfig.enum.ModPlatform.QUILT":"Quilt",
|
||||
"modid.midnightconfig.enum.ModPlatform.NEOFORGE":"NeoForge",
|
||||
"modid.midnightconfig.enum.ModPlatform.VANILLA":"Vanilla",
|
||||
"modid.midnightconfig.graphicsSteps":"I am an enum with TranslatableOption!",
|
||||
"modid.midnightconfig.myFileOrDirectory.fileChooser": "Select an image or directory",
|
||||
"modid.midnightconfig.myFileOrDirectory.fileFilter": "Supported Images (.png, .jpg, .jpeg)",
|
||||
"modid.midnightconfig.category.numbers": "Numbers",
|
||||
@@ -24,5 +25,6 @@
|
||||
"modid.midnightconfig.category.lists": "Lists",
|
||||
"modid.midnightconfig.category.files": "Files",
|
||||
"modid.midnightconfig.category.conditions": "Quiz",
|
||||
"modid.midnightconfig.category.extras": "Extras",
|
||||
"modid.midnightconfig.category.multiConditions": "Multi-Conditions"
|
||||
}
|
||||
28
test-fabric/src/main/resources/assets/modid/lang/es_ar.json
Normal file
28
test-fabric/src/main/resources/assets/modid/lang/es_ar.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"modid.midnightconfig.title": "Soy un título",
|
||||
"modid.midnightconfig.text1": "Soy un comentario *u*",
|
||||
"modid.midnightconfig.text2": "Soy un comentario centrado (╯°□°)╯︵ ┻━┻",
|
||||
"modid.midnightconfig.name": "¡Soy una cadena de texto!",
|
||||
"modid.midnightconfig.name.label.tooltip": "Soy el tooltip de una etiqueta \n¡Wujuu!",
|
||||
"modid.midnightconfig.name.tooltip": "Soy un tooltip uwu \nY una nueva línea",
|
||||
"modid.midnightconfig.fabric": "Soy un entero",
|
||||
"modid.midnightconfig.world": "Soy un número decimal",
|
||||
"modid.midnightconfig.showInfo": "Soy un booleano",
|
||||
"modid.midnightconfig.hello": "¡Soy un entero limitado!",
|
||||
"modid.midnightconfig.id": "¡Soy un identificador de ítem!",
|
||||
"modid.midnightconfig.modPlatform": "¡Soy un enumerador!",
|
||||
"modid.midnightconfig.enum.ModPlatform.FORGE": "Forge",
|
||||
"modid.midnightconfig.enum.ModPlatform.FABRIC": "Fabric",
|
||||
"modid.midnightconfig.enum.ModPlatform.QUILT": "Quilt",
|
||||
"modid.midnightconfig.enum.ModPlatform.NEOFORGE": "NeoForge",
|
||||
"modid.midnightconfig.enum.ModPlatform.VANILLA": "Vanilla",
|
||||
"modid.midnightconfig.myFileOrDirectory.fileChooser": "Seleccioná una imagen o carpeta",
|
||||
"modid.midnightconfig.myFileOrDirectory.fileFilter": "Imágenes compatibles (.png, .jpg, .jpeg)",
|
||||
"modid.midnightconfig.category.numbers": "Números",
|
||||
"modid.midnightconfig.category.text": "Texto",
|
||||
"modid.midnightconfig.category.sliders": "Deslizadores",
|
||||
"modid.midnightconfig.category.lists": "Listas",
|
||||
"modid.midnightconfig.category.files": "Archivos",
|
||||
"modid.midnightconfig.category.conditions": "Cuestionario",
|
||||
"modid.midnightconfig.category.multiConditions": "Condiciones múltiples"
|
||||
}
|
||||
Reference in New Issue
Block a user