mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-22 05:23:32 +03:00
Refactor arrow scene, give it reversibility and color
This commit is contained in:
parent
6b612c083d
commit
25d8905df8
@ -1,12 +1,13 @@
|
||||
extends Node2D
|
||||
|
||||
var source: String
|
||||
var target: String
|
||||
var target: String setget set_target
|
||||
var color = Color("333333") setget set_color
|
||||
|
||||
var repository: Control
|
||||
|
||||
func _ready():
|
||||
pass
|
||||
set_color(color)
|
||||
|
||||
func _process(_delta):
|
||||
position = Vector2(0,0)
|
||||
@ -15,28 +16,35 @@ func _process(_delta):
|
||||
return
|
||||
|
||||
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 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()
|
||||
var parent_position = get_parent().get_parent().position
|
||||
|
||||
$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[1]
|
||||
$Tip.rotation = PI+$Line.points[0].angle_to($Line.points[1])
|
||||
var show_arrow = repository.objects.has(target) and repository.objects[target].visible and repository.objects[source].visible and repository.objects[source].type != "head"
|
||||
|
||||
if repository.objects[source].type == "head":
|
||||
$Tip.hide()
|
||||
$Line.hide()
|
||||
if show_arrow:
|
||||
end = repository.objects[target].position
|
||||
$Target.hide()
|
||||
|
||||
$Line.visible = show_arrow
|
||||
$Tip.visible = show_arrow
|
||||
|
||||
if $Target.text.substr(0, 5) != "refs/":
|
||||
$Target.text = ""
|
||||
|
||||
$Line.points[0] = start - parent_position
|
||||
$Line.points[1] = end - parent_position
|
||||
|
||||
#$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.rotation = PI + atan2($Line.points[0].y - $Line.points[1].y, $Line.points[0].x - $Line.points[1].x)
|
||||
|
||||
func set_color(new_color):
|
||||
color = new_color
|
||||
$Line.default_color = new_color
|
||||
$Tip/Polygon.color = new_color
|
||||
|
||||
func set_target(new_target):
|
||||
target = new_target
|
||||
$Target.text = new_target
|
||||
|
@ -19,14 +19,7 @@ z_index = 1
|
||||
position = Vector2( -24.7164, -6.37881 )
|
||||
z_index = -1
|
||||
color = Color( 0.2, 0.2, 0.2, 1 )
|
||||
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 )
|
||||
polygon = PoolVector2Array( -4.87012, 27.2617, 39.7077, 6.0953, -4.87012, -15.0711 )
|
||||
|
||||
[node name="Label" type="Node2D" parent="."]
|
||||
visible = false
|
||||
|
@ -15,7 +15,6 @@ var hovered = false
|
||||
var start_pos = null
|
||||
|
||||
var arrow = preload("res://scenes/arrow.tscn")
|
||||
var time_arrow = preload("res://scenes/time_arrow.tscn")
|
||||
|
||||
func _ready():
|
||||
content_set(content)
|
||||
@ -101,9 +100,13 @@ func children_set(new_children):
|
||||
if not children.has(c):
|
||||
var a = arrow.instance()
|
||||
if type == "commit":
|
||||
a = time_arrow.instance()
|
||||
a.source = id
|
||||
a.target = c
|
||||
#a = time_arrow.instance()
|
||||
a.source = c
|
||||
a.target = id
|
||||
a.color = Color("c2bf26")
|
||||
else:
|
||||
a.source = id
|
||||
a.target = c
|
||||
a.repository = repository
|
||||
$Arrows.add_child(a)
|
||||
children = new_children
|
||||
|
@ -25,6 +25,7 @@ corner_radius_bottom_left = 5
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="Arrows" type="Node2D" parent="."]
|
||||
z_index = -1
|
||||
|
||||
[node name="Rect" type="ColorRect" parent="."]
|
||||
visible = false
|
||||
|
@ -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
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user