Mercurial > mamba
annotate 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 |
rev | line source |
---|---|
42
8521c142cd43
Add habitat for editor and reshuffle when options are checked to before initializing the display window.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
1 """Habitat for editing levels.""" |
8521c142cd43
Add habitat for editor and reshuffle when options are checked to before initializing the display window.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
2 |
52
d09f63429b80
Add screen size fiddling to editor habitat
Neil Muller <drnlmuller@gmail.com>
parents:
42
diff
changeset
|
3 import pygame.display |
64
fbb5cc655b47
More screen size fiddling hackery
Neil Muller <drnlmuller@gmail.com>
parents:
52
diff
changeset
|
4 from pygame.locals import SWSURFACE, KEYDOWN |
52
d09f63429b80
Add screen size fiddling to editor habitat
Neil Muller <drnlmuller@gmail.com>
parents:
42
diff
changeset
|
5 |
64
fbb5cc655b47
More screen size fiddling hackery
Neil Muller <drnlmuller@gmail.com>
parents:
52
diff
changeset
|
6 from mamba.engine import Habitat, NewHabitatEvent |
42
8521c142cd43
Add habitat for editor and reshuffle when options are checked to before initializing the display window.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
7 from mamba.widgets.level import LevelWidget |
8521c142cd43
Add habitat for editor and reshuffle when options are checked to before initializing the display window.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
8 from mamba.level import Level |
64
fbb5cc655b47
More screen size fiddling hackery
Neil Muller <drnlmuller@gmail.com>
parents:
52
diff
changeset
|
9 from mamba.constants import SCREEN, EDIT_SCREEN, NAME, ESCAPE_KEYS |
42
8521c142cd43
Add habitat for editor and reshuffle when options are checked to before initializing the display window.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
10 |
8521c142cd43
Add habitat for editor and reshuffle when options are checked to before initializing the display window.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
11 |
8521c142cd43
Add habitat for editor and reshuffle when options are checked to before initializing the display window.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
12 class EditorHabitat(Habitat): |
8521c142cd43
Add habitat for editor and reshuffle when options are checked to before initializing the display window.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
13 def __init__(self, level_name): |
8521c142cd43
Add habitat for editor and reshuffle when options are checked to before initializing the display window.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
14 super(EditorHabitat, self).__init__() |
8521c142cd43
Add habitat for editor and reshuffle when options are checked to before initializing the display window.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
15 self.level = Level(level_name) |
8521c142cd43
Add habitat for editor and reshuffle when options are checked to before initializing the display window.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
16 self.container.add(LevelWidget(self.level)) |
64
fbb5cc655b47
More screen size fiddling hackery
Neil Muller <drnlmuller@gmail.com>
parents:
52
diff
changeset
|
17 self.container.add_callback(KEYDOWN, self.keydown_event) |
52
d09f63429b80
Add screen size fiddling to editor habitat
Neil Muller <drnlmuller@gmail.com>
parents:
42
diff
changeset
|
18 |
d09f63429b80
Add screen size fiddling to editor habitat
Neil Muller <drnlmuller@gmail.com>
parents:
42
diff
changeset
|
19 def on_enter(self): |
d09f63429b80
Add screen size fiddling to editor habitat
Neil Muller <drnlmuller@gmail.com>
parents:
42
diff
changeset
|
20 # We need to juggle the display to the correct size |
d09f63429b80
Add screen size fiddling to editor habitat
Neil Muller <drnlmuller@gmail.com>
parents:
42
diff
changeset
|
21 # This is a horrible hack |
d09f63429b80
Add screen size fiddling to editor habitat
Neil Muller <drnlmuller@gmail.com>
parents:
42
diff
changeset
|
22 pygame.display.quit() |
d09f63429b80
Add screen size fiddling to editor habitat
Neil Muller <drnlmuller@gmail.com>
parents:
42
diff
changeset
|
23 pygame.display.init() |
d09f63429b80
Add screen size fiddling to editor habitat
Neil Muller <drnlmuller@gmail.com>
parents:
42
diff
changeset
|
24 pygame.display.set_mode(EDIT_SCREEN, SWSURFACE) |
d09f63429b80
Add screen size fiddling to editor habitat
Neil Muller <drnlmuller@gmail.com>
parents:
42
diff
changeset
|
25 pygame.display.set_caption('%s Level editor' % NAME) |
64
fbb5cc655b47
More screen size fiddling hackery
Neil Muller <drnlmuller@gmail.com>
parents:
52
diff
changeset
|
26 super(EditorHabitat, self).on_enter() |
52
d09f63429b80
Add screen size fiddling to editor habitat
Neil Muller <drnlmuller@gmail.com>
parents:
42
diff
changeset
|
27 |
d09f63429b80
Add screen size fiddling to editor habitat
Neil Muller <drnlmuller@gmail.com>
parents:
42
diff
changeset
|
28 def on_exit(self): |
d09f63429b80
Add screen size fiddling to editor habitat
Neil Muller <drnlmuller@gmail.com>
parents:
42
diff
changeset
|
29 # We need to juggle the display to the correct size |
d09f63429b80
Add screen size fiddling to editor habitat
Neil Muller <drnlmuller@gmail.com>
parents:
42
diff
changeset
|
30 # This is a horrible hack |
64
fbb5cc655b47
More screen size fiddling hackery
Neil Muller <drnlmuller@gmail.com>
parents:
52
diff
changeset
|
31 super(EditorHabitat, self).on_exit() |
52
d09f63429b80
Add screen size fiddling to editor habitat
Neil Muller <drnlmuller@gmail.com>
parents:
42
diff
changeset
|
32 pygame.display.quit() |
d09f63429b80
Add screen size fiddling to editor habitat
Neil Muller <drnlmuller@gmail.com>
parents:
42
diff
changeset
|
33 pygame.display.init() |
d09f63429b80
Add screen size fiddling to editor habitat
Neil Muller <drnlmuller@gmail.com>
parents:
42
diff
changeset
|
34 pygame.display.set_mode(SCREEN, SWSURFACE) |
d09f63429b80
Add screen size fiddling to editor habitat
Neil Muller <drnlmuller@gmail.com>
parents:
42
diff
changeset
|
35 pygame.display.set_caption(NAME) |
64
fbb5cc655b47
More screen size fiddling hackery
Neil Muller <drnlmuller@gmail.com>
parents:
52
diff
changeset
|
36 |
fbb5cc655b47
More screen size fiddling hackery
Neil Muller <drnlmuller@gmail.com>
parents:
52
diff
changeset
|
37 def keydown_event(self, ev, widget): |
fbb5cc655b47
More screen size fiddling hackery
Neil Muller <drnlmuller@gmail.com>
parents:
52
diff
changeset
|
38 if ev.key in ESCAPE_KEYS: |
fbb5cc655b47
More screen size fiddling hackery
Neil Muller <drnlmuller@gmail.com>
parents:
52
diff
changeset
|
39 from mamba.habitats.mainmenu import MainMenu |
fbb5cc655b47
More screen size fiddling hackery
Neil Muller <drnlmuller@gmail.com>
parents:
52
diff
changeset
|
40 NewHabitatEvent.post(MainMenu()) |