|
|
@ -11,8 +11,6 @@ import numpy as np
|
|
|
|
pygame.init()
|
|
|
|
pygame.init()
|
|
|
|
FPS = 60
|
|
|
|
FPS = 60
|
|
|
|
|
|
|
|
|
|
|
|
MAIN_PATH = "C:/Users/User/Documents/Coding/Picture_Puzzle/"
|
|
|
|
|
|
|
|
# School: MAIN_PATH = "C:/Users/RVKG/Documents/My Palettes/Picture Puzzle/"
|
|
|
|
|
|
|
|
IMAGES_PATH = "images/albums/"
|
|
|
|
IMAGES_PATH = "images/albums/"
|
|
|
|
SIZE_PATH = "images/assets/"
|
|
|
|
SIZE_PATH = "images/assets/"
|
|
|
|
|
|
|
|
|
|
|
@ -47,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"]
|
|
|
@ -129,6 +128,7 @@ if current_size == SIZE_CHOICES[0]:
|
|
|
|
arrow2 = (274, 0, 10, 13)
|
|
|
|
arrow2 = (274, 0, 10, 13)
|
|
|
|
spaces2 = [4, 5, 2, 5, 60, 42]
|
|
|
|
spaces2 = [4, 5, 2, 5, 60, 42]
|
|
|
|
spaces3 = [10, 20, 23]
|
|
|
|
spaces3 = [10, 20, 23]
|
|
|
|
|
|
|
|
# --> i forgor U+1F480
|
|
|
|
|
|
|
|
|
|
|
|
elif current_size == SIZE_CHOICES[1]:
|
|
|
|
elif current_size == SIZE_CHOICES[1]:
|
|
|
|
WIDTH, HEIGHT = 202, 216
|
|
|
|
WIDTH, HEIGHT = 202, 216
|
|
|
@ -254,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):
|
|
|
@ -288,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)
|
|
|
|
|
|
|
|
|
|
|
@ -428,7 +460,7 @@ class ImageRender:
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
self.current = image_names[self.index]
|
|
|
|
self.current = image_names[self.index]
|
|
|
|
selected_image = pygame.image.load(MAIN_PATH + IMAGES_PATH + self.album_name + "/" + self.current)
|
|
|
|
selected_image = pygame.image.load(IMAGES_PATH + self.album_name + "/" + self.current)
|
|
|
|
self.scaled_image = pygame.transform.scale(selected_image, (self.scaled_size[2], self.scaled_size[3]))
|
|
|
|
self.scaled_image = pygame.transform.scale(selected_image, (self.scaled_size[2], self.scaled_size[3]))
|
|
|
|
current_img = self.current
|
|
|
|
current_img = self.current
|
|
|
|
current_album = self.album_name
|
|
|
|
current_album = self.album_name
|
|
|
@ -517,7 +549,7 @@ def load_puzzle():
|
|
|
|
|
|
|
|
|
|
|
|
puzzle_version = settings_data["grid"]
|
|
|
|
puzzle_version = settings_data["grid"]
|
|
|
|
image_path = puzzle_data[f'current {puzzle_version}']['selected_image']
|
|
|
|
image_path = puzzle_data[f'current {puzzle_version}']['selected_image']
|
|
|
|
puzzle_image = pygame.image.load(MAIN_PATH + image_path)
|
|
|
|
puzzle_image = pygame.image.load(image_path)
|
|
|
|
|
|
|
|
|
|
|
|
directions = {"up": [4, 8, 12],
|
|
|
|
directions = {"up": [4, 8, 12],
|
|
|
|
"down": [],
|
|
|
|
"down": [],
|
|
|
@ -777,7 +809,7 @@ def set_hue():
|
|
|
|
|
|
|
|
|
|
|
|
sprite_sheet.set_hue(hue_value)
|
|
|
|
sprite_sheet.set_hue(hue_value)
|
|
|
|
|
|
|
|
|
|
|
|
pygame.image.save(sprite_sheet.sheet, MAIN_PATH + SIZE_PATH + str(INT) + STYLE_PATH + "spritesheet.png")
|
|
|
|
pygame.image.save(sprite_sheet.sheet, SIZE_PATH + str(INT) + STYLE_PATH + "spritesheet.png")
|
|
|
|
|
|
|
|
|
|
|
|
settings_data[gui][x] = hue_value
|
|
|
|
settings_data[gui][x] = hue_value
|
|
|
|
with open(SETTINGS_FILE, "w") as settings_file:
|
|
|
|
with open(SETTINGS_FILE, "w") as settings_file:
|
|
|
@ -812,8 +844,9 @@ def reset():
|
|
|
|
|
|
|
|
|
|
|
|
# STATS MODE
|
|
|
|
# STATS MODE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Not finished yet
|
|
|
|
|
|
|
|
|
|
|
|
#INFO MODE
|
|
|
|
# INFO MODE
|
|
|
|
text_size = [3, 5]
|
|
|
|
text_size = [3, 5]
|
|
|
|
|
|
|
|
|
|
|
|
def render_text_in_rect(long_text, rect_area):
|
|
|
|
def render_text_in_rect(long_text, rect_area):
|
|
|
@ -859,20 +892,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))
|
|
|
@ -881,20 +914,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))
|
|
|
@ -903,20 +936,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))
|
|
|
@ -1032,7 +1065,6 @@ start_pos = (0, 0)
|
|
|
|
pressed_button = None
|
|
|
|
pressed_button = None
|
|
|
|
slider_moving = False
|
|
|
|
slider_moving = False
|
|
|
|
setting = None
|
|
|
|
setting = None
|
|
|
|
arrow = None
|
|
|
|
|
|
|
|
# Select mode
|
|
|
|
# Select mode
|
|
|
|
clicked_image = False
|
|
|
|
clicked_image = False
|
|
|
|
image_display = None
|
|
|
|
image_display = None
|
|
|
|