# HG changeset patch # User Simon Cross # Date 1378551505 -7200 # Node ID da45406d08cda5764213f16b3d080833cbe70ec8 # Parent 3f15e071614f36bba8bcd37ae54cb2fc267c90db# Parent 367bdb91b998acd485cd37e75e337b455779d63d Merge. diff -r 367bdb91b998 -r da45406d08cd tools/area_editor.py --- a/tools/area_editor.py Sat Sep 07 12:56:42 2013 +0200 +++ b/tools/area_editor.py Sat Sep 07 12:58:25 2013 +0200 @@ -43,8 +43,10 @@ MENU_HALF_PAD = MENU_PAD // 2 MENU_LEFT = SCREEN[0] + MENU_HALF_PAD MENU_WIDTH = 200 - MENU_PAD +MENU_HALF_WIDTH = MENU_WIDTH // 2 - MENU_HALF_PAD BUTTON_RECT = pygame.rect.Rect(0, 0, MENU_WIDTH, MENU_BUTTON_HEIGHT) +HALF_BUTTON_RECT = pygame.rect.Rect(0, 0, MENU_HALF_WIDTH, MENU_BUTTON_HEIGHT) CHECK_RECT = pygame.rect.Rect(0, 0, MENU_BUTTON_HEIGHT // 2, MENU_BUTTON_HEIGHT // 2) @@ -450,6 +452,7 @@ self._draw_objects = False self._draw_enemies = False self._draw_lines = False + self.grid_size = 1 self.sel_mode = False self._start_pos = None self._parent = parent @@ -477,6 +480,9 @@ new_pos[1] = self.pos[1] self.pos = tuple(new_pos) + def inc_grid_size(self, amount): + self.grid_size = max(1, self.grid_size + amount) + def set_objects(self, value): if self._draw_objects != value: self._draw_objects = value @@ -831,6 +837,37 @@ self.highlight() +class GridSizeLabel(Label): + """Label and setter for grid size.""" + + def __init__(self, level_widget, **kwds): + self.level_widget = level_widget + super(GridSizeLabel, self).__init__(self.grid_text(), **kwds) + + def grid_text(self): + return "Grid size: %d" % self.level_widget.grid_size + + def inc_grid_size(self, amount): + self.level_widget.inc_grid_size(amount) + self.set_text(self.grid_text()) + + +class SnapButton(Button): + """Button for increasing or decreasing snap-to-grid size.""" + + def __init__(self, grid_size_label, parent, inc_amount): + self.grid_size_label = grid_size_label + self.inc_amount = inc_amount + text = "Grid %s%d" % ( + '-' if inc_amount < 0 else '+', + abs(inc_amount)) + self._parent = parent + super(SnapButton, self).__init__(text) + + def action(self): + self.grid_size_label.inc_grid_size(self.inc_amount) + + class EditorApp(RootWidget): def __init__(self, level, surface): @@ -854,6 +891,8 @@ def _make_draw_menu(self): widgets = [] + white = pygame.color.Color("white") + # Add poly buttons y = 15 for poly in range(1, 7): @@ -881,6 +920,23 @@ self.move_point_but.rect.move_ip(MENU_LEFT, y) widgets.append(self.move_point_but) self._light_buttons.append(self.move_point_but) + + # grid size widgets + grid_size_label = GridSizeLabel( + self.level_widget, width=BUTTON_RECT.width, + align="c", fg_color=white) + grid_size_label.rect.move_ip(MENU_LEFT, y) + widgets.append(grid_size_label) + y += grid_size_label.rect.height + MENU_PAD + inc_snap_but = SnapButton(grid_size_label, self, 1) + inc_snap_but.rect = HALF_BUTTON_RECT.copy() + inc_snap_but.rect.move_ip(MENU_LEFT, y) + widgets.append(inc_snap_but) + dec_snap_but = SnapButton(grid_size_label, self, -1) + dec_snap_but.rect = HALF_BUTTON_RECT.copy() + dec_snap_but.rect.move_ip( + MENU_LEFT + MENU_HALF_WIDTH, y) + widgets.append(dec_snap_but) y += MENU_BUTTON_HEIGHT + MENU_PAD self.draw_line_but = HighLightButton("Draw interior wall", self, @@ -904,7 +960,6 @@ widgets.append(close_poly_but) y += MENU_BUTTON_HEIGHT + MENU_PAD - white = pygame.color.Color("white") self.show_objs = CheckBox(fg_color=white) self.show_objs.rect = CHECK_RECT.copy() self.show_objs.rect.move_ip(MENU_LEFT, y)