mirror of
https://github.com/Motschen/midnightdust-eu.git
synced 2025-12-15 18:15:10 +01:00
wiki: update MidnightLib for upcoming 1.7.0 release
This commit is contained in:
@@ -45,7 +45,7 @@ dependencies {
|
|||||||
To get started with implementing the config, you must create a public class that extends MidnightConfig.
|
To get started with implementing the config, you must create a public class that extends MidnightConfig.
|
||||||
In this class, your variables can be stored and accessed. Here you can see the contents of an example config class:
|
In this class, your variables can be stored and accessed. Here you can see the contents of an example config class:
|
||||||
```java
|
```java
|
||||||
package eu.midnightdust.core.config;
|
package eu.midnightdust.fabric.example.config;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import eu.midnightdust.lib.config.MidnightConfig;
|
import eu.midnightdust.lib.config.MidnightConfig;
|
||||||
@@ -64,11 +64,13 @@ public class MidnightConfigExample extends MidnightConfig {
|
|||||||
public static final String SLIDERS = "sliders";
|
public static final String SLIDERS = "sliders";
|
||||||
public static final String LISTS = "lists";
|
public static final String LISTS = "lists";
|
||||||
public static final String FILES = "files";
|
public static final String FILES = "files";
|
||||||
|
public static final String CONDITIONS = "conditions";
|
||||||
|
|
||||||
@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) 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, 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
|
@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 boolean showInfo = true; // Example for a boolean option
|
||||||
|
@Entry(category = TEXT, name="I am a (non-primitive) Boolean") public static Boolean nonPrimitive = true; // Example for a non-primative 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 String name = "Hello World!"; // Example for a string option, which is in a category!
|
||||||
@Entry(category = TEXT, width = 7, min = 7, isColor = true, name = "I am a color!") public static String titleColor = "#ffffff"; // The isColor property adds a color chooser for a hexadecimal color
|
@Entry(category = TEXT, width = 7, min = 7, isColor = true, name = "I am a color!") public static String titleColor = "#ffffff"; // The isColor property adds a color chooser for a hexadecimal color
|
||||||
@Entry(category = TEXT, idMode = 0) public static Identifier id = Identifier.ofVanilla("diamond"); // Example for an identifier with matching items displayed next to it!
|
@Entry(category = TEXT, idMode = 0) public static Identifier id = Identifier.ofVanilla("diamond"); // Example for an identifier with matching items displayed next to it!
|
||||||
@@ -81,6 +83,7 @@ public class MidnightConfigExample extends MidnightConfig {
|
|||||||
@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 = 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 = 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 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
|
@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
|
||||||
|
@Entry(category = SLIDERS, name = "I am a non-primitive double slider!", isSlider = true, min = 0d, max = 4d, precision = 10000) public static Double nonPrimitiveDoubleSlider = 3.76d; // Even works for non-primitive fields
|
||||||
// The name field can be used to specify a custom translation string or plain text
|
// The name field can be used to specify a custom translation string or plain text
|
||||||
@Entry(category = LISTS, name = "I am a string list!") public static List<String> stringList = Lists.newArrayList("String1", "String2"); // Array String Lists are also supported
|
@Entry(category = LISTS, name = "I am a string list!") public static List<String> stringList = Lists.newArrayList("String1", "String2"); // Array String Lists are also supported
|
||||||
@Entry(category = LISTS, isColor = true, name = "I am a color list!") public static List<String> colorList = Lists.newArrayList("#ac5f99", "#11aa44"); // Lists also support colors
|
@Entry(category = LISTS, isColor = true, name = "I am a color list!") public static List<String> colorList = Lists.newArrayList("#ac5f99", "#11aa44"); // Lists also support colors
|
||||||
@@ -89,24 +92,24 @@ public class MidnightConfigExample extends MidnightConfig {
|
|||||||
@Entry(category = LISTS, name = "I am a float list!") public static List<Float> floatList = Lists.newArrayList(4.1f, -1.3f, -1f);
|
@Entry(category = LISTS, name = "I am a float list!") public static List<Float> floatList = Lists.newArrayList(4.1f, -1.3f, -1f);
|
||||||
|
|
||||||
@Entry(category = FILES,
|
@Entry(category = FILES,
|
||||||
selectionMode = JFileChooser.FILES_ONLY, // The FILES_ONLY selectionMode adds a file picker button
|
selectionMode = JFileChooser.FILES_ONLY,
|
||||||
fileExtensions = {"json", "txt", "log"}, // Define valid file extensions
|
fileExtensions = {"json", "txt", "log"}, // Define valid file extensions
|
||||||
fileChooserType = JFileChooser.SAVE_DIALOG,
|
fileChooserType = JFileChooser.SAVE_DIALOG,
|
||||||
name = "I am a file!")
|
name = "I am a file!")
|
||||||
public static String myFile = "";
|
public static String myFile = ""; // The isFile property adds a file picker button
|
||||||
|
|
||||||
@Entry(category = FILES,
|
@Entry(category = FILES,
|
||||||
selectionMode = JFileChooser.DIRECTORIES_ONLY, // The DIRECTORIES_ONLY selectionMode adds a directory picker button
|
selectionMode = JFileChooser.DIRECTORIES_ONLY,
|
||||||
fileChooserType = JFileChooser.OPEN_DIALOG,
|
fileChooserType = JFileChooser.OPEN_DIALOG,
|
||||||
name = "I am a directory!")
|
name = "I am a directory!")
|
||||||
public static String myDirectory = "";
|
public static String myDirectory = ""; // The isDirectory property adds a directory picker button
|
||||||
|
|
||||||
@Entry(category = FILES,
|
@Entry(category = FILES,
|
||||||
selectionMode = JFileChooser.FILES_AND_DIRECTORIES, // The FILES_AND_DIRECTORIES selectionMode adds a file or directory picker button
|
selectionMode = JFileChooser.FILES_AND_DIRECTORIES,
|
||||||
fileExtensions = {"png", "jpg", "jpeg"},
|
fileExtensions = {"png", "jpg", "jpeg"},
|
||||||
fileChooserType = JFileChooser.OPEN_DIALOG,
|
fileChooserType = JFileChooser.OPEN_DIALOG,
|
||||||
name = "I can choose both files & directories!")
|
name = "I can choose both files & directories!")
|
||||||
public static String myFileOrDirectory = "";
|
public static String myFileOrDirectory = ""; // The isFileOrDirectory property adds a file or directory picker button
|
||||||
@Entry(category = FILES,
|
@Entry(category = FILES,
|
||||||
selectionMode = JFileChooser.FILES_AND_DIRECTORIES,
|
selectionMode = JFileChooser.FILES_AND_DIRECTORIES,
|
||||||
fileExtensions = {"png", "jpg", "jpeg"},
|
fileExtensions = {"png", "jpg", "jpeg"},
|
||||||
@@ -114,6 +117,33 @@ public class MidnightConfigExample extends MidnightConfig {
|
|||||||
name = "I am a mf file/directory list!")
|
name = "I am a mf file/directory list!")
|
||||||
public static List<String> fileOrDirectoryList = new ArrayList<>(); // Yes, that's right – you can even have lists of files/directories
|
public static List<String> fileOrDirectoryList = new ArrayList<>(); // Yes, that's right – you can even have lists of files/directories
|
||||||
|
|
||||||
|
@Condition(requiredModId = "midnightlib") // Conditional options are here!
|
||||||
|
@Entry(category = CONDITIONS, name="Turn me on!")
|
||||||
|
public static boolean turnMeOn = false;
|
||||||
|
@Condition(requiredOption = "modid:turnMeOn", visibleButLocked = true)
|
||||||
|
@Entry(category = CONDITIONS, name="Turn me off!")
|
||||||
|
public static Boolean turnMeOff = true;
|
||||||
|
@Condition(requiredOption = "modid:turnMeOff", requiredValue = "false")
|
||||||
|
@Entry(category = CONDITIONS, name="Which is the best modloader?")
|
||||||
|
public static String bestModloader = "";
|
||||||
|
@Condition(requiredOption = "bestModloader", requiredValue = "Forge")
|
||||||
|
@Comment(category = CONDITIONS, name="❌ You have bad taste :(", centered = true) // Don't take this too seriously btw :)
|
||||||
|
public static Comment answerForge; // Comments can also be conditional!
|
||||||
|
@Condition(requiredOption = "bestModloader", requiredValue = "NeoForge")
|
||||||
|
@Comment(category = CONDITIONS, name="⛏ Not quite, but it's alright!", centered = true)
|
||||||
|
public static Comment answerNeoforge;
|
||||||
|
@Condition(requiredOption = "bestModloader", requiredValue = "Fabric")
|
||||||
|
@Comment(category = CONDITIONS, name="⭐ Correct! Fabric (and Quilt) are the best!", centered = true)
|
||||||
|
public static Comment answerFabric;
|
||||||
|
@Condition(requiredOption = "bestModloader", requiredValue = "Quilt")
|
||||||
|
@Comment(category = CONDITIONS, name="⭐ Correct! Quilt (and Fabric) are the best!", centered = true)
|
||||||
|
public static Comment answerQuilt;
|
||||||
|
|
||||||
|
@Condition(requiredOption = "midnightlib:config_screen_list", requiredValue = "FALSE") // Access options of other mods that are also using MidnightLib
|
||||||
|
@Comment(category = CONDITIONS) public static Comment spaceracer;
|
||||||
|
@Condition(requiredOption = "midnightlib:config_screen_list", requiredValue = "FALSE")
|
||||||
|
@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 static int imposter = 16777215; // - Entries without an @Entry or @Comment annotation are ignored
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -151,7 +181,8 @@ The .json language file for your config class could look similar to this:
|
|||||||
"modid.midnightconfig.category.text": "Text",
|
"modid.midnightconfig.category.text": "Text",
|
||||||
"modid.midnightconfig.category.sliders": "Sliders",
|
"modid.midnightconfig.category.sliders": "Sliders",
|
||||||
"modid.midnightconfig.category.lists": "Lists",
|
"modid.midnightconfig.category.lists": "Lists",
|
||||||
"modid.midnightconfig.category.files": "Files"
|
"modid.midnightconfig.category.files": "Files",
|
||||||
|
"modid.midnightconfig.category.conditions": "Quiz"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user