summaryrefslogtreecommitdiff
path: root/src/menu.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/menu.py')
-rw-r--r--src/menu.py43
1 files changed, 38 insertions, 5 deletions
diff --git a/src/menu.py b/src/menu.py
index 1b877ac..49e263f 100644
--- a/src/menu.py
+++ b/src/menu.py
@@ -5,19 +5,28 @@ import helper
import audio
import save
import constants
+import debug
+
+clock = pygame.time.Clock()
def show(screen):
running = True
+ focused = True
opacity = 0
audio.play_menu(True)
while running:
+ pygame.event.set_allowed([pygame.APPMOUSEFOCUS, pygame.APPINPUTFOCUS, pygame.WINDOWRESIZED, pygame.WINDOWEXPOSED, pygame.WINDOWENTER, pygame.WINDOWLEAVE, pygame.WINDOWFOCUSLOST, pygame.WINDOWFOCUSGAINED, pygame.WINDOWICCPROFCHANGED, pygame.WINDOWTAKEFOCUS, pygame.WINDOWMINIMIZED, pygame.MOUSEBUTTONDOWN, pygame.MOUSEMOTION, pygame.QUIT])
for event in pygame.event.get():
+ if event.type == pygame.WINDOWFOCUSLOST:
+ focused = False
+ if event.type == pygame.WINDOWFOCUSGAINED:
+ focused = True
if event.type == pygame.MOUSEMOTION:
pygame.mouse.set_visible(True)
if event.type == pygame.MOUSEBUTTONDOWN:
left, middle, right = pygame.mouse.get_pressed()
- mouse = pygame.mouse.get_pos()
+ mouse = helper.get_real_mouse(screen)
print(mouse)
if left:
@@ -43,7 +52,12 @@ def show(screen):
while run and not done:
canvas.fill("black")
+ pygame.event.set_allowed([pygame.APPMOUSEFOCUS, pygame.APPINPUTFOCUS, pygame.WINDOWRESIZED, pygame.WINDOWEXPOSED, pygame.WINDOWENTER, pygame.WINDOWLEAVE, pygame.WINDOWFOCUSLOST, pygame.WINDOWFOCUSGAINED, pygame.WINDOWICCPROFCHANGED, pygame.WINDOWTAKEFOCUS, pygame.WINDOWMINIMIZED, pygame.QUIT, pygame.KEYDOWN])
for event in pygame.event.get():
+ if event.type == pygame.WINDOWFOCUSLOST:
+ focused = False
+ if event.type == pygame.WINDOWFOCUSGAINED:
+ focused = True
if event.type == pygame.QUIT:
run = False
quit = True
@@ -77,7 +91,11 @@ def show(screen):
scaled_win = pygame.transform.scale(canvas, (width, height))
screen.blit(scaled_win, (screen.get_size()[0] / 2 - width / 2, screen.get_size()[1] / 2 - height / 2))
- pygame.display.flip()
+ if focused:
+ debug.show_debug(clock)
+ pygame.display.flip()
+
+ clock.tick(25)
if quit:
pygame.quit()
@@ -90,6 +108,7 @@ def show(screen):
scaled_win = pygame.transform.scale(canvas, (width, height))
screen.blit(scaled_win, (screen.get_size()[0] / 2 - width / 2, screen.get_size()[1] / 2 - height / 2))
+ debug.show_debug(clock)
pygame.display.flip()
audio.wait_for_sfx()
@@ -124,12 +143,17 @@ def show(screen):
while run and not done:
canvas.fill("black")
+ pygame.event.set_allowed([pygame.APPMOUSEFOCUS, pygame.APPINPUTFOCUS, pygame.WINDOWRESIZED, pygame.WINDOWEXPOSED, pygame.WINDOWENTER, pygame.WINDOWLEAVE, pygame.WINDOWFOCUSLOST, pygame.WINDOWFOCUSGAINED, pygame.WINDOWICCPROFCHANGED, pygame.WINDOWTAKEFOCUS, pygame.WINDOWMINIMIZED, pygame.QUIT, pygame.MOUSEBUTTONDOWN, pygame.KEYDOWN])
for event in pygame.event.get():
+ if event.type == pygame.WINDOWFOCUSLOST:
+ focused = False
+ if event.type == pygame.WINDOWFOCUSGAINED:
+ focused = True
if event.type == pygame.QUIT:
run = False
quit = True
elif event.type == pygame.MOUSEBUTTONDOWN:
- cursor = pygame.mouse.get_pos()
+ cursor = helper.get_real_mouse(screen)
for i in range(len(saves)):
save_name = saves[i]
@@ -161,7 +185,11 @@ def show(screen):
scaled_win = pygame.transform.scale(canvas, (width, height))
screen.blit(scaled_win, (screen.get_size()[0] / 2 - width / 2, screen.get_size()[1] / 2 - height / 2))
- pygame.display.flip()
+ if focused:
+ debug.show_debug(clock)
+ pygame.display.flip()
+
+ clock.tick(25)
if quit:
pygame.quit()
elif done:
@@ -173,6 +201,7 @@ def show(screen):
scaled_win = pygame.transform.scale(canvas, (width, height))
screen.blit(scaled_win, (screen.get_size()[0] / 2 - width / 2, screen.get_size()[1] / 2 - height / 2))
+ debug.show_debug(clock)
pygame.display.flip()
loaded = save.load_world(helper.get_data_path() + "/saves/" + world_name)
@@ -227,10 +256,14 @@ def show(screen):
screen.blit(result, (screen.get_size()[0] / 2 - width / 2, screen.get_size()[1] / 2 - height / 2))
audio.play_menu()
- pygame.display.flip()
+ if focused:
+ debug.show_debug(clock)
+ pygame.display.flip()
if opacity < 1:
opacity += 1/30
if opacity >= 1:
opacity = 1
+
+ clock.tick(25)