Compare commits

..

No commits in common. "25f1b20a7abb54d7b74d8a006cdccf12e00855cb" and "3e3dbcdda89581863f9b243270e0ccad5890824e" have entirely different histories.

View File

@ -45,7 +45,6 @@ class Editor:
self.typing_text: str = "" self.typing_text: str = ""
self.node_candidate_pos: tuple[int, int] = None self.node_candidate_pos: tuple[int, int] = None
self.node_radius: int = 10 self.node_radius: int = 10
self.selected_node: int = -1
def mainloop(self) -> None: def mainloop(self) -> None:
self.state = State.LOADING self.state = State.LOADING
@ -85,9 +84,6 @@ class Editor:
self.typing_text += event.unicode self.typing_text += event.unicode
else: else:
if event.key == pygame.K_ESCAPE: 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: elif event.key == pygame.K_PAGEUP:
self.zoom_in() self.zoom_in()
@ -100,8 +96,6 @@ class Editor:
if keys[pygame.K_LCTRL]: if keys[pygame.K_LCTRL]:
self.left_drag_pos = event.pos self.left_drag_pos = event.pos
else: 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.node_candidate_pos = self.screen_to_world(event.pos[0], event.pos[1])
self.is_creating_node = True self.is_creating_node = True
self.typing = True self.typing = True
@ -253,21 +247,17 @@ class Editor:
for node in self.graph.nodes: for node in self.graph.nodes:
blitpos = self.world_to_screen(node.x, node.z) blitpos = self.world_to_screen(node.x, node.z)
pygame.draw.circle(self.win, (255, 0, 0), (blitpos[0], blitpos[1]), self.node_radius) pygame.draw.circle(self.win, (255, 0, 0), (blitpos[0], blitpos[1]), self.node_radius)
if self.selected_node != -1: self.render_mouse_hover_node_text()
node = self.graph.nodes[self.selected_node]
def render_mouse_hover_node_text(self):
mouse_pos = pygame.mouse.get_pos()
for node in self.graph.nodes:
node_pos = self.world_to_screen(node.x, node.z) 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) hovering = ((mouse_pos[0] - node_pos[0]) ** 2 + (mouse_pos[1] - node_pos[1]) ** 2) < self.node_radius ** 2
self.render_mouse_hover_node() if (hovering):
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)) txt = self.loading_font.render(node.name, True, (0, 0, 0))
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()]) 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))
def set_zoom(self, zoom_i: int) -> None: def set_zoom(self, zoom_i: int) -> None:
self.zoom_i = max(0, min(len(self.ZOOMS) - 1, zoom_i)) self.zoom_i = max(0, min(len(self.ZOOMS) - 1, zoom_i))
@ -302,23 +292,6 @@ class Editor:
self.typing = False self.typing = False
self.is_creating_node = 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]