diff options
| author | Zoltan Szabatin <[email protected]> | 2025-05-14 21:36:56 -0700 |
|---|---|---|
| committer | Zoltan Szabatin <[email protected]> | 2025-05-14 21:36:56 -0700 |
| commit | 70a4c41a75275be6050683191e05ec1cb693ffce (patch) | |
| tree | ffa5257b21e227e17ab65d0ead0dd2851f22c97e /src/splitscreen_duo/menu.py | |
| parent | switched from usb hid to cdc (diff) | |
| download | splitscreen-duo-70a4c41a75275be6050683191e05ec1cb693ffce.tar.xz splitscreen-duo-70a4c41a75275be6050683191e05ec1cb693ffce.zip | |
Diffstat (limited to 'src/splitscreen_duo/menu.py')
| -rw-r--r-- | src/splitscreen_duo/menu.py | 45 |
1 files changed, 37 insertions, 8 deletions
diff --git a/src/splitscreen_duo/menu.py b/src/splitscreen_duo/menu.py index 18dcca6..bd292e7 100644 --- a/src/splitscreen_duo/menu.py +++ b/src/splitscreen_duo/menu.py @@ -13,15 +13,15 @@ IS_DEVELOPMENT_MODE = os.getenv("DEVELOPMENT", "").lower() != "" OPTIONS = Game.all() + ["Quit"] logger = logging.getLogger(__name__) WIDTH = HEIGHT = FONT = screen = selected_index = None +ORIGINAL_WIDTH = ORIGINAL_HEIGHT = None def init_display(): - global WIDTH, HEIGHT, FONT, screen, selected_index + global WIDTH, HEIGHT, FONT, screen, selected_index, ORIGINAL_WIDTH, ORIGINAL_HEIGHT - WIDTH, HEIGHT = ( - pygame.display.Info().current_w // 2, - pygame.display.Info().current_h // 2, - ) + ORIGINAL_WIDTH = pygame.display.Info().current_w // 2 + ORIGINAL_HEIGHT = pygame.display.Info().current_h // 2 + WIDTH, HEIGHT = ORIGINAL_WIDTH, ORIGINAL_HEIGHT FONT = pygame.font.Font(None, 36) screen = pygame.display.set_mode( (WIDTH, HEIGHT) if IS_DEVELOPMENT_MODE else (0, 0), @@ -30,17 +30,41 @@ def init_display(): selected_index = 0 -def draw_menu(): +def draw_menu(is_joint_mode=False): screen.fill(WHITE) + is_vertical = HEIGHT > WIDTH * 1.5 + start_y = 100 if is_vertical else 150 + spacing = 40 if is_vertical else 50 + title_text = FONT.render("SplitScreen Duo", True, BLACK) + + screen.blit(title_text, (WIDTH // 2 - title_text.get_width() // 2, start_y - 50)) + for i, option in enumerate(OPTIONS): text = FONT.render(option, True, BLACK if i != selected_index else (200, 0, 0)) - screen.blit(text, (WIDTH // 2 - text.get_width() // 2, 150 + i * 50)) + screen.blit(text, (WIDTH // 2 - text.get_width() // 2, start_y + i * spacing)) pygame.display.flip() +def set_screen_orientation(is_joint_mode): + global WIDTH, HEIGHT, screen, ORIGINAL_WIDTH, ORIGINAL_HEIGHT + + if is_joint_mode: + WIDTH = ORIGINAL_WIDTH + HEIGHT = ORIGINAL_HEIGHT * 2 + else: + WIDTH = ORIGINAL_WIDTH + HEIGHT = ORIGINAL_HEIGHT + + screen = pygame.display.set_mode( + (WIDTH, HEIGHT) if IS_DEVELOPMENT_MODE else (0, 0), + pygame.RESIZABLE if IS_DEVELOPMENT_MODE else pygame.FULLSCREEN, + ) + + logger.info(f"screen orientation changed to {'vertical' if is_joint_mode else 'horizontal'}") + def process_events(serial, instance, is_joint_mode): global selected_index @@ -84,7 +108,10 @@ def process_events(serial, instance, is_joint_mode): ): is_joint_mode[0] = not is_joint_mode[0] - logger.info(f"Toggled joint mode to {is_joint_mode[0]}") + if instance == "primary": + set_screen_orientation(is_joint_mode[0]) + + logger.info(f"toggled joint mode to {is_joint_mode[0]}") command = ( Command.ENTER_JOINT_MODE.value @@ -94,4 +121,6 @@ def process_events(serial, instance, is_joint_mode): serial.write(json.dumps({"command": command}).encode("utf-8")) + draw_menu(is_joint_mode[0] if isinstance(is_joint_mode, list) else is_joint_mode) + return None |