sep-pm-platformer/project/level/selection/OptionsScreenManager.py

52 lines
2.4 KiB
Python
Raw Normal View History

from level.selection.ScreenManager import ScreenManager
from physics.SpriteManager import DrawLayers, SpriteManager
from physics.TickData import TickData
from sprite.PositionScale import PositionScale
from sprite.SpritesheetManager import SpritesheetManager
from ui_elements import CoordinateTransform
from ui_elements.KeyManager import KeyManager
from ui_elements.TextLabel import TextLabel
class OptionsScreenManager(ScreenManager):
def __init__(self, sprite_manager: SpriteManager, spritesheet_manager: SpritesheetManager, main_loop):
super().__init__(sprite_manager, spritesheet_manager, main_loop)
def create_label(self, name: str, x_position, y_position, font_size):
label = TextLabel(name, x_position, y_position, font_size, alignment="left")
self.add_element(DrawLayers.UI, label)
label.position_scale.scale = (1, 1)
self.create_button(name, label)
def create_button(self, name: str, label: TextLabel):
if name == "SMALL":
label.add_click_listener(lambda click: self.make_small_screen(click))
elif name == "MEDIUM":
label.add_click_listener(lambda click: self.make_medium_screen(click))
elif name == "LARGE":
label.add_click_listener(lambda click: self.make_large_screen(click))
def make_small_screen(self, click):
self.main_loop.update_position_scale(PositionScale((0, 0), (1, 1)))
def make_medium_screen(self, click):
self.main_loop.update_position_scale(PositionScale((0, 0), (1.25, 1.25)))
def make_large_screen(self, click):
self.main_loop.update_position_scale(PositionScale((0, 0), (1.5, 1.5)))
def initialize(self):
size = CoordinateTransform.transform_screen_to_world(self.main_loop.window_size,
self.main_loop.screen_transform)
self.create_label("SCREEN SIZE", size[0] * 0.2, size[1] * 0.2, font_size=70)
self.create_label("SMALL", size[0] * 0.15, size[1] * 0.6, font_size=30)
self.create_label("MEDIUM", size[0] * 0.45, size[1] * 0.6, font_size=30)
self.create_label("LARGE", size[0] * 0.75, size[1] * 0.6, font_size=30)
def destroy(self):
super().destroy()
def tick(self, tick_data: TickData):
if tick_data.key_manager.is_keymap_down(KeyManager.KEY_ESCAPE):
self.main_loop.select_main_menu()