comparison 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
comparison
equal deleted inserted replaced
63:07f18421f121 64:fbb5cc655b47
1 """Habitat for editing levels.""" 1 """Habitat for editing levels."""
2 2
3 import pygame.display 3 import pygame.display
4 from pygame.locals import SWSURFACE 4 from pygame.locals import SWSURFACE, KEYDOWN
5 5
6 from mamba.engine import Habitat 6 from mamba.engine import Habitat, NewHabitatEvent
7 from mamba.widgets.level import LevelWidget 7 from mamba.widgets.level import LevelWidget
8 from mamba.level import Level 8 from mamba.level import Level
9 from mamba.constants import SCREEN, EDIT_SCREEN, NAME 9 from mamba.constants import SCREEN, EDIT_SCREEN, NAME, ESCAPE_KEYS
10 10
11 11
12 class EditorHabitat(Habitat): 12 class EditorHabitat(Habitat):
13 def __init__(self, level_name): 13 def __init__(self, level_name):
14 super(EditorHabitat, self).__init__() 14 super(EditorHabitat, self).__init__()
15 self.level = Level(level_name) 15 self.level = Level(level_name)
16 self.container.add(LevelWidget(self.level)) 16 self.container.add(LevelWidget(self.level))
17 self.container.add_callback(KEYDOWN, self.keydown_event)
17 18
18 def on_enter(self): 19 def on_enter(self):
19 # We need to juggle the display to the correct size 20 # We need to juggle the display to the correct size
20 # This is a horrible hack 21 # This is a horrible hack
21 pygame.display.quit() 22 pygame.display.quit()
22 pygame.display.init() 23 pygame.display.init()
23 pygame.display.set_mode(EDIT_SCREEN, SWSURFACE) 24 pygame.display.set_mode(EDIT_SCREEN, SWSURFACE)
24 pygame.display.set_caption('%s Level editor' % NAME) 25 pygame.display.set_caption('%s Level editor' % NAME)
26 super(EditorHabitat, self).on_enter()
25 27
26 def on_exit(self): 28 def on_exit(self):
27 # We need to juggle the display to the correct size 29 # We need to juggle the display to the correct size
28 # This is a horrible hack 30 # This is a horrible hack
31 super(EditorHabitat, self).on_exit()
29 pygame.display.quit() 32 pygame.display.quit()
30 pygame.display.init() 33 pygame.display.init()
31 pygame.display.set_mode(SCREEN, SWSURFACE) 34 pygame.display.set_mode(SCREEN, SWSURFACE)
32 pygame.display.set_caption(NAME) 35 pygame.display.set_caption(NAME)
36
37 def keydown_event(self, ev, widget):
38 if ev.key in ESCAPE_KEYS:
39 from mamba.habitats.mainmenu import MainMenu
40 NewHabitatEvent.post(MainMenu())