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,33 +687,53 @@ 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:
if event.key in (pygame.K_ESCAPE, pygame.K_RETURN): # Check for Alt modifier
return mods = pygame.key.get_mods()
alt_pressed = mods & pygame.KMOD_ALT
if event.key in [pygame.K_DOWN, pygame.K_s] and currentIndex < len(text) - 1: # Volume controls (require Alt)
currentIndex += 1 if alt_pressed:
speak(text[currentIndex]) 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 in [pygame.K_UP,pygame.K_w] and currentIndex > 0: if event.key in [pygame.K_DOWN, pygame.K_s] and currentIndex < len(text) - 1:
currentIndex -= 1 currentIndex += 1
speak(text[currentIndex]) speak(text[currentIndex])
if event.key == pygame.K_SPACE: if event.key in [pygame.K_UP, pygame.K_w] and currentIndex > 0:
speak(' '.join(text[1:])) currentIndex -= 1
speak(text[currentIndex])
if event.key == pygame.K_c: if event.key == pygame.K_SPACE:
try: speak(' '.join(text[1:]))
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: if event.key == pygame.K_c:
try: try:
pyperclip.copy(' '.join(text[1:-1])) pyperclip.copy(text[currentIndex])
speak("Copied entire message to the clipboard.") speak("Copied " + text[currentIndex] + " to the clipboard.")
except: except:
speak("Failed to copy the text to the clipboard.") 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() event = pygame.event.clear()
time.sleep(0.001) time.sleep(0.001)
@ -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,68 +895,81 @@ 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
if event.key == pygame.K_PAGEUP: mods = pygame.key.get_mods()
adjust_master_volume(0.1) alt_pressed = mods & pygame.KMOD_ALT
elif event.key == pygame.K_PAGEDOWN:
adjust_master_volume(-0.1) # Volume controls (require Alt)
elif event.key == pygame.K_HOME: if alt_pressed:
if currentIndex != 0: if event.key == pygame.K_PAGEUP:
currentIndex = 0 adjust_master_volume(0.1)
try: elif event.key == pygame.K_PAGEDOWN:
sounds['menu-move'].play() adjust_master_volume(-0.1)
except: elif event.key == pygame.K_HOME:
pass
if options[currentIndex] != "donate":
pygame.mixer.music.unpause()
else:
adjust_bgm_volume(0.1) adjust_bgm_volume(0.1)
elif event.key == pygame.K_END: elif event.key == pygame.K_END:
if currentIndex != len(options) - 1: adjust_bgm_volume(-0.1)
currentIndex = len(options) - 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: try:
sounds['menu-move'].play() sounds['menu-move'].play()
except: except:
pass pass
if options[currentIndex] != "donate": if options[currentIndex] != "donate":
pygame.mixer.music.unpause() pygame.mixer.music.unpause()
else: elif event.key in [pygame.K_UP, pygame.K_w] and currentIndex > 0:
adjust_bgm_volume(-0.1) currentIndex -= 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
try: try:
sounds['menu-select'].play() sounds['menu-move'].play()
time.sleep(sounds['menu-select'].get_length())
except: except:
pass pass
eval(options[currentIndex] + "()") if options[currentIndex] != "donate":
except: pygame.mixer.music.unpause()
lastSpoken = -1 elif event.key == pygame.K_RETURN:
return options[currentIndex] 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() event = pygame.event.clear()
time.sleep(0.001) time.sleep(0.001)