pocket-friends/pocket_friends/_development/surfaces/_dev_menu.py

59 lines
2.0 KiB
Python
Raw Normal View History

2023-05-14 17:47:56 -04:00
import pygame
from pocket_friends.elements import surface
2023-05-14 23:04:26 -04:00
from pocket_friends._development._sprites import FunctionSelector
import pocket_friends._development._dev as dev
dev_functions = {
'Restart': 'reboot_system',
2023-05-14 19:41:44 -04:00
'Shutdown': 'shutdown_system',
2023-05-14 19:48:29 -04:00
'Update': 'update',
2023-05-14 23:04:26 -04:00
'Re-open App': 'restart_app',
2023-05-15 01:20:37 -04:00
'Black screen': 'show_black',
'!!! Close App': 'quit'
}
2023-05-14 17:47:56 -04:00
class Surface(surface.GameSurface):
def __init__(self, game_res, resources_dir, game_fps, **kwargs):
super().__init__(game_res, resources_dir, game_fps)
self.frames = 1
self.game_fps = game_fps
self.delay = 1
self.font = pygame.font.Font(resources_dir + '/fonts/5Pts5.ttf', 10)
self.background = pygame.image.load(self.resource_dir + '/images/dev_menu/dev_bg.png').convert_alpha()
functions = []
for key in dev_functions.keys():
functions.append(key)
self.function_selector = FunctionSelector(resources_dir, game_res, functions)
def execute(self):
executing_function = getattr(dev, dev_functions.get(self.function_selector.get_function()))
2023-05-14 23:04:26 -04:00
output = executing_function()
if output == 'show_black':
self.next_surface = '_black_screen'
self.running = False
2023-05-14 17:47:56 -04:00
def update(self):
self.preprocess()
text = self.font.render('f: {0}'.format(self.frames), False, (128, 128, 128))
self.blit(text, (3, 68))
self.function_selector.draw(self)
2023-05-14 17:47:56 -04:00
self.frames += 1
self.frames %= self.game_fps
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
self.function_selector.scroll_up()
if event.key == pygame.K_DOWN:
self.function_selector.scroll_down()
if event.key == pygame.K_a:
self.execute()
2023-05-14 17:47:56 -04:00
if event.key == pygame.K_b:
self.running = False