Skip to content

Commit 9a61f80

Browse files
committed
Add onInit and onDeinit functions to visible mod options
1 parent 54939f3 commit 9a61f80

4 files changed

Lines changed: 17 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
- Added new mod option field `noNamePadding` that disables the padding after the option name
1010
- `INPUT_FIELD` can now have a name
11+
- Added optional `onInit` and `onDeinit` functions to visible mod options
1112

1213
### Changed
1314

src/gui/options/option-row.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,18 @@ modmanager.gui.OptionsOptionRow = sc.OptionRow.extend({
8484
this.nameGui?.setPos(baseX, 21)
8585
}
8686
this.hook.setMouseRecord(true)
87+
88+
// @ts-expect-error
89+
option.onInit?.call(option, this.typeGui)
8790
},
8891
updateDrawables(renderer) {
8992
/* fix divider y getting set based of the height instead of just being a predefined value */
9093
/* change here vv */
9194
if (this.divider) renderer.addColor('#545454', 0, 14, this.hook.size.x + 2, 1)
9295
},
96+
hide() {
97+
this.parent()
98+
// @ts-expect-error
99+
this.guiOption.onDeinit?.call(this.guiOption, this.typeGui)
100+
},
93101
})

src/gui/options/tabbox.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ declare global {
3838
updateEntries(this: this, mod: ModEntry): void
3939
createTabs(this: this): void
4040

41+
hideRows(this: this): void
4142
showMenu(this: this): void
4243
hideMenu(this: this): void
4344
_createOptionList(this: this, category: string): void
@@ -344,6 +345,9 @@ modmanager.gui.OptionsTabBox = ig.GuiElementBase.extend({
344345
hideMenu() {
345346
sc.menu.buttonInteract.removeParallelGroup(this.tabGroup)
346347

348+
for (const content of this.tabContent) {
349+
for (const row of content.rows ?? []) row.hide()
350+
}
347351
this.list.deactivate()
348352
this.keyBinder.remove()
349353
sc.keyBinderGui = null

src/mod-options.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ export interface OptionBase<T extends OptionTypes> {
1616

1717
/** Is the option hidden from the menu */
1818
hidden?: T extends OptionVisibleTypes ? boolean | (() => boolean) : never
19+
/** Gets called after the option gets shown */
20+
onInit?: T extends OptionVisibleTypes ? (gui: OptionInstanceType<T>) => void : never
21+
/** Gets called after the option gets hidden */
22+
onDeinit?: T extends OptionVisibleTypes ? (gui: OptionInstanceType<T>) => void : never
1923
}
2024

2125
/** Option that has state that can change */

0 commit comments

Comments
 (0)