Mercurial > nagslang
comparison tools/area_editor.py @ 419:3f15e071614f
Add grid size buttons.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Sat, 07 Sep 2013 12:55:38 +0200 |
parents | 060420389033 |
children | 2cb12311fedc |
comparison
equal
deleted
inserted
replaced
415:9d2a8dfba670 | 419:3f15e071614f |
---|---|
41 MENU_BUTTON_HEIGHT = 35 | 41 MENU_BUTTON_HEIGHT = 35 |
42 MENU_PAD = 6 | 42 MENU_PAD = 6 |
43 MENU_HALF_PAD = MENU_PAD // 2 | 43 MENU_HALF_PAD = MENU_PAD // 2 |
44 MENU_LEFT = SCREEN[0] + MENU_HALF_PAD | 44 MENU_LEFT = SCREEN[0] + MENU_HALF_PAD |
45 MENU_WIDTH = 200 - MENU_PAD | 45 MENU_WIDTH = 200 - MENU_PAD |
46 MENU_HALF_WIDTH = MENU_WIDTH // 2 - MENU_HALF_PAD | |
46 | 47 |
47 BUTTON_RECT = pygame.rect.Rect(0, 0, MENU_WIDTH, MENU_BUTTON_HEIGHT) | 48 BUTTON_RECT = pygame.rect.Rect(0, 0, MENU_WIDTH, MENU_BUTTON_HEIGHT) |
49 HALF_BUTTON_RECT = pygame.rect.Rect(0, 0, MENU_HALF_WIDTH, MENU_BUTTON_HEIGHT) | |
48 CHECK_RECT = pygame.rect.Rect(0, 0, MENU_BUTTON_HEIGHT // 2, | 50 CHECK_RECT = pygame.rect.Rect(0, 0, MENU_BUTTON_HEIGHT // 2, |
49 MENU_BUTTON_HEIGHT // 2) | 51 MENU_BUTTON_HEIGHT // 2) |
50 | 52 |
51 | 53 |
52 class TestWorld(object): | 54 class TestWorld(object): |
448 self.cur_poly = None | 450 self.cur_poly = None |
449 self._mouse_drag = False | 451 self._mouse_drag = False |
450 self._draw_objects = False | 452 self._draw_objects = False |
451 self._draw_enemies = False | 453 self._draw_enemies = False |
452 self._draw_lines = False | 454 self._draw_lines = False |
455 self.grid_size = 1 | |
453 self.sel_mode = False | 456 self.sel_mode = False |
454 self._start_pos = None | 457 self._start_pos = None |
455 self._parent = parent | 458 self._parent = parent |
456 self._move_point_mode = False | 459 self._move_point_mode = False |
457 self._move_point = False | 460 self._move_point = False |
474 if new_pos[1] < 0: | 477 if new_pos[1] < 0: |
475 new_pos[1] = self.pos[1] | 478 new_pos[1] = self.pos[1] |
476 elif new_pos[1] > self.level.y - SCREEN[1]: | 479 elif new_pos[1] > self.level.y - SCREEN[1]: |
477 new_pos[1] = self.pos[1] | 480 new_pos[1] = self.pos[1] |
478 self.pos = tuple(new_pos) | 481 self.pos = tuple(new_pos) |
482 | |
483 def inc_grid_size(self, amount): | |
484 self.grid_size = max(1, self.grid_size + amount) | |
479 | 485 |
480 def set_objects(self, value): | 486 def set_objects(self, value): |
481 if self._draw_objects != value: | 487 if self._draw_objects != value: |
482 self._draw_objects = value | 488 self._draw_objects = value |
483 self.invalidate() | 489 self.invalidate() |
829 self._parent.reset_lit_buttons() | 835 self._parent.reset_lit_buttons() |
830 if self.index is not None: | 836 if self.index is not None: |
831 self.highlight() | 837 self.highlight() |
832 | 838 |
833 | 839 |
840 class 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 | |
855 class 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 | |
834 class EditorApp(RootWidget): | 871 class EditorApp(RootWidget): |
835 | 872 |
836 def __init__(self, level, surface): | 873 def __init__(self, level, surface): |
837 super(EditorApp, self).__init__(surface) | 874 super(EditorApp, self).__init__(surface) |
838 self.level = level | 875 self.level = level |
851 | 888 |
852 self._zoom = 1 | 889 self._zoom = 1 |
853 | 890 |
854 def _make_draw_menu(self): | 891 def _make_draw_menu(self): |
855 widgets = [] | 892 widgets = [] |
893 | |
894 white = pygame.color.Color("white") | |
856 | 895 |
857 # Add poly buttons | 896 # Add poly buttons |
858 y = 15 | 897 y = 15 |
859 for poly in range(1, 7): | 898 for poly in range(1, 7): |
860 but = PolyButton(poly, self.level_widget, self) | 899 but = PolyButton(poly, self.level_widget, self) |
879 action=self.move_point) | 918 action=self.move_point) |
880 self.move_point_but.rect = BUTTON_RECT.copy() | 919 self.move_point_but.rect = BUTTON_RECT.copy() |
881 self.move_point_but.rect.move_ip(MENU_LEFT, y) | 920 self.move_point_but.rect.move_ip(MENU_LEFT, y) |
882 widgets.append(self.move_point_but) | 921 widgets.append(self.move_point_but) |
883 self._light_buttons.append(self.move_point_but) | 922 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) | |
884 y += MENU_BUTTON_HEIGHT + MENU_PAD | 940 y += MENU_BUTTON_HEIGHT + MENU_PAD |
885 | 941 |
886 self.draw_line_but = HighLightButton("Draw interior wall", self, | 942 self.draw_line_but = HighLightButton("Draw interior wall", self, |
887 action=self.set_line_mode) | 943 action=self.set_line_mode) |
888 self.draw_line_but.rect = BUTTON_RECT.copy() | 944 self.draw_line_but.rect = BUTTON_RECT.copy() |
902 close_poly_but.rect = BUTTON_RECT.copy() | 958 close_poly_but.rect = BUTTON_RECT.copy() |
903 close_poly_but.rect.move_ip(MENU_LEFT, y) | 959 close_poly_but.rect.move_ip(MENU_LEFT, y) |
904 widgets.append(close_poly_but) | 960 widgets.append(close_poly_but) |
905 y += MENU_BUTTON_HEIGHT + MENU_PAD | 961 y += MENU_BUTTON_HEIGHT + MENU_PAD |
906 | 962 |
907 white = pygame.color.Color("white") | |
908 self.show_objs = CheckBox(fg_color=white) | 963 self.show_objs = CheckBox(fg_color=white) |
909 self.show_objs.rect = CHECK_RECT.copy() | 964 self.show_objs.rect = CHECK_RECT.copy() |
910 self.show_objs.rect.move_ip(MENU_LEFT, y) | 965 self.show_objs.rect.move_ip(MENU_LEFT, y) |
911 label = Label("Show Objects", fg_color=white) | 966 label = Label("Show Objects", fg_color=white) |
912 label.rect.move_ip(MENU_LEFT + MENU_BUTTON_HEIGHT // 2 + MENU_PAD, y) | 967 label.rect.move_ip(MENU_LEFT + MENU_BUTTON_HEIGHT // 2 + MENU_PAD, y) |