diff --git a/worlds/sc2/client.py b/worlds/sc2/client.py index 57da534c43a2..a1d6728b2e98 100644 --- a/worlds/sc2/client.py +++ b/worlds/sc2/client.py @@ -806,10 +806,8 @@ def on_print_json(self, args: dict) -> None: super(SC2Context, self).on_print_json(args) def run_gui(self) -> None: - from .gui_config import apply_window_defaults - warnings = apply_window_defaults() from .client_gui import start_gui - start_gui(self, warnings) + start_gui(self) async def shutdown(self) -> None: await super(SC2Context, self).shutdown() diff --git a/worlds/sc2/client_gui.py b/worlds/sc2/client_gui.py index 717936497bf5..3c215271b49d 100644 --- a/worlds/sc2/client_gui.py +++ b/worlds/sc2/client_gui.py @@ -136,36 +136,19 @@ class SC2Manager(GameManager): first_mission = "" ctx: SC2Context - def __init__(self, ctx: SC2Context, startup_warnings: List[str]) -> None: + def __init__(self, ctx: SC2Context) -> None: super().__init__(ctx) self.json_to_kivy_parser = SC2JSONtoKivyParser(ctx) - self.startup_warnings = startup_warnings self.minimized = False - from kivy.core.window import Window - Window.bind(on_maximize=self.on_maximize) - Window.bind(on_minimize=self.on_minimize) - Window.bind(on_restore=self.on_restore) def on_start(self) -> None: - super().on_start() - for startup_warning in self.startup_warnings: + from . import gui_config + warnings, window_width, window_height = gui_config.get_window_defaults() + from kivy.core.window import Window + Window.size = window_width, window_height + for startup_warning in warnings: logging.getLogger("Starcraft2").warning(f"Startup WARNING: {startup_warning}") - def on_maximize(self, window) -> None: - SC2World.settings.window_maximized = True - force_settings_save_on_close() - - def on_minimize(self, window) -> None: - self.minimized = True - - def on_restore(self, window) -> None: - if self.minimized: - self.minimized = False - else: - # Restoring from maximized - SC2World.settings.window_maximized = False - force_settings_save_on_close() - def clear_tooltip(self) -> None: if self.ctx.current_tooltip: App.get_running_app().root.remove_widget(self.ctx.current_tooltip) @@ -479,8 +462,8 @@ def get_location_type_title(self, location_type: LocationType) -> str: title += "" return title -def start_gui(context: SC2Context, startup_warnings: List[str]): - context.ui = SC2Manager(context, startup_warnings) +def start_gui(context: SC2Context): + context.ui = SC2Manager(context) context.ui_task = asyncio.create_task(context.ui.async_run(), name="UI") import pkgutil data = pkgutil.get_data(SC2World.__module__, "starcraft2.kv").decode() diff --git a/worlds/sc2/gui_config.py b/worlds/sc2/gui_config.py index 604fcf0c1ffb..5de1ff04f081 100644 --- a/worlds/sc2/gui_config.py +++ b/worlds/sc2/gui_config.py @@ -4,23 +4,12 @@ from .settings import Starcraft2Settings from typing import List -def apply_window_defaults() -> List[str]: +def get_window_defaults() -> List[str]: """ - Set the kivy config keys from the sc2world user settings. - Returns a list of warnings to be printed once the GUI is started. + Gets the window size options from the sc2 settings. + Returns a list of warnings to be printed once the GUI is started, followed by the window width and height """ from . import SC2World - # This is necessary to prevent kivy from failing because it got invalid command-line args, - # or from spamming the logs. - # Must happen before importing kivy.config - import os - import Utils - os.environ["KIVY_NO_CONSOLELOG"] = "1" - os.environ["KIVY_NO_FILELOG"] = "1" - os.environ["KIVY_NO_ARGS"] = "1" - os.environ["KIVY_LOG_ENABLE"] = "0" - if Utils.is_frozen(): - os.environ["KIVY_DATA_DIR"] = Utils.local_path("data") # validate settings warnings: List[str] = [] @@ -35,9 +24,4 @@ def apply_window_defaults() -> List[str]: warnings.append(f"Invalid value for options.yaml key sc2_options.window_width: '{SC2World.settings.window_width}'. Expected a positive integer.") window_width = Starcraft2Settings.window_width - # from kivy.config import Config - # Config.set('graphics', 'width', str(window_width)) - # Config.set('graphics', 'height', str(window_height)) - # if SC2World.settings.window_maximized: - # Config.set('graphics', 'window_state', 'maximized') - return warnings + return warnings, window_width, window_height diff --git a/worlds/sc2/settings.py b/worlds/sc2/settings.py index f49c2eb772de..b065a59de994 100644 --- a/worlds/sc2/settings.py +++ b/worlds/sc2/settings.py @@ -7,12 +7,9 @@ class WindowWidth(int): """The starting width the client window in pixels""" class WindowHeight(int): """The starting height the client window in pixels""" - class StartMaximized(settings.Bool): - """Controls whether the client window should start maximized""" class GameWindowedMode(settings.Bool): """Controls whether the game should start in windowed mode""" window_width = WindowWidth(1080) window_height = WindowHeight(720) - window_maximized: Union[StartMaximized, bool] = False game_windowed_mode: Union[GameWindowedMode, bool] = False