feat: implemented pinboard mechanic
This commit is contained in:
parent
ac70e60dc2
commit
de854910ee
7 changed files with 147 additions and 4 deletions
|
|
@ -14,3 +14,9 @@ config/name="you_done_it"
|
|||
run/main_scene="uid://dosb4sb7pvss4"
|
||||
config/features=PackedStringArray("4.5", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[display]
|
||||
|
||||
window/size/viewport_width=1920
|
||||
window/size/viewport_height=1080
|
||||
window/stretch/mode="canvas_items"
|
||||
|
|
|
|||
|
|
@ -1,12 +1,52 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://dosb4sb7pvss4"]
|
||||
[gd_scene load_steps=8 format=3 uid="uid://dosb4sb7pvss4"]
|
||||
|
||||
[sub_resource type="QuadMesh" id="QuadMesh_usqe2"]
|
||||
|
||||
[sub_resource type="Gradient" id="Gradient_usqe2"]
|
||||
offsets = PackedFloat32Array(1)
|
||||
colors = PackedColorArray(0.7490196, 0.7019608, 0.6431373, 1)
|
||||
|
||||
[sub_resource type="GradientTexture1D" id="GradientTexture1D_87mh6"]
|
||||
gradient = SubResource("Gradient_usqe2")
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_87mh6"]
|
||||
size = Vector2(1288, 533)
|
||||
|
||||
[sub_resource type="QuadMesh" id="QuadMesh_87mh6"]
|
||||
|
||||
[sub_resource type="ImageTexture" id="ImageTexture_usqe2"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_usqe2"]
|
||||
size = Vector2(166, 172)
|
||||
|
||||
[node name="FlatscreenRoot" type="Node2D"]
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="."]
|
||||
anchor_mode = 0
|
||||
|
||||
[node name="MeshInstance2D" type="MeshInstance2D" parent="."]
|
||||
position = Vector2(142, -50)
|
||||
scale = Vector2(762.00006, 514)
|
||||
[node name="Pinboard" type="Pinboard" parent="."]
|
||||
position = Vector2(312, 19)
|
||||
|
||||
[node name="MeshInstance2D" type="MeshInstance2D" parent="Pinboard"]
|
||||
position = Vector2(794.49994, 417)
|
||||
scale = Vector2(1535.0001, 818)
|
||||
mesh = SubResource("QuadMesh_usqe2")
|
||||
texture = SubResource("GradientTexture1D_87mh6")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Pinboard"]
|
||||
position = Vector2(798, 465.5)
|
||||
shape = SubResource("RectangleShape2D_87mh6")
|
||||
|
||||
[node name="PinnedPhoto" type="PinnedPhoto" parent="."]
|
||||
position = Vector2(479, 904)
|
||||
input_pickable = true
|
||||
|
||||
[node name="MeshInstance2D" type="MeshInstance2D" parent="PinnedPhoto"]
|
||||
position = Vector2(0, 73.49998)
|
||||
scale = Vector2(162.00002, 168.99995)
|
||||
mesh = SubResource("QuadMesh_87mh6")
|
||||
texture = SubResource("ImageTexture_usqe2")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="PinnedPhoto"]
|
||||
position = Vector2(0, 73)
|
||||
shape = SubResource("RectangleShape2D_usqe2")
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "pinboard.h"
|
||||
#include "core/config/engine.h"
|
||||
#include "pinned_photo.h"
|
||||
|
||||
void Pinboard::_bind_methods() {
|
||||
|
|
@ -6,9 +7,30 @@ void Pinboard::_bind_methods() {
|
|||
|
||||
void Pinboard::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 Pinboard::on_body_entered(Node2D *node) {
|
||||
if (PinnedPhoto * photo{ cast_to<PinnedPhoto>(node) }) {
|
||||
photo->set_can_drop(true);
|
||||
}
|
||||
}
|
||||
|
||||
void Pinboard::on_body_exited(Node2D *node) {
|
||||
if (PinnedPhoto * photo{ cast_to<PinnedPhoto>(node) }) {
|
||||
photo->set_can_drop(false);
|
||||
}
|
||||
}
|
||||
|
||||
void Pinboard::_notification(int what) {
|
||||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
return;
|
||||
}
|
||||
switch (what) {
|
||||
default:
|
||||
return;
|
||||
case NOTIFICATION_ENTER_TREE:
|
||||
enter_tree();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ class Pinboard : public Area2D {
|
|||
static void _bind_methods();
|
||||
void enter_tree();
|
||||
void on_body_entered(Node2D *node);
|
||||
void on_body_exited(Node2D *node);
|
||||
|
||||
protected:
|
||||
void _notification(int what);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,29 @@
|
|||
#pragma once
|
||||
|
||||
#include "core/input/input_event.h"
|
||||
#include "scene/2d/physics/animatable_body_2d.h"
|
||||
#include "scene/main/viewport.h"
|
||||
#include "ydi_networking.h"
|
||||
|
||||
class PinnedPhoto : public AnimatableBody2D {
|
||||
GDCLASS(PinnedPhoto, AnimatableBody2D);
|
||||
static void _bind_methods();
|
||||
void enter_tree();
|
||||
void process(double delta);
|
||||
void on_input_event(Viewport *viewport, Ref<InputEvent> event, int shape);
|
||||
|
||||
protected:
|
||||
virtual void unhandled_input(Ref<InputEvent> const &event) override;
|
||||
void _notification(int what);
|
||||
|
||||
public:
|
||||
void set_can_drop(bool value);
|
||||
bool get_can_drop() const;
|
||||
void set_clue(NetworkData::ClueID id);
|
||||
NetworkData::ClueID get_clue() const;
|
||||
|
||||
private:
|
||||
NetworkData::ClueID clue{ NetworkData::CLUE_MAX };
|
||||
bool can_drop{ false };
|
||||
bool is_held{ false };
|
||||
};
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
#include "you_done_it/clue_data.h"
|
||||
#include "you_done_it/clue_finder.h"
|
||||
#include "you_done_it/clue_marker.h"
|
||||
#include "you_done_it/pinboard.h"
|
||||
#include "you_done_it/pinned_photo.h"
|
||||
#include "you_done_it/server_node.h"
|
||||
#include "you_done_it/ydi_networking.h"
|
||||
#include "you_done_it/ydi_vr_origin.h"
|
||||
|
|
@ -21,6 +23,8 @@ void initialize_you_done_it_module(ModuleInitializationLevel p_level) {
|
|||
ClassDB::register_class<ClueFinder>();
|
||||
ClassDB::register_class<ClueData>();
|
||||
ClassDB::register_class<ClueDB>();
|
||||
ClassDB::register_class<Pinboard>();
|
||||
ClassDB::register_class<PinnedPhoto>();
|
||||
}
|
||||
|
||||
void uninitialize_you_done_it_module(ModuleInitializationLevel p_level) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue