Skip to content

Commit

Permalink
Merge branch 'sc2-next' into shatter-the-all-in
Browse files Browse the repository at this point in the history
  • Loading branch information
EnvyDragon committed Sep 17, 2024
2 parents f3a6b71 + 0a8071a commit b0a0881
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 51 deletions.
4 changes: 1 addition & 3 deletions worlds/sc2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
33 changes: 8 additions & 25 deletions worlds/sc2/client_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
24 changes: 4 additions & 20 deletions worlds/sc2/gui_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []
Expand All @@ -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
3 changes: 0 additions & 3 deletions worlds/sc2/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b0a0881

Please sign in to comment.