Modding:Options: Difference between revisions
Kernelmethod (talk | contribs) m Make the Options class static in the provided example |
Kernelmethod (talk | contribs) m Improvements to the code examples |
||
Line 4: | Line 4: | ||
==Adding new options== | ==Adding new options== | ||
In some cases it may be desirable to add tunable settings to your mod | In some cases it may be desirable to add tunable settings to your mod to allow players to configure it to their liking. In these cases, you can piggyback off of Qud's built in options menu by merging your own settings into <code>Options.xml</code>. | ||
Here's an example of a custom <code>Options.xml</code>: | Here's an example of a custom <code>Options.xml</code>: | ||
Line 12: | Line 12: | ||
<options> | <options> | ||
<option ID="Option_MyName_MyMod_EnableFoo" DisplayText="Enable Foo" | <option ID="Option_MyName_MyMod_EnableFoo" DisplayText="Enable Foo" | ||
Category="Mods: MyMod" Type="Checkbox" Default="Yes" | Category="Mods: MyMod" Type="Checkbox" Default="Yes" /> | ||
<option ID="Option_MyName_MyMod_FooSelector" DisplayText="Foo, Bar, or Baz?" | <option ID="Option_MyName_MyMod_FooSelector" DisplayText="Foo, Bar, or Baz?" | ||
Category="Mods: MyMod" Type="Combo" Default="Foo" | Category="Mods: MyMod" Type="Combo" Default="Foo" /> | ||
</options> | </options> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 22: | Line 22: | ||
[[Image:Modding-Options example.png|center|600px|alt=Example of custom settings added to the Options menu by a mod. This settings menu includes three new options: a checkbox for "Enable Foo", a combo selector for "Foo, Bar, or Baz?", and a slider labeled "Amount of foo to use".]] | [[Image:Modding-Options example.png|center|600px|alt=Example of custom settings added to the Options menu by a mod. This settings menu includes three new options: a checkbox for "Enable Foo", a combo selector for "Foo, Bar, or Baz?", and a slider labeled "Amount of foo to use".]] | ||
The <code><option | The <code><option/></code> XML tag defines a new setting in <code>Options.xml</code>. This tag can have the following attributes: | ||
{| class="wikitable" style="min-width: 50%;" | {| class="wikitable" style="min-width: 50%;" | ||
Line 66: | Line 66: | ||
public static class Options { | public static class Options { | ||
private static string GetOption(string ID, string Default = "") { | private static string GetOption(string ID, string Default = "") { | ||
return XRL.UI.Options.GetOption(ID, Default); | return XRL.UI.Options.GetOption(ID, Default: Default); | ||
} | } | ||
Revision as of 10:18, 18 July 2024
![]() |
This page is about modding. See the modding overview for an abstract on modding. |
Adding new options
In some cases it may be desirable to add tunable settings to your mod to allow players to configure it to their liking. In these cases, you can piggyback off of Qud's built in options menu by merging your own settings into Options.xml
.
Here's an example of a custom Options.xml
:
<?xml version="1.0" encoding="utf-8" ?>
<options>
<option ID="Option_MyName_MyMod_EnableFoo" DisplayText="Enable Foo"
Category="Mods: MyMod" Type="Checkbox" Default="Yes" />
<option ID="Option_MyName_MyMod_FooSelector" DisplayText="Foo, Bar, or Baz?"
Category="Mods: MyMod" Type="Combo" Default="Foo" />
</options>
This produces a new section in the options menu, which appears as follows:

The <option/>
XML tag defines a new setting in Options.xml
. This tag can have the following attributes:
Tag | Meaning |
---|---|
ID
|
A unique ID corresponding to the option. This ID is referred to in the code when retrieving the value of the configured setting. |
DisplayText
|
The text that should be displayed alongside the option in the settings menu. |
Category
|
The area under which the option appears in the settings menu. In general, all of your options should go under a single custom category for your mod. |
Type
|
Affects the widget that is rendered for the option, and the values that it can take on. The following widget types are currently supported:
Each of these types has custom attributes that are specific to them; refer to the base game's |
Default
|
The default value that the option should be set to, before any user configuration. |
Requires
|
Hides an option unless a precondition is met. For instance, adding Requires="MyName_MyMod_EnableFoo==Yes" to an option will hide that option unless the checkbox for the "Enable Foo" option is selected.
|
SearchKeywords
|
Additional keywords that players can use to find an option in the settings menu. |
Using configured options in code
Once you've added your own custom options, you can retrieve them in code using the XRL.UI.Options.GetOption
method. This method always returns a string, but you may want to convert them into a different type before using them in your code. One way of doing so is to create a thin wrapper around XRL.UI.Options
that calls GetOption
under the hood, for instance:
using System;
namespace MyName.MyMod {
public static class Options {
private static string GetOption(string ID, string Default = "") {
return XRL.UI.Options.GetOption(ID, Default: Default);
}
public static bool EnableFoo => GetOption("Option_MyName_MyMod_EnableFoo").EqualsNoCase("Yes");
public static int FooAmount => Convert.ToInt32(GetOption("Option_MyName_MyMod_FooAmount"));
}
}
Enabling and disabling XML
Options are not natively supported by the game for conditionally enabling or disabling behavior in XML. For example, there isn't a way to configure the game only to merge into an object's blueprint if a given option is enabled. For one possible solution to this problem, check out the submodule-management mod.
|