godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.17k stars 21.2k forks source link

GraphElement don't display in the minimap of the graphedit. #88710

Open rm-software-programming opened 8 months ago

rm-software-programming commented 8 months ago

Tested versions

Godot 4.2.1 Mono stable.

GraphElement don't display in the GraphEdit minimap.

There is a need for a way to display a indicator in the minimap. Thanks.

System information

Godot v4.2.1.stable.mono - Windows 10.0.22631 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 4060 Ti (NVIDIA; 31.0.15.5123) - AMD Ryzen 7 2700 Eight-Core Processor (16 Threads)

Issue description

The presence of a GraphElement in the GraphEdit, make the minimap react to the interaction with the GraphElement like with the GraphNode. But, where the GraphNode display an indicator in the minimap, the GraphEdit don't.

Steps to reproduce

Create a scene. Add a GraphEdit. Make it FullRect. Add a GraphElement the GraphEdit. Add a ColorRect to the GraphElement to make it visible. Move it around. The minimap react but display nothing.

Minimal reproduction project (MRP)

GraphElementMinimap.zip

rm-software-programming commented 8 months ago

I don't know how to upload the fix, and i don't know if it's good but:

struct ThemeCache {
    Ref<Texture2D> resizer;
    Ref<StyleBoxFlat> fallback_minimap_panel;
} theme_cache;
//in godot\scene\gui\graph_element.h

//#include "scene/resources/style_box_flat.h"
...
struct ThemeCache {
    Ref<Texture2D> resizer;
    Ref<StyleBoxFlat> fallback_minimap_panel;// Adding this stylebox
} theme_cache;

//in godot\scene\gui\graph_edit.cpp

void GraphEdit::_minimap_draw() {
    if (!is_minimap_enabled()) {
        return;
    }

    minimap->update_minimap();

    // Draw the minimap background.
    Rect2 minimap_rect = Rect2(Point2(), minimap->get_size());
    minimap->draw_style_box(minimap->theme_cache.panel, minimap_rect);

    Vector2 graph_offset = minimap->_get_graph_offset();
    Vector2 minimap_offset = minimap->minimap_offset;

    // Draw graph nodes.
    for (int i = get_child_count() - 1; i >= 0; i--) {
        GraphElement *graph_element = Object::cast_to<GraphElement>(get_child(i));// casting for graphelement
        if (!graph_element || !graph_element->is_visible()) {
            continue;
        }

        Vector2 node_position = minimap->_convert_from_graph_position(graph_element->get_position_offset() * zoom - graph_offset) + minimap_offset;
        Vector2 node_size = minimap->_convert_from_graph_position(graph_element->get_size() * zoom);
        Rect2 node_rect = Rect2(node_position, node_size);

        Ref<StyleBoxFlat> sb_minimap = minimap->theme_cache.node_style->duplicate();

        // Override default values with colors provided by the GraphNode's stylebox, if possible.

        GraphNode *graph_node = Object::cast_to<GraphNode>(graph_element);// same code that before
        Ref<StyleBoxFlat> sb_frame;// early declaration
        if (graph_node) {
            sb_frame = graph_node->is_selected() ? graph_node->theme_cache.panel_selected : graph_node->theme_cache.panel;
        } else {// if graph element
            sb_frame = graph_element->theme_cache.fallback_minimap_panel;//use fallback panel
        }
        if (sb_frame.is_valid()) {//from now its the same code
            Color node_color = sb_frame->get_bg_color();
            sb_minimap->set_bg_color(node_color);
        }

        minimap->draw_style_box(sb_minimap, node_rect);
    }

    // Draw node connections.
    for (const Ref<Connection> &c : connections) {
        Vector2 from_position = minimap->_convert_from_graph_position(c->_cache.from_pos * zoom - graph_offset) + minimap_offset;
        Vector2 to_position = minimap->_convert_from_graph_position(c->_cache.to_pos * zoom - graph_offset) + minimap_offset;
        Color from_color = c->_cache.from_color;
        Color to_color = c->_cache.to_color;

        if (c->activity > 0) {
            from_color = from_color.lerp(theme_cache.activity_color, c->activity);
            to_color = to_color.lerp(theme_cache.activity_color, c->activity);
        }
        _draw_minimap_connection_line(minimap, from_position, to_position, from_color, to_color);
    }

    // Draw the "camera" viewport.
    Rect2 camera_rect = minimap->get_camera_rect();
    minimap->draw_style_box(minimap->theme_cache.camera_style, camera_rect);

    // Draw the resizer control.
    Ref<Texture2D> resizer = minimap->theme_cache.resizer;
    Color resizer_color = minimap->theme_cache.resizer_color;
    minimap->draw_texture(resizer, Point2(), resizer_color);
}

I don't think this code break something, it's didn't for, the project in the work without change.
I don't know how to make it (the fallback panel) in the theme section.
Sorry for the method, but i don't know how to pull request, i need to learn.
Calinou commented 8 months ago

cc @Geometror

This may have been fixed in the GraphEdit refactoring coming to 4.3 already. Try building the master branch from source and check there.

rm-software-programming commented 8 months ago

tryed in v4.3.dev.custom_build [2e7fc8131] problem still here.

rm-software-programming commented 8 months ago

adding:

BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, GraphElement, fallback_minimap_panel);

in GraphElement::_bind_methods() Make it appear in the editor but change are nor updated (it show up only when the app run). How to make the editor feedback the update (for ui theme in general). Also, in theme editor there is no graph element available.