Refactor arrow scene, give it reversibility and color

This commit is contained in:
Sebastian Morr 2020-10-29 16:59:46 +01:00
parent 6b612c083d
commit 25d8905df8
6 changed files with 41 additions and 138 deletions

View file

@ -1,12 +1,13 @@
extends Node2D extends Node2D
var source: String var source: String
var target: String var target: String setget set_target
var color = Color("333333") setget set_color
var repository: Control var repository: Control
func _ready(): func _ready():
pass set_color(color)
func _process(_delta): func _process(_delta):
position = Vector2(0,0) position = Vector2(0,0)
@ -15,28 +16,35 @@ func _process(_delta):
return return
var start = repository.objects[source].position var start = repository.objects[source].position
var end = start + Vector2(0, 60) var end = start
if repository and repository.objects.has(target) and repository.objects[target].visible: var parent_position = get_parent().get_parent().position
var t = repository.objects[target]
end = t.position var show_arrow = repository.objects.has(target) and repository.objects[target].visible and repository.objects[source].visible and repository.objects[source].type != "head"
if show_arrow:
end = repository.objects[target].position
$Target.hide() $Target.hide()
$Line.show()
$Tip.show() $Line.visible = show_arrow
else: $Tip.visible = show_arrow
$Target.text = target
if $Target.text.substr(0, 5) != "refs/": if $Target.text.substr(0, 5) != "refs/":
$Target.text = "" $Target.text = ""
$Target.show()
$Line.hide()
$Tip.hide()
$Line.points[1] = end - repository.objects[source].position $Line.points[0] = start - parent_position
# Move the tip away from the object a bit. $Line.points[1] = end - parent_position
$Line.points[1] -= $Line.points[1].normalized()*30
#$Line.points[0] += ($Line.points[1] - $Line.points[0]).normalized()*30
$Line.points[1] -= ($Line.points[1] - $Line.points[0]).normalized()*30
$Tip.position = $Line.points[1] $Tip.position = $Line.points[1]
$Tip.rotation = PI+$Line.points[0].angle_to($Line.points[1]) $Tip.rotation = PI + atan2($Line.points[0].y - $Line.points[1].y, $Line.points[0].x - $Line.points[1].x)
if repository.objects[source].type == "head": func set_color(new_color):
$Tip.hide() color = new_color
$Line.hide() $Line.default_color = new_color
$Tip/Polygon.color = new_color
func set_target(new_target):
target = new_target
$Target.text = new_target

View file

@ -19,14 +19,7 @@ z_index = 1
position = Vector2( -24.7164, -6.37881 ) position = Vector2( -24.7164, -6.37881 )
z_index = -1 z_index = -1
color = Color( 0.2, 0.2, 0.2, 1 ) color = Color( 0.2, 0.2, 0.2, 1 )
polygon = PoolVector2Array( -8.50021, 20.4619, 36.1874, 8.44903, 0.869781, -21.8232 ) polygon = PoolVector2Array( -4.87012, 27.2617, 39.7077, 6.0953, -4.87012, -15.0711 )
[node name="Polygon2" type="Polygon2D" parent="Tip"]
visible = false
position = Vector2( -9.66138, -2.89842 )
z_index = -1
color = Color( 0.2, 0.2, 0.2, 1 )
polygon = PoolVector2Array( -8.50021, 20.4619, 22.2526, 5.80623, 2.31131, -19.9012, -12.104, -23.7453, 4.95413, 1.72188, -21.9546, 16.1372 )
[node name="Label" type="Node2D" parent="."] [node name="Label" type="Node2D" parent="."]
visible = false visible = false

View file

@ -15,7 +15,6 @@ var hovered = false
var start_pos = null var start_pos = null
var arrow = preload("res://scenes/arrow.tscn") var arrow = preload("res://scenes/arrow.tscn")
var time_arrow = preload("res://scenes/time_arrow.tscn")
func _ready(): func _ready():
content_set(content) content_set(content)
@ -101,7 +100,11 @@ func children_set(new_children):
if not children.has(c): if not children.has(c):
var a = arrow.instance() var a = arrow.instance()
if type == "commit": if type == "commit":
a = time_arrow.instance() #a = time_arrow.instance()
a.source = c
a.target = id
a.color = Color("c2bf26")
else:
a.source = id a.source = id
a.target = c a.target = c
a.repository = repository a.repository = repository

View file

@ -25,6 +25,7 @@ corner_radius_bottom_left = 5
script = ExtResource( 2 ) script = ExtResource( 2 )
[node name="Arrows" type="Node2D" parent="."] [node name="Arrows" type="Node2D" parent="."]
z_index = -1
[node name="Rect" type="ColorRect" parent="."] [node name="Rect" type="ColorRect" parent="."]
visible = false visible = false

View file

@ -1,39 +0,0 @@
extends Node2D
var source: String
var target: String
var repository: Control
func _ready():
pass
func _process(_delta):
position = Vector2(0,0)
if not (repository and repository.objects.has(source)):
return
var start = repository.objects[source].position
var end = start + Vector2(0, 60)
if repository and repository.objects.has(target) and repository.objects[target].visible:
var t = repository.objects[target]
end = t.position
$Target.hide()
$Line.show()
$Tip.show()
else:
$Target.text = target
if $Target.text.substr(0, 5) != "refs/":
$Target.text = ""
$Target.show()
$Line.hide()
$Tip.hide()
$Line.points[1] = end - repository.objects[source].position
# Move the tip away from the object a bit.
#$Line.points[1] -= $Line.points[1].normalized()*30
#$Tip.position = $Line.points[0]
#$Tip.rotation = PI+$Line.points[1].angle_to($Line.points[0])
$Tip.rotation = PI-$Line.points[1].angle_to($Line.points[0])+0.25

View file

@ -1,63 +0,0 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://fonts/default.tres" type="DynamicFont" id=1]
[ext_resource path="res://scenes/time_arrow.gd" type="Script" id=2]
[node name="Arrow" type="Node2D"]
show_behind_parent = true
script = ExtResource( 2 )
[node name="Line" type="Line2D" parent="."]
z_index = -1
points = PoolVector2Array( -0.480499, -0.11055, 158.301, 0.581757 )
default_color = Color( 0.760784, 0.74902, 0.14902, 1 )
[node name="Tip" type="Node2D" parent="."]
position = Vector2( 0.175903, -0.0836948 )
rotation = -0.0733038
z_index = 1
[node name="Polygon" type="Polygon2D" parent="Tip"]
position = Vector2( -0.0332336, 0.422104 )
rotation = 2.86234
z_index = -1
color = Color( 0.760784, 0.74902, 0.14902, 1 )
offset = Vector2( -52.4162, -12.5157 )
polygon = PoolVector2Array( -8.50021, 20.4619, 36.1874, 8.44903, 0.869781, -21.8232 )
[node name="Polygon2" type="Polygon2D" parent="Tip"]
visible = false
position = Vector2( -9.66138, -2.89842 )
z_index = -1
color = Color( 0.2, 0.2, 0.2, 1 )
polygon = PoolVector2Array( -8.50021, 20.4619, 22.2526, 5.80623, 2.31131, -19.9012, -12.104, -23.7453, 4.95413, 1.72188, -21.9546, 16.1372 )
[node name="Label" type="Node2D" parent="."]
visible = false
position = Vector2( 102, 46 )
[node name="ID" type="Label" parent="Label"]
margin_left = -19.374
margin_top = -5.93085
margin_right = 20.626
margin_bottom = 8.06915
custom_fonts/font = ExtResource( 1 )
custom_colors/font_color = Color( 1, 1, 1, 1 )
text = "label"
align = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Target" type="Label" parent="."]
margin_left = -230.84
margin_top = 42.1225
margin_right = 231.16
margin_bottom = 68.1225
custom_fonts/font = ExtResource( 1 )
custom_colors/font_color = Color( 0.356863, 0.356863, 0.356863, 1 )
text = "label"
align = 1
__meta__ = {
"_edit_use_anchors_": false
}