From 7a4271104dbb719e7c66bd86067d161ebde0eb90 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 11 May 2024 21:50:55 +0200 Subject: [PATCH] VertexLight2D support for LayeredTileSetAtlasSourceEditor. --- .../editor/layered_tile_data_editors.cpp | 4 +- .../editor/layered_tile_data_editors.h | 2 +- .../layered_tile_set_atlas_source_editor.cpp | 97 +++++++++++++++++++ 3 files changed, 100 insertions(+), 3 deletions(-) diff --git a/modules/layered_tile_map/editor/layered_tile_data_editors.cpp b/modules/layered_tile_map/editor/layered_tile_data_editors.cpp index 76acd86c8..8bd2d29a1 100644 --- a/modules/layered_tile_map/editor/layered_tile_data_editors.cpp +++ b/modules/layered_tile_map/editor/layered_tile_data_editors.cpp @@ -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; @@ -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()) { diff --git a/modules/layered_tile_map/editor/layered_tile_data_editors.h b/modules/layered_tile_map/editor/layered_tile_data_editors.h index 571f730ac..d5ee28376 100644 --- a/modules/layered_tile_map/editor/layered_tile_data_editors.h +++ b/modules/layered_tile_map/editor/layered_tile_data_editors.h @@ -253,7 +253,7 @@ public: virtual void forward_painting_alternatives_gui_input(LayeredTileAtlasView *p_tile_atlas_view, LayeredTileSetAtlasSource *p_tile_atlas_source, const Ref &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(); diff --git a/modules/layered_tile_map/editor/layered_tile_set_atlas_source_editor.cpp b/modules/layered_tile_map/editor/layered_tile_set_atlas_source_editor.cpp index e4b8b88a1..54d874361 100644 --- a/modules/layered_tile_map/editor/layered_tile_set_atlas_source_editor.cpp +++ b/modules/layered_tile_map/editor/layered_tile_set_atlas_source_editor.cpp @@ -64,6 +64,8 @@ #include "servers/navigation_2d_server.h" +#include "modules/modules_enabled.gen.h" + #include void LayeredTileSetAtlasSourceEditor::LayeredTileSetAtlasSourceProxyObject::set_id(int p_id) { @@ -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