Implemented undo redo support for world generator's DataList.

This commit is contained in:
Relintai 2022-01-21 23:57:37 +01:00
parent be14831b47
commit f3c9129171
2 changed files with 32 additions and 5 deletions

View File

@ -82,11 +82,15 @@ func get_all_contents_with_name(name : String) -> Array:
return arr
func duplicate_content_entry(entry : WorldGenBaseResource) -> void:
func duplicate_content_entry(entry : WorldGenBaseResource, add : bool = true) -> WorldGenBaseResource:
var de : WorldGenBaseResource = entry.duplicate(true)
de.resource_name += " (Duplicate)"
if add:
add_content(de)
return de
func setup_terra_library(library : TerramanLibrary, pseed : int) -> void:
_setup_terra_library(library, pseed)

View File

@ -6,6 +6,8 @@ export(int, "Continent,Zone,Sub Zone") var class_types : int = 0
var edited_resource : WorldGenBaseResource = null
var name_edited_resource : WorldGenBaseResource = null
var _ignore_changed_event : bool = false
var _plugin : EditorPlugin = null
var _undo_redo : UndoRedo = null
@ -59,7 +61,13 @@ func add_item(item_name : String = "") -> void:
e.resource_name = item_name
edited_resource.add_content(e)
#edited_resource.add_content(e)
#remove_content_entry
_undo_redo.create_action("WE: Created Entry")
_undo_redo.add_do_method(edited_resource, "add_content", e)
_undo_redo.add_undo_method(edited_resource, "remove_content_entry", e)
_undo_redo.commit_action()
func refresh() -> void:
clear()
@ -119,7 +127,12 @@ func delete_button_pressed() -> void:
if !item_resource:
return
edited_resource.remove_content_entry(item_resource)
#edited_resource.remove_content_entry(item_resource)
_undo_redo.create_action("WE: Created Entry")
_undo_redo.add_do_method(edited_resource, "remove_content_entry", item_resource)
_undo_redo.add_undo_method(edited_resource, "add_content", item_resource)
_undo_redo.commit_action()
func duplicate_button_pressed() -> void:
var item : TreeItem = get_selected()
@ -132,9 +145,19 @@ func duplicate_button_pressed() -> void:
if !item_resource:
return
edited_resource.duplicate_content_entry(item_resource)
#edited_resource.duplicate_content_entry(item_resource)
var de = edited_resource.duplicate_content_entry(item_resource, false)
_undo_redo.create_action("WE: Created Entry")
_undo_redo.add_do_method(edited_resource, "add_content", de)
_undo_redo.add_undo_method(edited_resource, "remove_content_entry", de)
_undo_redo.commit_action()
func on_resource_changed() -> void:
if _ignore_changed_event:
return
call_deferred("refresh")
func on_item_activated() -> void: