elukjanovica 2024-06-05 18:57:29 +03:00
parent 9694a271d6
commit f7212f320d
2 changed files with 38 additions and 38 deletions

60
main.py
View File

@ -417,13 +417,11 @@ def quick_game():
def render_albums():
global current_mode, album_name, delete_mode, accepted
global current_mode, album_name, delete_mode, accepted, adjusted_pos
current_hovered_index = -1
size_to_y = {"small": 25, "medium": 35, "big": 65}
y = size_to_y[current_size]
albums_to_delete = []
checked = {}
adjusted_pos = None
for hover_index, album in enumerate(list(storage["albums"].keys())):
render_text(album, (size[1], y), screen)
@ -437,16 +435,18 @@ def render_albums():
return album
if delete_mode:
if album not in checked:
checked[album] = False
delete_albums_mode(album, albums_to_delete, checked, y, album_rect, current_hovered_index)
albums_to_delete = delete_albums_mode(album, y, album_rect, current_hovered_index)
if adjusted_pos:
album_hoverrr = album_rect.collidepoint(adjusted_pos)
index = update_hover_index(current_hovered_index, album_hoverrr, hover_index)
bebra = list(storage["albums"].keys())[index]
y += cons[0]
if delete_mode and albums_to_delete:
accepted = True
if accepted and albums_to_delete:
delete_albums(albums_to_delete)
delete_mode = False
accepted = False
if not delete_mode:
draw_arrow(current_hovered_index)
@ -473,7 +473,9 @@ def handle_album_interaction(album_hover, album):
return None
def delete_albums_mode(album, albums_to_delete, checked, y, album_rect, current_hovered_index):
def delete_albums_mode(album, y, album_rect, current_hovered_index):
global adjusted_pos
albums_to_delete = []
checkbox_rect = pygame.Rect(cons[2], y + cons[3], checkbox[1], checkbox[1])
checkbox_hover = checkbox_rect.collidepoint(pygame.mouse.get_pos())
@ -481,33 +483,32 @@ def delete_albums_mode(album, albums_to_delete, checked, y, album_rect, current_
pygame.time.wait(100)
cursor_pos = pygame.mouse.get_pos()
adjusted_pos = (cursor_pos[0] + 30, cursor_pos[1])
print("Adjusted Pos:", adjusted_pos)
print("Album Rect:", album_rect)
adjusted_pos = (cursor_pos[0] + 20, cursor_pos[1])
#print("Adjusted Pos:", adjusted_pos, current_hovered_index)
#print("Album Rect:", album_rect)
if current_hovered_index is not None and current_hovered_index >= 0:
hovered_album = list(storage["albums"].keys())[current_hovered_index]
if hovered_album == album:
print("Checkbox Clicked for Album:", album)
if album_rect.collidepoint(adjusted_pos):
#print(album)
album = list(storage["albums"].keys())[current_hovered_index]
#print("Checkbox Clicked for Album:", album)
checked[album] = not checked[album]
if checked[album]:
if album not in albums_to_delete:
albums_to_delete.append(album)
print("Album added to delete:", album)
#print(albums_to_delete, album)
else:
if album in albums_to_delete:
albums_to_delete.remove(album)
print("Album removed from delete:", album)
#print("Album removed from delete:", album)
#print(albums_to_delete, adjusted_pos)
return albums_to_delete
checkbox_image = Image((checkbox[0], 0), (cons[2], y + cons[3]), (checkbox[1], checkbox[1]))
if checked[album]:
if album in albums_to_delete:
checkbox_image = Image((checkbox[0] + checkbox[1] + 3, 0), (cons[2], y + cons[3]), (checkbox[1], checkbox[1]))
checkbox_image.draw(screen)
def delete_albums(albums_to_delete):
for album in albums_to_delete:
if album in storage["albums"]:
@ -536,7 +537,6 @@ def album_creation(y):
mouse_clicked = pygame.mouse.get_pressed()[0]
keys = pygame.key.get_pressed()
if (user_text and mouse_clicked) or (user_text and keys[pygame.K_RETURN]):
user_text = user_text.strip()
if user_text not in storage["albums"]:
storage["albums"][user_text] = {}
with open(DATA_FILE, 'w') as data_file:
@ -1108,14 +1108,10 @@ def button_check(pressed_button, run, current_mode, timer_running, delete_mode):
current_mode = "game"
elif pressed_button == delete_button:
if current_mode == "menu":
if not delete_mode:
if delete_mode is False:
delete_mode = True
accepted = False
elif not accepted:
elif accepted is False:
accepted = True
else:
delete_mode = False
accepted = False
elif pressed_button == new_button:
if current_mode == "menu":
typing = True
@ -1312,7 +1308,7 @@ while run:
if event.key == pygame.K_BACKSPACE:
user_text = user_text[0:-1]
elif len(user_text) < 15:
elif len(user_text) < 15 and event.key != pygame.K_RETURN:
user_text += event.unicode
if current_mode == "game":

View File

@ -120,6 +120,10 @@
"00:00:00",
0
]
}
},
"2": {},
"3": {},
"4": {},
"5": {}
}
}