Mercurial > mamba
comparison mamba/habitats/editor.py @ 240:f0c14d9abd84
Hack in multi-page toolbar
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Wed, 14 Sep 2011 23:57:00 +0200 |
parents | 9498b259c248 |
children | 74ae1645df6e |
comparison
equal
deleted
inserted
replaced
239:676523572a01 | 240:f0c14d9abd84 |
---|---|
11 from mamba.widgets.entrybox import EntryBox | 11 from mamba.widgets.entrybox import EntryBox |
12 from mamba.level import Level, TILE_MAP, THING_MAP | 12 from mamba.level import Level, TILE_MAP, THING_MAP |
13 from mamba.data import check_level_exists | 13 from mamba.data import check_level_exists |
14 from mamba.constants import SCREEN, EDIT_SCREEN, NAME, ESCAPE_KEYS | 14 from mamba.constants import SCREEN, EDIT_SCREEN, NAME, ESCAPE_KEYS |
15 | 15 |
16 MAX_TOOLS = 8 | |
17 | |
16 | 18 |
17 class EditorHabitat(Habitat): | 19 class EditorHabitat(Habitat): |
18 def __init__(self, level_name): | 20 def __init__(self, level_name): |
19 super(EditorHabitat, self).__init__(EDIT_SCREEN) | 21 super(EditorHabitat, self).__init__(EDIT_SCREEN) |
20 self.level = Level(level_name) | 22 self.level = Level(level_name) |
21 self.edit_widget = EditLevelWidget(self.level) | 23 self.edit_widget = EditLevelWidget(self.level) |
22 self.container.add(self.edit_widget) | 24 self.container.add(self.edit_widget) |
23 self.container.add_callback(KEYDOWN, self.keydown_event) | 25 self.container.add_callback(KEYDOWN, self.keydown_event) |
24 self.mode = 'Tile' | 26 self.mode = 'Tile' |
27 self.tool_page = 0 | |
25 | 28 |
26 def on_enter(self): | 29 def on_enter(self): |
27 # We need to juggle the display to the correct size | 30 # We need to juggle the display to the correct size |
28 # This is a horrible hack | 31 # This is a horrible hack |
29 pygame.display.quit() | 32 pygame.display.quit() |
91 tile_map = TILE_MAP | 94 tile_map = TILE_MAP |
92 change_mode_text = 'Switch to Things' | 95 change_mode_text = 'Switch to Things' |
93 elif self.mode == 'Thing': | 96 elif self.mode == 'Thing': |
94 tile_map = THING_MAP | 97 tile_map = THING_MAP |
95 change_mode_text = 'Switch to Tiles' | 98 change_mode_text = 'Switch to Tiles' |
99 total_tools = len(tile_map) | |
100 start_page = MAX_TOOLS * self.tool_page | |
101 end_page = start_page + MAX_TOOLS | |
102 tile_map = sorted(tile_map)[start_page:end_page] | |
96 for tile_char in tile_map: | 103 for tile_char in tile_map: |
97 try: | 104 try: |
98 tile = self.level.tileset[tile_char] | 105 tile = self.level.tileset[tile_char] |
99 except pygame.error: | 106 except pygame.error: |
100 # Ignore stuff we can't load for now | 107 # Ignore stuff we can't load for now |
113 self.container.add(tile_button) | 120 self.container.add(tile_button) |
114 button_height += \ | 121 button_height += \ |
115 tile_button.surface.get_height() + button_padding | 122 tile_button.surface.get_height() + button_padding |
116 button_height += 2 | 123 button_height += 2 |
117 | 124 |
125 prev_page = None | |
126 next_page = None | |
127 if start_page > 0: | |
128 prev_page = TextButton((button_left, button_height), | |
129 'Prev') | |
130 prev_page.add_callback('clicked', self.change_page, -1) | |
131 self.container.add(prev_page) | |
132 if end_page < total_tools: | |
133 next_page = TextButton((button_left + 100, button_height), | |
134 'Next') | |
135 next_page.add_callback('clicked', self.change_page, +1) | |
136 self.container.add(next_page) | |
137 if prev_page: | |
138 button_height += prev_page.rect.height | |
139 elif next_page: | |
140 button_height += next_page.rect.height | |
118 mode_button = TextButton((button_left, button_height), | 141 mode_button = TextButton((button_left, button_height), |
119 change_mode_text) | 142 change_mode_text) |
120 mode_button.add_callback('clicked', self.change_toolbar) | 143 mode_button.add_callback('clicked', self.change_toolbar) |
121 self.container.add(mode_button) | 144 self.container.add(mode_button) |
122 button_height += mode_button.surface.get_height() + button_padding | 145 button_height += mode_button.surface.get_height() + button_padding |
137 def change_toolbar(self, ev, widget): | 160 def change_toolbar(self, ev, widget): |
138 if self.mode == 'Tile': | 161 if self.mode == 'Tile': |
139 self.mode = 'Thing' | 162 self.mode = 'Thing' |
140 elif self.mode == 'Thing': | 163 elif self.mode == 'Thing': |
141 self.mode = 'Tile' | 164 self.mode = 'Tile' |
165 self.tool_page = 0 | |
166 self.clear_toolbar() | |
167 self.setup_toolbar() | |
168 | |
169 def change_page(self, ev, widget, change): | |
170 self.tool_page += change | |
142 self.clear_toolbar() | 171 self.clear_toolbar() |
143 self.setup_toolbar() | 172 self.setup_toolbar() |
144 | 173 |
145 def clear_toolbar(self): | 174 def clear_toolbar(self): |
146 """Remove every non-edit widget from the container""" | 175 """Remove every non-edit widget from the container""" |