-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.py
159 lines (137 loc) · 5.89 KB
/
gui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import pygame
import pygame_gui
import cell
from pygame_gui.core import ObjectID
from legend_cell import LegendCell
from grid import GREY
GUI_ELEMENT_OFFSET = 20
class GUI:
"""GUI handler class"""
def __init__(self, win, ui_manager, grid, algorithms, mazes, width, height, animation_speed):
self.algo_menu = pygame_gui.elements.UIDropDownMenu(
options_list=[algo for algo in algorithms],
starting_option=algorithms.ASTAR,
relative_rect=pygame.Rect((grid.x, grid.y / 2 - 15), (230, 30)),
manager=ui_manager,
)
self.visualize_button = pygame_gui.elements.UIButton(
relative_rect=pygame.Rect(
(
self.algo_menu.get_abs_rect().x
+ self.algo_menu.get_abs_rect().width
+ GUI_ELEMENT_OFFSET,
grid.y / 2 - 15,
),
(100, 30),
),
text="Visualize",
manager=ui_manager,
object_id="#visualize_button",
)
self.maze_menu = pygame_gui.elements.UIDropDownMenu(
options_list=[maze for maze in mazes],
starting_option=mazes.RECDIV,
relative_rect=pygame.Rect(
(
self.visualize_button.get_abs_rect().x
+ self.visualize_button.get_abs_rect().width
+ GUI_ELEMENT_OFFSET,
grid.y / 2 - 15,
),
(305, 30),
),
manager=ui_manager,
)
self.generate_button = pygame_gui.elements.UIButton(
relative_rect=pygame.Rect(
(
self.maze_menu.get_abs_rect().x
+ self.maze_menu.get_abs_rect().width
+ GUI_ELEMENT_OFFSET,
grid.y / 2 - 15,
),
(100, 30),
),
text="Generate",
manager=ui_manager,
)
self.clear_everything_button = pygame_gui.elements.UIButton(
relative_rect=pygame.Rect((width - 55, grid.y / 2 - 15), (50, 30)),
text="CE",
manager=ui_manager,
)
self.unvisited_cell_lable = pygame_gui.elements.UILabel(
relative_rect=pygame.Rect((grid.x + grid.gap, height - 30), (90, grid.gap)),
text="-unvisited",
manager=ui_manager,
object_id=ObjectID(object_id=None, class_id="@legend_cell_lables"),
)
self.visited_cell_lable = pygame_gui.elements.UILabel(
relative_rect=pygame.Rect((grid.x + 800 + grid.gap, height - 30), (123, grid.gap)),
text="-visited",
manager=ui_manager,
object_id=ObjectID(object_id=None, class_id="@legend_cell_lables"),
)
self.open_cell_lable = pygame_gui.elements.UILabel(
relative_rect=pygame.Rect((grid.x + 400 + grid.gap, height - 30), (50, grid.gap)),
text="-open",
manager=ui_manager,
object_id=ObjectID(object_id=None, class_id="@legend_cell_lables"),
)
self.path_cell_lable = pygame_gui.elements.UILabel(
relative_rect=pygame.Rect((grid.x + 600 + grid.gap, height - 30), (50, grid.gap)),
text="-path",
manager=ui_manager,
object_id=ObjectID(object_id=None, class_id="@legend_cell_lables"),
)
self.wall_cell_lable = pygame_gui.elements.UILabel(
relative_rect=pygame.Rect((grid.x + 200 + grid.gap, height - 30), (50, grid.gap)),
text="-wall",
manager=ui_manager,
object_id=ObjectID(object_id=None, class_id="@legend_cell_lables"),
)
self.legend_cells = [
LegendCell(win, grid.x, height - 30, cell.UNVISITED_COLOR, GREY, grid),
LegendCell(win, grid.x + 200, height - 30, cell.WALL_COLOR, GREY, grid),
LegendCell(win, grid.x + 400, height - 30, cell.OPEN_COLOR, GREY, grid),
LegendCell(win, grid.x + 600, height - 30, cell.PATH_COLOR, GREY, grid),
LegendCell(win, grid.x + 800, height - 30, cell.VISITED_COLOR_1, GREY, grid),
LegendCell(win, grid.x + 825, height - 30, cell.VISITED_COLOR_2, GREY, grid),
]
self.clear_button = pygame_gui.elements.UIButton(
relative_rect=pygame.Rect((width - 105, grid.y / 2 - 15), (50, 30)),
text="C",
manager=ui_manager,
)
self.parcel_button = pygame_gui.elements.UIButton(
relative_rect=pygame.Rect(
(
self.generate_button.get_abs_rect().x
+ self.generate_button.get_abs_rect().width
+ GUI_ELEMENT_OFFSET,
grid.y / 2 - 15,
),
(130, 30),
),
text="Add Parcel",
manager=ui_manager,
)
self.speed_lable = pygame_gui.elements.UILabel(
relative_rect=pygame.Rect((grid.x + 1000, height - 32), (50, grid.gap + 5)),
text="Speed:",
manager=ui_manager,
object_id=ObjectID(object_id=None, class_id="@legend_cell_lables"),
)
self.speed_slider = pygame_gui.elements.UIHorizontalSlider(
start_value=animation_speed,
value_range=(animation_speed - animation_speed / 2, animation_speed + animation_speed / 2,),
relative_rect=pygame.Rect((grid.x + 1050, height - 32), (200, grid.gap + 5)),
manager=ui_manager,
)
self.speed_value_lable = pygame_gui.elements.UILabel(
relative_rect=pygame.Rect((grid.x + 1250, height - 32), (35, grid.gap + 5)),
text="x",
manager=ui_manager,
object_id=ObjectID(object_id=None, class_id="@legend_cell_lables"),
)
self.speed_value_lable.set_text(f"{round(self.speed_slider.current_percentage * 100)}%")