Mercurial > nagslang
annotate tools/area_editor.py @ 204:687459429550
Display interior walls and start working towards drawing them
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Tue, 03 Sep 2013 23:14:48 +0200 |
parents | c291fd4b49bf |
children | 51f979ddddbb |
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 | |
152
8bbe57d9de0c
Rejig sys.path hacking above albow import, so I can hide it in the root of my repo
Stefano Rivera <stefano@rivera.za.net>
parents:
151
diff
changeset
|
20 sys.path.append(os.path.join(os.path.dirname(__file__), '..')) |
8bbe57d9de0c
Rejig sys.path hacking above albow import, so I can hide it in the root of my repo
Stefano Rivera <stefano@rivera.za.net>
parents:
151
diff
changeset
|
21 |
153
6c5f1a78db75
Levels need a pymunk Space to load
Stefano Rivera <stefano@rivera.za.net>
parents:
152
diff
changeset
|
22 import pymunk |
6c5f1a78db75
Levels need a pymunk Space to load
Stefano Rivera <stefano@rivera.za.net>
parents:
152
diff
changeset
|
23 |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
24 from albow.root import RootWidget |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
25 from albow.widget import Widget |
198 | 26 from albow.controls import Button, Label, CheckBox |
122
02423600d958
Use dialogs to report save results
Neil Muller <drnlmuller@gmail.com>
parents:
117
diff
changeset
|
27 from albow.dialogs import alert |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
28 |
199
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
29 from nagslang.options import parse_args |
109
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
30 from nagslang.constants import SCREEN |
204
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
31 from nagslang.level import Level, POLY_COLORS, LINE_COLOR |
199
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
32 from nagslang.enemies import Enemy |
51 | 33 |
34 | |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
35 # layout constants |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
36 MENU_BUTTON_HEIGHT = 35 |
115 | 37 MENU_PAD = 6 |
38 MENU_HALF_PAD = MENU_PAD // 2 | |
39 MENU_LEFT = SCREEN[0] + MENU_HALF_PAD | |
40 MENU_WIDTH = 200 - MENU_PAD | |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
41 |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
42 |
51 | 43 class EditorLevel(Level): |
44 | |
45 def __init__(self, name, x=800, y=600): | |
46 super(EditorLevel, self).__init__(name) | |
47 self.x = x | |
48 self.y = y | |
49 | |
50 def round_point(self, pos): | |
51 return (10 * (pos[0] // 10), 10 * (pos[1] // 10)) | |
52 | |
53 def point_to_pymunk(self, pos): | |
54 # inverse of point_to_pygame | |
55 # (this is also the same as point_to_pygame, but a additional | |
56 # function for sanity later in pyweek). | |
57 return (pos[0], self.y - pos[1]) | |
58 | |
59 def add_point(self, poly_index, pos): | |
60 self.polygons.setdefault(poly_index, []) | |
61 if not self.polygons[poly_index]: | |
99 | 62 point = self.point_to_pymunk(self.round_point(pos)) |
63 self.polygons[poly_index].append(point) | |
51 | 64 else: |
65 add_pos = self.fix_angle(poly_index, pos) | |
66 self.polygons[poly_index].append(add_pos) | |
67 | |
68 def fix_angle(self, index, pos): | |
69 # Last point | |
70 point1 = self.point_to_pygame(self.polygons[index][-1]) | |
71 pos = self.round_point(pos) | |
72 # We want the line (point1 to pos) to be an angle of | |
73 # 0, 45, 90, 135, 180, 225, 270, 305 | |
74 # However, we only need to consider half the circle | |
75 # This is a hack to approximate the right thing | |
76 pos0 = (pos[0], point1[1]) | |
77 pos90 = (point1[0], pos[1]) | |
78 dist = max(abs(point1[0] - pos[0]), abs(point1[1] - pos[1])) | |
79 pos45 = (point1[0] + dist, point1[1] + dist) | |
80 pos135 = (point1[0] + dist, point1[1] - dist) | |
81 pos225 = (point1[0] - dist, point1[1] - dist) | |
82 pos305 = (point1[0] - dist, point1[1] + dist) | |
83 min_dist = 9999999 | |
84 new_pos = point1 | |
85 for cand in [pos0, pos90, pos45, pos135, pos225, pos305]: | |
86 dist = (pos[0] - cand[0]) ** 2 + (pos[1] - cand[1]) ** 2 | |
87 if dist < min_dist: | |
88 new_pos = cand | |
89 min_dist = dist | |
90 return self.point_to_pymunk(new_pos) | |
91 | |
92 def delete_point(self, index): | |
93 if index in self.polygons and len(self.polygons[index]) > 0: | |
94 self.polygons[index].pop() | |
95 | |
135
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
96 def close_poly(self, index): |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
97 """Attempts to close the current polygon. |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
98 |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
99 We allow a small additional step to close the polygon, but |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
100 it's limited as it's a magic point addition""" |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
101 if len(self.polygons[index]) < 2: |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
102 # Too small |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
103 return False |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
104 first = self.polygons[index][0] |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
105 if self.fix_angle(index, self.point_to_pygame(first)) == first: |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
106 self.add_point(index, self.point_to_pygame(first)) |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
107 return True |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
108 candidates = [(first[0] + 10 * i, first[1]) for |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
109 i in (-3, -2, -1, 1, 2, 3)] |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
110 candidates.extend([(first[0], first[1] + 10 * i) for |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
111 i in (-3, -2, -1, 1, 2, 3)]) |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
112 candidates.extend([(first[0] + 10 * i, first[1] + 10 * i) for |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
113 i in (-3, -2, -1, 1, 2, 3)]) |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
114 candidates.extend([(first[0] + 10 * i, first[1] - 10 * i) for |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
115 i in (-3, -2, -1, 1, 2, 3)]) |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
116 min_dist = 99999 |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
117 poss = None |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
118 for cand in candidates: |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
119 if self.fix_angle(index, self.point_to_pygame(cand)) == cand: |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
120 dist = (first[0] - cand[0]) ** 2 + (first[1] - cand[1]) ** 2 |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
121 if dist < min_dist: |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
122 poss = cand |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
123 if poss is not None: |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
124 self.add_point(index, self.point_to_pygame(poss)) |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
125 self.add_point(index, self.point_to_pygame(first)) |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
126 return True |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
127 return False |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
128 |
199
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
129 def draw(self, mouse_pos, mouse_poly, filled): |
51 | 130 self._draw_background(True) |
131 # 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
|
132 if filled: |
a9b564c38bef
Support showing exterior filled view in the editor
Neil Muller <drnlmuller@gmail.com>
parents:
72
diff
changeset
|
133 self._draw_exterior(True) |
51 | 134 for index, polygon in self.polygons.items(): |
135 color = POLY_COLORS[index] | |
136 if len(polygon) > 1: | |
137 pointlist = [self.point_to_pygame(p) for p in polygon] | |
138 pygame.draw.lines(self._surface, color, False, pointlist, 2) | |
139 if index == mouse_poly and mouse_pos: | |
140 endpoint = self.fix_angle(index, mouse_pos) | |
141 pygame.draw.line(self._surface, color, | |
99 | 142 self.point_to_pygame(polygon[-1]), |
143 self.point_to_pygame(endpoint)) | |
204
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
144 for line in self.lines: |
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
145 pointlist = [self.point_to_pygame(p) for p in line] |
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
146 pygame.draw.lines(self._surface, LINE_COLOR, False, pointlist, 2) |
199
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
147 return self._surface.copy() |
51 | 148 |
109
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
149 |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
150 class LevelWidget(Widget): |
51 | 151 |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
152 def __init__(self, level): |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
153 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
|
154 SCREEN[0], SCREEN[1])) |
51 | 155 self.level = level |
156 self.pos = (0, 0) | |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
157 self.filled_mode = False |
51 | 158 self.mouse_pos = None |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
159 self.cur_poly = None |
167
bb297f3f99f4
Allow using right mouse button to drag level display
Neil Muller <drnlmuller@gmail.com>
parents:
166
diff
changeset
|
160 self._mouse_drag = False |
199
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
161 self._draw_objects = False |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
162 self._draw_enemies = False |
204
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
163 self._draw_lines = False |
51 | 164 |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
165 def _level_coordinates(self, pos): |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
166 # Move positions to level values |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
167 if not pos: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
168 return (0, 0) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
169 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
|
170 |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
171 def _move_view(self, offset): |
51 | 172 new_pos = [self.pos[0] + offset[0], self.pos[1] + offset[1]] |
173 if new_pos[0] < 0: | |
174 new_pos[0] = self.pos[0] | |
175 elif new_pos[0] > self.level.x - SCREEN[0]: | |
176 new_pos[0] = self.pos[0] | |
177 if new_pos[1] < 0: | |
178 new_pos[1] = self.pos[1] | |
179 elif new_pos[1] > self.level.y - SCREEN[1]: | |
180 new_pos[1] = self.pos[1] | |
181 self.pos = tuple(new_pos) | |
182 | |
199
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
183 def set_objects(self, value): |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
184 if self._draw_objects != value: |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
185 self._draw_objects = value |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
186 self.invalidate() |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
187 |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
188 def set_enemies(self, value): |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
189 if self._draw_enemies != value: |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
190 self._draw_enemies = value |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
191 self.invalidate() |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
192 |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
193 def draw(self, surface): |
51 | 194 if (self.cur_poly is not None and self.cur_poly in self.level.polygons |
195 and len(self.level.polygons[self.cur_poly])): | |
196 # We have an active polygon | |
197 mouse_pos = self._level_coordinates(self.mouse_pos) | |
198 else: | |
199 mouse_pos = None | |
199
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
200 level_surface = level.draw(mouse_pos, self.cur_poly, self.filled_mode) |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
201 if self._draw_objects: |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
202 for thing in self.level.drawables: |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
203 if not isinstance(thing, Enemy): |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
204 thing.render(level_surface) |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
205 if self._draw_enemies: |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
206 for thing in self.level.drawables: |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
207 if isinstance(thing, Enemy): |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
208 thing.render(level_surface) |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
209 surface_area = pygame.rect.Rect(self.pos, SCREEN) |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
210 surface.blit(level_surface, (0, 0), surface_area) |
51 | 211 |
115 | 212 def change_poly(self, new_poly): |
213 self.cur_poly = new_poly | |
204
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
214 self._draw_lines = False |
115 | 215 if self.cur_poly is not None: |
216 self.filled_mode = False | |
217 | |
204
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
218 def line_mode(self): |
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
219 self.cur_poly = None |
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
220 self._draw_lines = True |
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
221 self.filled_mode = False |
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
222 |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
223 def key_down(self, ev): |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
224 if ev.key == pgl.K_LEFT: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
225 self._move_view((-10, 0)) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
226 elif ev.key == pgl.K_RIGHT: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
227 self._move_view((10, 0)) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
228 elif ev.key == pgl.K_UP: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
229 self._move_view((0, -10)) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
230 elif ev.key == pgl.K_DOWN: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
231 self._move_view((0, 10)) |
115 | 232 elif ev.key in (pgl.K_1, pgl.K_2, pgl.K_3, pgl.K_4, pgl.K_5, pgl.K_6): |
233 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
|
234 elif ev.key == pgl.K_0: |
115 | 235 self.change_poly(None) |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
236 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
|
237 self.level.delete_point(self.cur_poly) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
238 elif ev.key == pgl.K_f: |
117 | 239 self.set_filled() |
135
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
240 elif ev.key == pgl.K_c: |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
241 self.close_poly() |
117 | 242 |
243 def set_filled(self): | |
165
dba8bc454a43
Fix 'fill exterior' button
Neil Muller <drnlmuller@gmail.com>
parents:
157
diff
changeset
|
244 closed, _ = self.level.all_closed() |
dba8bc454a43
Fix 'fill exterior' button
Neil Muller <drnlmuller@gmail.com>
parents:
157
diff
changeset
|
245 if closed: |
117 | 246 self.cur_poly = None |
247 self.filled_mode = True | |
204
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
248 self._draw_lines = False |
117 | 249 else: |
165
dba8bc454a43
Fix 'fill exterior' button
Neil Muller <drnlmuller@gmail.com>
parents:
157
diff
changeset
|
250 alert('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
|
251 |
109
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
252 def mouse_move(self, ev): |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
253 old_pos = self.mouse_pos |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
254 self.mouse_pos = ev.pos |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
255 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
|
256 self.invalidate() |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
257 |
167
bb297f3f99f4
Allow using right mouse button to drag level display
Neil Muller <drnlmuller@gmail.com>
parents:
166
diff
changeset
|
258 def mouse_drag(self, ev): |
bb297f3f99f4
Allow using right mouse button to drag level display
Neil Muller <drnlmuller@gmail.com>
parents:
166
diff
changeset
|
259 if self._mouse_drag: |
bb297f3f99f4
Allow using right mouse button to drag level display
Neil Muller <drnlmuller@gmail.com>
parents:
166
diff
changeset
|
260 old_pos = self.mouse_pos |
bb297f3f99f4
Allow using right mouse button to drag level display
Neil Muller <drnlmuller@gmail.com>
parents:
166
diff
changeset
|
261 self.mouse_pos = ev.pos |
bb297f3f99f4
Allow using right mouse button to drag level display
Neil Muller <drnlmuller@gmail.com>
parents:
166
diff
changeset
|
262 diff = (-self.mouse_pos[0] + old_pos[0], |
bb297f3f99f4
Allow using right mouse button to drag level display
Neil Muller <drnlmuller@gmail.com>
parents:
166
diff
changeset
|
263 -self.mouse_pos[1] + old_pos[1]) |
bb297f3f99f4
Allow using right mouse button to drag level display
Neil Muller <drnlmuller@gmail.com>
parents:
166
diff
changeset
|
264 self._move_view(diff) |
bb297f3f99f4
Allow using right mouse button to drag level display
Neil Muller <drnlmuller@gmail.com>
parents:
166
diff
changeset
|
265 self.invalidate() |
bb297f3f99f4
Allow using right mouse button to drag level display
Neil Muller <drnlmuller@gmail.com>
parents:
166
diff
changeset
|
266 |
109
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
267 def mouse_down(self, ev): |
184
e003b994c48b
Output coordinates from the level editor, to help place things
Stefano Rivera <stefano@rivera.za.net>
parents:
167
diff
changeset
|
268 if ev.button == 1: |
204
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
269 if self._draw_lines: |
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
270 pass |
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
271 else: |
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
272 print "Click: %r" % ( |
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
273 self.level.point_to_pymunk( |
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
274 self._level_coordinates(ev.pos)),) |
157 | 275 if ev.button == 4: # Scroll up |
276 self._move_view((0, -10)) | |
277 elif ev.button == 5: # Scroll down | |
278 self._move_view((0, 10)) | |
279 elif ev.button == 6: # Scroll left | |
280 self._move_view((-10, 0)) | |
281 elif ev.button == 7: # Scroll right | |
282 self._move_view((10, 0)) | |
167
bb297f3f99f4
Allow using right mouse button to drag level display
Neil Muller <drnlmuller@gmail.com>
parents:
166
diff
changeset
|
283 elif self.cur_poly and ev.button == 1: |
109
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
284 # Add a point |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
285 self.level.add_point(self.cur_poly, |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
286 self._level_coordinates(ev.pos)) |
167
bb297f3f99f4
Allow using right mouse button to drag level display
Neil Muller <drnlmuller@gmail.com>
parents:
166
diff
changeset
|
287 elif ev.button == 3: |
bb297f3f99f4
Allow using right mouse button to drag level display
Neil Muller <drnlmuller@gmail.com>
parents:
166
diff
changeset
|
288 self._mouse_drag = True |
bb297f3f99f4
Allow using right mouse button to drag level display
Neil Muller <drnlmuller@gmail.com>
parents:
166
diff
changeset
|
289 |
bb297f3f99f4
Allow using right mouse button to drag level display
Neil Muller <drnlmuller@gmail.com>
parents:
166
diff
changeset
|
290 def mouse_up(self, ev): |
bb297f3f99f4
Allow using right mouse button to drag level display
Neil Muller <drnlmuller@gmail.com>
parents:
166
diff
changeset
|
291 if ev.button == 3: |
bb297f3f99f4
Allow using right mouse button to drag level display
Neil Muller <drnlmuller@gmail.com>
parents:
166
diff
changeset
|
292 self._mouse_drag = False |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
293 |
135
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
294 def close_poly(self): |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
295 if self.cur_poly is None: |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
296 return |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
297 if self.level.close_poly(self.cur_poly): |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
298 alert("Successfully closed the polygon") |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
299 self.change_poly(None) |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
300 else: |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
301 alert("Failed to close the polygon") |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
302 |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
303 |
115 | 304 class PolyButton(Button): |
305 """Button for coosing the correct polygon""" | |
306 | |
307 def __init__(self, index, level_widget): | |
308 if index is not None: | |
309 text = "Draw: %s" % index | |
310 else: | |
311 text = 'Exit Draw Mode' | |
312 super(PolyButton, self).__init__(text) | |
313 self.index = index | |
314 self.level_widget = level_widget | |
315 | |
316 def action(self): | |
317 self.level_widget.change_poly(self.index) | |
318 | |
319 | |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
320 class EditorApp(RootWidget): |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
321 |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
322 def __init__(self, level, surface): |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
323 super(EditorApp, self).__init__(surface) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
324 self.level = level |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
325 self.level_widget = LevelWidget(self.level) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
326 self.add(self.level_widget) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
327 |
115 | 328 # Add poly buttons |
329 y = 15 | |
330 for poly in range(1, 7): | |
331 but = PolyButton(poly, self.level_widget) | |
332 but.rect = pygame.rect.Rect(0, 0, MENU_WIDTH // 2 - MENU_PAD, | |
333 MENU_BUTTON_HEIGHT) | |
334 if poly % 2: | |
335 but.rect.move_ip(MENU_LEFT, y) | |
336 else: | |
337 but.rect.move_ip(MENU_LEFT + MENU_WIDTH // 2 - MENU_HALF_PAD, | |
338 y) | |
339 y += MENU_BUTTON_HEIGHT + MENU_PAD | |
340 self.add(but) | |
341 | |
134
2e1059b1a247
Tweak button creation code
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
342 button_rect = pygame.rect.Rect(0, 0, MENU_WIDTH, MENU_BUTTON_HEIGHT) |
2e1059b1a247
Tweak button creation code
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
343 |
198 | 344 check_rect = pygame.rect.Rect(0, 0, MENU_BUTTON_HEIGHT // 2, |
345 MENU_BUTTON_HEIGHT // 2) | |
346 | |
115 | 347 end_poly_but = PolyButton(None, self.level_widget) |
134
2e1059b1a247
Tweak button creation code
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
348 end_poly_but.rect = button_rect.copy() |
115 | 349 end_poly_but.rect.move_ip(MENU_LEFT, y) |
350 self.add(end_poly_but) | |
351 y += MENU_BUTTON_HEIGHT + MENU_PAD | |
352 | |
204
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
353 draw_line = Button("Draw interior wall", self.level_widget.line_mode) |
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
354 draw_line.rect = button_rect.copy() |
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
355 draw_line.rect.move_ip(MENU_LEFT, y) |
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
356 self.add(draw_line) |
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
357 y += MENU_BUTTON_HEIGHT + MENU_PAD |
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
358 |
117 | 359 fill_but = Button('Fill exterior', action=self.level_widget.set_filled) |
134
2e1059b1a247
Tweak button creation code
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
360 fill_but.rect = button_rect.copy() |
117 | 361 fill_but.rect.move_ip(MENU_LEFT, y) |
362 self.add(fill_but) | |
363 y += MENU_BUTTON_HEIGHT + MENU_PAD | |
364 | |
116 | 365 save_but = Button('Save Level', action=self.save) |
134
2e1059b1a247
Tweak button creation code
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
366 save_but.rect = button_rect.copy() |
116 | 367 save_but.rect.move_ip(MENU_LEFT, y) |
368 self.add(save_but) | |
369 y += MENU_BUTTON_HEIGHT + MENU_PAD | |
370 | |
135
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
371 close_poly_but = Button('Close Polygon', |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
372 action=self.level_widget.close_poly) |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
373 close_poly_but.rect = button_rect.copy() |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
374 close_poly_but.rect.move_ip(MENU_LEFT, y) |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
375 self.add(close_poly_but) |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
376 y += MENU_BUTTON_HEIGHT + MENU_PAD |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
377 |
198 | 378 white = pygame.color.Color("white") |
379 self.show_objs = CheckBox(fg_color=white) | |
380 self.show_objs.rect = check_rect.copy() | |
381 self.show_objs.rect.move_ip(MENU_LEFT, y) | |
382 label = Label("Show Objects", fg_color=white) | |
383 label.rect.move_ip(MENU_LEFT + MENU_BUTTON_HEIGHT // 2 + MENU_PAD, y) | |
384 self.add(self.show_objs) | |
385 self.add(label) | |
386 y += label.rect.height + MENU_PAD | |
387 | |
388 self.show_enemies = CheckBox(fg_color=white) | |
389 self.show_enemies.rect = check_rect.copy() | |
390 self.show_enemies.rect.move_ip(MENU_LEFT, y) | |
391 label = Label("Show enemy start pos", fg_color=white) | |
392 label.rect.move_ip(MENU_LEFT + MENU_BUTTON_HEIGHT // 2 + MENU_PAD, y) | |
393 self.add(self.show_enemies) | |
394 self.add(label) | |
395 y += label.rect.height + MENU_PAD | |
396 | |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
397 quit_but = Button('Quit', action=self.quit) |
134
2e1059b1a247
Tweak button creation code
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
398 quit_but.rect = button_rect.copy() |
115 | 399 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
|
400 self.add(quit_but) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
401 |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
402 def key_down(self, ev): |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
403 if ev.key == pgl.K_ESCAPE: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
404 self.quit() |
116 | 405 elif ev.key == pgl.K_s: |
406 self.save() | |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
407 else: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
408 self.level_widget.key_down(ev) |
51 | 409 |
116 | 410 def save(self): |
122
02423600d958
Use dialogs to report save results
Neil Muller <drnlmuller@gmail.com>
parents:
117
diff
changeset
|
411 closed, messages = self.level.all_closed() |
02423600d958
Use dialogs to report save results
Neil Muller <drnlmuller@gmail.com>
parents:
117
diff
changeset
|
412 if closed: |
02423600d958
Use dialogs to report save results
Neil Muller <drnlmuller@gmail.com>
parents:
117
diff
changeset
|
413 self.level.save() |
02423600d958
Use dialogs to report save results
Neil Muller <drnlmuller@gmail.com>
parents:
117
diff
changeset
|
414 # display success |
02423600d958
Use dialogs to report save results
Neil Muller <drnlmuller@gmail.com>
parents:
117
diff
changeset
|
415 alert("Level %s saved successfully." % self.level.name) |
02423600d958
Use dialogs to report save results
Neil Muller <drnlmuller@gmail.com>
parents:
117
diff
changeset
|
416 else: |
02423600d958
Use dialogs to report save results
Neil Muller <drnlmuller@gmail.com>
parents:
117
diff
changeset
|
417 # display errors |
02423600d958
Use dialogs to report save results
Neil Muller <drnlmuller@gmail.com>
parents:
117
diff
changeset
|
418 alert("Failed to save level.\n\n%s" % '\n'.join(messages)) |
116 | 419 |
109
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
420 def mouse_move(self, ev): |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
421 self.level_widget.mouse_move(ev) |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
422 |
199
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
423 def draw(self, surface): |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
424 # Update checkbox state |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
425 self.level_widget.set_objects(self.show_objs.value) |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
426 self.level_widget.set_enemies(self.show_enemies.value) |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
427 super(EditorApp, self).draw(surface) |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
428 |
51 | 429 |
430 if __name__ == "__main__": | |
195
b8701c0bb184
Reorder startup to avoid pygame init issues
Neil Muller <drnlmuller@gmail.com>
parents:
187
diff
changeset
|
431 if len(sys.argv) not in [2, 4]: |
51 | 432 print 'Please supply a levelname or levelname and level size' |
433 sys.exit() | |
199
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
434 # Need to ensure we have defaults for rendering |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
435 parse_args([]) |
51 | 436 pygame.display.init() |
437 pygame.font.init() | |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
438 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
|
439 pgl.SWSURFACE) |
195
b8701c0bb184
Reorder startup to avoid pygame init issues
Neil Muller <drnlmuller@gmail.com>
parents:
187
diff
changeset
|
440 if len(sys.argv) == 2: |
b8701c0bb184
Reorder startup to avoid pygame init issues
Neil Muller <drnlmuller@gmail.com>
parents:
187
diff
changeset
|
441 level = EditorLevel(sys.argv[1]) |
b8701c0bb184
Reorder startup to avoid pygame init issues
Neil Muller <drnlmuller@gmail.com>
parents:
187
diff
changeset
|
442 level.load(pymunk.Space()) |
b8701c0bb184
Reorder startup to avoid pygame init issues
Neil Muller <drnlmuller@gmail.com>
parents:
187
diff
changeset
|
443 elif len(sys.argv) == 4: |
b8701c0bb184
Reorder startup to avoid pygame init issues
Neil Muller <drnlmuller@gmail.com>
parents:
187
diff
changeset
|
444 level = EditorLevel(sys.argv[1], int(sys.argv[2]), int(sys.argv[3])) |
51 | 445 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
|
446 pygame.key.set_repeat(200, 100) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
447 app = EditorApp(level, pygame.display.get_surface()) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
448 app.run() |