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
- Copy current line or full text
- 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:
text (list): List of text lines to display
@ -683,33 +687,53 @@ def display_text(text):
while True:
event = pygame.event.wait()
if event.type == pygame.KEYDOWN:
if event.key in (pygame.K_ESCAPE, pygame.K_RETURN):
return
if event.key in [pygame.K_DOWN, pygame.K_s] and currentIndex < len(text) - 1:
currentIndex += 1
speak(text[currentIndex])
if event.key in [pygame.K_UP,pygame.K_w] and currentIndex > 0:
currentIndex -= 1
speak(text[currentIndex])
if event.key == pygame.K_SPACE:
speak(' '.join(text[1:]))
if event.key == pygame.K_c:
try:
pyperclip.copy(text[currentIndex])
speak("Copied " + text[currentIndex] + " to the clipboard.")
except:
speak("Failed to copy the text to the clipboard.")
# 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):
return
if event.key == pygame.K_t:
try:
pyperclip.copy(' '.join(text[1:-1]))
speak("Copied entire message to the clipboard.")
except:
speak("Failed to copy the text to the clipboard.")
if event.key in [pygame.K_DOWN, pygame.K_s] and currentIndex < len(text) - 1:
currentIndex += 1
speak(text[currentIndex])
if event.key in [pygame.K_UP, pygame.K_w] and currentIndex > 0:
currentIndex -= 1
speak(text[currentIndex])
if event.key == pygame.K_SPACE:
speak(' '.join(text[1:]))
if event.key == pygame.K_c:
try:
pyperclip.copy(text[currentIndex])
speak("Copied " + text[currentIndex] + " to the clipboard.")
except:
speak("Failed to copy the text to the clipboard.")
if event.key == pygame.K_t:
try:
pyperclip.copy(' '.join(text[1:-1]))
speak("Copied entire message to the clipboard.")
except:
speak("Failed to copy the text to the clipboard.")
event = pygame.event.clear()
time.sleep(0.001)
@ -736,6 +760,11 @@ def instructions():
Reads and displays instructions from 'files/instructions.txt'.
If file is missing, displays an error message.
"""
try:
pygame.mixer.music.pause()
except:
pass
try:
with open('files/instructions.txt', 'r') as f:
info = f.readlines()
@ -743,6 +772,11 @@ def instructions():
info = ["Instructions file is missing."]
display_text(info)
try:
pygame.mixer.music.unpause()
except:
pass
def credits():
"""Display game credits from file.
@ -750,6 +784,11 @@ def credits():
Adds game name header before displaying.
If file is missing, displays an error message.
"""
try:
pygame.mixer.music.pause()
except:
pass
try:
with open('files/credits.txt', 'r') as f:
info = f.readlines()
@ -759,6 +798,11 @@ def credits():
info = ["Credits file is missing."]
display_text(info)
try:
pygame.mixer.music.unpause()
except:
pass
def learn_sounds(sounds):
"""Interactive menu for learning game sounds.
@ -825,14 +869,10 @@ def game_menu(sounds, *options):
- Home/End for first/last option
- Enter to select
- Escape to exit
- Volume controls for all options
Args:
sounds (dict): Dictionary of sound objects
*options: Variable list of menu options
Returns:
str: Selected menu option if not handled internally
- 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
"""
loop = True
pygame.mixer.stop()
@ -855,68 +895,81 @@ def game_menu(sounds, *options):
event = pygame.event.wait()
if event.type == pygame.KEYDOWN:
# Volume controls
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:
if currentIndex != 0:
currentIndex = 0
try:
sounds['menu-move'].play()
except:
pass
if options[currentIndex] != "donate":
pygame.mixer.music.unpause()
else:
# 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:
if currentIndex != len(options) - 1:
currentIndex = len(options) - 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:
if currentIndex != 0:
currentIndex = 0
try:
sounds['menu-move'].play()
except:
pass
if options[currentIndex] != "donate":
pygame.mixer.music.unpause()
elif event.key == pygame.K_END:
if currentIndex != len(options) - 1:
currentIndex = len(options) - 1
try:
sounds['menu-move'].play()
except:
pass
if options[currentIndex] != "donate":
pygame.mixer.music.unpause()
elif event.key in [pygame.K_DOWN, pygame.K_s] and currentIndex < len(options) - 1:
currentIndex += 1
try:
sounds['menu-move'].play()
except:
pass
if options[currentIndex] != "donate":
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:
currentIndex += 1
try:
sounds['menu-move'].play()
except:
pass
if options[currentIndex] != "donate":
pygame.mixer.music.unpause()
elif event.key in [pygame.K_UP, pygame.K_w] and currentIndex > 0:
currentIndex -= 1
try:
sounds['menu-move'].play()
except:
pass
if options[currentIndex] != "donate":
pygame.mixer.music.unpause()
elif event.key == pygame.K_RETURN:
try:
lastSpoken = -1
elif event.key in [pygame.K_UP, pygame.K_w] and currentIndex > 0:
currentIndex -= 1
try:
sounds['menu-select'].play()
time.sleep(sounds['menu-select'].get_length())
sounds['menu-move'].play()
except:
pass
eval(options[currentIndex] + "()")
except:
lastSpoken = -1
return options[currentIndex]
if options[currentIndex] != "donate":
pygame.mixer.music.unpause()
elif event.key == pygame.K_RETURN:
try:
lastSpoken = -1
try:
sounds['menu-select'].play()
time.sleep(sounds['menu-select'].get_length())
except:
pass
eval(options[currentIndex] + "()")
except:
lastSpoken = -1
pygame.mixer.music.fadeout(500)
try:
pygame.mixer.music.fadeout(750)
time.sleep(1.0)
except:
pass
return options[currentIndex]
event = pygame.event.clear()
time.sleep(0.001)