From bda07f9d138c9fb43e2620b832591ab712149553 Mon Sep 17 00:00:00 2001 From: Sara Date: Mon, 3 Nov 2025 17:08:33 +0100 Subject: [PATCH] feat: added info popups to photos --- flatscreen-project/objects/pinned_photo.tscn | 13 +++++++++++++ modules/you_done_it/pinned_photo.cpp | 18 +++++++++++++++++- modules/you_done_it/pinned_photo.h | 4 ++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/flatscreen-project/objects/pinned_photo.tscn b/flatscreen-project/objects/pinned_photo.tscn index 2207acc1..9a679e77 100644 --- a/flatscreen-project/objects/pinned_photo.tscn +++ b/flatscreen-project/objects/pinned_photo.tscn @@ -20,3 +20,16 @@ texture = SubResource("ImageTexture_usqe2") [node name="CollisionShape2D" type="CollisionShape2D" parent="."] position = Vector2(0, 73) shape = SubResource("RectangleShape2D_usqe2") + +[node name="PanelContainer" type="PanelContainer" parent="."] +z_index = 1 +offset_left = -252.0 +offset_top = -12.0 +offset_right = -88.0 +offset_bottom = 157.0 + +[node name="HoverLabel" type="RichTextLabel" parent="PanelContainer"] +unique_name_in_owner = true +layout_mode = 2 +text = "PLACEHOLDER TOOLTIP" +fit_content = true diff --git a/modules/you_done_it/pinned_photo.cpp b/modules/you_done_it/pinned_photo.cpp index 690456b3..c49dc061 100644 --- a/modules/you_done_it/pinned_photo.cpp +++ b/modules/you_done_it/pinned_photo.cpp @@ -3,6 +3,7 @@ #include "core/input/input_event.h" #include "macros.h" #include "scene/2d/mesh_instance_2d.h" +#include "scene/gui/rich_text_label.h" #include "you_done_it/clue_db.h" #include "you_done_it/conclusion_field.h" #include "you_done_it/ydi_networking.h" @@ -15,12 +16,18 @@ void PinnedPhoto::_bind_methods() { void PinnedPhoto::enter_tree() { connect("input_event", callable_mp(this, &self_type::on_input_event)); connect("child_entered_tree", callable_mp(this, &self_type::on_child_entered_tree)); + if ((this->popup_label = cast_to(get_node(NodePath("%HoverLabel"))))) { + set_clue(get_clue()); + } } void PinnedPhoto::on_child_entered_tree(Node *node) { if (MeshInstance2D * meshinst{ cast_to(node) }) { this->photo_mesh = meshinst; set_clue(get_clue()); // force reset clue to update image + } else if (PanelContainer * container{ cast_to(node) }) { + this->popup_container = container; + container->set_visible(false); } } @@ -39,6 +46,7 @@ void PinnedPhoto::on_input_event(Viewport *viewport, Ref event, int this->conclusion_field->notify_photo_picked(this); this->conclusion_field = nullptr; } + this->popup_container->set_visible(true); } } @@ -52,10 +60,12 @@ void PinnedPhoto::unhandled_input(Ref const &event) { get_viewport()->set_input_as_handled(); set_global_position(this->conclusion_field->get_global_position()); set_global_rotation(this->conclusion_field->get_global_rotation()); + this->popup_container->set_visible(false); } else if (this->can_drop) { this->is_held = false; get_viewport()->set_input_as_handled(); set_global_rotation(0.0); + this->popup_container->set_visible(false); } } } @@ -97,12 +107,18 @@ bool PinnedPhoto::get_can_drop() const { void PinnedPhoto::set_clue(NetworkData::ClueID id) { this->clue = id; - if (photo_mesh && this->clue != NetworkData::CLUE_MAX) { + if (this->clue == NetworkData::CLUE_MAX) { + return; + } + if (this->photo_mesh) { Ref texture{ ClueDB::get_singleton()->get_clue(id)->get_image() }; if (texture.is_valid()) { photo_mesh->set_texture(texture); } } + if (this->popup_label) { + this->popup_label->set_text(ClueDB::get_singleton()->get_clue(id)->get_popup_text()); + } } NetworkData::ClueID PinnedPhoto::get_clue() const { diff --git a/modules/you_done_it/pinned_photo.h b/modules/you_done_it/pinned_photo.h index c2c16ed4..d2827bde 100644 --- a/modules/you_done_it/pinned_photo.h +++ b/modules/you_done_it/pinned_photo.h @@ -3,6 +3,8 @@ #include "core/input/input_event.h" #include "scene/2d/mesh_instance_2d.h" #include "scene/2d/physics/animatable_body_2d.h" +#include "scene/gui/panel_container.h" +#include "scene/gui/rich_text_label.h" #include "scene/main/viewport.h" #include "you_done_it/ydi_networking.h" class ConclusionField; @@ -34,4 +36,6 @@ private: bool is_held{ false }; ConclusionField *conclusion_field{}; Vector near_fields{}; + RichTextLabel *popup_label{ nullptr }; + PanelContainer *popup_container{ nullptr }; };