feat: added info popups to photos

This commit is contained in:
Sara Gerretsen 2025-11-03 17:08:33 +01:00
parent b9b2d0a249
commit bda07f9d13
3 changed files with 34 additions and 1 deletions

View file

@ -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

View file

@ -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<RichTextLabel>(get_node(NodePath("%HoverLabel"))))) {
set_clue(get_clue());
}
}
void PinnedPhoto::on_child_entered_tree(Node *node) {
if (MeshInstance2D * meshinst{ cast_to<MeshInstance2D>(node) }) {
this->photo_mesh = meshinst;
set_clue(get_clue()); // force reset clue to update image
} else if (PanelContainer * container{ cast_to<PanelContainer>(node) }) {
this->popup_container = container;
container->set_visible(false);
}
}
@ -39,6 +46,7 @@ void PinnedPhoto::on_input_event(Viewport *viewport, Ref<InputEvent> 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<InputEvent> 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<Texture2D> 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 {

View file

@ -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<ConclusionField *> near_fields{};
RichTextLabel *popup_label{ nullptr };
PanelContainer *popup_container{ nullptr };
};