bombsquad-community / plugin-manager

A Plugin Manager for Bombsquad 1.7+
https://bombsquad-community.web.app/pluginmanager
Other
39 stars 28 forks source link

Explore not override the menu ui completely #241

Open rikkolovescats opened 4 months ago

rikkolovescats commented 4 months ago

Right now, we show the plugin manager button (the one with the store icon) in the game's settings window. The way this is currently implemented is in that it completely overwrites the vanilla menu implementation to rebuild the menu with the plugin manager entry in it. This isn't the best way to do it, since if there are any other plugins that want to show their own entry in main menu (similar to plugin manager), then this will end up causing a race condition where which ever plugin gets loaded the last will supersede any parent implementations of the main menu. And in the case if plugin manager is the last plugin to load up, then we'll end up overwriting the previous menu overrides from any earlier loaded plugins.

A better idea should be to override only the very specific methods of the main menu in a way that reuses as much of the vanilla code as possible. Something along these lines say when overriding the _save_state method. The current implementation in plugin manager completely overwrites the parent method: https://github.com/bombsquad-community/plugin-manager/blob/1885090ed09fa19c70a51b2c01755a7894961333/plugin_manager.py#L2526-L2548

Instead, a better approach could be to do something like this:

class NewAllSettingsWindow(AllSettingsWindow):
    ...

    def _save_state(self) -> None:
        sel = self._root_widget.get_selected_child()
        if sel == self._modmgr_button:
            sel_name = 'Mod Manager'
            assert bui.app.classic is not None
            bui.app.ui_v1.window_states[type(self)] = {
                'sel_name': sel_name
            }
        else:
            return super()._save_state()

Still need more exploration here to see if this approach can fit well with when overriding all the other remaining methods in AllSettingsWindow. but the idea here is that such changes will help plugin manager to co-exist with other main menu overriding plugins.