Skip to content

Commit

Permalink
VertexLight2D support for LayeredTileSetAtlasSourceEditor.
Browse files Browse the repository at this point in the history
  • Loading branch information
Relintai committed May 11, 2024
1 parent 48c65ce commit 7a42711
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 3 deletions.
4 changes: 2 additions & 2 deletions modules/layered_tile_map/editor/layered_tile_data_editors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,7 @@ void TileDataDefaultEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2
}
}

void TileDataDefaultEditor::setup_property_editor(Variant::Type p_type, const String &p_property, const String &p_label, const Variant &p_default_value) {
void TileDataDefaultEditor::setup_property_editor(Variant::Type p_type, const String &p_property, const String &p_label, const Variant &p_default_value, PropertyHint p_hint, const String &p_hint_text, int p_usage) {
ERR_FAIL_COND_MSG(!property.empty(), "Cannot setup TileDataDefaultEditor twice");
property = p_property;
property_type = p_type;
Expand All @@ -1328,7 +1328,7 @@ void TileDataDefaultEditor::setup_property_editor(Variant::Type p_type, const St
}

// Create and setup the property editor.
property_editor = EditorInspector::instantiate_property_editor(dummy_object, p_type, p_property, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT);
property_editor = EditorInspector::instantiate_property_editor(dummy_object, p_type, p_property, p_hint, p_hint_text, p_usage);

property_editor->set_object_and_property(dummy_object, p_property);
if (p_label.empty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class TileDataDefaultEditor : public LayeredTileDataEditor {
virtual void forward_painting_alternatives_gui_input(LayeredTileAtlasView *p_tile_atlas_view, LayeredTileSetAtlasSource *p_tile_atlas_source, const Ref<InputEvent> &p_event);
virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, LayeredTileMapCell p_cell, bool p_selected = false);

void setup_property_editor(Variant::Type p_type, const String &p_property, const String &p_label = "", const Variant &p_default_value = Variant());
void setup_property_editor(Variant::Type p_type, const String &p_property, const String &p_label = "", const Variant &p_default_value = Variant(), PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_text = "", int p_usage = PROPERTY_USAGE_DEFAULT);
Variant::Type get_property_type();

TileDataDefaultEditor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@

#include "servers/navigation_2d_server.h"

#include "modules/modules_enabled.gen.h"

#include <limits.h>

void LayeredTileSetAtlasSourceEditor::LayeredTileSetAtlasSourceProxyObject::set_id(int p_id) {
Expand Down Expand Up @@ -900,6 +902,101 @@ void LayeredTileSetAtlasSourceEditor::_update_tile_data_editors() {

//tile_data_editors_tree->update_minimum_size();

// VertexLights2D
#ifdef MODULE_VERTEX_LIGHTS_2D_ENABLED
ADD_TILE_DATA_EDITOR_GROUP(TTR("VertexLight2D"));

ADD_TILE_DATA_EDITOR(group, TTR("Enabled"), "vertex_light_enabled");
if (!tile_data_editors.has("vertex_light_enabled")) {
TileDataDefaultEditor *tde = memnew(TileDataDefaultEditor());
tde->hide();
tde->setup_property_editor(Variant::BOOL, "vertex_light_enabled");
tde->connect("needs_redraw", tile_atlas_control_unscaled, "update");
tde->connect("needs_redraw", alternative_tiles_control_unscaled, "update");
tile_data_editors["vertex_light_enabled"] = tde;
}

ADD_TILE_DATA_EDITOR(group, TTR("Position"), "vertex_light_position");
if (!tile_data_editors.has("vertex_light_position")) {
TileDataPositionEditor *tde = memnew(TileDataPositionEditor);
tde->hide();
tde->setup_property_editor(Variant::VECTOR2I, "vertex_light_position");
tde->connect("needs_redraw", tile_atlas_control_unscaled, "update");
tde->connect("needs_redraw", alternative_tiles_control_unscaled, "update");
tile_data_editors["vertex_light_position"] = tde;
}

ADD_TILE_DATA_EDITOR(group, TTR("Range"), "vertex_light_range");
if (!tile_data_editors.has("vertex_light_range")) {
TileDataDefaultEditor *tde = memnew(TileDataDefaultEditor());
tde->hide();
tde->setup_property_editor(Variant::VECTOR2I, "vertex_light_range", "", Vector2i(32, 32));
tde->connect("needs_redraw", tile_atlas_control_unscaled, "update");
tde->connect("needs_redraw", alternative_tiles_control_unscaled, "update");
tile_data_editors["vertex_light_range"] = tde;
}

ADD_TILE_DATA_EDITOR(group, TTR("Attenuation"), "vertex_light_attenuation");
if (!tile_data_editors.has("vertex_light_attenuation")) {
TileDataDefaultEditor *tde = memnew(TileDataDefaultEditor());
tde->hide();
tde->setup_property_editor(Variant::REAL, "vertex_light_attenuation", "", 1, PROPERTY_HINT_EXP_EASING, "attenuation");
tde->connect("needs_redraw", tile_atlas_control_unscaled, "update");
tde->connect("needs_redraw", alternative_tiles_control_unscaled, "update");
tile_data_editors["vertex_light_attenuation"] = tde;
}

ADD_TILE_DATA_EDITOR(group, TTR("Color"), "vertex_light_color");
if (!tile_data_editors.has("vertex_light_color")) {
TileDataDefaultEditor *tde = memnew(TileDataDefaultEditor());
tde->hide();
tde->setup_property_editor(Variant::COLOR, "vertex_light_color", "", Color(1, 1, 1, 1));
tde->connect("needs_redraw", tile_atlas_control_unscaled, "update");
tde->connect("needs_redraw", alternative_tiles_control_unscaled, "update");
tile_data_editors["vertex_light_color"] = tde;
}

ADD_TILE_DATA_EDITOR(group, TTR("Light Mode"), "set_vertex_light_mode");
if (!tile_data_editors.has("set_vertex_light_mode")) {
TileDataDefaultEditor *tde = memnew(TileDataDefaultEditor());
tde->hide();
tde->setup_property_editor(Variant::INT, "set_vertex_light_mode", "", 0, PROPERTY_HINT_ENUM, "Add,Sub,Mix");
tde->connect("needs_redraw", tile_atlas_control_unscaled, "update");
tde->connect("needs_redraw", alternative_tiles_control_unscaled, "update");
tile_data_editors["set_vertex_light_mode"] = tde;
}

ADD_TILE_DATA_EDITOR(group, TTR("Z Range"), "vertex_light_z_range");
if (!tile_data_editors.has("vertex_light_z_range")) {
TileDataDefaultEditor *tde = memnew(TileDataDefaultEditor());
tde->hide();
tde->setup_property_editor(Variant::VECTOR2I, "vertex_light_z_range", "", Vector2i(-1024, 1024), PROPERTY_HINT_RANGE, itos(RS::CANVAS_ITEM_Z_MIN) + "," + itos(RS::CANVAS_ITEM_Z_MAX) + ",1");
tde->connect("needs_redraw", tile_atlas_control_unscaled, "update");
tde->connect("needs_redraw", alternative_tiles_control_unscaled, "update");
tile_data_editors["vertex_light_z_range"] = tde;
}

ADD_TILE_DATA_EDITOR(group, TTR("Layer Range"), "vertex_light_layer_range");
if (!tile_data_editors.has("vertex_light_layer_range")) {
TileDataDefaultEditor *tde = memnew(TileDataDefaultEditor());
tde->hide();
tde->setup_property_editor(Variant::VECTOR2I, "vertex_light_layer_range", "", Vector2i(-512, 512), PROPERTY_HINT_RANGE, "-512,512,1");
tde->connect("needs_redraw", tile_atlas_control_unscaled, "update");
tde->connect("needs_redraw", alternative_tiles_control_unscaled, "update");
tile_data_editors["vertex_light_layer_range"] = tde;
}

ADD_TILE_DATA_EDITOR(group, TTR("Item Cull Mask"), "vertex_light_item_cull_mask");
if (!tile_data_editors.has("vertex_light_item_cull_mask")) {
TileDataDefaultEditor *tde = memnew(TileDataDefaultEditor());
tde->hide();
tde->setup_property_editor(Variant::INT, "vertex_light_item_cull_mask", "", 1, PROPERTY_HINT_LAYERS_2D_RENDER);
tde->connect("needs_redraw", tile_atlas_control_unscaled, "update");
tde->connect("needs_redraw", alternative_tiles_control_unscaled, "update");
tile_data_editors["vertex_light_item_cull_mask"] = tde;
}
#endif

#undef ADD_TILE_DATA_EDITOR_GROUP
#undef ADD_TILE_DATA_EDITOR

Expand Down

0 comments on commit 7a42711

Please sign in to comment.