2
TODO
|
@ -6,7 +6,7 @@ TODO main:
|
||||||
[meh] add setting - move pieses = slow/normal/fast/instant
|
[meh] add setting - move pieses = slow/normal/fast/instant
|
||||||
[meh] fix quick game window moving thing
|
[meh] fix quick game window moving thing
|
||||||
[meh] add popup when loading time - load previous or reset
|
[meh] add popup when loading time - load previous or reset
|
||||||
[ ] add small notes on button hover
|
[x] add small notes on button hover
|
||||||
[ ] add functionality in select and menu mode
|
[ ] add functionality in select and menu mode
|
||||||
[sorta] add settings, info and stats with full functionality
|
[sorta] add settings, info and stats with full functionality
|
||||||
[meh] optimise code as possible
|
[meh] optimise code as possible
|
||||||
|
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 3.0 KiB |
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 5.8 KiB |
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 9.7 KiB After Width: | Height: | Size: 10 KiB |
113
main.py
|
@ -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,13 +292,43 @@ 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, 24)
|
||||||
|
text_surface = font.render(self.popup_text, True, (0, 0, 0), (255, 255, 225))
|
||||||
|
text_rect = text_surface.get_rect(center=mouse_pos)
|
||||||
|
|
||||||
|
# Increase the size of the popup surface
|
||||||
|
popup_width = text_rect.width + 14
|
||||||
|
popup_height = text_rect.height + 14
|
||||||
|
|
||||||
|
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, (255, 255, 255), self.popup_surface.get_rect())
|
||||||
|
pygame.draw.rect(self.popup_surface, (0, 0, 0), self.popup_surface.get_rect(), 1)
|
||||||
|
self.popup_surface.blit(text_surface, (7, 7))
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Ability to move window
|
# Ability to move window
|
||||||
def move_win(coordinates):
|
def move_win(coordinates):
|
||||||
hwnd = pygame.display.get_wm_info()["window"]
|
hwnd = pygame.display.get_wm_info()["window"]
|
||||||
|
@ -853,26 +887,26 @@ long_text = (
|
||||||
)
|
)
|
||||||
|
|
||||||
text_surfaces, text_rects = render_text_in_rect(long_text, rect_area)
|
text_surfaces, text_rects = render_text_in_rect(long_text, rect_area)
|
||||||
|
names = ("Pause", "Menu", "Hint", "Shuffle", "Close", "Delete", "Continue", "Settings", "Quick game", "Add new", "Info", "Stats")
|
||||||
|
|
||||||
# Buttons (maybe optimise?)
|
# Buttons (maybe optimise?)
|
||||||
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, names[0])
|
||||||
menu_button = Button((15, 0), (80, 3), px12)
|
menu_button = Button((15, 0), (80, 3), px12, names[1])
|
||||||
hint_button = Button((30, 0), (95, 3), px12)
|
hint_button = Button((30, 0), (95, 3), px12, names[2])
|
||||||
shuffle_button = Button((45, 0), (110, 3), px12)
|
shuffle_button = Button((45, 0), (110, 3), px12, names[3])
|
||||||
close_button = Button((60, 0), (125, 3), px12)
|
close_button = Button((60, 0), (125, 3), px12, names[4])
|
||||||
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, names[5])
|
||||||
continue_button = Button((120, 0), (110, 3), px12)
|
continue_button = Button((120, 0), (110, 3), px12, names[6])
|
||||||
settings_button = Button((135, 0), (7, 3), px12)
|
settings_button = Button((135, 0), (7, 3), px12, names[7])
|
||||||
quick_add_button = Button((34, 30), (22, 3), (55, 12))
|
quick_add_button = Button((34, 30), (22, 3), (55, 12), names[8])
|
||||||
new_button = Button((150, 0), (80, 3), px12)
|
new_button = Button((150, 0), (80, 3), px12, names[9])
|
||||||
info_button = Button((165, 0), (7, 3), px12)
|
info_button = Button((165, 0), (7, 3), px12, names[10])
|
||||||
stats_button = Button((180, 0), (95, 3), px12)
|
stats_button = Button((180, 0), (95, 3), px12, names[11])
|
||||||
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 +915,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, names[0])
|
||||||
menu_button = Button((19, 0), (118, 4), px16)
|
menu_button = Button((19, 0), (118, 4), px16, names[1])
|
||||||
hint_button = Button((38, 0), (138, 4), px16)
|
hint_button = Button((38, 0), (138, 4), px16, names[2])
|
||||||
shuffle_button = Button((57, 0), (158, 4), px16)
|
shuffle_button = Button((57, 0), (158, 4), px16, names[3])
|
||||||
close_button = Button((76, 0), (178, 4), px16)
|
close_button = Button((76, 0), (178, 4), px16, names[4])
|
||||||
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, names[5])
|
||||||
continue_button = Button((152, 0), (158, 4), px16)
|
continue_button = Button((152, 0), (158, 4), px16, names[6])
|
||||||
settings_button = Button((171, 0), (8, 4), px16)
|
settings_button = Button((171, 0), (8, 4), px16, names[7])
|
||||||
quick_add_button = Button((46, 38), (28, 4), (86, 16))
|
quick_add_button = Button((46, 38), (28, 4), (86, 16), names[8])
|
||||||
new_button = Button((190, 0), (118, 4), px16)
|
new_button = Button((190, 0), (118, 4), px16, names[9])
|
||||||
info_button = Button((209, 0), (8, 4), px16)
|
info_button = Button((209, 0), (8, 4), px16, names[10])
|
||||||
stats_button = Button((228, 0), (138, 4), px16)
|
stats_button = Button((228, 0), (138, 4), px16, names[11])
|
||||||
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 +937,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, names[0])
|
||||||
menu_button = Button((35, 0), (241, 6), px32)
|
menu_button = Button((35, 0), (241, 6), px32, names[1])
|
||||||
hint_button = Button((72, 0), (278, 6), px32)
|
hint_button = Button((72, 0), (278, 6), px32, names[2])
|
||||||
shuffle_button = Button((105, 0), (315, 6), px32)
|
shuffle_button = Button((105, 0), (315, 6), px32, names[3])
|
||||||
close_button = Button((140, 0), (352, 6), px32)
|
close_button = Button((140, 0), (352, 6), px32, names[4])
|
||||||
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, names[5])
|
||||||
continue_button = Button((280, 0), (315, 6), px32)
|
continue_button = Button((280, 0), (315, 6), px32, names[6])
|
||||||
settings_button = Button((315, 0), (12, 6), px32)
|
settings_button = Button((315, 0), (12, 6), px32, names[7])
|
||||||
quick_add_button = Button((86, 70), (49, 6), (187, 32))
|
quick_add_button = Button((86, 70), (49, 6), (187, 32), names[8])
|
||||||
new_button = Button((350, 0), (241, 6), px32)
|
new_button = Button((350, 0), (241, 6), px32, names[9])
|
||||||
info_button = Button((385, 0), (12, 6), px32)
|
info_button = Button((385, 0), (12, 6), px32, names[10])
|
||||||
stats_button = Button((420, 0), (278, 6), px32)
|
stats_button = Button((420, 0), (278, 6), px32, names[11])
|
||||||
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))
|
||||||
|
@ -1194,6 +1228,9 @@ while run:
|
||||||
piece_y = row * puzzle_size[1] // len(puzzle_matrix) + non_movable_area.y
|
piece_y = row * puzzle_size[1] // len(puzzle_matrix) + non_movable_area.y
|
||||||
screen.blit(puzzle_pieces[puzzle_matrix[row][col] - 1][0], (piece_x, piece_y))
|
screen.blit(puzzle_pieces[puzzle_matrix[row][col] - 1][0], (piece_x, piece_y))
|
||||||
|
|
||||||
|
for button in current_buttons:
|
||||||
|
button.draw(screen)
|
||||||
|
|
||||||
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
|
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
|
||||||
mouse_x, mouse_y = pygame.mouse.get_pos()
|
mouse_x, mouse_y = pygame.mouse.get_pos()
|
||||||
|
|
||||||
|
|
|
@ -14,10 +14,10 @@
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
111,
|
112,
|
||||||
"00:01:00",
|
"00:01:02",
|
||||||
"00:01:00",
|
"00:01:02",
|
||||||
3
|
0
|
||||||
],
|
],
|
||||||
"3.png": [
|
"3.png": [
|
||||||
0,
|
0,
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"puzzle 4x4": [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 0]], "puzzle 3x3": [[1, 2, 3], [4, 5, 6], [7, 8, 0]], "current 4x4": {"matrix": [[6, 13, 10, 2], [4, 3, 5, 12], [11, 14, 8, 15], [1, 7, 9, 0]], "selected_image": "images/albums/Original images/2.png"}, "current 3x3": {"matrix": [[3, 6, 7], [5, 4, 1], [0, 8, 2]], "selected_image": "/images/albums/Birds/1.png"}}
|
{"puzzle 4x4": [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 0]], "puzzle 3x3": [[1, 2, 3], [4, 5, 6], [7, 8, 0]], "current 4x4": {"matrix": [[6, 13, 10, 2], [4, 3, 5, 12], [11, 14, 8, 0], [1, 7, 9, 15]], "selected_image": "images/albums/Original images/2.png"}, "current 3x3": {"matrix": [[3, 6, 7], [5, 4, 1], [0, 8, 2]], "selected_image": "/images/albums/Birds/1.png"}}
|