Skip to content

Commit 4541fec

Browse files
authored
config: Add capability to disable/hide config options (#594)
This adds two optional properties to config options, `disabled` and `hidden`, that can access the values of other config options in the config group and programmatically be hidden or disabled as other config options change. Essentially, this allows the ability to create "child" config options that will only appear or only be modifiable if their "parent" is set a certain way. I originally had a stronger use case for this with some FRU p4 stuff I was working on, but I figured out an alternative way to do it without needing configs. I was going to shelve this, but someone in discord recently requested an option to have relative (vs. true) directions called out for P3 Ultimate Relativity, so there is at least a potential use for this now. Some completely made up mockups below to illustrate: Parent Strat is `none`, so both sub-options are hidden: ![demo1](https://github.com/user-attachments/assets/e41733ab-0e21-4552-8ae3-ad0b438a7a01) Parent strat set; both sub-options visible; but checkbox is false, so the final sub-option is disabled: ![demo2](https://github.com/user-attachments/assets/2d1510a0-7dfb-410f-a67b-4b21991fc9f5) Checkbox now true, so the final sub-option is enabled: ![demo3](https://github.com/user-attachments/assets/ed7492d5-fce6-4563-a515-010be922d6dc)
1 parent 39251c6 commit 4541fec

File tree

4 files changed

+257
-74
lines changed

4 files changed

+257
-74
lines changed

docs/RaidbossGuide.md

+12
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ By default, you should not pick a particular strategy if there are multiple.
8080

8181
See: [P12S](../ui/raidboss/data/06-ew/raid/p12s.ts) for an example of many different tower and classical concept options.
8282

83+
You can also use the `disabled` and/or `hidden` properties to programmatically hide or disable options based on the values of other options.
84+
This allows you to effectively create sub-options that will only appear or be modifiable if the "parent" option is set to a particular value.
85+
8386
TODO: update this guide to explain the structure of the config section better
8487

8588
### Trigger Implementation Guidelines for Developers
@@ -130,6 +133,15 @@ export default {
130133
},
131134
type: 'checkbox',
132135
default: false,
136+
// optional properties below
137+
disabled: (values) => {
138+
// code that returns true or false; if true, the input field will be disabled in the UI
139+
// can access current values of other config options via values.[id of config option]
140+
},
141+
hidden: (values) => {
142+
// code that returns true or false; if true, the config text and input will be hidden in the UI
143+
// can access current values of other config options via values.[id of config option]
144+
},
133145
},
134146
],
135147
resetWhenOutOfCombat: true,

resources/user_config.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ export type UserFileCallback = (
5656
basePath: string,
5757
) => void;
5858
export type ConfigValue = string | number | boolean;
59+
// Map of config ids to current value
60+
export type ConfigIdToValueMap = { [id: string]: ConfigValue };
61+
// Map of ConfigEntries to an array containing the leftDiv and inputDiv elements
62+
export type ConfigEntryToDivMap = Map<ConfigEntry, [HTMLElement, HTMLElement]>;
5963
export type ConfigEntry = {
6064
id: string;
6165
comment?: Partial<LocaleText>;
@@ -65,6 +69,10 @@ export type ConfigEntry = {
6569
// This must be a valid option even if there is a setterFunc, as `_getOptionLeafHelper`
6670
// for the config ui reads from the SavedConfig directly rather than post-setterFunc.
6771
default: ConfigValue | ((options: BaseOptions) => ConfigValue);
72+
// If true, the leftDiv and inputDiv will be shown, but inputs in the inputDiv will be disabled.
73+
disabled?: (values: ConfigIdToValueMap) => boolean;
74+
// If true, both the leftDiv and the inputDiv will be hidden.
75+
hidden?: (values: ConfigIdToValueMap) => boolean;
6876
debug?: boolean;
6977
debugOnly?: boolean;
7078
// For select.
@@ -81,8 +89,12 @@ export type ConfigEntry = {
8189
) => ConfigValue | void | undefined;
8290
};
8391

84-
export interface NamedConfigEntry<NameUnion> extends Omit<ConfigEntry, 'id'> {
92+
export type NamedConfigIdToValueMap<NameUnion extends string> = Record<NameUnion, ConfigValue>;
93+
export interface NamedConfigEntry<NameUnion extends string>
94+
extends Omit<ConfigEntry, 'id' | 'disabled' | 'hidden'> {
8595
id: NameUnion;
96+
disabled?: (values: NamedConfigIdToValueMap<NameUnion>) => boolean;
97+
hidden?: (values: NamedConfigIdToValueMap<NameUnion>) => boolean;
8698
}
8799

88100
export type OptionsTemplate = {

0 commit comments

Comments
 (0)