Compare commits
No commits in common. "25f1b20a7abb54d7b74d8a006cdccf12e00855cb" and "3e3dbcdda89581863f9b243270e0ccad5890824e" have entirely different histories.
25f1b20a7a
...
3e3dbcdda8
@ -45,7 +45,6 @@ class Editor:
|
||||
self.typing_text: str = ""
|
||||
self.node_candidate_pos: tuple[int, int] = None
|
||||
self.node_radius: int = 10
|
||||
self.selected_node: int = -1
|
||||
|
||||
def mainloop(self) -> None:
|
||||
self.state = State.LOADING
|
||||
@ -85,10 +84,7 @@ class Editor:
|
||||
self.typing_text += event.unicode
|
||||
else:
|
||||
if event.key == pygame.K_ESCAPE:
|
||||
if self.selected_node != -1:
|
||||
self.selected_node = -1
|
||||
else:
|
||||
self.state = State.STOPPING
|
||||
self.state = State.STOPPING
|
||||
elif event.key == pygame.K_PAGEUP:
|
||||
self.zoom_in()
|
||||
elif event.key == pygame.K_PAGEDOWN:
|
||||
@ -100,11 +96,9 @@ class Editor:
|
||||
if keys[pygame.K_LCTRL]:
|
||||
self.left_drag_pos = event.pos
|
||||
else:
|
||||
self.selected_node = self.get_hover_node()
|
||||
elif event.button == 3:
|
||||
self.node_candidate_pos = self.screen_to_world(event.pos[0], event.pos[1])
|
||||
self.is_creating_node = True
|
||||
self.typing = True
|
||||
self.node_candidate_pos = self.screen_to_world(event.pos[0], event.pos[1])
|
||||
self.is_creating_node = True
|
||||
self.typing = True
|
||||
elif event.button == 4:
|
||||
self.zoom_in()
|
||||
elif event.button == 5:
|
||||
@ -253,21 +247,17 @@ class Editor:
|
||||
for node in self.graph.nodes:
|
||||
blitpos = self.world_to_screen(node.x, node.z)
|
||||
pygame.draw.circle(self.win, (255, 0, 0), (blitpos[0], blitpos[1]), self.node_radius)
|
||||
if self.selected_node != -1:
|
||||
node = self.graph.nodes[self.selected_node]
|
||||
node_pos = self.world_to_screen(node.x, node.z)
|
||||
pygame.draw.circle(self.win, (0, 255, 255), (node_pos[0], node_pos[1]), self.node_radius)
|
||||
self.render_mouse_hover_node()
|
||||
self.render_mouse_hover_node_text()
|
||||
|
||||
def render_mouse_hover_node_text(self):
|
||||
mouse_pos = pygame.mouse.get_pos()
|
||||
|
||||
def render_mouse_hover_node(self):
|
||||
node_index = self.get_hover_node()
|
||||
if node_index != -1:
|
||||
node = self.graph.nodes[self.get_hover_node()]
|
||||
txt = self.loading_font.render(node.name, True, (0, 0, 0))
|
||||
for node in self.graph.nodes:
|
||||
node_pos = self.world_to_screen(node.x, node.z)
|
||||
self.win.blit(txt, [node_pos[0] - txt.get_width(), node_pos[1] - txt.get_height()])
|
||||
pygame.draw.circle(self.win, (0, 0, 0), (node_pos[0], node_pos[1]), self.node_radius, (int) (self.node_radius / 5))
|
||||
hovering = ((mouse_pos[0] - node_pos[0]) ** 2 + (mouse_pos[1] - node_pos[1]) ** 2) < self.node_radius ** 2
|
||||
if (hovering):
|
||||
txt = self.loading_font.render(node.name, True, (0, 0, 0))
|
||||
self.win.blit(txt, [node_pos[0] - txt.get_width(), node_pos[1] - txt.get_height()])
|
||||
|
||||
def set_zoom(self, zoom_i: int) -> None:
|
||||
self.zoom_i = max(0, min(len(self.ZOOMS) - 1, zoom_i))
|
||||
@ -302,23 +292,6 @@ class Editor:
|
||||
self.typing = False
|
||||
self.is_creating_node = False
|
||||
|
||||
def get_hovering_nodes(self) -> list[int]:
|
||||
hovering = []
|
||||
mouse_pos = pygame.mouse.get_pos()
|
||||
|
||||
for node in self.graph.nodes:
|
||||
node_pos = self.world_to_screen(node.x, node.z)
|
||||
if ((mouse_pos[0] - node_pos[0]) ** 2 + (mouse_pos[1] - node_pos[1]) ** 2) < self.node_radius ** 2 :
|
||||
hovering.append(self.graph.nodes.index(node))
|
||||
|
||||
return hovering
|
||||
|
||||
def get_hover_node(self) -> int:
|
||||
hover_nodes = self.get_hovering_nodes()
|
||||
return -1 if len(hover_nodes) == 0 else hover_nodes[0]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user