diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/2d/path_2d.cpp | 20 | ||||
-rw-r--r-- | scene/2d/ray_cast_2d.cpp | 12 | ||||
-rw-r--r-- | scene/3d/ray_cast.cpp | 35 | ||||
-rw-r--r-- | scene/3d/ray_cast.h | 4 | ||||
-rw-r--r-- | scene/SCsub | 2 | ||||
-rw-r--r-- | scene/gui/file_dialog.cpp | 57 | ||||
-rw-r--r-- | scene/gui/file_dialog.h | 5 | ||||
-rw-r--r-- | scene/gui/text_edit.cpp | 6 | ||||
-rw-r--r-- | scene/gui/tree.cpp | 27 | ||||
-rw-r--r-- | scene/gui/tree.h | 2 | ||||
-rw-r--r-- | scene/resources/material.cpp | 6 |
11 files changed, 142 insertions, 34 deletions
diff --git a/scene/2d/path_2d.cpp b/scene/2d/path_2d.cpp index 55c055e34f..e1c7331393 100644 --- a/scene/2d/path_2d.cpp +++ b/scene/2d/path_2d.cpp @@ -117,29 +117,27 @@ void PathFollow2D::_update_transform() { Vector2 pos = c->interpolate_baked(o, cubic); - Vector2 offset = Vector2(h_offset, v_offset); - - Transform2D t = get_transform(); - t.set_origin(pos); + Vector2 displacement_offset = Vector2(h_offset, v_offset); if (rotate) { Vector2 t_prev = (pos - c->interpolate_baked(o - delta_offset, cubic)).normalized(); - Vector2 t_cur = (c->interpolate_baked(o + delta_offset, cubic) - pos).normalized(); + Vector2 t_next = (c->interpolate_baked(o + delta_offset, cubic) - pos).normalized(); - float dot = t_prev.dot(t_cur); - float angle = Math::acos(CLAMP(dot, -1, 1)); + float angle = t_prev.angle_to(t_next); - t.rotate(angle); + set_rotation(get_rotation() + angle); - t.translate(offset); + Vector2 n = t_next; + Vector2 t = -n.tangent(); + pos += n * h_offset + t * v_offset; } else { - t.set_origin(t.get_origin() + offset); + pos += displacement_offset; } - set_transform(t); + set_position(pos); } void PathFollow2D::_notification(int p_what) { diff --git a/scene/2d/ray_cast_2d.cpp b/scene/2d/ray_cast_2d.cpp index 6ab20efdcc..a809023083 100644 --- a/scene/2d/ray_cast_2d.cpp +++ b/scene/2d/ray_cast_2d.cpp @@ -120,11 +120,11 @@ void RayCast2D::set_exclude_parent_body(bool p_exclude_parent_body) { if (!is_inside_tree()) return; - if (Object::cast_to<PhysicsBody2D>(get_parent())) { + if (Object::cast_to<CollisionObject2D>(get_parent())) { if (exclude_parent_body) - exclude.insert(Object::cast_to<PhysicsBody2D>(get_parent())->get_rid()); + exclude.insert(Object::cast_to<CollisionObject2D>(get_parent())->get_rid()); else - exclude.erase(Object::cast_to<PhysicsBody2D>(get_parent())->get_rid()); + exclude.erase(Object::cast_to<CollisionObject2D>(get_parent())->get_rid()); } } @@ -144,11 +144,11 @@ void RayCast2D::_notification(int p_what) { else set_physics_process(false); - if (Object::cast_to<PhysicsBody2D>(get_parent())) { + if (Object::cast_to<CollisionObject2D>(get_parent())) { if (exclude_parent_body) - exclude.insert(Object::cast_to<PhysicsBody2D>(get_parent())->get_rid()); + exclude.insert(Object::cast_to<CollisionObject2D>(get_parent())->get_rid()); else - exclude.erase(Object::cast_to<PhysicsBody2D>(get_parent())->get_rid()); + exclude.erase(Object::cast_to<CollisionObject2D>(get_parent())->get_rid()); } } break; case NOTIFICATION_EXIT_TREE: { diff --git a/scene/3d/ray_cast.cpp b/scene/3d/ray_cast.cpp index aebdcaf183..faeb18691a 100644 --- a/scene/3d/ray_cast.cpp +++ b/scene/3d/ray_cast.cpp @@ -119,6 +119,29 @@ bool RayCast::is_enabled() const { return enabled; } +void RayCast::set_exclude_parent_body(bool p_exclude_parent_body) { + + if (exclude_parent_body == p_exclude_parent_body) + return; + + exclude_parent_body = p_exclude_parent_body; + + if (!is_inside_tree()) + return; + + if (Object::cast_to<CollisionObject>(get_parent())) { + if (exclude_parent_body) + exclude.insert(Object::cast_to<CollisionObject>(get_parent())->get_rid()); + else + exclude.erase(Object::cast_to<CollisionObject>(get_parent())->get_rid()); + } +} + +bool RayCast::get_exclude_parent_body() const { + + return exclude_parent_body; +} + void RayCast::_notification(int p_what) { switch (p_what) { @@ -133,6 +156,13 @@ void RayCast::_notification(int p_what) { } else set_physics_process(false); + if (Object::cast_to<CollisionObject>(get_parent())) { + if (exclude_parent_body) + exclude.insert(Object::cast_to<CollisionObject>(get_parent())->get_rid()); + else + exclude.erase(Object::cast_to<CollisionObject>(get_parent())->get_rid()); + } + } break; case NOTIFICATION_EXIT_TREE: { @@ -256,7 +286,11 @@ void RayCast::_bind_methods() { ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &RayCast::set_collision_mask_bit); ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &RayCast::get_collision_mask_bit); + ClassDB::bind_method(D_METHOD("set_exclude_parent_body", "mask"), &RayCast::set_exclude_parent_body); + ClassDB::bind_method(D_METHOD("get_exclude_parent_body"), &RayCast::get_exclude_parent_body); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "exclude_parent"), "set_exclude_parent_body", "get_exclude_parent_body"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "cast_to"), "set_cast_to", "get_cast_to"); ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask"); } @@ -332,4 +366,5 @@ RayCast::RayCast() { collision_mask = 1; cast_to = Vector3(0, -1, 0); debug_shape = NULL; + exclude_parent_body = true; } diff --git a/scene/3d/ray_cast.h b/scene/3d/ray_cast.h index ca94580271..9fb1a1be67 100644 --- a/scene/3d/ray_cast.h +++ b/scene/3d/ray_cast.h @@ -48,6 +48,7 @@ class RayCast : public Spatial { Set<RID> exclude; uint32_t collision_mask; + bool exclude_parent_body; Node *debug_shape; Ref<Material> debug_material; @@ -74,6 +75,9 @@ public: void set_collision_mask_bit(int p_bit, bool p_value); bool get_collision_mask_bit(int p_bit) const; + void set_exclude_parent_body(bool p_exclude_parent_body); + bool get_exclude_parent_body() const; + void force_raycast_update(); bool is_colliding() const; Object *get_collider() const; diff --git a/scene/SCsub b/scene/SCsub index 513adeffda..5d81e818ba 100644 --- a/scene/SCsub +++ b/scene/SCsub @@ -30,7 +30,7 @@ SConscript('resources/SCsub') # Build it all as a library -lib = env.Library("scene", env.scene_sources) +lib = env.add_library("scene", env.scene_sources) env.Prepend(LIBS=[lib]) Export('env') diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 663a2b390e..9bfb70bf42 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -47,6 +47,7 @@ void FileDialog::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { refresh->set_icon(get_icon("reload")); + dir_up->set_icon(get_icon("ArrowUp", "EditorIcons")); } if (p_what == NOTIFICATION_DRAW) { @@ -122,6 +123,9 @@ void FileDialog::update_dir() { if (drives->is_visible()) { drives->select(dir_access->get_current_drive()); } + + // Deselect any item, to make "Select Current Folder" button text by default. + deselect_items(); } void FileDialog::_dir_entered(String p_dir) { @@ -156,6 +160,10 @@ void FileDialog::_post_popup() { tree->grab_focus(); set_process_unhandled_input(true); + + // For open dir mode, deselect all items on file dialog open. + if (mode == MODE_OPEN_DIR) + deselect_items(); } void FileDialog::_action_pressed() { @@ -296,6 +304,37 @@ bool FileDialog::_is_open_should_be_disabled() { return false; } +void FileDialog::_go_up() { + + dir_access->change_dir(".."); + update_file_list(); + update_dir(); +} + +void FileDialog::deselect_items() { + + // Clear currently selected items in file manager. + tree->deselect_all(); + + // And change get_ok title. + if (!tree->is_anything_selected()) { + get_ok()->set_disabled(_is_open_should_be_disabled()); + + switch (mode) { + + case MODE_OPEN_FILE: + case MODE_OPEN_FILES: + get_ok()->set_text(TTR("Open")); + get_ok()->set_disabled(false); + break; + + case MODE_OPEN_DIR: + get_ok()->set_text(TTR("Select Current Folder")); + get_ok()->set_disabled(false); + break; + } + } +} void FileDialog::_tree_selected() { TreeItem *ti = tree->get_selected(); @@ -306,6 +345,8 @@ void FileDialog::_tree_selected() { if (!d["dir"]) { file->set_text(d["name"]); + } else if (mode == MODE_OPEN_DIR) { + get_ok()->set_text(TTR("Select this Folder")); } get_ok()->set_disabled(_is_open_should_be_disabled()); @@ -349,7 +390,7 @@ void FileDialog::update_file_list() { while ((item = dir_access->get_next(&isdir)) != "") { - if (item == ".") + if (item == "." || item == "..") continue; ishidden = dir_access->current_is_hidden(); @@ -362,11 +403,6 @@ void FileDialog::update_file_list() { } } - if (dirs.find("..") == NULL) { - //may happen if lacking permissions - dirs.push_back(".."); - } - dirs.sort_custom<NaturalNoCaseComparator>(); files.sort_custom<NaturalNoCaseComparator>(); @@ -742,6 +778,8 @@ void FileDialog::_bind_methods() { ClassDB::bind_method(D_METHOD("_make_dir_confirm"), &FileDialog::_make_dir_confirm); ClassDB::bind_method(D_METHOD("_update_file_list"), &FileDialog::update_file_list); ClassDB::bind_method(D_METHOD("_update_dir"), &FileDialog::update_dir); + ClassDB::bind_method(D_METHOD("_go_up"), &FileDialog::_go_up); + ClassDB::bind_method(D_METHOD("deselect_items"), &FileDialog::deselect_items); ClassDB::bind_method(D_METHOD("invalidate"), &FileDialog::invalidate); @@ -789,6 +827,12 @@ FileDialog::FileDialog() { set_title(RTR("Save a File")); HBoxContainer *hbc = memnew(HBoxContainer); + + dir_up = memnew(ToolButton); + dir_up->set_tooltip(TTR("Go to parent folder")); + hbc->add_child(dir_up); + dir_up->connect("pressed", this, "_go_up"); + hbc->add_child(memnew(Label(RTR("Path:")))); dir = memnew(LineEdit); hbc->add_child(dir); @@ -833,6 +877,7 @@ FileDialog::FileDialog() { //cancel->connect("pressed", this,"_cancel_pressed"); tree->connect("cell_selected", this, "_tree_selected", varray(), CONNECT_DEFERRED); tree->connect("item_activated", this, "_tree_db_selected", varray()); + tree->connect("nothing_selected", this, "deselect_items"); dir->connect("text_entered", this, "_dir_entered"); file->connect("text_entered", this, "_file_entered"); filter->connect("item_selected", this, "_filter_selected"); diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h index 6281e88731..ca3d9f54b2 100644 --- a/scene/gui/file_dialog.h +++ b/scene/gui/file_dialog.h @@ -86,6 +86,8 @@ private: DirAccess *dir_access; ConfirmationDialog *confirm_save; + ToolButton *dir_up; + ToolButton *refresh; Vector<String> filters; @@ -111,6 +113,7 @@ private: void _filter_selected(int); void _make_dir(); void _make_dir_confirm(); + void _go_up(); void _update_drives(); @@ -156,6 +159,8 @@ public: void invalidate(); + void deselect_items(); + FileDialog(); ~FileDialog(); }; diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 166b55d6f3..6fa73e4b58 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -303,8 +303,6 @@ void TextEdit::_update_scrollbars() { int total_rows = (is_hiding_enabled() ? get_total_unhidden_rows() : text.size()); if (scroll_past_end_of_file_enabled) { total_rows += visible_rows - 1; - } else { - total_rows -= 1; } int vscroll_pixels = v_scroll->get_combined_minimum_size().width; @@ -3081,7 +3079,7 @@ void TextEdit::_scroll_down(real_t p_delta) { if (smooth_scroll_enabled) { int max_v_scroll = get_total_unhidden_rows(); if (!scroll_past_end_of_file_enabled) { - max_v_scroll -= get_visible_rows() + 1; + max_v_scroll -= get_visible_rows(); max_v_scroll = CLAMP(max_v_scroll, 0, get_total_unhidden_rows()); } @@ -3139,7 +3137,7 @@ void TextEdit::_scroll_lines_down() { // calculate the maximum vertical scroll position int max_v_scroll = get_total_unhidden_rows(); if (!scroll_past_end_of_file_enabled) { - max_v_scroll -= get_visible_rows() + 1; + max_v_scroll -= get_visible_rows(); max_v_scroll = CLAMP(max_v_scroll, 0, get_total_unhidden_rows()); } diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 57c6737848..ab12d123ba 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -1923,9 +1923,6 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool c = c->next; item_h += child_h; } - - if (!c && !p_mod->get_shift() && !p_mod->get_control() && !p_mod->get_command() && !click_handled && p_button != BUTTON_RIGHT) - emit_signal("nothing_selected"); } } @@ -2602,6 +2599,11 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { if (drag_touching) { set_physics_process(true); } + + if (b->get_button_index() == BUTTON_LEFT) { + if (get_item_at_position(b->get_position()) == NULL && !b->get_shift() && !b->get_control() && !b->get_command()) + emit_signal("nothing_selected"); + } } } break; @@ -3046,6 +3048,25 @@ void Tree::set_select_mode(SelectMode p_mode) { select_mode = p_mode; } +void Tree::deselect_all() { + + TreeItem *item = get_next_selected(get_root()); + while (item) { + item->deselect(selected_col); + item = get_next_selected(get_root()); + } + + selected_item = NULL; + selected_col = -1; + + update(); +} + +bool Tree::is_anything_selected() { + + return (selected_item != NULL); +} + void Tree::clear() { if (blocked > 0) { diff --git a/scene/gui/tree.h b/scene/gui/tree.h index 64d6016942..112de3165f 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -546,6 +546,8 @@ public: int get_selected_column() const; int get_pressed_button() const; void set_select_mode(SelectMode p_mode); + void deselect_all(); + bool is_anything_selected(); void set_columns(int p_columns); int get_columns() const; diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 286840656b..79f642a09b 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -653,16 +653,16 @@ void SpatialMaterial::_update_shader() { code += "\t\tvec2 P = view_dir.xy * depth_scale;\n"; code += "\t\tvec2 delta = P / num_layers;\n"; code += "\t\tvec2 ofs = base_uv;\n"; - code += "\t\tfloat depth = texture(texture_depth, ofs).r;\n"; + code += "\t\tfloat depth = textureLod(texture_depth, ofs,0.0).r;\n"; code += "\t\tfloat current_depth = 0.0;\n"; code += "\t\twhile(current_depth < depth) {\n"; code += "\t\t\tofs -= delta;\n"; - code += "\t\t\tdepth = texture(texture_depth, ofs).r;\n"; + code += "\t\t\tdepth = textureLod(texture_depth, ofs,0.0).r;\n"; code += "\t\t\tcurrent_depth += layer_depth;\n"; code += "\t\t}\n"; code += "\t\tvec2 prev_ofs = ofs + delta;\n"; code += "\t\tfloat after_depth = depth - current_depth;\n"; - code += "\t\tfloat before_depth = texture(texture_depth, prev_ofs).r - current_depth + layer_depth;\n"; + code += "\t\tfloat before_depth = textureLod(texture_depth, prev_ofs, 0.0).r - current_depth + layer_depth;\n"; code += "\t\tfloat weight = after_depth / (after_depth - before_depth);\n"; code += "\t\tofs = mix(ofs,prev_ofs,weight);\n"; |