Fixed indentation error.
This commit is contained in:
parent
e35c826b05
commit
a20da7df8c
134
menu.py
134
menu.py
@ -155,78 +155,78 @@ class Menu:
|
||||
elif selection == "exit":
|
||||
self.game.exit_game()
|
||||
|
||||
def learn_sounds(self):
|
||||
"""Interactive menu for learning game sounds.
|
||||
def learn_sounds(self):
|
||||
"""Interactive menu for learning game sounds.
|
||||
|
||||
Allows users to:
|
||||
- Navigate through available sounds
|
||||
- Play selected sounds
|
||||
- Return to menu with escape key
|
||||
Allows users to:
|
||||
- Navigate through available sounds
|
||||
- Play selected sounds
|
||||
- Return to menu with escape key
|
||||
|
||||
Returns:
|
||||
str: "menu" if user exits with escape
|
||||
"""
|
||||
try:
|
||||
self.game.sound.currentBgm.pause()
|
||||
except:
|
||||
pass
|
||||
Returns:
|
||||
str: "menu" if user exits with escape
|
||||
"""
|
||||
try:
|
||||
self.game.sound.currentBgm.pause()
|
||||
except:
|
||||
pass
|
||||
|
||||
# Get list of available sounds, excluding music and ambiance directories
|
||||
soundList = self.game.sound.get_sound_list()
|
||||
# Get list of available sounds, excluding music and ambiance directories
|
||||
soundList = self.game.sound.get_sound_list()
|
||||
|
||||
if not soundList:
|
||||
self.game.speech.speak("No sounds available to learn.")
|
||||
return "menu"
|
||||
|
||||
# Sort sounds by name
|
||||
soundList.sort()
|
||||
|
||||
self.currentIndex = 0
|
||||
|
||||
validKeys = [
|
||||
pyglet.window.key.ESCAPE,
|
||||
pyglet.window.key.RETURN,
|
||||
pyglet.window.key.UP,
|
||||
pyglet.window.key.DOWN,
|
||||
pyglet.window.key.W,
|
||||
pyglet.window.key.S
|
||||
]
|
||||
|
||||
# Speak initial instructions
|
||||
self.game.speech.speak("Learn game sounds. Use up and down arrow keys or W/S to navigate, Enter to play sound, Escape to exit.")
|
||||
|
||||
# Speak initial sound name
|
||||
soundName = soundList[self.currentIndex]
|
||||
displayName = soundName.replace("/", " in folder ")
|
||||
self.game.speech.speak(f"Sound 1 of {len(soundList)}: {displayName}")
|
||||
|
||||
while True:
|
||||
key, _ = self.game.wait(validKeys)
|
||||
|
||||
if key == pyglet.window.key.ESCAPE:
|
||||
try:
|
||||
self.game.sound.currentBgm.play()
|
||||
except:
|
||||
pass
|
||||
if not soundList:
|
||||
self.game.speech.speak("No sounds available to learn.")
|
||||
return "menu"
|
||||
|
||||
if key in [pyglet.window.key.DOWN, pyglet.window.key.S]:
|
||||
if self.currentIndex < len(soundList) - 1:
|
||||
self.game.sound.stop_all_sounds()
|
||||
self.currentIndex += 1
|
||||
soundName = soundList[self.currentIndex]
|
||||
displayName = soundName.replace("/", " in folder ")
|
||||
self.game.speech.speak(f"Sound {self.currentIndex + 1} of {len(soundList)}: {displayName}")
|
||||
# Sort sounds by name
|
||||
soundList.sort()
|
||||
|
||||
if key in [pyglet.window.key.UP, pyglet.window.key.W]:
|
||||
if self.currentIndex > 0:
|
||||
self.game.sound.stop_all_sounds()
|
||||
self.currentIndex -= 1
|
||||
soundName = soundList[self.currentIndex]
|
||||
displayName = soundName.replace("/", " in folder ")
|
||||
self.game.speech.speak(f"Sound {self.currentIndex + 1} of {len(soundList)}: {displayName}")
|
||||
self.currentIndex = 0
|
||||
|
||||
if key == pyglet.window.key.RETURN:
|
||||
soundName = soundList[self.currentIndex]
|
||||
self.game.sound.stop_all_sounds()
|
||||
self.game.sound.play_sound(soundName)
|
||||
validKeys = [
|
||||
pyglet.window.key.ESCAPE,
|
||||
pyglet.window.key.RETURN,
|
||||
pyglet.window.key.UP,
|
||||
pyglet.window.key.DOWN,
|
||||
pyglet.window.key.W,
|
||||
pyglet.window.key.S
|
||||
]
|
||||
|
||||
# Speak initial instructions
|
||||
self.game.speech.speak("Learn game sounds. Use up and down arrow keys or W/S to navigate, Enter to play sound, Escape to exit.")
|
||||
|
||||
# Speak initial sound name
|
||||
soundName = soundList[self.currentIndex]
|
||||
displayName = soundName.replace("/", " in folder ")
|
||||
self.game.speech.speak(f"Sound 1 of {len(soundList)}: {displayName}")
|
||||
|
||||
while True:
|
||||
key, _ = self.game.wait(validKeys)
|
||||
|
||||
if key == pyglet.window.key.ESCAPE:
|
||||
try:
|
||||
self.game.sound.currentBgm.play()
|
||||
except:
|
||||
pass
|
||||
return "menu"
|
||||
|
||||
if key in [pyglet.window.key.DOWN, pyglet.window.key.S]:
|
||||
if self.currentIndex < len(soundList) - 1:
|
||||
self.game.sound.stop_all_sounds()
|
||||
self.currentIndex += 1
|
||||
soundName = soundList[self.currentIndex]
|
||||
displayName = soundName.replace("/", " in folder ")
|
||||
self.game.speech.speak(f"Sound {self.currentIndex + 1} of {len(soundList)}: {displayName}")
|
||||
|
||||
if key in [pyglet.window.key.UP, pyglet.window.key.W]:
|
||||
if self.currentIndex > 0:
|
||||
self.game.sound.stop_all_sounds()
|
||||
self.currentIndex -= 1
|
||||
soundName = soundList[self.currentIndex]
|
||||
displayName = soundName.replace("/", " in folder ")
|
||||
self.game.speech.speak(f"Sound {self.currentIndex + 1} of {len(soundList)}: {displayName}")
|
||||
|
||||
if key == pyglet.window.key.RETURN:
|
||||
soundName = soundList[self.currentIndex]
|
||||
self.game.sound.stop_all_sounds()
|
||||
self.game.sound.play_sound(soundName)
|
||||
|
Loading…
x
Reference in New Issue
Block a user