feat: implemented interaction tooltips
This commit is contained in:
parent
34db607145
commit
2511ac69c0
|
@ -4,12 +4,17 @@ HeadsUpDisplay *HeadsUpDisplay::singleton_instance{ nullptr };
|
||||||
|
|
||||||
void HeadsUpDisplay::_bind_methods() {
|
void HeadsUpDisplay::_bind_methods() {
|
||||||
ClassDB::bind_static_method("HeadsUpDisplay", D_METHOD("get_singleton"), &self_type::get_singleton);
|
ClassDB::bind_static_method("HeadsUpDisplay", D_METHOD("get_singleton"), &self_type::get_singleton);
|
||||||
|
ClassDB::bind_method(D_METHOD("set_tooltip"), &self_type::set_tooltip);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeadsUpDisplay::on_child_entered(Node *child) {
|
void HeadsUpDisplay::on_child_entered(Node *child) {
|
||||||
|
child->connect("child_entered_tree", callable_mp(this, &self_type::on_child_entered));
|
||||||
if (child->is_unique_name_in_owner() && child->get_name() == "Reticle") {
|
if (child->is_unique_name_in_owner() && child->get_name() == "Reticle") {
|
||||||
this->reticle = cast_to<Control>(child);
|
this->reticle = cast_to<Control>(child);
|
||||||
}
|
}
|
||||||
|
if (child->is_unique_name_in_owner() && child->get_name() == "Tooltip") {
|
||||||
|
this->tooltip = cast_to<Label>(child);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeadsUpDisplay::enter_tree() {
|
void HeadsUpDisplay::enter_tree() {
|
||||||
|
@ -46,3 +51,7 @@ void HeadsUpDisplay::set_reticle_visibility(bool visible) {
|
||||||
this->reticle->set_visible(visible);
|
this->reticle->set_visible(visible);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HeadsUpDisplay::set_tooltip(String const &tooltip) {
|
||||||
|
this->tooltip->set_text(tooltip);
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define HEADS_UP_DISPLAY_H
|
#define HEADS_UP_DISPLAY_H
|
||||||
|
|
||||||
#include "scene/gui/control.h"
|
#include "scene/gui/control.h"
|
||||||
|
#include "scene/gui/label.h"
|
||||||
|
|
||||||
class HeadsUpDisplay : public Control {
|
class HeadsUpDisplay : public Control {
|
||||||
GDCLASS(HeadsUpDisplay, Control);
|
GDCLASS(HeadsUpDisplay, Control);
|
||||||
|
@ -17,9 +18,11 @@ protected:
|
||||||
public:
|
public:
|
||||||
static HeadsUpDisplay *get_singleton();
|
static HeadsUpDisplay *get_singleton();
|
||||||
void set_reticle_visibility(bool visible);
|
void set_reticle_visibility(bool visible);
|
||||||
|
void set_tooltip(String const &tooltip);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Control *reticle{ nullptr };
|
Control *reticle{ nullptr };
|
||||||
|
Label *tooltip{ nullptr };
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !HEADS_UP_DISPLAY_H
|
#endif // !HEADS_UP_DISPLAY_H
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "interactable.h"
|
#include "interactable.h"
|
||||||
|
#include "heads_up_display.h"
|
||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
|
|
||||||
void Interactable::_bind_methods() {
|
void Interactable::_bind_methods() {
|
||||||
|
@ -23,11 +24,3 @@ void Interactable::set_highlighted(PlayerInteractor *interactor, bool value) {
|
||||||
bool Interactable::get_highlighted() const {
|
bool Interactable::get_highlighted() const {
|
||||||
return this->highlighted;
|
return this->highlighted;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Interactable::set_highlight_tooltip(String value) {
|
|
||||||
this->highlight_tooltip = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
String Interactable::get_highlight_tooltip() const {
|
|
||||||
return this->highlight_tooltip;
|
|
||||||
}
|
|
||||||
|
|
|
@ -19,12 +19,9 @@ public:
|
||||||
|
|
||||||
void set_highlighted(PlayerInteractor *interactor, bool value);
|
void set_highlighted(PlayerInteractor *interactor, bool value);
|
||||||
bool get_highlighted() const;
|
bool get_highlighted() const;
|
||||||
void set_highlight_tooltip(String value);
|
|
||||||
String get_highlight_tooltip() const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool highlighted{ false };
|
bool highlighted{ false };
|
||||||
String highlight_tooltip{ "Activate" };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !INTERACTABLE_H
|
#endif // !INTERACTABLE_H
|
||||||
|
|
|
@ -19,6 +19,23 @@ anchor_bottom = 1.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
|
|
||||||
[node name="TextureRect" type="TextureRect" parent="CenterContainer"]
|
[node name="Reticle" type="TextureRect" parent="CenterContainer"]
|
||||||
|
unique_name_in_owner = true
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
texture = ExtResource("1_1o2rr")
|
texture = ExtResource("1_1o2rr")
|
||||||
|
|
||||||
|
[node name="Control" type="Control" parent="CenterContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="Tooltip" type="Label" parent="CenterContainer/Control"]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = 5
|
||||||
|
anchor_left = 0.5
|
||||||
|
anchor_right = 0.5
|
||||||
|
offset_left = -30.5
|
||||||
|
offset_right = 30.5
|
||||||
|
offset_bottom = 44.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
horizontal_alignment = 1
|
||||||
|
vertical_alignment = 2
|
||||||
|
|
|
@ -16,6 +16,11 @@
|
||||||
[sub_resource type="GDScript" id="GDScript_ug5on"]
|
[sub_resource type="GDScript" id="GDScript_ug5on"]
|
||||||
script/source = "extends Interactable
|
script/source = "extends Interactable
|
||||||
|
|
||||||
|
func _highlight_changed(_interactor: PlayerInteractor, value: bool) -> void:
|
||||||
|
var hud = HeadsUpDisplay.get_singleton()
|
||||||
|
if hud:
|
||||||
|
hud.set_tooltip(\"Demolish with demo pack\" if value else \"\")
|
||||||
|
|
||||||
func _activated(interactor):
|
func _activated(interactor):
|
||||||
if interactor.try_use_demo_pack():
|
if interactor.try_use_demo_pack():
|
||||||
get_parent().queue_free()
|
get_parent().queue_free()
|
||||||
|
@ -127,6 +132,9 @@ size = Vector3(5.24, 4.325, 8.29)
|
||||||
|
|
||||||
[node name="IndustrialAreaMap" type="Node3D"]
|
[node name="IndustrialAreaMap" type="Node3D"]
|
||||||
|
|
||||||
|
[node name="DemoPackPickup" parent="." instance=ExtResource("11_foo0w")]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -9.609407, 0.8542257, 2.3071413)
|
||||||
|
|
||||||
[node name="DestructableGate1" type="CSGBox3D" parent="."]
|
[node name="DestructableGate1" type="CSGBox3D" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -18.062351, 2.0328617, 5.9408145)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -18.062351, 2.0328617, 5.9408145)
|
||||||
use_collision = true
|
use_collision = true
|
||||||
|
@ -788,9 +796,6 @@ collision_layer = 3
|
||||||
mesh = SubResource("PrismMesh_foo0w")
|
mesh = SubResource("PrismMesh_foo0w")
|
||||||
material = ExtResource("4_fwhga")
|
material = ExtResource("4_fwhga")
|
||||||
|
|
||||||
[node name="DemoPackPickup" parent="Map" instance=ExtResource("11_foo0w")]
|
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -9.609407, 0.8542257, 2.3071413)
|
|
||||||
|
|
||||||
[node name="BrokenGate" type="CSGBox3D" parent="Map"]
|
[node name="BrokenGate" type="CSGBox3D" parent="Map"]
|
||||||
transform = Transform3D(0.9117334, 0.41078255, -2.3283064e-10, 0.0033696396, -0.0074789287, -0.9999664, -0.41076872, 0.91170275, -0.0082029775, -9.67504, 0.1504199, 7.5122595)
|
transform = Transform3D(0.9117334, 0.41078255, -2.3283064e-10, 0.0033696396, -0.0074789287, -0.9999664, -0.41076872, 0.91170275, -0.0082029775, -9.67504, 0.1504199, 7.5122595)
|
||||||
use_collision = true
|
use_collision = true
|
||||||
|
|
|
@ -6,6 +6,11 @@ radius = 0.1282442
|
||||||
[sub_resource type="GDScript" id="GDScript_kl827"]
|
[sub_resource type="GDScript" id="GDScript_kl827"]
|
||||||
script/source = "extends Interactable
|
script/source = "extends Interactable
|
||||||
|
|
||||||
|
func _highlight_changed(_interactor: PlayerInteractor, value: bool) -> void:
|
||||||
|
var hud := HeadsUpDisplay.get_singleton()
|
||||||
|
if hud:
|
||||||
|
hud.set_tooltip(\"Pick up Demolition Pack\" if value else \"\")
|
||||||
|
|
||||||
func _activated(interactor: PlayerInteractor) -> void:
|
func _activated(interactor: PlayerInteractor) -> void:
|
||||||
interactor.pickup_demo_pack()
|
interactor.pickup_demo_pack()
|
||||||
get_owner().queue_free()
|
get_owner().queue_free()
|
||||||
|
|
Loading…
Reference in a new issue