-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoadLevelMenu.py
85 lines (61 loc) · 2.24 KB
/
LoadLevelMenu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/python
import pygame
import glob
import Editor
import Resources
from Button import *
from pygame.locals import *
class LoadLevelMenu():
pygame.mixer.pre_init(44100, -16, 2, 1024)
pygame.mixer.init()
def __init__(self):
self.screen = pygame.display.get_surface()
self.background = pygame.Surface(self.screen.get_size())
self.background = self.background.convert()
self.background.fill((50, 50, 50))
self.buttonSound = pygame.mixer.Sound("resources/sound/button.wav")
self.buttonSound.set_volume(float(Resources.getOptionValue("sound"))/100)
self.buttons = {}
pos = 25
for f in glob.glob("save/maps/*.mabbit"):
name = f.split("\\")[-1].split(".")[0]
if(name != "last"):
self.buttons[name] = Button(self.screen.get_width()/2 - 200/2, pos, 200, 40, name.upper())
pos +=100
self.buttons["back"] = Button(self.screen.get_width()/2 - 200/2, pos, 200, 40, "BACK")
pygame.display.flip()
def update(self):
key = pygame.key.get_pressed()
mouse = pygame.mouse.get_pressed()
for event in pygame.event.get():
if event.type == QUIT or (key[K_F4] and key[K_LALT]):
return False, self
elif event.type == MOUSEBUTTONDOWN:
if event.button == 5:
if self.buttons[self.buttons.keys()[0]].getY() > self.screen.get_height() - 65:
for button in self.buttons.values():
button.setY(button.getY() - 25)
if event.button == 4:
if self.buttons[self.buttons.keys()[1]].getY() <= 25:
for button in self.buttons.values():
button.setY(button.getY() + 25)
for name, button in self.buttons.items():
mse = pygame.mouse.get_pos()
if event.button == 1:
if button.onButton(mse):
self.buttonSound.play()
if name == "back":
return True, Editor.Editor("last")
else:
return True, Editor.Editor(name)
elif event.type == MOUSEMOTION:
mse = pygame.mouse.get_pos()
pygame.mouse.set_cursor(*pygame.cursors.arrow)
for button in self.buttons.values():
if button.onButton(mse):
pygame.mouse.set_cursor(*pygame.cursors.tri_left)
self.screen.blit(self.background, self.background.get_rect(), self.background.get_rect())
for button in self.buttons.values():
button.update()
pygame.display.update()
return True, self