How do I destroy a GUI on load after a mod update?
Posted: Tue Apr 19, 2016 11:16 pm
I have a mod that creates a GUI with a bunch of buttons on it. However, in a newer version, I changed the buttons to checkboxes. This means the new styles are checkbox_styles, not button_styles.
The problem is that when the game is saved it saves GUIs in the save file. So if the user saved the game with the GUI open, when they load the game after updating the module, the game tries to create buttons, but the new styles are for checkboxes. Therefore the new styles are incompatible, the game pops up an error dialog and exits completely, and the user has no way to load their game unless they downgrade the module, open the game, close the GUI, save it, then upgrade. Which... yeah.
So my question is, how can I destroy the GUI before it loads, so that if I make a module update that makes style changes incompatible with the old GUI, the saved old GUI doesn't crash the game?
I can't do it in on_init because that function isn't called at the right times.
I can't do it in on_load because there's no access to 'game' there, and the GUI is stored with game.player.
I can't do it in on_configuration_changed because that happens after the GUI is loaded from the save, so it doesn't solve the problem.
The only option I can really think of is to keep the old styles around for compatibility and give the new styles different names, but I really don't like the idea of lugging these old styles around for all eternity just to support users who may be updating from an older incompatible version who saved the game with the GUI open. (The other problem with that is my styles are actually programatically generated based on the game's item prototypes, since this is the only way to put game icons on GUI's, really, so if an item is removed in the future I can't even guarantee that all the old compatibility styles will stick around.)
How can I stop this from happening?
The problem is that when the game is saved it saves GUIs in the save file. So if the user saved the game with the GUI open, when they load the game after updating the module, the game tries to create buttons, but the new styles are for checkboxes. Therefore the new styles are incompatible, the game pops up an error dialog and exits completely, and the user has no way to load their game unless they downgrade the module, open the game, close the GUI, save it, then upgrade. Which... yeah.
So my question is, how can I destroy the GUI before it loads, so that if I make a module update that makes style changes incompatible with the old GUI, the saved old GUI doesn't crash the game?
I can't do it in on_init because that function isn't called at the right times.
I can't do it in on_load because there's no access to 'game' there, and the GUI is stored with game.player.
I can't do it in on_configuration_changed because that happens after the GUI is loaded from the save, so it doesn't solve the problem.
The only option I can really think of is to keep the old styles around for compatibility and give the new styles different names, but I really don't like the idea of lugging these old styles around for all eternity just to support users who may be updating from an older incompatible version who saved the game with the GUI open. (The other problem with that is my styles are actually programatically generated based on the game's item prototypes, since this is the only way to put game icons on GUI's, really, so if an item is removed in the future I can't even guarantee that all the old compatibility styles will stick around.)
How can I stop this from happening?