From 32b0770a7382325305bdfb008665b7e150778124 Mon Sep 17 00:00:00 2001 From: kobewi Date: Mon, 19 Dec 2022 11:51:37 +0100 Subject: Add a method to get global modulate --- editor/plugins/tiles/tile_map_editor.cpp | 2 +- scene/main/canvas_item.cpp | 10 ++++++++++ scene/main/canvas_item.h | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/editor/plugins/tiles/tile_map_editor.cpp b/editor/plugins/tiles/tile_map_editor.cpp index 4131c06745..e33f4c6671 100644 --- a/editor/plugins/tiles/tile_map_editor.cpp +++ b/editor/plugins/tiles/tile_map_editor.cpp @@ -922,7 +922,7 @@ void TileMapEditorTilesPlugin::forward_canvas_draw_over_viewport(Control *p_over // Get the tile modulation. Color modulate = tile_data->get_modulate(); - Color self_modulate = tile_map->get_self_modulate(); + Color self_modulate = tile_map->get_modulate_in_tree() * tile_map->get_self_modulate(); modulate *= self_modulate; // Draw the tile. diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp index 2563fa5914..76d5494ce3 100644 --- a/scene/main/canvas_item.cpp +++ b/scene/main/canvas_item.cpp @@ -388,6 +388,16 @@ Color CanvasItem::get_modulate() const { return modulate; } +Color CanvasItem::get_modulate_in_tree() const { + Color final_modulate = modulate; + CanvasItem *parent_item = get_parent_item(); + while (parent_item) { + final_modulate *= parent_item->get_modulate(); + parent_item = parent_item->get_parent_item(); + } + return final_modulate; +} + void CanvasItem::set_as_top_level(bool p_top_level) { if (top_level == p_top_level) { return; diff --git a/scene/main/canvas_item.h b/scene/main/canvas_item.h index 4ace982825..a60a2bb5a1 100644 --- a/scene/main/canvas_item.h +++ b/scene/main/canvas_item.h @@ -224,6 +224,7 @@ public: void set_modulate(const Color &p_modulate); Color get_modulate() const; + Color get_modulate_in_tree() const; void set_self_modulate(const Color &p_self_modulate); Color get_self_modulate() const; -- cgit v1.2.3