From f8c05fffb1c54acff868b18215d511c8d2171c9d Mon Sep 17 00:00:00 2001 From: Sebastian Morr Date: Wed, 18 Mar 2020 16:28:48 +0100 Subject: [PATCH] Show content on hover --- main.gd | 5 +++-- node.gd | 13 ++++++++++++- node.tscn | 25 ++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/main.gd b/main.gd index f9ca184..c0001d3 100644 --- a/main.gd +++ b/main.gd @@ -9,6 +9,7 @@ func _ready(): var n = node.instance() n.id = o n.type = object_type(o) + n.content = object_content(o) var viewport_size = get_viewport_rect().size n.position = Vector2(rand_range(0, viewport_size.x), rand_range(0, viewport_size.y)) @@ -38,8 +39,8 @@ func _ready(): func git(args, splitlines = false): var output = [] var a = args.split(" ") - #a.insert(0, "-C") - #a.insert(1, "/home/seb/tmp/godotgit") + a.insert(0, "-C") + a.insert(1, "/home/seb/tmp/godotgit") #print ("Running: ", a) OS.execute("git", a, true, output, true) var o = output[0] diff --git a/node.gd b/node.gd index 7124958..d3082c7 100644 --- a/node.gd +++ b/node.gd @@ -1,7 +1,7 @@ extends Node2D var id setget id_set - +var content setget content_set var type setget type_set var children = [] setget children_set @@ -17,6 +17,10 @@ func _process(delta): func id_set(new_id): id = new_id $ID.text = id + +func content_set(new_content): + content = new_content + $Content.text = content func type_set(new_type): type = new_type @@ -38,3 +42,10 @@ func children_set(new_children): a.label = "test" a.target = c add_child(a) + +func _on_hover(): + $Content.visible = true + +func _on_unhover(): + $Content.visible = false + diff --git a/node.tscn b/node.tscn index fdf21fa..f44be40 100644 --- a/node.tscn +++ b/node.tscn @@ -1,7 +1,10 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=3 format=2] [ext_resource path="res://node.gd" type="Script" id=1] +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 69.1778, 29.9015 ) + [node name="Node" type="Node2D"] script = ExtResource( 1 ) @@ -10,6 +13,7 @@ margin_left = -62.0578 margin_top = -20.6286 margin_right = 61.9422 margin_bottom = 21.3714 +mouse_filter = 2 __meta__ = { "_edit_use_anchors_": false } @@ -25,3 +29,22 @@ align = 1 __meta__ = { "_edit_use_anchors_": false } + +[node name="Content" type="Label" parent="."] +visible = false +margin_left = -57.0 +margin_top = 29.0 +margin_right = 250.0 +margin_bottom = 238.0 +custom_colors/font_color = Color( 0, 0, 0, 1 ) +text = "content" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Area" type="Area2D" parent="."] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Area"] +shape = SubResource( 1 ) +[connection signal="mouse_entered" from="Area" to="." method="_on_hover"] +[connection signal="mouse_exited" from="Area" to="." method="_on_unhover"]