diff options
author | kobewi <kobewi4e@gmail.com> | 2022-12-19 11:51:37 +0100 |
---|---|---|
committer | kobewi <kobewi4e@gmail.com> | 2022-12-19 11:51:37 +0100 |
commit | 32b0770a7382325305bdfb008665b7e150778124 (patch) | |
tree | d4bbf250b0b610942afd11f4b5b57fd7b4ce8b5b | |
parent | e780dc332a0a3f642a6daf8548cb211d79a2cc45 (diff) |
Add a method to get global modulate
-rw-r--r-- | editor/plugins/tiles/tile_map_editor.cpp | 2 | ||||
-rw-r--r-- | scene/main/canvas_item.cpp | 10 | ||||
-rw-r--r-- | scene/main/canvas_item.h | 1 |
3 files changed, 12 insertions, 1 deletions
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; |