Path: blob/master/scene/resources/2d/skeleton/skeleton_modification_2d_stackholder.cpp
9903 views
/**************************************************************************/1/* skeleton_modification_2d_stackholder.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "skeleton_modification_2d_stackholder.h"31#include "scene/2d/skeleton_2d.h"3233bool SkeletonModification2DStackHolder::_set(const StringName &p_path, const Variant &p_value) {34String path = p_path;3536if (path == "held_modification_stack") {37set_held_modification_stack(p_value);38}39#ifdef TOOLS_ENABLED40else if (path == "editor/draw_gizmo") {41set_editor_draw_gizmo(p_value);42}43#endif // TOOLS_ENABLED44else {45return false;46}4748return true;49}5051bool SkeletonModification2DStackHolder::_get(const StringName &p_path, Variant &r_ret) const {52String path = p_path;5354if (path == "held_modification_stack") {55r_ret = get_held_modification_stack();56}57#ifdef TOOLS_ENABLED58else if (path == "editor/draw_gizmo") {59r_ret = get_editor_draw_gizmo();60}61#endif // TOOLS_ENABLED62else {63return false;64}6566return true;67}6869void SkeletonModification2DStackHolder::_get_property_list(List<PropertyInfo> *p_list) const {70p_list->push_back(PropertyInfo(Variant::OBJECT, "held_modification_stack", PROPERTY_HINT_RESOURCE_TYPE, "SkeletonModificationStack2D", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_ALWAYS_DUPLICATE));7172#ifdef TOOLS_ENABLED73if (Engine::get_singleton()->is_editor_hint()) {74p_list->push_back(PropertyInfo(Variant::BOOL, "editor/draw_gizmo", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT));75}76#endif // TOOLS_ENABLED77}7879void SkeletonModification2DStackHolder::_execute(float p_delta) {80ERR_FAIL_COND_MSG(!stack || !is_setup || stack->skeleton == nullptr,81"Modification is not setup and therefore cannot execute!");8283if (held_modification_stack.is_valid()) {84held_modification_stack->execute(p_delta, execution_mode);85}86}8788void SkeletonModification2DStackHolder::_setup_modification(SkeletonModificationStack2D *p_stack) {89stack = p_stack;9091if (stack != nullptr) {92is_setup = true;9394if (held_modification_stack.is_valid()) {95held_modification_stack->set_skeleton(stack->get_skeleton());96held_modification_stack->setup();97}98}99}100101void SkeletonModification2DStackHolder::_draw_editor_gizmo() {102if (stack) {103if (held_modification_stack.is_valid()) {104held_modification_stack->draw_editor_gizmos();105}106}107}108109void SkeletonModification2DStackHolder::set_held_modification_stack(Ref<SkeletonModificationStack2D> p_held_stack) {110held_modification_stack = p_held_stack;111112if (is_setup && held_modification_stack.is_valid()) {113held_modification_stack->set_skeleton(stack->get_skeleton());114held_modification_stack->setup();115}116}117118Ref<SkeletonModificationStack2D> SkeletonModification2DStackHolder::get_held_modification_stack() const {119return held_modification_stack;120}121122void SkeletonModification2DStackHolder::_bind_methods() {123ClassDB::bind_method(D_METHOD("set_held_modification_stack", "held_modification_stack"), &SkeletonModification2DStackHolder::set_held_modification_stack);124ClassDB::bind_method(D_METHOD("get_held_modification_stack"), &SkeletonModification2DStackHolder::get_held_modification_stack);125}126127SkeletonModification2DStackHolder::SkeletonModification2DStackHolder() {128stack = nullptr;129is_setup = false;130enabled = true;131}132133SkeletonModification2DStackHolder::~SkeletonModification2DStackHolder() {134}135136137