Instructions and credits menu options now working.
This commit is contained in:
parent
fd93c993c1
commit
99d26b7951
@ -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)
|
||||
|
68
display.py
68
display.py
@ -17,67 +17,81 @@ 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.
|
||||
|
||||
|
||||
Args:
|
||||
text (list): List of text lines to display
|
||||
speech (Speech): Speech system for audio output
|
||||
"""
|
||||
# Store original text with blank lines for copying
|
||||
self.originalText = text.copy()
|
||||
|
||||
|
||||
# Create navigation text by filtering out blank lines
|
||||
self.navText = [line for line in text if line.strip()]
|
||||
|
||||
|
||||
# Add instructions at start
|
||||
instructions = ("Press space to read the whole text. Use up and down arrows to navigate "
|
||||
"the text line by line. Press c to copy the current line to the clipboard "
|
||||
"or t to copy the entire text. Press enter or escape when you are done reading.")
|
||||
"the text line by line. Press c to copy the current line to the clipboard "
|
||||
"or t to copy the entire text. Press enter or escape when you are done reading.")
|
||||
self.navText.insert(0, instructions)
|
||||
|
||||
|
||||
# Add end marker
|
||||
self.navText.append("End of text.")
|
||||
|
||||
|
||||
self.currentIndex = 0
|
||||
speech.speak(self.navText[self.currentIndex])
|
||||
|
||||
# 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
|
||||
]
|
||||
|
||||
while True:
|
||||
key = self.game.wait(validKeys)
|
||||
|
||||
@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
|
||||
|
||||
if symbol in (key.DOWN, key.S) and self.currentIndex < len(self.navText) - 1:
|
||||
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.")
|
||||
|
44
menu.py
44
menu.py
@ -110,8 +110,48 @@ class Menu:
|
||||
"donate",
|
||||
"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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user