master
parent
7a62b4dd00
commit
36371f1dc1
105
main.py
105
main.py
|
@ -45,6 +45,7 @@ style = "style"
|
||||||
current_size = settings_data["size"]
|
current_size = settings_data["size"]
|
||||||
current_style = settings_data["style"]
|
current_style = settings_data["style"]
|
||||||
|
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
SIZE_CHOICES = ["small", "medium", "big"]
|
SIZE_CHOICES = ["small", "medium", "big"]
|
||||||
STYLE_CHOICES = ["classic", "original", "dark"]
|
STYLE_CHOICES = ["classic", "original", "dark"]
|
||||||
|
@ -253,13 +254,17 @@ class Image:
|
||||||
|
|
||||||
|
|
||||||
class Button:
|
class Button:
|
||||||
def __init__(self, sprite_position, window_position, size):
|
def __init__(self, sprite_position, window_position, size, popup_text=None):
|
||||||
self.sprite_sheet = sprite_sheet
|
self.sprite_sheet = sprite_sheet
|
||||||
self.sprite_position = sprite_position
|
self.sprite_position = sprite_position
|
||||||
self.window_position = window_position
|
self.window_position = window_position
|
||||||
self.size = size
|
self.size = size
|
||||||
|
self.popup_text = popup_text
|
||||||
self.hovered = False
|
self.hovered = False
|
||||||
self.disabled = False
|
self.disabled = False
|
||||||
|
self.popup_timer = 0
|
||||||
|
self.popup_duration = 3000
|
||||||
|
self.popup_surface = None
|
||||||
self.update_images()
|
self.update_images()
|
||||||
|
|
||||||
def update_images(self):
|
def update_images(self):
|
||||||
|
@ -287,9 +292,37 @@ class Button:
|
||||||
def update(self, mouse_pos):
|
def update(self, mouse_pos):
|
||||||
self.hovered = self.is_hovered(mouse_pos)
|
self.hovered = self.is_hovered(mouse_pos)
|
||||||
|
|
||||||
|
if self.popup_text is not None and self.hovered:
|
||||||
|
self.popup_timer += FPS
|
||||||
|
if self.popup_timer >= self.popup_duration:
|
||||||
|
self.show_popup(mouse_pos)
|
||||||
|
else:
|
||||||
|
self.popup_timer = 0
|
||||||
|
self.popup_surface = None
|
||||||
|
|
||||||
|
def show_popup(self, mouse_pos):
|
||||||
|
font = pygame.font.Font(None, 22)
|
||||||
|
text_surface = font.render(self.popup_text, True, (0, 0, 0), (255, 255, 225))
|
||||||
|
text_rect = text_surface.get_rect(center=mouse_pos)
|
||||||
|
|
||||||
|
popup_width = text_rect.width + 4
|
||||||
|
popup_height = text_rect.height + 4
|
||||||
|
|
||||||
|
popup_x = min(mouse_pos[0], WIDTH - popup_width - 1)
|
||||||
|
popup_y = min(mouse_pos[1] + 20, HEIGHT - popup_height - 1)
|
||||||
|
|
||||||
|
self.popup_surface = pygame.Surface((popup_width, popup_height), pygame.SRCALPHA)
|
||||||
|
pygame.draw.rect(self.popup_surface, (0, 0, 0), self.popup_surface.get_rect())
|
||||||
|
self.popup_surface.blit(text_surface, (2, 2))
|
||||||
|
|
||||||
|
self.popup_rect = self.popup_surface.get_rect(topleft=(popup_x, popup_y))
|
||||||
|
|
||||||
|
|
||||||
def draw(self, screen):
|
def draw(self, screen):
|
||||||
if not self.disabled:
|
if not self.disabled:
|
||||||
screen.blit(self.hover_image if self.hovered else self.img, self.rect)
|
screen.blit(self.hover_image if self.hovered else self.img, self.rect)
|
||||||
|
if self.popup_surface:
|
||||||
|
screen.blit(self.popup_surface, self.popup_rect)
|
||||||
else:
|
else:
|
||||||
screen.blit(self.img, self.rect)
|
screen.blit(self.img, self.rect)
|
||||||
|
|
||||||
|
@ -858,20 +891,20 @@ text_surfaces, text_rects = render_text_in_rect(long_text, rect_area)
|
||||||
if current_size == SIZE_CHOICES[0]:
|
if current_size == SIZE_CHOICES[0]:
|
||||||
px12 = (12, 12)
|
px12 = (12, 12)
|
||||||
px14 = (14, 14)
|
px14 = (14, 14)
|
||||||
timer_button = Button((0, 0), (7, 3), px12)
|
timer_button = Button((0, 0), (7, 3), px12, "Pause timer")
|
||||||
menu_button = Button((15, 0), (80, 3), px12)
|
menu_button = Button((15, 0), (80, 3), px12, "Menu")
|
||||||
hint_button = Button((30, 0), (95, 3), px12)
|
hint_button = Button((30, 0), (95, 3), px12, "Hint")
|
||||||
shuffle_button = Button((45, 0), (110, 3), px12)
|
shuffle_button = Button((45, 0), (110, 3), px12, "Shuffle")
|
||||||
close_button = Button((60, 0), (125, 3), px12)
|
close_button = Button((60, 0), (125, 3), px12, "Close")
|
||||||
finished_button = Button((75, 0), (7, 3), px12)
|
finished_button = Button((75, 0), (7, 3), px12)
|
||||||
not_finished_button = Button((90, 0), (7, 3), px12)
|
not_finished_button = Button((90, 0), (7, 3), px12)
|
||||||
delete_button = Button((105, 0), (95, 3), px12)
|
delete_button = Button((105, 0), (95, 3), px12, "Delete")
|
||||||
continue_button = Button((120, 0), (110, 3), px12)
|
continue_button = Button((120, 0), (110, 3), px12, "Continue")
|
||||||
settings_button = Button((135, 0), (7, 3), px12)
|
settings_button = Button((135, 0), (7, 3), px12, "Settings")
|
||||||
quick_add_button = Button((34, 30), (22, 3), (55, 12))
|
quick_add_button = Button((34, 30), (22, 3), (55, 12))
|
||||||
new_button = Button((150, 0), (80, 3), px12)
|
new_button = Button((150, 0), (80, 3), px12, "New")
|
||||||
info_button = Button((165, 0), (7, 3), px12)
|
info_button = Button((165, 0), (7, 3), px12, "Info")
|
||||||
stats_button = Button((180, 0), (95, 3), px12)
|
stats_button = Button((180, 0), (95, 3), px12, "Stats")
|
||||||
to_left_button = Button((0, 30), (33, 136), px14)
|
to_left_button = Button((0, 30), (33, 136), px14)
|
||||||
to_right_button = Button((17, 30), (97, 136), px14)
|
to_right_button = Button((17, 30), (97, 136), px14)
|
||||||
BACKGROUND_IMAGE = Image((0, 64), (0, 0), (WIDTH, HEIGHT))
|
BACKGROUND_IMAGE = Image((0, 64), (0, 0), (WIDTH, HEIGHT))
|
||||||
|
@ -880,20 +913,20 @@ if current_size == SIZE_CHOICES[0]:
|
||||||
elif current_size == SIZE_CHOICES[1]:
|
elif current_size == SIZE_CHOICES[1]:
|
||||||
px16 = (16, 16)
|
px16 = (16, 16)
|
||||||
px20 = (20, 20)
|
px20 = (20, 20)
|
||||||
timer_button = Button((0, 0), (8, 4), px16)
|
timer_button = Button((0, 0), (8, 4), px16, "Pause timer")
|
||||||
menu_button = Button((19, 0), (118, 4), px16)
|
menu_button = Button((19, 0), (118, 4), px16, "Menu")
|
||||||
hint_button = Button((38, 0), (138, 4), px16)
|
hint_button = Button((38, 0), (138, 4), px16, "Hint")
|
||||||
shuffle_button = Button((57, 0), (158, 4), px16)
|
shuffle_button = Button((57, 0), (158, 4), px16, "Shuffle")
|
||||||
close_button = Button((76, 0), (178, 4), px16)
|
close_button = Button((76, 0), (178, 4), px16, "Close")
|
||||||
finished_button = Button((95, 0), (8, 4), px16)
|
finished_button = Button((95, 0), (8, 4), px16)
|
||||||
not_finished_button = Button((114, 0), (8, 4), px16)
|
not_finished_button = Button((114, 0), (8, 4), px16)
|
||||||
delete_button = Button((133, 0), (138, 4), px16)
|
delete_button = Button((133, 0), (138, 4), px16, "Delete")
|
||||||
continue_button = Button((152, 0), (158, 4), px16)
|
continue_button = Button((152, 0), (158, 4), px16, "Continue")
|
||||||
settings_button = Button((171, 0), (8, 4), px16)
|
settings_button = Button((171, 0), (8, 4), px16, "Settings")
|
||||||
quick_add_button = Button((46, 38), (28, 4), (86, 16))
|
quick_add_button = Button((46, 38), (28, 4), (86, 16))
|
||||||
new_button = Button((190, 0), (118, 4), px16)
|
new_button = Button((190, 0), (118, 4), px16, "Stats")
|
||||||
info_button = Button((209, 0), (8, 4), px16)
|
info_button = Button((209, 0), (8, 4), px16, "Info")
|
||||||
stats_button = Button((228, 0), (138, 4), px16)
|
stats_button = Button((228, 0), (138, 4), px16, "Stats")
|
||||||
to_left_button = Button((0, 38), (46, 191), px20)
|
to_left_button = Button((0, 38), (46, 191), px20)
|
||||||
to_right_button = Button((23, 38), (136, 191), px20)
|
to_right_button = Button((23, 38), (136, 191), px20)
|
||||||
BACKGROUND_IMAGE = Image((0, 84), (0, 0), (WIDTH, HEIGHT))
|
BACKGROUND_IMAGE = Image((0, 84), (0, 0), (WIDTH, HEIGHT))
|
||||||
|
@ -902,20 +935,20 @@ elif current_size == SIZE_CHOICES[1]:
|
||||||
else:
|
else:
|
||||||
px32 = (32, 32)
|
px32 = (32, 32)
|
||||||
px40 = (40, 40)
|
px40 = (40, 40)
|
||||||
timer_button = Button((0, 0), (12, 6), px32)
|
timer_button = Button((0, 0), (12, 6), px32, "Pause timer")
|
||||||
menu_button = Button((35, 0), (241, 6), px32)
|
menu_button = Button((35, 0), (241, 6), px32, "Menu")
|
||||||
hint_button = Button((72, 0), (278, 6), px32)
|
hint_button = Button((72, 0), (278, 6), px32, "Hint")
|
||||||
shuffle_button = Button((105, 0), (315, 6), px32)
|
shuffle_button = Button((105, 0), (315, 6), px32, "Shuffle")
|
||||||
close_button = Button((140, 0), (352, 6), px32)
|
close_button = Button((140, 0), (352, 6), px32, "Close")
|
||||||
finished_button = Button((175, 0), (12, 6), px32)
|
finished_button = Button((175, 0), (12, 6), px32, )
|
||||||
not_finished_button = Button((210, 0), (8, 6), px32)
|
not_finished_button = Button((210, 0), (8, 6), px32, )
|
||||||
delete_button = Button((245, 0), (278, 6), px32)
|
delete_button = Button((245, 0), (278, 6), px32, "Delete")
|
||||||
continue_button = Button((280, 0), (315, 6), px32)
|
continue_button = Button((280, 0), (315, 6), px32, "Continue")
|
||||||
settings_button = Button((315, 0), (12, 6), px32)
|
settings_button = Button((315, 0), (12, 6), px32, "Settings")
|
||||||
quick_add_button = Button((86, 70), (49, 6), (187, 32))
|
quick_add_button = Button((86, 70), (49, 6), (187, 32))
|
||||||
new_button = Button((350, 0), (241, 6), px32)
|
new_button = Button((350, 0), (241, 6), px32, "Stats")
|
||||||
info_button = Button((385, 0), (12, 6), px32)
|
info_button = Button((385, 0), (12, 6), px32, "Info")
|
||||||
stats_button = Button((420, 0), (278, 6), px32)
|
stats_button = Button((420, 0), (278, 6), px32, "Stats")
|
||||||
to_left_button = Button((0, 70), (107, 372), px40)
|
to_left_button = Button((0, 70), (107, 372), px40)
|
||||||
to_right_button = Button((43, 70), (248, 372), px40)
|
to_right_button = Button((43, 70), (248, 372), px40)
|
||||||
BACKGROUND_IMAGE = Image((0, 156), (0, 0), (WIDTH, HEIGHT))
|
BACKGROUND_IMAGE = Image((0, 156), (0, 0), (WIDTH, HEIGHT))
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"size": "medium",
|
"size": "big",
|
||||||
"style": "classic",
|
"style": "classic",
|
||||||
"grid": "4x4",
|
"grid": "4x4",
|
||||||
"gui color": 0,
|
"gui color": 0,
|
||||||
|
|
Loading…
Reference in New Issue