feat: implemented pinboard mechanic

This commit is contained in:
Sara Gerretsen 2025-10-30 16:26:27 +01:00
parent ac70e60dc2
commit de854910ee
7 changed files with 147 additions and 4 deletions

View file

@ -1,8 +1,56 @@
#include "pinned_photo.h"
#include "core/config/engine.h"
#include "core/input/input_event.h"
#include "macros.h"
void PinnedPhoto::_bind_methods() {
BIND_PROPERTY(Variant::BOOL, can_drop);
BIND_HPROPERTY(Variant::INT, clue, PROPERTY_HINT_ENUM, NetworkData::ClueID_hint());
}
void PinnedPhoto::enter_tree() {
connect("input_event", callable_mp(this, &self_type::on_input_event));
}
void PinnedPhoto::process(double delta) {
if (this->is_held) {
set_global_position(get_global_mouse_position());
}
}
void PinnedPhoto::on_input_event(Viewport *viewport, Ref<InputEvent> event, int shape) {
Ref<InputEventMouseButton> button{ event };
if (button.is_valid() && button->is_pressed()) {
this->is_held = true;
viewport->set_input_as_handled();
}
}
void PinnedPhoto::unhandled_input(Ref<InputEvent> const &event) {
Ref<InputEventMouseButton> button{ event };
if (button.is_valid() && this->can_drop && button->is_released()) {
this->is_held = false;
get_viewport()->set_input_as_handled();
}
}
void PinnedPhoto::_notification(int what) {
if (Engine::get_singleton()->is_editor_hint()) {
return;
}
switch (what) {
default:
return;
case NOTIFICATION_ENTER_TREE:
set_process(true);
set_pickable(true);
set_process_unhandled_input(true);
enter_tree();
return;
case NOTIFICATION_PROCESS:
process(get_process_delta_time());
return;
}
}
void PinnedPhoto::set_can_drop(bool value) {
@ -12,3 +60,11 @@ void PinnedPhoto::set_can_drop(bool value) {
bool PinnedPhoto::get_can_drop() const {
return this->can_drop;
}
void PinnedPhoto::set_clue(NetworkData::ClueID id) {
this->clue = id;
}
NetworkData::ClueID PinnedPhoto::get_clue() const {
return this->clue;
}