mirror of
https://github.com/godotengine/godot.git
synced 2025-01-24 03:24:32 -05:00
Merge pull request #98401 from vaner-org/green-arrow-priority-for-transition-selection
Prioritize proximity to green arrow when selecting overlapping transitions in AnimationNodeStateMachine
This commit is contained in:
commit
463c479ac8
1 changed files with 27 additions and 3 deletions
|
@ -228,9 +228,12 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//test the lines now
|
// Test the transition lines.
|
||||||
int closest = -1;
|
int closest = -1;
|
||||||
float closest_d = 1e20;
|
float closest_d = 1e20;
|
||||||
|
Vector<int> close_candidates;
|
||||||
|
|
||||||
|
// First find closest lines using point-to-segment distance.
|
||||||
for (int i = 0; i < transition_lines.size(); i++) {
|
for (int i = 0; i < transition_lines.size(); i++) {
|
||||||
Vector2 s[2] = {
|
Vector2 s[2] = {
|
||||||
transition_lines[i].from,
|
transition_lines[i].from,
|
||||||
|
@ -238,13 +241,34 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv
|
||||||
};
|
};
|
||||||
Vector2 cpoint = Geometry2D::get_closest_point_to_segment(mb->get_position(), s);
|
Vector2 cpoint = Geometry2D::get_closest_point_to_segment(mb->get_position(), s);
|
||||||
float d = cpoint.distance_to(mb->get_position());
|
float d = cpoint.distance_to(mb->get_position());
|
||||||
|
|
||||||
if (d > transition_lines[i].width) {
|
if (d > transition_lines[i].width) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d < closest_d) {
|
// If this is very close to our current closest distance, add it to candidates.
|
||||||
closest = i;
|
if (Math::abs(d - closest_d) < 2.0) { // Within 2 pixels.
|
||||||
|
close_candidates.push_back(i);
|
||||||
|
} else if (d < closest_d) {
|
||||||
closest_d = d;
|
closest_d = d;
|
||||||
|
closest = i;
|
||||||
|
close_candidates.clear();
|
||||||
|
close_candidates.push_back(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use midpoint distance as bias.
|
||||||
|
if (close_candidates.size() > 1) {
|
||||||
|
float best_midpoint_dist = 1e20;
|
||||||
|
|
||||||
|
for (int idx : close_candidates) {
|
||||||
|
Vector2 midpoint = (transition_lines[idx].from + transition_lines[idx].to) / 2.0;
|
||||||
|
float midpoint_dist = midpoint.distance_to(mb->get_position());
|
||||||
|
|
||||||
|
if (midpoint_dist < best_midpoint_dist) {
|
||||||
|
best_midpoint_dist = midpoint_dist;
|
||||||
|
closest = idx;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue