Binding for volume keys changed to alt+pageup/down, alt+home/end, etc.
This commit is contained in:
parent
d5d737d0c0
commit
b479811a98
95
__init__.py
95
__init__.py
@ -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,6 +687,26 @@ def display_text(text):
|
||||
while True:
|
||||
event = pygame.event.wait()
|
||||
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):
|
||||
return
|
||||
|
||||
@ -690,7 +714,7 @@ def display_text(text):
|
||||
currentIndex += 1
|
||||
speak(text[currentIndex])
|
||||
|
||||
if event.key in [pygame.K_UP,pygame.K_w] and currentIndex > 0:
|
||||
if event.key in [pygame.K_UP, pygame.K_w] and currentIndex > 0:
|
||||
currentIndex -= 1
|
||||
speak(text[currentIndex])
|
||||
|
||||
@ -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,11 +895,28 @@ def game_menu(sounds, *options):
|
||||
|
||||
event = pygame.event.wait()
|
||||
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:
|
||||
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 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
|
||||
@ -869,8 +926,6 @@ def game_menu(sounds, *options):
|
||||
pass
|
||||
if options[currentIndex] != "donate":
|
||||
pygame.mixer.music.unpause()
|
||||
else:
|
||||
adjust_bgm_volume(0.1)
|
||||
elif event.key == pygame.K_END:
|
||||
if currentIndex != len(options) - 1:
|
||||
currentIndex = len(options) - 1
|
||||
@ -880,15 +935,6 @@ def game_menu(sounds, *options):
|
||||
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:
|
||||
@ -916,6 +962,13 @@ def game_menu(sounds, *options):
|
||||
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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user