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

41 lines
1.6 KiB
Python

from abc import abstractmethod
from level.selection.ScreenManager import ScreenManager
from physics.SpriteManager import SpriteManager, DrawLayers
from physics.TickData import TickData
from sprite.SpritesheetManager import SpritesheetManager
from ui_elements import CoordinateTransform
from ui_elements.KeyManager import KeyManager
from ui_elements.TextLabel import TextLabel
from ui_elements.ClickEvent import ClickEvent
class MainMenuScreenManager(ScreenManager):
def __init__(self, sprite_manager: SpriteManager, spritesheet_manager: SpritesheetManager, main_loop):
super().__init__(sprite_manager, spritesheet_manager, main_loop)
def go_to_menu(self, click):
if click.is_click_down(ClickEvent.CLICK_LEFT):
self.main_loop.select_level_selection()
def go_to_options_screen(self, click):
self.destroy()
def initialize(self):
size = CoordinateTransform.transform_screen_to_world(self.main_loop.window_size, self.main_loop.screen_transform)
self.create_button("START", size[0] * 0.5, size[1] * 0.5)
self.create_button("OPTIONS", size[0] * 0.5, size[1] * 0.65)
def create_button(self, name: str, x_position, y_position):
label = TextLabel(name, x_position, y_position, font_size=70, alignment="center")
self.add_element(DrawLayers.UI, label)
label.position_scale.scale = (1, 1)
if name == "START":
label.add_click_listener(lambda click: self.go_to_menu(click))
elif name == "OPTIONS":
label.add_click_listener(lambda click: self.go_to_options_screen(click))
def destroy(self):
super().destroy()