Commits

schlangen committed 146ec09

- added proper handling of escape key

Comments (0)

Files changed (2)

                     return
                 elif event.type == pygame.KEYDOWN:
                     if event.key == pygame.K_ESCAPE:
-                        return
+                        if self.state != "menu":
+                            self.start_main_menu()
+                        else:
+                            self.quit()
                     elif event.key == pygame.K_F11:
                         pygame.image.save(self.screen, os.path.join(PROJECT_DIR, "screeny.png"))
                         self.photo_sound.play()

gallox/ui/menu.py

                 elif event.key == pygame.K_DOWN:
                     self.roll_focus(1)
                     continue
+                elif event.key == pygame.K_ESCAPE:
+                    if self.main_menu.visible:
+                        self.quit()
+                    else:
+                        self.set_layer(self.main_menu)
+                    continue
                 elif event.key in [pygame.K_RETURN, pygame.K_KP_ENTER]:
                     self.focused_widget._send_event("mouse_down")
             not_used.append(event)
         elif item == "about":
             self.set_layer(self.about)
         elif item == "exit":
-            self._send_event("exit")
+            self.quit()
             
     # new game
     
         """
         self.set_layer(self.main_menu)
 
-    
+    def quit(self):
+        self._send_event("exit")
         
     def roll_focus(self, direction):
         if not direction: