mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-11-22 00:48:09 +01:00
Added enabled property for VertexLight2Ds.
This commit is contained in:
parent
9df448113d
commit
02fe45b08a
@ -31,6 +31,17 @@
|
||||
|
||||
#include "vertex_light_2d.h"
|
||||
|
||||
#include "core/config/engine.h"
|
||||
|
||||
bool VertexLight2D::get_is_enabled() {
|
||||
return _enabled;
|
||||
}
|
||||
void VertexLight2D::set_enabled(const bool p_enabled) {
|
||||
_enabled = p_enabled;
|
||||
|
||||
_update_light_visibility();
|
||||
}
|
||||
|
||||
Color VertexLight2D::get_color() {
|
||||
return _color;
|
||||
}
|
||||
@ -78,7 +89,8 @@ void VertexLight2D::set_item_cull_mask(const int p_item_cull_mask) {
|
||||
|
||||
VertexLight2D::VertexLight2D() {
|
||||
_vertex_light = RID_PRIME(VertexLights2DServer::get_singleton()->light_create());
|
||||
|
||||
|
||||
_enabled = true;
|
||||
_color = Color(1, 1, 1, 1);
|
||||
_item_cull_mask = 1;
|
||||
_z_range = Vector2i(-1024, 1024);
|
||||
@ -96,10 +108,25 @@ void VertexLight2D::_notification(int p_what) {
|
||||
case NOTIFICATION_TRANSFORM_CHANGED: {
|
||||
VertexLights2DServer::get_singleton()->light_set_position(_vertex_light, get_global_transform().get_origin());
|
||||
} break;
|
||||
case NOTIFICATION_VISIBILITY_CHANGED: {
|
||||
_update_light_visibility();
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void VertexLight2D::_update_light_visibility() {
|
||||
if (!is_inside_tree()) {
|
||||
return;
|
||||
}
|
||||
|
||||
VertexLights2DServer::get_singleton()->light_set_enabled(_vertex_light, _enabled && is_visible_in_tree());
|
||||
}
|
||||
|
||||
void VertexLight2D::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_is_enabled"), &VertexLight2D::get_is_enabled);
|
||||
ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &VertexLight2D::set_enabled);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "get_is_enabled");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_color"), &VertexLight2D::get_color);
|
||||
ClassDB::bind_method(D_METHOD("set_color", "color"), &VertexLight2D::set_color);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color");
|
||||
|
@ -52,6 +52,9 @@ public:
|
||||
//VERTEX_LIGHT_2D_MODE_MASK = VertexLights2DServer::VERTEX_LIGHT_2D_MODE_MASK
|
||||
};
|
||||
|
||||
bool get_is_enabled();
|
||||
void set_enabled(const bool p_enabled);
|
||||
|
||||
Color get_color();
|
||||
void set_color(const Color &p_color);
|
||||
|
||||
@ -72,11 +75,14 @@ public:
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
|
||||
void _update_light_visibility();
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
RID _vertex_light;
|
||||
|
||||
|
||||
bool _enabled;
|
||||
Color _color;
|
||||
VertexLight2DMode _mode;
|
||||
Vector2i _z_range;
|
||||
|
@ -47,6 +47,7 @@ class VertexLightData2D;
|
||||
|
||||
class VertexLightData2D : public RID_Data {
|
||||
public:
|
||||
bool enabled;
|
||||
Vector2 position;
|
||||
Color color;
|
||||
VertexLights2DServer::VertexLight2DMode mode;
|
||||
@ -62,7 +63,8 @@ public:
|
||||
VertexLightData2D() {
|
||||
map = NULL;
|
||||
quadrant = NULL;
|
||||
|
||||
|
||||
enabled = true;
|
||||
color = Color(1, 1, 1, 1);
|
||||
item_cull_mask = 1;
|
||||
z_range = Vector2i(-1024, 1024);
|
||||
|
@ -124,6 +124,19 @@ void VertexLights2DServer::light_set_map(RID p_light, RID p_map) {
|
||||
}
|
||||
}
|
||||
|
||||
bool VertexLights2DServer::light_get_is_enabled(RID p_light) {
|
||||
const VertexLightData2D *light = light_owner.getornull(p_light);
|
||||
ERR_FAIL_COND_V(light == NULL, false);
|
||||
|
||||
return light->enabled;
|
||||
}
|
||||
void VertexLights2DServer::light_set_enabled(RID p_light, const bool p_enabled) {
|
||||
VertexLightData2D *light = light_owner.getornull(p_light);
|
||||
ERR_FAIL_COND(light == NULL);
|
||||
|
||||
light->enabled = p_enabled;
|
||||
}
|
||||
|
||||
Vector2 VertexLights2DServer::light_get_position(RID p_light) {
|
||||
const VertexLightData2D *light = light_owner.getornull(p_light);
|
||||
ERR_FAIL_COND_V(light == NULL, Vector2());
|
||||
@ -230,7 +243,7 @@ void VertexLights2DServer::free(RID p_rid) {
|
||||
if (light->map) {
|
||||
light->map->remove_light(light);
|
||||
}
|
||||
|
||||
|
||||
light->self = RID();
|
||||
|
||||
light_owner.free(p_rid);
|
||||
@ -274,6 +287,9 @@ void VertexLights2DServer::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("light_get_map", "light"), &VertexLights2DServer::light_get_map);
|
||||
ClassDB::bind_method(D_METHOD("light_set_map", "light", "map"), &VertexLights2DServer::light_set_map);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("light_get_is_enabled", "light"), &VertexLights2DServer::light_get_is_enabled);
|
||||
ClassDB::bind_method(D_METHOD("light_set_enabled", "light", "enabled"), &VertexLights2DServer::light_set_enabled);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("light_get_position", "light"), &VertexLights2DServer::light_get_position);
|
||||
ClassDB::bind_method(D_METHOD("light_set_position", "light", "position"), &VertexLights2DServer::light_set_position);
|
||||
|
||||
|
@ -76,6 +76,9 @@ public:
|
||||
|
||||
RID light_get_map(RID p_light);
|
||||
void light_set_map(RID p_light, RID p_map);
|
||||
|
||||
bool light_get_is_enabled(RID p_light);
|
||||
void light_set_enabled(RID p_light, const bool p_enabled);
|
||||
|
||||
Vector2 light_get_position(RID p_light);
|
||||
void light_set_position(RID p_light, const Vector2 &p_position);
|
||||
|
Loading…
Reference in New Issue
Block a user