1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-10 13:00:37 +00:00

Allow Sprite2D being dragged to change their region_rect

This commit is contained in:
Lazy-Rabbit-2001
2025-04-28 22:43:41 +08:00
parent 1b4ed4c038
commit 1410bca5ce
4 changed files with 92 additions and 10 deletions

View File

@@ -665,8 +665,38 @@ Sprite2DEditor::Sprite2DEditor() {
add_child(debug_uv_dialog);
}
void Sprite2DEditorPlugin::_editor_theme_changed() {
dragging_mode_hint->add_theme_color_override(SceneStringName(font_color), Color(0.6f, 0.6f, 0.6f, 1));
dragging_mode_hint->add_theme_color_override("font_shadow_color", Color(0.2f, 0.2f, 0.2f, 1));
dragging_mode_hint->add_theme_constant_override("shadow_outline_size", 1 * EDSCALE);
dragging_mode_hint->add_theme_constant_override("line_spacing", 0);
}
void Sprite2DEditorPlugin::_update_dragging_mode_hint(bool p_region_enabled) {
if (p_region_enabled) {
dragging_mode_hint->show();
} else {
dragging_mode_hint->hide();
}
}
void Sprite2DEditorPlugin::edit(Object *p_object) {
sprite_editor->edit(Object::cast_to<Sprite2D>(p_object));
Callable update_text = callable_mp(this, &Sprite2DEditorPlugin::_update_dragging_mode_hint);
StringName update_signal = SNAME("_editor_region_rect_enabled");
Sprite2D *spr = sprite_editor->node;
if (spr != nullptr && spr->is_connected(update_signal, update_text)) {
spr->disconnect(update_signal, update_text);
}
spr = Object::cast_to<Sprite2D>(p_object);
sprite_editor->edit(spr);
if (spr != nullptr) {
_update_dragging_mode_hint(spr->is_editor_region_rect_draggable());
if (!spr->is_connected(update_signal, update_text)) {
spr->connect(update_signal, update_text);
}
}
}
bool Sprite2DEditorPlugin::handles(Object *p_object) const {
@@ -678,14 +708,20 @@ void Sprite2DEditorPlugin::make_visible(bool p_visible) {
sprite_editor->options->show();
} else {
sprite_editor->options->hide();
dragging_mode_hint->hide();
sprite_editor->edit(nullptr);
}
}
Sprite2DEditorPlugin::Sprite2DEditorPlugin() {
sprite_editor = memnew(Sprite2DEditor);
sprite_editor->connect(SceneStringName(theme_changed), callable_mp(this, &Sprite2DEditorPlugin::_editor_theme_changed));
EditorNode::get_singleton()->get_gui_base()->add_child(sprite_editor);
make_visible(false);
dragging_mode_hint = memnew(Label);
dragging_mode_hint->set_text(TTRC("When dragging:\nHold Ctrl + left mouse button to change the region_rect and position.\nHold left mouse button to modify the scale of the sprite."));
CanvasItemEditor::get_singleton()->get_controls_container()->add_child(dragging_mode_hint);
make_visible(false);
//sprite_editor->options->hide();
}