main
parent
6e8ce4b544
commit
1e8f1e3fa7
104
main.py
104
main.py
|
@ -423,7 +423,7 @@ def render_albums():
|
||||||
y = size_to_y[current_size]
|
y = size_to_y[current_size]
|
||||||
|
|
||||||
albums_to_delete = []
|
albums_to_delete = []
|
||||||
checked = False
|
checked = {}
|
||||||
|
|
||||||
for hover_index, album in enumerate(list(storage["albums"].keys())):
|
for hover_index, album in enumerate(list(storage["albums"].keys())):
|
||||||
render_text(album, (size[1], y), screen)
|
render_text(album, (size[1], y), screen)
|
||||||
|
@ -435,24 +435,11 @@ def render_albums():
|
||||||
album = handle_album_interaction(album_hover, album)
|
album = handle_album_interaction(album_hover, album)
|
||||||
if album:
|
if album:
|
||||||
return album
|
return album
|
||||||
|
|
||||||
if delete_mode:
|
if delete_mode:
|
||||||
checkbox_rect = pygame.Rect(cons[2], y + cons[3], checkbox[1], checkbox[1])
|
if album not in checked:
|
||||||
checkbox_hover = checkbox_rect.collidepoint(pygame.mouse.get_pos())
|
checked[album] = False
|
||||||
|
delete_albums_mode(album, albums_to_delete, checked, y, album_rect, current_hovered_index)
|
||||||
if checkbox_hover and pygame.mouse.get_pressed()[0]:
|
|
||||||
checked = not checked
|
|
||||||
|
|
||||||
if checked:
|
|
||||||
if album not in albums_to_delete:
|
|
||||||
albums_to_delete.append(album)
|
|
||||||
checkbox_image = Image((checkbox[0] + checkbox[1] + 3, 0), (cons[2], y + cons[3]), (checkbox[1], checkbox[1]))
|
|
||||||
else:
|
|
||||||
if album in albums_to_delete:
|
|
||||||
albums_to_delete.remove(album)
|
|
||||||
|
|
||||||
checkbox_image = Image((checkbox[0], 0), (cons[2], y + cons[3]), (checkbox[1], checkbox[1]))
|
|
||||||
checkbox_image.draw(screen)
|
|
||||||
|
|
||||||
y += cons[0]
|
y += cons[0]
|
||||||
|
|
||||||
|
@ -461,8 +448,11 @@ def render_albums():
|
||||||
delete_albums(albums_to_delete)
|
delete_albums(albums_to_delete)
|
||||||
delete_mode = False
|
delete_mode = False
|
||||||
|
|
||||||
if delete_mode is False:
|
if not delete_mode:
|
||||||
draw_arrow(current_hovered_index)
|
draw_arrow(current_hovered_index)
|
||||||
|
|
||||||
|
if typing:
|
||||||
|
album_creation(y)
|
||||||
|
|
||||||
|
|
||||||
def update_hover_index(current_hovered_index, album_hover, hover_index):
|
def update_hover_index(current_hovered_index, album_hover, hover_index):
|
||||||
|
@ -483,13 +473,50 @@ def handle_album_interaction(album_hover, album):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def delete_albums_mode(album, albums_to_delete, checked, y, album_rect, current_hovered_index):
|
||||||
|
checkbox_rect = pygame.Rect(cons[2], y + cons[3], checkbox[1], checkbox[1])
|
||||||
|
checkbox_hover = checkbox_rect.collidepoint(pygame.mouse.get_pos())
|
||||||
|
|
||||||
|
if checkbox_hover and pygame.mouse.get_pressed()[0]:
|
||||||
|
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)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
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)
|
||||||
|
else:
|
||||||
|
if album in albums_to_delete:
|
||||||
|
albums_to_delete.remove(album)
|
||||||
|
print("Album removed from delete:", album)
|
||||||
|
|
||||||
|
checkbox_image = Image((checkbox[0], 0), (cons[2], y + cons[3]), (checkbox[1], checkbox[1]))
|
||||||
|
if checked[album]:
|
||||||
|
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):
|
def delete_albums(albums_to_delete):
|
||||||
for album in albums_to_delete:
|
for album in albums_to_delete:
|
||||||
del storage["albums"][album]
|
if album in storage["albums"]:
|
||||||
|
del storage["albums"][album]
|
||||||
|
|
||||||
with open(DATA_FILE, 'w') as data_file:
|
with open(DATA_FILE, 'w') as data_file:
|
||||||
data_file.write(json.dumps(storage, indent=3))
|
data_file.write(json.dumps(storage, indent=3))
|
||||||
|
|
||||||
|
|
||||||
def draw_arrow(current_hovered_index):
|
def draw_arrow(current_hovered_index):
|
||||||
if current_hovered_index == -1:
|
if current_hovered_index == -1:
|
||||||
current_hovered_index = 0
|
current_hovered_index = 0
|
||||||
|
@ -497,9 +524,24 @@ def draw_arrow(current_hovered_index):
|
||||||
arrow_image.draw(screen)
|
arrow_image.draw(screen)
|
||||||
|
|
||||||
|
|
||||||
def album_creation():
|
def album_creation(y):
|
||||||
# Not finished yet
|
global user_text, typing
|
||||||
pass
|
|
||||||
|
render_text(user_text, (size[1], y), screen)
|
||||||
|
|
||||||
|
if pygame.time.get_ticks() % 1000 < 500:
|
||||||
|
caret_x = size[1] + pygame.font.SysFont(FONT, FONT_SIZE).size(user_text)[0] - 2
|
||||||
|
render_text("|", (caret_x, y), screen)
|
||||||
|
|
||||||
|
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]):
|
||||||
|
if user_text not in storage["albums"]:
|
||||||
|
storage["albums"][user_text] = {}
|
||||||
|
with open(DATA_FILE, 'w') as data_file:
|
||||||
|
data_file.write(json.dumps(storage, indent=3))
|
||||||
|
typing = False
|
||||||
|
user_text = ''
|
||||||
|
|
||||||
# SELECT MODE
|
# SELECT MODE
|
||||||
class ImageRender:
|
class ImageRender:
|
||||||
|
@ -1049,7 +1091,7 @@ do_not_save = False
|
||||||
|
|
||||||
|
|
||||||
def button_check(pressed_button, run, current_mode, timer_running, delete_mode):
|
def button_check(pressed_button, run, current_mode, timer_running, delete_mode):
|
||||||
global completed, not_shuffled, current_timer_text, current_moves, real_time, accepted
|
global completed, not_shuffled, current_timer_text, current_moves, real_time, accepted, typing
|
||||||
do_not_save = False
|
do_not_save = False
|
||||||
if pressed_button == close_button:
|
if pressed_button == close_button:
|
||||||
run = False
|
run = False
|
||||||
|
@ -1074,7 +1116,8 @@ def button_check(pressed_button, run, current_mode, timer_running, delete_mode):
|
||||||
delete_mode = False
|
delete_mode = False
|
||||||
accepted = False
|
accepted = False
|
||||||
elif pressed_button == new_button:
|
elif pressed_button == new_button:
|
||||||
album_creation()
|
if current_mode == "menu":
|
||||||
|
typing = True
|
||||||
elif pressed_button == quick_add_button:
|
elif pressed_button == quick_add_button:
|
||||||
quick_game()
|
quick_game()
|
||||||
current_mode = "game"
|
current_mode = "game"
|
||||||
|
@ -1133,6 +1176,8 @@ pressed_button = None
|
||||||
slider_moving = False
|
slider_moving = False
|
||||||
setting = None
|
setting = None
|
||||||
arrow = None
|
arrow = None
|
||||||
|
user_text = ''
|
||||||
|
typing = False
|
||||||
# Select mode
|
# Select mode
|
||||||
clicked_image = False
|
clicked_image = False
|
||||||
image_display = None
|
image_display = None
|
||||||
|
@ -1261,6 +1306,15 @@ while run:
|
||||||
elif event.button == 5:
|
elif event.button == 5:
|
||||||
scroll_offset += 20
|
scroll_offset += 20
|
||||||
scroll_offset = min(scroll_offset, max_scroll_offset)
|
scroll_offset = min(scroll_offset, max_scroll_offset)
|
||||||
|
|
||||||
|
elif typing and event.type == pygame.KEYDOWN:
|
||||||
|
|
||||||
|
if event.key == pygame.K_BACKSPACE:
|
||||||
|
user_text = user_text[0:-1]
|
||||||
|
elif len(user_text) < 15:
|
||||||
|
user_text += event.unicode
|
||||||
|
elif event.key == pygame.K_RETURN:
|
||||||
|
user_text = user_text.strip()
|
||||||
|
|
||||||
if current_mode == "game":
|
if current_mode == "game":
|
||||||
if timer_running:
|
if timer_running:
|
||||||
|
|
Loading…
Reference in New Issue