diff options
Diffstat (limited to 'scene')
27 files changed, 1562 insertions, 42 deletions
diff --git a/scene/2d/animated_sprite.cpp b/scene/2d/animated_sprite.cpp index 312b04d414..b49426f7e2 100644 --- a/scene/2d/animated_sprite.cpp +++ b/scene/2d/animated_sprite.cpp @@ -329,7 +329,7 @@ void AnimatedSprite::_bind_methods() { ADD_SIGNAL(MethodInfo("frame_changed")); ADD_PROPERTYNZ( PropertyInfo( Variant::OBJECT, "frames",PROPERTY_HINT_RESOURCE_TYPE,"SpriteFrames"), _SCS("set_sprite_frames"),_SCS("get_sprite_frames")); - ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "frame"), _SCS("set_frame"),_SCS("get_frame")); + ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "frame",PROPERTY_HINT_SPRITE_FRAME), _SCS("set_frame"),_SCS("get_frame")); ADD_PROPERTY( PropertyInfo( Variant::BOOL, "centered"), _SCS("set_centered"),_SCS("is_centered")); ADD_PROPERTYNZ( PropertyInfo( Variant::VECTOR2, "offset"), _SCS("set_offset"),_SCS("get_offset")); ADD_PROPERTY( PropertyInfo( Variant::BOOL, "flip_h"), _SCS("set_flip_h"),_SCS("is_flipped_h")); diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp index 827256c2fa..f9e79e25bc 100644 --- a/scene/2d/area_2d.cpp +++ b/scene/2d/area_2d.cpp @@ -52,6 +52,17 @@ bool Area2D::is_gravity_a_point() const{ return gravity_is_point; } +void Area2D::set_gravity_distance_scale(real_t p_scale){ + + gravity_distance_scale=p_scale; + Physics2DServer::get_singleton()->area_set_param(get_rid(),Physics2DServer::AREA_PARAM_GRAVITY_DISTANCE_SCALE,p_scale); + +} + +real_t Area2D::get_gravity_distance_scale() const{ + return gravity_distance_scale; +} + void Area2D::set_gravity_vector(const Vector2& p_vec){ gravity_vec=p_vec; @@ -535,6 +546,39 @@ uint32_t Area2D::get_layer_mask() const { return layer_mask; } +void Area2D::set_collision_mask_bit(int p_bit, bool p_value) { + + uint32_t mask = get_collision_mask(); + if (p_value) + mask|=1<<p_bit; + else + mask&=~(1<<p_bit); + set_collision_mask(mask); + +} + +bool Area2D::get_collision_mask_bit(int p_bit) const{ + + return get_collision_mask()&(1<<p_bit); +} + + +void Area2D::set_layer_mask_bit(int p_bit, bool p_value) { + + uint32_t mask = get_layer_mask(); + if (p_value) + mask|=1<<p_bit; + else + mask&=~(1<<p_bit); + set_layer_mask(mask); + +} + +bool Area2D::get_layer_mask_bit(int p_bit) const{ + + return get_layer_mask()&(1<<p_bit); +} + void Area2D::_bind_methods() { @@ -550,6 +594,9 @@ void Area2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_gravity_is_point","enable"),&Area2D::set_gravity_is_point); ObjectTypeDB::bind_method(_MD("is_gravity_a_point"),&Area2D::is_gravity_a_point); + ObjectTypeDB::bind_method(_MD("set_gravity_distance_scale","distance_scale"),&Area2D::set_gravity_distance_scale); + ObjectTypeDB::bind_method(_MD("get_gravity_distance_scale"),&Area2D::get_gravity_distance_scale); + ObjectTypeDB::bind_method(_MD("set_gravity_vector","vector"),&Area2D::set_gravity_vector); ObjectTypeDB::bind_method(_MD("get_gravity_vector"),&Area2D::get_gravity_vector); @@ -571,6 +618,12 @@ void Area2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_layer_mask","layer_mask"),&Area2D::set_layer_mask); ObjectTypeDB::bind_method(_MD("get_layer_mask"),&Area2D::get_layer_mask); + ObjectTypeDB::bind_method(_MD("set_collision_mask_bit","bit","value"),&Area2D::set_collision_mask_bit); + ObjectTypeDB::bind_method(_MD("get_collision_mask_bit","bit"),&Area2D::get_collision_mask_bit); + + ObjectTypeDB::bind_method(_MD("set_layer_mask_bit","bit","value"),&Area2D::set_layer_mask_bit); + ObjectTypeDB::bind_method(_MD("get_layer_mask_bit","bit"),&Area2D::get_layer_mask_bit); + ObjectTypeDB::bind_method(_MD("set_enable_monitoring","enable"),&Area2D::set_enable_monitoring); ObjectTypeDB::bind_method(_MD("is_monitoring_enabled"),&Area2D::is_monitoring_enabled); @@ -600,6 +653,7 @@ void Area2D::_bind_methods() { ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"space_override",PROPERTY_HINT_ENUM,"Disabled,Combine,Replace"),_SCS("set_space_override_mode"),_SCS("get_space_override_mode")); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"gravity_point"),_SCS("set_gravity_is_point"),_SCS("is_gravity_a_point")); + ADD_PROPERTY( PropertyInfo(Variant::REAL,"gravity_distance_scale", PROPERTY_HINT_RANGE,"0,1024,0.001"),_SCS("set_gravity_distance_scale"),_SCS("get_gravity_distance_scale")); ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"gravity_vec"),_SCS("set_gravity_vector"),_SCS("get_gravity_vector")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"gravity",PROPERTY_HINT_RANGE,"-1024,1024,0.01"),_SCS("set_gravity"),_SCS("get_gravity")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"linear_damp",PROPERTY_HINT_RANGE,"0,1024,0.001"),_SCS("set_linear_damp"),_SCS("get_linear_damp")); @@ -618,6 +672,7 @@ Area2D::Area2D() : CollisionObject2D(Physics2DServer::get_singleton()->area_crea set_gravity(98);; set_gravity_vector(Vector2(0,1)); gravity_is_point=false; + gravity_distance_scale=0; linear_damp=0.1; angular_damp=1; locked=false; diff --git a/scene/2d/area_2d.h b/scene/2d/area_2d.h index 0c064f54cd..f5a88390e7 100644 --- a/scene/2d/area_2d.h +++ b/scene/2d/area_2d.h @@ -49,6 +49,7 @@ private: Vector2 gravity_vec; real_t gravity; bool gravity_is_point; + real_t gravity_distance_scale; real_t linear_damp; real_t angular_damp; uint32_t collision_mask; @@ -132,6 +133,9 @@ public: void set_gravity_is_point(bool p_enabled); bool is_gravity_a_point() const; + void set_gravity_distance_scale(real_t p_scale); + real_t get_gravity_distance_scale() const; + void set_gravity_vector(const Vector2& p_vec); Vector2 get_gravity_vector() const; @@ -159,6 +163,12 @@ public: void set_layer_mask(uint32_t p_mask); uint32_t get_layer_mask() const; + void set_collision_mask_bit(int p_bit, bool p_value); + bool get_collision_mask_bit(int p_bit) const; + + void set_layer_mask_bit(int p_bit, bool p_value); + bool get_layer_mask_bit(int p_bit) const; + Array get_overlapping_bodies() const; //function for script Array get_overlapping_areas() const; //function for script diff --git a/scene/2d/navigation2d.cpp b/scene/2d/navigation2d.cpp index 5a02501816..5db0e0a9fc 100644 --- a/scene/2d/navigation2d.cpp +++ b/scene/2d/navigation2d.cpp @@ -91,9 +91,13 @@ void Navigation2D::_navpoly_link(int p_id) { } else { if (C->get().B!=NULL) { - print_line(String()+_get_vertex(ek.a)+" -> "+_get_vertex(ek.b)); + ConnectionPending pending; + pending.polygon=&p; + pending.edge=j; + p.edges[j].P=C->get().pending.push_back(pending); + continue; + //print_line(String()+_get_vertex(ek.a)+" -> "+_get_vertex(ek.b)); } - ERR_CONTINUE(C->get().B!=NULL); //wut C->get().B=&p; C->get().B_edge=j; @@ -133,7 +137,12 @@ void Navigation2D::_navpoly_unlink(int p_id) { EdgeKey ek(edges[i].point,edges[next].point); Map<EdgeKey,Connection>::Element *C=connections.find(ek); ERR_CONTINUE(!C); - if (C->get().B) { + + if (edges[i].P) { + C->get().pending.erase(edges[i].P); + edges[i].P=NULL; + + } else if (C->get().B) { //disconnect C->get().B->edges[C->get().B_edge].C=NULL; @@ -149,6 +158,20 @@ void Navigation2D::_navpoly_unlink(int p_id) { C->get().B=NULL; C->get().B_edge=-1; + if (C->get().pending.size()) { + //reconnect if something is pending + ConnectionPending cp = C->get().pending.front()->get(); + C->get().pending.pop_front(); + + C->get().B=cp.polygon; + C->get().B_edge=cp.edge; + C->get().A->edges[C->get().A_edge].C=cp.polygon; + C->get().A->edges[C->get().A_edge].C_edge=cp.edge; + cp.polygon->edges[cp.edge].C=C->get().A; + cp.polygon->edges[cp.edge].C_edge=C->get().A_edge; + cp.polygon->edges[cp.edge].P=NULL; + } + } else { connections.erase(C); //erase diff --git a/scene/2d/navigation2d.h b/scene/2d/navigation2d.h index 829b0f544b..231f1e8c63 100644 --- a/scene/2d/navigation2d.h +++ b/scene/2d/navigation2d.h @@ -41,7 +41,13 @@ class Navigation2D : public Node2D { struct NavMesh; + struct Polygon; + struct ConnectionPending { + + Polygon *polygon; + int edge; + }; struct Polygon { @@ -49,7 +55,8 @@ class Navigation2D : public Node2D { Point point; Polygon *C; //connection int C_edge; - Edge() { C=NULL; C_edge=-1; } + List<ConnectionPending>::Element *P; + Edge() { C=NULL; C_edge=-1; P=NULL; } }; Vector<Edge> edges; @@ -72,6 +79,9 @@ class Navigation2D : public Node2D { int A_edge; Polygon *B; int B_edge; + + List<ConnectionPending> pending; + Connection() { A=NULL; B=NULL; A_edge=-1; B_edge=-1;} }; diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 3d2917d843..c30921eb69 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -85,6 +85,14 @@ void PhysicsBody2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_layer_mask"),&PhysicsBody2D::get_layer_mask); ObjectTypeDB::bind_method(_MD("set_collision_mask","mask"),&PhysicsBody2D::set_collision_mask); ObjectTypeDB::bind_method(_MD("get_collision_mask"),&PhysicsBody2D::get_collision_mask); + + + ObjectTypeDB::bind_method(_MD("set_collision_mask_bit","bit","value"),&PhysicsBody2D::set_collision_mask_bit); + ObjectTypeDB::bind_method(_MD("get_collision_mask_bit","bit"),&PhysicsBody2D::get_collision_mask_bit); + + ObjectTypeDB::bind_method(_MD("set_layer_mask_bit","bit","value"),&PhysicsBody2D::set_layer_mask_bit); + ObjectTypeDB::bind_method(_MD("get_layer_mask_bit","bit"),&PhysicsBody2D::get_layer_mask_bit); + ObjectTypeDB::bind_method(_MD("_set_layers","mask"),&PhysicsBody2D::_set_layers); ObjectTypeDB::bind_method(_MD("_get_layers"),&PhysicsBody2D::_get_layers); ObjectTypeDB::bind_method(_MD("set_one_way_collision_direction","dir"),&PhysicsBody2D::set_one_way_collision_direction); @@ -122,6 +130,37 @@ uint32_t PhysicsBody2D::get_collision_mask() const { return collision_mask; } +void PhysicsBody2D::set_collision_mask_bit(int p_bit, bool p_value) { + + uint32_t mask = get_collision_mask(); + if (p_value) + mask|=1<<p_bit; + else + mask&=~(1<<p_bit); + set_collision_mask(mask); + +} +bool PhysicsBody2D::get_collision_mask_bit(int p_bit) const{ + + return get_collision_mask()&(1<<p_bit); +} + + +void PhysicsBody2D::set_layer_mask_bit(int p_bit, bool p_value) { + + uint32_t mask = get_layer_mask(); + if (p_value) + mask|=1<<p_bit; + else + mask&=~(1<<p_bit); + set_layer_mask(mask); + +} + +bool PhysicsBody2D::get_layer_mask_bit(int p_bit) const{ + + return get_layer_mask()&(1<<p_bit); +} PhysicsBody2D::PhysicsBody2D(Physics2DServer::BodyMode p_mode) : CollisionObject2D( Physics2DServer::get_singleton()->body_create(p_mode), false) { diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h index 03f95959b6..b70fdd59cf 100644 --- a/scene/2d/physics_body_2d.h +++ b/scene/2d/physics_body_2d.h @@ -61,6 +61,13 @@ public: void set_collision_mask(uint32_t p_mask); uint32_t get_collision_mask() const; + + void set_collision_mask_bit(int p_bit, bool p_value); + bool get_collision_mask_bit(int p_bit) const; + + void set_layer_mask_bit(int p_bit, bool p_value); + bool get_layer_mask_bit(int p_bit) const; + void add_collision_exception_with(Node* p_node); //must be physicsbody void remove_collision_exception_with(Node* p_node); diff --git a/scene/2d/sprite.cpp b/scene/2d/sprite.cpp index 0c0a0d7822..067b4794b4 100644 --- a/scene/2d/sprite.cpp +++ b/scene/2d/sprite.cpp @@ -320,7 +320,7 @@ void Sprite::_bind_methods() { ADD_PROPERTY( PropertyInfo( Variant::BOOL, "flip_v"), _SCS("set_flip_v"),_SCS("is_flipped_v")); ADD_PROPERTY( PropertyInfo( Variant::INT, "vframes"), _SCS("set_vframes"),_SCS("get_vframes")); ADD_PROPERTY( PropertyInfo( Variant::INT, "hframes"), _SCS("set_hframes"),_SCS("get_hframes")); - ADD_PROPERTY( PropertyInfo( Variant::INT, "frame"), _SCS("set_frame"),_SCS("get_frame")); + ADD_PROPERTY( PropertyInfo( Variant::INT, "frame",PROPERTY_HINT_SPRITE_FRAME), _SCS("set_frame"),_SCS("get_frame")); ADD_PROPERTY( PropertyInfo( Variant::COLOR, "modulate"), _SCS("set_modulate"),_SCS("get_modulate")); ADD_PROPERTY( PropertyInfo( Variant::BOOL, "region"), _SCS("set_region"),_SCS("is_region")); ADD_PROPERTY( PropertyInfo( Variant::RECT2, "region_rect"), _SCS("set_region_rect"),_SCS("get_region_rect")); diff --git a/scene/3d/area.cpp b/scene/3d/area.cpp index d49ffff729..76527c72e6 100644 --- a/scene/3d/area.cpp +++ b/scene/3d/area.cpp @@ -52,6 +52,17 @@ bool Area::is_gravity_a_point() const{ return gravity_is_point; } +void Area::set_gravity_distance_scale(real_t p_scale){ + + gravity_distance_scale=p_scale; + PhysicsServer::get_singleton()->area_set_param(get_rid(),PhysicsServer::AREA_PARAM_GRAVITY_DISTANCE_SCALE,p_scale); + +} + +real_t Area::get_gravity_distance_scale() const{ + return gravity_distance_scale; +} + void Area::set_gravity_vector(const Vector3& p_vec){ gravity_vec=p_vec; @@ -302,6 +313,9 @@ void Area::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_gravity_is_point","enable"),&Area::set_gravity_is_point); ObjectTypeDB::bind_method(_MD("is_gravity_a_point"),&Area::is_gravity_a_point); + ObjectTypeDB::bind_method(_MD("set_gravity_distance_scale","distance_scale"),&Area::set_gravity_distance_scale); + ObjectTypeDB::bind_method(_MD("get_gravity_distance_scale"),&Area::get_gravity_distance_scale); + ObjectTypeDB::bind_method(_MD("set_gravity_vector","vector"),&Area::set_gravity_vector); ObjectTypeDB::bind_method(_MD("get_gravity_vector"),&Area::get_gravity_vector); @@ -330,6 +344,7 @@ void Area::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::INT,"space_override",PROPERTY_HINT_ENUM,"Disabled,Combine,Replace"),_SCS("set_space_override_mode"),_SCS("get_space_override_mode")); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"gravity_point"),_SCS("set_gravity_is_point"),_SCS("is_gravity_a_point")); + ADD_PROPERTY( PropertyInfo(Variant::REAL,"gravity_distance_scale", PROPERTY_HINT_RANGE,"0,1024,0.001"),_SCS("set_gravity_distance_scale"),_SCS("get_gravity_distance_scale")); ADD_PROPERTY( PropertyInfo(Variant::VECTOR3,"gravity_vec"),_SCS("set_gravity_vector"),_SCS("get_gravity_vector")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"gravity",PROPERTY_HINT_RANGE,"-1024,1024,0.01"),_SCS("set_gravity"),_SCS("get_gravity")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"density",PROPERTY_HINT_RANGE,"0,1024,0.001"),_SCS("set_density"),_SCS("get_density")); @@ -345,6 +360,7 @@ Area::Area() : CollisionObject(PhysicsServer::get_singleton()->area_create(),tru locked=false; set_gravity_vector(Vector3(0,-1,0)); gravity_is_point=false; + gravity_distance_scale=0; density=0.1; priority=0; monitoring=false; diff --git a/scene/3d/area.h b/scene/3d/area.h index 493c71c595..fb853092f3 100644 --- a/scene/3d/area.h +++ b/scene/3d/area.h @@ -49,6 +49,7 @@ private: Vector3 gravity_vec; real_t gravity; bool gravity_is_point; + real_t gravity_distance_scale; real_t density; int priority; bool monitoring; @@ -98,6 +99,9 @@ public: void set_gravity_is_point(bool p_enabled); bool is_gravity_a_point() const; + void set_gravity_distance_scale(real_t p_scale); + real_t get_gravity_distance_scale() const; + void set_gravity_vector(const Vector3& p_vec); Vector3 get_gravity_vector() const; diff --git a/scene/3d/navigation.cpp b/scene/3d/navigation.cpp index 48820706dd..bfa8add09c 100644 --- a/scene/3d/navigation.cpp +++ b/scene/3d/navigation.cpp @@ -85,9 +85,14 @@ void Navigation::_navmesh_link(int p_id) { } else { if (C->get().B!=NULL) { - print_line(String()+_get_vertex(ek.a)+" -> "+_get_vertex(ek.b)); + ConnectionPending pending; + pending.polygon=&p; + pending.edge=j; + p.edges[j].P=C->get().pending.push_back(pending); + continue; + //print_line(String()+_get_vertex(ek.a)+" -> "+_get_vertex(ek.b)); } - ERR_CONTINUE(C->get().B!=NULL); //wut + //ERR_CONTINUE(C->get().B!=NULL); //wut C->get().B=&p; C->get().B_edge=j; @@ -126,8 +131,13 @@ void Navigation::_navmesh_unlink(int p_id) { EdgeKey ek(edges[i].point,edges[next].point); Map<EdgeKey,Connection>::Element *C=connections.find(ek); + ERR_CONTINUE(!C); - if (C->get().B) { + + if (edges[i].P) { + C->get().pending.erase(edges[i].P); + edges[i].P=NULL; + } else if (C->get().B) { //disconnect C->get().B->edges[C->get().B_edge].C=NULL; @@ -143,6 +153,20 @@ void Navigation::_navmesh_unlink(int p_id) { C->get().B=NULL; C->get().B_edge=-1; + if (C->get().pending.size()) { + //reconnect if something is pending + ConnectionPending cp = C->get().pending.front()->get(); + C->get().pending.pop_front(); + + C->get().B=cp.polygon; + C->get().B_edge=cp.edge; + C->get().A->edges[C->get().A_edge].C=cp.polygon; + C->get().A->edges[C->get().A_edge].C_edge=cp.edge; + cp.polygon->edges[cp.edge].C=C->get().A; + cp.polygon->edges[cp.edge].C_edge=C->get().A_edge; + cp.polygon->edges[cp.edge].P=NULL; + } + } else { connections.erase(C); //erase diff --git a/scene/3d/navigation.h b/scene/3d/navigation.h index 0f7f67571f..f8434aaf72 100644 --- a/scene/3d/navigation.h +++ b/scene/3d/navigation.h @@ -42,6 +42,13 @@ class Navigation : public Spatial { struct NavMesh; + struct Polygon; + + struct ConnectionPending { + + Polygon *polygon; + int edge; + }; struct Polygon { @@ -50,7 +57,8 @@ class Navigation : public Spatial { Point point; Polygon *C; //connection int C_edge; - Edge() { C=NULL; C_edge=-1; } + List<ConnectionPending>::Element *P; + Edge() { C=NULL; C_edge=-1; P=NULL; } }; Vector<Edge> edges; @@ -72,6 +80,9 @@ class Navigation : public Spatial { int A_edge; Polygon *B; int B_edge; + + List<ConnectionPending> pending; + Connection() { A=NULL; B=NULL; A_edge=-1; B_edge=-1;} }; diff --git a/scene/3d/spatial.cpp b/scene/3d/spatial.cpp index 9c69520a85..c672d0e94f 100644 --- a/scene/3d/spatial.cpp +++ b/scene/3d/spatial.cpp @@ -626,10 +626,11 @@ void Spatial::rotate_z(float p_radians){ void Spatial::translate(const Vector3& p_offset){ Transform t =get_transform(); - t.origin+=p_offset; + t.translate(p_offset); set_transform(t); } + void Spatial::scale(const Vector3& p_ratio){ Transform t =get_transform(); diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp index 4952f742df..e9da95f3fb 100644 --- a/scene/3d/sprite_3d.cpp +++ b/scene/3d/sprite_3d.cpp @@ -580,7 +580,7 @@ void Sprite3D::_bind_methods() { ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE,"Texture"), _SCS("set_texture"),_SCS("get_texture")); ADD_PROPERTY( PropertyInfo( Variant::INT, "vframes"), _SCS("set_vframes"),_SCS("get_vframes")); ADD_PROPERTY( PropertyInfo( Variant::INT, "hframes"), _SCS("set_hframes"),_SCS("get_hframes")); - ADD_PROPERTY( PropertyInfo( Variant::INT, "frame"), _SCS("set_frame"),_SCS("get_frame")); + ADD_PROPERTY( PropertyInfo( Variant::INT, "frame",PROPERTY_HINT_SPRITE_FRAME), _SCS("set_frame"),_SCS("get_frame")); ADD_PROPERTY( PropertyInfo( Variant::BOOL, "region"), _SCS("set_region"),_SCS("is_region")); ADD_PROPERTY( PropertyInfo( Variant::RECT2, "region_rect"), _SCS("set_region_rect"),_SCS("get_region_rect")); @@ -727,7 +727,7 @@ void AnimatedSprite3D::_bind_methods(){ ObjectTypeDB::bind_method(_MD("get_frame"),&AnimatedSprite3D::get_frame); ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "frames", PROPERTY_HINT_RESOURCE_TYPE,"SpriteFrames"), _SCS("set_sprite_frames"),_SCS("get_sprite_frames")); - ADD_PROPERTY( PropertyInfo( Variant::INT, "frame"), _SCS("set_frame"),_SCS("get_frame")); + ADD_PROPERTY( PropertyInfo( Variant::INT, "frame",PROPERTY_HINT_SPRITE_FRAME), _SCS("set_frame"),_SCS("get_frame")); ADD_SIGNAL(MethodInfo("frame_changed")); diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index 4949b33c47..74ae2c0d55 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -223,7 +223,7 @@ void AnimationPlayer::_notification(int p_what) { } break; case NOTIFICATION_EXIT_TREE: { - stop_all(); + //stop_all(); clear_caches(); } break; } @@ -967,14 +967,16 @@ String AnimationPlayer::get_current_animation() const { } -void AnimationPlayer::stop() { +void AnimationPlayer::stop(bool p_reset) { Playback &c=playback; c.blend.clear(); - c.current.from=NULL; + if (p_reset) { + c.current.from=NULL; + } _set_process(false); queued.clear(); - playing = false; + playing = false; } void AnimationPlayer::stop_all() { @@ -1211,7 +1213,7 @@ void AnimationPlayer::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_default_blend_time"),&AnimationPlayer::get_default_blend_time); ObjectTypeDB::bind_method(_MD("play","name","custom_blend","custom_speed","from_end"),&AnimationPlayer::play,DEFVAL(""),DEFVAL(-1),DEFVAL(1.0),DEFVAL(false)); - ObjectTypeDB::bind_method(_MD("stop"),&AnimationPlayer::stop); + ObjectTypeDB::bind_method(_MD("stop","reset"),&AnimationPlayer::stop,DEFVAL(true)); ObjectTypeDB::bind_method(_MD("stop_all"),&AnimationPlayer::stop_all); ObjectTypeDB::bind_method(_MD("is_playing"),&AnimationPlayer::is_playing); ObjectTypeDB::bind_method(_MD("set_current_animation","anim"),&AnimationPlayer::set_current_animation); diff --git a/scene/animation/animation_player.h b/scene/animation/animation_player.h index 8d7d6d04e0..3fddc283ae 100644 --- a/scene/animation/animation_player.h +++ b/scene/animation/animation_player.h @@ -260,7 +260,7 @@ public: void play(const StringName& p_name=StringName(),float p_custom_blend=-1,float p_custom_scale=1.0,bool p_from_end=false); void queue(const StringName& p_name); void clear_queue(); - void stop(); + void stop(bool p_reset=true); bool is_playing() const; String get_current_animation() const; void set_current_animation(const String& p_anim); diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp new file mode 100644 index 0000000000..2fd4d810de --- /dev/null +++ b/scene/gui/item_list.cpp @@ -0,0 +1,1048 @@ +#include "item_list.h" +#include "os/os.h" +#include "globals.h" + + +void ItemList::add_item(const String& p_item,const Ref<Texture>& p_texture,bool p_selectable) { + + Item item; + item.icon=p_texture; + item.text=p_item; + item.selectable=p_selectable; + item.selected=false; + item.disabled=false; + items.push_back(item); + + update(); + shape_changed=true; + +} + +void ItemList::add_icon_item(const Ref<Texture>& p_item,bool p_selectable){ + + Item item; + item.icon=p_item; + //item.text=p_item; + item.selectable=p_selectable; + item.selected=false; + item.disabled=false; + items.push_back(item); + + update(); + shape_changed=true; + +} + +void ItemList::set_item_text(int p_idx,const String& p_text){ + + ERR_FAIL_INDEX(p_idx,items.size()); + + items[p_idx].text=p_text; + update(); + shape_changed=true; + +} + +String ItemList::get_item_text(int p_idx) const{ + + ERR_FAIL_INDEX_V(p_idx,items.size(),String()); + return items[p_idx].text; + +} + +void ItemList::set_item_tooltip(int p_idx,const String& p_tooltip){ + + ERR_FAIL_INDEX(p_idx,items.size()); + + items[p_idx].tooltip=p_tooltip; + update(); + shape_changed=true; + +} + +String ItemList::get_item_tooltip(int p_idx) const{ + + ERR_FAIL_INDEX_V(p_idx,items.size(),String()); + return items[p_idx].tooltip; + +} + +void ItemList::set_item_icon(int p_idx,const Ref<Texture>& p_icon){ + + ERR_FAIL_INDEX(p_idx,items.size()); + + items[p_idx].icon=p_icon; + update(); + shape_changed=true; + + +} +Ref<Texture> ItemList::get_item_icon(int p_idx) const{ + + ERR_FAIL_INDEX_V(p_idx,items.size(),Ref<Texture>()); + + return items[p_idx].icon; + +} + + +void ItemList::set_item_tag_icon(int p_idx,const Ref<Texture>& p_tag_icon){ + + ERR_FAIL_INDEX(p_idx,items.size()); + + items[p_idx].tag_icon=p_tag_icon; + update(); + shape_changed=true; + + +} +Ref<Texture> ItemList::get_item_tag_icon(int p_idx) const{ + + ERR_FAIL_INDEX_V(p_idx,items.size(),Ref<Texture>()); + + return items[p_idx].tag_icon; + +} + +void ItemList::set_item_selectable(int p_idx,bool p_selectable){ + + ERR_FAIL_INDEX(p_idx,items.size()); + + items[p_idx].selectable=p_selectable; + + +} + + +bool ItemList::is_item_selectable(int p_idx) const{ + + ERR_FAIL_INDEX_V(p_idx,items.size(),false); + return items[p_idx].selectable; +} + +void ItemList::set_item_disabled(int p_idx,bool p_disabled){ + + ERR_FAIL_INDEX(p_idx,items.size()); + + items[p_idx].disabled=p_disabled; + + +} + + +bool ItemList::is_item_disabled(int p_idx) const{ + + ERR_FAIL_INDEX_V(p_idx,items.size(),false); + return items[p_idx].disabled; +} + + +void ItemList::set_item_metadata(int p_idx,const Variant& p_metadata){ + + ERR_FAIL_INDEX(p_idx,items.size()); + + items[p_idx].metadata=p_metadata; + update(); + shape_changed=true; + +} + +Variant ItemList::get_item_metadata(int p_idx) const{ + + ERR_FAIL_INDEX_V(p_idx,items.size(),Variant()); + return items[p_idx].metadata; + +} +void ItemList::select(int p_idx,bool p_single){ + + ERR_FAIL_INDEX(p_idx,items.size()); + + if (p_single || select_mode==SELECT_SINGLE) { + + if (!items[p_idx].selectable) { + return; + } + + for(int i=0;i<items.size();i++) { + items[i].selected=p_idx==i; + } + + current=p_idx; + } else { + + if (items[p_idx].selectable) { + items[p_idx].selected=true; + } + } + update(); + +} +void ItemList::unselect(int p_idx){ + + ERR_FAIL_INDEX(p_idx,items.size()); + + if (select_mode!=SELECT_MULTI) { + items[p_idx].selected=false; + current=-1; + } else { + items[p_idx].selected=false; + } + update(); + +} +bool ItemList::is_selected(int p_idx) const{ + + ERR_FAIL_INDEX_V(p_idx,items.size(),false); + + return items[p_idx].selected; + +} + +void ItemList::set_current(int p_current) { + ERR_FAIL_INDEX(p_current,items.size()); + + if (select_mode==SELECT_SINGLE) + select(p_current,true); + else { + current=p_current; + update(); + } +} + +int ItemList::get_current() const { + + return current; +} + + +int ItemList::get_item_count() const{ + + return items.size(); +} +void ItemList::remove_item(int p_idx){ + + ERR_FAIL_INDEX(p_idx,items.size()); + + items.remove(p_idx); + update(); + shape_changed=true; + +} + +void ItemList::clear(){ + + items.clear(); + current=-1; + update(); + +} + +void ItemList::set_fixed_column_width(int p_size){ + + ERR_FAIL_COND(p_size<0); + fixed_column_width=p_size; + update(); + shape_changed=true; + +} +int ItemList::get_fixed_column_width() const{ + + return fixed_column_width; +} + +void ItemList::set_max_text_lines(int p_lines){ + + ERR_FAIL_COND(p_lines<1); + max_text_lines=p_lines; + update(); + shape_changed=true; + +} +int ItemList::get_max_text_lines() const{ + + return max_text_lines; +} + +void ItemList::set_max_columns(int p_amount){ + + ERR_FAIL_COND(p_amount<0); + max_columns=p_amount; + update(); +} +int ItemList::get_max_columns() const{ + + return max_columns; +} + +void ItemList::set_select_mode(SelectMode p_mode) { + + select_mode=p_mode; + update(); +} + +ItemList::SelectMode ItemList::get_select_mode() const { + + return select_mode; +} + +void ItemList::set_icon_mode(IconMode p_mode){ + + icon_mode=p_mode; + update(); + shape_changed=true; + +} +ItemList::IconMode ItemList::get_icon_mode() const{ + + return icon_mode; +} + +void ItemList::set_min_icon_size(const Size2& p_size) { + + min_icon_size=p_size; + update(); +} + +Size2 ItemList::get_min_icon_size() const { + + return min_icon_size; +} + + + +void ItemList::_input_event(const InputEvent& p_event) { + if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==BUTTON_LEFT && p_event.mouse_button.pressed) { + + const InputEventMouseButton &mb = p_event.mouse_button; + + search_string=""; //any mousepress cancels + Vector2 pos(mb.x,mb.y); + Ref<StyleBox> bg = get_stylebox("bg"); + pos-=bg->get_offset(); + pos.y+=scroll_bar->get_val(); + + int closest = -1; + int closest_dist=0x7FFFFFFF; + + for(int i=0;i<items.size();i++) { + + Rect2 rc = items[i].rect_cache; + if (i%current_columns==current_columns-1) { + rc.size.width=get_size().width; //not right but works + } + + if (rc.has_point(pos)) { + closest=i; + break; + } + + float dist = rc.distance_to(pos); + if (dist<closest_dist) { + closest=i; + closest_dist=dist; + } + } + + if (closest!=-1) { + + int i = closest; + + if (select_mode==SELECT_MULTI && items[i].selected && mb.mod.command) { + unselect(i); + emit_signal("multi_selected",i,false); + } else if (select_mode==SELECT_MULTI && mb.mod.shift && current>=0 && current<items.size() && current!=i) { + + int from = current; + int to = i; + if (i<current) { + SWAP(from,to); + } + for(int j=from;j<=to;j++) { + bool selected = !items[j].selected; + select(j,false); + if (selected) + emit_signal("multi_selected",i,true); + } + } else { + bool selected = !items[i].selected; + select(i,select_mode==SELECT_SINGLE || !mb.mod.command); + if (selected) { + if (select_mode==SELECT_SINGLE) { + emit_signal("item_selected",i); + } else + emit_signal("multi_selected",i,true); + } + + if (/*select_mode==SELECT_SINGLE &&*/ mb.doubleclick) { + + emit_signal("item_activated",i); + + } + + + } + + + return; + } + } + if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==BUTTON_WHEEL_UP && p_event.mouse_button.pressed) { + + scroll_bar->set_val( scroll_bar->get_val()-scroll_bar->get_page()/8 ); + + } + if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==BUTTON_WHEEL_DOWN && p_event.mouse_button.pressed) { + + scroll_bar->set_val( scroll_bar->get_val()+scroll_bar->get_page()/8 ); + + } + + if (p_event.is_pressed() && items.size()>0) { + if (p_event.is_action("ui_up")) { + + if (search_string!="") { + + uint64_t now = OS::get_singleton()->get_ticks_msec(); + uint64_t diff = now-search_time_msec; + + if (diff<int(Globals::get_singleton()->get("gui/incr_search_max_interval_msec"))*2) { + + for(int i=current-1;i>=0;i--) { + + if (items[i].text.begins_with(search_string)) { + + set_current(i); + ensure_current_is_visible(); + if (select_mode==SELECT_SINGLE) { + emit_signal("item_selected",current); + } + + + break; + } + } + accept_event(); + return; + } + } + + if (current>=current_columns) { + set_current(current-current_columns); + ensure_current_is_visible(); + if (select_mode==SELECT_SINGLE) { + emit_signal("item_selected",current); + } + accept_event(); + } + } else if (p_event.is_action("ui_down")) { + + if (search_string!="") { + + uint64_t now = OS::get_singleton()->get_ticks_msec(); + uint64_t diff = now-search_time_msec; + + if (diff<int(Globals::get_singleton()->get("gui/incr_search_max_interval_msec"))*2) { + + for(int i=current+1;i<items.size();i++) { + + if (items[i].text.begins_with(search_string)) { + + set_current(i); + ensure_current_is_visible(); + if (select_mode==SELECT_SINGLE) { + emit_signal("item_selected",current); + } + break; + } + } + accept_event(); + return; + } + } + + if (current<items.size()-current_columns) { + set_current(current+current_columns); + ensure_current_is_visible(); + if (select_mode==SELECT_SINGLE) { + emit_signal("item_selected",current); + } + accept_event(); + + } + } else if (p_event.is_action("ui_page_up")) { + + search_string=""; //any mousepress cancels + + for(int i=4;i>0;i--) { + if (current-current_columns*i >=0 ) { + set_current( current- current_columns*i); + ensure_current_is_visible(); + if (select_mode==SELECT_SINGLE) { + emit_signal("item_selected",current); + } + accept_event(); + break; + } + } + } else if (p_event.is_action("ui_page_down")) { + + search_string=""; //any mousepress cancels + + for(int i=4;i>0;i--) { + if (current+current_columns*i < items.size() ) { + set_current( current+ current_columns*i); + ensure_current_is_visible(); + if (select_mode==SELECT_SINGLE) { + emit_signal("item_selected",current); + } + accept_event(); + + break; + } + } + } else if (p_event.is_action("ui_left")) { + + search_string=""; //any mousepress cancels + + if (current%current_columns!=0) { + set_current(current-1); + ensure_current_is_visible(); + if (select_mode==SELECT_SINGLE) { + emit_signal("item_selected",current); + } + accept_event(); + + } + } else if (p_event.is_action("ui_right")) { + + search_string=""; //any mousepress cancels + + if (current%current_columns!=(current_columns-1)) { + set_current(current+1); + ensure_current_is_visible(); + if (select_mode==SELECT_SINGLE) { + emit_signal("item_selected",current); + } + accept_event(); + + } + } else if (p_event.is_action("ui_cancel")) { + search_string=""; + } else if (p_event.is_action("ui_select")) { + + + if (select_mode==SELECT_MULTI && current>=0 && current<items.size()) { + if (items[current].selectable && !items[current].selected) { + select(current,false); + emit_signal("multi_selected",current,true); + } else if (items[current].selected) { + unselect(current); + emit_signal("multi_selected",current,false); + } + } + } else if (p_event.is_action("ui_accept")) { + search_string=""; //any mousepress cance + + if (current>=0 && current<items.size()) { + emit_signal("item_activated",current); + } + } else if (p_event.type==InputEvent::KEY) { + + if (p_event.key.unicode) { + + uint64_t now = OS::get_singleton()->get_ticks_msec(); + uint64_t diff = now-search_time_msec; + uint64_t max_interval = uint64_t(GLOBAL_DEF("gui/incr_search_max_interval_msec",2000)); + search_time_msec = now; + + if (diff>max_interval) { + search_string=""; + } + + search_string+=String::chr(p_event.key.unicode); + for(int i=0;i<items.size();i++) { + if (items[i].text.begins_with(search_string)) { + set_current(i); + ensure_current_is_visible(); + if (select_mode==SELECT_SINGLE) { + emit_signal("item_selected",current); + } + break; + } + } + + } + + } + } + + + + +} + +void ItemList::ensure_current_is_visible() { + + if (current>=0 && current <=items.size()) { + + Rect2 r = items[current].rect_cache; + int from = scroll_bar->get_val(); + int to = from + scroll_bar->get_page(); + + if (r.pos.y < from) { + scroll_bar->set_val(r.pos.y); + } else if (r.pos.y+r.size.y > to) { + scroll_bar->set_val(r.pos.y+r.size.y - (to-from)); + } + } +} + +void ItemList::_notification(int p_what) { + + if (p_what==NOTIFICATION_RESIZED) { + shape_changed=true; + update(); + } + + if (p_what==NOTIFICATION_DRAW) { + + VS::get_singleton()->canvas_item_set_clip(get_canvas_item(),true); + Ref<StyleBox> bg = get_stylebox("bg"); + + int mw = scroll_bar->get_minimum_size().x; + scroll_bar->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_END,mw+bg->get_margin(MARGIN_RIGHT)); + scroll_bar->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,bg->get_margin(MARGIN_RIGHT)); + scroll_bar->set_anchor_and_margin(MARGIN_TOP,ANCHOR_BEGIN,bg->get_margin(MARGIN_TOP)); + scroll_bar->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,bg->get_margin(MARGIN_BOTTOM)); + + + Size2 size = get_size(); + + float page = size.height-bg->get_minimum_size().height; + int width = size.width - mw - bg->get_minimum_size().width; + scroll_bar->set_page(page); + + draw_style_box(bg,Rect2(Point2(),size)); + + int hseparation = get_constant("hseparation"); + int vseparation = get_constant("vseparation"); + int icon_margin = get_constant("icon_margin"); + int line_separation = get_constant("line_separation"); + + Ref<StyleBox> sbsel = has_focus()?get_stylebox("selected_focus"):get_stylebox("selected"); + Ref<StyleBox> cursor = has_focus()?get_stylebox("cursor"):get_stylebox("cursor_unfocused"); + + Ref<Font> font = get_font("font"); + Color guide_color = get_color("guide_color"); + Color font_color = get_color("font_color"); + int font_height = font->get_height(); + Vector<int> line_size_cache; + Vector<int> line_limit_cache; + + if (max_text_lines) { + line_size_cache.resize(max_text_lines); + line_limit_cache.resize(max_text_lines); + } + + if (has_focus()) { + VisualServer::get_singleton()->canvas_item_add_clip_ignore(get_canvas_item(),true); + draw_style_box(get_stylebox("bg_focus"),Rect2(Point2(),size)); + VisualServer::get_singleton()->canvas_item_add_clip_ignore(get_canvas_item(),false); + } + + if (shape_changed) { + + //1- compute item minimum sizes + for(int i=0;i<items.size();i++) { + + Size2 minsize; + if (items[i].icon.is_valid()) { + minsize=items[i].icon->get_size(); + if (min_icon_size.x!=0) + minsize.x = MAX(minsize.x,min_icon_size.x); + if (min_icon_size.y!=0) + minsize.y = MAX(minsize.y,min_icon_size.y); + + if (items[i].text!="") { + if (icon_mode==ICON_MODE_TOP) { + minsize.y+=icon_margin; + } else { + minsize.x+=icon_margin; + } + } + } + + if (items[i].text!="") { + + Size2 s = font->get_string_size(items[i].text); + //s.width=MIN(s.width,fixed_column_width); + + + + if (icon_mode==ICON_MODE_TOP) { + minsize.x=MAX(minsize.x,s.width); + if (max_text_lines>0) { + minsize.y+=(font_height+line_separation)*max_text_lines; + } else { + minsize.y+=s.height; + } + + } else { + minsize.y=MAX(minsize.y,s.height); + minsize.x+=s.width; + } + } + + + + items[i].rect_cache.size=minsize; + if (fixed_column_width>0) + items[i].rect_cache.size.x=fixed_column_width; + + } + + int fit_size = size.x - bg->get_minimum_size().width - mw; + + //2-attempt best fit + current_columns = 0x7FFFFFFF; + if (max_columns>0) + current_columns=max_columns; + + + while(true) { + //repeat util all fits + //print_line("try with "+itos(current_columns)); + bool all_fit=true; + Vector2 ofs; + int col=0; + int max_h=0; + separators.clear();; + for(int i=0;i<items.size();i++) { + + if (current_columns>1 && items[i].rect_cache.size.width+ofs.x > fit_size) { + //went past + current_columns=MAX(col,1); + all_fit=false; + break; + } + + items[i].rect_cache.pos=ofs; + max_h=MAX(max_h,items[i].rect_cache.size.y); + ofs.x+=items[i].rect_cache.size.x; + //print_line("item "+itos(i)+" ofs "+rtos(items[i].rect_cache.size.x)); + if (col>0) + ofs.x+=hseparation; + col++; + if (col==current_columns) { + + if (i<items.size()-1) + separators.push_back(ofs.y+max_h+vseparation/2); + ofs.x=0; + ofs.y+=max_h+vseparation; + col=0; + max_h=0; + } + } + + if (all_fit) { + float max = MAX(page,ofs.y+max_h); + scroll_bar->set_max(max); + //print_line("max: "+rtos(max)+" page "+rtos(page)); + if (max<=page) { + scroll_bar->set_val(0); + scroll_bar->hide(); + } else { + scroll_bar->show(); + } + break; + } + } + + + shape_changed=false; + } + + + + Vector2 base_ofs = bg->get_offset(); + base_ofs.y-=int(scroll_bar->get_val()); + + Rect2 clip(Point2(),size-bg->get_minimum_size()+Vector2(0,scroll_bar->get_val())); + + for(int i=0;i<items.size();i++) { + + + Rect2 rcache = items[i].rect_cache; + + if (!clip.intersects(rcache)) + continue; + + + if (current_columns==1) { + rcache.size.width = width-rcache.pos.x; + } + if (items[i].selected) { + Rect2 r=rcache; + r.pos+=base_ofs; + + r.pos.x-=sbsel->get_margin(MARGIN_LEFT); + r.size.x+=sbsel->get_margin(MARGIN_LEFT)+sbsel->get_margin(MARGIN_RIGHT); + r.pos.y-=sbsel->get_margin(MARGIN_TOP); + r.size.y+=sbsel->get_margin(MARGIN_TOP)+sbsel->get_margin(MARGIN_BOTTOM); + + draw_style_box(sbsel,r); + + } + + + Vector2 text_ofs; + if (items[i].icon.is_valid()) { + + Vector2 icon_ofs; + if (min_icon_size!=Vector2()) { + icon_ofs = (min_icon_size - items[i].icon->get_size())/2; + } + + if (icon_mode==ICON_MODE_TOP) { + draw_texture(items[i].icon,icon_ofs+items[i].rect_cache.pos+Vector2(items[i].rect_cache.size.width/2-items[i].icon->get_width()/2,0).floor()+base_ofs); + text_ofs.y = MAX(items[i].icon->get_height(),min_icon_size.y)+icon_margin; + } else { + draw_texture(items[i].icon,icon_ofs+items[i].rect_cache.pos+Vector2(0,items[i].rect_cache.size.height/2-items[i].icon->get_height()/2).floor()+base_ofs); + text_ofs.x = MAX(items[i].icon->get_width(),min_icon_size.x)+icon_margin; + } + } + + if (items[i].tag_icon.is_valid()) { + + draw_texture(items[i].tag_icon,items[i].rect_cache.pos+base_ofs); + } + + if (items[i].text!="") { + + int max_len=-1; + + Vector2 size = font->get_string_size(items[i].text); + if (fixed_column_width) + max_len=fixed_column_width; + else + max_len=size.x; + + if (icon_mode==ICON_MODE_TOP && max_text_lines>0) { + + int ss = items[i].text.length(); + float ofs=0; + int line=0; + for(int j=0;j<=ss;j++) { + + int cs = j<ss?font->get_char_size(items[i].text[j],items[i].text[j+1]).x:0; + if (ofs+cs>max_len || j==ss) { + line_limit_cache[line]=j; + line_size_cache[line]=ofs; + line++; + ofs=0; + if (line>=max_text_lines) + break; + } else { + ofs+=cs; + } + + } + + line=0; + ofs=0; + + text_ofs.y+=font->get_ascent(); + text_ofs=text_ofs.floor(); + text_ofs+=base_ofs; + text_ofs+=items[i].rect_cache.pos; + + for(int j=0;j<ss;j++) { + + if (j==line_limit_cache[line]) { + line++; + ofs=0; + if (line>=max_text_lines) + break; + } + ofs+=font->draw_char(get_canvas_item(),text_ofs+Vector2(ofs+(max_len-line_size_cache[line])/2,line*(font_height+line_separation)).floor(),items[i].text[j],items[i].text[j+1],font_color); + } + + //special multiline mode + } else { + + if (fixed_column_width>0) + size.x=MIN(size.x,fixed_column_width); + + if (icon_mode==ICON_MODE_TOP) { + text_ofs.x+=(items[i].rect_cache.size.width-size.x)/2; + } else { + text_ofs.y+=(items[i].rect_cache.size.height-size.y)/2; + } + + text_ofs.y+=font->get_ascent(); + text_ofs=text_ofs.floor(); + text_ofs+=base_ofs; + text_ofs+=items[i].rect_cache.pos; + + draw_string(font,text_ofs,items[i].text,font_color,max_len+1); + } + + + } + + if (select_mode==SELECT_MULTI && i==current) { + + Rect2 r=rcache; + r.pos+=base_ofs; + draw_style_box(cursor,r); + + } + } + + for(int i=0;i<separators.size();i++) { + draw_line(Vector2(bg->get_margin(MARGIN_LEFT),base_ofs.y+separators[i]),Vector2(size.width-bg->get_margin(MARGIN_LEFT),base_ofs.y+separators[i]),guide_color); + } + + } +} + +void ItemList::_scroll_changed(double) { + update(); +} + + +String ItemList::get_tooltip(const Point2& p_pos) const { + + Vector2 pos=p_pos; + Ref<StyleBox> bg = get_stylebox("bg"); + pos-=bg->get_offset(); + pos.y+=scroll_bar->get_val(); + + int closest = -1; + int closest_dist=0x7FFFFFFF; + + for(int i=0;i<items.size();i++) { + + Rect2 rc = items[i].rect_cache; + if (i%current_columns==current_columns-1) { + rc.size.width=get_size().width; //not right but works + } + + if (rc.has_point(pos)) { + closest=i; + break; + } + + float dist = rc.distance_to(pos); + if (dist<closest_dist) { + closest=i; + closest_dist=dist; + } + } + + if (closest!=-1) { + if (items[closest].tooltip!="") { + return items[closest].tooltip; + } + if (items[closest].text!="") { + return items[closest].text; + } + } + + return Control::get_tooltip(p_pos); + + +} + + +void ItemList::_bind_methods(){ + + ObjectTypeDB::bind_method(_MD("add_item","text","icon:Texture","selectable"),&ItemList::add_item,DEFVAL(Ref<Texture>()),DEFVAL(true)); + ObjectTypeDB::bind_method(_MD("add_icon_item","icon:Texture","selectable"),&ItemList::add_icon_item,DEFVAL(true)); + + ObjectTypeDB::bind_method(_MD("set_item_text","idx","text"),&ItemList::set_item_text); + ObjectTypeDB::bind_method(_MD("get_item_text","idx"),&ItemList::get_item_text); + + ObjectTypeDB::bind_method(_MD("set_item_icon","idx","icon:Texture"),&ItemList::set_item_icon); + ObjectTypeDB::bind_method(_MD("get_item_icon:Tedture","idx"),&ItemList::get_item_icon); + + ObjectTypeDB::bind_method(_MD("set_item_selectable","idx","selectable"),&ItemList::set_item_selectable); + ObjectTypeDB::bind_method(_MD("is_item_selectable","idx"),&ItemList::is_item_selectable); + + ObjectTypeDB::bind_method(_MD("set_item_disabled","idx","disabled"),&ItemList::set_item_disabled); + ObjectTypeDB::bind_method(_MD("is_item_disabled","idx"),&ItemList::is_item_disabled); + + ObjectTypeDB::bind_method(_MD("set_item_tooltip","idx","tooltip"),&ItemList::set_item_tooltip); + ObjectTypeDB::bind_method(_MD("get_item_tooltip","idx"),&ItemList::get_item_tooltip); + + ObjectTypeDB::bind_method(_MD("select","idx","single"),&ItemList::select,DEFVAL(true)); + ObjectTypeDB::bind_method(_MD("unselect","idx"),&ItemList::unselect); + ObjectTypeDB::bind_method(_MD("is_selected","idx"),&ItemList::is_selected); + + ObjectTypeDB::bind_method(_MD("get_item_count"),&ItemList::get_item_count); + ObjectTypeDB::bind_method(_MD("remove_item","idx"),&ItemList::remove_item); + + ObjectTypeDB::bind_method(_MD("clear"),&ItemList::clear); + + ObjectTypeDB::bind_method(_MD("set_fixed_column_width","width"),&ItemList::set_fixed_column_width); + ObjectTypeDB::bind_method(_MD("get_fixed_column_width"),&ItemList::get_fixed_column_width); + + ObjectTypeDB::bind_method(_MD("set_max_text_lines","lines"),&ItemList::set_max_text_lines); + ObjectTypeDB::bind_method(_MD("get_max_text_lines"),&ItemList::get_max_text_lines); + + ObjectTypeDB::bind_method(_MD("set_max_columns","amount"),&ItemList::set_max_columns); + ObjectTypeDB::bind_method(_MD("get_max_columns"),&ItemList::get_max_columns); + + ObjectTypeDB::bind_method(_MD("set_select_mode","mode"),&ItemList::set_select_mode); + ObjectTypeDB::bind_method(_MD("get_select_mode"),&ItemList::get_select_mode); + + ObjectTypeDB::bind_method(_MD("set_icon_mode","mode"),&ItemList::set_icon_mode); + ObjectTypeDB::bind_method(_MD("get_icon_mode"),&ItemList::get_icon_mode); + + ObjectTypeDB::bind_method(_MD("set_min_icon_size","size"),&ItemList::set_min_icon_size); + ObjectTypeDB::bind_method(_MD("get_min_icon_size"),&ItemList::get_min_icon_size); + + ObjectTypeDB::bind_method(_MD("ensure_current_is_visible"),&ItemList::ensure_current_is_visible); + + ObjectTypeDB::bind_method(_MD("_scroll_changed"),&ItemList::_scroll_changed); + ObjectTypeDB::bind_method(_MD("_input_event"),&ItemList::_input_event); + + BIND_CONSTANT( ICON_MODE_TOP ); + BIND_CONSTANT( ICON_MODE_LEFT ); + BIND_CONSTANT( SELECT_SINGLE ); + BIND_CONSTANT( SELECT_MULTI ); + + ADD_SIGNAL( MethodInfo("item_selected",PropertyInfo(Variant::INT,"index"))); + ADD_SIGNAL( MethodInfo("multi_selected",PropertyInfo(Variant::INT,"index"),PropertyInfo(Variant::BOOL,"selected"))); + ADD_SIGNAL( MethodInfo("item_activated",PropertyInfo(Variant::INT,"index"))); +} + + + +ItemList::ItemList() { + + current=-1; + + select_mode=SELECT_SINGLE; + icon_mode=ICON_MODE_LEFT; + + fixed_column_width=0; + max_text_lines=1; + max_columns=1; + + scroll_bar = memnew( VScrollBar ); + add_child(scroll_bar); + + shape_changed=true; + scroll_bar->connect("value_changed",this,"_scroll_changed"); + + set_focus_mode(FOCUS_ALL); + current_columns=1; + search_time_msec=0; + +} + +ItemList::~ItemList() { + +} + diff --git a/scene/gui/item_list.h b/scene/gui/item_list.h new file mode 100644 index 0000000000..6bbb416970 --- /dev/null +++ b/scene/gui/item_list.h @@ -0,0 +1,132 @@ +#ifndef ITEMLIST_H +#define ITEMLIST_H + +#include "scene/gui/control.h" +#include "scene/gui/scroll_bar.h" + +class ItemList : public Control { + + OBJ_TYPE( ItemList, Control ); +public: + + enum IconMode { + ICON_MODE_TOP, + ICON_MODE_LEFT + }; + + enum SelectMode { + SELECT_SINGLE, + SELECT_MULTI + }; +private: + struct Item { + + Ref<Texture> icon; + Ref<Texture> tag_icon; + String text; + bool selectable; + bool selected; + bool disabled; + Variant metadata; + String tooltip; + + Rect2 rect_cache; + }; + + int current; + + bool shape_changed; + + Vector<Item> items; + Vector<int> separators; + + SelectMode select_mode; + IconMode icon_mode; + VScrollBar *scroll_bar; + + uint64_t search_time_msec; + String search_string; + + int current_columns; + int fixed_column_width; + int max_text_lines; + int max_columns; + Size2 min_icon_size; + + void _scroll_changed(double); + void _input_event(const InputEvent& p_event); +protected: + + void _notification(int p_what); + static void _bind_methods(); +public: + + void add_item(const String& p_item,const Ref<Texture>& p_texture=Ref<Texture>(),bool p_selectable=true); + void add_icon_item(const Ref<Texture>& p_item,bool p_selectable=true); + + void set_item_text(int p_idx,const String& p_text); + String get_item_text(int p_idx) const; + + void set_item_icon(int p_idx,const Ref<Texture>& p_icon); + Ref<Texture> get_item_icon(int p_idx) const; + + void set_item_selectable(int p_idx,bool p_selectable); + bool is_item_selectable(int p_idx) const; + + void set_item_disabled(int p_idx,bool p_disabled); + bool is_item_disabled(int p_idx) const; + + void set_item_metadata(int p_idx,const Variant& p_metadata); + Variant get_item_metadata(int p_idx) const; + + void set_item_tag_icon(int p_idx,const Ref<Texture>& p_tag_icon); + Ref<Texture> get_item_tag_icon(int p_idx) const; + + void set_item_tooltip(int p_idx,const String& p_tooltip); + String get_item_tooltip(int p_idx) const; + + void select(int p_idx,bool p_single=true); + void unselect(int p_idx); + bool is_selected(int p_idx) const; + + void set_current(int p_current); + int get_current() const; + + + int get_item_count() const; + void remove_item(int p_idx); + + void clear(); + + void set_fixed_column_width(int p_size); + int get_fixed_column_width() const; + + void set_max_text_lines(int p_amount); + int get_max_text_lines() const; + + void set_max_columns(int p_amount); + int get_max_columns() const; + + void set_select_mode(SelectMode p_mode); + SelectMode get_select_mode() const; + + void set_icon_mode(IconMode p_mode); + IconMode get_icon_mode() const; + + void set_min_icon_size(const Size2& p_size); + Size2 get_min_icon_size() const; + + void ensure_current_is_visible(); + + + virtual String get_tooltip(const Point2& p_pos) const; + + ItemList(); + ~ItemList(); +}; + +VARIANT_ENUM_CAST(ItemList::SelectMode); +VARIANT_ENUM_CAST(ItemList::IconMode); + + +#endif // ITEMLIST_H diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 987a2ed800..7a607786ee 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -58,7 +58,7 @@ RichTextLabel::Item *RichTextLabel::_get_next_item(Item* p_item) { } -void RichTextLabel::_process_line(int &y, int p_width, int p_line, ProcessMode p_mode,const Ref<Font> &p_base_font,const Color &p_base_color,const Point2i& p_click_pos,Item **r_click_item,int *r_click_char,bool *r_outside) { +void RichTextLabel::_process_line(int &y, int p_width, int p_line, ProcessMode p_mode,const Ref<Font> &p_base_font,const Color &p_base_color,const Point2i& p_click_pos,Item **r_click_item,int *r_click_char,bool *r_outside,int p_char_count) { RID ci; if (r_outside) @@ -80,6 +80,7 @@ void RichTextLabel::_process_line(int &y, int p_width, int p_line, ProcessMode p int line=0; int spaces=0; + if (p_mode!=PROCESS_CACHE) { ERR_FAIL_INDEX(line,l.offset_caches.size()); @@ -89,6 +90,7 @@ void RichTextLabel::_process_line(int &y, int p_width, int p_line, ProcessMode p if (p_mode==PROCESS_CACHE) { l.offset_caches.clear(); l.height_caches.clear(); + l.char_count=0; } int wofs=margin; @@ -216,6 +218,8 @@ if (m_height > line_height) {\ underline=true; } + } else if (p_mode==PROCESS_CACHE) { + l.char_count+=text->text.length(); } rchar=0; @@ -326,18 +330,23 @@ if (m_height > line_height) {\ } } - int cw; + int cw=0; + + bool visible = visible_characters<0 || p_char_count<visible_characters; if (selected) { cw = font->get_char_size(c[i],c[i+1]).x; draw_rect(Rect2(pofs,y,cw,lh),selection_bg); - font->draw_char(ci,Point2(pofs,y+lh-(fh-ascent)),c[i],c[i+1],selection_fg); + if (visible) + font->draw_char(ci,Point2(pofs,y+lh-(fh-ascent)),c[i],c[i+1],selection_fg); } else { - cw=font->draw_char(ci,Point2(pofs,y+lh-(fh-ascent)),c[i],c[i+1],color); + if (visible) + cw=font->draw_char(ci,Point2(pofs,y+lh-(fh-ascent)),c[i],c[i+1],color); } + p_char_count++; if (c[i]=='\t') { cw=tab_size*font->get_char_size(' ').width; } @@ -371,6 +380,8 @@ if (m_height > line_height) {\ lh=0; if (p_mode!=PROCESS_CACHE) lh = line<l.height_caches.size()?l.height_caches[line]:1; + else + l.char_count+=1; //images count as chars too ItemImage *img = static_cast<ItemImage*>(it); @@ -383,9 +394,12 @@ if (m_height > line_height) {\ ENSURE_WIDTH( img->image->get_width() ); - if (p_mode==PROCESS_DRAW) { + bool visible = visible_characters<0 || p_char_count<visible_characters; + + if (p_mode==PROCESS_DRAW && visible) { img->image->draw(ci,Point2(wofs,y+lh-font->get_descent()-img->image->get_height())); } + p_char_count++; ADVANCE( img->image->get_width() ); CHECK_HEIGHT( (img->image->get_height()+font->get_descent()) ); @@ -556,11 +570,13 @@ void RichTextLabel::_notification(int p_what) { //todo, change to binary search int from_line = 0; + int total_chars = 0; while (from_line<lines.size()) { if (lines[from_line].height_accum_cache>=ofs) break; from_line++; + total_chars+=lines[from_line].char_count; } if (from_line>=lines.size()) @@ -572,7 +588,8 @@ void RichTextLabel::_notification(int p_what) { while (y<size.height && from_line<lines.size()) { - _process_line(y,size.width-scroll_w,from_line,PROCESS_DRAW,base_font,base_color); + _process_line(y,size.width-scroll_w,from_line,PROCESS_DRAW,base_font,base_color,Point2i(),NULL,NULL,NULL,total_chars); + total_chars+=lines[from_line].char_count; from_line++; } } @@ -1688,11 +1705,17 @@ void RichTextLabel::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_bbcode","text"),&RichTextLabel::set_bbcode); ObjectTypeDB::bind_method(_MD("get_bbcode"),&RichTextLabel::get_bbcode); + ObjectTypeDB::bind_method(_MD("set_visible_characters","amount"),&RichTextLabel::set_visible_characters); + ObjectTypeDB::bind_method(_MD("get_visible_characters"),&RichTextLabel::get_visible_characters); + + ObjectTypeDB::bind_method(_MD("get_total_character_count"),&RichTextLabel::get_total_character_count); + ObjectTypeDB::bind_method(_MD("set_use_bbcode","enable"),&RichTextLabel::set_use_bbcode); ObjectTypeDB::bind_method(_MD("is_using_bbcode"),&RichTextLabel::is_using_bbcode); ADD_PROPERTY(PropertyInfo(Variant::BOOL,"bbcode/enabled"),_SCS("set_use_bbcode"),_SCS("is_using_bbcode")); ADD_PROPERTY(PropertyInfo(Variant::STRING,"bbcode/bbcode",PROPERTY_HINT_MULTILINE_TEXT),_SCS("set_bbcode"),_SCS("get_bbcode")); + ADD_PROPERTY(PropertyInfo(Variant::INT,"visible_characters",PROPERTY_HINT_RANGE,"-1,128000,1"),_SCS("set_visible_characters"),_SCS("get_visible_characters")); ADD_SIGNAL( MethodInfo("meta_clicked",PropertyInfo(Variant::NIL,"meta"))); @@ -1719,6 +1742,27 @@ void RichTextLabel::_bind_methods() { } + +void RichTextLabel::set_visible_characters(int p_visible) { + + visible_characters=p_visible; + update(); +} + +int RichTextLabel::get_visible_characters() const { + + return visible_characters; +} +int RichTextLabel::get_total_character_count() const { + + int tc=0; + for(int i=0;i<lines.size();i++) + tc+=lines[i].char_count; + + return tc; +} + + RichTextLabel::RichTextLabel() { @@ -1756,6 +1800,8 @@ RichTextLabel::RichTextLabel() { selection.active=false; selection.enabled=false; + visible_characters=-1; + } RichTextLabel::~RichTextLabel() { diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index 7172e8e500..eaa8d5d60a 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -171,8 +171,9 @@ private: Vector<int> space_caches; int height_cache; int height_accum_cache; + int char_count; - Line() { from=NULL; } + Line() { from=NULL; char_count=0; } }; @@ -223,10 +224,10 @@ private: Selection selection; + int visible_characters; - - void _process_line(int &y, int p_width, int p_line, ProcessMode p_mode,const Ref<Font> &p_base_font,const Color &p_base_color,const Point2i& p_click_pos=Point2i(),Item **r_click_item=NULL,int *r_click_char=NULL,bool *r_outside=NULL); + void _process_line(int &y, int p_width, int p_line, ProcessMode p_mode,const Ref<Font> &p_base_font,const Color &p_base_color,const Point2i& p_click_pos=Point2i(),Item **r_click_item=NULL,int *r_click_char=NULL,bool *r_outside=NULL,int p_char_count=0); void _find_click(const Point2i& p_click,Item **r_click_item=NULL,int *r_click_char=NULL,bool *r_outside=NULL); @@ -246,6 +247,8 @@ private: bool use_bbcode; String bbcode; + + protected: void _notification(int p_what); @@ -304,6 +307,10 @@ public: void set_bbcode(const String& p_bbcode); String get_bbcode() const; + void set_visible_characters(int p_visible); + int get_visible_characters() const; + int get_total_character_count() const; + RichTextLabel(); ~RichTextLabel(); }; diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 0c15f99509..c497bc5363 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -3601,6 +3601,10 @@ TextEdit::TextEdit() { set_focus_mode(FOCUS_ALL); _update_caches(); cache.size=Size2(1,1); + cache.row_height=1; + cache.line_spacing=1; + cache.line_number_w=1; + tab_size=4; text.set_tab_size(tab_size); text.clear(); diff --git a/scene/io/resource_format_wav.cpp b/scene/io/resource_format_wav.cpp index b246eb66f5..7c90a4b3cd 100644 --- a/scene/io/resource_format_wav.cpp +++ b/scene/io/resource_format_wav.cpp @@ -150,10 +150,10 @@ RES ResourceFormatLoaderWAV::load(const String &p_path,const String& p_original_ frames/=format_channels; frames/=(format_bits>>3); - print_line("chunksize: "+itos(chunksize)); + /*print_line("chunksize: "+itos(chunksize)); print_line("channels: "+itos(format_channels)); print_line("bits: "+itos(format_bits)); - +*/ sample->create( (format_bits==8) ? Sample::FORMAT_PCM8 : Sample::FORMAT_PCM16, (format_channels==2)?true:false, diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index d3446ca62d..717ed93b16 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -66,6 +66,7 @@ #include "scene/gui/file_dialog.h" #include "scene/gui/dialogs.h" #include "scene/gui/tree.h" +#include "scene/gui/item_list.h" #include "scene/gui/text_edit.h" #include "scene/gui/texture_button.h" #include "scene/gui/separator.h" @@ -328,7 +329,7 @@ void register_scene_types() { ObjectTypeDB::register_type<HButtonArray>(); ObjectTypeDB::register_type<VButtonArray>(); ObjectTypeDB::register_type<TextureProgress>(); - + ObjectTypeDB::register_type<ItemList>(); #ifndef ADVANCED_GUI_DISABLED @@ -336,6 +337,7 @@ void register_scene_types() { ObjectTypeDB::register_type<LineEdit>(); ObjectTypeDB::register_type<PopupMenu>(); ObjectTypeDB::register_type<Tree>(); + ObjectTypeDB::register_type<TextEdit>(); ObjectTypeDB::register_virtual_type<TreeItem>(); diff --git a/scene/resources/audio_stream_resampled.cpp b/scene/resources/audio_stream_resampled.cpp index 506b34fbf6..6317780bd3 100644 --- a/scene/resources/audio_stream_resampled.cpp +++ b/scene/resources/audio_stream_resampled.cpp @@ -230,6 +230,51 @@ bool AudioStreamResampled::mix(int32_t *p_dest, int p_frames) { case 4: read=_resample<4>(p_dest,todo,increment); break; case 6: read=_resample<6>(p_dest,todo,increment); break; } +#if 1 + //end of stream, fadeout + int remaining = p_frames-todo; + if (remaining && todo>0) { + + //print_line("fadeout"); + for(int c=0;c<channels;c++) { + + for(int i=0;i<todo;i++) { + + int32_t samp = p_dest[i*channels+c]>>8; + uint32_t mul = (todo-i) * 256 /todo; + //print_line("mul: "+itos(i)+" "+itos(mul)); + p_dest[i*channels+c]=samp*mul; + } + + } + + } + +#else + int remaining = p_frames-todo; + if (remaining && todo>0) { + + + for(int c=0;c<channels;c++) { + + int32_t from = p_dest[(todo-1)*channels+c]>>8; + + for(int i=0;i<remaining;i++) { + + uint32_t mul = (remaining-i) * 256 /remaining; + p_dest[(todo+i)*channels+c]=from*mul; + } + + } + + } +#endif + + //zero out what remains there to avoid glitches + for(int i=todo*channels;i<int(p_frames)*channels;i++) { + + p_dest[i]=0; + } if (read>rb_todo) read=rb_todo; @@ -316,6 +361,16 @@ AudioStreamResampled::AudioStreamResampled() { rb=NULL; offset=0; read_buf=NULL; + rb_read_pos=0; + rb_write_pos=0; + + rb_bits=0; + rb_len=0; + rb_mask=0; + read_buff_len=0; + channels=0; + mix_rate=0; + } AudioStreamResampled::~AudioStreamResampled() { diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 2fddafc07b..62fa01f587 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -574,7 +574,7 @@ void make_default_theme() { // Tree Ref<StyleBoxTexture> tree_selected = make_stylebox( selection_png,4,4,4,4,8,0,8,0); - Ref<StyleBoxTexture> tree_selected_oof = make_stylebox( selection_oof_png,4,4,4,4,8,0,8,0); + Ref<StyleBoxTexture> tree_selected_oof = make_stylebox( selection_oof_png,4,4,4,4,8,0,8,0); t->set_stylebox("bg","Tree", make_stylebox( tree_bg_png,4,4,4,5) ); t->set_stylebox("bg_focus","Tree", focus ); @@ -605,12 +605,31 @@ void make_default_theme() { t->set_color("guide_color","Tree", Color(0,0,0,0.1) ); t->set_constant("hseparation","Tree",4); - t->set_constant("vseparation","Tree",2); + t->set_constant("vseparation","Tree",4); t->set_constant("guide_width","Tree",2); t->set_constant("item_margin","Tree",12); t->set_constant("button_margin","Tree",4); + // ItemList + Ref<StyleBoxTexture> item_selected = make_stylebox( selection_png,4,4,4,4,8,2,8,2); + Ref<StyleBoxTexture> item_selected_oof = make_stylebox( selection_oof_png,4,4,4,4,8,2,8,2); + + t->set_stylebox("bg","ItemList", make_stylebox( tree_bg_png,4,4,4,5) ); + t->set_stylebox("bg_focus","ItemList", focus ); + t->set_constant("hseparation","ItemList",4); + t->set_constant("vseparation","ItemList",2); + t->set_constant("icon_margin","ItemList",4); + t->set_constant("line_separation","ItemList",2); + t->set_font("font","ItemList", default_font ); + t->set_color("font_color","ItemList", control_font_color_low ); + t->set_color("font_color_selected","ItemList", control_font_color_pressed ); + t->set_color("guide_color","ItemList", Color(0,0,0,0.1) ); + t->set_stylebox("selected","ItemList", item_selected_oof ); + t->set_stylebox("selected_focus","ItemList", item_selected ); + t->set_stylebox("cursor","ItemList", focus ); + t->set_stylebox("cursor_unfocused","ItemList", focus ); + // TextEdit @@ -692,7 +711,6 @@ void make_default_theme() { // FileDialog t->set_icon("folder","FileDialog",make_icon(icon_folder_png)); - t->set_color("files_disabled","FileDialog",Color(0,0,0,0.7)); diff --git a/scene/resources/shader.cpp b/scene/resources/shader.cpp index 862669ecd8..90598ee789 100644 --- a/scene/resources/shader.cpp +++ b/scene/resources/shader.cpp @@ -36,7 +36,7 @@ Shader::Mode Shader::get_mode() const { - return (Mode)VisualServer::get_singleton()->shader_get_mode(shader); + return mode; } void Shader::set_code( const String& p_vertex, const String& p_fragment, const String& p_light,int p_fragment_ofs,int p_light_ofs) { @@ -203,6 +203,7 @@ void Shader::_bind_methods() { Shader::Shader(Mode p_mode) { + mode=p_mode; shader = VisualServer::get_singleton()->shader_create(VS::ShaderMode(p_mode)); params_cache_dirty=true; } diff --git a/scene/resources/shader.h b/scene/resources/shader.h index c5ef3777f7..b805cbec96 100644 --- a/scene/resources/shader.h +++ b/scene/resources/shader.h @@ -37,8 +37,18 @@ class Shader : public Resource { OBJ_TYPE(Shader,Resource); OBJ_SAVE_TYPE( Shader ); RES_BASE_EXTENSION("shd"); - RID shader; +public: + enum Mode { + + MODE_MATERIAL, + MODE_CANVAS_ITEM, + MODE_POST_PROCESS, + MODE_MAX + }; +private: + RID shader; + Mode mode; Dictionary _get_code(); void _set_code(const Dictionary& p_string); @@ -55,15 +65,10 @@ class Shader : public Resource { protected: + static void _bind_methods(); public: - enum Mode { - MODE_MATERIAL, - MODE_CANVAS_ITEM, - MODE_POST_PROCESS, - MODE_MAX - }; //void set_mode(Mode p_mode); Mode get_mode() const; |