Mercurial > nagslang
annotate tools/area_editor.py @ 457:fcf9f6edf153
Use right cordinates for interior walls
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Sat, 07 Sep 2013 15:32:24 +0200 |
parents | 9ae08939fd90 |
children | 41ebc538109c |
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 # | |
315 | 10 # editor levelname <xsize> <ysize> |
51 | 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 |
225
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
27 from albow.dialogs import alert, Dialog |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
28 from albow.layout import Row |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
29 from albow.fields import TextField |
225
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
30 from albow.table_view import TableView, TableColumn |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
31 |
199
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
32 from nagslang.options import parse_args |
109
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
33 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
|
34 from nagslang.level import Level, POLY_COLORS, LINE_COLOR |
255 | 35 from nagslang.yamlish import load_s |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
36 import nagslang.enemies as ne |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
37 import nagslang.game_object as ngo |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
38 import nagslang.puzzle as np |
51 | 39 |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
40 # layout constants |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
41 MENU_BUTTON_HEIGHT = 35 |
423 | 42 MENU_PAD = 4 |
115 | 43 MENU_HALF_PAD = MENU_PAD // 2 |
44 MENU_LEFT = SCREEN[0] + MENU_HALF_PAD | |
45 MENU_WIDTH = 200 - MENU_PAD | |
419 | 46 MENU_HALF_WIDTH = MENU_WIDTH // 2 - MENU_HALF_PAD |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
47 |
220
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
48 BUTTON_RECT = pygame.rect.Rect(0, 0, MENU_WIDTH, MENU_BUTTON_HEIGHT) |
419 | 49 HALF_BUTTON_RECT = pygame.rect.Rect(0, 0, MENU_HALF_WIDTH, MENU_BUTTON_HEIGHT) |
220
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
50 CHECK_RECT = pygame.rect.Rect(0, 0, MENU_BUTTON_HEIGHT // 2, |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
51 MENU_BUTTON_HEIGHT // 2) |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
52 |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
53 |
355
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
54 class TestWorld(object): |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
55 |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
56 def __init__(self): |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
57 self.level_state = {} |
407 | 58 self.inventory = {} |
59 | |
60 | |
61 def distance(tup1, tup2): | |
62 return (tup1[0] - tup2[0]) ** 2 + (tup1[1] - tup2[1]) ** 2 | |
355
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
63 |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
64 |
51 | 65 class EditorLevel(Level): |
66 | |
67 def __init__(self, name, x=800, y=600): | |
355
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
68 world = TestWorld() |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
69 super(EditorLevel, self).__init__(name, world) |
51 | 70 self.x = x |
71 self.y = y | |
275
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
72 # Lookup initiliasition info from the objects |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
73 self.lookup = {} |
407 | 74 self._move_poly = None |
51 | 75 |
439
4c60df80b91b
Don't allow placing points outside the level
Neil Muller <drnlmuller@gmail.com>
parents:
436
diff
changeset
|
76 def _in_bounds(self, pos): |
4c60df80b91b
Don't allow placing points outside the level
Neil Muller <drnlmuller@gmail.com>
parents:
436
diff
changeset
|
77 if pos[0] < 0 or pos[0] >= self.x: |
4c60df80b91b
Don't allow placing points outside the level
Neil Muller <drnlmuller@gmail.com>
parents:
436
diff
changeset
|
78 return False |
4c60df80b91b
Don't allow placing points outside the level
Neil Muller <drnlmuller@gmail.com>
parents:
436
diff
changeset
|
79 if pos[1] < 0 or pos[1] >= self.y: |
4c60df80b91b
Don't allow placing points outside the level
Neil Muller <drnlmuller@gmail.com>
parents:
436
diff
changeset
|
80 return False |
4c60df80b91b
Don't allow placing points outside the level
Neil Muller <drnlmuller@gmail.com>
parents:
436
diff
changeset
|
81 return True |
4c60df80b91b
Don't allow placing points outside the level
Neil Muller <drnlmuller@gmail.com>
parents:
436
diff
changeset
|
82 |
275
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
83 def load(self, space): |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
84 super(EditorLevel, self).load(space) |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
85 # Needed to fill in the lookup dict |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
86 self.reset_objs() |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
87 |
51 | 88 def point_to_pymunk(self, pos): |
89 # inverse of point_to_pygame | |
90 # (this is also the same as point_to_pygame, but a additional | |
91 # function for sanity later in pyweek). | |
92 return (pos[0], self.y - pos[1]) | |
93 | |
94 def add_point(self, poly_index, pos): | |
95 self.polygons.setdefault(poly_index, []) | |
439
4c60df80b91b
Don't allow placing points outside the level
Neil Muller <drnlmuller@gmail.com>
parents:
436
diff
changeset
|
96 if not self._in_bounds(pos): |
4c60df80b91b
Don't allow placing points outside the level
Neil Muller <drnlmuller@gmail.com>
parents:
436
diff
changeset
|
97 return False |
51 | 98 if not self.polygons[poly_index]: |
424 | 99 point = self.point_to_pymunk(pos) |
99 | 100 self.polygons[poly_index].append(point) |
51 | 101 else: |
424 | 102 add_pos = self.point_to_pymunk(pos) |
51 | 103 self.polygons[poly_index].append(add_pos) |
439
4c60df80b91b
Don't allow placing points outside the level
Neil Muller <drnlmuller@gmail.com>
parents:
436
diff
changeset
|
104 return True |
51 | 105 |
106 def delete_point(self, index): | |
107 if index in self.polygons and len(self.polygons[index]) > 0: | |
108 self.polygons[index].pop() | |
109 | |
135
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
110 def close_poly(self, index): |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
111 """Attempts to close the current polygon. |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
112 |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
113 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
|
114 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
|
115 if len(self.polygons[index]) < 2: |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
116 # Too small |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
117 return False |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
118 first = self.polygons[index][0] |
439
4c60df80b91b
Don't allow placing points outside the level
Neil Muller <drnlmuller@gmail.com>
parents:
436
diff
changeset
|
119 if self.add_point(index, self.point_to_pygame(first)): |
4c60df80b91b
Don't allow placing points outside the level
Neil Muller <drnlmuller@gmail.com>
parents:
436
diff
changeset
|
120 return True |
4c60df80b91b
Don't allow placing points outside the level
Neil Muller <drnlmuller@gmail.com>
parents:
436
diff
changeset
|
121 return False |
135
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
122 |
205
51f979ddddbb
Munge in interior wall drawing
Neil Muller <drnlmuller@gmail.com>
parents:
204
diff
changeset
|
123 def add_line(self, start_pos, end_pos): |
424 | 124 startpoint = self.point_to_pymunk(start_pos) |
125 endpoint = self.point_to_pymunk(end_pos) | |
205
51f979ddddbb
Munge in interior wall drawing
Neil Muller <drnlmuller@gmail.com>
parents:
204
diff
changeset
|
126 self.lines.append([startpoint, endpoint]) |
51f979ddddbb
Munge in interior wall drawing
Neil Muller <drnlmuller@gmail.com>
parents:
204
diff
changeset
|
127 |
407 | 128 def draw(self, mouse_pos, mouse_poly, filled, draw_cand_line, start_pos, |
452
9ae08939fd90
Hack to fix call to snap_to_grid from EditLevel
Neil Muller <drnlmuller@gmail.com>
parents:
450
diff
changeset
|
129 move_point_mode, move_point, zoom_factor, level_widget): |
51 | 130 self._draw_background(True) |
131 # Draw polygons as needed for the editor | |
436
7079c3214d72
Scale lines when we zoom out
Neil Muller <drnlmuller@gmail.com>
parents:
435
diff
changeset
|
132 line_width = int(2 * zoom_factor) |
96
a9b564c38bef
Support showing exterior filled view in the editor
Neil Muller <drnlmuller@gmail.com>
parents:
72
diff
changeset
|
133 if filled: |
a9b564c38bef
Support showing exterior filled view in the editor
Neil Muller <drnlmuller@gmail.com>
parents:
72
diff
changeset
|
134 self._draw_exterior(True) |
51 | 135 for index, polygon in self.polygons.items(): |
425 | 136 color = POLY_COLORS.get(index, pygame.color.THECOLORS['black']) |
407 | 137 if move_point_mode and index == self._move_poly: |
138 pointlist = [p for p in polygon] | |
139 pointlist = [self.point_to_pygame(p) if p != move_point else | |
140 mouse_pos for p in pointlist] | |
436
7079c3214d72
Scale lines when we zoom out
Neil Muller <drnlmuller@gmail.com>
parents:
435
diff
changeset
|
141 pygame.draw.lines(self._surface, color, False, pointlist, |
7079c3214d72
Scale lines when we zoom out
Neil Muller <drnlmuller@gmail.com>
parents:
435
diff
changeset
|
142 line_width) |
411 | 143 break |
144 if len(polygon) > 1: | |
51 | 145 pointlist = [self.point_to_pygame(p) for p in polygon] |
436
7079c3214d72
Scale lines when we zoom out
Neil Muller <drnlmuller@gmail.com>
parents:
435
diff
changeset
|
146 pygame.draw.lines(self._surface, color, False, pointlist, |
7079c3214d72
Scale lines when we zoom out
Neil Muller <drnlmuller@gmail.com>
parents:
435
diff
changeset
|
147 line_width) |
411 | 148 if index == mouse_poly and mouse_pos: |
424 | 149 endpoint = self.point_to_pymunk(mouse_pos) |
51 | 150 pygame.draw.line(self._surface, color, |
99 | 151 self.point_to_pygame(polygon[-1]), |
441 | 152 self.point_to_pygame(endpoint), |
153 line_width // 2) | |
407 | 154 line_found = False # Hack for sane behaviour if lines overlap |
204
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
155 for line in self.lines: |
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
156 pointlist = [self.point_to_pygame(p) for p in line] |
407 | 157 if move_point_mode and not self._move_poly and not line_found: |
158 if move_point in line: | |
159 line_found = True | |
160 pointlist.remove(self.point_to_pygame(move_point)) | |
161 pointlist.append(mouse_pos) | |
436
7079c3214d72
Scale lines when we zoom out
Neil Muller <drnlmuller@gmail.com>
parents:
435
diff
changeset
|
162 pygame.draw.lines(self._surface, LINE_COLOR, False, pointlist, |
7079c3214d72
Scale lines when we zoom out
Neil Muller <drnlmuller@gmail.com>
parents:
435
diff
changeset
|
163 line_width) |
205
51f979ddddbb
Munge in interior wall drawing
Neil Muller <drnlmuller@gmail.com>
parents:
204
diff
changeset
|
164 if draw_cand_line and start_pos and mouse_pos: |
452
9ae08939fd90
Hack to fix call to snap_to_grid from EditLevel
Neil Muller <drnlmuller@gmail.com>
parents:
450
diff
changeset
|
165 endpoint = level_widget.snap_to_grid(mouse_pos) |
457
fcf9f6edf153
Use right cordinates for interior walls
Neil Muller <drnlmuller@gmail.com>
parents:
452
diff
changeset
|
166 endpoint = self.point_to_pymunk(endpoint) |
424 | 167 pointlist = [start_pos, |
206 | 168 self.point_to_pygame(endpoint)] |
205
51f979ddddbb
Munge in interior wall drawing
Neil Muller <drnlmuller@gmail.com>
parents:
204
diff
changeset
|
169 pygame.draw.lines(self._surface, LINE_COLOR, False, pointlist, 1) |
432 | 170 return self._surface |
51 | 171 |
239 | 172 def reset_objs(self): |
173 # Reset the object state - needed when changing stuff | |
174 self.drawables = [] | |
175 self.overlay_drawables = [] | |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
176 self._glue = np.PuzzleGlue() |
239 | 177 for game_object_dict in self._game_objects: |
275
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
178 obj = self._create_game_object(pymunk.Space(), **game_object_dict) |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
179 self.lookup[obj] = game_object_dict |
239 | 180 for enemy_dict in self._enemies: |
275
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
181 obj = self._create_enemy(pymunk.Space(), **enemy_dict) |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
182 self.lookup[obj] = enemy_dict |
239 | 183 |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
184 def get_class(self, classname, mod=None): |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
185 # Get the class given the classname |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
186 modules = { |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
187 'game_object': ngo, |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
188 'enemies': ne, |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
189 'puzzle': np, |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
190 } |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
191 if '.' in classname: |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
192 modname, classname = classname.split('.') |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
193 mod = modules[modname] |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
194 if mod is None: |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
195 mod = ngo |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
196 return getattr(mod, classname) |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
197 |
262
521f73061872
Better reporting of object errors. Fix incorrect assumption about ordering
Neil Muller <drnlmuller@gmail.com>
parents:
255
diff
changeset
|
198 def try_new_object(self, classname, target, new, old=None): |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
199 if old in target: |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
200 target.remove(old) |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
201 try: |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
202 target.append(new) |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
203 self.reset_objs() |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
204 return True |
262
521f73061872
Better reporting of object errors. Fix incorrect assumption about ordering
Neil Muller <drnlmuller@gmail.com>
parents:
255
diff
changeset
|
205 except Exception as e: |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
206 target.remove(new) |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
207 if old is not None: |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
208 target.append(old) |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
209 self.reset_objs() |
262
521f73061872
Better reporting of object errors. Fix incorrect assumption about ordering
Neil Muller <drnlmuller@gmail.com>
parents:
255
diff
changeset
|
210 alert("Failed to update object %s: %s" % (classname, e)) |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
211 return False |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
212 |
275
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
213 def find_obj_at_pos(self, mouse_pos): |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
214 pymunk_pos = self.point_to_pymunk(mouse_pos) |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
215 # Search visible objects |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
216 for obj in self.drawables: |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
217 if obj.get_shape().point_query(pymunk_pos): |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
218 return obj |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
219 return None |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
220 |
407 | 221 def find_vertex(self, mouse_pos): |
222 # search for vertexes closest to where we've killed | |
223 mindist = 400 | |
224 move_point = None | |
225 search_point = self.point_to_pymunk(mouse_pos) | |
226 for index, polygon in self.polygons.items(): | |
227 for point in polygon: | |
228 dist = distance(point, search_point) | |
229 if dist < mindist: | |
230 mindist = dist | |
231 move_point = point | |
232 self._move_poly = index | |
233 # Also check lines | |
234 for line in self.lines: | |
235 for point in line: | |
236 dist = distance(point, search_point) | |
237 if dist < mindist: | |
238 mindist = dist | |
239 move_point = point | |
240 self._move_poly = None | |
241 return move_point | |
242 | |
243 def replace_vertex(self, old_point, new_point): | |
244 new_point = self.point_to_pymunk(new_point) | |
245 if self._move_poly: | |
246 new_polygon = [p if p != old_point else new_point for p in | |
247 self.polygons[self._move_poly]] | |
248 self.polygons[self._move_poly] = new_polygon | |
249 else: | |
250 for line in self.lines: | |
251 if old_point in line: | |
252 line.remove(old_point) | |
253 line.append(new_point) | |
254 break | |
255 | |
109
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
256 |
225
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
257 class ObjectTable(TableView): |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
258 |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
259 columns = [TableColumn("Object", 690, 'l', '%r')] |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
260 |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
261 def __init__(self, data): |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
262 super(ObjectTable, self).__init__(height=450) |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
263 self.data = data |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
264 self.selected_row = -1 |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
265 |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
266 def num_rows(self): |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
267 return len(self.data) |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
268 |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
269 def row_data(self, i): |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
270 data = self.data[i] |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
271 if 'name' in data: |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
272 return ('%s (%s)' % (data['classname'], data['name']), ) |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
273 return (data['classname'], ) |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
274 |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
275 def row_is_selected(self, i): |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
276 return self.selected_row == i |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
277 |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
278 def click_row(self, i, ev): |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
279 self.selected_row = i |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
280 |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
281 def get_selection(self): |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
282 if self.selected_row >= 0: |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
283 return self.data[self.selected_row] |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
284 return None |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
285 |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
286 |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
287 class EditClassDialog(Dialog): |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
288 |
355
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
289 def __init__(self, classname, cls, data, level_widget, |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
290 delete=False): |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
291 super(EditClassDialog, self).__init__() |
355
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
292 self.level_widget = level_widget |
255 | 293 self.classname = classname |
355
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
294 self.rect = pygame.rect.Rect(0, 0, 900, 550) |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
295 title = Label("Editing %s" % classname) |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
296 title.rect = pygame.rect.Rect(100, 10, 600, 25) |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
297 self.add(title) |
262
521f73061872
Better reporting of object errors. Fix incorrect assumption about ordering
Neil Muller <drnlmuller@gmail.com>
parents:
255
diff
changeset
|
298 self.requires = cls.requires() |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
299 y = 40 |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
300 self.fields = {} |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
301 index = 0 |
355
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
302 self.poly_field = None |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
303 self.needs_cleanup = False |
262
521f73061872
Better reporting of object errors. Fix incorrect assumption about ordering
Neil Muller <drnlmuller@gmail.com>
parents:
255
diff
changeset
|
304 for requirement, hint in self.requires: |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
305 label = Label(requirement) |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
306 label.rect = pygame.rect.Rect(40, y, 200, 25) |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
307 self.add(label) |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
308 field = TextField() |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
309 field.rect = pygame.rect.Rect(220, y, 400, 25) |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
310 self.add(field) |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
311 if data is not None: |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
312 if requirement in data: |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
313 field.set_text('%s' % data[requirement]) |
255 | 314 elif 'args' in data and requirement != 'name': |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
315 # NB: The ordering assumptions in requires should make |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
316 # this safe, but it's really, really, really fragile |
255 | 317 try: |
318 field.set_text('%s' % data['args'][index]) | |
319 index += 1 | |
320 except IndexError: | |
321 # Assumed to be arguments with the default value | |
322 pass | |
355
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
323 if hint.startswith('polygon'): |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
324 self.poly_field = field |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
325 self.fields[requirement] = field |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
326 hintlabel = Label(hint) |
355
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
327 hintlabel.rect = pygame.rect.Rect(640, y, 250, 25) |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
328 self.add(hintlabel) |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
329 y += 30 |
355
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
330 if self.poly_field: |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
331 y += 20 |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
332 button = Button('Use Polygon 6', action=self.get_poly) |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
333 button.rect = pygame.rect.Rect(350, y, 250, 30) |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
334 self.add(button) |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
335 buttons = [] |
275
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
336 if delete: |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
337 labels = ['OK', 'Delete', 'Cancel'] |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
338 else: |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
339 labels = ['OK', 'Cancel'] |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
340 for text in labels: |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
341 but = Button(text, action=lambda x=text: self.dismiss(x)) |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
342 buttons.append(but) |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
343 row = Row(buttons) |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
344 row.rect = pygame.rect.Rect(250, 500, 700, 50) |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
345 self.add(row) |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
346 |
355
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
347 def get_poly(self): |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
348 try: |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
349 data = self.level_widget.level.polygons[6][:] |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
350 except KeyError: |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
351 data = [] |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
352 if data: |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
353 # We unclose the polygon, because that's what pymunk |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
354 # wants |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
355 if data[0] == data[-1] and len(data) > 1: |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
356 data.pop() |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
357 data = [list(x) for x in data] |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
358 self.needs_cleanup = True |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
359 self.poly_field.set_text('%s' % data) |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
360 |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
361 def cleanup(self): |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
362 if self.needs_cleanup: |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
363 self.level_widget.level.polygons[6] = [] |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
364 self.level_widget.invalidate() |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
365 |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
366 def get_data(self): |
255 | 367 result = {} |
368 result['classname'] = self.classname | |
369 args = [] | |
370 # We arrange to bounce this through yaml'ish to convert | |
371 # stuff to the expected type | |
262
521f73061872
Better reporting of object errors. Fix incorrect assumption about ordering
Neil Muller <drnlmuller@gmail.com>
parents:
255
diff
changeset
|
372 for val, _ in self.requires: |
255 | 373 text = self.fields[val].get_text() |
374 if not text: | |
375 # skip empty fields | |
376 continue | |
377 if val == 'name': | |
378 result['name'] = text | |
355
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
379 elif self.fields[val] == self.poly_field and text: |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
380 # Evil, but faster than good |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
381 try: |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
382 l = eval(text) |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
383 except Exception: |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
384 alert("Invalid polygon %s" % text) |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
385 self.needs_cleanup = False |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
386 return None |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
387 # Check for convexity |
449
a99e5e724545
Better convex polygon protection
Neil Muller <drnlmuller@gmail.com>
parents:
441
diff
changeset
|
388 if not pymunk.util.is_convex(l): |
355
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
389 alert("Invalid polygon %s - not convex" % text) |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
390 return None |
449
a99e5e724545
Better convex polygon protection
Neil Muller <drnlmuller@gmail.com>
parents:
441
diff
changeset
|
391 if not pymunk.util.is_clockwise(l): |
a99e5e724545
Better convex polygon protection
Neil Muller <drnlmuller@gmail.com>
parents:
441
diff
changeset
|
392 l.reverse() |
a99e5e724545
Better convex polygon protection
Neil Muller <drnlmuller@gmail.com>
parents:
441
diff
changeset
|
393 if not pymunk.util.is_clockwise(l): |
a99e5e724545
Better convex polygon protection
Neil Muller <drnlmuller@gmail.com>
parents:
441
diff
changeset
|
394 alert("Invalid polygon %s - unable to make clockwise" |
a99e5e724545
Better convex polygon protection
Neil Muller <drnlmuller@gmail.com>
parents:
441
diff
changeset
|
395 % text) |
a99e5e724545
Better convex polygon protection
Neil Muller <drnlmuller@gmail.com>
parents:
441
diff
changeset
|
396 return None |
a99e5e724545
Better convex polygon protection
Neil Muller <drnlmuller@gmail.com>
parents:
441
diff
changeset
|
397 args.append(' - - %s' % l[0]) |
a99e5e724545
Better convex polygon protection
Neil Muller <drnlmuller@gmail.com>
parents:
441
diff
changeset
|
398 for coord in l[1:]: |
a99e5e724545
Better convex polygon protection
Neil Muller <drnlmuller@gmail.com>
parents:
441
diff
changeset
|
399 args.append(' - %s' % coord) |
255 | 400 else: |
401 args.append(' - ' + text) | |
402 data = "args:\n" + '\n'.join(args) | |
403 result['args'] = load_s(data)['args'] | |
404 return result | |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
405 |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
406 |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
407 class LevelWidget(Widget): |
51 | 408 |
280 | 409 def __init__(self, level, parent): |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
410 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
|
411 SCREEN[0], SCREEN[1])) |
51 | 412 self.level = level |
413 self.pos = (0, 0) | |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
414 self.filled_mode = False |
51 | 415 self.mouse_pos = None |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
416 self.cur_poly = None |
167
bb297f3f99f4
Allow using right mouse button to drag level display
Neil Muller <drnlmuller@gmail.com>
parents:
166
diff
changeset
|
417 self._mouse_drag = False |
199
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
418 self._draw_objects = False |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
419 self._draw_enemies = False |
204
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
420 self._draw_lines = False |
419 | 421 self.grid_size = 1 |
275
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
422 self.sel_mode = False |
205
51f979ddddbb
Munge in interior wall drawing
Neil Muller <drnlmuller@gmail.com>
parents:
204
diff
changeset
|
423 self._start_pos = None |
280 | 424 self._parent = parent |
407 | 425 self._move_point_mode = False |
426 self._move_point = False | |
413 | 427 self._zoom_factor = 1.0 |
51 | 428 |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
429 def _level_coordinates(self, pos): |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
430 # Move positions to level values |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
431 if not pos: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
432 return (0, 0) |
413 | 433 # Apply zoom_factor |
450
fe6546d07d5e
Combine zoom and offset more correctly
Neil Muller <drnlmuller@gmail.com>
parents:
449
diff
changeset
|
434 pos = pos[0] + self.pos[0], pos[1] + self.pos[1] |
413 | 435 zoomed = (pos[0] * self._zoom_factor, pos[1] * self._zoom_factor) |
450
fe6546d07d5e
Combine zoom and offset more correctly
Neil Muller <drnlmuller@gmail.com>
parents:
449
diff
changeset
|
436 return int(zoomed[0]), int(zoomed[1]) |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
437 |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
438 def _move_view(self, offset): |
51 | 439 new_pos = [self.pos[0] + offset[0], self.pos[1] + offset[1]] |
440 if new_pos[0] < 0: | |
441 new_pos[0] = self.pos[0] | |
442 elif new_pos[0] > self.level.x - SCREEN[0]: | |
443 new_pos[0] = self.pos[0] | |
444 if new_pos[1] < 0: | |
445 new_pos[1] = self.pos[1] | |
446 elif new_pos[1] > self.level.y - SCREEN[1]: | |
447 new_pos[1] = self.pos[1] | |
448 self.pos = tuple(new_pos) | |
449 | |
419 | 450 def inc_grid_size(self, amount): |
451 self.grid_size = max(1, self.grid_size + amount) | |
426 | 452 if self.grid_size > 1: |
453 self.grid_size = self.grid_size - (self.grid_size % 5) | |
419 | 454 |
424 | 455 def snap_to_grid(self, pos): |
456 x = pos[0] - (pos[0] % self.grid_size) | |
457 y = pos[1] - (pos[1] % self.grid_size) | |
458 return (x, y) | |
459 | |
199
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
460 def set_objects(self, value): |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
461 if self._draw_objects != value: |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
462 self._draw_objects = value |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
463 self.invalidate() |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
464 |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
465 def set_enemies(self, value): |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
466 if self._draw_enemies != value: |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
467 self._draw_enemies = value |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
468 self.invalidate() |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
469 |
413 | 470 def zoom_out(self): |
471 self._zoom_factor = self._zoom_factor * 2.0 | |
472 if self._zoom_factor > 8: | |
473 self._zoom_factor = 8 | |
474 | |
475 def zoom_in(self): | |
476 self._zoom_factor = self._zoom_factor // 2.0 | |
477 if self._zoom_factor < 1: | |
478 self._zoom_factor = 1 | |
479 | |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
480 def draw(self, surface): |
51 | 481 if (self.cur_poly is not None and self.cur_poly in self.level.polygons |
482 and len(self.level.polygons[self.cur_poly])): | |
483 # We have an active polygon | |
484 mouse_pos = self._level_coordinates(self.mouse_pos) | |
424 | 485 mouse_pos = self.snap_to_grid(mouse_pos) |
205
51f979ddddbb
Munge in interior wall drawing
Neil Muller <drnlmuller@gmail.com>
parents:
204
diff
changeset
|
486 elif self._draw_lines: |
51f979ddddbb
Munge in interior wall drawing
Neil Muller <drnlmuller@gmail.com>
parents:
204
diff
changeset
|
487 # Interior wall mode |
51f979ddddbb
Munge in interior wall drawing
Neil Muller <drnlmuller@gmail.com>
parents:
204
diff
changeset
|
488 mouse_pos = self._level_coordinates(self.mouse_pos) |
424 | 489 mouse_pos = self.snap_to_grid(mouse_pos) |
407 | 490 elif self._move_point_mode: |
491 mouse_pos = self._level_coordinates(self.mouse_pos) | |
424 | 492 mouse_pos = self.snap_to_grid(mouse_pos) |
51 | 493 else: |
494 mouse_pos = None | |
205
51f979ddddbb
Munge in interior wall drawing
Neil Muller <drnlmuller@gmail.com>
parents:
204
diff
changeset
|
495 level_surface = level.draw(mouse_pos, self.cur_poly, self.filled_mode, |
407 | 496 self._draw_lines, self._start_pos, |
436
7079c3214d72
Scale lines when we zoom out
Neil Muller <drnlmuller@gmail.com>
parents:
435
diff
changeset
|
497 self._move_point_mode, self._move_point, |
452
9ae08939fd90
Hack to fix call to snap_to_grid from EditLevel
Neil Muller <drnlmuller@gmail.com>
parents:
450
diff
changeset
|
498 self._zoom_factor, self) |
199
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
499 if self._draw_objects: |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
500 for thing in self.level.drawables: |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
501 if not isinstance(thing, ne.Enemy): |
199
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
502 thing.render(level_surface) |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
503 if self._draw_enemies: |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
504 for thing in self.level.drawables: |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
505 if isinstance(thing, ne.Enemy): |
199
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
506 thing.render(level_surface) |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
507 surface_area = pygame.rect.Rect(self.pos, SCREEN) |
413 | 508 zoomed_surface = level_surface.copy() |
432 | 509 if self._zoom_factor != 1: |
510 zoomed_surface = pygame.transform.scale( | |
511 level_surface, | |
433 | 512 (int(level_surface.get_width() / self._zoom_factor), |
513 int(level_surface.get_height() / self._zoom_factor))) | |
413 | 514 surface.blit(zoomed_surface, (0, 0), surface_area) |
51 | 515 |
115 | 516 def change_poly(self, new_poly): |
517 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
|
518 self._draw_lines = False |
115 | 519 if self.cur_poly is not None: |
280 | 520 self._parent.reset_lit_buttons() |
115 | 521 self.filled_mode = False |
522 | |
204
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
523 def line_mode(self): |
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
524 self.cur_poly = None |
280 | 525 self._parent.reset_lit_buttons() |
204
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
526 self._draw_lines = True |
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
527 self.filled_mode = False |
205
51f979ddddbb
Munge in interior wall drawing
Neil Muller <drnlmuller@gmail.com>
parents:
204
diff
changeset
|
528 self._start_pos = None |
407 | 529 self._move_point_mode = False |
204
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
530 |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
531 def key_down(self, ev): |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
532 if ev.key == pgl.K_LEFT: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
533 self._move_view((-10, 0)) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
534 elif ev.key == pgl.K_RIGHT: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
535 self._move_view((10, 0)) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
536 elif ev.key == pgl.K_UP: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
537 self._move_view((0, -10)) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
538 elif ev.key == pgl.K_DOWN: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
539 self._move_view((0, 10)) |
115 | 540 elif ev.key in (pgl.K_1, pgl.K_2, pgl.K_3, pgl.K_4, pgl.K_5, pgl.K_6): |
541 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
|
542 elif ev.key == pgl.K_0: |
115 | 543 self.change_poly(None) |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
544 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
|
545 self.level.delete_point(self.cur_poly) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
546 elif ev.key == pgl.K_f: |
117 | 547 self.set_filled() |
135
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
548 elif ev.key == pgl.K_c: |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
549 self.close_poly() |
117 | 550 |
407 | 551 def set_move_mode(self): |
552 self._draw_lines = False | |
553 self._move_point_mode = True | |
554 self.filled_mode = False | |
555 self._parent.reset_lit_buttons() | |
556 self._move_point = None | |
557 | |
117 | 558 def set_filled(self): |
165
dba8bc454a43
Fix 'fill exterior' button
Neil Muller <drnlmuller@gmail.com>
parents:
157
diff
changeset
|
559 closed, _ = self.level.all_closed() |
dba8bc454a43
Fix 'fill exterior' button
Neil Muller <drnlmuller@gmail.com>
parents:
157
diff
changeset
|
560 if closed: |
117 | 561 self.cur_poly = None |
280 | 562 self._parent.reset_lit_buttons() |
117 | 563 self.filled_mode = True |
204
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
564 self._draw_lines = False |
407 | 565 self._move_point_mode = False |
117 | 566 else: |
165
dba8bc454a43
Fix 'fill exterior' button
Neil Muller <drnlmuller@gmail.com>
parents:
157
diff
changeset
|
567 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
|
568 |
109
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
569 def mouse_move(self, ev): |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
570 old_pos = self.mouse_pos |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
571 self.mouse_pos = ev.pos |
407 | 572 if old_pos != self.mouse_pos and (self.cur_poly or self._draw_lines |
421 | 573 or self._move_point_mode): |
109
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
574 self.invalidate() |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
575 |
167
bb297f3f99f4
Allow using right mouse button to drag level display
Neil Muller <drnlmuller@gmail.com>
parents:
166
diff
changeset
|
576 def mouse_drag(self, ev): |
bb297f3f99f4
Allow using right mouse button to drag level display
Neil Muller <drnlmuller@gmail.com>
parents:
166
diff
changeset
|
577 if self._mouse_drag: |
bb297f3f99f4
Allow using right mouse button to drag level display
Neil Muller <drnlmuller@gmail.com>
parents:
166
diff
changeset
|
578 old_pos = self.mouse_pos |
bb297f3f99f4
Allow using right mouse button to drag level display
Neil Muller <drnlmuller@gmail.com>
parents:
166
diff
changeset
|
579 self.mouse_pos = ev.pos |
bb297f3f99f4
Allow using right mouse button to drag level display
Neil Muller <drnlmuller@gmail.com>
parents:
166
diff
changeset
|
580 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
|
581 -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
|
582 self._move_view(diff) |
bb297f3f99f4
Allow using right mouse button to drag level display
Neil Muller <drnlmuller@gmail.com>
parents:
166
diff
changeset
|
583 self.invalidate() |
bb297f3f99f4
Allow using right mouse button to drag level display
Neil Muller <drnlmuller@gmail.com>
parents:
166
diff
changeset
|
584 |
109
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
585 def mouse_down(self, ev): |
414 | 586 corrected_pos = self._level_coordinates(ev.pos) |
424 | 587 snapped_pos = self.snap_to_grid(corrected_pos) |
275
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
588 if self.sel_mode and ev.button == 1: |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
589 obj = self.level.find_obj_at_pos(corrected_pos) |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
590 if obj is not None: |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
591 self._edit_selected(obj) |
407 | 592 elif self._move_point_mode and ev.button == 1: |
593 if self._move_point: | |
594 # Place the current point | |
424 | 595 self.level.replace_vertex(self._move_point, snapped_pos) |
407 | 596 self._move_point = None |
597 self.invalidate() | |
598 else: | |
599 # find the current point | |
424 | 600 self._move_point = self.level.find_vertex(snapped_pos) |
275
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
601 elif ev.button == 1: |
204
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
602 if self._draw_lines: |
205
51f979ddddbb
Munge in interior wall drawing
Neil Muller <drnlmuller@gmail.com>
parents:
204
diff
changeset
|
603 if self._start_pos is None: |
414 | 604 self._start_pos = corrected_pos |
205
51f979ddddbb
Munge in interior wall drawing
Neil Muller <drnlmuller@gmail.com>
parents:
204
diff
changeset
|
605 else: |
424 | 606 self.level.add_line(self._start_pos, snapped_pos) |
205
51f979ddddbb
Munge in interior wall drawing
Neil Muller <drnlmuller@gmail.com>
parents:
204
diff
changeset
|
607 self._start_pos = None |
204
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
608 else: |
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
609 print "Click: %r" % ( |
414 | 610 self.level.point_to_pymunk(corrected_pos),) |
157 | 611 if ev.button == 4: # Scroll up |
612 self._move_view((0, -10)) | |
613 elif ev.button == 5: # Scroll down | |
614 self._move_view((0, 10)) | |
615 elif ev.button == 6: # Scroll left | |
616 self._move_view((-10, 0)) | |
617 elif ev.button == 7: # Scroll right | |
618 self._move_view((10, 0)) | |
413 | 619 elif self.cur_poly and ev.button == 1: |
620 # Add a point | |
439
4c60df80b91b
Don't allow placing points outside the level
Neil Muller <drnlmuller@gmail.com>
parents:
436
diff
changeset
|
621 if not self.level.add_point(self.cur_poly, snapped_pos): |
4c60df80b91b
Don't allow placing points outside the level
Neil Muller <drnlmuller@gmail.com>
parents:
436
diff
changeset
|
622 alert("Failed to place point") |
167
bb297f3f99f4
Allow using right mouse button to drag level display
Neil Muller <drnlmuller@gmail.com>
parents:
166
diff
changeset
|
623 elif ev.button == 3: |
bb297f3f99f4
Allow using right mouse button to drag level display
Neil Muller <drnlmuller@gmail.com>
parents:
166
diff
changeset
|
624 self._mouse_drag = True |
bb297f3f99f4
Allow using right mouse button to drag level display
Neil Muller <drnlmuller@gmail.com>
parents:
166
diff
changeset
|
625 |
bb297f3f99f4
Allow using right mouse button to drag level display
Neil Muller <drnlmuller@gmail.com>
parents:
166
diff
changeset
|
626 def mouse_up(self, ev): |
bb297f3f99f4
Allow using right mouse button to drag level display
Neil Muller <drnlmuller@gmail.com>
parents:
166
diff
changeset
|
627 if ev.button == 3: |
bb297f3f99f4
Allow using right mouse button to drag level display
Neil Muller <drnlmuller@gmail.com>
parents:
166
diff
changeset
|
628 self._mouse_drag = False |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
629 |
135
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
630 def close_poly(self): |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
631 if self.cur_poly is None: |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
632 return |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
633 if self.level.close_poly(self.cur_poly): |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
634 alert("Successfully closed the polygon") |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
635 self.change_poly(None) |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
636 else: |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
637 alert("Failed to close the polygon") |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
638 |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
639 def _edit_class(self, classname, cls, data): |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
640 # Dialog for class properties |
355
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
641 dialog = EditClassDialog(classname, cls, data, self) |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
642 if dialog.present() == 'OK': |
355
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
643 return dialog |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
644 return None |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
645 |
275
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
646 def _edit_selected(self, obj): |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
647 data = self.level.lookup[obj] |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
648 cls = obj.__class__ |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
649 classname = obj.__class__.__name__ |
355
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
650 dialog = EditClassDialog(classname, cls, data, self, True) |
275
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
651 res = dialog.present() |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
652 if res == 'OK': |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
653 edited = dialog.get_data() |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
654 if edited is not None: |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
655 for target in [self.level._game_objects, self.level._enemies]: |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
656 if data in target: |
355
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
657 if self.level.try_new_object(classname, target, |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
658 edited, data): |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
659 dialog.cleanup() |
275
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
660 break |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
661 elif res == 'Delete': |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
662 for target in [self.level._game_objects, self.level._enemies]: |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
663 if data in target: |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
664 target.remove(data) |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
665 self.level.reset_objs() |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
666 break |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
667 |
225
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
668 def _make_edit_dialog(self, entries): |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
669 # Dialog to hold the editor |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
670 edit_box = Dialog() |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
671 edit_box.rect = pygame.rect.Rect(0, 0, 700, 500) |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
672 table = ObjectTable(entries) |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
673 edit_box.add(table) |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
674 buttons = [] |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
675 for text in ['OK', 'Delete', 'Cancel']: |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
676 but = Button(text, action=lambda x=text: edit_box.dismiss(x)) |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
677 buttons.append(but) |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
678 row = Row(buttons) |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
679 row.rect = pygame.rect.Rect(250, 450, 700, 50) |
225
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
680 edit_box.add(row) |
236
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
681 edit_box.get_selection = lambda: table.get_selection() |
225
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
682 return edit_box |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
683 |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
684 def edit_objects(self): |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
685 edit_box = self._make_edit_dialog(self.level._game_objects) |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
686 res = edit_box.present() |
236
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
687 choice = edit_box.get_selection() |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
688 if choice is None: |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
689 return |
225
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
690 if res == 'OK': |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
691 cls = self.level.get_class(choice['classname']) |
355
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
692 edit_dlg = self._edit_class(choice['classname'], cls, choice) |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
693 if edit_dlg is not None: |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
694 edited = edit_dlg.get_data() |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
695 if self.level.try_new_object(choice["classname"], |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
696 self.level._game_objects, |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
697 edited, choice): |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
698 edit_dlg.cleanup() |
225
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
699 elif res == 'Delete': |
239 | 700 self.level._game_objects.remove(choice) |
701 self.level.reset_objs() | |
225
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
702 |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
703 def edit_enemies(self): |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
704 edit_box = self._make_edit_dialog(self.level._enemies) |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
705 res = edit_box.present() |
236
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
706 choice = edit_box.get_selection() |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
707 if choice is None: |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
708 return |
225
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
709 if res == 'OK': |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
710 cls = self.level.get_class(choice['classname'], ne) |
355
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
711 edit_dlg = self._edit_class(choice['classname'], cls, choice) |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
712 if edit_dlg is not None: |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
713 edited = edit_dlg.get_data() |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
714 if self.level.try_new_object(choice["classname"], |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
715 self.level._enemies, |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
716 edited, choice): |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
717 edit_dlg.cleanup() |
225
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
718 elif res == 'Delete': |
239 | 719 self.level._enemies.remove(choice) |
720 self.level.reset_objs() | |
225
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
721 |
236
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
722 def _make_choice_dialog(self, classes): |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
723 # Dialog to hold the editor |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
724 data = [] |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
725 for cls_name, cls in classes: |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
726 data.append({"classname": cls_name, "class": cls}) |
239 | 727 choice_box = Dialog() |
728 choice_box.rect = pygame.rect.Rect(0, 0, 700, 500) | |
236
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
729 table = ObjectTable(data) |
239 | 730 choice_box.add(table) |
236
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
731 buttons = [] |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
732 for text in ['OK', 'Cancel']: |
239 | 733 but = Button(text, action=lambda x=text: choice_box.dismiss(x)) |
236
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
734 buttons.append(but) |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
735 row = Row(buttons) |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
736 row.rect = pygame.rect.Rect(250, 450, 700, 50) |
239 | 737 choice_box.add(row) |
738 choice_box.get_selection = lambda: table.get_selection() | |
739 return choice_box | |
236
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
740 |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
741 def add_game_object(self): |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
742 classes = ngo.get_editable_game_objects() |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
743 choose = self._make_choice_dialog(classes) |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
744 res = choose.present() |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
745 choice = choose.get_selection() |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
746 if res == 'OK' and choice is not None: |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
747 classname = choice['classname'] |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
748 cls = choice['class'] |
355
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
749 edit_dlg = self._edit_class(classname, cls, None) |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
750 if edit_dlg is not None: |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
751 new_cls = edit_dlg.get_data() |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
752 if self.level.try_new_object(classname, |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
753 self.level._game_objects, |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
754 new_cls, None): |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
755 edit_dlg.cleanup() |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
756 |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
757 def add_enemy(self): |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
758 classes = ne.get_editable_enemies() |
236
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
759 choose = self._make_choice_dialog(classes) |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
760 res = choose.present() |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
761 choice = choose.get_selection() |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
762 if res == 'OK' and choice is not None: |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
763 classname = choice['classname'] |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
764 cls = choice['class'] |
355
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
765 edit_dlg = self._edit_class(classname, cls, None) |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
766 if edit_dlg is not None: |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
767 new_cls = edit_dlg.get_data() |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
768 if self.level.try_new_object(classname, self.level._enemies, |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
769 new_cls, None): |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
770 edit_dlg.cleanup() |
236
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
771 |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
772 def add_puzzler(self): |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
773 classes = np.get_editable_puzzlers() |
236
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
774 choose = self._make_choice_dialog(classes) |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
775 res = choose.present() |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
776 choice = choose.get_selection() |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
777 if res == 'OK' and choice is not None: |
251
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
778 classname = choice['classname'] |
611370331bd1
Add framework of edit object dialog
Neil Muller <drnlmuller@gmail.com>
parents:
239
diff
changeset
|
779 cls = choice['class'] |
355
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
780 edit_dlg = self._edit_class(classname, cls, None) |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
781 if edit_dlg is not None: |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
782 new_cls = edit_dlg.get_data() |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
783 if self.level.try_new_object(classname, |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
784 self.level._game_objects, |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
785 new_cls, None): |
9589e1db4433
Allow copying polygon 6 into terrain objects
Neil Muller <drnlmuller@gmail.com>
parents:
330
diff
changeset
|
786 edit_dlg.cleanup() |
236
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
787 |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
788 |
280 | 789 class HighLightButton(Button): |
790 """Button with highlight support""" | |
791 def __init__(self, text, parent, **kwds): | |
792 super(HighLightButton, self).__init__(text, **kwds) | |
793 self._parent = parent | |
794 | |
795 def highlight(self): | |
796 self.border_color = pygame.color.Color('red') | |
797 | |
798 def reset(self): | |
799 self.border_color = self.fg_color | |
800 | |
801 | |
802 class PolyButton(HighLightButton): | |
115 | 803 """Button for coosing the correct polygon""" |
804 | |
280 | 805 def __init__(self, index, level_widget, parent): |
115 | 806 if index is not None: |
807 text = "Draw: %s" % index | |
808 else: | |
809 text = 'Exit Draw Mode' | |
280 | 810 super(PolyButton, self).__init__(text, parent) |
115 | 811 self.index = index |
812 self.level_widget = level_widget | |
813 | |
814 def action(self): | |
815 self.level_widget.change_poly(self.index) | |
280 | 816 self._parent.reset_lit_buttons() |
817 if self.index is not None: | |
818 self.highlight() | |
115 | 819 |
820 | |
419 | 821 class GridSizeLabel(Label): |
822 """Label and setter for grid size.""" | |
823 | |
824 def __init__(self, level_widget, **kwds): | |
825 self.level_widget = level_widget | |
826 super(GridSizeLabel, self).__init__(self.grid_text(), **kwds) | |
827 | |
828 def grid_text(self): | |
829 return "Grid size: %d" % self.level_widget.grid_size | |
830 | |
831 def inc_grid_size(self, amount): | |
832 self.level_widget.inc_grid_size(amount) | |
833 self.set_text(self.grid_text()) | |
834 | |
835 | |
836 class SnapButton(Button): | |
837 """Button for increasing or decreasing snap-to-grid size.""" | |
838 | |
839 def __init__(self, grid_size_label, parent, inc_amount): | |
840 self.grid_size_label = grid_size_label | |
841 self.inc_amount = inc_amount | |
842 text = "Grid %s%d" % ( | |
843 '-' if inc_amount < 0 else '+', | |
844 abs(inc_amount)) | |
845 self._parent = parent | |
846 super(SnapButton, self).__init__(text) | |
847 | |
848 def action(self): | |
849 self.grid_size_label.inc_grid_size(self.inc_amount) | |
850 | |
851 | |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
852 class EditorApp(RootWidget): |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
853 |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
854 def __init__(self, level, surface): |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
855 super(EditorApp, self).__init__(surface) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
856 self.level = level |
280 | 857 self.level_widget = LevelWidget(self.level, self) |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
858 self.add(self.level_widget) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
859 |
220
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
860 self._dMenus = {} |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
861 |
280 | 862 self._light_buttons = [] |
863 | |
220
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
864 self._make_draw_menu() |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
865 self._make_objects_menu() |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
866 |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
867 self._menu_mode = 'drawing' |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
868 self._populate_menu() |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
869 |
413 | 870 self._zoom = 1 |
871 | |
220
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
872 def _make_draw_menu(self): |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
873 widgets = [] |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
874 |
419 | 875 white = pygame.color.Color("white") |
876 | |
115 | 877 # Add poly buttons |
423 | 878 y = 5 |
115 | 879 for poly in range(1, 7): |
280 | 880 but = PolyButton(poly, self.level_widget, self) |
115 | 881 but.rect = pygame.rect.Rect(0, 0, MENU_WIDTH // 2 - MENU_PAD, |
882 MENU_BUTTON_HEIGHT) | |
883 if poly % 2: | |
884 but.rect.move_ip(MENU_LEFT, y) | |
885 else: | |
886 but.rect.move_ip(MENU_LEFT + MENU_WIDTH // 2 - MENU_HALF_PAD, | |
887 y) | |
888 y += MENU_BUTTON_HEIGHT + MENU_PAD | |
280 | 889 self._light_buttons.append(but) |
220
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
890 widgets.append(but) |
198 | 891 |
280 | 892 end_poly_but = PolyButton(None, self.level_widget, self) |
220
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
893 end_poly_but.rect = BUTTON_RECT.copy() |
115 | 894 end_poly_but.rect.move_ip(MENU_LEFT, y) |
220
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
895 widgets.append(end_poly_but) |
115 | 896 y += MENU_BUTTON_HEIGHT + MENU_PAD |
897 | |
407 | 898 self.move_point_but = HighLightButton("Move Point", self, |
899 action=self.move_point) | |
900 self.move_point_but.rect = BUTTON_RECT.copy() | |
901 self.move_point_but.rect.move_ip(MENU_LEFT, y) | |
902 widgets.append(self.move_point_but) | |
903 self._light_buttons.append(self.move_point_but) | |
423 | 904 y += MENU_BUTTON_HEIGHT + MENU_PAD |
419 | 905 |
906 # grid size widgets | |
907 grid_size_label = GridSizeLabel( | |
908 self.level_widget, width=BUTTON_RECT.width, | |
909 align="c", fg_color=white) | |
910 grid_size_label.rect.move_ip(MENU_LEFT, y) | |
911 widgets.append(grid_size_label) | |
912 y += grid_size_label.rect.height + MENU_PAD | |
426 | 913 inc_snap_but = SnapButton(grid_size_label, self, 5) |
419 | 914 inc_snap_but.rect = HALF_BUTTON_RECT.copy() |
915 inc_snap_but.rect.move_ip(MENU_LEFT, y) | |
916 widgets.append(inc_snap_but) | |
426 | 917 dec_snap_but = SnapButton(grid_size_label, self, -5) |
419 | 918 dec_snap_but.rect = HALF_BUTTON_RECT.copy() |
919 dec_snap_but.rect.move_ip( | |
920 MENU_LEFT + MENU_HALF_WIDTH, y) | |
921 widgets.append(dec_snap_but) | |
407 | 922 y += MENU_BUTTON_HEIGHT + MENU_PAD |
923 | |
280 | 924 self.draw_line_but = HighLightButton("Draw interior wall", self, |
925 action=self.set_line_mode) | |
926 self.draw_line_but.rect = BUTTON_RECT.copy() | |
927 self.draw_line_but.rect.move_ip(MENU_LEFT, y) | |
928 widgets.append(self.draw_line_but) | |
929 self._light_buttons.append(self.draw_line_but) | |
204
687459429550
Display interior walls and start working towards drawing them
Neil Muller <drnlmuller@gmail.com>
parents:
199
diff
changeset
|
930 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
|
931 |
117 | 932 fill_but = Button('Fill exterior', action=self.level_widget.set_filled) |
220
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
933 fill_but.rect = BUTTON_RECT.copy() |
117 | 934 fill_but.rect.move_ip(MENU_LEFT, y) |
220
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
935 widgets.append(fill_but) |
117 | 936 y += MENU_BUTTON_HEIGHT + MENU_PAD |
937 | |
135
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
938 close_poly_but = Button('Close Polygon', |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
939 action=self.level_widget.close_poly) |
220
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
940 close_poly_but.rect = BUTTON_RECT.copy() |
135
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
941 close_poly_but.rect.move_ip(MENU_LEFT, y) |
220
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
942 widgets.append(close_poly_but) |
135
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
943 y += MENU_BUTTON_HEIGHT + MENU_PAD |
c9b6685ebebf
Add hack'ish 'close polygon' option
Neil Muller <drnlmuller@gmail.com>
parents:
134
diff
changeset
|
944 |
198 | 945 self.show_objs = CheckBox(fg_color=white) |
220
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
946 self.show_objs.rect = CHECK_RECT.copy() |
198 | 947 self.show_objs.rect.move_ip(MENU_LEFT, y) |
948 label = Label("Show Objects", fg_color=white) | |
949 label.rect.move_ip(MENU_LEFT + MENU_BUTTON_HEIGHT // 2 + MENU_PAD, y) | |
220
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
950 widgets.append(self.show_objs) |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
951 widgets.append(label) |
198 | 952 y += label.rect.height + MENU_PAD |
953 | |
954 self.show_enemies = CheckBox(fg_color=white) | |
220
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
955 self.show_enemies.rect = CHECK_RECT.copy() |
198 | 956 self.show_enemies.rect.move_ip(MENU_LEFT, y) |
957 label = Label("Show enemy start pos", fg_color=white) | |
958 label.rect.move_ip(MENU_LEFT + MENU_BUTTON_HEIGHT // 2 + MENU_PAD, y) | |
220
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
959 widgets.append(self.show_enemies) |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
960 widgets.append(label) |
198 | 961 y += label.rect.height + MENU_PAD |
962 | |
236
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
963 y += MENU_PAD |
220
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
964 switch_but = Button('Switch to Objects', action=self.switch_to_objects) |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
965 switch_but.rect = BUTTON_RECT.copy() |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
966 switch_but.rect.move_ip(MENU_LEFT, y) |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
967 widgets.append(switch_but) |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
968 y += switch_but.rect.height + MENU_PAD |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
969 |
236
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
970 save_but = Button('Save Level', action=self.save) |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
971 save_but.rect = BUTTON_RECT.copy() |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
972 save_but.rect.move_ip(MENU_LEFT, y) |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
973 widgets.append(save_but) |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
974 y += MENU_BUTTON_HEIGHT + MENU_PAD |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
975 |
413 | 976 zoom_out = Button('Zoom out', action=self.level_widget.zoom_out) |
977 zoom_out.rect = BUTTON_RECT.copy() | |
422
6925f540a0c6
Tweak zoom button layout
Neil Muller <drnlmuller@gmail.com>
parents:
421
diff
changeset
|
978 zoom_out.rect.width = zoom_out.rect.width // 2 |
413 | 979 zoom_out.rect.move_ip(MENU_LEFT, y) |
980 widgets.append(zoom_out) | |
981 | |
982 zoom_in = Button('Zoom in', action=self.level_widget.zoom_in) | |
983 zoom_in.rect = BUTTON_RECT.copy() | |
422
6925f540a0c6
Tweak zoom button layout
Neil Muller <drnlmuller@gmail.com>
parents:
421
diff
changeset
|
984 zoom_in.width = zoom_in.width // 2 |
6925f540a0c6
Tweak zoom button layout
Neil Muller <drnlmuller@gmail.com>
parents:
421
diff
changeset
|
985 zoom_in.rect.move_ip(MENU_LEFT + zoom_out.width, y) |
413 | 986 widgets.append(zoom_in) |
987 | |
330
6e32494b9f9e
Move quit button away from other stuff
Neil Muller <drnlmuller@gmail.com>
parents:
315
diff
changeset
|
988 y = SCREEN[1] - MENU_BUTTON_HEIGHT - MENU_PAD |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
989 quit_but = Button('Quit', action=self.quit) |
220
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
990 quit_but.rect = BUTTON_RECT.copy() |
115 | 991 quit_but.rect.move_ip(MENU_LEFT, y) |
220
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
992 widgets.append(quit_but) |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
993 |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
994 self._dMenus['drawing'] = widgets |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
995 |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
996 def _make_objects_menu(self): |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
997 widgets = [] |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
998 |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
999 # Add poly buttons |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1000 y = 15 |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1001 |
225
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
1002 edit_objs_but = Button('Edit Objects', |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
1003 action=self.level_widget.edit_objects) |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
1004 edit_objs_but.rect = BUTTON_RECT.copy() |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
1005 edit_objs_but.rect.move_ip(MENU_LEFT, y) |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
1006 widgets.append(edit_objs_but) |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
1007 y += MENU_BUTTON_HEIGHT + MENU_PAD |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
1008 |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
1009 edir_enemies_but = Button('Edit Enemies', |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
1010 action=self.level_widget.edit_enemies) |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
1011 edir_enemies_but.rect = BUTTON_RECT.copy() |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
1012 edir_enemies_but.rect.move_ip(MENU_LEFT, y) |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
1013 widgets.append(edir_enemies_but) |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
1014 y += MENU_BUTTON_HEIGHT + MENU_PAD |
c8ead015c48e
Display list of objects to edit / delete
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
1015 |
236
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
1016 add_obj_but = Button('Add Game Object', |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
1017 action=self.level_widget.add_game_object) |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
1018 add_obj_but.rect = BUTTON_RECT.copy() |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
1019 add_obj_but.rect.move_ip(MENU_LEFT, y) |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
1020 widgets.append(add_obj_but) |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
1021 y += MENU_BUTTON_HEIGHT + MENU_PAD |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
1022 |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
1023 add_puzzle_but = Button('Add Puzzler', |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
1024 action=self.level_widget.add_puzzler) |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
1025 add_puzzle_but.rect = BUTTON_RECT.copy() |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
1026 add_puzzle_but.rect.move_ip(MENU_LEFT, y) |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
1027 widgets.append(add_puzzle_but) |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
1028 y += MENU_BUTTON_HEIGHT + MENU_PAD |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
1029 |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
1030 add_enemy_but = Button('Add Enemy', |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
1031 action=self.level_widget.add_enemy) |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
1032 add_enemy_but.rect = BUTTON_RECT.copy() |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
1033 add_enemy_but.rect.move_ip(MENU_LEFT, y) |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
1034 widgets.append(add_enemy_but) |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
1035 y += MENU_BUTTON_HEIGHT + MENU_PAD |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
1036 |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
1037 y += MENU_PAD |
280 | 1038 self.sel_mode_but = HighLightButton('Select Object', self, |
1039 action=self.sel_mode) | |
1040 self.sel_mode_but.rect = BUTTON_RECT.copy() | |
1041 self.sel_mode_but.rect.move_ip(MENU_LEFT, y) | |
1042 widgets.append(self.sel_mode_but) | |
1043 self._light_buttons.append(self.sel_mode_but) | |
275
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
1044 y += MENU_BUTTON_HEIGHT + MENU_PAD |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
1045 |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
1046 y += MENU_PAD |
236
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
1047 switch_but = Button('Switch to Drawing', action=self.switch_to_draw) |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
1048 switch_but.rect = BUTTON_RECT.copy() |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
1049 switch_but.rect.move_ip(MENU_LEFT, y) |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
1050 widgets.append(switch_but) |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
1051 y += switch_but.rect.height + MENU_PAD |
261fd65a8816
More work towards object editing
Neil Muller <drnlmuller@gmail.com>
parents:
225
diff
changeset
|
1052 |
220
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1053 save_but = Button('Save Level', action=self.save) |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1054 save_but.rect = BUTTON_RECT.copy() |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1055 save_but.rect.move_ip(MENU_LEFT, y) |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1056 widgets.append(save_but) |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1057 y += MENU_BUTTON_HEIGHT + MENU_PAD |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1058 |
414 | 1059 zoom_out = Button('Zoom out', action=self.level_widget.zoom_out) |
1060 zoom_out.rect = BUTTON_RECT.copy() | |
422
6925f540a0c6
Tweak zoom button layout
Neil Muller <drnlmuller@gmail.com>
parents:
421
diff
changeset
|
1061 zoom_out.rect.width = zoom_out.rect.width // 2 |
414 | 1062 zoom_out.rect.move_ip(MENU_LEFT, y) |
1063 widgets.append(zoom_out) | |
1064 | |
1065 zoom_in = Button('Zoom in', action=self.level_widget.zoom_in) | |
1066 zoom_in.rect = BUTTON_RECT.copy() | |
422
6925f540a0c6
Tweak zoom button layout
Neil Muller <drnlmuller@gmail.com>
parents:
421
diff
changeset
|
1067 zoom_in.width = zoom_in.width // 2 |
6925f540a0c6
Tweak zoom button layout
Neil Muller <drnlmuller@gmail.com>
parents:
421
diff
changeset
|
1068 zoom_in.rect.move_ip(MENU_LEFT + zoom_out.width, y) |
414 | 1069 widgets.append(zoom_in) |
422
6925f540a0c6
Tweak zoom button layout
Neil Muller <drnlmuller@gmail.com>
parents:
421
diff
changeset
|
1070 y += MENU_BUTTON_HEIGHT + MENU_PAD |
414 | 1071 |
330
6e32494b9f9e
Move quit button away from other stuff
Neil Muller <drnlmuller@gmail.com>
parents:
315
diff
changeset
|
1072 y = SCREEN[1] - MENU_BUTTON_HEIGHT - MENU_PAD |
220
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1073 quit_but = Button('Quit', action=self.quit) |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1074 quit_but.rect = BUTTON_RECT.copy() |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1075 quit_but.rect.move_ip(MENU_LEFT, y) |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1076 widgets.append(quit_but) |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1077 |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1078 self._dMenus['objects'] = widgets |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
1079 |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
1080 def key_down(self, ev): |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
1081 if ev.key == pgl.K_ESCAPE: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
1082 self.quit() |
116 | 1083 elif ev.key == pgl.K_s: |
1084 self.save() | |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
1085 else: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
1086 self.level_widget.key_down(ev) |
51 | 1087 |
116 | 1088 def save(self): |
122
02423600d958
Use dialogs to report save results
Neil Muller <drnlmuller@gmail.com>
parents:
117
diff
changeset
|
1089 closed, messages = self.level.all_closed() |
02423600d958
Use dialogs to report save results
Neil Muller <drnlmuller@gmail.com>
parents:
117
diff
changeset
|
1090 if closed: |
02423600d958
Use dialogs to report save results
Neil Muller <drnlmuller@gmail.com>
parents:
117
diff
changeset
|
1091 self.level.save() |
02423600d958
Use dialogs to report save results
Neil Muller <drnlmuller@gmail.com>
parents:
117
diff
changeset
|
1092 # display success |
02423600d958
Use dialogs to report save results
Neil Muller <drnlmuller@gmail.com>
parents:
117
diff
changeset
|
1093 alert("Level %s saved successfully." % self.level.name) |
02423600d958
Use dialogs to report save results
Neil Muller <drnlmuller@gmail.com>
parents:
117
diff
changeset
|
1094 else: |
02423600d958
Use dialogs to report save results
Neil Muller <drnlmuller@gmail.com>
parents:
117
diff
changeset
|
1095 # display errors |
02423600d958
Use dialogs to report save results
Neil Muller <drnlmuller@gmail.com>
parents:
117
diff
changeset
|
1096 alert("Failed to save level.\n\n%s" % '\n'.join(messages)) |
116 | 1097 |
220
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1098 def switch_to_draw(self): |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1099 if self._menu_mode != 'drawing': |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1100 self._clear_menu() |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1101 self._menu_mode = 'drawing' |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1102 self._populate_menu() |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1103 |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1104 def switch_to_objects(self): |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1105 if self._menu_mode != 'objects': |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1106 self._clear_menu() |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1107 self._menu_mode = 'objects' |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1108 self._populate_menu() |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1109 |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1110 def _clear_menu(self): |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1111 for widget in self._dMenus[self._menu_mode]: |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1112 self.remove(widget) |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1113 |
280 | 1114 def reset_lit_buttons(self): |
1115 for but in self._light_buttons: | |
1116 but.reset() | |
1117 | |
220
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1118 def _populate_menu(self): |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1119 self.level_widget.change_poly(None) |
275
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
1120 self.level_widget.sel_mode = False |
220
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1121 for widget in self._dMenus[self._menu_mode]: |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1122 self.add(widget) |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1123 self.invalidate() |
06c52529e2ed
Add placeholder object mode menu
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
1124 |
280 | 1125 def set_line_mode(self): |
1126 self.level_widget.line_mode() | |
1127 self.draw_line_but.highlight() | |
1128 | |
275
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
1129 def sel_mode(self): |
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
1130 self.level_widget.sel_mode = not self.level_widget.sel_mode |
280 | 1131 if self.level_widget.sel_mode: |
1132 self.sel_mode_but.highlight() | |
1133 else: | |
1134 self.sel_mode_but.reset() | |
275
2abb61878bb1
Add a 'select object' with pop-up for easier editing
Neil Muller <drnlmuller@gmail.com>
parents:
262
diff
changeset
|
1135 |
109
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
1136 def mouse_move(self, ev): |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
1137 self.level_widget.mouse_move(ev) |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
1138 |
407 | 1139 def move_point(self): |
1140 self.level_widget.set_move_mode() | |
1141 self.move_point_but.highlight() | |
1142 | |
199
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
1143 def draw(self, surface): |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
1144 # Update checkbox state |
223
4197350b9897
Always show objects in objects mode
Neil Muller <drnlmuller@gmail.com>
parents:
220
diff
changeset
|
1145 if self._menu_mode == 'drawing': |
4197350b9897
Always show objects in objects mode
Neil Muller <drnlmuller@gmail.com>
parents:
220
diff
changeset
|
1146 self.level_widget.set_objects(self.show_objs.value) |
4197350b9897
Always show objects in objects mode
Neil Muller <drnlmuller@gmail.com>
parents:
220
diff
changeset
|
1147 self.level_widget.set_enemies(self.show_enemies.value) |
4197350b9897
Always show objects in objects mode
Neil Muller <drnlmuller@gmail.com>
parents:
220
diff
changeset
|
1148 else: |
4197350b9897
Always show objects in objects mode
Neil Muller <drnlmuller@gmail.com>
parents:
220
diff
changeset
|
1149 self.level_widget.set_objects(True) |
4197350b9897
Always show objects in objects mode
Neil Muller <drnlmuller@gmail.com>
parents:
220
diff
changeset
|
1150 self.level_widget.set_enemies(True) |
199
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
1151 super(EditorApp, self).draw(surface) |
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
1152 |
51 | 1153 |
1154 if __name__ == "__main__": | |
195
b8701c0bb184
Reorder startup to avoid pygame init issues
Neil Muller <drnlmuller@gmail.com>
parents:
187
diff
changeset
|
1155 if len(sys.argv) not in [2, 4]: |
51 | 1156 print 'Please supply a levelname or levelname and level size' |
1157 sys.exit() | |
199
c291fd4b49bf
Add showing objects to the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
198
diff
changeset
|
1158 # 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
|
1159 parse_args([]) |
51 | 1160 pygame.display.init() |
1161 pygame.font.init() | |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
1162 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
|
1163 pgl.SWSURFACE) |
195
b8701c0bb184
Reorder startup to avoid pygame init issues
Neil Muller <drnlmuller@gmail.com>
parents:
187
diff
changeset
|
1164 if len(sys.argv) == 2: |
b8701c0bb184
Reorder startup to avoid pygame init issues
Neil Muller <drnlmuller@gmail.com>
parents:
187
diff
changeset
|
1165 level = EditorLevel(sys.argv[1]) |
b8701c0bb184
Reorder startup to avoid pygame init issues
Neil Muller <drnlmuller@gmail.com>
parents:
187
diff
changeset
|
1166 level.load(pymunk.Space()) |
b8701c0bb184
Reorder startup to avoid pygame init issues
Neil Muller <drnlmuller@gmail.com>
parents:
187
diff
changeset
|
1167 elif len(sys.argv) == 4: |
b8701c0bb184
Reorder startup to avoid pygame init issues
Neil Muller <drnlmuller@gmail.com>
parents:
187
diff
changeset
|
1168 level = EditorLevel(sys.argv[1], int(sys.argv[2]), int(sys.argv[3])) |
51 | 1169 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
|
1170 pygame.key.set_repeat(200, 100) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
1171 app = EditorApp(level, pygame.display.get_surface()) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
1172 app.run() |