Skip to content

Commit 640169d

Browse files
committed
Fix mod menu sometimes opening empty
1 parent b9a8aa8 commit 640169d

3 files changed

Lines changed: 13 additions & 16 deletions

File tree

src/gui/list-entry.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ declare global {
2828
modEntryActionButtons: sc.ButtonGui.Type & { ninepatch: ig.NinePatch }
2929
iconGui: ig.ImageGui
3030

31+
addObservers(this: this): void
32+
removeObservers(this: this): void
3133
updateIcon(this: this, config: ModImageConfig): void
3234
tryDisableMod(this: this, mod: ModEntryLocal): string | undefined
3335
tryEnableMod(this: this, mod: ModEntryLocal): string | undefined
@@ -66,14 +68,14 @@ modmanager.gui.ListEntry = ig.FocusGui.extend({
6668

6769
init(mod, modList) {
6870
this.parent()
71+
6972
this.mod = mod
7073
this.modList = modList
7174

7275
if (!mod.isLocal && mod.testingVersion && ModDB.isModTestingOptIn(mod.id)) {
7376
mod = mod.testingVersion
7477
}
7578

76-
sc.Model.addObserver(modmanager.gui.menu, this)
7779
const isGrid = Opts.isGrid
7880
FileCache.getIconConfig(mod).then(config => this.updateIcon(config))
7981

@@ -171,6 +173,12 @@ modmanager.gui.ListEntry = ig.FocusGui.extend({
171173
}
172174
this.updateHighlightWidth()
173175
},
176+
onAttach() {
177+
sc.Model.addObserver(modmanager.gui.menu, this)
178+
},
179+
onDetach() {
180+
sc.Model.removeObserver(modmanager.gui.menu, this)
181+
},
174182
updateIcon(config) {
175183
const image = new ig.Image(config.path)
176184
this.iconGui = new ig.ImageGui(image, config.offsetX, config.offsetY, config.sizeX, config.sizeY)

src/gui/list.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ declare global {
7878
}
7979
}
8080

81-
export const modMenuListWidth = 552
81+
const modMenuListWidth = 552
8282
const modMenuListHeight = 240
8383

8484
modmanager.gui.MenuList = sc.ListTabbedPane.extend({
@@ -206,8 +206,8 @@ modmanager.gui.MenuList = sc.ListTabbedPane.extend({
206206
return { skipSounds: true }
207207
},
208208
onContentCreation(index, settings) {
209-
this.currentList && this.currentList.clear()
210-
this.currentGroup && this.currentGroup.clear()
209+
if (this.currentList) this.currentList.clear()
210+
if (this.currentGroup) this.currentGroup.clear()
211211
return this.parent(index, settings)
212212
},
213213
onCreateListEntries(list, buttonGroup) {

src/gui/menu.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ sc.Control.inject({
130130
},
131131
})
132132

133-
let menuPurgeTimeoutId: NodeJS.Timeout
134133
modmanager.gui.Menu = sc.ListInfoMenu.extend({
135134
observers: [],
136135
init() {
@@ -460,7 +459,6 @@ modmanager.gui.Menu = sc.ListInfoMenu.extend({
460459
if (main?.topBar) main.topBar.doStateTransition(state)
461460
},
462461
showMenu() {
463-
clearTimeout(menuPurgeTimeoutId)
464462
this.parent()
465463
sc.menu.pushBackCallback(() => this.onBackButtonPress())
466464
sc.menu.moveLeaSprite(0, 0, sc.MENU_LEA_STATE.HIDDEN)
@@ -490,7 +488,7 @@ modmanager.gui.Menu = sc.ListInfoMenu.extend({
490488

491489
new modmanager.gui.ManualEnforcer('ModManagerManual', Lang.help.title, Lang.help.pages)
492490
},
493-
hideMenu(_afterSubmenu, nextSubmenu) {
491+
hideMenu() {
494492
this.parent()
495493
sc.menu.moveLeaSprite(0, 0, sc.MENU_LEA_STATE.LARGE)
496494
this.exitMenu()
@@ -520,15 +518,6 @@ modmanager.gui.Menu = sc.ListInfoMenu.extend({
520518
})
521519
}
522520

523-
if (nextSubmenu != sc.MENU_SUBMENU.MOD_OPTIONS) {
524-
/* purging the menu immediately would disable the smooth fade out transition */
525-
menuPurgeTimeoutId = setTimeout(() => {
526-
const main = sc.menu.guiReference
527-
main.removeChildGui(this)
528-
this.removeObservers()
529-
delete main.submenus[modsMenuId]
530-
}, 1000)
531-
}
532521
},
533522
onBackButtonPress() {
534523
sc.menu.popBackCallback()

0 commit comments

Comments
 (0)