Instructions and credits menu options now working.

This commit is contained in:
Storm Dragon 2025-02-23 14:00:55 -05:00
parent fd93c993c1
commit 99d26b7951
3 changed files with 84 additions and 30 deletions

View File

@ -27,7 +27,7 @@ class pygstormgames:
# Initialize core systems
self.config = Config(gameTitle)
self.display = Display(gameTitle)
self.display = Display(self)
self.speech = Speech()
self.sound = Sound(self)
self.scoreboard = Scoreboard(self)

View File

@ -17,16 +17,17 @@ import wx
class Display:
"""Handles display and text navigation systems."""
def __init__(self, gameTitle):
def __init__(self, game):
"""Initialize display system.
Args:
gameTitle (str): Title of the game
game (PygStormGames): Reference to main game object
"""
self.window = pyglet.window.Window(800, 600, caption=gameTitle)
self.game = game
self.window = pyglet.window.Window(800, 600, caption=game.gameTitle)
self.currentText = []
self.currentIndex = 0
self.gameTitle = gameTitle
self.gameTitle = game.gameTitle
def display_text(self, text, speech):
"""Display and navigate text with speech output.
@ -53,31 +54,44 @@ class Display:
self.currentIndex = 0
speech.speak(self.navText[self.currentIndex])
@self.window.event
def on_key_press(symbol, modifiers):
if symbol in (key.ESCAPE, key.RETURN):
self.window.remove_handler('on_key_press', on_key_press)
return
# Use the game's existing input handlers
validKeys = [
pyglet.window.key.ESCAPE,
pyglet.window.key.RETURN,
pyglet.window.key.SPACE,
pyglet.window.key.UP,
pyglet.window.key.DOWN,
pyglet.window.key.W,
pyglet.window.key.S,
pyglet.window.key.C,
pyglet.window.key.T
]
if symbol in (key.DOWN, key.S) and self.currentIndex < len(self.navText) - 1:
while True:
key = self.game.wait(validKeys)
if key in (pyglet.window.key.ESCAPE, pyglet.window.key.RETURN):
break
if key in (pyglet.window.key.DOWN, pyglet.window.key.S) and self.currentIndex < len(self.navText) - 1:
self.currentIndex += 1
speech.speak(self.navText[self.currentIndex])
if symbol in (key.UP, key.W) and self.currentIndex > 0:
if key in (pyglet.window.key.UP, pyglet.window.key.W) and self.currentIndex > 0:
self.currentIndex -= 1
speech.speak(self.navText[self.currentIndex])
if symbol == key.SPACE:
if key == pyglet.window.key.SPACE:
speech.speak('\n'.join(self.originalText[1:-1]))
if symbol == key.C:
if key == pyglet.window.key.C:
try:
pyperclip.copy(self.navText[self.currentIndex])
speech.speak("Copied " + self.navText[self.currentIndex] + " to the clipboard.")
except:
speech.speak("Failed to copy the text to the clipboard.")
if symbol == key.T:
if key == pyglet.window.key.T:
try:
pyperclip.copy(''.join(self.originalText[2:-1]))
speech.speak("Copied entire message to the clipboard.")

42
menu.py
View File

@ -111,7 +111,47 @@ class Menu:
"exit"
]
return self.show_menu(options, with_music=True)
while True:
selection = self.show_menu(options, with_music=True)
if selection == "play":
return selection
elif selection == "instructions":
# Pause menu music
if self.game.sound.currentBgm:
self.game.sound.currentBgm.pause()
self.game.display.instructions(self.game.speech)
# Resume menu music
if self.game.sound.currentBgm:
self.game.sound.currentBgm.play()
elif selection == "learn_sounds":
if self.learn_sounds() == "menu":
continue
elif selection == "credits":
# Pause menu music
if self.game.sound.currentBgm:
self.game.sound.currentBgm.pause()
self.game.display.credits(self.game.speech)
# Resume menu music
if self.game.sound.currentBgm:
self.game.sound.currentBgm.play()
elif selection == "donate":
# Pause menu music
if self.game.sound.currentBgm:
self.game.sound.currentBgm.pause()
self.game.display.donate(self.game.speech)
# Resume menu music
if self.game.sound.currentBgm:
self.game.sound.currentBgm.play()
def learn_sounds(self):
"""Interactive menu for learning game sounds.