Merge pull request #88829 from ryevdokimov/institate_message-2d
Show instantiating or inherit message when using drag to instantiate in 2D
This commit is contained in:
commit
6d8ca17139
2 changed files with 62 additions and 48 deletions
|
@ -3684,11 +3684,8 @@ void CanvasItemEditor::_draw_hover() {
|
|||
}
|
||||
}
|
||||
|
||||
void CanvasItemEditor::_draw_transform_message() {
|
||||
if (drag_type == DRAG_NONE || drag_selection.is_empty() || !drag_selection.front()->get()) {
|
||||
return;
|
||||
}
|
||||
String transform_message;
|
||||
void CanvasItemEditor::_draw_message() {
|
||||
if (drag_type != DRAG_NONE && !drag_selection.is_empty() && drag_selection.front()->get()) {
|
||||
Transform2D current_transform = drag_selection.front()->get()->get_global_transform();
|
||||
|
||||
double snap = EDITOR_GET("interface/inspector/default_float_step");
|
||||
|
@ -3701,17 +3698,17 @@ void CanvasItemEditor::_draw_transform_message() {
|
|||
case DRAG_MOVE_Y: {
|
||||
Vector2 delta = current_transform.get_origin() - original_transform.get_origin();
|
||||
if (drag_type == DRAG_MOVE) {
|
||||
transform_message = TTR("Moving:") + " (" + FORMAT(delta.x) + ", " + FORMAT(delta.y) + ") px";
|
||||
message = TTR("Moving:") + " (" + FORMAT(delta.x) + ", " + FORMAT(delta.y) + ") px";
|
||||
} else if (drag_type == DRAG_MOVE_X) {
|
||||
transform_message = TTR("Moving:") + " " + FORMAT(delta.x) + " px";
|
||||
message = TTR("Moving:") + " " + FORMAT(delta.x) + " px";
|
||||
} else if (drag_type == DRAG_MOVE_Y) {
|
||||
transform_message = TTR("Moving:") + " " + FORMAT(delta.y) + " px";
|
||||
message = TTR("Moving:") + " " + FORMAT(delta.y) + " px";
|
||||
}
|
||||
} break;
|
||||
|
||||
case DRAG_ROTATE: {
|
||||
real_t delta = Math::rad_to_deg(current_transform.get_rotation() - original_transform.get_rotation());
|
||||
transform_message = TTR("Rotating:") + " " + FORMAT(delta) + String::utf8(" °");
|
||||
message = TTR("Rotating:") + " " + FORMAT(delta) + String::utf8(" °");
|
||||
} break;
|
||||
|
||||
case DRAG_SCALE_X:
|
||||
|
@ -3720,11 +3717,11 @@ void CanvasItemEditor::_draw_transform_message() {
|
|||
Vector2 original_scale = (Math::is_zero_approx(original_transform.get_scale().x) || Math::is_zero_approx(original_transform.get_scale().y)) ? Vector2(CMP_EPSILON, CMP_EPSILON) : original_transform.get_scale();
|
||||
Vector2 delta = current_transform.get_scale() / original_scale;
|
||||
if (drag_type == DRAG_SCALE_BOTH) {
|
||||
transform_message = TTR("Scaling:") + String::utf8(" ×(") + FORMAT(delta.x) + ", " + FORMAT(delta.y) + ")";
|
||||
message = TTR("Scaling:") + String::utf8(" ×(") + FORMAT(delta.x) + ", " + FORMAT(delta.y) + ")";
|
||||
} else if (drag_type == DRAG_SCALE_X) {
|
||||
transform_message = TTR("Scaling:") + String::utf8(" ×") + FORMAT(delta.x);
|
||||
message = TTR("Scaling:") + String::utf8(" ×") + FORMAT(delta.x);
|
||||
} else if (drag_type == DRAG_SCALE_Y) {
|
||||
transform_message = TTR("Scaling:") + String::utf8(" ×") + FORMAT(delta.y);
|
||||
message = TTR("Scaling:") + String::utf8(" ×") + FORMAT(delta.y);
|
||||
}
|
||||
} break;
|
||||
|
||||
|
@ -3732,17 +3729,18 @@ void CanvasItemEditor::_draw_transform_message() {
|
|||
break;
|
||||
}
|
||||
#undef FORMAT
|
||||
}
|
||||
|
||||
if (transform_message.is_empty()) {
|
||||
if (message.is_empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
|
||||
int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
|
||||
Point2 msgpos = Point2(RULER_WIDTH + 5 * EDSCALE, viewport->get_size().y - 20 * EDSCALE);
|
||||
viewport->draw_string(font, msgpos + Point2(1, 1), transform_message, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, Color(0, 0, 0, 0.8));
|
||||
viewport->draw_string(font, msgpos + Point2(-1, -1), transform_message, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, Color(0, 0, 0, 0.8));
|
||||
viewport->draw_string(font, msgpos, transform_message, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, Color(1, 1, 1, 1));
|
||||
viewport->draw_string(font, msgpos + Point2(1, 1), message, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, Color(0, 0, 0, 0.8));
|
||||
viewport->draw_string(font, msgpos + Point2(-1, -1), message, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, Color(0, 0, 0, 0.8));
|
||||
viewport->draw_string(font, msgpos, message, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, Color(1, 1, 1, 1));
|
||||
}
|
||||
|
||||
void CanvasItemEditor::_draw_locks_and_groups(Node *p_node, const Transform2D &p_parent_xform, const Transform2D &p_canvas_xform) {
|
||||
|
@ -3856,7 +3854,7 @@ void CanvasItemEditor::_draw_viewport() {
|
|||
_draw_smart_snapping();
|
||||
_draw_focus();
|
||||
_draw_hover();
|
||||
_draw_transform_message();
|
||||
_draw_message();
|
||||
}
|
||||
|
||||
void CanvasItemEditor::update_viewport() {
|
||||
|
@ -4740,6 +4738,7 @@ void CanvasItemEditor::_focus_selection(int p_op) {
|
|||
}
|
||||
|
||||
void CanvasItemEditor::_reset_drag() {
|
||||
message = "";
|
||||
drag_type = DRAG_NONE;
|
||||
drag_selection.clear();
|
||||
}
|
||||
|
@ -5693,6 +5692,7 @@ void CanvasItemEditorViewport::_create_preview(const Vector<String> &files) cons
|
|||
|
||||
void CanvasItemEditorViewport::_remove_preview() {
|
||||
if (preview_node->get_parent()) {
|
||||
canvas_item_editor->message = "";
|
||||
for (int i = preview_node->get_child_count() - 1; i >= 0; i--) {
|
||||
Node *node = preview_node->get_child(i);
|
||||
node->queue_free();
|
||||
|
@ -5938,7 +5938,19 @@ bool CanvasItemEditorViewport::can_drop_data(const Point2 &p_point, const Varian
|
|||
}
|
||||
Transform2D trans = canvas_item_editor->get_canvas_transform();
|
||||
preview_node->set_position((p_point - trans.get_origin()) / trans.get_scale().x);
|
||||
String scene_file_path = preview_node->get_child(0)->get_scene_file_path();
|
||||
if (scene_file_path.is_empty() || preview_node->get_tree()->get_edited_scene_root()) {
|
||||
double snap = EDITOR_GET("interface/inspector/default_float_step");
|
||||
int snap_step_decimals = Math::range_step_decimals(snap);
|
||||
#define FORMAT(value) (TS->format_number(String::num(value, snap_step_decimals)))
|
||||
Vector2 preview_node_pos = preview_node->get_global_position();
|
||||
canvas_item_editor->message = TTR("Instantiating:") + " (" + FORMAT(preview_node_pos.x) + ", " + FORMAT(preview_node_pos.y) + ") px";
|
||||
label->set_text(vformat(TTR("Adding %s..."), default_texture_node_type));
|
||||
} else {
|
||||
canvas_item_editor->message = TTR("Creating inherited scene from: ") + scene_file_path;
|
||||
}
|
||||
|
||||
canvas_item_editor->update_viewport();
|
||||
}
|
||||
return can_instantiate;
|
||||
}
|
||||
|
|
|
@ -458,7 +458,7 @@ private:
|
|||
void _draw_invisible_nodes_positions(Node *p_node, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D());
|
||||
void _draw_locks_and_groups(Node *p_node, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D());
|
||||
void _draw_hover();
|
||||
void _draw_transform_message();
|
||||
void _draw_message();
|
||||
|
||||
void _draw_viewport();
|
||||
|
||||
|
@ -544,6 +544,8 @@ public:
|
|||
SNAP_DEFAULT = SNAP_GRID | SNAP_GUIDES | SNAP_PIXEL,
|
||||
};
|
||||
|
||||
String message;
|
||||
|
||||
Point2 snap_point(Point2 p_target, unsigned int p_modes = SNAP_DEFAULT, unsigned int p_forced_modes = 0, const CanvasItem *p_self_canvas_item = nullptr, const List<CanvasItem *> &p_other_nodes_exceptions = List<CanvasItem *>());
|
||||
real_t snap_angle(real_t p_target, real_t p_start = 0) const;
|
||||
|
||||
|
|
Loading…
Reference in a new issue