Binding for volume keys changed to alt+pageup/down, alt+home/end, etc.

This commit is contained in:
Storm Dragon 2025-02-08 19:21:14 -05:00
parent d5d737d0c0
commit b479811a98

View File

@ -669,6 +669,10 @@ def display_text(text):
- Listen to full text with space - Listen to full text with space
- Copy current line or full text - Copy current line or full text
- Exit with enter/escape - Exit with enter/escape
- Volume controls (with Alt modifier):
- Alt+PageUp/PageDown: Master volume up/down
- Alt+Home/End: Background music volume up/down
- Alt+Insert/Delete: Sound effects volume up/down
Args: Args:
text (list): List of text lines to display text (list): List of text lines to display
@ -683,6 +687,26 @@ def display_text(text):
while True: while True:
event = pygame.event.wait() event = pygame.event.wait()
if event.type == pygame.KEYDOWN: if event.type == pygame.KEYDOWN:
# Check for Alt modifier
mods = pygame.key.get_mods()
alt_pressed = mods & pygame.KMOD_ALT
# Volume controls (require Alt)
if alt_pressed:
if event.key == pygame.K_PAGEUP:
adjust_master_volume(0.1)
elif event.key == pygame.K_PAGEDOWN:
adjust_master_volume(-0.1)
elif event.key == pygame.K_HOME:
adjust_bgm_volume(0.1)
elif event.key == pygame.K_END:
adjust_bgm_volume(-0.1)
elif event.key == pygame.K_INSERT:
adjust_sfx_volume(0.1)
elif event.key == pygame.K_DELETE:
adjust_sfx_volume(-0.1)
# Regular text navigation (no Alt required)
else:
if event.key in (pygame.K_ESCAPE, pygame.K_RETURN): if event.key in (pygame.K_ESCAPE, pygame.K_RETURN):
return return
@ -736,6 +760,11 @@ def instructions():
Reads and displays instructions from 'files/instructions.txt'. Reads and displays instructions from 'files/instructions.txt'.
If file is missing, displays an error message. If file is missing, displays an error message.
""" """
try:
pygame.mixer.music.pause()
except:
pass
try: try:
with open('files/instructions.txt', 'r') as f: with open('files/instructions.txt', 'r') as f:
info = f.readlines() info = f.readlines()
@ -743,6 +772,11 @@ def instructions():
info = ["Instructions file is missing."] info = ["Instructions file is missing."]
display_text(info) display_text(info)
try:
pygame.mixer.music.unpause()
except:
pass
def credits(): def credits():
"""Display game credits from file. """Display game credits from file.
@ -750,6 +784,11 @@ def credits():
Adds game name header before displaying. Adds game name header before displaying.
If file is missing, displays an error message. If file is missing, displays an error message.
""" """
try:
pygame.mixer.music.pause()
except:
pass
try: try:
with open('files/credits.txt', 'r') as f: with open('files/credits.txt', 'r') as f:
info = f.readlines() info = f.readlines()
@ -759,6 +798,11 @@ def credits():
info = ["Credits file is missing."] info = ["Credits file is missing."]
display_text(info) display_text(info)
try:
pygame.mixer.music.unpause()
except:
pass
def learn_sounds(sounds): def learn_sounds(sounds):
"""Interactive menu for learning game sounds. """Interactive menu for learning game sounds.
@ -825,14 +869,10 @@ def game_menu(sounds, *options):
- Home/End for first/last option - Home/End for first/last option
- Enter to select - Enter to select
- Escape to exit - Escape to exit
- Volume controls for all options - Volume controls (with Alt modifier):
- Alt+PageUp/PageDown: Master volume up/down
Args: - Alt+Home/End: Background music volume up/down
sounds (dict): Dictionary of sound objects - Alt+Insert/Delete: Sound effects volume up/down
*options: Variable list of menu options
Returns:
str: Selected menu option if not handled internally
""" """
loop = True loop = True
pygame.mixer.stop() pygame.mixer.stop()
@ -855,11 +895,28 @@ def game_menu(sounds, *options):
event = pygame.event.wait() event = pygame.event.wait()
if event.type == pygame.KEYDOWN: if event.type == pygame.KEYDOWN:
# Volume controls # Check for Alt modifier
mods = pygame.key.get_mods()
alt_pressed = mods & pygame.KMOD_ALT
# Volume controls (require Alt)
if alt_pressed:
if event.key == pygame.K_PAGEUP: if event.key == pygame.K_PAGEUP:
adjust_master_volume(0.1) adjust_master_volume(0.1)
elif event.key == pygame.K_PAGEDOWN: elif event.key == pygame.K_PAGEDOWN:
adjust_master_volume(-0.1) adjust_master_volume(-0.1)
elif event.key == pygame.K_HOME:
adjust_bgm_volume(0.1)
elif event.key == pygame.K_END:
adjust_bgm_volume(-0.1)
elif event.key == pygame.K_INSERT:
adjust_sfx_volume(0.1)
elif event.key == pygame.K_DELETE:
adjust_sfx_volume(-0.1)
# Regular menu navigation (no Alt required)
else:
if event.key == pygame.K_ESCAPE:
exit_game()
elif event.key == pygame.K_HOME: elif event.key == pygame.K_HOME:
if currentIndex != 0: if currentIndex != 0:
currentIndex = 0 currentIndex = 0
@ -869,8 +926,6 @@ def game_menu(sounds, *options):
pass pass
if options[currentIndex] != "donate": if options[currentIndex] != "donate":
pygame.mixer.music.unpause() pygame.mixer.music.unpause()
else:
adjust_bgm_volume(0.1)
elif event.key == pygame.K_END: elif event.key == pygame.K_END:
if currentIndex != len(options) - 1: if currentIndex != len(options) - 1:
currentIndex = len(options) - 1 currentIndex = len(options) - 1
@ -880,15 +935,6 @@ def game_menu(sounds, *options):
pass pass
if options[currentIndex] != "donate": if options[currentIndex] != "donate":
pygame.mixer.music.unpause() pygame.mixer.music.unpause()
else:
adjust_bgm_volume(-0.1)
elif event.key == pygame.K_INSERT:
adjust_sfx_volume(0.1)
elif event.key == pygame.K_DELETE:
adjust_sfx_volume(-0.1)
# Menu navigation
elif event.key == pygame.K_ESCAPE:
exit_game()
elif event.key in [pygame.K_DOWN, pygame.K_s] and currentIndex < len(options) - 1: elif event.key in [pygame.K_DOWN, pygame.K_s] and currentIndex < len(options) - 1:
currentIndex += 1 currentIndex += 1
try: try:
@ -916,6 +962,13 @@ def game_menu(sounds, *options):
eval(options[currentIndex] + "()") eval(options[currentIndex] + "()")
except: except:
lastSpoken = -1 lastSpoken = -1
pygame.mixer.music.fadeout(500)
try:
pygame.mixer.music.fadeout(750)
time.sleep(1.0)
except:
pass
return options[currentIndex] return options[currentIndex]
event = pygame.event.clear() event = pygame.event.clear()