From 956f21fd0e437c45a10a96f02f2379f76a5c3370 Mon Sep 17 00:00:00 2001 From: Sara Date: Thu, 6 Nov 2025 02:20:54 +0100 Subject: [PATCH] fix: only one photo can be held at any time --- modules/you_done_it/pinned_photo.cpp | 10 ++++++---- modules/you_done_it/pinned_photo.h | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/you_done_it/pinned_photo.cpp b/modules/you_done_it/pinned_photo.cpp index aec43c5d..52f9a2f8 100644 --- a/modules/you_done_it/pinned_photo.cpp +++ b/modules/you_done_it/pinned_photo.cpp @@ -8,6 +8,8 @@ #include "you_done_it/conclusion_field.h" #include "you_done_it/ydi_networking.h" +bool PinnedPhoto::a_photo_is_held{}; + String const PinnedPhoto::sig_grabbed{ "grabbed" }; String const PinnedPhoto::sig_released{ "released" }; @@ -44,8 +46,8 @@ void PinnedPhoto::process(double delta) { void PinnedPhoto::on_input_event(Viewport *viewport, Ref event, int shape) { Ref button{ event }; - if (!this->is_held && button.is_valid() && button->is_pressed()) { - this->is_held = true; + if (!a_photo_is_held && !this->is_held && button.is_valid() && button->is_pressed()) { + a_photo_is_held = this->is_held = true; viewport->set_input_as_handled(); if (this->conclusion_field) { this->conclusion_field->notify_photo_picked(this); @@ -62,7 +64,7 @@ void PinnedPhoto::unhandled_input(Ref const &event) { Ref button{ event }; if (this->is_held && button.is_valid() && button->is_released()) { if (!this->near_fields.is_empty()) { - this->is_held = false; + a_photo_is_held = this->is_held = false; this->conclusion_field = this->near_fields[this->near_fields.size() - 1]; this->conclusion_field->notify_photo_dropped(this); get_viewport()->set_input_as_handled(); @@ -71,7 +73,7 @@ void PinnedPhoto::unhandled_input(Ref const &event) { this->popup_container->set_visible(false); emit_signal(sig_released); } else if (this->can_drop) { - this->is_held = false; + a_photo_is_held = this->is_held = false; get_viewport()->set_input_as_handled(); set_global_rotation(0.0); this->popup_container->set_visible(false); diff --git a/modules/you_done_it/pinned_photo.h b/modules/you_done_it/pinned_photo.h index 0596944d..5abc4114 100644 --- a/modules/you_done_it/pinned_photo.h +++ b/modules/you_done_it/pinned_photo.h @@ -12,6 +12,7 @@ class ConclusionField; class PinnedPhoto : public AnimatableBody2D { GDCLASS(PinnedPhoto, AnimatableBody2D); static void _bind_methods(); + static bool a_photo_is_held; void enter_tree(); void on_child_entered_tree(Node *node); void process(double delta);