| 1 | /**************************************************************************/ |
| 2 | /* skeleton_modification_2d_lookat.h */ |
| 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 | #ifndef SKELETON_MODIFICATION_2D_LOOKAT_H |
| 32 | #define SKELETON_MODIFICATION_2D_LOOKAT_H |
| 33 | |
| 34 | #include "scene/2d/skeleton_2d.h" |
| 35 | #include "scene/resources/skeleton_modification_2d.h" |
| 36 | |
| 37 | /////////////////////////////////////// |
| 38 | // SkeletonModification2DLookAt |
| 39 | /////////////////////////////////////// |
| 40 | |
| 41 | class SkeletonModification2DLookAt : public SkeletonModification2D { |
| 42 | GDCLASS(SkeletonModification2DLookAt, SkeletonModification2D); |
| 43 | |
| 44 | private: |
| 45 | int bone_idx = -1; |
| 46 | NodePath bone2d_node; |
| 47 | ObjectID bone2d_node_cache; |
| 48 | |
| 49 | NodePath target_node; |
| 50 | ObjectID target_node_cache; |
| 51 | Node2D *target_node_reference = nullptr; |
| 52 | |
| 53 | float additional_rotation = 0; |
| 54 | bool enable_constraint = false; |
| 55 | float constraint_angle_min = 0; |
| 56 | float constraint_angle_max = (2.0 * Math_PI); |
| 57 | bool constraint_angle_invert = false; |
| 58 | bool constraint_in_localspace = true; |
| 59 | |
| 60 | void update_bone2d_cache(); |
| 61 | void update_target_cache(); |
| 62 | |
| 63 | protected: |
| 64 | static void _bind_methods(); |
| 65 | bool _set(const StringName &p_path, const Variant &p_value); |
| 66 | bool _get(const StringName &p_path, Variant &r_ret) const; |
| 67 | void _get_property_list(List<PropertyInfo> *p_list) const; |
| 68 | |
| 69 | public: |
| 70 | void _execute(float p_delta) override; |
| 71 | void _setup_modification(SkeletonModificationStack2D *p_stack) override; |
| 72 | void _draw_editor_gizmo() override; |
| 73 | |
| 74 | void set_bone2d_node(const NodePath &p_target_node); |
| 75 | NodePath get_bone2d_node() const; |
| 76 | void set_bone_index(int p_idx); |
| 77 | int get_bone_index() const; |
| 78 | |
| 79 | void set_target_node(const NodePath &p_target_node); |
| 80 | NodePath get_target_node() const; |
| 81 | |
| 82 | void set_additional_rotation(float p_rotation); |
| 83 | float get_additional_rotation() const; |
| 84 | |
| 85 | void set_enable_constraint(bool p_constraint); |
| 86 | bool get_enable_constraint() const; |
| 87 | void set_constraint_angle_min(float p_angle_min); |
| 88 | float get_constraint_angle_min() const; |
| 89 | void set_constraint_angle_max(float p_angle_max); |
| 90 | float get_constraint_angle_max() const; |
| 91 | void set_constraint_angle_invert(bool p_invert); |
| 92 | bool get_constraint_angle_invert() const; |
| 93 | void set_constraint_in_localspace(bool p_constraint_in_localspace); |
| 94 | bool get_constraint_in_localspace() const; |
| 95 | |
| 96 | SkeletonModification2DLookAt(); |
| 97 | ~SkeletonModification2DLookAt(); |
| 98 | }; |
| 99 | |
| 100 | #endif // SKELETON_MODIFICATION_2D_LOOKAT_H |
| 101 | |