43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
from states.game_state import GameState
|
|
from widgets.button import Button
|
|
from widgets.switch import Switch
|
|
import pygame
|
|
|
|
class SettingsMenu(GameState):
|
|
def __init__(self, switch_state_callback, context):
|
|
super().__init__(switch_state_callback, context)
|
|
|
|
# Buttons
|
|
self.back_button = Button(10, 10, 50, 50, lambda: self.switch_state("start_menu"))
|
|
self.back_button.set_text("Back")
|
|
|
|
self.show_yaw_text = self.font.render("Show Yaw: ", True, (255, 255, 255))
|
|
self.show_yaw_button = Switch(100, 100, 50, 50, self.options["show_yaw"])
|
|
|
|
def handle_events(self, events):
|
|
"""Handles user inputs."""
|
|
for event in events:
|
|
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
|
|
self.switch_state("start_menu")
|
|
self.show_yaw_button.handle_event(event)
|
|
self.back_button.handle_event(event)
|
|
|
|
def update(self):
|
|
"""Updates settings based on user input."""
|
|
if self.show_yaw_button.get_is_toggled():
|
|
self.options["show_yaw"] = True
|
|
else:
|
|
self.options["show_yaw"] = False
|
|
|
|
# Save settings to context
|
|
self.context["options"] = self.options
|
|
|
|
def draw(self):
|
|
"""Renders the settings menu."""
|
|
self.screen.fill((30, 30, 30)) # Clear screen
|
|
self.screen.blit(self.show_yaw_text, (self.show_yaw_button.x + self.show_yaw_button.width + 10,
|
|
self.show_yaw_button.y))
|
|
self.show_yaw_button.draw(self.screen)
|
|
self.back_button.draw(self.screen)
|
|
|