66 lines
1.8 KiB
C++
66 lines
1.8 KiB
C++
#include "conclusion_field.h"
|
|
#include "core/config/engine.h"
|
|
#include "you_done_it/pinned_photo.h"
|
|
#include "you_done_it/ydi_networking.h"
|
|
|
|
String const ConclusionField::sig_selection_changed{ "selection_changed" };
|
|
|
|
void ConclusionField::_bind_methods() {
|
|
ADD_SIGNAL(MethodInfo(sig_selection_changed, PropertyInfo(Variant::INT, "new_value", PROPERTY_HINT_ENUM, NetworkData::ClueID_hint())));
|
|
ClassDB::bind_method(D_METHOD("is_filled"), &self_type::is_filled);
|
|
ClassDB::bind_method(D_METHOD("get_current_clue"), &self_type::get_current_clue);
|
|
}
|
|
|
|
void ConclusionField::enter_tree() {
|
|
connect("body_entered", callable_mp(this, &self_type::on_body_entered));
|
|
connect("body_exited", callable_mp(this, &self_type::on_body_exited));
|
|
}
|
|
|
|
void ConclusionField::on_body_entered(Node2D *node) {
|
|
if (PinnedPhoto * photo{ cast_to<PinnedPhoto>(node) }) {
|
|
photo->push_conclusion_slot(this);
|
|
}
|
|
}
|
|
|
|
void ConclusionField::on_body_exited(Node2D *node) {
|
|
if (PinnedPhoto * photo{ cast_to<PinnedPhoto>(node) }) {
|
|
photo->pull_conclusion_slot(this);
|
|
}
|
|
}
|
|
|
|
void ConclusionField::_notification(int what) {
|
|
if (Engine::get_singleton()->is_editor_hint()) {
|
|
return;
|
|
}
|
|
switch (what) {
|
|
default:
|
|
return;
|
|
case NOTIFICATION_ENTER_TREE:
|
|
enter_tree();
|
|
return;
|
|
}
|
|
}
|
|
|
|
void ConclusionField::notify_photo_dropped(PinnedPhoto *photo) {
|
|
this->photo = photo;
|
|
emit_signal(sig_selection_changed, this->photo->get_clue());
|
|
}
|
|
|
|
void ConclusionField::notify_photo_picked(PinnedPhoto *photo) {
|
|
if (photo == this->photo) {
|
|
this->photo = nullptr;
|
|
emit_signal(sig_selection_changed, NetworkData::CLUE_MAX);
|
|
}
|
|
}
|
|
|
|
bool ConclusionField::is_filled() const {
|
|
return this->photo;
|
|
}
|
|
|
|
NetworkData::ClueID ConclusionField::get_current_clue() const {
|
|
if (!this->photo) {
|
|
return NetworkData::CLUE_MAX;
|
|
} else {
|
|
return photo->get_clue();
|
|
}
|
|
}
|