elukjanovica 2024-05-21 20:57:56 +03:00
parent 52902e988c
commit 1f2e610ac9
1 changed files with 30 additions and 11 deletions

41
main.py
View File

@ -404,12 +404,15 @@ def quick_game():
def render_albums():
global current_mode, album_name
global current_mode, album_name, album_delete
current_hovered_index = -1
size_to_y = {"small": 25, "medium": 35, "big": 65}
y = size_to_y[current_size]
for hover_index, album in enumerate(storage["albums"]):
# Collect albums to be deleted
albums_to_delete = []
for hover_index, album in enumerate(list(storage["albums"].keys())):
render_text(album, (size[1], y), screen)
album_rect = pygame.Rect(size[0], y, size[2], size[3])
album_hover = album_rect.collidepoint(pygame.mouse.get_pos())
@ -418,17 +421,31 @@ def render_albums():
current_hovered_index = hover_index
if album_hover and pygame.mouse.get_pressed()[0]:
album_name = album
if album_name != album:
album_name = None
if album_delete:
if album in storage["albums"]:
albums_to_delete.append(album)
album_delete = False
else:
print(f"Album {album} not found in storage.")
else:
album_name = album
if album_name != album:
album_name = None
if album_name is not None:
current_mode = "select"
if album_name is not None:
current_mode = "select"
return album
return album
y += cons[0]
for album in albums_to_delete:
del storage["albums"][album]
if albums_to_delete:
with open(DATA_FILE, 'w') as data_file:
data_file.write(json.dumps(storage, indent=3))
if current_hovered_index == -1:
current_hovered_index = 0
arrow_image = Image((cons[1], 0), (cons[2], size[1] + cons[0] * current_hovered_index + cons[3]), (cons[4], cons[4]))
@ -991,7 +1008,7 @@ settings_buttons = [info_button, menu_button, stats_button, continue_button, clo
do_not_save = False
def button_check(pressed_button, run, current_mode, timer_running):
def button_check(pressed_button, run, current_mode, timer_running, album_delete):
global completed, not_shuffled, current_timer_text, current_moves, real_time
do_not_save = False
if pressed_button == close_button:
@ -1009,6 +1026,7 @@ def button_check(pressed_button, run, current_mode, timer_running):
elif pressed_button == delete_button:
if current_mode == "menu":
album_deletion()
album_delete = True
else:
# Not finished yet
pass
@ -1029,7 +1047,7 @@ def button_check(pressed_button, run, current_mode, timer_running):
elif pressed_button == stats_button:
current_mode = "stats"
return run, current_mode, timer_running, do_not_save
return run, current_mode, timer_running, do_not_save, album_delete
win32gui.SetWindowLong(hwnd, win32con.GWL_EXSTYLE,
@ -1062,6 +1080,7 @@ def data_check(current_mode):
# Game state
run = True
current_mode = "menu"
album_delete = False
# Dragging and mouse interaction
dragging = False
can_move = False
@ -1174,7 +1193,7 @@ while run:
for button in current_buttons:
if button.rect.collidepoint(start_pos):
pressed_button = button
run, current_mode, timer_running, do_not_save = button_check(pressed_button, run, current_mode, timer_running)
run, current_mode, timer_running, do_not_save, album_delete = button_check(pressed_button, run, current_mode, timer_running, album_delete)
elif event.type == pygame.MOUSEMOTION and can_move:
new_pos = pygame.mouse.get_pos()