diff options
Diffstat (limited to 'scene/2d')
-rw-r--r-- | scene/2d/canvas_item.cpp | 103 | ||||
-rw-r--r-- | scene/2d/canvas_item.h | 19 | ||||
-rw-r--r-- | scene/2d/node_2d.cpp | 42 | ||||
-rw-r--r-- | scene/2d/node_2d.h | 7 | ||||
-rw-r--r-- | scene/2d/physics_body_2d.cpp | 37 | ||||
-rw-r--r-- | scene/2d/physics_body_2d.h | 8 |
6 files changed, 209 insertions, 7 deletions
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index f90da51eea..ae857bbce9 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -720,6 +720,95 @@ bool CanvasItem::is_draw_behind_parent_enabled() const{ return behind; } +void CanvasItem::set_shader(const Ref<Shader>& p_shader) { + + ERR_FAIL_COND(p_shader.is_valid() && p_shader->get_mode()!=Shader::MODE_CANVAS_ITEM); + +#ifdef TOOLS_ENABLED + + if (shader.is_valid()) { + shader->disconnect("changed",this,"_shader_changed"); + } +#endif + shader=p_shader; + +#ifdef TOOLS_ENABLED + + if (shader.is_valid()) { + shader->connect("changed",this,"_shader_changed"); + } +#endif + + RID rid; + if (shader.is_valid()) + rid=shader->get_rid(); + VS::get_singleton()->canvas_item_set_shader(canvas_item,rid); + _change_notify(); //properties for shader exposed +} + +void CanvasItem::set_use_parent_shader(bool p_use_parent_shader) { + + use_parent_shader=p_use_parent_shader; + VS::get_singleton()->canvas_item_set_use_parent_shader(canvas_item,p_use_parent_shader); +} + +bool CanvasItem::get_use_parent_shader() const{ + + return use_parent_shader; +} + +Ref<Shader> CanvasItem::get_shader() const{ + + return shader; +} + +void CanvasItem::set_shader_param(const StringName& p_param,const Variant& p_value) { + + VS::get_singleton()->canvas_item_set_shader_param(canvas_item,p_param,p_value); +} + +Variant CanvasItem::get_shader_param(const StringName& p_param) const { + + return VS::get_singleton()->canvas_item_get_shader_param(canvas_item,p_param); +} + +bool CanvasItem::_set(const StringName& p_name, const Variant& p_value) { + + if (shader.is_valid()) { + StringName pr = shader->remap_param(p_name); + if (pr) { + set_shader_param(pr,p_value); + return true; + } + } + return false; +} + +bool CanvasItem::_get(const StringName& p_name,Variant &r_ret) const{ + + if (shader.is_valid()) { + StringName pr = shader->remap_param(p_name); + if (pr) { + r_ret=get_shader_param(pr); + return true; + } + } + return false; + +} +void CanvasItem::_get_property_list( List<PropertyInfo> *p_list) const{ + + if (shader.is_valid()) { + shader->get_param_list(p_list); + } +} + +#ifdef TOOLS_ENABLED +void CanvasItem::_shader_changed() { + + _change_notify(); +} +#endif void CanvasItem::_bind_methods() { @@ -761,7 +850,9 @@ void CanvasItem::_bind_methods() { ObjectTypeDB::bind_method(_MD("_set_on_top","on_top"),&CanvasItem::_set_on_top); ObjectTypeDB::bind_method(_MD("_is_on_top"),&CanvasItem::_is_on_top); - +#ifdef TOOLS_ENABLED + ObjectTypeDB::bind_method(_MD("_shader_changed"),&CanvasItem::_shader_changed); +#endif //ObjectTypeDB::bind_method(_MD("get_transform"),&CanvasItem::get_transform); ObjectTypeDB::bind_method(_MD("draw_line","from","to","color","width"),&CanvasItem::draw_line,DEFVAL(1.0)); @@ -786,15 +877,22 @@ void CanvasItem::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_world_2d"),&CanvasItem::get_world_2d); //ObjectTypeDB::bind_method(_MD("get_viewport"),&CanvasItem::get_viewport); + ObjectTypeDB::bind_method(_MD("set_shader","shader"),&CanvasItem::set_shader); + ObjectTypeDB::bind_method(_MD("get_shader"),&CanvasItem::get_shader); + ObjectTypeDB::bind_method(_MD("set_use_parent_shader","enable"),&CanvasItem::set_use_parent_shader); + ObjectTypeDB::bind_method(_MD("get_use_parent_shader"),&CanvasItem::get_use_parent_shader); + BIND_VMETHOD(MethodInfo("_draw")); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"visibility/visible"), _SCS("_set_visible_"),_SCS("_is_visible_") ); ADD_PROPERTY( PropertyInfo(Variant::REAL,"visibility/opacity",PROPERTY_HINT_RANGE, "0,1,0.01"), _SCS("set_opacity"),_SCS("get_opacity") ); ADD_PROPERTY( PropertyInfo(Variant::REAL,"visibility/self_opacity",PROPERTY_HINT_RANGE, "0,1,0.01"), _SCS("set_self_opacity"),_SCS("get_self_opacity") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"visibility/behind_parent"), _SCS("set_draw_behind_parent"),_SCS("is_draw_behind_parent_enabled") ); + ADD_PROPERTYNZ( PropertyInfo(Variant::BOOL,"visibility/behind_parent"), _SCS("set_draw_behind_parent"),_SCS("is_draw_behind_parent_enabled") ); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"visibility/on_top",PROPERTY_HINT_NONE,"",0), _SCS("_set_on_top"),_SCS("_is_on_top") ); //compatibility ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"visibility/blend_mode",PROPERTY_HINT_ENUM, "Mix,Add,Sub,Mul,PMAlpha"), _SCS("set_blend_mode"),_SCS("get_blend_mode") ); + ADD_PROPERTYNZ( PropertyInfo(Variant::OBJECT,"shader/shader",PROPERTY_HINT_RESOURCE_TYPE, "CanvasItemShader,CanvasItemShaderGraph"), _SCS("set_shader"),_SCS("get_shader") ); + ADD_PROPERTYNZ( PropertyInfo(Variant::BOOL,"shader/use_parent"), _SCS("set_use_parent_shader"),_SCS("get_use_parent_shader") ); //exporting these two things doesn't really make much sense i think //ADD_PROPERTY( PropertyInfo(Variant::BOOL,"transform/toplevel"), _SCS("set_as_toplevel"),_SCS("is_set_as_toplevel") ); //ADD_PROPERTY(PropertyInfo(Variant::BOOL,"transform/notify"),_SCS("set_transform_notify"),_SCS("is_transform_notify_enabled")); @@ -871,6 +969,7 @@ CanvasItem::CanvasItem() : xform_change(this) { block_transform_notify=false; // viewport=NULL; canvas_layer=NULL; + use_parent_shader; global_invalid=true; C=NULL; diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h index dbf8fd79e9..ed3ade9df2 100644 --- a/scene/2d/canvas_item.h +++ b/scene/2d/canvas_item.h @@ -32,6 +32,7 @@ #include "scene/main/node.h" #include "scene/resources/texture.h" #include "scene/main/scene_main_loop.h" +#include "scene/resources/shader.h" class CanvasLayer; class Viewport; @@ -80,6 +81,9 @@ private: bool block_transform_notify; bool behind; + bool use_parent_shader; + Ref<Shader> shader; + mutable Matrix32 global_transform; mutable bool global_invalid; @@ -99,8 +103,9 @@ private: void _queue_sort_children(); void _sort_children(); - - +#ifdef TOOLS_ENABLED + void _shader_changed(); +#endif void _notify_transform(CanvasItem *p_node); void _set_on_top(bool p_on_top) { set_draw_behind_parent(!p_on_top); } @@ -108,6 +113,9 @@ private: protected: + bool _set(const StringName& p_name, const Variant& p_value); + bool _get(const StringName& p_name,Variant &r_ret) const; + void _get_property_list( List<PropertyInfo> *p_list) const; _FORCE_INLINE_ void _notify_transform() { if (!is_inside_tree()) return; _notify_transform(this); if (!block_transform_notify) notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED); } @@ -204,7 +212,14 @@ public: RID get_canvas() const; Ref<World2D> get_world_2d() const; + void set_shader(const Ref<Shader>& p_shader); + Ref<Shader> get_shader() const; + + void set_use_parent_shader(bool p_use_parent_shader); + bool get_use_parent_shader() const; + void set_shader_param(const StringName& p_param,const Variant& p_value); + Variant get_shader_param(const StringName& p_param) const; CanvasItem(); ~CanvasItem(); diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp index 6dcee3458f..8b4196ee7f 100644 --- a/scene/2d/node_2d.cpp +++ b/scene/2d/node_2d.cpp @@ -289,6 +289,35 @@ void Node2D::set_global_transform(const Matrix32& p_transform) { } +void Node2D::set_z(int p_z) { + + ERR_FAIL_COND(p_z<VS::CANVAS_ITEM_Z_MIN); + ERR_FAIL_COND(p_z>VS::CANVAS_ITEM_Z_MAX); + z=p_z; + VS::get_singleton()->canvas_item_set_z(get_canvas_item(),z); + +} + +void Node2D::set_z_as_relative(bool p_enabled) { + + if (z_relative==p_enabled) + return; + z_relative=p_enabled; + VS::get_singleton()->canvas_item_set_z_as_relative_to_parent(get_canvas_item(),p_enabled); +} + +bool Node2D::is_z_relative() const { + + return z_relative; +} + + +int Node2D::get_z() const{ + + return z; +} + + void Node2D::_bind_methods() { @@ -308,18 +337,25 @@ void Node2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("move_local_x","delta","scaled"),&Node2D::move_x,DEFVAL(false)); ObjectTypeDB::bind_method(_MD("move_local_y","delta","scaled"),&Node2D::move_y,DEFVAL(false)); + ObjectTypeDB::bind_method(_MD("set_global_pos","pos"),&Node2D::set_global_pos); ObjectTypeDB::bind_method(_MD("get_global_pos"),&Node2D::get_global_pos); - ObjectTypeDB::bind_method(_MD("set_global_pos"),&Node2D::set_global_pos); ObjectTypeDB::bind_method(_MD("set_transform","xform"),&Node2D::set_transform); ObjectTypeDB::bind_method(_MD("set_global_transform","xform"),&Node2D::set_global_transform); + ObjectTypeDB::bind_method(_MD("set_z","z"),&Node2D::set_z); + ObjectTypeDB::bind_method(_MD("get_z"),&Node2D::get_z); + + ObjectTypeDB::bind_method(_MD("set_z_as_relative","enable"),&Node2D::set_z_as_relative); + ObjectTypeDB::bind_method(_MD("is_z_relative"),&Node2D::is_z_relative); + ObjectTypeDB::bind_method(_MD("edit_set_pivot"),&Node2D::edit_set_pivot); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2,"transform/pos"),_SCS("set_pos"),_SCS("get_pos")); ADD_PROPERTY(PropertyInfo(Variant::REAL,"transform/rot",PROPERTY_HINT_RANGE,"-1440,1440,0.1"),_SCS("_set_rotd"),_SCS("_get_rotd")); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2,"transform/scale"),_SCS("set_scale"),_SCS("get_scale")); - + ADD_PROPERTY(PropertyInfo(Variant::INT,"z/z",PROPERTY_HINT_RANGE,itos(VS::CANVAS_ITEM_Z_MIN)+","+itos(VS::CANVAS_ITEM_Z_MAX)+",1"),_SCS("set_z"),_SCS("get_z")); + ADD_PROPERTY(PropertyInfo(Variant::BOOL,"z/relative"),_SCS("set_z_as_relative"),_SCS("is_z_relative")); } @@ -331,6 +367,8 @@ Node2D::Node2D() { angle=0; scale=Vector2(1,1); _xform_dirty=false; + z=0; + z_relative=true; } diff --git a/scene/2d/node_2d.h b/scene/2d/node_2d.h index 582c56fa9b..61b8c829d6 100644 --- a/scene/2d/node_2d.h +++ b/scene/2d/node_2d.h @@ -38,6 +38,8 @@ class Node2D : public CanvasItem { Point2 pos; float angle; Size2 scale; + int z; + bool z_relative; Matrix32 _mat; @@ -85,6 +87,11 @@ public: void set_global_transform(const Matrix32& p_transform); void set_global_pos(const Point2& p_pos); + void set_z(int p_z); + int get_z() const; + + void set_z_as_relative(bool p_enabled); + bool is_z_relative() const; Matrix32 get_transform() const; diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 2413fbded1..6f18325212 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -43,13 +43,44 @@ void PhysicsBody2D::_notification(int p_what) { */ } +void PhysicsBody2D::set_one_way_collision_direction(const Vector2& p_dir) { + + one_way_collision_direction=p_dir; + Physics2DServer::get_singleton()->body_set_one_way_collision_direction(get_rid(),p_dir); +} + +Vector2 PhysicsBody2D::get_one_way_collision_direction() const{ + + return one_way_collision_direction; +} + + +void PhysicsBody2D::set_one_way_collision_max_depth(float p_depth) { + + one_way_collision_max_depth=p_depth; + Physics2DServer::get_singleton()->body_set_one_way_collision_max_depth(get_rid(),p_depth); + +} + +float PhysicsBody2D::get_one_way_collision_max_depth() const{ + + return one_way_collision_max_depth; +} + + void PhysicsBody2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_layer_mask","mask"),&PhysicsBody2D::set_layer_mask); ObjectTypeDB::bind_method(_MD("get_layer_mask"),&PhysicsBody2D::get_layer_mask); + ObjectTypeDB::bind_method(_MD("set_one_way_collision_direction","dir"),&PhysicsBody2D::set_one_way_collision_direction); + ObjectTypeDB::bind_method(_MD("get_one_way_collision_direction"),&PhysicsBody2D::get_one_way_collision_direction); + ObjectTypeDB::bind_method(_MD("set_one_way_collision_max_depth","depth"),&PhysicsBody2D::set_one_way_collision_max_depth); + ObjectTypeDB::bind_method(_MD("get_one_way_collision_max_depth"),&PhysicsBody2D::get_one_way_collision_max_depth); ObjectTypeDB::bind_method(_MD("add_collision_exception_with","body:PhysicsBody2D"),&PhysicsBody2D::add_collision_exception_with); ObjectTypeDB::bind_method(_MD("remove_collision_exception_with","body:PhysicsBody2D"),&PhysicsBody2D::remove_collision_exception_with); ADD_PROPERTY(PropertyInfo(Variant::INT,"layers",PROPERTY_HINT_ALL_FLAGS),_SCS("set_layer_mask"),_SCS("get_layer_mask")); + ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2,"one_way_collision/direction"),_SCS("set_one_way_collision_direction"),_SCS("get_one_way_collision_direction")); + ADD_PROPERTYNZ(PropertyInfo(Variant::REAL,"one_way_collision/max_depth"),_SCS("set_one_way_collision_max_depth"),_SCS("get_one_way_collision_max_depth")); } void PhysicsBody2D::set_layer_mask(uint32_t p_mask) { @@ -66,6 +97,7 @@ uint32_t PhysicsBody2D::get_layer_mask() const { PhysicsBody2D::PhysicsBody2D(Physics2DServer::BodyMode p_mode) : CollisionObject2D( Physics2DServer::get_singleton()->body_create(p_mode), false) { mask=1; + set_one_way_collision_max_depth(0); } @@ -932,7 +964,7 @@ Vector2 KinematicBody2D::move(const Vector2& p_motion) { //if (d<margin) /// continue; - recover_motion+=(b-a)*0.2; + recover_motion+=(b-a)*0.4; } if (recover_motion==Vector2()) { @@ -963,6 +995,7 @@ Vector2 KinematicBody2D::move(const Vector2& p_motion) { bool valid = dss->cast_motion(get_shape(i)->get_rid(), get_global_transform() * get_shape_transform(i), p_motion, 0,lsafe,lunsafe,exclude,get_layer_mask(),mask); //print_line("shape: "+itos(i)+" travel:"+rtos(ltravel)); if (!valid) { + safe=0; unsafe=0; best_shape=i; //sadly it's the best @@ -994,9 +1027,11 @@ Vector2 KinematicBody2D::move(const Vector2& p_motion) { bool c2 = dss->rest_info(get_shape(best_shape)->get_rid(), ugt*get_shape_transform(best_shape), Vector2(), margin,&rest_info,exclude,get_layer_mask(),mask); if (!c2) { //should not happen, but floating point precision is so weird.. + colliding=false; } else { + //print_line("Travel: "+rtos(travel)); colliding=true; collision=rest_info.point; diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h index 956999ce31..eed43c95be 100644 --- a/scene/2d/physics_body_2d.h +++ b/scene/2d/physics_body_2d.h @@ -39,6 +39,8 @@ class PhysicsBody2D : public CollisionObject2D { OBJ_TYPE(PhysicsBody2D,CollisionObject2D); uint32_t mask; + Vector2 one_way_collision_direction; + float one_way_collision_max_depth; protected: void _notification(int p_what); @@ -53,6 +55,12 @@ public: void add_collision_exception_with(Node* p_node); //must be physicsbody void remove_collision_exception_with(Node* p_node); + void set_one_way_collision_direction(const Vector2& p_dir); + Vector2 get_one_way_collision_direction() const; + + void set_one_way_collision_max_depth(float p_dir); + float get_one_way_collision_max_depth() const; + PhysicsBody2D(); }; |