Changeset 199:c291fd4b49bf


Ignore:
Timestamp:
Sep 3, 2013, 8:53:23 PM (7 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
rebase_source:
466afde104ebfdf3cd36939e8aae02dedb69cf91
Message:

Add showing objects to the level editor

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/area_editor.py

    r198 r199  
    2727from albow.dialogs import alert
    2828
     29from nagslang.options import parse_args
    2930from nagslang.constants import SCREEN
    3031from nagslang.level import Level, POLY_COLORS
     32from nagslang.enemies import Enemy
    3133
    3234
     
    125127        return False
    126128
    127     def draw(self, surface, topleft, mouse_pos, mouse_poly, filled):
     129    def draw(self, mouse_pos, mouse_poly, filled):
    128130        self._draw_background(True)
    129131        # Draw polygons as needed for the editor
     
    140142                                 self.point_to_pygame(polygon[-1]),
    141143                                 self.point_to_pygame(endpoint))
    142         surface_area = pygame.rect.Rect(topleft, SCREEN)
    143         surface.blit(self._surface, (0, 0), surface_area)
     144        return self._surface.copy()
    144145
    145146
     
    155156        self.cur_poly = None
    156157        self._mouse_drag = False
     158        self._draw_objects = False
     159        self._draw_enemies = False
    157160
    158161    def _level_coordinates(self, pos):
     
    174177        self.pos = tuple(new_pos)
    175178
     179    def set_objects(self, value):
     180        if self._draw_objects != value:
     181            self._draw_objects = value
     182            self.invalidate()
     183
     184    def set_enemies(self, value):
     185        if self._draw_enemies != value:
     186            self._draw_enemies = value
     187            self.invalidate()
     188
    176189    def draw(self, surface):
    177190        if (self.cur_poly is not None and self.cur_poly in self.level.polygons
     
    181194        else:
    182195            mouse_pos = None
    183         level.draw(surface, self.pos, mouse_pos, self.cur_poly,
    184                    self.filled_mode)
     196        level_surface = level.draw(mouse_pos, self.cur_poly, self.filled_mode)
     197        if self._draw_objects:
     198            for thing in self.level.drawables:
     199                if not isinstance(thing, Enemy):
     200                    thing.render(level_surface)
     201        if self._draw_enemies:
     202            for thing in self.level.drawables:
     203                if isinstance(thing, Enemy):
     204                    thing.render(level_surface)
     205        surface_area = pygame.rect.Rect(self.pos, SCREEN)
     206        surface.blit(level_surface, (0, 0), surface_area)
    185207
    186208    def change_poly(self, new_poly):
     
    378400        self.level_widget.mouse_move(ev)
    379401
     402    def draw(self, surface):
     403        # Update checkbox state
     404        self.level_widget.set_objects(self.show_objs.value)
     405        self.level_widget.set_enemies(self.show_enemies.value)
     406        super(EditorApp, self).draw(surface)
     407
    380408
    381409if __name__ == "__main__":
     
    383411        print 'Please supply a levelname or levelname and level size'
    384412        sys.exit()
     413    # Need to ensure we have defaults for rendering
     414    parse_args([])
    385415    pygame.display.init()
    386416    pygame.font.init()
Note: See TracChangeset for help on using the changeset viewer.