diff --git a/inv_system/item_slot.gd b/inv_system/item_slot.gd index 7c404a1..5df56c0 100644 --- a/inv_system/item_slot.gd +++ b/inv_system/item_slot.gd @@ -44,3 +44,15 @@ func _drop_data(at_position: Vector2, data: Variant) -> void: data.icon.show() update_ui() data.update_ui() + + +func _on_mouse_entered() -> void: + print("im real?") + if item: + Tooltip.show_tip(item.item_name) + pass # Replace with function body. + + +func _on_mouse_exited() -> void: + Tooltip.hide_tip() + pass # Replace with function body. diff --git a/inv_system/item_slot.tscn b/inv_system/item_slot.tscn index 18f5256..20fd246 100644 --- a/inv_system/item_slot.tscn +++ b/inv_system/item_slot.tscn @@ -28,6 +28,7 @@ expand_mode = 3 stretch_mode = 4 [node name="Label" type="Label" parent="Icon"] +visible = false layout_mode = 1 anchors_preset = 7 anchor_left = 0.5 @@ -43,3 +44,6 @@ grow_vertical = 0 text = "120 GB" label_settings = SubResource("LabelSettings_ab1u2") horizontal_alignment = 2 + +[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"] +[connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"] diff --git a/project.godot b/project.godot index 69209bf..13296cb 100644 --- a/project.godot +++ b/project.godot @@ -15,6 +15,10 @@ run/main_scene="uid://dsfal3m4siap2" config/features=PackedStringArray("4.5", "GL Compatibility") config/icon="res://icon.svg" +[autoload] + +Tooltip="*res://tooltip.tscn" + [rendering] renderer/rendering_method="gl_compatibility" diff --git a/test.tscn b/test.tscn index bcdd048..083a901 100644 --- a/test.tscn +++ b/test.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=12 format=3 uid="uid://dsfal3m4siap2"] +[gd_scene load_steps=11 format=3 uid="uid://dsfal3m4siap2"] [ext_resource type="Script" uid="uid://c6oycdae5wvjf" path="res://inv_system/inventory.gd" id="1_6uqi0"] [ext_resource type="Texture2D" uid="uid://dj487wauiay6i" path="res://assets/ewase bins.png" id="1_g14j6"] @@ -10,9 +10,9 @@ [ext_resource type="Resource" uid="uid://88v5bcyrgpob" path="res://items/large_psu_item.tres" id="6_77dp3"] [ext_resource type="Resource" uid="uid://swd1m0hvep4c" path="res://items/small_psu_item.tres" id="7_5tkv4"] [ext_resource type="PackedScene" uid="uid://dgqs20xf7l8c" path="res://inv_system/item_slot.tscn" id="7_xersf"] -[ext_resource type="Script" uid="uid://cbta38dhunndc" path="res://tooltip.gd" id="11_77dp3"] [node name="Control" type="Control" node_paths=PackedStringArray("bin_inventory", "loot_button")] +z_index = -1 layout_mode = 3 anchors_preset = 15 anchor_right = 1.0 @@ -192,19 +192,4 @@ grow_horizontal = 2 grow_vertical = 0 text = "Return to workshop" -[node name="Tooltip" type="PanelContainer" parent="." node_paths=PackedStringArray("tooltip_label")] -layout_mode = 1 -offset_right = 161.0 -offset_bottom = 40.0 -mouse_filter = 2 -script = ExtResource("11_77dp3") -tooltip_label = NodePath("VBoxContainer/Label") - -[node name="VBoxContainer" type="VBoxContainer" parent="Tooltip"] -layout_mode = 2 - -[node name="Label" type="Label" parent="Tooltip/VBoxContainer"] -layout_mode = 2 -text = "Item Name" - [connection signal="pressed" from="LootButton" to="." method="_on_loot_button_pressed"] diff --git a/tooltip.gd b/tooltip.gd index fa11a57..645805c 100644 --- a/tooltip.gd +++ b/tooltip.gd @@ -9,4 +9,12 @@ func _ready() -> void: # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta: float) -> void: - global_position = get_global_mouse_position() + Vector2(1,1) + global_position = get_global_mouse_position() + Vector2(12,-6) + +func show_tip(text : String): + tooltip_label.text = text + show() + +func hide_tip(): + hide() + pass diff --git a/tooltip.tscn b/tooltip.tscn new file mode 100644 index 0000000..f2bf746 --- /dev/null +++ b/tooltip.tscn @@ -0,0 +1,41 @@ +[gd_scene load_steps=4 format=3 uid="uid://sb2wq874p37j"] + +[ext_resource type="Script" uid="uid://cbta38dhunndc" path="res://tooltip.gd" id="1_gwequ"] + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_gwequ"] +content_margin_left = 4.0 +content_margin_top = 4.0 +content_margin_right = 4.0 +content_margin_bottom = 4.0 +bg_color = Color(0.101960786, 0.101960786, 0.101960786, 0.8784314) +border_width_left = 2 +border_width_top = 2 +border_width_right = 2 +border_width_bottom = 2 +corner_radius_top_left = 3 +corner_radius_top_right = 3 +corner_radius_bottom_right = 3 +corner_radius_bottom_left = 3 + +[sub_resource type="LabelSettings" id="LabelSettings_oxk8h"] + +[node name="Tooltip" type="PanelContainer" node_paths=PackedStringArray("tooltip_label")] +offset_right = 95.0 +offset_bottom = 31.0 +size_flags_horizontal = 0 +size_flags_vertical = 0 +mouse_filter = 2 +theme_override_styles/panel = SubResource("StyleBoxFlat_gwequ") +script = ExtResource("1_gwequ") +tooltip_label = NodePath("VBoxContainer/Label") + +[node name="VBoxContainer" type="VBoxContainer" parent="."] +layout_mode = 2 +size_flags_horizontal = 0 +size_flags_vertical = 0 + +[node name="Label" type="Label" parent="VBoxContainer"] +layout_mode = 2 +size_flags_vertical = 6 +text = "Item Name" +label_settings = SubResource("LabelSettings_oxk8h")