Changeset 419:3f15e071614f


Ignore:
Timestamp:
09/07/13 10:55:38 (8 years ago)
Author:
Simon Cross <hodgestar@…>
Branch:
default
Phase:
public
Rebase:
32616366623333323765396666326435303930653533313266323831333463643866383633326136
Message:

Add grid size buttons.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/area_editor.py

    r414 r419  
    4444MENU_LEFT = SCREEN[0] + MENU_HALF_PAD
    4545MENU_WIDTH = 200 - MENU_PAD
     46MENU_HALF_WIDTH = MENU_WIDTH // 2 - MENU_HALF_PAD
    4647
    4748BUTTON_RECT = pygame.rect.Rect(0, 0, MENU_WIDTH, MENU_BUTTON_HEIGHT)
     49HALF_BUTTON_RECT = pygame.rect.Rect(0, 0, MENU_HALF_WIDTH, MENU_BUTTON_HEIGHT)
    4850CHECK_RECT = pygame.rect.Rect(0, 0, MENU_BUTTON_HEIGHT // 2,
    4951                              MENU_BUTTON_HEIGHT // 2)
     
    451453        self._draw_enemies = False
    452454        self._draw_lines = False
     455        self.grid_size = 1
    453456        self.sel_mode = False
    454457        self._start_pos = None
     
    477480            new_pos[1] = self.pos[1]
    478481        self.pos = tuple(new_pos)
     482
     483    def inc_grid_size(self, amount):
     484        self.grid_size = max(1, self.grid_size + amount)
    479485
    480486    def set_objects(self, value):
     
    832838
    833839
     840class GridSizeLabel(Label):
     841    """Label and setter for grid size."""
     842
     843    def __init__(self, level_widget, **kwds):
     844        self.level_widget = level_widget
     845        super(GridSizeLabel, self).__init__(self.grid_text(), **kwds)
     846
     847    def grid_text(self):
     848        return "Grid size: %d" % self.level_widget.grid_size
     849
     850    def inc_grid_size(self, amount):
     851        self.level_widget.inc_grid_size(amount)
     852        self.set_text(self.grid_text())
     853
     854
     855class SnapButton(Button):
     856    """Button for increasing or decreasing snap-to-grid size."""
     857
     858    def __init__(self, grid_size_label, parent, inc_amount):
     859        self.grid_size_label = grid_size_label
     860        self.inc_amount = inc_amount
     861        text = "Grid %s%d" % (
     862            '-' if inc_amount < 0 else '+',
     863            abs(inc_amount))
     864        self._parent = parent
     865        super(SnapButton, self).__init__(text)
     866
     867    def action(self):
     868        self.grid_size_label.inc_grid_size(self.inc_amount)
     869
     870
    834871class EditorApp(RootWidget):
    835872
     
    854891    def _make_draw_menu(self):
    855892        widgets = []
     893
     894        white = pygame.color.Color("white")
    856895
    857896        # Add poly buttons
     
    882921        widgets.append(self.move_point_but)
    883922        self._light_buttons.append(self.move_point_but)
     923
     924        # grid size widgets
     925        grid_size_label = GridSizeLabel(
     926            self.level_widget, width=BUTTON_RECT.width,
     927            align="c", fg_color=white)
     928        grid_size_label.rect.move_ip(MENU_LEFT, y)
     929        widgets.append(grid_size_label)
     930        y += grid_size_label.rect.height + MENU_PAD
     931        inc_snap_but = SnapButton(grid_size_label, self, 1)
     932        inc_snap_but.rect = HALF_BUTTON_RECT.copy()
     933        inc_snap_but.rect.move_ip(MENU_LEFT, y)
     934        widgets.append(inc_snap_but)
     935        dec_snap_but = SnapButton(grid_size_label, self, -1)
     936        dec_snap_but.rect = HALF_BUTTON_RECT.copy()
     937        dec_snap_but.rect.move_ip(
     938            MENU_LEFT + MENU_HALF_WIDTH, y)
     939        widgets.append(dec_snap_but)
    884940        y += MENU_BUTTON_HEIGHT + MENU_PAD
    885941
     
    905961        y += MENU_BUTTON_HEIGHT + MENU_PAD
    906962
    907         white = pygame.color.Color("white")
    908963        self.show_objs = CheckBox(fg_color=white)
    909964        self.show_objs.rect = CHECK_RECT.copy()
Note: See TracChangeset for help on using the changeset viewer.