mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-03 09:29:38 +01:00
Keep property values when extending script
(cherry picked from commit 44cf3c22acb140cc2f19f1062c0a4c0a931fd27b)
This commit is contained in:
parent
522c324760
commit
3b7b860b18
@ -3058,7 +3058,10 @@ void EditorPropertyResource::_resource_selected(const RES &p_resource, bool p_ed
|
||||
void EditorPropertyResource::_resource_changed(const RES &p_resource) {
|
||||
// Make visual script the correct type.
|
||||
Ref<Script> s = p_resource;
|
||||
bool is_script = false;
|
||||
if (get_edited_object() && s.is_valid()) {
|
||||
is_script = true;
|
||||
EditorNode::get_singleton()->get_inspector_dock()->store_script_properties(get_edited_object());
|
||||
s->call("set_instance_base_type", get_edited_object()->get_class());
|
||||
}
|
||||
|
||||
@ -3084,6 +3087,11 @@ void EditorPropertyResource::_resource_changed(const RES &p_resource) {
|
||||
emit_changed(get_edited_property(), p_resource);
|
||||
update_property();
|
||||
|
||||
if (is_script) {
|
||||
// Restore properties if script was changed.
|
||||
EditorNode::get_singleton()->get_inspector_dock()->apply_script_properties(get_edited_object());
|
||||
}
|
||||
|
||||
// Automatically suggest setting up the path for a ViewportTexture.
|
||||
if (vpt.is_valid() && vpt->get_viewport_path_in_scene().is_empty()) {
|
||||
if (!scene_tree) {
|
||||
|
@ -420,6 +420,9 @@ void InspectorDock::_bind_methods() {
|
||||
ClassDB::bind_method("_edit_forward", &InspectorDock::_edit_forward);
|
||||
ClassDB::bind_method("_edit_back", &InspectorDock::_edit_back);
|
||||
|
||||
ClassDB::bind_method("store_script_properties", &InspectorDock::store_script_properties);
|
||||
ClassDB::bind_method("apply_script_properties", &InspectorDock::apply_script_properties);
|
||||
|
||||
ADD_SIGNAL(MethodInfo("request_help"));
|
||||
}
|
||||
|
||||
@ -532,6 +535,32 @@ void InspectorDock::update_keying() {
|
||||
inspector->set_keying(valid);
|
||||
}
|
||||
|
||||
void InspectorDock::store_script_properties(Object *p_object) {
|
||||
ERR_FAIL_NULL(p_object);
|
||||
ScriptInstance *si = p_object->get_script_instance();
|
||||
if (!si) {
|
||||
return;
|
||||
}
|
||||
si->get_property_state(stored_properties);
|
||||
}
|
||||
|
||||
void InspectorDock::apply_script_properties(Object *p_object) {
|
||||
ERR_FAIL_NULL(p_object);
|
||||
ScriptInstance *si = p_object->get_script_instance();
|
||||
if (!si) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (List<Pair<StringName, Variant>>::Element *E = stored_properties.front(); E; E = E->next()) {
|
||||
const Pair<StringName, Variant> &p = E->get();
|
||||
Variant current;
|
||||
if (si->get(p.first, current) && current.get_type() == p.second.get_type()) {
|
||||
si->set(p.first, p.second);
|
||||
}
|
||||
}
|
||||
stored_properties.clear();
|
||||
}
|
||||
|
||||
InspectorDock::InspectorDock(EditorNode *p_editor, EditorData &p_editor_data) {
|
||||
set_name("Inspector");
|
||||
set_theme(p_editor->get_gui_base()->get_theme());
|
||||
|
@ -99,6 +99,7 @@ class InspectorDock : public VBoxContainer {
|
||||
Button *warning;
|
||||
AcceptDialog *warning_dialog;
|
||||
|
||||
List<Pair<StringName, Variant>> stored_properties;
|
||||
void _menu_option(int p_option);
|
||||
|
||||
void _new_resource();
|
||||
@ -139,6 +140,9 @@ public:
|
||||
Container *get_addon_area();
|
||||
EditorInspector *get_inspector() { return inspector; }
|
||||
|
||||
|
||||
void store_script_properties(Object *p_object);
|
||||
void apply_script_properties(Object *p_object);
|
||||
InspectorDock(EditorNode *p_editor, EditorData &p_editor_data);
|
||||
~InspectorDock();
|
||||
};
|
||||
|
@ -2029,16 +2029,24 @@ void SceneTreeDock::_script_created(Ref<Script> p_script) {
|
||||
return;
|
||||
}
|
||||
|
||||
editor_data->get_undo_redo().create_action(TTR("Attach Script"));
|
||||
InspectorDock *inspector_dock = EditorNode::get_singleton()->get_inspector_dock();
|
||||
UndoRedo &undo_redo = editor_data->get_undo_redo();
|
||||
|
||||
undo_redo.create_action(TTR("Attach Script"));
|
||||
for (List<Node *>::Element *E = selected.front(); E; E = E->next()) {
|
||||
Ref<Script> existing = E->get()->get_script();
|
||||
editor_data->get_undo_redo().add_do_method(E->get(), "set_script", p_script.get_ref_ptr());
|
||||
editor_data->get_undo_redo().add_undo_method(E->get(), "set_script", existing);
|
||||
editor_data->get_undo_redo().add_do_method(this, "_update_script_button");
|
||||
editor_data->get_undo_redo().add_undo_method(this, "_update_script_button");
|
||||
Node *node = E->get();
|
||||
Ref<Script> existing = node->get_script();
|
||||
undo_redo.add_do_method(inspector_dock, "store_script_properties", node);
|
||||
undo_redo.add_undo_method(inspector_dock, "store_script_properties", node);
|
||||
undo_redo.add_do_method(node, "set_script", p_script.get_ref_ptr());
|
||||
undo_redo.add_undo_method(node, "set_script", existing);
|
||||
undo_redo.add_do_method(inspector_dock, "apply_script_properties", node);
|
||||
undo_redo.add_undo_method(inspector_dock, "apply_script_properties", node);
|
||||
undo_redo.add_do_method(this, "_update_script_button");
|
||||
undo_redo.add_undo_method(this, "_update_script_button");
|
||||
}
|
||||
|
||||
editor_data->get_undo_redo().commit_action();
|
||||
undo_redo.commit_action();
|
||||
|
||||
_push_item(p_script.operator->());
|
||||
_update_script_button();
|
||||
@ -2682,12 +2690,19 @@ void SceneTreeDock::_script_dropped(String p_file, NodePath p_to) {
|
||||
ERR_FAIL_COND(!scr.is_valid());
|
||||
Node *n = get_node(p_to);
|
||||
if (n) {
|
||||
editor_data->get_undo_redo().create_action(TTR("Attach Script"));
|
||||
editor_data->get_undo_redo().add_do_method(n, "set_script", scr);
|
||||
editor_data->get_undo_redo().add_undo_method(n, "set_script", n->get_script());
|
||||
editor_data->get_undo_redo().add_do_method(this, "_update_script_button");
|
||||
editor_data->get_undo_redo().add_undo_method(this, "_update_script_button");
|
||||
editor_data->get_undo_redo().commit_action();
|
||||
InspectorDock *inspector_dock = EditorNode::get_singleton()->get_inspector_dock();
|
||||
UndoRedo &undo_redo = editor_data->get_undo_redo();
|
||||
|
||||
undo_redo.create_action(TTR("Attach Script"));
|
||||
undo_redo.add_do_method(inspector_dock, "store_script_properties", n);
|
||||
undo_redo.add_undo_method(inspector_dock, "store_script_properties", n);
|
||||
undo_redo.add_do_method(n, "set_script", scr);
|
||||
undo_redo.add_undo_method(n, "set_script", n->get_script());
|
||||
undo_redo.add_do_method(inspector_dock, "apply_script_properties", n);
|
||||
undo_redo.add_undo_method(inspector_dock, "apply_script_properties", n);
|
||||
undo_redo.add_do_method(this, "_update_script_button");
|
||||
undo_redo.add_undo_method(this, "_update_script_button");
|
||||
undo_redo.commit_action();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user