Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added progress bar when changing type on multiple nodes #31452

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions core/undo_redo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,18 @@ void UndoRedo::commit_action() {

void UndoRedo::_process_operation_list(List<Operation>::Element *E) {

int step = 0;

for (; E; E = E->next()) {

Operation &op = E->get();

Object *obj = ObjectDB::get_instance(op.object);

if (progress_callback) {
progress_callback(progress_callback_ud, obj, op.name, step++);
}

if (!obj) //may have been deleted and this is fine
continue;

Expand Down Expand Up @@ -409,6 +416,12 @@ void UndoRedo::set_property_notify_callback(PropertyNotifyCallback p_property_ca
prop_callback_ud = p_ud;
}

void UndoRedo::set_progress_notify_callback(ProgressNotifyCallback p_progress_callback, void *p_ud) {

progress_callback = p_progress_callback;
progress_callback_ud = p_ud;
}

UndoRedo::UndoRedo() {

committing = 0;
Expand All @@ -424,6 +437,9 @@ UndoRedo::UndoRedo() {
prop_callback_ud = NULL;
method_callback = NULL;
property_callback = NULL;

progress_callback_ud = NULL;
progress_callback = NULL;
}

UndoRedo::~UndoRedo() {
Expand Down
7 changes: 7 additions & 0 deletions core/undo_redo.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class UndoRedo : public Object {
typedef void (*MethodNotifyCallback)(void *p_ud, Object *p_base, const StringName &p_name, VARIANT_ARG_DECLARE);
typedef void (*PropertyNotifyCallback)(void *p_ud, Object *p_base, const StringName &p_property, const Variant &p_value);

typedef void (*ProgressNotifyCallback)(void *p_ud, Object *p_base, const StringName &p_name, int p_step);

private:
struct Operation {

Expand Down Expand Up @@ -91,10 +93,13 @@ class UndoRedo : public Object {
void *callback_ud;
void *method_callbck_ud;
void *prop_callback_ud;
void *progress_callback_ud;

MethodNotifyCallback method_callback;
PropertyNotifyCallback property_callback;

ProgressNotifyCallback progress_callback;

int committing;

protected:
Expand Down Expand Up @@ -128,6 +133,8 @@ class UndoRedo : public Object {
void set_method_notify_callback(MethodNotifyCallback p_method_callback, void *p_ud);
void set_property_notify_callback(PropertyNotifyCallback p_property_callback, void *p_ud);

void set_progress_notify_callback(ProgressNotifyCallback p_progress_callback, void *p_ud);

UndoRedo();
~UndoRedo();
};
Expand Down
20 changes: 20 additions & 0 deletions editor/scene_tree_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2006,7 +2006,19 @@ void SceneTreeDock::_create() {
ur->add_undo_reference(n);
}

int step_count = selection.size() * 2;
EditorProgress *progress = NULL;
if (step_count > 20) {
progress = new EditorProgress("process_replace", TTR("Process operations"), step_count);
ur->set_progress_notify_callback(_progress_callback, progress);
}

ur->commit_action();

if (progress) {
ur->set_progress_notify_callback(NULL, NULL);
delete progress;
}
} else if (current_option == TOOL_REPARENT_TO_NEW_NODE) {
List<Node *> selection = editor_selection->get_selected_node_list();
ERR_FAIL_COND(selection.size() <= 0);
Expand Down Expand Up @@ -2058,6 +2070,14 @@ void SceneTreeDock::_create() {
scene_tree->get_scene_tree()->call_deferred("grab_focus");
}

void SceneTreeDock::_progress_callback(void *p_ud, Object *p_object, const StringName &p_name, int p_step) {
if ((p_step % 20) == 0) {

EditorProgress *progress = (EditorProgress *)p_ud;
progress->step("", p_step, false);
}
}

void SceneTreeDock::replace_node(Node *p_node, Node *p_by_node, bool p_keep_properties, bool p_remove_old) {

Node *n = p_node;
Expand Down
2 changes: 2 additions & 0 deletions editor/scene_tree_dock.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ class SceneTreeDock : public VBoxContainer {

void _set_owners(Node *p_owner, const Array &p_nodes);

static void _progress_callback(void *p_ud, Object *p_object, const StringName &p_name, int p_step);

enum ReplaceOwnerMode {
MODE_BIDI,
MODE_DO,
Expand Down