Compare commits

..

3 Commits

Author SHA1 Message Date
Motschen
2db6b33d30 Bump version 2023-03-09 21:11:02 +01:00
Motschen
c881db8be4 Fix <Ctrl>+<Number> keybinds not working for tabs 2023-03-09 21:10:01 +01:00
Motschen
79eb8936ff Update the example config 2023-03-09 20:37:44 +01:00
4 changed files with 24 additions and 11 deletions

View File

@@ -13,9 +13,10 @@ import java.util.List;
public class MidnightConfigExample extends MidnightConfig {
@Comment public static Comment text1; // Comments are rendered like an option without a button and are excluded from the config file
@Comment(centered = true) public static Comment text2; // Centered comments are the same as normal ones - just centered!
@Entry public static boolean showInfo = true; // Example for a boolean option
@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!
@Comment(category = "text") public static Comment spacer1; // Comments containing the word "spacer" will just appear as a blank line
@Entry(category = "text") public static boolean showInfo = true; // Example for a boolean option
@Entry(category = "text") public static String name = "Hello World!"; // Example for a string option, which is in a category!
@Entry(category = "text") public static TestEnum testEnum = TestEnum.FABRIC; // Example for an enum option
public enum TestEnum { // Enums allow the user to cycle through predefined options
@@ -25,7 +26,7 @@ public class MidnightConfigExample extends MidnightConfig {
@Entry(category = "numbers") public static double world = 1.4D; // Example for a double option
@Entry(category = "numbers", min=69,max=420) public static int hello = 420; // - The entered number has to be larger than 69 and smaller than 420
@Entry(category = "text", width = 7, min = 7, isColor = true, name = "I am a color!") public static String titleColor = "#ffffff"; // The isColor property adds a preview box for a hexadecimal color
@Entry(category = "sliders", name = "I am an array list!") public static List<String> arrayList = Lists.newArrayList("String1", "String2"); // Array String Lists are also supported
@Entry(category = "text", name = "I am an array list!") public static List<String> arrayList = Lists.newArrayList("String1", "String2"); // Array String Lists are also supported
@Entry(category = "sliders", name = "I am an int slider.",isSlider = true, min = 0, max = 100) public static int intSlider = 35; // Int fields can also be displayed as a Slider
@Entry(category = "sliders", name = "I am a float slider!", isSlider = true, min = 0f, max = 1f, precision = 1000) public static float floatSlider = 0.24f; // And so can floats! Precision defines the amount of decimal places
// The name field can be used to specify a custom translation string or plain text

View File

@@ -202,8 +202,9 @@ public abstract class MidnightConfig {
public final String modid;
public MidnightConfigListWidget list;
public boolean reload = false;
public TabManager tabManager = new TabManager(a -> refresh(), a -> refresh());
public TabManager tabManager = new TabManager(a -> {}, a -> {});
public Tab prevTab;
public TabNavigationWidget tabNavigation;
public ButtonWidget done;
// Real Time config update //
@@ -242,6 +243,11 @@ public abstract class MidnightConfig {
} catch (IllegalAccessException ignored) {}
}
}
@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (this.tabNavigation.trySwitchTabsWithKey(keyCode)) return true;
return super.keyPressed(keyCode, scanCode, modifiers);
}
public Tooltip getTooltip(EntryInfo info) {
return Tooltip.of(info.error != null ? info.error : I18n.hasTranslation(translationPrefix+info.field.getName()+".tooltip") ? Text.translatable(translationPrefix+info.field.getName()+".tooltip") : Text.empty());
}
@@ -270,7 +276,7 @@ public abstract class MidnightConfig {
} else e.tab = tabs.get(name);
}
}
TabNavigationWidget tabNavigation = TabNavigationWidget.builder(tabManager, this.width).tabs(tabs.values().toArray(new Tab[0])).build();
tabNavigation = TabNavigationWidget.builder(tabManager, this.width).tabs(tabs.values().toArray(new Tab[0])).build();
if (tabs.size() > 1) this.addDrawableChild(tabNavigation);
if (!reload) tabNavigation.selectTab(0, false);
tabNavigation.init();
@@ -280,10 +286,6 @@ public abstract class MidnightConfig {
loadValues();
Objects.requireNonNull(client).setScreen(parent);
}).dimensions(this.width / 2 - 154, this.height - 28, 150, 20).build());
this.list = new MidnightConfigListWidget(this.client, this.width, this.height, 32, this.height - 32, 25);
if (this.client != null && this.client.world != null) this.list.setRenderBackground(false);
this.addSelectableChild(this.list);
done = this.addDrawableChild(ButtonWidget.builder(ScreenTexts.DONE, (button) -> {
for (EntryInfo info : entries)
if (info.id.equals(modid)) {
@@ -294,6 +296,11 @@ public abstract class MidnightConfig {
write(modid);
Objects.requireNonNull(client).setScreen(parent);
}).dimensions(this.width / 2 + 4, this.height - 28, 150, 20).build());
this.list = new MidnightConfigListWidget(this.client, this.width, this.height, 32, this.height - 32, 25);
if (this.client != null && this.client.world != null) this.list.setRenderBackground(false);
this.addSelectableChild(this.list);
fillList();
}
public void fillList() {

View File

@@ -30,6 +30,11 @@
"eu.midnightdust.lib.config.AutoModMenu"
]
},
"depends": {
"fabric-models-v0": "*",
"fabric-resource-loader-v0": "*",
"minecraft": ">=1.19.4-rc.1"
},
"mixins": [
"midnightlib.mixins.json"

View File

@@ -5,7 +5,7 @@ yarn_mappings=1.19.4-pre4+build.1
enabled_platforms=fabric
archives_base_name=midnightlib
mod_version=1.2.0
mod_version=1.2.1
maven_group=eu.midnightdust
fabric_loader_version=0.14.17