diff options
Diffstat (limited to 'scene/main')
-rw-r--r-- | scene/main/canvas_layer.cpp | 2 | ||||
-rwxr-xr-x | scene/main/node.cpp | 97 | ||||
-rw-r--r-- | scene/main/node.h | 2 | ||||
-rw-r--r-- | scene/main/scene_tree.cpp | 4 | ||||
-rw-r--r-- | scene/main/viewport.cpp | 87 |
5 files changed, 139 insertions, 53 deletions
diff --git a/scene/main/canvas_layer.cpp b/scene/main/canvas_layer.cpp index 150aee99ba..0ee57bd794 100644 --- a/scene/main/canvas_layer.cpp +++ b/scene/main/canvas_layer.cpp @@ -204,7 +204,7 @@ void CanvasLayer::set_custom_viewport(Node *p_viewport) { custom_viewport = p_viewport->cast_to<Viewport>(); if (custom_viewport) { - custom_viewport_id = custom_viewport->get_instance_ID(); + custom_viewport_id = custom_viewport->get_instance_id(); } else { custom_viewport_id = 0; } diff --git a/scene/main/node.cpp b/scene/main/node.cpp index c3849f79df..6999091609 100755 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -77,11 +77,11 @@ void Node::_notification(int p_notification) { } if (data.input) - add_to_group("_vp_input" + itos(get_viewport()->get_instance_ID())); + add_to_group("_vp_input" + itos(get_viewport()->get_instance_id())); if (data.unhandled_input) - add_to_group("_vp_unhandled_input" + itos(get_viewport()->get_instance_ID())); + add_to_group("_vp_unhandled_input" + itos(get_viewport()->get_instance_id())); if (data.unhandled_key_input) - add_to_group("_vp_unhandled_key_input" + itos(get_viewport()->get_instance_ID())); + add_to_group("_vp_unhandled_key_input" + itos(get_viewport()->get_instance_id())); get_tree()->node_count++; @@ -90,11 +90,11 @@ void Node::_notification(int p_notification) { get_tree()->node_count--; if (data.input) - remove_from_group("_vp_input" + itos(get_viewport()->get_instance_ID())); + remove_from_group("_vp_input" + itos(get_viewport()->get_instance_id())); if (data.unhandled_input) - remove_from_group("_vp_unhandled_input" + itos(get_viewport()->get_instance_ID())); + remove_from_group("_vp_unhandled_input" + itos(get_viewport()->get_instance_id())); if (data.unhandled_key_input) - remove_from_group("_vp_unhandled_key_input" + itos(get_viewport()->get_instance_ID())); + remove_from_group("_vp_unhandled_key_input" + itos(get_viewport()->get_instance_id())); data.pause_owner = NULL; if (data.path_cache) { @@ -705,12 +705,12 @@ void Node::rpcp(int p_peer_id, bool p_unreliable, const StringName &p_method, co ERR_FAIL_COND(!is_inside_tree()); bool skip_rpc = false; + bool call_local_native = false; + bool call_local_script = false; if (p_peer_id == 0 || p_peer_id == get_tree()->get_network_unique_id() || (p_peer_id < 0 && p_peer_id != -get_tree()->get_network_unique_id())) { //check that send mode can use local call - bool call_local = false; - Map<StringName, RPCMode>::Element *E = data.rpc_methods.find(p_method); if (E) { @@ -724,29 +724,22 @@ void Node::rpcp(int p_peer_id, bool p_unreliable, const StringName &p_method, co } break; case RPC_MODE_SYNC: { //call it, sync always results in call - call_local = true; + call_local_native = true; } break; case RPC_MODE_MASTER: { - call_local = is_network_master(); - if (call_local) { + call_local_native = is_network_master(); + if (call_local_native) { skip_rpc = true; //no other master so.. } } break; case RPC_MODE_SLAVE: { - call_local = !is_network_master(); + call_local_native = !is_network_master(); } break; } } - if (call_local) { - Variant::CallError ce; - call(p_method, p_arg, p_argcount, ce); - if (ce.error != Variant::CallError::CALL_OK) { - String error = Variant::get_call_error_text(this, p_method, p_arg, p_argcount, ce); - error = "rpc() aborted in local call: - " + error; - ERR_PRINTS(error); - return; - } + if (call_local_native) { + // done below } else if (get_script_instance()) { //attempt with script ScriptInstance::RPCMode rpc_mode = get_script_instance()->get_rpc_mode(p_method); @@ -761,37 +754,47 @@ void Node::rpcp(int p_peer_id, bool p_unreliable, const StringName &p_method, co } break; case ScriptInstance::RPC_MODE_SYNC: { //call it, sync always results in call - call_local = true; + call_local_script = true; } break; case ScriptInstance::RPC_MODE_MASTER: { - call_local = is_network_master(); - if (call_local) { + call_local_script = is_network_master(); + if (call_local_script) { skip_rpc = true; //no other master so.. } } break; case ScriptInstance::RPC_MODE_SLAVE: { - call_local = !is_network_master(); + call_local_script = !is_network_master(); } break; } - - if (call_local) { - Variant::CallError ce; - ce.error = Variant::CallError::CALL_OK; - get_script_instance()->call(p_method, p_arg, p_argcount, ce); - if (ce.error != Variant::CallError::CALL_OK) { - String error = Variant::get_call_error_text(this, p_method, p_arg, p_argcount, ce); - error = "rpc() aborted in script local call: - " + error; - ERR_PRINTS(error); - return; - } - } } } - if (skip_rpc) - return; + if (!skip_rpc) { + get_tree()->_rpc(this, p_peer_id, p_unreliable, false, p_method, p_arg, p_argcount); + } + + if (call_local_native) { + Variant::CallError ce; + call(p_method, p_arg, p_argcount, ce); + if (ce.error != Variant::CallError::CALL_OK) { + String error = Variant::get_call_error_text(this, p_method, p_arg, p_argcount, ce); + error = "rpc() aborted in local call: - " + error; + ERR_PRINTS(error); + return; + } + } - get_tree()->_rpc(this, p_peer_id, p_unreliable, false, p_method, p_arg, p_argcount); + if (call_local_script) { + Variant::CallError ce; + ce.error = Variant::CallError::CALL_OK; + get_script_instance()->call(p_method, p_arg, p_argcount, ce); + if (ce.error != Variant::CallError::CALL_OK) { + String error = Variant::get_call_error_text(this, p_method, p_arg, p_argcount, ce); + error = "rpc() aborted in script local call: - " + error; + ERR_PRINTS(error); + return; + } + } } /******** RSET *********/ @@ -1115,9 +1118,9 @@ void Node::set_process_input(bool p_enable) { return; if (p_enable) - add_to_group("_vp_input" + itos(get_viewport()->get_instance_ID())); + add_to_group("_vp_input" + itos(get_viewport()->get_instance_id())); else - remove_from_group("_vp_input" + itos(get_viewport()->get_instance_ID())); + remove_from_group("_vp_input" + itos(get_viewport()->get_instance_id())); } bool Node::is_processing_input() const { @@ -1133,9 +1136,9 @@ void Node::set_process_unhandled_input(bool p_enable) { return; if (p_enable) - add_to_group("_vp_unhandled_input" + itos(get_viewport()->get_instance_ID())); + add_to_group("_vp_unhandled_input" + itos(get_viewport()->get_instance_id())); else - remove_from_group("_vp_unhandled_input" + itos(get_viewport()->get_instance_ID())); + remove_from_group("_vp_unhandled_input" + itos(get_viewport()->get_instance_id())); } bool Node::is_processing_unhandled_input() const { @@ -1151,9 +1154,9 @@ void Node::set_process_unhandled_key_input(bool p_enable) { return; if (p_enable) - add_to_group("_vp_unhandled_key_input" + itos(get_viewport()->get_instance_ID())); + add_to_group("_vp_unhandled_key_input" + itos(get_viewport()->get_instance_id())); else - remove_from_group("_vp_unhandled_key_input" + itos(get_viewport()->get_instance_ID())); + remove_from_group("_vp_unhandled_key_input" + itos(get_viewport()->get_instance_id())); } bool Node::is_processing_unhandled_key_input() const { @@ -2606,7 +2609,7 @@ static void _Node_debug_sn(Object *p_obj) { path = n->get_name(); else path = String(p->get_name()) + "/" + p->get_path_to(n); - print_line(itos(p_obj->get_instance_ID()) + "- Stray Node: " + path + " (Type: " + n->get_class() + ")"); + print_line(itos(p_obj->get_instance_id()) + "- Stray Node: " + path + " (Type: " + n->get_class() + ")"); } void Node::_print_stray_nodes() { diff --git a/scene/main/node.h b/scene/main/node.h index 1794cce9f6..0447deccc1 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -33,7 +33,7 @@ #include "class_db.h" #include "map.h" #include "object.h" -#include "path_db.h" +#include "node_path.h" #include "project_settings.h" #include "scene/main/scene_tree.h" #include "script_language.h" diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 48e6a44745..6aa2c83941 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -1106,7 +1106,7 @@ static void _fill_array(Node *p_node, Array &array, int p_level) { array.push_back(p_level); array.push_back(p_node->get_name()); array.push_back(p_node->get_class()); - array.push_back(p_node->get_instance_ID()); + array.push_back(p_node->get_instance_id()); for (int i = 0; i < p_node->get_child_count(); i++) { _fill_array(p_node->get_child(i), array, p_level + 1); @@ -1141,7 +1141,7 @@ void SceneTree::queue_delete(Object *p_object) { _THREAD_SAFE_METHOD_ ERR_FAIL_NULL(p_object); p_object->_is_queued_for_deletion = true; - delete_queue.push_back(p_object->get_instance_ID()); + delete_queue.push_back(p_object->get_instance_id()); } int SceneTree::get_node_count() const { diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 76b281ebac..ee9323ca1d 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -2028,6 +2028,89 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { } } + Ref<InputEventScreenTouch> touch_event = p_event; + if (touch_event.is_valid()) { + + Size2 pos = touch_event->get_position(); + if (touch_event->is_pressed()) { + + Control *over = _gui_find_control(pos); + if (over) { + + if (!gui.modal_stack.empty()) { + + Control *top = gui.modal_stack.back()->get(); + if (over != top && !top->is_a_parent_of(over)) { + + return; + } + } + if (over->can_process()) { + + touch_event = touch_event->xformed_by(Transform2D()); //make a copy + if (over == gui.mouse_focus) { + pos = gui.focus_inv_xform.xform(pos); + } else { + pos = over->get_global_transform_with_canvas().affine_inverse().xform(pos); + } + touch_event->set_position(pos); + _gui_call_input(over, touch_event); + } + get_tree()->set_input_as_handled(); + return; + } + } else if (gui.mouse_focus) { + + if (gui.mouse_focus->can_process()) { + + touch_event = touch_event->xformed_by(Transform2D()); //make a copy + touch_event->set_position(gui.focus_inv_xform.xform(pos)); + + _gui_call_input(gui.mouse_focus, touch_event); + } + get_tree()->set_input_as_handled(); + return; + } + } + + Ref<InputEventScreenDrag> drag_event = p_event; + if (drag_event.is_valid()) { + + Control *over = gui.mouse_focus; + if (!over) { + over = _gui_find_control(drag_event->get_position()); + } + if (over) { + + if (!gui.modal_stack.empty()) { + + Control *top = gui.modal_stack.back()->get(); + if (over != top && !top->is_a_parent_of(over)) { + + return; + } + } + if (over->can_process()) { + + Transform2D localizer = over->get_global_transform_with_canvas().affine_inverse(); + Size2 pos = localizer.xform(drag_event->get_position()); + Vector2 speed = localizer.basis_xform(drag_event->get_speed()); + Vector2 rel = localizer.basis_xform(drag_event->get_relative()); + + drag_event = drag_event->xformed_by(Transform2D()); //make a copy + + drag_event->set_speed(speed); + drag_event->set_relative(rel); + drag_event->set_position(pos); + + _gui_call_input(over, drag_event); + } + + get_tree()->set_input_as_handled(); + return; + } + } + if (mm.is_null() && mb.is_null() && p_event->is_action_type()) { if (gui.key_focus && !gui.key_focus->is_visible_in_tree()) { @@ -2303,7 +2386,7 @@ List<Control *>::Element *Viewport::_gui_show_modal(Control *p_control) { gui.modal_stack.push_back(p_control); if (gui.key_focus) - p_control->_modal_set_prev_focus_owner(gui.key_focus->get_instance_ID()); + p_control->_modal_set_prev_focus_owner(gui.key_focus->get_instance_id()); else p_control->_modal_set_prev_focus_owner(0); @@ -2769,7 +2852,7 @@ Viewport::Viewport() { set_shadow_atlas_quadrant_subdiv(2, SHADOW_ATLAS_QUADRANT_SUBDIV_16); set_shadow_atlas_quadrant_subdiv(3, SHADOW_ATLAS_QUADRANT_SUBDIV_64); - String id = itos(get_instance_ID()); + String id = itos(get_instance_id()); input_group = "_vp_input" + id; gui_input_group = "_vp_gui_input" + id; unhandled_input_group = "_vp_unhandled_input" + id; |