fix position of text labels in LevelMenu
parent
121dbb31f9
commit
070aa5497a
|
@ -17,7 +17,7 @@ from ui_elements.KeyManager import KeyManager
|
||||||
from ui_elements.LevelMenu import LevelMenu
|
from ui_elements.LevelMenu import LevelMenu
|
||||||
from ui_elements.TextLabel import TextLabel
|
from ui_elements.TextLabel import TextLabel
|
||||||
|
|
||||||
what_to_run = 'level'
|
what_to_run = 'menu'
|
||||||
|
|
||||||
|
|
||||||
def apply_frame_rate(number: float):
|
def apply_frame_rate(number: float):
|
||||||
|
@ -33,8 +33,10 @@ def apply_frame_rate(number: float):
|
||||||
if what_to_run == 'menu':
|
if what_to_run == 'menu':
|
||||||
screen_transform = PositionScale((0, 0), (1.5, 1.5))
|
screen_transform = PositionScale((0, 0), (1.5, 1.5))
|
||||||
|
|
||||||
|
screen_height = 12 * 40 * 1.5
|
||||||
|
screen_width = 12 * 71 * 1.5
|
||||||
pygame.init()
|
pygame.init()
|
||||||
screen = pygame.display.set_mode((12 * 71 * 1.5, 12 * 40 * 1.5))
|
screen = pygame.display.set_mode((screen_width, screen_height))
|
||||||
pygame.display.set_caption("PM GAME")
|
pygame.display.set_caption("PM GAME")
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
frame_rate = 30
|
frame_rate = 30
|
||||||
|
@ -48,7 +50,9 @@ if what_to_run == 'menu':
|
||||||
|
|
||||||
generated_level = LoadedLevel(sprite_manager, spritesheet_manager)
|
generated_level = LoadedLevel(sprite_manager, spritesheet_manager)
|
||||||
|
|
||||||
level_menu = LevelMenu(parsed_levels_manager.levels, 0, 0)
|
level_menu_width = screen_width / 2
|
||||||
|
level_menu_height = screen_height / 2
|
||||||
|
level_menu = LevelMenu(parsed_levels_manager.levels, 0, 0, level_menu_width, level_menu_height, 3)
|
||||||
level_menu.level_select_listener = lambda selected_level: print(selected_level.name, "selected")
|
level_menu.level_select_listener = lambda selected_level: print(selected_level.name, "selected")
|
||||||
# generated_level.load_level(selected_level)
|
# generated_level.load_level(selected_level)
|
||||||
|
|
||||||
|
@ -79,7 +83,8 @@ elif what_to_run == 'level':
|
||||||
screen_transform = PositionScale((0, 0), (1.5, 1.5))
|
screen_transform = PositionScale((0, 0), (1.5, 1.5))
|
||||||
|
|
||||||
pygame.init()
|
pygame.init()
|
||||||
screen = pygame.display.set_mode((12 * ConstantsParser.CONFIG.level_size[0] * screen_transform.scale[0], 12 * ConstantsParser.CONFIG.level_size[1] * screen_transform.scale[1]))
|
screen = pygame.display.set_mode((12 * ConstantsParser.CONFIG.level_size[0] * screen_transform.scale[0],
|
||||||
|
12 * ConstantsParser.CONFIG.level_size[1] * screen_transform.scale[1]))
|
||||||
pygame.display.set_caption("PM GAME")
|
pygame.display.set_caption("PM GAME")
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
frame_rate = 30
|
frame_rate = 30
|
||||||
|
|
|
@ -4,12 +4,15 @@ from ui_elements.TextLabel import TextLabel
|
||||||
|
|
||||||
class LevelMenu:
|
class LevelMenu:
|
||||||
|
|
||||||
def __init__(self, levels: [Level], x_pos: int, y_pos: int):
|
def __init__(self, levels: [Level], x_pos: int, y_pos: int, width: float, height: float, column_count: int):
|
||||||
self.levels = levels
|
self.levels = levels
|
||||||
self.x_pos = x_pos
|
self.x_pos = x_pos
|
||||||
self.y_pos = y_pos
|
self.y_pos = y_pos
|
||||||
self.level_select_listener = lambda selected_level: None
|
self.level_select_listener = lambda selected_level: None
|
||||||
self.level_text_labels = []
|
self.level_text_labels = []
|
||||||
|
self.width = width
|
||||||
|
self.height = height
|
||||||
|
self.column_count = column_count
|
||||||
|
|
||||||
self.create_level_text_labels()
|
self.create_level_text_labels()
|
||||||
|
|
||||||
|
@ -18,19 +21,16 @@ class LevelMenu:
|
||||||
current_text_label_y = self.y_pos
|
current_text_label_y = self.y_pos
|
||||||
|
|
||||||
for index, level in enumerate(self.levels):
|
for index, level in enumerate(self.levels):
|
||||||
# name=extraxt_level(level.name)
|
|
||||||
text_label = TextLabel(level.name, current_text_label_x, current_text_label_y, 35)
|
text_label = TextLabel(level.name, current_text_label_x, current_text_label_y, 35)
|
||||||
|
# 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: self.level_select_listener(level))
|
||||||
|
self.level_text_labels.append(text_label)
|
||||||
|
|
||||||
if (index + 1) % 3 == 0:
|
if (index + 1) % self.column_count == 0:
|
||||||
current_text_label_y += text_label.current_height + text_label.current_height / 4
|
current_text_label_y += self.height / (len(self.levels) / self.column_count)
|
||||||
current_text_label_x = self.x_pos
|
current_text_label_x = self.x_pos
|
||||||
else:
|
else:
|
||||||
current_text_label_x += text_label.current_width + text_label.current_width / 3
|
current_text_label_x += self.width / self.column_count
|
||||||
self.level_text_labels.append(text_label)
|
|
||||||
if current_text_label_x % 10 != 0:
|
|
||||||
current_text_label_x = current_text_label_x + current_text_label_x % 10
|
|
||||||
# menu_labels.append(text_label)
|
|
||||||
|
|
||||||
def extract_level(name):
|
def extract_level(name):
|
||||||
return name
|
return name
|
||||||
|
|
Loading…
Reference in New Issue