annotate tools/area_editor.py @ 690:9ae338ad2416

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