| … | … | @@ -0,0 +1,43 @@ |
| 1 | extends Camera2D | |
| 2 | # Customize these values as needed | |
| 3 | var zoom_speed: float = 0.01 | |
| 4 | var min_zoom: float = 0.5 | |
| 5 | var max_zoom: float = 2.0 | |
| 6 | var dragging: bool = false | |
| 7 | var drag_last_position: Vector2 | |
| 8 | ||
| 9 | func _ready(): | |
| 10 | # Initial setup if needed | |
| 11 | pass | |
| 12 | ||
| 13 | func _input(event): | |
| 14 | if event is InputEventMouseButton: | |
| 15 | if event.button_index == MOUSE_BUTTON_RIGHT: | |
| 16 | if event.pressed: | |
| 17 | dragging = true | |
| 18 | drag_last_position = event.global_position | |
| 19 | else: | |
| 20 | dragging = false | |
| 21 | elif event.button_index == MOUSE_BUTTON_WHEEL_UP or event.button_index == MOUSE_BUTTON_WHEEL_DOWN: | |
| 22 | var zoom_direction = 0 | |
| 23 | if event.button_index == MOUSE_BUTTON_WHEEL_UP: | |
| 24 | zoom_direction = 1 | |
| 25 | else: | |
| 26 | zoom_direction = -1 | |
| 27 | ||
| 28 | zoom += Vector2(zoom_speed, zoom_speed) * zoom_direction | |
| 29 | # Clamp the zoom value | |
| 30 | zoom.x = clamp(zoom.x, min_zoom, max_zoom) | |
| 31 | zoom.y = clamp(zoom.y, min_zoom, max_zoom) | |
| 32 | zoom += Vector2(zoom_speed, zoom_speed) * zoom_direction | |
| 33 | # Clamp the zoom value to ensure it's within the min and max thresholds | |
| 34 | zoom.x = clamp(zoom.x, min_zoom, max_zoom) | |
| 35 | zoom.y = clamp(zoom.y, min_zoom, max_zoom) | |
| 36 | ||
| 37 | elif event is InputEventMouseMotion and dragging: | |
| 38 | # Calculate the drag movement | |
| 39 | var drag_current_position = event.global_position | |
| 40 | var drag_delta = drag_last_position - drag_current_position | |
| 41 | # Move the camera based on the drag | |
| 42 | position += drag_delta | |
| 43 | drag_last_position = drag_current_position |
| … | … | @@ -19,7 +19,9 @@ func _input(event): |
| 19 | 19 | if event.button_index == MOUSE_BUTTON_LEFT: |
| 20 | 20 | if event.pressed: |
| 21 | 21 | var mouse_pos = get_viewport().get_mouse_position() |
| 22 | if get_rect().has_point(mouse_pos): | |
| 22 | var mouse_pos2 = get_global_mouse_position() # Adjusted line | |
| 23 | print(mouse_pos2, get_rect().position) | |
| 24 | if get_rect().has_point(mouse_pos2): | |
| 23 | 25 | dragging = true |
| 24 | 26 | drag_offset = mouse_pos - get_position() |
| 25 | 27 | emit_signal("node_drag_started", self) |
| … | … | @@ -38,7 +38,6 @@ func populate_edge_data(): |
| 38 | 38 | var hyperedge_scene = load("res://HyperEdge.tscn") |
| 39 | 39 | for node_id in nodes: |
| 40 | 40 | var node_edges = nodes[node_id].edges |
| 41 | print(nodes) | |
| 42 | 41 | var circle_ref = get_node(str(node_id)) # Assuming this gets a node instance with 'offset_circles' available |
| 43 | 42 | var offset_circles = circle_ref.offset_circles # List of radii for offset circles |
| 44 | 43 | for edge_index in range(node_edges.size()): |
| … | … | @@ -62,16 +61,10 @@ func populate_edge_data(): |
| 62 | 61 | var radius = edge_data["radii"][i] |
| 63 | 62 | node_radii_pairs[nodeid] = radius |
| 64 | 63 | hyperedge_instance.nodes = node_radii_pairs |
| 65 | ||
| 66 | 64 | var color = Color(randf(), randf(), randf(), 0.5) # Generate a random color |
| 67 | 65 | hyperedge_instance.color = color |
| 68 | 66 | add_child(hyperedge_instance) |
| 69 | ||
| 70 | 67 | |
| 71 | ||
| 72 | ||
| 73 | ||
| 74 | ||
| 75 | 68 | |
| 76 | 69 | func _ready(): |
| 77 | 70 | nodes = read_file("patterns.txt") |
| … | … | @@ -1,6 +1,7 @@ |
| 1 | [gd_scene load_steps=2 format=3 uid="uid://2f8fvrck2f38"] | |
| 1 | [gd_scene load_steps=3 format=3 uid="uid://2f8fvrck2f38"] | |
| 2 | 2 | |
| 3 | 3 | [ext_resource type="Script" path="res://main.gd" id="1_1hwno"] |
| 4 | [ext_resource type="Script" path="res://Camera2D.gd" id="2_iiqxp"] | |
| 4 | 5 | |
| 5 | 6 | [node name="Node2D" type="Node2D"] |
| 6 | 7 | script = ExtResource("1_1hwno") |
| … | … | @@ -19,3 +20,6 @@ visible = false |
| 19 | 20 | offset_right = 195.0 |
| 20 | 21 | offset_bottom = 401.0 |
| 21 | 22 | color = Color(0.0980392, 0.0980392, 0.0980392, 1) |
| 23 | ||
| 24 | [node name="Camera2D" type="Camera2D" parent="."] | |
| 25 | script = ExtResource("2_iiqxp") |