main
parent
1f2e610ac9
commit
6e8ce4b544
Binary file not shown.
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 4.6 KiB |
Binary file not shown.
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 5.9 KiB |
Binary file not shown.
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 13 KiB |
126
main.py
126
main.py
|
@ -97,14 +97,25 @@ if current_size == SIZE_CHOICES[0]:
|
||||||
# --> timer_area[1] (1) - position y for timer area
|
# --> timer_area[1] (1) - position y for timer area
|
||||||
# --> timer_area[2] (55) - width of timer area
|
# --> timer_area[2] (55) - width of timer area
|
||||||
# --> timer_area[3] (12) - heigth of timer area
|
# --> timer_area[3] (12) - heigth of timer area
|
||||||
win_area = pygame.Rect(74, 78, 128, 128)
|
win_area = pygame.Rect(74, 78, 128, 128) # "You win !!" area positioning
|
||||||
# --> win_area[0] (74) - position x for "You win !!" text area in game mode
|
# --> win_area[0] (74) - position x for "You win !!" text area in game mode
|
||||||
# --> win_area[1] (78) - position y for "You win !!" text area
|
# --> win_area[1] (78) - position y for "You win !!" text area
|
||||||
# --> win_area[2] (128) - width of "You win !!" text area
|
# --> win_area[2] (128) - width of "You win !!" text area
|
||||||
# --> win_area[3] (128) - heigth of "You win !!" text area
|
# --> win_area[3] (128) - heigth of "You win !!" text area
|
||||||
size = [20, 25, 116, 15]
|
size = [20, 25, 116, 15] # album name positioning
|
||||||
cons = [15, 195, 12, 3, 9]
|
# --> size[0] (20) - x position of clickable area
|
||||||
# size and cons (constants) are too complicated, I cant remember what each element was, sorry :(
|
# --> size[1] (25) - x position of album name
|
||||||
|
# --> size[2] (116) - width of clickable area
|
||||||
|
# --> size[3] (15) - height of clickable area
|
||||||
|
cons = [15, 195, 12, 3, 9] # constants, reffering to arrow
|
||||||
|
# --> cons[0] (15) - spacing between album names
|
||||||
|
# --> cons[1] (195) - position x for element in spritesheet
|
||||||
|
# --> cons[2] (12) - x position of arrow
|
||||||
|
# --> cons[3] (3) - aligned y position of arrow next to album name
|
||||||
|
# --> cons[4] (9) - size of arrow
|
||||||
|
checkbox = [233, 9] # checkbox positioning
|
||||||
|
# --> checkbox[0] (233) - position x for arrow in spritesheet
|
||||||
|
# --> checkbox[1] (9) - size of checkbox in spritesheet
|
||||||
scaled_size = (18, 21, 108, 108)
|
scaled_size = (18, 21, 108, 108)
|
||||||
# --> scaled_size[0] (18) - x position for image in select mode
|
# --> scaled_size[0] (18) - x position for image in select mode
|
||||||
# --> scaled_size[1] (21) - y position for image
|
# --> scaled_size[1] (21) - y position for image
|
||||||
|
@ -118,9 +129,9 @@ if current_size == SIZE_CHOICES[0]:
|
||||||
# --> spaces[2] (20) - space between setting names, increasing
|
# --> spaces[2] (20) - space between setting names, increasing
|
||||||
# --> spaces[3] (30) - space between slider and non_movable_area edge, decreasing
|
# --> spaces[3] (30) - space between slider and non_movable_area edge, decreasing
|
||||||
# --> spaces[4] (8) - space between setting names and non_movable_area edge, increasing
|
# --> spaces[4] (8) - space between setting names and non_movable_area edge, increasing
|
||||||
f_line = [92, 30, 80, 12]
|
f_line = [92, 30, 80, 12] # first line positioning
|
||||||
s_line = [92, 45, 80, 12]
|
s_line = [92, 45, 80, 12] # second line positioning
|
||||||
s_button = [175, 30, 10, 16]
|
s_button = [175, 30, 10, 16] # second button positioning
|
||||||
# for list in f_line, s_line and s_button:
|
# for list in f_line, s_line and s_button:
|
||||||
# --> list[0] (135, 135, 218) - position x for element in spritesheet
|
# --> list[0] (135, 135, 218) - position x for element in spritesheet
|
||||||
# --> list[1] (38, 53, 38) - position y for element in spritesheet
|
# --> list[1] (38, 53, 38) - position y for element in spritesheet
|
||||||
|
@ -149,6 +160,7 @@ elif current_size == SIZE_CHOICES[1]:
|
||||||
win_area = pygame.Rect(104, 108, 180, 180)
|
win_area = pygame.Rect(104, 108, 180, 180)
|
||||||
size = [30, 35, 161, 25]
|
size = [30, 35, 161, 25]
|
||||||
cons = [25, 247, 18, 3, 13]
|
cons = [25, 247, 18, 3, 13]
|
||||||
|
checkbox = [296, 13]
|
||||||
scaled_size = (22, 26, 158, 158)
|
scaled_size = (22, 26, 158, 158)
|
||||||
area = (100, 200)
|
area = (100, 200)
|
||||||
spaces = [14, 30, 30, 40, 8]
|
spaces = [14, 30, 30, 40, 8]
|
||||||
|
@ -180,6 +192,7 @@ else:
|
||||||
win_area = pygame.Rect(200, 214, 360, 360)
|
win_area = pygame.Rect(200, 214, 360, 360)
|
||||||
size = [50, 58, 328, 35]
|
size = [50, 58, 328, 35]
|
||||||
cons = [35, 455, 26, 10, 26]
|
cons = [35, 455, 26, 10, 26]
|
||||||
|
checkbox = [565, 27]
|
||||||
scaled_size = (43, 48, 310, 310)
|
scaled_size = (43, 48, 310, 310)
|
||||||
area = (197, 390)
|
area = (197, 390)
|
||||||
spaces = [24, 34, 50, 84, 8]
|
spaces = [24, 34, 50, 84, 8]
|
||||||
|
@ -404,59 +417,86 @@ def quick_game():
|
||||||
|
|
||||||
|
|
||||||
def render_albums():
|
def render_albums():
|
||||||
global current_mode, album_name, album_delete
|
global current_mode, album_name, delete_mode, accepted
|
||||||
current_hovered_index = -1
|
current_hovered_index = -1
|
||||||
size_to_y = {"small": 25, "medium": 35, "big": 65}
|
size_to_y = {"small": 25, "medium": 35, "big": 65}
|
||||||
y = size_to_y[current_size]
|
y = size_to_y[current_size]
|
||||||
|
|
||||||
# Collect albums to be deleted
|
|
||||||
albums_to_delete = []
|
albums_to_delete = []
|
||||||
|
checked = False
|
||||||
|
|
||||||
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)
|
||||||
album_rect = pygame.Rect(size[0], y, size[2], size[3])
|
album_rect = pygame.Rect(size[0], y, size[2], size[3])
|
||||||
album_hover = album_rect.collidepoint(pygame.mouse.get_pos())
|
album_hover = album_rect.collidepoint(pygame.mouse.get_pos())
|
||||||
|
|
||||||
if album_hover:
|
current_hovered_index = update_hover_index(current_hovered_index, album_hover, hover_index)
|
||||||
current_hovered_index = hover_index
|
|
||||||
|
|
||||||
if album_hover and pygame.mouse.get_pressed()[0]:
|
|
||||||
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"
|
|
||||||
|
|
||||||
|
album = handle_album_interaction(album_hover, album)
|
||||||
|
if album:
|
||||||
return album
|
return album
|
||||||
|
|
||||||
|
if delete_mode:
|
||||||
|
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]:
|
||||||
|
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]
|
||||||
|
|
||||||
|
if delete_mode and albums_to_delete:
|
||||||
|
accepted = True
|
||||||
|
delete_albums(albums_to_delete)
|
||||||
|
delete_mode = False
|
||||||
|
|
||||||
|
if delete_mode is False:
|
||||||
|
draw_arrow(current_hovered_index)
|
||||||
|
|
||||||
|
|
||||||
|
def update_hover_index(current_hovered_index, album_hover, hover_index):
|
||||||
|
if album_hover:
|
||||||
|
current_hovered_index = hover_index
|
||||||
|
return current_hovered_index
|
||||||
|
|
||||||
|
|
||||||
|
def handle_album_interaction(album_hover, album):
|
||||||
|
global current_mode, album_name
|
||||||
|
|
||||||
|
if album_hover and pygame.mouse.get_pressed()[0]:
|
||||||
|
album_name = album
|
||||||
|
if album_name is not None:
|
||||||
|
current_mode = "select"
|
||||||
|
return album
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def delete_albums(albums_to_delete):
|
||||||
for album in albums_to_delete:
|
for album in albums_to_delete:
|
||||||
del storage["albums"][album]
|
del storage["albums"][album]
|
||||||
|
|
||||||
if albums_to_delete:
|
|
||||||
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):
|
||||||
if current_hovered_index == -1:
|
if current_hovered_index == -1:
|
||||||
current_hovered_index = 0
|
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]))
|
arrow_image = Image((cons[1], 0), (cons[2], size[1] + cons[0] * current_hovered_index + cons[3]), (cons[4], cons[4]))
|
||||||
arrow_image.draw(screen)
|
arrow_image.draw(screen)
|
||||||
|
|
||||||
|
|
||||||
def album_deletion():
|
|
||||||
# Not finished yet
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def album_creation():
|
def album_creation():
|
||||||
# Not finished yet
|
# Not finished yet
|
||||||
pass
|
pass
|
||||||
|
@ -1008,8 +1048,8 @@ settings_buttons = [info_button, menu_button, stats_button, continue_button, clo
|
||||||
do_not_save = False
|
do_not_save = False
|
||||||
|
|
||||||
|
|
||||||
def button_check(pressed_button, run, current_mode, timer_running, album_delete):
|
def button_check(pressed_button, run, current_mode, timer_running, delete_mode):
|
||||||
global completed, not_shuffled, current_timer_text, current_moves, real_time
|
global completed, not_shuffled, current_timer_text, current_moves, real_time, accepted
|
||||||
do_not_save = False
|
do_not_save = False
|
||||||
if pressed_button == close_button:
|
if pressed_button == close_button:
|
||||||
run = False
|
run = False
|
||||||
|
@ -1025,11 +1065,14 @@ def button_check(pressed_button, run, current_mode, timer_running, album_delete)
|
||||||
current_mode = "game"
|
current_mode = "game"
|
||||||
elif pressed_button == delete_button:
|
elif pressed_button == delete_button:
|
||||||
if current_mode == "menu":
|
if current_mode == "menu":
|
||||||
album_deletion()
|
if not delete_mode:
|
||||||
album_delete = True
|
delete_mode = True
|
||||||
|
accepted = False
|
||||||
|
elif not accepted:
|
||||||
|
accepted = True
|
||||||
else:
|
else:
|
||||||
# Not finished yet
|
delete_mode = False
|
||||||
pass
|
accepted = False
|
||||||
elif pressed_button == new_button:
|
elif pressed_button == new_button:
|
||||||
album_creation()
|
album_creation()
|
||||||
elif pressed_button == quick_add_button:
|
elif pressed_button == quick_add_button:
|
||||||
|
@ -1047,7 +1090,7 @@ def button_check(pressed_button, run, current_mode, timer_running, album_delete)
|
||||||
elif pressed_button == stats_button:
|
elif pressed_button == stats_button:
|
||||||
current_mode = "stats"
|
current_mode = "stats"
|
||||||
|
|
||||||
return run, current_mode, timer_running, do_not_save, album_delete
|
return run, current_mode, timer_running, do_not_save, delete_mode
|
||||||
|
|
||||||
|
|
||||||
win32gui.SetWindowLong(hwnd, win32con.GWL_EXSTYLE,
|
win32gui.SetWindowLong(hwnd, win32con.GWL_EXSTYLE,
|
||||||
|
@ -1080,7 +1123,8 @@ def data_check(current_mode):
|
||||||
# Game state
|
# Game state
|
||||||
run = True
|
run = True
|
||||||
current_mode = "menu"
|
current_mode = "menu"
|
||||||
album_delete = False
|
delete_mode = False
|
||||||
|
accepted = False
|
||||||
# Dragging and mouse interaction
|
# Dragging and mouse interaction
|
||||||
dragging = False
|
dragging = False
|
||||||
can_move = False
|
can_move = False
|
||||||
|
@ -1193,7 +1237,7 @@ while run:
|
||||||
for button in current_buttons:
|
for button in current_buttons:
|
||||||
if button.rect.collidepoint(start_pos):
|
if button.rect.collidepoint(start_pos):
|
||||||
pressed_button = button
|
pressed_button = button
|
||||||
run, current_mode, timer_running, do_not_save, album_delete = button_check(pressed_button, run, current_mode, timer_running, album_delete)
|
run, current_mode, timer_running, do_not_save, delete_mode = button_check(pressed_button, run, current_mode, timer_running, delete_mode)
|
||||||
|
|
||||||
elif event.type == pygame.MOUSEMOTION and can_move:
|
elif event.type == pygame.MOUSEMOTION and can_move:
|
||||||
new_pos = pygame.mouse.get_pos()
|
new_pos = pygame.mouse.get_pos()
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
{
|
{
|
||||||
"size": "big",
|
"size": "small",
|
||||||
"style": "classic",
|
"style": "classic",
|
||||||
"grid": "4x4",
|
"grid": "4x4",
|
||||||
"gui color": 0,
|
"gui color": 0,
|
||||||
"music": {
|
"music": {
|
||||||
"on": true,
|
"on": true,
|
||||||
"volume": 8,
|
"volume": 0,
|
||||||
"version": "serenity"
|
"version": "serenity"
|
||||||
},
|
},
|
||||||
"sound": {
|
"sound": {
|
||||||
|
|
Loading…
Reference in New Issue