diff options
-rw-r--r-- | doc/classes/AnimationPlayer.xml | 3 | ||||
-rw-r--r-- | editor/plugins/animation_player_editor_plugin.cpp | 24 | ||||
-rw-r--r-- | editor/plugins/spatial_editor_plugin.cpp | 38 | ||||
-rw-r--r-- | editor/property_editor.cpp | 2 | ||||
-rw-r--r-- | scene/animation/animation_player.cpp | 28 | ||||
-rw-r--r-- | scene/animation/animation_player.h | 2 | ||||
-rw-r--r-- | scene/gui/viewport_container.cpp | 28 | ||||
-rw-r--r-- | scene/gui/viewport_container.h | 1 |
8 files changed, 89 insertions, 37 deletions
diff --git a/doc/classes/AnimationPlayer.xml b/doc/classes/AnimationPlayer.xml index 8808e324d6..46602911d2 100644 --- a/doc/classes/AnimationPlayer.xml +++ b/doc/classes/AnimationPlayer.xml @@ -208,6 +208,9 @@ </method> </methods> <members> + <member name="assigned_animation" type="String" setter="set_assigned_animation" getter="get_assigned_animation"> + If playing, the current animation; otherwise, the animation last played. When set, would change the animation, but would not play it unless currently playing. See also [member current_animation]. + </member> <member name="autoplay" type="String" setter="set_autoplay" getter="get_autoplay"> The name of the animation to play when the scene loads. Default value: [code]""[/code]. </member> diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index 3593493d11..d071d43cb7 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -73,7 +73,7 @@ void AnimationPlayerEditor::_notification(int p_what) { if (player->is_playing()) { { - String animname = player->get_current_animation(); + String animname = player->get_assigned_animation(); if (player->has_animation(animname)) { Ref<Animation> anim = player->get_animation(animname); @@ -186,7 +186,7 @@ void AnimationPlayerEditor::_play_pressed() { if (current != "") { - if (current == player->get_current_animation()) + if (current == player->get_assigned_animation()) player->stop(); //so it wont blend with itself player->play(current); } @@ -209,7 +209,7 @@ void AnimationPlayerEditor::_play_from_pressed() { float time = player->get_current_animation_position(); - if (current == player->get_current_animation() && player->is_playing()) { + if (current == player->get_assigned_animation() && player->is_playing()) { player->stop(); //so it wont blend with itself } @@ -234,7 +234,7 @@ void AnimationPlayerEditor::_play_bw_pressed() { if (current != "") { - if (current == player->get_current_animation()) + if (current == player->get_assigned_animation()) player->stop(); //so it wont blend with itself player->play(current, -1, -1, true); } @@ -256,7 +256,7 @@ void AnimationPlayerEditor::_play_bw_from_pressed() { if (current != "") { float time = player->get_current_animation_position(); - if (current == player->get_current_animation()) + if (current == player->get_assigned_animation()) player->stop(); //so it wont blend with itself player->play(current, -1, -1, true); @@ -299,7 +299,7 @@ void AnimationPlayerEditor::_animation_selected(int p_which) { if (current != "") { - // player->set_current_animation(current, false); + player->set_assigned_animation(current); Ref<Animation> anim = player->get_animation(current); { @@ -654,9 +654,7 @@ Dictionary AnimationPlayerEditor::get_state() const { d["visible"] = is_visible_in_tree(); if (EditorNode::get_singleton()->get_edited_scene() && is_visible_in_tree() && player) { d["player"] = EditorNode::get_singleton()->get_edited_scene()->get_path_to(player); - } - if (animation->get_selected() >= 0 && animation->get_selected() < animation->get_item_count()) { - d["animation"] = animation->get_item_text(animation->get_selected()); + d["animation"] = player->get_assigned_animation(); } return d; @@ -784,7 +782,7 @@ void AnimationPlayerEditor::_update_animation() { } scale->set_text(String::num(player->get_speed_scale(), 2)); - String current = player->get_current_animation(); + String current = player->get_assigned_animation(); for (int i = 0; i < animation->get_item_count(); i++) { @@ -831,7 +829,7 @@ void AnimationPlayerEditor::_update_player() { else animation->add_item(E->get()); - if (player->get_current_animation() == E->get()) + if (player->get_assigned_animation() == E->get()) active_idx = animation->get_item_count() - 1; } @@ -988,7 +986,7 @@ void AnimationPlayerEditor::_seek_value_changed(float p_value, bool p_set) { }; updating = true; - String current = player->get_current_animation(); //animation->get_item_text( animation->get_selected() ); + String current = player->get_assigned_animation(); //animation->get_item_text( animation->get_selected() ); if (current == "" || !player->has_animation(current)) { updating = false; current = ""; @@ -1338,7 +1336,7 @@ void AnimationPlayerEditor::_prepare_onion_layers_1() { void AnimationPlayerEditor::_prepare_onion_layers_2() { - Ref<Animation> anim = player->get_animation(player->get_current_animation()); + Ref<Animation> anim = player->get_animation(player->get_assigned_animation()); if (!anim.is_valid()) return; diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index cef1da1d06..e2ea853052 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -2017,6 +2017,20 @@ Point2i SpatialEditorViewport::_get_warped_mouse_motion(const Ref<InputEventMous return relative; } +static bool is_shortcut_pressed(const String &p_path) { + Ref<ShortCut> shortcut = ED_GET_SHORTCUT(p_path); + if (shortcut.is_null()) { + return false; + } + InputEventKey *k = Object::cast_to<InputEventKey>(shortcut->get_shortcut().ptr()); + if (k == NULL) { + return false; + } + const Input &input = *Input::get_singleton(); + int scancode = k->get_scancode(); + return input.is_key_pressed(scancode); +} + void SpatialEditorViewport::_update_freelook(real_t delta) { if (!is_freelook_active()) { @@ -2027,38 +2041,28 @@ void SpatialEditorViewport::_update_freelook(real_t delta) { Vector3 right = camera->get_transform().basis.xform(Vector3(1, 0, 0)); Vector3 up = camera->get_transform().basis.xform(Vector3(0, 1, 0)); - int key_left = Object::cast_to<InputEventKey>(ED_GET_SHORTCUT("spatial_editor/freelook_left")->get_shortcut().ptr())->get_scancode(); - int key_right = Object::cast_to<InputEventKey>(ED_GET_SHORTCUT("spatial_editor/freelook_right")->get_shortcut().ptr())->get_scancode(); - int key_forward = Object::cast_to<InputEventKey>(ED_GET_SHORTCUT("spatial_editor/freelook_forward")->get_shortcut().ptr())->get_scancode(); - int key_backwards = Object::cast_to<InputEventKey>(ED_GET_SHORTCUT("spatial_editor/freelook_backwards")->get_shortcut().ptr())->get_scancode(); - int key_up = Object::cast_to<InputEventKey>(ED_GET_SHORTCUT("spatial_editor/freelook_up")->get_shortcut().ptr())->get_scancode(); - int key_down = Object::cast_to<InputEventKey>(ED_GET_SHORTCUT("spatial_editor/freelook_down")->get_shortcut().ptr())->get_scancode(); - int key_speed_modifier = Object::cast_to<InputEventKey>(ED_GET_SHORTCUT("spatial_editor/freelook_speed_modifier")->get_shortcut().ptr())->get_scancode(); - Vector3 direction; bool speed_modifier = false; - const Input &input = *Input::get_singleton(); - - if (input.is_key_pressed(key_left)) { + if (is_shortcut_pressed("spatial_editor/freelook_left")) { direction -= right; } - if (input.is_key_pressed(key_right)) { + if (is_shortcut_pressed("spatial_editor/freelook_right")) { direction += right; } - if (input.is_key_pressed(key_forward)) { + if (is_shortcut_pressed("spatial_editor/freelook_forward")) { direction += forward; } - if (input.is_key_pressed(key_backwards)) { + if (is_shortcut_pressed("spatial_editor/freelook_backwards")) { direction -= forward; } - if (input.is_key_pressed(key_up)) { + if (is_shortcut_pressed("spatial_editor/freelook_up")) { direction += up; } - if (input.is_key_pressed(key_down)) { + if (is_shortcut_pressed("spatial_editor/freelook_down")) { direction -= up; } - if (input.is_key_pressed(key_speed_modifier)) { + if (is_shortcut_pressed("spatial_editor/freelook_speed_modifier")) { speed_modifier = true; } diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp index 46d52d21d4..87906c5a93 100644 --- a/editor/property_editor.cpp +++ b/editor/property_editor.cpp @@ -665,6 +665,8 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: } else if (hint == PROPERTY_HINT_PROPERTY_OF_INSTANCE) { + MAKE_PROPSELECT + Object *instance = ObjectDB::get_instance(hint_text.to_int64()); if (instance) property_select->select_property_from_instance(instance, v); diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index d1829ce4d4..b20bc64d41 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -977,6 +977,7 @@ bool AnimationPlayer::is_playing() const { return true; */ } + void AnimationPlayer::set_current_animation(const String &p_anim) { if (p_anim == "[stop]" || p_anim == "") { @@ -986,13 +987,6 @@ void AnimationPlayer::set_current_animation(const String &p_anim) { } else { // Same animation, do not replay from start } - - /* - ERR_FAIL_COND(!animation_set.has(p_anim)); - playback.current.pos = 0; - playback.current.from = &animation_set[p_anim]; - playback.assigned = p_anim; - */ } String AnimationPlayer::get_current_animation() const { @@ -1000,6 +994,23 @@ String AnimationPlayer::get_current_animation() const { return (is_playing() ? playback.assigned : ""); } +void AnimationPlayer::set_assigned_animation(const String &p_anim) { + + if (is_playing()) { + play(p_anim); + } else { + ERR_FAIL_COND(!animation_set.has(p_anim)); + playback.current.pos = 0; + playback.current.from = &animation_set[p_anim]; + playback.assigned = p_anim; + } +} + +String AnimationPlayer::get_assigned_animation() const { + + return playback.assigned; +} + void AnimationPlayer::stop(bool p_reset) { Playback &c = playback; @@ -1301,6 +1312,8 @@ void AnimationPlayer::_bind_methods() { ClassDB::bind_method(D_METHOD("set_current_animation", "anim"), &AnimationPlayer::set_current_animation); ClassDB::bind_method(D_METHOD("get_current_animation"), &AnimationPlayer::get_current_animation); + ClassDB::bind_method(D_METHOD("set_assigned_animation", "anim"), &AnimationPlayer::set_assigned_animation); + ClassDB::bind_method(D_METHOD("get_assigned_animation"), &AnimationPlayer::get_assigned_animation); ClassDB::bind_method(D_METHOD("queue", "name"), &AnimationPlayer::queue); ClassDB::bind_method(D_METHOD("clear_queue"), &AnimationPlayer::clear_queue); @@ -1331,6 +1344,7 @@ void AnimationPlayer::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "root_node"), "set_root", "get_root"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "current_animation", PROPERTY_HINT_ENUM, "", PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_ANIMATE_AS_TRIGGER), "set_current_animation", "get_current_animation"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "assigned_animation", PROPERTY_HINT_NONE, "", 0), "set_assigned_animation", "get_assigned_animation"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "autoplay", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_autoplay", "get_autoplay"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "current_animation_length", PROPERTY_HINT_NONE, "", 0), "", "get_current_animation_length"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "current_animation_position", PROPERTY_HINT_NONE, "", 0), "", "get_current_animation_position"); diff --git a/scene/animation/animation_player.h b/scene/animation/animation_player.h index ef1720443f..ef758bac44 100644 --- a/scene/animation/animation_player.h +++ b/scene/animation/animation_player.h @@ -284,6 +284,8 @@ public: bool is_playing() const; String get_current_animation() const; void set_current_animation(const String &p_anim); + String get_assigned_animation() const; + void set_assigned_animation(const String &p_anim); void stop_all(); void set_active(bool p_active); bool is_active() const; diff --git a/scene/gui/viewport_container.cpp b/scene/gui/viewport_container.cpp index af849589cf..ac5e6020eb 100644 --- a/scene/gui/viewport_container.cpp +++ b/scene/gui/viewport_container.cpp @@ -30,6 +30,7 @@ #include "viewport_container.h" +#include "core/engine.h" #include "scene/main/viewport.h" Size2 ViewportContainer::get_minimum_size() const { @@ -139,8 +140,34 @@ void ViewportContainer::_notification(int p_what) { } } +void ViewportContainer::_input(const Ref<InputEvent> &p_event) { + + if (Engine::get_singleton()->is_editor_hint()) + return; + + Transform2D xform = get_global_transform(); + + if (stretch) { + Transform2D scale_xf; + scale_xf.scale(Vector2(shrink, shrink)); + xform *= scale_xf; + } + + Ref<InputEvent> ev = p_event->xformed_by(xform.affine_inverse()); + + for (int i = 0; i < get_child_count(); i++) { + + Viewport *c = Object::cast_to<Viewport>(get_child(i)); + if (!c || c->is_input_disabled()) + continue; + + c->input(ev); + } +} + void ViewportContainer::_bind_methods() { + ClassDB::bind_method(D_METHOD("_input", "event"), &ViewportContainer::_input); ClassDB::bind_method(D_METHOD("set_stretch", "enable"), &ViewportContainer::set_stretch); ClassDB::bind_method(D_METHOD("is_stretch_enabled"), &ViewportContainer::is_stretch_enabled); @@ -155,4 +182,5 @@ ViewportContainer::ViewportContainer() { stretch = false; shrink = 1; + set_process_input(true); } diff --git a/scene/gui/viewport_container.h b/scene/gui/viewport_container.h index cd8b4dd5c1..45c4cd03a1 100644 --- a/scene/gui/viewport_container.h +++ b/scene/gui/viewport_container.h @@ -48,6 +48,7 @@ public: void set_stretch(bool p_enable); bool is_stretch_enabled() const; + void _input(const Ref<InputEvent> &p_event); void set_stretch_shrink(int p_shrink); int get_stretch_shrink() const; |