diff mamba/habitats/editor.py @ 267:1e8dca95c48a

Hook up hot-keys in editor for jerith
author Neil Muller <drnlmuller@gmail.com>
date Thu, 15 Sep 2011 12:54:16 +0200
parents 74ae1645df6e
children 3c95ba7408f1
line wrap: on
line diff
--- a/mamba/habitats/editor.py	Thu Sep 15 12:53:52 2011 +0200
+++ b/mamba/habitats/editor.py	Thu Sep 15 12:54:16 2011 +0200
@@ -1,7 +1,7 @@
 """Habitat for editing levels."""
 
 import pygame.display
-from pygame.locals import SWSURFACE, KEYDOWN
+from pygame.locals import SWSURFACE, KEYDOWN, K_1, K_2
 
 from mamba.engine import Habitat, NewHabitatEvent
 from mamba.widgets.level import EditLevelWidget
@@ -49,6 +49,9 @@
         if ev.key in ESCAPE_KEYS:
             from mamba.habitats.mainmenu import MainMenu
             NewHabitatEvent.post(MainMenu())
+        elif ev.key == K_1:
+            # Activate floor button
+            self.floor_button.forced_click()
 
     def setup_toolbar(self):
         """Draw the editor toolbar"""
@@ -82,14 +85,15 @@
         self.container.add(self.current_tool)
         button_height += self.current_tool.surface.get_height()
         button_height += button_padding
-        floor_button = ImageButtonWidget(
+        self.floor_button = ImageButtonWidget(
                 (button_left, button_height), self.level.tileset.floor,
                 'Floor', color='white')
-        self.container.add(floor_button)
-        floor_button.add_callback('clicked', self.change_tool,
+        self.container.add(self.floor_button)
+        self.floor_button.add_callback('clicked', self.change_tool,
                 '.', 'Floor')
         self.edit_widget.set_tool('.')
-        button_height += floor_button.surface.get_height() + button_padding
+        button_height += (self.floor_button.surface.get_height()
+                + button_padding)
         if self.mode == 'Tile':
             tile_map = TILE_MAP
             change_mode_text = 'Switch to Things'
@@ -114,10 +118,10 @@
             tile_button.add_callback('clicked', self.change_tool,
                     tile_char, text)
             tool_list.append(tile_button)
-        tool_widget = ToolListWidget((button_left, button_height),
-                tool_list, MAX_TOOLS)
-        self.container.add(tool_widget)
-        button_height += tool_widget.rect.height + 2
+        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)