changeset 236:261fd65a8816

More work towards object editing
author Neil Muller <drnlmuller@gmail.com>
date Wed, 04 Sep 2013 21:32:55 +0200
parents 831e4f6b3d18
children 6995dbefdbfb
files tools/area_editor.py
diffstat 1 files changed, 90 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/tools/area_editor.py	Wed Sep 04 21:16:09 2013 +0200
+++ b/tools/area_editor.py	Wed Sep 04 21:32:55 2013 +0200
@@ -31,8 +31,9 @@
 from nagslang.options import parse_args
 from nagslang.constants import SCREEN
 from nagslang.level import Level, POLY_COLORS, LINE_COLOR
-from nagslang.enemies import Enemy
-
+from nagslang.enemies import Enemy, get_editable_enemies
+from nagslang.game_object import get_editable_game_objects
+from nagslang.puzzle import get_editable_puzzlers
 
 # layout constants
 MENU_BUTTON_HEIGHT = 35
@@ -377,11 +378,15 @@
         row = Row(buttons)
         row.rect = pygame.rect.Rect(0, 450, 700, 50)
         edit_box.add(row)
+        edit_box.get_selection = lambda: table.get_selection()
         return edit_box
 
     def edit_objects(self):
         edit_box = self._make_edit_dialog(self.level._game_objects)
         res = edit_box.present()
+        choice = edit_box.get_selection()
+        if choice is None:
+            return
         if res == 'OK':
             # Edit object stuff goes here
             pass
@@ -391,12 +396,58 @@
     def edit_enemies(self):
         edit_box = self._make_edit_dialog(self.level._enemies)
         res = edit_box.present()
+        choice = edit_box.get_selection()
+        if choice is None:
+            return
         if res == 'OK':
             # Edit object stuff goes here
             pass
         elif res == 'Delete':
             pass
 
+    def _make_choice_dialog(self, classes):
+        # Dialog to hold the editor
+        data = []
+        for cls_name, cls in classes:
+            data.append({"classname": cls_name, "class": cls})
+        edit_box = Dialog()
+        edit_box.rect = pygame.rect.Rect(0, 0, 700, 500)
+        table = ObjectTable(data)
+        edit_box.add(table)
+        buttons = []
+        for text in ['OK', 'Cancel']:
+            but = Button(text, action=lambda x=text: edit_box.dismiss(x))
+            buttons.append(but)
+        row = Row(buttons)
+        row.rect = pygame.rect.Rect(0, 450, 700, 50)
+        edit_box.add(row)
+        edit_box.get_selection = lambda: table.get_selection()
+        return edit_box
+
+    def add_game_object(self):
+        classes = get_editable_game_objects()
+        choose = self._make_choice_dialog(classes)
+        res = choose.present()
+        choice = choose.get_selection()
+        if res == 'OK' and choice is not None:
+            pass
+
+    def add_enemy(self):
+        classes = get_editable_enemies()
+        choose = self._make_choice_dialog(classes)
+        res = choose.present()
+        choice = choose.get_selection()
+        if res == 'OK' and choice is not None:
+            pass
+
+    def add_puzzler(self):
+        classes = get_editable_puzzlers()
+        choose = self._make_choice_dialog(classes)
+        res = choose.present()
+        choice = choose.get_selection()
+        if res == 'OK' and choice is not None:
+            pass
+
 
 class PolyButton(Button):
     """Button for coosing the correct polygon"""
@@ -465,12 +516,6 @@
         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.move_ip(MENU_LEFT, y)
-        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()
@@ -497,12 +542,20 @@
         widgets.append(label)
         y += label.rect.height + MENU_PAD
 
+        y += 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
 
+        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
+
+        y += MENU_PAD
         quit_but = Button('Quit', action=self.quit)
         quit_but.rect = BUTTON_RECT.copy()
         quit_but.rect.move_ip(MENU_LEFT, y)
@@ -530,18 +583,41 @@
         widgets.append(edir_enemies_but)
         y += MENU_BUTTON_HEIGHT + MENU_PAD
 
+        add_obj_but = Button('Add Game Object',
+                             action=self.level_widget.add_game_object)
+        add_obj_but.rect = BUTTON_RECT.copy()
+        add_obj_but.rect.move_ip(MENU_LEFT, y)
+        widgets.append(add_obj_but)
+        y += MENU_BUTTON_HEIGHT + MENU_PAD
+
+        add_puzzle_but = Button('Add Puzzler',
+                                action=self.level_widget.add_puzzler)
+        add_puzzle_but.rect = BUTTON_RECT.copy()
+        add_puzzle_but.rect.move_ip(MENU_LEFT, y)
+        widgets.append(add_puzzle_but)
+        y += MENU_BUTTON_HEIGHT + MENU_PAD
+
+        add_enemy_but = Button('Add Enemy',
+                               action=self.level_widget.add_enemy)
+        add_enemy_but.rect = BUTTON_RECT.copy()
+        add_enemy_but.rect.move_ip(MENU_LEFT, y)
+        widgets.append(add_enemy_but)
+        y += MENU_BUTTON_HEIGHT + MENU_PAD
+
+        y += 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
+
         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
-
+        y += MENU_PAD
         quit_but = Button('Quit', action=self.quit)
         quit_but.rect = BUTTON_RECT.copy()
         quit_but.rect.move_ip(MENU_LEFT, y)