Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/resources/2d/skeleton/skeleton_modification_2d_stackholder.cpp
9903 views
1
/**************************************************************************/
2
/* skeleton_modification_2d_stackholder.cpp */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#include "skeleton_modification_2d_stackholder.h"
32
#include "scene/2d/skeleton_2d.h"
33
34
bool SkeletonModification2DStackHolder::_set(const StringName &p_path, const Variant &p_value) {
35
String path = p_path;
36
37
if (path == "held_modification_stack") {
38
set_held_modification_stack(p_value);
39
}
40
#ifdef TOOLS_ENABLED
41
else if (path == "editor/draw_gizmo") {
42
set_editor_draw_gizmo(p_value);
43
}
44
#endif // TOOLS_ENABLED
45
else {
46
return false;
47
}
48
49
return true;
50
}
51
52
bool SkeletonModification2DStackHolder::_get(const StringName &p_path, Variant &r_ret) const {
53
String path = p_path;
54
55
if (path == "held_modification_stack") {
56
r_ret = get_held_modification_stack();
57
}
58
#ifdef TOOLS_ENABLED
59
else if (path == "editor/draw_gizmo") {
60
r_ret = get_editor_draw_gizmo();
61
}
62
#endif // TOOLS_ENABLED
63
else {
64
return false;
65
}
66
67
return true;
68
}
69
70
void SkeletonModification2DStackHolder::_get_property_list(List<PropertyInfo> *p_list) const {
71
p_list->push_back(PropertyInfo(Variant::OBJECT, "held_modification_stack", PROPERTY_HINT_RESOURCE_TYPE, "SkeletonModificationStack2D", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_ALWAYS_DUPLICATE));
72
73
#ifdef TOOLS_ENABLED
74
if (Engine::get_singleton()->is_editor_hint()) {
75
p_list->push_back(PropertyInfo(Variant::BOOL, "editor/draw_gizmo", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT));
76
}
77
#endif // TOOLS_ENABLED
78
}
79
80
void SkeletonModification2DStackHolder::_execute(float p_delta) {
81
ERR_FAIL_COND_MSG(!stack || !is_setup || stack->skeleton == nullptr,
82
"Modification is not setup and therefore cannot execute!");
83
84
if (held_modification_stack.is_valid()) {
85
held_modification_stack->execute(p_delta, execution_mode);
86
}
87
}
88
89
void SkeletonModification2DStackHolder::_setup_modification(SkeletonModificationStack2D *p_stack) {
90
stack = p_stack;
91
92
if (stack != nullptr) {
93
is_setup = true;
94
95
if (held_modification_stack.is_valid()) {
96
held_modification_stack->set_skeleton(stack->get_skeleton());
97
held_modification_stack->setup();
98
}
99
}
100
}
101
102
void SkeletonModification2DStackHolder::_draw_editor_gizmo() {
103
if (stack) {
104
if (held_modification_stack.is_valid()) {
105
held_modification_stack->draw_editor_gizmos();
106
}
107
}
108
}
109
110
void SkeletonModification2DStackHolder::set_held_modification_stack(Ref<SkeletonModificationStack2D> p_held_stack) {
111
held_modification_stack = p_held_stack;
112
113
if (is_setup && held_modification_stack.is_valid()) {
114
held_modification_stack->set_skeleton(stack->get_skeleton());
115
held_modification_stack->setup();
116
}
117
}
118
119
Ref<SkeletonModificationStack2D> SkeletonModification2DStackHolder::get_held_modification_stack() const {
120
return held_modification_stack;
121
}
122
123
void SkeletonModification2DStackHolder::_bind_methods() {
124
ClassDB::bind_method(D_METHOD("set_held_modification_stack", "held_modification_stack"), &SkeletonModification2DStackHolder::set_held_modification_stack);
125
ClassDB::bind_method(D_METHOD("get_held_modification_stack"), &SkeletonModification2DStackHolder::get_held_modification_stack);
126
}
127
128
SkeletonModification2DStackHolder::SkeletonModification2DStackHolder() {
129
stack = nullptr;
130
is_setup = false;
131
enabled = true;
132
}
133
134
SkeletonModification2DStackHolder::~SkeletonModification2DStackHolder() {
135
}
136
137