Allowed for user input using key arrows
parent
95be2902b1
commit
969c040e88
|
@ -1,5 +1,7 @@
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
import pygame.time
|
||||||
|
|
||||||
from level.Level import Level
|
from level.Level import Level
|
||||||
from level.LevelManager import LevelManager
|
from level.LevelManager import LevelManager
|
||||||
from level.selection.ScreenManager import ScreenManager
|
from level.selection.ScreenManager import ScreenManager
|
||||||
|
@ -31,13 +33,15 @@ class LevelSelectionScreenManager(ScreenManager):
|
||||||
|
|
||||||
self.selected_theme = self.themes[0]
|
self.selected_theme = self.themes[0]
|
||||||
|
|
||||||
def select_next_theme(self, click: ClickEvent):
|
self.key_input_delay = -1
|
||||||
if click.is_click_down(ClickEvent.CLICK_LEFT):
|
|
||||||
|
def select_next_theme(self, click=None):
|
||||||
|
if click is None or click.is_click_down(ClickEvent.CLICK_LEFT):
|
||||||
index = (self.themes.index(self.selected_theme) + 1) % len(self.themes)
|
index = (self.themes.index(self.selected_theme) + 1) % len(self.themes)
|
||||||
self.select_theme(self.themes[index])
|
self.select_theme(self.themes[index])
|
||||||
|
|
||||||
def select_prev_theme(self, click):
|
def select_prev_theme(self, click=None):
|
||||||
if click.is_click_down(ClickEvent.CLICK_LEFT):
|
if click is None or click.is_click_down(ClickEvent.CLICK_LEFT):
|
||||||
index = self.themes.index(self.selected_theme) - 1
|
index = self.themes.index(self.selected_theme) - 1
|
||||||
if index < 0:
|
if index < 0:
|
||||||
index = len(self.themes) - 1
|
index = len(self.themes) - 1
|
||||||
|
@ -53,14 +57,14 @@ class LevelSelectionScreenManager(ScreenManager):
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
arrow_left = StaticSprite(self.spritesheet_manager.get_sheet('ui_arrow'))
|
arrow_left = StaticSprite(self.spritesheet_manager.get_sheet('ui_arrow'))
|
||||||
arrow_left.set_animation_state('left')
|
arrow_left.set_animation_state('right')
|
||||||
arrow_left.position_scale = PositionScale((OFFSET[0], OFFSET[1]), (3, 3))
|
arrow_left.position_scale = PositionScale((OFFSET[0], OFFSET[1]), (1.8, 1.8))
|
||||||
arrow_left.add_click_listener(self.select_prev_theme)
|
arrow_left.add_click_listener(self.select_prev_theme)
|
||||||
self.add_element(DrawLayers.UI, arrow_left)
|
self.add_element(DrawLayers.UI, arrow_left)
|
||||||
|
|
||||||
arrow_right = StaticSprite(self.spritesheet_manager.get_sheet('ui_arrow'))
|
arrow_right = StaticSprite(self.spritesheet_manager.get_sheet('ui_arrow'))
|
||||||
arrow_right.set_animation_state('right')
|
arrow_right.set_animation_state('left')
|
||||||
arrow_right.position_scale = PositionScale((OFFSET[0] + 50, OFFSET[1]), (3, 3))
|
arrow_right.position_scale = PositionScale((OFFSET[0] + 50, OFFSET[1]), (1.8, 1.8))
|
||||||
arrow_right.add_click_listener(self.select_next_theme)
|
arrow_right.add_click_listener(self.select_next_theme)
|
||||||
self.add_element(DrawLayers.UI, arrow_right)
|
self.add_element(DrawLayers.UI, arrow_right)
|
||||||
|
|
||||||
|
@ -146,5 +150,14 @@ class LevelSelectionScreenManager(ScreenManager):
|
||||||
super().destroy()
|
super().destroy()
|
||||||
|
|
||||||
def tick(self, tick_data: TickData):
|
def tick(self, tick_data: TickData):
|
||||||
|
if self.key_input_delay >= 0:
|
||||||
|
self.key_input_delay -= tick_data.dt
|
||||||
|
if self.key_input_delay <= 0:
|
||||||
if tick_data.key_manager.is_keymap_down(KeyManager.KEY_ESCAPE):
|
if tick_data.key_manager.is_keymap_down(KeyManager.KEY_ESCAPE):
|
||||||
self.main_loop.select_main_menu()
|
self.main_loop.select_main_menu()
|
||||||
|
elif tick_data.key_manager.is_keymap_down(KeyManager.KEY_LEFT):
|
||||||
|
self.select_prev_theme()
|
||||||
|
self.key_input_delay = 5
|
||||||
|
elif tick_data.key_manager.is_keymap_down(KeyManager.KEY_RIGHT):
|
||||||
|
self.select_next_theme()
|
||||||
|
self.key_input_delay = 5
|
||||||
|
|
Loading…
Reference in New Issue