From 417c28bd6063c206e41945058c574cdef3b3e435 Mon Sep 17 00:00:00 2001 From: Mike Date: Tue, 28 Mar 2023 10:13:03 +0200 Subject: [PATCH] add next steps for level menu --- project/main.py | 6 +++--- project/ui_elements/LevelMenu.py | 11 ++++++++++- project/ui_elements/UiElement.py | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/project/main.py b/project/main.py index e3feb6f..9abf09e 100644 --- a/project/main.py +++ b/project/main.py @@ -18,7 +18,7 @@ from ui_elements.KeyManager import KeyManager from ui_elements.LevelMenu import LevelMenu from ui_elements.TextLabel import TextLabel -what_to_run = 'level' +what_to_run = 'menu' def apply_frame_rate(number: float): @@ -77,8 +77,8 @@ if what_to_run == 'menu': if event.type == pygame.QUIT: pygame.quit() quit() - elif event.type == pygame.MOUSEBUTTONDOWN: - generated_level.load_level(parsed_levels_manager.levels[0]) + # elif event.type == pygame.MOUSEBUTTONDOWN: + # generated_level.load_level(parsed_levels_manager.levels[0]) screen.fill((0, 0, 0)) # level_menu.draw(screen, screen_transform) diff --git a/project/ui_elements/LevelMenu.py b/project/ui_elements/LevelMenu.py index a650dbf..ca8dd4d 100644 --- a/project/ui_elements/LevelMenu.py +++ b/project/ui_elements/LevelMenu.py @@ -1,4 +1,9 @@ +import copy + +import pygame + from level.Level import Level +from ui_elements.ClickEvent import ClickEvent from ui_elements.TextLabel import TextLabel @@ -24,7 +29,7 @@ class LevelMenu: text_label = TextLabel(level.name, current_text_label_x, current_text_label_y, 60) text_label.position_scale.scale = (0.5, 0.5) # text_label = TextLabel(self.extract_level(level.name), current_text_label_x, current_text_label_y, 35) - text_label.add_click_listener(lambda: self.level_select_listener(level)) + text_label.add_click_listener(lambda click_event: self.handle_level_text_label_click(click_event, level)) self.level_text_labels.append(text_label) if (index + 1) % self.column_count == 0: @@ -33,5 +38,9 @@ class LevelMenu: else: current_text_label_x += self.width / self.column_count + def handle_level_text_label_click(self, click_event: ClickEvent, level: Level): + if click_event.event.type == pygame.MOUSEBUTTONUP: + self.level_select_listener(level) + def extract_level(self): return self diff --git a/project/ui_elements/UiElement.py b/project/ui_elements/UiElement.py index 664e21e..22cb598 100644 --- a/project/ui_elements/UiElement.py +++ b/project/ui_elements/UiElement.py @@ -29,7 +29,7 @@ class UiElement: def click(self, click_event): for listener in self.click_listeners: - listener(self, click_event) + listener(click_event) @abc.abstractmethod def tick(self, tick_data: TickData):