def __init__(self, text, height=400, line_width=50):
     self.text_list = []
     if type(text) == type("bla"):
         self.text_list = utils.separate_text_into_lines(text, line_width)
     elif type(text) == type([]):
         self.text_list.append(text)
     else:
         s = "Doh! That type of data shouldn't be here!"
         raise ValueError(s)
     # -------------------------
     pygame.init()
     self.font = pygame.font.Font(None, 35)
     # -------------------------
     # Calculate the width and hight of the window we're using
     # for the back of the dialog box.
     text_width, text_height = self.font.size("a")
     self.width = 50 * text_width
     if len(self.text_list) > 12:
         self.height = 600
     else:
         self.height = height
     self.screen = pygame.display.set_mode((self.width, self.height))
     # ----
     # Calulate the desired height of each line, given the
     # text we want to display.
     self.line_height = -1
     for elem in self.text_list:
         text_width, text_height = self.font.size(elem)
         if text_height > self.line_height:
             self.line_height = text_height
     # -------------------------
     self.button_color = con.BLACK
     self.BG_COLOR = con.LIGHTGREY
     self.window_background_color = con.WHITE
     # -------------------------
     self.mouse_pos = None
     self.okay_rect = None
     self.keep_looping = True
Exemplo n.º 2
0
 def __init__(self, text, line_width=40):
     self.window_width = 600
     self.window_height = 300
     # -------------------------
     pygame.init()
     self.screen = pygame.display.set_mode(
         (self.window_width, self.window_height))
     self.BG_COLOR = con.LIGHTGREY
     self.text_list = []
     # -------------------------
     if type(text) == type("bla"):
         self.text_list = utils.separate_text_into_lines(text, line_width)
     elif type(text) == type([]):
         self.text_list.append(text)
     else:
         s = "Doh! That type of data shouldn't be here!"
         raise ValueError(s)
     # -------------------------
     self.font = pygame.font.Font(None, 35)
     # -------------------------
     self.yes_rect = pygame.Rect(300, 300, 100, 75)
     self.yes_image = pygame.image.load(
         os.path.join("data", "images", "buttons",
                      "yes_grey.png")).convert_alpha()
     self.yes_image = pygame.transform.scale(self.yes_image, (100, 50))
     # -------------------------
     self.no_rect = pygame.Rect(10, 230, 250, 75)
     self.no_image = pygame.image.load(
         os.path.join("data", "images", "buttons",
                      "no_grey.png")).convert_alpha()
     self.no_image = pygame.transform.scale(self.no_image, (100, 50))
     # -------------------------
     self.text_window_rect = pygame.Rect(10, 10, 580, 220)
     # -------------------------
     self.message = ""
     self.mouse_pos = None
     self.keep_looping = True
Exemplo n.º 3
0
 def play_script(self):
     line_length = 60
     indy = "com.apple.speech.synthesis.voice.daniel.premium"
     satipo = "com.apple.speech.synthesis.voice.Alex"
     serena = "com.apple.speech.synthesis.voice.moira.premium"
     # ------------------------------------------
     text = "Indy and Satipo fan out to fight their way through the entwined "
     text += "trees that guard the temple. Visibility is cut to five feet "
     text += "in the heavy mist. Satipo extracts a short, native dart from "
     text += "a tree and examines the point gingerly. ... As Satipo shows Indy the dart, he says,"
     text_list = utils.separate_text_into_lines(text, line_length)
     [print(i) for i in text_list]
     print("")
     self.engine.setProperty("voice", serena)
     self.engine.setProperty("volume", 1)
     self.engine.setProperty("rate", 200)
     self.speak(text)
     # -----
     text = "The Hovitos are near. The poison is still fresh...three days. "
     text += "I tell you, they’re following us."
     text_list = utils.separate_text_into_lines(text, line_length)
     [print(i) for i in text_list]
     print("")
     self.engine.setProperty("voice", satipo)
     self.engine.setProperty("volume", 1)
     self.engine.setProperty("rate", 400)
     self.speak(text)
     # -----
     text = "If they knew we were here, they would have killed us already."
     text_list = utils.separate_text_into_lines(text, line_length)
     [print(i) for i in text_list]
     print("")
     self.engine.setProperty("voice", indy)
     self.engine.setProperty("volume", 1)
     self.engine.setProperty("rate", 200)
     self.speak(text)
     # -----
     text = "In the undergrowth, there is a slithering movement. Their eyes "
     text += "are drawn to one of the trees that surround them. There is something ..."
     text += "A dessicated corpse is attached to the trunk of the tree with arrows. Sapito screams."
     text += "Indy examins the corpse."
     text_list = utils.separate_text_into_lines(text, line_length)
     [print(i) for i in text_list]
     print("")
     self.engine.setProperty("voice", serena)
     self.engine.setProperty("volume", 1)
     self.engine.setProperty("rate", 200)
     self.speak(text)
     # -----
     text = "So this is where Forestal cashed in."
     text_list = utils.separate_text_into_lines(text, line_length)
     [print(i) for i in text_list]
     self.engine.setProperty("voice", indy)
     self.engine.setProperty("volume", 1)
     self.engine.setProperty("rate", 200)
     self.speak(text)
     # -----
     text = "A friend of yours?"
     print(text)
     print("")
     self.engine.setProperty("voice", satipo)
     self.engine.setProperty("volume", 1)
     self.engine.setProperty("rate", 400)
     self.speak(text)
     # -----
     text = "Competitor. He was good, very good."
     print(text)
     print("")
     self.engine.setProperty("voice", indy)
     self.engine.setProperty("volume", 1)
     self.engine.setProperty("rate", 200)
     self.speak(text)
     # -----
     text = "No one has ever come out of there alive. Why should we put our faith in you?"
     text_list = utils.separate_text_into_lines(text, line_length)
     [print(i) for i in text_list]
     print("")
     self.engine.setProperty("voice", satipo)
     self.engine.setProperty("volume", 1)
     self.engine.setProperty("rate", 400)
     self.speak(text)
     # -----
     text = "Indy shows Satipo his map. Satipo looks at it with naked greed. "
     text += "Indy spreads out the map on the grass. Minutes go by as the men study it. "
     text += "Satipo leans closer. He says,"
     text_list = utils.separate_text_into_lines(text, line_length)
     [print(i) for i in text_list]
     print("")
     self.engine.setProperty("voice", serena)
     self.engine.setProperty("volume", 1)
     self.engine.setProperty("rate", 200)
     self.speak(text)
     # -----
     text = "It's the floor plan of the temple! It has to be!"
     text_list = utils.separate_text_into_lines(text, line_length)
     [print(i) for i in text_list]
     print("")
     self.engine.setProperty("voice", satipo)
     self.engine.setProperty("volume", 1)
     self.engine.setProperty("rate", 400)
     self.speak(text)
     # -----
     text = "Indy nodded."
     text_list = utils.separate_text_into_lines(text, line_length)
     [print(i) for i in text_list]
     print("")
     self.engine.setProperty("voice", serena)
     self.engine.setProperty("volume", 1)
     self.engine.setProperty("rate", 200)
     self.speak(text)
     # -----
     text = "That's how I figure it."
     text_list = utils.separate_text_into_lines(text, line_length)
     [print(i) for i in text_list]
     self.engine.setProperty("voice", indy)
     self.engine.setProperty("volume", 1)
     self.engine.setProperty("rate", 200)
     self.speak(text)
     # -----
     text = "No one else had this ... Only us."
     print(text)
     self.engine.setProperty("voice", satipo)
     self.engine.setProperty("volume", 1)
     self.engine.setProperty("rate", 400)
     self.speak(text)
     # -----
     text = "Will Indy survive the dangers that await him in the tunnel, "
     text += "or will he die an agonizing death like all those before him?"
     print(text)
     self.engine.setProperty("voice", serena)
     self.engine.setProperty("volume", 1)
     self.engine.setProperty("rate", 200)
     self.speak(text)
     # -----
     text = "The end."
     print(text)
     self.engine.setProperty("voice", serena)
     self.engine.setProperty("volume", 1)
     self.engine.setProperty("rate", 200)
     self.speak(text)
Exemplo n.º 4
0
 def __init__(self, text, line_width=40):
     self.window_width = 600
     self.window_height = 500
     # -------------------------
     pygame.init()
     self.screen = pygame.display.set_mode(
         (self.window_width, self.window_height))
     # -------------------------
     if len(text) > 910:
         s = "That text is too long! "
         s += "It must be equal to or less than 910 characters."
         raise ValueError(s)
     # -------------------------
     large_height = 600
     # -------------------------
     self.BG_COLOR = con.LIGHTGREY
     self.text_list = []
     if type(text) == type("bla"):
         self.text_list = utils.separate_text_into_lines(text, line_width)
     elif type(text) == type([]):
         self.text_list = text
     else:
         s = "Doh! That type of data shouldn't be here!"
         raise ValueError(s)
     # -------------------------
     self.font = pygame.font.Font(None, 35)
     # -------------------------
     self.okay_rect = pygame.Rect(300, 300, 100, 75)
     self.ok_image = pygame.image.load(
         os.path.join("data", "images", "buttons",
                      "ok02.png")).convert_alpha()
     self.ok_image = pygame.transform.scale(
         self.ok_image, (self.okay_rect[0], self.okay_rect[1]))
     # -------------------------
     text_width, text_height = self.font.size("a")
     self.width = 50 * text_width
     kind = ""
     self.height = large_height
     kind = "large dialog"
     self.line_height = -1
     for elem in self.text_list:
         text_width, text_height = self.font.size(elem)
         if text_height > self.line_height:
             self.line_height = text_height
     window_left = 10
     window_top = 10
     window_width = self.width - 20
     window_height = self.height - (20 * 3)
     self.window_rect = pygame.Rect(window_left, window_top,
                                    window_width - 50, window_height - 100)
     # --------------------------
     # -------- OK Button -------
     button_width = 60
     button_height = 35
     button_left = int(self.height / 2)
     top = 600 - button_height
     print("width: ", button_width)
     self.okay_rect = pygame.Rect(button_left, top, button_width,
                                  button_height)
     self.ok_image = pygame.image.load(
         os.path.join("data", "images", "buttons",
                      "ok02.png")).convert_alpha()
     self.ok_image = pygame.transform.scale(self.ok_image, (0, 0))
     # -------------------------
     self.mouse_pos = None
     self.keep_looping = True