aboutsummaryrefslogtreecommitdiff
path: root/src/splitscreen_duo/menu.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/splitscreen_duo/menu.py')
-rw-r--r--src/splitscreen_duo/menu.py45
1 files changed, 35 insertions, 10 deletions
diff --git a/src/splitscreen_duo/menu.py b/src/splitscreen_duo/menu.py
index bd292e7..66c4573 100644
--- a/src/splitscreen_duo/menu.py
+++ b/src/splitscreen_duo/menu.py
@@ -9,11 +9,14 @@ import json
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
-IS_DEVELOPMENT_MODE = os.getenv("DEVELOPMENT", "").lower() != ""
+IS_DEVELOPMENT_MODE = os.getenv("DEVELOPMENT", "") not in ["", "0"]
+ROTATION_ENABLED = not IS_DEVELOPMENT_MODE
OPTIONS = Game.all() + ["Quit"]
logger = logging.getLogger(__name__)
WIDTH = HEIGHT = FONT = screen = selected_index = None
ORIGINAL_WIDTH = ORIGINAL_HEIGHT = None
+rotated_surface = None
+rotation_angle = 0
def init_display():
@@ -31,30 +34,52 @@ def init_display():
def draw_menu(is_joint_mode=False):
- screen.fill(WHITE)
+ global rotated_surface
- is_vertical = HEIGHT > WIDTH * 1.5
+ base_surface = pygame.Surface((WIDTH, HEIGHT))
+
+ base_surface.fill(WHITE)
+
+ is_vertical = is_joint_mode
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))
+ title_text = FONT.render("SplitScreen Duo", True, BLACK)
+ base_surface.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))
+ base_surface.blit(text, (WIDTH // 2 - text.get_width() // 2, start_y + i * spacing))
- screen.blit(text, (WIDTH // 2 - text.get_width() // 2, start_y + i * spacing))
+ if ROTATION_ENABLED and not is_joint_mode and rotation_angle != 0:
+ rotated_surface = pygame.transform.rotate(base_surface, rotation_angle)
+ pos_x = (WIDTH - rotated_surface.get_width()) // 2
+ pos_y = (HEIGHT - rotated_surface.get_height()) // 2
+
+ screen.fill(WHITE)
+ screen.blit(rotated_surface, (pos_x, pos_y))
+ else:
+ screen.blit(base_surface, (0, 0))
pygame.display.flip()
def set_screen_orientation(is_joint_mode):
- global WIDTH, HEIGHT, screen, ORIGINAL_WIDTH, ORIGINAL_HEIGHT
+ global WIDTH, HEIGHT, screen, ORIGINAL_WIDTH, ORIGINAL_HEIGHT, rotation_angle
+
+ instance = os.getenv("INSTANCE", "Unknown")
+ rotation_angle = 0 # Reset rotation angle
if is_joint_mode:
WIDTH = ORIGINAL_WIDTH
HEIGHT = ORIGINAL_HEIGHT * 2
else:
+ if ROTATION_ENABLED and not is_joint_mode:
+ if instance == "primary":
+ rotation_angle = 90 # Primary: Right is down
+ elif instance == "secondary":
+ rotation_angle = -90 # Secondary: Left is down
+
WIDTH = ORIGINAL_WIDTH
HEIGHT = ORIGINAL_HEIGHT
@@ -63,18 +88,19 @@ def set_screen_orientation(is_joint_mode):
pygame.RESIZABLE if IS_DEVELOPMENT_MODE else pygame.FULLSCREEN,
)
- logger.info(f"screen orientation changed to {'vertical' if is_joint_mode else 'horizontal'}")
+ logger.info(f"screen orientation changed: is_joint={is_joint_mode}, rotation={rotation_angle}, instance={instance}")
def process_events(serial, instance, is_joint_mode):
global selected_index
input_handler = Input(debug=IS_DEVELOPMENT_MODE)
+ is_joint_mode_value = is_joint_mode[0] if isinstance(is_joint_mode, list) else is_joint_mode
for event in pygame.event.get():
if event.type == pygame.QUIT:
return {"command": Command.QUIT.value, "action": None, "value": None}
- action = input_handler.get_input(event)
+ action = input_handler.get_input(event, rotation_angle, is_joint_mode_value)
if action == "UP":
selected_index = (selected_index - 1) % len(OPTIONS)
@@ -104,7 +130,6 @@ def process_events(serial, instance, is_joint_mode):
event.type == pygame.KEYDOWN
and event.key == pygame.K_b
and instance == "primary"
- and IS_DEVELOPMENT_MODE
):
is_joint_mode[0] = not is_joint_mode[0]