changeset 220:06c52529e2ed

Add placeholder object mode menu
author Neil Muller <drnlmuller@gmail.com>
date Wed, 04 Sep 2013 16:37:10 +0200
parents f9e92d540bfa
children 0c0d5919f70a
files tools/area_editor.py
diffstat 1 files changed, 89 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/tools/area_editor.py	Wed Sep 04 16:21:21 2013 +0200
+++ b/tools/area_editor.py	Wed Sep 04 16:37:10 2013 +0200
@@ -39,6 +39,10 @@
 MENU_LEFT = SCREEN[0] + MENU_HALF_PAD
 MENU_WIDTH = 200 - MENU_PAD
 
+BUTTON_RECT = pygame.rect.Rect(0, 0, MENU_WIDTH, MENU_BUTTON_HEIGHT)
+CHECK_RECT = pygame.rect.Rect(0, 0, MENU_BUTTON_HEIGHT // 2,
+                              MENU_BUTTON_HEIGHT // 2)
+
 
 class EditorLevel(Level):
 
@@ -353,6 +357,17 @@
         self.level_widget = LevelWidget(self.level)
         self.add(self.level_widget)
 
+        self._dMenus = {}
+
+        self._make_draw_menu()
+        self._make_objects_menu()
+
+        self._menu_mode = 'drawing'
+        self._populate_menu()
+
+    def _make_draw_menu(self):
+        widgets = []
+
         # Add poly buttons
         y = 15
         for poly in range(1, 7):
@@ -365,67 +380,95 @@
                 but.rect.move_ip(MENU_LEFT + MENU_WIDTH // 2 - MENU_HALF_PAD,
                                  y)
                 y += MENU_BUTTON_HEIGHT + MENU_PAD
-            self.add(but)
-
-        button_rect = pygame.rect.Rect(0, 0, MENU_WIDTH, MENU_BUTTON_HEIGHT)
-
-        check_rect = pygame.rect.Rect(0, 0, MENU_BUTTON_HEIGHT // 2,
-                                      MENU_BUTTON_HEIGHT // 2)
+            widgets.append(but)
 
         end_poly_but = PolyButton(None, self.level_widget)
-        end_poly_but.rect = button_rect.copy()
+        end_poly_but.rect = BUTTON_RECT.copy()
         end_poly_but.rect.move_ip(MENU_LEFT, y)
-        self.add(end_poly_but)
+        widgets.append(end_poly_but)
         y += MENU_BUTTON_HEIGHT + MENU_PAD
 
         draw_line = Button("Draw interior wall", self.level_widget.line_mode)
-        draw_line.rect = button_rect.copy()
+        draw_line.rect = BUTTON_RECT.copy()
         draw_line.rect.move_ip(MENU_LEFT, y)
-        self.add(draw_line)
+        widgets.append(draw_line)
         y += MENU_BUTTON_HEIGHT + MENU_PAD
 
         fill_but = Button('Fill exterior', action=self.level_widget.set_filled)
-        fill_but.rect = button_rect.copy()
+        fill_but.rect = BUTTON_RECT.copy()
         fill_but.rect.move_ip(MENU_LEFT, y)
-        self.add(fill_but)
+        widgets.append(fill_but)
         y += MENU_BUTTON_HEIGHT + MENU_PAD
 
         save_but = Button('Save Level', action=self.save)
-        save_but.rect = button_rect.copy()
+        save_but.rect = BUTTON_RECT.copy()
         save_but.rect.move_ip(MENU_LEFT, y)
-        self.add(save_but)
+        widgets.append(save_but)
         y += MENU_BUTTON_HEIGHT + MENU_PAD
 
         close_poly_but = Button('Close Polygon',
                                 action=self.level_widget.close_poly)
-        close_poly_but.rect = button_rect.copy()
+        close_poly_but.rect = BUTTON_RECT.copy()
         close_poly_but.rect.move_ip(MENU_LEFT, y)
-        self.add(close_poly_but)
+        widgets.append(close_poly_but)
         y += MENU_BUTTON_HEIGHT + MENU_PAD
 
         white = pygame.color.Color("white")
         self.show_objs = CheckBox(fg_color=white)
-        self.show_objs.rect = check_rect.copy()
+        self.show_objs.rect = CHECK_RECT.copy()
         self.show_objs.rect.move_ip(MENU_LEFT, y)
         label = Label("Show Objects", fg_color=white)
         label.rect.move_ip(MENU_LEFT + MENU_BUTTON_HEIGHT // 2 + MENU_PAD, y)
-        self.add(self.show_objs)
-        self.add(label)
+        widgets.append(self.show_objs)
+        widgets.append(label)
         y += label.rect.height + MENU_PAD
 
         self.show_enemies = CheckBox(fg_color=white)
-        self.show_enemies.rect = check_rect.copy()
+        self.show_enemies.rect = CHECK_RECT.copy()
         self.show_enemies.rect.move_ip(MENU_LEFT, y)
         label = Label("Show enemy start pos", fg_color=white)
         label.rect.move_ip(MENU_LEFT + MENU_BUTTON_HEIGHT // 2 + MENU_PAD, y)
-        self.add(self.show_enemies)
-        self.add(label)
+        widgets.append(self.show_enemies)
+        widgets.append(label)
         y += label.rect.height + MENU_PAD
 
+        switch_but = Button('Switch to Objects', action=self.switch_to_objects)
+        switch_but.rect = BUTTON_RECT.copy()
+        switch_but.rect.move_ip(MENU_LEFT, y)
+        widgets.append(switch_but)
+        y += switch_but.rect.height + MENU_PAD
+
         quit_but = Button('Quit', action=self.quit)
-        quit_but.rect = button_rect.copy()
+        quit_but.rect = BUTTON_RECT.copy()
         quit_but.rect.move_ip(MENU_LEFT, y)
-        self.add(quit_but)
+        widgets.append(quit_but)
+
+        self._dMenus['drawing'] = widgets
+
+    def _make_objects_menu(self):
+        widgets = []
+
+        # Add poly buttons
+        y = 15
+
+        save_but = Button('Save Level', action=self.save)
+        save_but.rect = BUTTON_RECT.copy()
+        save_but.rect.move_ip(MENU_LEFT, y)
+        widgets.append(save_but)
+        y += MENU_BUTTON_HEIGHT + MENU_PAD
+
+        switch_but = Button('Switch to Drawing', action=self.switch_to_draw)
+        switch_but.rect = BUTTON_RECT.copy()
+        switch_but.rect.move_ip(MENU_LEFT, y)
+        widgets.append(switch_but)
+        y += switch_but.rect.height + MENU_PAD
+
+        quit_but = Button('Quit', action=self.quit)
+        quit_but.rect = BUTTON_RECT.copy()
+        quit_but.rect.move_ip(MENU_LEFT, y)
+        widgets.append(quit_but)
+
+        self._dMenus['objects'] = widgets
 
     def key_down(self, ev):
         if ev.key == pgl.K_ESCAPE:
@@ -445,6 +488,28 @@
             # display errors
             alert("Failed to save level.\n\n%s" % '\n'.join(messages))
 
+    def switch_to_draw(self):
+        if self._menu_mode != 'drawing':
+            self._clear_menu()
+            self._menu_mode = 'drawing'
+            self._populate_menu()
+
+    def switch_to_objects(self):
+        if self._menu_mode != 'objects':
+            self._clear_menu()
+            self._menu_mode = 'objects'
+            self._populate_menu()
+
+    def _clear_menu(self):
+        for widget in self._dMenus[self._menu_mode]:
+            self.remove(widget)
+
+    def _populate_menu(self):
+        self.level_widget.change_poly(None)
+        for widget in self._dMenus[self._menu_mode]:
+            self.add(widget)
+        self.invalidate()
+
     def mouse_move(self, ev):
         self.level_widget.mouse_move(ev)