-
Notifications
You must be signed in to change notification settings - Fork 0
/
button.py
100 lines (85 loc) · 3.24 KB
/
button.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import math
import pygame
class Button():
def __init__(self, image, pos, text_input, font, base_color, hovering_color, listeType=[], nomMap=""):
self.image = image
self.x_pos = pos[0]
self.y_pos = pos[1]
self.font = font
self.base_color, self.hovering_color = base_color, hovering_color
self.text_input = text_input
self.text = self.font.render(self.text_input, True, self.base_color)
if self.image is None:
self.image = self.text
self.rect = self.image.get_rect(center=(self.x_pos, self.y_pos))
self.text_rect = self.text.get_rect(center=(self.x_pos, self.y_pos))
self.deg = 0
self.sonBouton = pygame.mixer.Sound("data/son/effets/boutonMenu.mp3")
self.sonBouton.set_volume(0.1)
self.sonBoutonPress = pygame.mixer.Sound("data/son/effets/boutonPress.mp3")
self.sonBoutonPress.set_volume(0.1)
self.pressed2 = False
self.pressed=False
self.scale=False
self.nomMap = nomMap
self.imageSelect = pygame.transform.scale(pygame.image.load("data/menu/backButtonMapS.png").convert_alpha(), (self.image.get_width(), self.image.get_height()))
self.listeType = listeType #une map
self.aleatoire = pygame.image.load("data/menu/aleatoire.png")
#def setTxt(self, str):
def getColor(self, i):
if i == 1:
color= (20, 163, 107)
if i == 2:
color = (117, 119, 119)
if i == 3:
color = (53,81,149)
if i == 4:
color = (52, 125, 107)
if i==5:
color = (215,217,209)
if i == 6:
color = (215,163, 107)
if i == 7:
color = (94, 20, 30)
if i == 9:
color = (69,33,74)
if i == 10:
color = (3,166,74)
return color
def update(self, screen):
if self.image is not None:
screen.blit(self.image, self.rect)
if self.pressed2:
screen.blit(self.imageSelect, self.rect)
elif self.listeType:
infoObject = pygame.display.Info()
scale =infoObject.current_w//120
posX = infoObject.current_w//1.57
posY = infoObject.current_h//3.42
for y in range(len(self.listeType)):
for x in range(len(self.listeType[y])):
pygame.draw.rect(screen, self.getColor(self.listeType[y][x]), pygame.Rect(scale*x+scale+posX, scale*y+scale+posY, scale, scale))
else:
infoObject = pygame.display.Info()
scale =infoObject.current_w//120
posX = infoObject.current_w//1.57
posY = infoObject.current_h//3.42
if not self.scale:
self.aleatoire = pygame.transform.scale(self.aleatoire, (posX/3.3, posY+20/100*posY))
self.scale = True
screen.blit(self.aleatoire, (scale+posX, scale+posY))
if not self.listeType and self.text_input!="aleatoire":
screen.blit(self.text,self.text_rect)
def checkForInput(self, position):
if position[0] in range(self.rect.left, self.rect.right) and position[1] in range(self.rect.top, self.rect.bottom):
return True
return False
def changeColor(self, position):
if position[0] in range(self.rect.left, self.rect.right) and position[1] in range(self.rect.top, self.rect.bottom):
self.text = self.font.render(self.text_input, True, self.hovering_color)
if not self.pressed :
pygame.mixer.Sound.play(self.sonBouton)
self.pressed=True
else:
self.text = self.font.render(self.text_input, True, self.base_color)
self.pressed=False