changeset 284:96b4ad9b4d30

Start work on sprite editor. Tweak layout issues
author Neil Muller <drnlmuller@gmail.com>
date Thu, 15 Sep 2011 21:45:07 +0200
parents 11cf3a259eaa
children cacc03748580
files mamba/habitats/editor.py
diffstat 1 files changed, 65 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/mamba/habitats/editor.py	Thu Sep 15 21:44:26 2011 +0200
+++ b/mamba/habitats/editor.py	Thu Sep 15 21:45:07 2011 +0200
@@ -17,6 +17,7 @@
         RESERVED_NAMES)
 
 MAX_TOOLS = 6
+MODE_HEIGHT = 500
 
 
 class EditorHabitat(Habitat):
@@ -26,7 +27,8 @@
         self.edit_widget = EditLevelWidget(self.level)
         self.container.add(self.edit_widget)
         self.container.add_callback(KEYDOWN, self.keydown_event)
-        self.mode = 'Tile'
+        self.mode = 'Tiles'
+        self.sprite_mode = 'Add'
 
     def on_enter(self):
         # We need to juggle the display to the correct size
@@ -81,26 +83,31 @@
         self.container.add(tilesetname)
         button_height += tilesetname.surface.get_height() + button_padding
         # TODO: Add Image widget for the current tool
-        self.current_tool = TextWidget((button_left, button_height),
-                'Tool: Floor', color='white')
+        if self.mode != 'Sprites':
+            self.current_tool = TextWidget((button_left, button_height),
+                    'Tool: Floor', color='white')
+        else:
+            self.current_tool = TextWidget((button_left, button_height),
+                    '%s Sprite' % self.sprite_mode, color='white')
         self.container.add(self.current_tool)
         button_height += self.current_tool.surface.get_height()
         button_height += button_padding
-        self.floor_button = ImageButtonWidget(
-                (button_left, button_height), self.level.tileset.floor,
-                'Floor', color='white')
-        self.container.add(self.floor_button)
-        self.floor_button.add_callback('clicked', self.change_tool,
-                '.', 'Floor')
-        self.edit_widget.set_tool('.')
-        button_height += (self.floor_button.surface.get_height()
-                + button_padding)
-        if self.mode == 'Tile':
+        if self.mode != 'Sprites':
+            self.floor_button = ImageButtonWidget(
+                    (button_left, button_height), self.level.tileset.floor,
+                    'Floor', color='white')
+            self.container.add(self.floor_button)
+            self.floor_button.add_callback('clicked', self.change_tool,
+                    '.', 'Floor')
+            self.edit_widget.set_tool('.')
+            button_height += (self.floor_button.surface.get_height()
+                    + button_padding)
+        if self.mode == 'Tiles':
             tile_map = TILE_MAP
-            change_mode_text = 'Switch to Things'
-        elif self.mode == 'Thing':
+        elif self.mode == 'Things':
             tile_map = THING_MAP
-            change_mode_text = 'Switch to Tiles'
+        else:
+            tile_map = []
         tool_list = []
         for tile_char in sorted(tile_map):
             try:
@@ -119,16 +126,43 @@
             tile_button.add_callback('clicked', self.change_tool,
                     tile_char, text)
             tool_list.append(tile_button)
+        if self.mode == "Sprites":
+            for name in ['Add', 'Edit', 'Delete']:
+                tile_button = TextButton((0, 0), '%s Sprite' % name)
+                tile_button.add_callback('clicked', self.sprite_tool,
+                        name)
+                tool_list.append(tile_button)
         self.tool_widget = ToolListWidget((button_left, button_height),
                 tool_list, MAX_TOOLS, start_key=K_2)
         self.container.add(self.tool_widget)
-        button_height += self.tool_widget.rect.height + 2
-
-        mode_button = TextButton((button_left, button_height),
-                change_mode_text)
-        mode_button.add_callback('clicked', self.change_toolbar)
-        self.container.add(mode_button)
-        button_height += mode_button.surface.get_height() + button_padding
+        button_height = self.container.rect.top + MODE_HEIGHT
+        if self.mode == 'Tiles':
+            mode_button1 = TextButton((button_left, button_height),
+                'Things')
+            mode_button1.add_callback('clicked', self.change_toolbar, 'Things')
+            mode_button2 = TextButton((button_left + 100, button_height),
+                'Sprites')
+            mode_button2.add_callback('clicked', self.change_toolbar,
+                    'Sprites')
+        elif self.mode == 'Things':
+            mode_button1 = TextButton((button_left, button_height),
+                'Tiles')
+            mode_button1.add_callback('clicked', self.change_toolbar, 'Tiles')
+            mode_button2 = TextButton((button_left + 100, button_height),
+                'Sprites')
+            mode_button2.add_callback('clicked', self.change_toolbar,
+                    'Sprites')
+        elif self.mode == 'Sprites':
+            mode_button1 = TextButton((button_left, button_height),
+                'Tiles')
+            mode_button1.add_callback('clicked', self.change_toolbar, 'Tiles')
+            mode_button2 = TextButton((button_left + 100, button_height),
+                'Things')
+            mode_button2.add_callback('clicked', self.change_toolbar,
+                    'Things')
+        self.container.add(mode_button1)
+        self.container.add(mode_button2)
+        button_height += mode_button1.rect.height + button_padding
         button_height += 2
 
         new = TextButton((button_left, button_height), "New")
@@ -193,11 +227,8 @@
         self.clear_toolbar()
         self.setup_toolbar()
 
-    def change_toolbar(self, ev, widget):
-        if self.mode == 'Tile':
-            self.mode = 'Thing'
-        elif self.mode == 'Thing':
-            self.mode = 'Tile'
+    def change_toolbar(self, ev, widget, new_mode):
+        self.mode = new_mode
         self.clear_toolbar()
         self.setup_toolbar()
 
@@ -276,3 +307,9 @@
         self.clear_toolbar()
         self.setup_toolbar()
         return True
+
+    def sprite_tool(self, ev, widget, sprite_mode):
+        """Handle sprite stuff"""
+        self.sprite_mode = sprite_mode
+        self.clear_toolbar()
+        self.setup_toolbar()