fix: only one photo can be held at any time
This commit is contained in:
parent
bd5b459725
commit
956f21fd0e
2 changed files with 7 additions and 4 deletions
|
|
@ -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<InputEvent> event, int shape) {
|
||||
Ref<InputEventMouseButton> 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<InputEvent> const &event) {
|
|||
Ref<InputEventMouseButton> 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<InputEvent> 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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue