editor option
[pp] / PictureProcessing.py
index 21639cb..68f07dc 100644 (file)
@@ -66,11 +66,6 @@ class PictureProcessing(Game):
            (self.get_configuration("mouse", "resets") and event.type == MOUSEBUTTONDOWN and
             (1 <= event.button <= 3)):
             self.reset()
-        elif self.delegate.compare(event, "context"):
-            if not self.editor.active:
-                self.editor.activate()
-            else:
-                self.editor.deactivate()
 
     def reset(self):
         self.title.reset()
@@ -298,6 +293,10 @@ class Editor(GameChild):
         # self.tile_load_preview_background.location.topright = self.tile_load_background.location.topright
         self.loaded = True
         self.current_level_is_default = False
+        self.level_index = len(self.levels) - 1
+        self.set_level_title()
+        for level in self.levels:
+            print "path:", level.path
 
     def draw_tile_database(self):
         padding = self.TILE_LOAD_MENU_PADDING
@@ -412,6 +411,7 @@ class Editor(GameChild):
 
     def deactivate(self):
         self.active = False
+        self.get_game().interface.reset()
 
     def respond(self, event):
         if self.active:
@@ -472,9 +472,11 @@ class Editor(GameChild):
             if compare(event, "cancel"):
                 if self.at_level_select:
                     self.deactivate()
+                    self.get_game().title.activate()
                 elif self.at_view:
                     self.at_view = False
                     self.at_level_select = True
+                    self.set_level_title()
                     self.tile_index = 0
                     self.palette_index = 0
                 elif self.at_tile_bar:
@@ -504,6 +506,7 @@ class Editor(GameChild):
                     self.level_index += 1
                     if self.level_index >= len(self.levels):
                         self.level_index = 0
+                    self.set_level_title()
                 if self.at_tile_bar:
                     self.tile_index += 1
                     if self.tile_index == Interface.MAX_TILE_COUNT or \
@@ -511,7 +514,7 @@ class Editor(GameChild):
                         self.tile_index = 0
                 if self.at_tile_menu:
                     self.tile_menu_index += 1
-                    if self.tile_menu_index > 2:
+                    if self.tile_menu_index > 2 or (self.add_tile_selected() and self.tile_menu_index > 1):
                         self.tile_menu_index = 0
                 if self.at_tile_edit or self.at_box:
                     dx = 1
@@ -566,6 +569,7 @@ class Editor(GameChild):
                     self.level_index -= 1
                     if self.level_index < 0:
                         self.level_index = len(self.levels) - 1
+                    self.set_level_title()
                 if self.at_tile_bar:
                     self.tile_index -= 1
                     if self.tile_index < 0:
@@ -575,7 +579,10 @@ class Editor(GameChild):
                 if self.at_tile_menu:
                     self.tile_menu_index -= 1
                     if self.tile_menu_index < 0:
-                        self.tile_menu_index = 2
+                        if self.add_tile_selected():
+                            self.tile_menu_index = 1
+                        else:
+                            self.tile_menu_index = 2
                 if self.at_tile_edit or self.at_box:
                     dx = -1
                 if self.at_tile_edit:
@@ -640,6 +647,17 @@ class Editor(GameChild):
             elif self.palette_index < 0:
                 self.palette_index = self.get_palette_cell_count() - 1
 
+    def set_level_title(self):
+        level = self.get_current_level()
+        if level.path is None:
+            text = "DEFAULT"
+        else:
+            text = basename(self.get_current_level().path)
+        rect = self.get_current_level().preview.get_rect()
+        rect.center = self.get_display_surface().get_rect().center
+        self.label_title = self.get_label("ID: %s" % text)
+        self.label_title.location.bottomright = rect.right, rect.bottom - 3
+
     def delete_tile(self, index):
         level = self.get_current_level()
         level.tiles.pop(index)
@@ -801,6 +819,7 @@ class Editor(GameChild):
                 rect = preview.get_rect()
                 rect.center = ds.get_rect().center
                 ds.blit(preview, rect)
+                self.label_title.update()
                 self.level_select_cursor.update()
                 if len(self.levels) > 1:
                     self.label_left.update()
@@ -1587,9 +1606,9 @@ class Interface(Animation):
         if self.is_countdown_active():
             self.countdown_plate.toggle_hidden()
             if self.countdown_plate.is_hidden():
-                self.set_title_plate_visibility(False)
-            else:
                 self.set_title_plate_visibility(True)
+            else:
+                self.set_title_plate_visibility(False)
 
     def set_title_plate_visibility(self, visible=True):
         title_plate = self.get_title_plate()
@@ -1651,10 +1670,10 @@ class Interface(Animation):
                                 self.set_countdown_plate()
                                 if self.is_countdown_active():
                                     self.countdown_plate.unhide()
-                                    self.set_title_plate_visibility(True)
+                                    self.set_title_plate_visibility(False)
                                     self.reset_timer(self.blink_countdown)
                                 else:
-                                    self.set_title_plate_visibility(False)
+                                    self.set_title_plate_visibility(True)
                                     self.countdown_plate.hide()
                             elif not self.get_game().editor.active:
                                 effects.play("clear")
@@ -1846,7 +1865,7 @@ class Title(Animation):
     MENU_OFFSET = 100
     MENU_WIDTH = 440
     ADVANCE_TEXT = "PRESS ENTER", "PRESS START"
-    MENU_OPTIONS = "NEW GAME", "CONTINUE"
+    MENU_OPTIONS = "NEW GAME", "CONTINUE", "EDITOR"
     MENU_MARGIN = 12
     MENU_PADDING = 16
     TRANSPARENT_COLOR = (128, 128, 128)
@@ -1915,7 +1934,7 @@ class Title(Animation):
         if self.get_game().get_progress()[0] > 0:
             option_texts = self.MENU_OPTIONS
         else:
-            option_texts = self.MENU_OPTIONS[:1]
+            option_texts = [self.MENU_OPTIONS[0], self.MENU_OPTIONS[2]]
         height = glyphs.get_tile(0).get_height() * len(option_texts) + \
                  self.MENU_MARGIN * (len(option_texts) - 1) + \
                  self.MENU_PADDING * 2 + 3
@@ -1934,6 +1953,7 @@ class Title(Animation):
                                        (len(options) - 1) * self.MENU_MARGIN
         indicator = self.indicator = Sprite(self)
         indicator.add_frame(self.get_game().glyphs.get_tile(16))
+        self.option_texts = option_texts
 
     def respond(self, event):
         if self.active and not self.get_game().editor.active:
@@ -1957,14 +1977,17 @@ class Title(Animation):
                     self.menu_index += 1
                 elif delegate.compare(event, "advance") or delegate.compare(event, "action"):
                     self.get_game().sound_effects.play("start")
-                    if self.menu_index == 0:
+                    if self.get_selected_option() == "NEW GAME":
                         self.deactivate()
                         self.get_game().introduction.load()
                         self.get_game().write_progress(0, 0)
-                    elif self.menu_index == 1:
+                    elif self.get_selected_option() == "CONTINUE":
                         self.deactivate()
                         self.get_game().levels.\
                             levels[self.get_game().get_progress()[0]].begin()
+                    elif self.get_selected_option() == "EDITOR":
+                        self.deactivate()
+                        self.get_game().editor.activate()
                     else:
                         pass
                     event.dict["command"] = ""
@@ -1973,6 +1996,9 @@ class Title(Animation):
                 elif self.menu_index >= len(self.options):
                     self.menu_index = 0
 
+    def get_selected_option(self):
+        return self.option_texts[self.menu_index]
+
     def deactivate(self):
         self.active = False
         self.audio_loop.stop()
@@ -2187,7 +2213,7 @@ class Ending(Animation):
         self.register(self.unsuppress_advance)
 
     def respond(self, event):
-        if self.active and not self.suppress_commands and not self.get_game().editor.active \
+        if self.active and not self.suppress_commands and not self.get_game().editor.active and \
            ((self.get_game().is_gamepad_mode() and self.get_game().delegate.compare(event, "advance")) or \
             (not self.get_game().is_gamepad_mode() and self.get_game().delegate.compare(event, "action"))):
             self.deactivate()