diff options
author | Pedro J. Estébanez <pedrojrulez@gmail.com> | 2016-10-04 16:44:59 +0200 |
---|---|---|
committer | Pedro J. Estébanez <pedrojrulez@gmail.com> | 2016-10-04 16:44:59 +0200 |
commit | 34c02fad5ac54f6c10730c9a930b883b08e51e45 (patch) | |
tree | 6ea0f8d993b73a3c4c088f426158e046cdaef3a7 /scene/2d | |
parent | dabcabe9815612c7ef1c99909b14d632f13df165 (diff) |
Add editor_only param to Light2D
Diffstat (limited to 'scene/2d')
-rw-r--r-- | scene/2d/light_2d.cpp | 34 | ||||
-rw-r--r-- | scene/2d/light_2d.h | 4 |
2 files changed, 37 insertions, 1 deletions
diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp index f37cef673d..3e548a24b0 100644 --- a/scene/2d/light_2d.cpp +++ b/scene/2d/light_2d.cpp @@ -67,7 +67,23 @@ void Light2D::_update_light_visibility() { if (!is_inside_tree()) return; - VS::get_singleton()->canvas_light_set_enabled(canvas_light,enabled && is_visible()); + bool editor_ok=true; + +#ifdef TOOLS_ENABLED + if (editor_only) { + if (!get_tree()->is_editor_hint()) { + editor_ok=false; + } else { + editor_ok = (get_tree()->get_edited_scene_root() && (this==get_tree()->get_edited_scene_root() || get_owner()==get_tree()->get_edited_scene_root())); + } + } +#else + if (editor_only) { + editor_ok=false; + } +#endif + + VS::get_singleton()->canvas_light_set_enabled(canvas_light,enabled && is_visible() && editor_ok); } void Light2D::set_enabled( bool p_enabled) { @@ -82,6 +98,17 @@ bool Light2D::is_enabled() const { return enabled; } +void Light2D::set_editor_only(bool p_editor_only) { + + editor_only=p_editor_only; + _update_light_visibility(); +} + +bool Light2D::is_editor_only() const{ + + return editor_only; +} + void Light2D::set_texture( const Ref<Texture>& p_texture) { texture=p_texture; @@ -328,6 +355,9 @@ void Light2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_enabled","enabled"),&Light2D::set_enabled); ObjectTypeDB::bind_method(_MD("is_enabled"),&Light2D::is_enabled); + ObjectTypeDB::bind_method(_MD("set_editor_only","editor_only"), &Light2D::set_editor_only ); + ObjectTypeDB::bind_method(_MD("is_editor_only"), &Light2D::is_editor_only ); + ObjectTypeDB::bind_method(_MD("set_texture","texture"),&Light2D::set_texture); ObjectTypeDB::bind_method(_MD("get_texture"),&Light2D::get_texture); @@ -383,6 +413,7 @@ void Light2D::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::BOOL,"enabled"),_SCS("set_enabled"),_SCS("is_enabled")); + ADD_PROPERTY( PropertyInfo(Variant::BOOL, "editor_only"),_SCS("set_editor_only"),_SCS("is_editor_only")); ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"texture",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),_SCS("set_texture"),_SCS("get_texture")); ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"offset"),_SCS("set_texture_offset"),_SCS("get_texture_offset")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"scale",PROPERTY_HINT_RANGE,"0.01,50,0.01"),_SCS("set_texture_scale"),_SCS("get_texture_scale")); @@ -413,6 +444,7 @@ Light2D::Light2D() { canvas_light=VisualServer::get_singleton()->canvas_light_create(); enabled=true; + editor_only=false; shadow=false; color=Color(1,1,1); height=0; diff --git a/scene/2d/light_2d.h b/scene/2d/light_2d.h index c03ef96eff..57c89b15e7 100644 --- a/scene/2d/light_2d.h +++ b/scene/2d/light_2d.h @@ -45,6 +45,7 @@ public: private: RID canvas_light; bool enabled; + bool editor_only; bool shadow; Color color; Color shadow_color; @@ -78,6 +79,9 @@ public: void set_enabled( bool p_enabled); bool is_enabled() const; + void set_editor_only(bool p_editor_only); + bool is_editor_only() const; + void set_texture( const Ref<Texture>& p_texture); Ref<Texture> get_texture() const; |