added black screen to dev menu
This commit is contained in:
0
pocket_friends/_development/__init__.py
Normal file
0
pocket_friends/_development/__init__.py
Normal file
22
pocket_friends/_development/_dev.py
Normal file
22
pocket_friends/_development/_dev.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
import pygame
|
||||
|
||||
|
||||
def reboot_system():
|
||||
os.system('sudo reboot')
|
||||
|
||||
|
||||
def shutdown_system():
|
||||
os.system('sudo shutdown now')
|
||||
|
||||
def update():
|
||||
os.system('bash ~/update.sh')
|
||||
sys.exit(1)
|
||||
|
||||
def restart_app():
|
||||
sys.exit(1)
|
||||
|
||||
def show_black():
|
||||
return 'show_black'
|
34
pocket_friends/_development/_sprites.py
Normal file
34
pocket_friends/_development/_sprites.py
Normal 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]
|
33
pocket_friends/_development/surfaces/_black_screen.py
Normal file
33
pocket_friends/_development/surfaces/_black_screen.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import pygame
|
||||
from pocket_friends.elements import surface
|
||||
|
||||
|
||||
class Surface(surface.GameSurface):
|
||||
def __init__(self, game_res, resources_dir, game_fps, **kwargs):
|
||||
super().__init__(game_res, resources_dir, game_fps)
|
||||
self.game_fps = game_fps
|
||||
self.frames = -3 * game_fps
|
||||
self.delay = 1
|
||||
self.font = pygame.font.Font(resources_dir + '/fonts/5Pts5.ttf', 10)
|
||||
self.title = pygame.image.load(resources_dir + '/images/debug/invalid.png').convert_alpha()
|
||||
self.next_surface = 'title'
|
||||
|
||||
def update(self):
|
||||
self.preprocess()
|
||||
self.fill((0, 0, 0))
|
||||
|
||||
text_1 = self.font.render('Press B', False, (64, 64, 64))
|
||||
text_2 = self.font.render('to return', False, (64, 64, 64))
|
||||
|
||||
if self.frames < 0:
|
||||
self.blit(text_1, (3, 20))
|
||||
self.blit(text_2, (3, 40))
|
||||
|
||||
self.frames += 1
|
||||
if self.frames > self.game_fps:
|
||||
self.frames = 0
|
||||
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.KEYDOWN:
|
||||
if event.key == pygame.K_b:
|
||||
self.running = False
|
57
pocket_friends/_development/surfaces/_dev_menu.py
Normal file
57
pocket_friends/_development/surfaces/_dev_menu.py
Normal file
@@ -0,0 +1,57 @@
|
||||
import pygame
|
||||
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',
|
||||
'Update': 'update',
|
||||
'Re-open App': 'restart_app',
|
||||
'Black screen': 'show_black'
|
||||
}
|
||||
|
||||
|
||||
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.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()))
|
||||
output = executing_function()
|
||||
if output == 'show_black':
|
||||
self.next_surface = '_black_screen'
|
||||
self.running = False
|
||||
|
||||
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)
|
||||
|
||||
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()
|
||||
if event.key == pygame.K_b:
|
||||
self.running = False
|
Reference in New Issue
Block a user