2020-03-18 18:20:55 +03:00
|
|
|
extends Node2D
|
|
|
|
|
|
|
|
var id setget id_set
|
2020-03-18 18:28:48 +03:00
|
|
|
var content setget content_set
|
2020-03-18 18:20:55 +03:00
|
|
|
var type setget type_set
|
2020-09-03 18:50:03 +03:00
|
|
|
var repository: Container
|
2020-03-18 18:20:55 +03:00
|
|
|
|
2020-03-18 22:03:17 +03:00
|
|
|
var children = {} setget children_set
|
2020-09-01 22:25:24 +03:00
|
|
|
var id_always_visible = false
|
2020-09-04 16:10:04 +03:00
|
|
|
var held = false
|
2020-09-21 19:53:36 +03:00
|
|
|
var hovered = false
|
2020-03-18 18:20:55 +03:00
|
|
|
|
|
|
|
var arrow = preload("res://arrow.tscn")
|
|
|
|
|
2020-09-15 19:41:06 +03:00
|
|
|
|
2020-03-18 18:20:55 +03:00
|
|
|
func _ready():
|
2020-08-24 17:48:30 +03:00
|
|
|
pass
|
2020-03-18 18:20:55 +03:00
|
|
|
|
2020-09-08 21:26:14 +03:00
|
|
|
func _process(_delta):
|
2020-09-04 16:10:04 +03:00
|
|
|
if held:
|
2020-09-21 19:33:34 +03:00
|
|
|
if not Input.is_action_pressed("click"):
|
|
|
|
held = false
|
|
|
|
else:
|
|
|
|
global_position = get_global_mouse_position()
|
2020-09-14 17:03:01 +03:00
|
|
|
|
|
|
|
if visible:
|
|
|
|
apply_forces()
|
|
|
|
|
|
|
|
func apply_forces():
|
2020-09-14 15:54:30 +03:00
|
|
|
var offset = Vector2(0, 80)
|
2020-09-14 17:03:01 +03:00
|
|
|
|
2020-08-24 17:48:30 +03:00
|
|
|
for c in children.keys():
|
2020-09-15 19:41:06 +03:00
|
|
|
if repository.objects.has(c):
|
|
|
|
var other = repository.objects[c]
|
2020-09-14 17:03:01 +03:00
|
|
|
if other.visible:
|
|
|
|
var d = other.position.distance_to(position+offset)
|
|
|
|
var dir = (other.position - (position+offset)).normalized()
|
|
|
|
var f = (d*0.03)
|
|
|
|
position += dir*f
|
|
|
|
other.position -= dir*f
|
2020-08-24 17:48:30 +03:00
|
|
|
|
2020-03-18 18:20:55 +03:00
|
|
|
func id_set(new_id):
|
2020-08-24 17:48:30 +03:00
|
|
|
id = new_id
|
|
|
|
$ID.text = id
|
|
|
|
|
2020-03-18 18:28:48 +03:00
|
|
|
func content_set(new_content):
|
2020-08-24 17:48:30 +03:00
|
|
|
content = new_content
|
|
|
|
$Content.text = content
|
2020-03-18 18:20:55 +03:00
|
|
|
|
|
|
|
func type_set(new_type):
|
2020-08-24 17:48:30 +03:00
|
|
|
type = new_type
|
|
|
|
if type != "ref":
|
|
|
|
$ID.text = $ID.text.substr(0,8)
|
2020-09-13 22:55:24 +03:00
|
|
|
#elif type == "ref":
|
|
|
|
#$ID.text = $ID.text.replace("refs/", "")
|
2020-08-24 17:48:30 +03:00
|
|
|
match new_type:
|
|
|
|
"blob":
|
2020-09-01 22:25:24 +03:00
|
|
|
$Rect.color = Color("#333333")
|
2020-08-24 17:48:30 +03:00
|
|
|
"tree":
|
|
|
|
$Rect.color = Color.darkgreen
|
|
|
|
"commit":
|
|
|
|
$Rect.color = Color.orange
|
|
|
|
"tag":
|
|
|
|
$Rect.color = Color.blue
|
|
|
|
"ref":
|
|
|
|
$Rect.color = Color("#6680ff")
|
2020-09-01 22:25:24 +03:00
|
|
|
id_always_visible = true
|
2020-08-24 17:48:30 +03:00
|
|
|
"head":
|
|
|
|
$Rect.color = Color.red
|
2020-09-01 22:25:24 +03:00
|
|
|
id_always_visible = true
|
|
|
|
if id_always_visible:
|
|
|
|
$ID.show()
|
2020-03-18 18:20:55 +03:00
|
|
|
|
|
|
|
func children_set(new_children):
|
2020-08-24 17:48:30 +03:00
|
|
|
for c in $Arrows.get_children():
|
|
|
|
if not new_children.has(c.target):
|
|
|
|
c.queue_free()
|
|
|
|
for c in new_children:
|
|
|
|
if not children.has(c):
|
|
|
|
var a = arrow.instance()
|
|
|
|
a.label = new_children[c]
|
|
|
|
a.target = c
|
2020-09-01 18:24:21 +03:00
|
|
|
a.repository = repository
|
2020-08-24 17:48:30 +03:00
|
|
|
$Arrows.add_child(a)
|
|
|
|
children = new_children
|
2020-03-18 18:28:48 +03:00
|
|
|
|
|
|
|
func _on_hover():
|
2020-09-21 19:53:36 +03:00
|
|
|
hovered = true
|
2020-09-21 20:28:39 +03:00
|
|
|
if not id_always_visible:
|
|
|
|
$Content.visible = true
|
|
|
|
$ID.visible = true
|
2020-08-24 17:48:30 +03:00
|
|
|
|
2020-03-18 18:28:48 +03:00
|
|
|
func _on_unhover():
|
2020-09-21 19:53:36 +03:00
|
|
|
hovered = false
|
2020-09-01 22:25:24 +03:00
|
|
|
if not id_always_visible:
|
|
|
|
$Content.visible = false
|
|
|
|
$ID.visible = false
|
2020-09-21 19:53:36 +03:00
|
|
|
|
|
|
|
func _input(event):
|
|
|
|
if hovered:
|
|
|
|
if event.is_action_pressed("click"):
|
|
|
|
held = true
|
|
|
|
if event.is_action_released("click"):
|
|
|
|
held = false
|
|
|
|
|
|
|
|
|
2020-09-08 21:26:14 +03:00
|
|
|
func _input_event(_viewport, event, _shape_idx):
|
2020-09-04 16:10:04 +03:00
|
|
|
if event is InputEventMouseButton:
|
|
|
|
if event.button_index == BUTTON_LEFT:
|
|
|
|
held = event.pressed
|
|
|
|
if event.button_index == BUTTON_RIGHT:
|
|
|
|
if event.pressed:
|
|
|
|
var input = get_tree().get_current_scene().find_node("Terminal").find_node("Control").find_node("Input")
|
2020-09-15 23:34:22 +03:00
|
|
|
input.text += id
|
2020-09-04 16:10:04 +03:00
|
|
|
input.caret_position = input.text.length()
|