Mercurial > mamba
diff mamba/habitats/editor.py @ 64:fbb5cc655b47
More screen size fiddling hackery
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Sun, 11 Sep 2011 17:23:42 +0200 |
parents | d09f63429b80 |
children | aba653f8383e |
line wrap: on
line diff
--- a/mamba/habitats/editor.py Sun Sep 11 16:54:09 2011 +0200 +++ b/mamba/habitats/editor.py Sun Sep 11 17:23:42 2011 +0200 @@ -1,12 +1,12 @@ """Habitat for editing levels.""" import pygame.display -from pygame.locals import SWSURFACE +from pygame.locals import SWSURFACE, KEYDOWN -from mamba.engine import Habitat +from mamba.engine import Habitat, NewHabitatEvent from mamba.widgets.level import LevelWidget from mamba.level import Level -from mamba.constants import SCREEN, EDIT_SCREEN, NAME +from mamba.constants import SCREEN, EDIT_SCREEN, NAME, ESCAPE_KEYS class EditorHabitat(Habitat): @@ -14,6 +14,7 @@ super(EditorHabitat, self).__init__() self.level = Level(level_name) self.container.add(LevelWidget(self.level)) + self.container.add_callback(KEYDOWN, self.keydown_event) def on_enter(self): # We need to juggle the display to the correct size @@ -22,11 +23,18 @@ pygame.display.init() pygame.display.set_mode(EDIT_SCREEN, SWSURFACE) pygame.display.set_caption('%s Level editor' % NAME) + super(EditorHabitat, self).on_enter() def on_exit(self): # We need to juggle the display to the correct size # This is a horrible hack + super(EditorHabitat, self).on_exit() pygame.display.quit() pygame.display.init() pygame.display.set_mode(SCREEN, SWSURFACE) pygame.display.set_caption(NAME) + + def keydown_event(self, ev, widget): + if ev.key in ESCAPE_KEYS: + from mamba.habitats.mainmenu import MainMenu + NewHabitatEvent.post(MainMenu())