created dev menu selector and test functions

This commit is contained in:
Nicholas Dyer 2023-05-14 19:06:50 -04:00
parent b6432e233a
commit 8a34ed7c01
6 changed files with 70 additions and 3 deletions

View File

@ -0,0 +1,9 @@
import os
def reboot_system():
os.system('echo TEST REBOOT')
def shutdown_system():
os.system('echo TEST SHUTDOWN')

View File

@ -1,5 +1,12 @@
import pygame import pygame
from pocket_friends.elements import surface from pocket_friends.elements import surface
from pocket_friends.development.sprites import FunctionSelector
import pocket_friends.development.dev as dev
dev_functions = {
'Restart': 'reboot_system',
'Shutdown': 'shutdown_system'
}
class Surface(surface.GameSurface): class Surface(surface.GameSurface):
@ -9,18 +16,36 @@ class Surface(surface.GameSurface):
self.game_fps = game_fps self.game_fps = game_fps
self.delay = 1 self.delay = 1
self.font = pygame.font.Font(resources_dir + '/fonts/5Pts5.ttf', 10) self.font = pygame.font.Font(resources_dir + '/fonts/5Pts5.ttf', 10)
self.bg = pygame.image.load(self.resource_dir + '/images/dev_bg.png').convert_alpha() self.bg = 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()))
executing_function()
def update(self): def update(self):
self.preprocess() self.preprocess()
text = self.font.render('f: {0}'.format(self.frames), False, (128, 128, 128)) text = self.font.render('f: {0}'.format(self.frames), False, (128, 128, 128))
self.blit(text, (3, 68)) self.blit(text, (3, 68))
self.function_selector.draw(self)
self.frames += 1 self.frames += 1
self.frames %= self.game_fps self.frames %= self.game_fps
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == pygame.KEYDOWN: 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()
if event.key == pygame.K_b: if event.key == pygame.K_b:
self.running = False self.running = False

View File

@ -0,0 +1,34 @@
import pygame
class FunctionSelector:
def __init__(self, resources_dir, game_res, functions):
self.font = pygame.font.Font(resources_dir + '/fonts/5Pts5.ttf', 10)
self.functions = functions
self.max_lines = 6 # Max number of lines to be shown on screen at a time.
self.offset = 0
self.game_res = game_res
self.selected = 0
self.max_index = len(self.functions) - 1
self.selector = pygame.image.load(resources_dir + '/images/dev_menu/selector.png').convert_alpha()
def draw(self, surface):
for i in range(self.max_index + 1):
text = self.font.render(self.functions[i], False, (0, 0, 0))
surface.blit(text, (8, (-3 + (i * 6))))
surface.blit(self.selector, (0, (self.selected * 6)))
def scroll_down(self):
self.selected += 1
if self.selected > self.max_index:
self.selected = self.max_index
def scroll_up(self):
self.selected -= 1
if self.selected < 0:
self.selected = 0
def get_function(self):
return self.functions[self.selected]

View File

@ -3,7 +3,6 @@ import os
import pocket_friends import pocket_friends
import importlib import importlib
valid_surfaces = [ valid_surfaces = [
'title', 'title',
'egg_select', 'egg_select',
@ -66,7 +65,7 @@ def start_game(resolution=240):
next_surface = surface.next_surface next_surface = surface.next_surface
additional_args = surface.additional_args additional_args = surface.additional_args
if next_surface not in valid_surfaces: if next_surface not in valid_surfaces:
next_surface = 'dev_menu' next_surface = 'error_screen'
surface = surface_modules.get(next_surface).Surface((game_res, game_res), resources_dir, surface = surface_modules.get(next_surface).Surface((game_res, game_res), resources_dir,
game_fps, **additional_args) game_fps, **additional_args)
pygame.display.flip() pygame.display.flip()

View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 839 B