Changeset 205:51f979ddddbb


Ignore:
Timestamp:
Sep 3, 2013, 9:31:54 PM (7 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
rebase_source:
05a9b89aff0b864cc551a08bceb4c4e0207f120b
Message:

Munge in interior wall drawing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/area_editor.py

    r204 r205  
    6363            self.polygons[poly_index].append(point)
    6464        else:
    65             add_pos = self.fix_angle(poly_index, pos)
     65            add_pos = self.fix_poly_angle(poly_index, pos)
    6666            self.polygons[poly_index].append(add_pos)
    6767
    68     def fix_angle(self, index, pos):
    69         # Last point
    70         point1 = self.point_to_pygame(self.polygons[index][-1])
    71         pos = self.round_point(pos)
     68    def _fix_angle(self, point1, pos):
    7269        # We want the line (point1 to pos) to be an angle of
    7370        # 0, 45, 90, 135, 180, 225, 270, 305
     
    9087        return self.point_to_pymunk(new_pos)
    9188
     89    def fix_line_angle(self, start_pos, pos):
     90        start_pos = self.round_point(start_pos)
     91        pos = self.round_point(pos)
     92        return self._fix_angle(start_pos, pos)
     93
     94    def fix_poly_angle(self, index, pos):
     95        # Last point
     96        point1 = self.point_to_pygame(self.polygons[index][-1])
     97        pos = self.round_point(pos)
     98        return self._fix_angle(point1, pos)
     99
    92100    def delete_point(self, index):
    93101        if index in self.polygons and len(self.polygons[index]) > 0:
     
    103111            return False
    104112        first = self.polygons[index][0]
    105         if self.fix_angle(index, self.point_to_pygame(first)) == first:
     113        if self.fix_poly_angle(index, self.point_to_pygame(first)) == first:
    106114            self.add_point(index, self.point_to_pygame(first))
    107115            return True
     
    117125        poss = None
    118126        for cand in candidates:
    119             if self.fix_angle(index, self.point_to_pygame(cand)) == cand:
     127            if self.fix_poly_angle(index, self.point_to_pygame(cand)) == cand:
    120128                dist = (first[0] - cand[0]) ** 2 + (first[1] - cand[1]) ** 2
    121129                if dist < min_dist:
     
    127135        return False
    128136
    129     def draw(self, mouse_pos, mouse_poly, filled):
     137    def add_line(self, start_pos, end_pos):
     138        endpoint = self.fix_line_angle(start_pos, end_pos)
     139        startpoint = self.point_to_pymunk(self.round_point(start_pos))
     140        self.lines.append([startpoint, endpoint])
     141
     142    def draw(self, mouse_pos, mouse_poly, filled, draw_cand_line, start_pos):
    130143        self._draw_background(True)
    131144        # Draw polygons as needed for the editor
     
    138151                pygame.draw.lines(self._surface, color, False, pointlist, 2)
    139152            if index == mouse_poly and mouse_pos:
    140                 endpoint = self.fix_angle(index, mouse_pos)
     153                endpoint = self.fix_poly_angle(index, mouse_pos)
    141154                pygame.draw.line(self._surface, color,
    142155                                 self.point_to_pygame(polygon[-1]),
     
    145158            pointlist = [self.point_to_pygame(p) for p in line]
    146159            pygame.draw.lines(self._surface, LINE_COLOR, False, pointlist, 2)
     160        if draw_cand_line and start_pos and mouse_pos:
     161            endpoint = self.fix_line_angle(start_pos, mouse_pos)
     162            pointlist = [self.round_point(start_pos),
     163                    self.point_to_pygame(endpoint)]
     164            pygame.draw.lines(self._surface, LINE_COLOR, False, pointlist, 1)
    147165        return self._surface.copy()
    148166
     
    162180        self._draw_enemies = False
    163181        self._draw_lines = False
     182        self._start_pos = None
    164183
    165184    def _level_coordinates(self, pos):
     
    196215            # We have an active polygon
    197216            mouse_pos = self._level_coordinates(self.mouse_pos)
     217        elif self._draw_lines:
     218            # Interior wall mode
     219            mouse_pos = self._level_coordinates(self.mouse_pos)
    198220        else:
    199221            mouse_pos = None
    200         level_surface = level.draw(mouse_pos, self.cur_poly, self.filled_mode)
     222        level_surface = level.draw(mouse_pos, self.cur_poly, self.filled_mode,
     223                self._draw_lines, self._start_pos)
    201224        if self._draw_objects:
    202225            for thing in self.level.drawables:
     
    220243        self._draw_lines = True
    221244        self.filled_mode = False
     245        self._start_pos = None
    222246
    223247    def key_down(self, ev):
     
    253277        old_pos = self.mouse_pos
    254278        self.mouse_pos = ev.pos
    255         if self.cur_poly and old_pos != self.mouse_pos:
     279        if old_pos != self.mouse_pos and (self.cur_poly or self._draw_lines):
    256280            self.invalidate()
    257281
     
    268292        if ev.button == 1:
    269293            if self._draw_lines:
    270                 pass
     294                if self._start_pos is None:
     295                    self._start_pos = ev.pos
     296                else:
     297                    self.level.add_line(self._start_pos, ev.pos)
     298                    self._start_pos = None
    271299            else:
    272300                print "Click: %r" % (
Note: See TracChangeset for help on using the changeset viewer.