[godot] Fix SpineSprite hover rendering.

This commit is contained in:
badlogic 2022-05-03 02:49:28 +02:00
parent a90cdfbee6
commit ce73d3c986
3 changed files with 20 additions and 12 deletions

View File

@ -13,7 +13,7 @@ bones = true
bones_color = Color( 0.968627, 1, 0, 0.501961 )
paths_color = Color( 1, 0.498039, 0, 0.466667 )
paths_clipping = Color( 0.8, 0, 0, 0.5 )
preview_animation = "portal"
preview_animation = "run"
preview_frame = true
preview_time = 2.18
preview_time = 0.24
script = ExtResource( 1 )

View File

@ -7,6 +7,7 @@
[node name="SpineSprite" type="SpineSprite" parent="."]
position = Vector2( 502, 480 )
skeleton_data_res = ExtResource( 1 )
bones = true
preview_animation = "-- Empty --"
preview_frame = false
preview_time = 0.0

View File

@ -641,13 +641,13 @@ void SpineSprite::draw() {
}
scratch_points.push_back(Vector2(vertices->buffer()[0], vertices->buffer()[1]));
Color color = debug_regions_color;
if (Geometry::is_point_in_polygon(mouse_position, scratch_points)) {
hovered_slot = slot;
draw_colored_polygon(scratch_points, debug_regions_color);
} else {
scratch_points.push_back(Vector2(vertices->buffer()[0], vertices->buffer()[1]));
draw_polyline(scratch_points, debug_regions_color, 2);
color = Color(1, 1, 1, 1);
}
scratch_points.push_back(Vector2(vertices->buffer()[0], vertices->buffer()[1]));
draw_polyline(scratch_points, color, 2);
}
}
@ -671,13 +671,13 @@ void SpineSprite::draw() {
scratch_points.push_back(Vector2(x, y));
}
Color color = debug_meshes_color;
if (Geometry::is_point_in_polygon(mouse_position, scratch_points)) {
hovered_slot = slot;
draw_colored_polygon(scratch_points, debug_meshes_color);
} else {
scratch_points.push_back(Vector2(vertices->buffer()[0], vertices->buffer()[1]));
draw_polyline(scratch_points, debug_meshes_color, 2);
color = Color(1, 1, 1, 1);
}
scratch_points.push_back(Vector2(vertices->buffer()[0], vertices->buffer()[1]));
draw_polyline(scratch_points, color, 2);
}
}
@ -772,9 +772,16 @@ void SpineSprite::draw() {
}
auto global_scale = get_global_scale();
draw_set_transform(mouse_position, -get_global_rotation(), Vector2(inverse_zoom * (1 / global_scale.x), inverse_zoom * (1 / global_scale.y)));
draw_set_transform(mouse_position + Vector2(20, 0), -get_global_rotation(), Vector2(inverse_zoom * (1 / global_scale.x), inverse_zoom * (1 / global_scale.y)));
float line_height = default_font->get_height() + default_font->get_descent();
float rect_width = 0;
for (int i = 0; i < hover_text_lines.size(); i++) {
rect_width = MAX(rect_width, default_font->get_string_size(hover_text_lines[i]).x);
}
Rect2 background_rect(0, -default_font->get_height() - 5, rect_width + 20, line_height * hover_text_lines.size() + 10);
if (hover_text_lines.size() > 0) draw_rect(background_rect, Color(0, 0, 0 ,0.8));
for (int i = 0; i < hover_text_lines.size(); i++) {
draw_string(default_font, Vector2(11, 1 + i * default_font->get_height()), hover_text_lines[i], Color(0, 0, 0, 1));
draw_string(default_font, Vector2(10, 0 + i * default_font->get_height()), hover_text_lines[i], Color (1, 1, 1, 1));
}
#endif