Mercurial > nagslang
annotate tools/area_editor.py @ 122:02423600d958
Use dialogs to report save results
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Mon, 02 Sep 2013 16:40:56 +0200 |
parents | 9f3557e4833a |
children | 2e1059b1a247 |
rev | line source |
---|---|
71
c449a3507a6b
Shebang and path hacking, so that the area_editor runs
Stefano Rivera <stefano@rivera.za.net>
parents:
57
diff
changeset
|
1 #!/usr/bin/env python |
c449a3507a6b
Shebang and path hacking, so that the area_editor runs
Stefano Rivera <stefano@rivera.za.net>
parents:
57
diff
changeset
|
2 |
51 | 3 # The basic area editor |
4 # | |
5 # To edit an existing level, use | |
6 # editor levelname | |
7 # | |
8 # To create a new level: | |
9 # | |
10 # editor levelname <xsize> <ysiz> | |
11 # (size specified in pixels | |
12 # | |
13 | |
71
c449a3507a6b
Shebang and path hacking, so that the area_editor runs
Stefano Rivera <stefano@rivera.za.net>
parents:
57
diff
changeset
|
14 import os |
c449a3507a6b
Shebang and path hacking, so that the area_editor runs
Stefano Rivera <stefano@rivera.za.net>
parents:
57
diff
changeset
|
15 import sys |
c449a3507a6b
Shebang and path hacking, so that the area_editor runs
Stefano Rivera <stefano@rivera.za.net>
parents:
57
diff
changeset
|
16 |
51 | 17 import pygame |
18 import pygame.locals as pgl | |
19 | |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
20 from albow.root import RootWidget |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
21 from albow.widget import Widget |
109
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
22 from albow.controls import Button |
122
02423600d958
Use dialogs to report save results
Neil Muller <drnlmuller@gmail.com>
parents:
117
diff
changeset
|
23 from albow.dialogs import alert |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
24 |
71
c449a3507a6b
Shebang and path hacking, so that the area_editor runs
Stefano Rivera <stefano@rivera.za.net>
parents:
57
diff
changeset
|
25 sys.path.append(os.path.join(os.path.dirname(__file__), '..')) |
c449a3507a6b
Shebang and path hacking, so that the area_editor runs
Stefano Rivera <stefano@rivera.za.net>
parents:
57
diff
changeset
|
26 |
109
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
27 from nagslang.constants import SCREEN |
51 | 28 from nagslang.level import Level, POLY_COLORS |
29 | |
30 | |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
31 # layout constants |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
32 MENU_BUTTON_HEIGHT = 35 |
115 | 33 MENU_PAD = 6 |
34 MENU_HALF_PAD = MENU_PAD // 2 | |
35 MENU_LEFT = SCREEN[0] + MENU_HALF_PAD | |
36 MENU_WIDTH = 200 - MENU_PAD | |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
37 |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
38 |
51 | 39 class EditorLevel(Level): |
40 | |
41 def __init__(self, name, x=800, y=600): | |
42 super(EditorLevel, self).__init__(name) | |
43 self.x = x | |
44 self.y = y | |
45 | |
46 def round_point(self, pos): | |
47 return (10 * (pos[0] // 10), 10 * (pos[1] // 10)) | |
48 | |
49 def point_to_pymunk(self, pos): | |
50 # inverse of point_to_pygame | |
51 # (this is also the same as point_to_pygame, but a additional | |
52 # function for sanity later in pyweek). | |
53 return (pos[0], self.y - pos[1]) | |
54 | |
55 def add_point(self, poly_index, pos): | |
56 self.polygons.setdefault(poly_index, []) | |
57 if not self.polygons[poly_index]: | |
99 | 58 point = self.point_to_pymunk(self.round_point(pos)) |
59 self.polygons[poly_index].append(point) | |
51 | 60 else: |
61 add_pos = self.fix_angle(poly_index, pos) | |
62 self.polygons[poly_index].append(add_pos) | |
63 | |
64 def fix_angle(self, index, pos): | |
65 # Last point | |
66 point1 = self.point_to_pygame(self.polygons[index][-1]) | |
67 pos = self.round_point(pos) | |
68 # We want the line (point1 to pos) to be an angle of | |
69 # 0, 45, 90, 135, 180, 225, 270, 305 | |
70 # However, we only need to consider half the circle | |
71 # This is a hack to approximate the right thing | |
72 pos0 = (pos[0], point1[1]) | |
73 pos90 = (point1[0], pos[1]) | |
74 dist = max(abs(point1[0] - pos[0]), abs(point1[1] - pos[1])) | |
75 pos45 = (point1[0] + dist, point1[1] + dist) | |
76 pos135 = (point1[0] + dist, point1[1] - dist) | |
77 pos225 = (point1[0] - dist, point1[1] - dist) | |
78 pos305 = (point1[0] - dist, point1[1] + dist) | |
79 min_dist = 9999999 | |
80 new_pos = point1 | |
81 for cand in [pos0, pos90, pos45, pos135, pos225, pos305]: | |
82 dist = (pos[0] - cand[0]) ** 2 + (pos[1] - cand[1]) ** 2 | |
83 if dist < min_dist: | |
84 new_pos = cand | |
85 min_dist = dist | |
86 return self.point_to_pymunk(new_pos) | |
87 | |
88 def delete_point(self, index): | |
89 if index in self.polygons and len(self.polygons[index]) > 0: | |
90 self.polygons[index].pop() | |
91 | |
96
a9b564c38bef
Support showing exterior filled view in the editor
Neil Muller <drnlmuller@gmail.com>
parents:
72
diff
changeset
|
92 def draw(self, surface, topleft, mouse_pos, mouse_poly, filled): |
51 | 93 self._draw_background(True) |
94 # Draw polygons as needed for the editor | |
96
a9b564c38bef
Support showing exterior filled view in the editor
Neil Muller <drnlmuller@gmail.com>
parents:
72
diff
changeset
|
95 if filled: |
a9b564c38bef
Support showing exterior filled view in the editor
Neil Muller <drnlmuller@gmail.com>
parents:
72
diff
changeset
|
96 self._draw_exterior(True) |
51 | 97 for index, polygon in self.polygons.items(): |
98 color = POLY_COLORS[index] | |
99 if len(polygon) > 1: | |
100 pointlist = [self.point_to_pygame(p) for p in polygon] | |
101 pygame.draw.lines(self._surface, color, False, pointlist, 2) | |
102 if index == mouse_poly and mouse_pos: | |
103 endpoint = self.fix_angle(index, mouse_pos) | |
104 pygame.draw.line(self._surface, color, | |
99 | 105 self.point_to_pygame(polygon[-1]), |
106 self.point_to_pygame(endpoint)) | |
51 | 107 surface_area = pygame.rect.Rect(topleft, SCREEN) |
108 surface.blit(self._surface, (0, 0), surface_area) | |
109 | |
109
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
110 |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
111 class LevelWidget(Widget): |
51 | 112 |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
113 def __init__(self, level): |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
114 super(LevelWidget, self).__init__(pygame.rect.Rect(0, 0, |
109
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
115 SCREEN[0], SCREEN[1])) |
51 | 116 self.level = level |
117 self.pos = (0, 0) | |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
118 self.filled_mode = False |
51 | 119 self.mouse_pos = None |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
120 self.cur_poly = None |
51 | 121 |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
122 def _level_coordinates(self, pos): |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
123 # Move positions to level values |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
124 if not pos: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
125 return (0, 0) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
126 return pos[0] + self.pos[0], pos[1] + self.pos[1] |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
127 |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
128 def _move_view(self, offset): |
51 | 129 new_pos = [self.pos[0] + offset[0], self.pos[1] + offset[1]] |
130 if new_pos[0] < 0: | |
131 new_pos[0] = self.pos[0] | |
132 elif new_pos[0] > self.level.x - SCREEN[0]: | |
133 new_pos[0] = self.pos[0] | |
134 if new_pos[1] < 0: | |
135 new_pos[1] = self.pos[1] | |
136 elif new_pos[1] > self.level.y - SCREEN[1]: | |
137 new_pos[1] = self.pos[1] | |
138 self.pos = tuple(new_pos) | |
139 | |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
140 def draw(self, surface): |
51 | 141 if (self.cur_poly is not None and self.cur_poly in self.level.polygons |
142 and len(self.level.polygons[self.cur_poly])): | |
143 # We have an active polygon | |
144 mouse_pos = self._level_coordinates(self.mouse_pos) | |
145 else: | |
146 mouse_pos = None | |
109
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
147 level.draw(surface, self.pos, mouse_pos, self.cur_poly, |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
148 self.filled_mode) |
51 | 149 |
115 | 150 def change_poly(self, new_poly): |
151 self.cur_poly = new_poly | |
152 if self.cur_poly is not None: | |
153 self.filled_mode = False | |
154 | |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
155 def key_down(self, ev): |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
156 if ev.key == pgl.K_LEFT: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
157 self._move_view((-10, 0)) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
158 elif ev.key == pgl.K_RIGHT: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
159 self._move_view((10, 0)) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
160 elif ev.key == pgl.K_UP: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
161 self._move_view((0, -10)) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
162 elif ev.key == pgl.K_DOWN: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
163 self._move_view((0, 10)) |
115 | 164 elif ev.key in (pgl.K_1, pgl.K_2, pgl.K_3, pgl.K_4, pgl.K_5, pgl.K_6): |
165 self.change_poly(ev.key - pgl.K_0) | |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
166 elif ev.key == pgl.K_0: |
115 | 167 self.change_poly(None) |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
168 elif ev.key == pgl.K_d and self.cur_poly: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
169 self.level.delete_point(self.cur_poly) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
170 elif ev.key == pgl.K_f: |
117 | 171 self.set_filled() |
172 | |
173 def set_filled(self): | |
174 if level.all_closed(): | |
175 self.cur_poly = None | |
176 self.filled_mode = True | |
177 else: | |
178 print 'Not all polygons closed, so not filling' | |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
179 |
109
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
180 def mouse_move(self, ev): |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
181 old_pos = self.mouse_pos |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
182 self.mouse_pos = ev.pos |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
183 if self.cur_poly and old_pos != self.mouse_pos: |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
184 self.invalidate() |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
185 |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
186 def mouse_down(self, ev): |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
187 if self.cur_poly: |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
188 # Add a point |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
189 self.level.add_point(self.cur_poly, |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
190 self._level_coordinates(ev.pos)) |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
191 |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
192 |
115 | 193 class PolyButton(Button): |
194 """Button for coosing the correct polygon""" | |
195 | |
196 def __init__(self, index, level_widget): | |
197 if index is not None: | |
198 text = "Draw: %s" % index | |
199 else: | |
200 text = 'Exit Draw Mode' | |
201 super(PolyButton, self).__init__(text) | |
202 self.index = index | |
203 self.level_widget = level_widget | |
204 | |
205 def action(self): | |
206 self.level_widget.change_poly(self.index) | |
207 | |
208 | |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
209 class EditorApp(RootWidget): |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
210 |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
211 def __init__(self, level, surface): |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
212 super(EditorApp, self).__init__(surface) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
213 self.level = level |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
214 self.level_widget = LevelWidget(self.level) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
215 self.add(self.level_widget) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
216 |
115 | 217 # Add poly buttons |
218 y = 15 | |
219 for poly in range(1, 7): | |
220 but = PolyButton(poly, self.level_widget) | |
221 but.rect = pygame.rect.Rect(0, 0, MENU_WIDTH // 2 - MENU_PAD, | |
222 MENU_BUTTON_HEIGHT) | |
223 if poly % 2: | |
224 but.rect.move_ip(MENU_LEFT, y) | |
225 else: | |
226 but.rect.move_ip(MENU_LEFT + MENU_WIDTH // 2 - MENU_HALF_PAD, | |
227 y) | |
228 y += MENU_BUTTON_HEIGHT + MENU_PAD | |
229 self.add(but) | |
230 | |
231 end_poly_but = PolyButton(None, self.level_widget) | |
232 end_poly_but.rect = pygame.rect.Rect(0, 0, MENU_WIDTH, | |
233 MENU_BUTTON_HEIGHT) | |
234 end_poly_but.rect.move_ip(MENU_LEFT, y) | |
235 self.add(end_poly_but) | |
236 y += MENU_BUTTON_HEIGHT + MENU_PAD | |
237 | |
117 | 238 fill_but = Button('Fill exterior', action=self.level_widget.set_filled) |
239 fill_but.rect = pygame.rect.Rect(0, 0, MENU_WIDTH, MENU_BUTTON_HEIGHT) | |
240 fill_but.rect.move_ip(MENU_LEFT, y) | |
241 self.add(fill_but) | |
242 y += MENU_BUTTON_HEIGHT + MENU_PAD | |
243 | |
116 | 244 save_but = Button('Save Level', action=self.save) |
245 save_but.rect = pygame.rect.Rect(0, 0, MENU_WIDTH, MENU_BUTTON_HEIGHT) | |
246 save_but.rect.move_ip(MENU_LEFT, y) | |
247 self.add(save_but) | |
248 y += MENU_BUTTON_HEIGHT + MENU_PAD | |
249 | |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
250 quit_but = Button('Quit', action=self.quit) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
251 quit_but.rect = pygame.rect.Rect(0, 0, MENU_WIDTH, MENU_BUTTON_HEIGHT) |
115 | 252 quit_but.rect.move_ip(MENU_LEFT, y) |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
253 self.add(quit_but) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
254 |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
255 def key_down(self, ev): |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
256 if ev.key == pgl.K_ESCAPE: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
257 self.quit() |
116 | 258 elif ev.key == pgl.K_s: |
259 self.save() | |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
260 else: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
261 self.level_widget.key_down(ev) |
51 | 262 |
116 | 263 def save(self): |
122
02423600d958
Use dialogs to report save results
Neil Muller <drnlmuller@gmail.com>
parents:
117
diff
changeset
|
264 closed, messages = self.level.all_closed() |
02423600d958
Use dialogs to report save results
Neil Muller <drnlmuller@gmail.com>
parents:
117
diff
changeset
|
265 if closed: |
02423600d958
Use dialogs to report save results
Neil Muller <drnlmuller@gmail.com>
parents:
117
diff
changeset
|
266 self.level.save() |
02423600d958
Use dialogs to report save results
Neil Muller <drnlmuller@gmail.com>
parents:
117
diff
changeset
|
267 # display success |
02423600d958
Use dialogs to report save results
Neil Muller <drnlmuller@gmail.com>
parents:
117
diff
changeset
|
268 alert("Level %s saved successfully." % self.level.name) |
02423600d958
Use dialogs to report save results
Neil Muller <drnlmuller@gmail.com>
parents:
117
diff
changeset
|
269 else: |
02423600d958
Use dialogs to report save results
Neil Muller <drnlmuller@gmail.com>
parents:
117
diff
changeset
|
270 # display errors |
02423600d958
Use dialogs to report save results
Neil Muller <drnlmuller@gmail.com>
parents:
117
diff
changeset
|
271 alert("Failed to save level.\n\n%s" % '\n'.join(messages)) |
116 | 272 |
109
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
273 def mouse_move(self, ev): |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
274 self.level_widget.mouse_move(ev) |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
275 |
51 | 276 |
277 if __name__ == "__main__": | |
278 if len(sys.argv) == 2: | |
279 level = EditorLevel(sys.argv[1]) | |
280 level.load() | |
281 elif len(sys.argv) == 4: | |
282 level = EditorLevel(sys.argv[1], int(sys.argv[2]), int(sys.argv[3])) | |
283 else: | |
284 print 'Please supply a levelname or levelname and level size' | |
285 sys.exit() | |
286 pygame.display.init() | |
287 pygame.font.init() | |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
288 pygame.display.set_mode((SCREEN[0] + MENU_WIDTH, SCREEN[1]), |
109
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
289 pgl.SWSURFACE) |
51 | 290 pygame.display.set_caption('Nagslang Area Editor') |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
291 pygame.key.set_repeat(200, 100) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
292 app = EditorApp(level, pygame.display.get_surface()) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
293 app.run() |