2022-09-19 23:10:57 +02:00
|
|
|
tool
|
|
|
|
extends Control
|
|
|
|
|
|
|
|
export var table_header_scene : PackedScene
|
|
|
|
|
2022-09-21 22:09:50 +02:00
|
|
|
export(Array, Script) var cell_editor_classes := []
|
|
|
|
|
2022-09-19 23:10:57 +02:00
|
|
|
export var path_folder_path := NodePath("")
|
|
|
|
export var path_recent_paths := NodePath("")
|
|
|
|
export var path_table_root := NodePath("")
|
2022-09-22 00:55:12 +02:00
|
|
|
export var path_property_editors := NodePath("")
|
2022-09-19 23:10:57 +02:00
|
|
|
|
|
|
|
var editor_interface : EditorInterface
|
|
|
|
var editor_plugin : EditorPlugin
|
|
|
|
|
|
|
|
var current_path := ""
|
|
|
|
var recent_paths := []
|
|
|
|
var save_data_path : String = get_script().resource_path.get_base_dir() + "/saved_state.json"
|
|
|
|
var sorting_by := ""
|
|
|
|
var sorting_reverse := false
|
2022-09-21 22:09:50 +02:00
|
|
|
var is_undo_redoing := false
|
2022-09-21 23:06:07 +02:00
|
|
|
var undo_redo_version := 0
|
2022-09-21 22:09:50 +02:00
|
|
|
|
|
|
|
var all_cell_editors := []
|
2022-09-19 23:10:57 +02:00
|
|
|
|
|
|
|
var columns := []
|
|
|
|
var column_types := []
|
|
|
|
var column_hints := []
|
2022-09-21 22:09:50 +02:00
|
|
|
var column_editors := []
|
2022-09-19 23:10:57 +02:00
|
|
|
var rows := []
|
|
|
|
var remembered_paths := {}
|
|
|
|
|
|
|
|
var edited_cells := []
|
|
|
|
var edit_cursor_positions := []
|
2022-09-22 16:48:28 +02:00
|
|
|
var inspector_resource : Resource
|
2022-09-19 23:10:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
get_node(path_recent_paths).clear()
|
2022-09-21 22:09:50 +02:00
|
|
|
editor_plugin.get_undo_redo().connect("version_changed", self, "_on_undo_redo_version_changed")
|
2022-09-19 23:10:57 +02:00
|
|
|
editor_interface.get_resource_filesystem()\
|
|
|
|
.connect("filesystem_changed", self, "_on_filesystem_changed")
|
2022-09-22 16:48:28 +02:00
|
|
|
editor_interface.get_inspector()\
|
|
|
|
.connect("property_edited", self, "_on_inspector_property_edited")
|
2022-09-19 23:10:57 +02:00
|
|
|
|
2022-09-21 22:09:50 +02:00
|
|
|
# Load saved recent paths
|
2022-09-19 23:10:57 +02:00
|
|
|
var file := File.new()
|
|
|
|
if file.file_exists(save_data_path):
|
|
|
|
file.open(save_data_path, File.READ)
|
|
|
|
|
|
|
|
var as_text = file.get_as_text()
|
|
|
|
var as_var = str2var(as_text)
|
|
|
|
for x in as_var["recent_paths"]:
|
|
|
|
add_path_to_recent(x, true)
|
|
|
|
|
2022-09-21 22:09:50 +02:00
|
|
|
# Load cell editors and instantiate them
|
|
|
|
for x in cell_editor_classes:
|
|
|
|
all_cell_editors.append(x.new())
|
|
|
|
|
|
|
|
display_folder(recent_paths[0])
|
|
|
|
|
|
|
|
|
|
|
|
func _on_undo_redo_version_changed():
|
|
|
|
is_undo_redoing = true
|
2022-09-19 23:10:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
func _on_filesystem_changed():
|
|
|
|
var path = editor_interface.get_resource_filesystem().get_filesystem_path(current_path)
|
|
|
|
if !path: return
|
|
|
|
if path.get_file_count() != rows.size():
|
2022-09-21 04:32:40 +02:00
|
|
|
display_folder(current_path, sorting_by, sorting_reverse, true)
|
2022-09-19 23:10:57 +02:00
|
|
|
|
|
|
|
else:
|
|
|
|
for k in remembered_paths:
|
|
|
|
if remembered_paths[k].resource_path != k:
|
2022-09-22 20:00:21 +02:00
|
|
|
var res = remembered_paths[k]
|
|
|
|
remembered_paths.erase(k)
|
|
|
|
remembered_paths[res.resource_path] = res
|
2022-09-21 04:32:40 +02:00
|
|
|
display_folder(current_path, sorting_by, sorting_reverse, true)
|
2022-09-19 23:10:57 +02:00
|
|
|
break
|
|
|
|
|
|
|
|
|
2022-09-21 04:32:40 +02:00
|
|
|
func display_folder(folderpath : String, sort_by : String = "", sort_reverse : bool = false, force_rebuild : bool = false):
|
2022-09-19 23:10:57 +02:00
|
|
|
if folderpath == "": return # Root folder resources tend to have MANY properties.
|
|
|
|
if !folderpath.ends_with("/"):
|
|
|
|
folderpath += "/"
|
2022-09-21 22:09:50 +02:00
|
|
|
|
|
|
|
_load_resources_from_folder(folderpath, sort_by, sort_reverse)
|
|
|
|
if columns.size() == 0: return
|
|
|
|
|
|
|
|
get_node(path_folder_path).text = folderpath
|
2022-09-22 16:48:28 +02:00
|
|
|
_create_table(force_rebuild or current_path != folderpath)
|
2022-09-21 22:09:50 +02:00
|
|
|
current_path = folderpath
|
|
|
|
|
|
|
|
|
|
|
|
func _load_resources_from_folder(folderpath : String, sort_by : String, sort_reverse : bool):
|
2022-09-19 23:10:57 +02:00
|
|
|
var dir := Directory.new()
|
|
|
|
dir.open(folderpath)
|
|
|
|
dir.list_dir_begin()
|
|
|
|
|
|
|
|
rows.clear()
|
|
|
|
remembered_paths.clear()
|
|
|
|
var cur_dir_script : Script = null
|
|
|
|
|
|
|
|
var filepath = dir.get_next()
|
|
|
|
var res : Resource
|
|
|
|
|
|
|
|
while filepath != "":
|
|
|
|
if filepath.ends_with(".tres"):
|
|
|
|
filepath = folderpath + filepath
|
|
|
|
res = load(filepath)
|
|
|
|
if !is_instance_valid(cur_dir_script):
|
|
|
|
columns.clear()
|
|
|
|
column_types.clear()
|
|
|
|
column_hints.clear()
|
2022-09-21 22:09:50 +02:00
|
|
|
column_editors.clear()
|
2022-09-19 23:10:57 +02:00
|
|
|
for x in res.get_property_list():
|
|
|
|
if x["usage"] & PROPERTY_USAGE_EDITOR != 0 and x["name"] != "script":
|
|
|
|
columns.append(x["name"])
|
|
|
|
column_types.append(x["type"])
|
|
|
|
column_hints.append(x["hint"])
|
2022-09-21 22:09:50 +02:00
|
|
|
for y in all_cell_editors:
|
2022-09-21 23:06:07 +02:00
|
|
|
if y.can_edit_value(res.get(x["name"]), x["type"], x["hint"]):
|
2022-09-21 22:09:50 +02:00
|
|
|
column_editors.append(y)
|
|
|
|
break
|
2022-09-21 23:06:07 +02:00
|
|
|
|
2022-09-19 23:10:57 +02:00
|
|
|
cur_dir_script = res.get_script()
|
|
|
|
if !(sort_by in res):
|
|
|
|
sort_by = "resource_path"
|
|
|
|
|
|
|
|
if res.get_script() == cur_dir_script:
|
|
|
|
_insert_row_sorted(res, rows, sort_by, sort_reverse)
|
|
|
|
remembered_paths[res.resource_path] = res
|
|
|
|
|
|
|
|
filepath = dir.get_next()
|
|
|
|
|
|
|
|
|
|
|
|
func _insert_row_sorted(res : Resource, rows : Array, sort_by : String, sort_reverse : bool):
|
|
|
|
for i in rows.size():
|
2022-09-22 18:28:34 +02:00
|
|
|
if sort_reverse == _compare_values(res.get(sort_by), rows[i].get(sort_by)):
|
2022-09-19 23:10:57 +02:00
|
|
|
rows.insert(i, res)
|
|
|
|
return
|
|
|
|
|
|
|
|
rows.append(res)
|
|
|
|
|
|
|
|
|
2022-09-22 18:28:34 +02:00
|
|
|
func _compare_values(a, b) -> bool:
|
|
|
|
if a == null or b == null: return b == null
|
|
|
|
if a is Color:
|
|
|
|
return a.h > b.h if a.h != b.h else a.v > b.v
|
|
|
|
|
|
|
|
if a is Resource:
|
|
|
|
return a.resource_path > b.resource_path
|
|
|
|
|
|
|
|
return a > b
|
|
|
|
|
|
|
|
|
2022-09-19 23:10:57 +02:00
|
|
|
func _set_sorting(sort_by):
|
|
|
|
var sort_reverse : bool = !(sorting_by != sort_by or sorting_reverse)
|
|
|
|
sorting_reverse = sort_reverse
|
|
|
|
display_folder(current_path, sort_by, sort_reverse)
|
|
|
|
sorting_by = sort_by
|
|
|
|
|
|
|
|
|
2022-09-22 16:48:28 +02:00
|
|
|
func _create_table(columns_changed : bool):
|
|
|
|
var root_node = get_node(path_table_root)
|
2022-09-22 14:53:03 +02:00
|
|
|
deselect_all_cells()
|
2022-09-19 23:10:57 +02:00
|
|
|
edited_cells = []
|
|
|
|
edit_cursor_positions = []
|
|
|
|
var new_node : Control
|
|
|
|
if columns_changed:
|
|
|
|
root_node.columns = columns.size()
|
|
|
|
for x in root_node.get_children():
|
|
|
|
x.queue_free()
|
|
|
|
|
|
|
|
for x in columns:
|
|
|
|
new_node = table_header_scene.instance()
|
|
|
|
root_node.add_child(new_node)
|
|
|
|
new_node.get_node("Button").text = x
|
|
|
|
new_node.get_node("Button").connect("pressed", self, "_set_sorting", [x])
|
|
|
|
|
|
|
|
var to_free = root_node.get_child_count() - (rows.size() + 1) * columns.size()
|
|
|
|
while to_free > 0:
|
|
|
|
root_node.get_child(columns.size()).free()
|
|
|
|
to_free -= 1
|
2022-09-21 23:06:07 +02:00
|
|
|
|
2022-09-19 23:10:57 +02:00
|
|
|
for i in rows.size():
|
2022-09-22 16:48:28 +02:00
|
|
|
_update_row(i)
|
2022-09-19 23:10:57 +02:00
|
|
|
|
|
|
|
|
2022-09-22 16:48:28 +02:00
|
|
|
func _update_row(row_index : int):
|
|
|
|
var root_node = get_node(path_table_root)
|
|
|
|
var current_node : Control
|
|
|
|
var next_color := Color.white
|
|
|
|
for i in columns.size():
|
|
|
|
if root_node.get_child_count() <= (row_index + 1) * columns.size() + i:
|
2022-09-22 18:18:09 +02:00
|
|
|
current_node = column_editors[i].create_cell(self)
|
2022-09-22 16:48:28 +02:00
|
|
|
current_node.connect("gui_input", self, "_on_cell_gui_input", [current_node])
|
|
|
|
root_node.add_child(current_node)
|
|
|
|
|
|
|
|
else:
|
|
|
|
current_node = root_node.get_child((row_index + 1) * columns.size() + i)
|
|
|
|
current_node.hint_tooltip = columns[i] + "\nOf " + rows[row_index].resource_path.get_file()
|
2022-09-19 23:10:57 +02:00
|
|
|
|
2022-09-22 16:48:28 +02:00
|
|
|
column_editors[i].set_value(current_node, rows[row_index].get(columns[i]))
|
|
|
|
if columns[i] == "resource_path":
|
|
|
|
column_editors[i].set_value(current_node, current_node.text.get_file())
|
2022-09-21 23:06:07 +02:00
|
|
|
|
2022-09-22 16:48:28 +02:00
|
|
|
if column_types[i] == TYPE_COLOR:
|
|
|
|
next_color = rows[row_index].get(columns[i])
|
|
|
|
|
|
|
|
column_editors[i].set_color(current_node, next_color)
|
2022-09-21 23:06:07 +02:00
|
|
|
|
|
|
|
|
2022-09-19 23:10:57 +02:00
|
|
|
func add_path_to_recent(path : String, is_loading : bool = false):
|
|
|
|
if path in recent_paths: return
|
|
|
|
|
|
|
|
var node_recent := get_node(path_recent_paths)
|
|
|
|
var idx_in_array := recent_paths.find(path)
|
|
|
|
if idx_in_array != -1:
|
|
|
|
node_recent.remove_item(idx_in_array)
|
|
|
|
recent_paths.remove(idx_in_array)
|
|
|
|
|
2022-09-21 04:32:40 +02:00
|
|
|
recent_paths.append(path)
|
|
|
|
node_recent.add_item(path)
|
2022-09-19 23:10:57 +02:00
|
|
|
node_recent.select(node_recent.get_item_count() - 1)
|
|
|
|
|
|
|
|
if !is_loading:
|
|
|
|
save_data()
|
|
|
|
|
|
|
|
|
|
|
|
func remove_selected_path_from_recent():
|
|
|
|
if get_node(path_recent_paths).get_item_count() == 0:
|
|
|
|
return
|
|
|
|
|
|
|
|
var idx_in_array = get_node(path_recent_paths).selected
|
|
|
|
recent_paths.remove(idx_in_array)
|
|
|
|
get_node(path_recent_paths).remove_item(idx_in_array)
|
|
|
|
|
|
|
|
if get_node(path_recent_paths).get_item_count() != 0:
|
|
|
|
get_node(path_recent_paths).select(0)
|
|
|
|
display_folder(recent_paths[0])
|
|
|
|
save_data()
|
|
|
|
|
|
|
|
|
|
|
|
func save_data():
|
|
|
|
var file = File.new()
|
|
|
|
file.open(save_data_path, File.WRITE)
|
|
|
|
file.store_string(var2str(
|
|
|
|
{
|
|
|
|
"recent_paths" : recent_paths,
|
|
|
|
}
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
func _on_Path_text_entered(new_text : String):
|
|
|
|
current_path = new_text
|
|
|
|
|
|
|
|
add_path_to_recent(new_text)
|
2022-09-21 04:32:40 +02:00
|
|
|
display_folder(new_text, "", false, true)
|
2022-09-19 23:10:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
func _on_RecentPaths_item_selected(index : int):
|
|
|
|
current_path = recent_paths[index]
|
|
|
|
get_node(path_folder_path).text = recent_paths[index]
|
|
|
|
display_folder(current_path)
|
|
|
|
|
|
|
|
|
|
|
|
func _on_FileDialog_dir_selected(dir : String):
|
|
|
|
get_node(path_folder_path).text = dir
|
|
|
|
add_path_to_recent(dir)
|
|
|
|
display_folder(dir)
|
|
|
|
|
|
|
|
|
|
|
|
func deselect_all_cells():
|
|
|
|
for x in edited_cells:
|
2022-09-21 22:09:50 +02:00
|
|
|
column_editors[_get_cell_column(x)].set_selected(x, false)
|
2022-09-19 23:10:57 +02:00
|
|
|
|
2022-09-21 22:09:50 +02:00
|
|
|
edited_cells.clear()
|
|
|
|
edit_cursor_positions.clear()
|
2022-09-19 23:10:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
func deselect_cell(cell : Control):
|
|
|
|
var idx := edited_cells.find(cell)
|
|
|
|
if idx == -1: return
|
|
|
|
|
2022-09-21 22:09:50 +02:00
|
|
|
column_editors[_get_cell_column(cell)].set_selected(cell, false)
|
2022-09-19 23:10:57 +02:00
|
|
|
edited_cells.remove(idx)
|
|
|
|
edit_cursor_positions.remove(idx)
|
|
|
|
|
|
|
|
|
|
|
|
func select_cell(cell : Control):
|
2022-09-21 22:09:50 +02:00
|
|
|
var column_index := _get_cell_column(cell)
|
2022-09-19 23:10:57 +02:00
|
|
|
if _can_select_cell(cell):
|
2022-09-22 21:27:09 +02:00
|
|
|
_add_cell_to_selection(cell)
|
2022-09-22 20:00:21 +02:00
|
|
|
_try_open_docks(cell)
|
2022-09-22 16:48:28 +02:00
|
|
|
inspector_resource = rows[_get_cell_row(cell)].duplicate()
|
|
|
|
editor_plugin.get_editor_interface().edit_resource(inspector_resource)
|
2022-09-19 23:10:57 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
if column_index != _get_cell_column(edited_cells[edited_cells.size() - 1]):
|
|
|
|
return
|
|
|
|
|
2022-09-22 16:48:28 +02:00
|
|
|
var row_start = _get_cell_row(edited_cells[edited_cells.size() - 1]) + 1
|
|
|
|
var row_end := _get_cell_row(cell) + 1
|
2022-09-22 14:53:03 +02:00
|
|
|
var edge_shift = -1 if row_start > row_end else 1
|
|
|
|
row_start += edge_shift
|
|
|
|
row_end += edge_shift
|
2022-09-19 23:10:57 +02:00
|
|
|
var table_root := get_node(path_table_root)
|
|
|
|
|
2022-09-22 14:53:03 +02:00
|
|
|
for i in range(row_start, row_end, edge_shift):
|
2022-09-19 23:10:57 +02:00
|
|
|
var cur_cell := table_root.get_child(i * columns.size() + column_index)
|
2022-09-22 00:55:12 +02:00
|
|
|
if !cur_cell.visible:
|
|
|
|
# When search is active, some cells will be hidden.
|
|
|
|
continue
|
|
|
|
|
2022-09-21 22:09:50 +02:00
|
|
|
column_editors[column_index].set_selected(cur_cell, true)
|
2022-09-19 23:10:57 +02:00
|
|
|
edited_cells.append(cur_cell)
|
2022-09-21 22:09:50 +02:00
|
|
|
edit_cursor_positions.append(column_editors[column_index].get_text_length(cur_cell))
|
2022-09-19 23:10:57 +02:00
|
|
|
|
|
|
|
|
2022-09-22 21:27:09 +02:00
|
|
|
func _add_cell_to_selection(cell : Control):
|
|
|
|
column_editors[_get_cell_column(cell)].set_selected(cell, true)
|
|
|
|
edited_cells.append(cell)
|
|
|
|
edit_cursor_positions.append(column_editors[_get_cell_column(cell)].get_text_length(cell))
|
|
|
|
|
|
|
|
|
2022-09-22 20:00:21 +02:00
|
|
|
func _try_open_docks(cell : Control):
|
|
|
|
var column_index = _get_cell_column(cell)
|
|
|
|
for x in get_node(path_property_editors).get_children():
|
|
|
|
x.visible = x.try_edit_value(
|
|
|
|
column_editors[column_index].get_value(cell),
|
|
|
|
column_types[column_index],
|
|
|
|
column_hints[column_index]
|
|
|
|
)
|
|
|
|
x.get_node(x.path_property_name).text = columns[column_index]
|
|
|
|
|
|
|
|
|
2022-09-22 16:48:28 +02:00
|
|
|
func set_edited_cells_values(new_cell_values : Array, update_whole_row : bool = false):
|
2022-09-22 14:53:03 +02:00
|
|
|
var column = _get_cell_column(edited_cells[0])
|
|
|
|
var edited_cells_resources = _get_edited_cells_resources()
|
|
|
|
|
|
|
|
editor_plugin.undo_redo.create_action("Set Cell Value Externally")
|
|
|
|
editor_plugin.undo_redo.add_undo_method(
|
|
|
|
self,
|
|
|
|
"_update_resources",
|
|
|
|
edited_cells_resources.duplicate(),
|
|
|
|
edited_cells.duplicate(),
|
|
|
|
column,
|
|
|
|
get_edited_cells_values()
|
|
|
|
)
|
|
|
|
for i in new_cell_values.size():
|
|
|
|
column_editors[column].set_value(edited_cells[i], new_cell_values[i])
|
2022-09-22 16:48:28 +02:00
|
|
|
if update_whole_row:
|
|
|
|
_update_row(_get_cell_row(edited_cells[i]) + 1)
|
2022-09-22 14:53:03 +02:00
|
|
|
|
|
|
|
editor_plugin.undo_redo.add_do_method(
|
|
|
|
self,
|
|
|
|
"_update_resources",
|
|
|
|
edited_cells_resources.duplicate(),
|
|
|
|
edited_cells.duplicate(),
|
|
|
|
column,
|
|
|
|
get_edited_cells_values()
|
|
|
|
)
|
|
|
|
editor_plugin.undo_redo.commit_action()
|
|
|
|
editor_interface.get_resource_filesystem().scan()
|
|
|
|
undo_redo_version = editor_plugin.undo_redo.get_version()
|
|
|
|
|
|
|
|
|
|
|
|
func get_edited_cells_values() -> Array:
|
|
|
|
var arr := edited_cells.duplicate()
|
|
|
|
var cell_editor = column_editors[_get_cell_column(edited_cells[0])]
|
|
|
|
for i in arr.size():
|
|
|
|
arr[i] = cell_editor.get_value(arr[i])
|
|
|
|
|
|
|
|
return arr
|
|
|
|
|
|
|
|
|
2022-09-19 23:10:57 +02:00
|
|
|
func _can_select_cell(cell : Control) -> bool:
|
|
|
|
if edited_cells.size() == 0:
|
|
|
|
return true
|
|
|
|
|
|
|
|
if !Input.is_key_pressed(KEY_CONTROL):
|
|
|
|
return false
|
|
|
|
|
|
|
|
if (
|
|
|
|
_get_cell_column(cell)
|
|
|
|
!= _get_cell_column(edited_cells[0])
|
|
|
|
):
|
|
|
|
return false
|
|
|
|
|
|
|
|
return !cell in edited_cells
|
|
|
|
|
|
|
|
|
|
|
|
func _get_cell_column(cell) -> int:
|
|
|
|
return cell.get_position_in_parent() % columns.size()
|
|
|
|
|
|
|
|
|
|
|
|
func _get_cell_row(cell) -> int:
|
2022-09-22 16:48:28 +02:00
|
|
|
return cell.get_position_in_parent() / columns.size() - 1
|
2022-09-19 23:10:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
func _on_cell_gui_input(event : InputEvent, cell : Control):
|
|
|
|
if event is InputEventMouseButton:
|
2022-09-22 00:55:12 +02:00
|
|
|
if event.button_index != BUTTON_LEFT:
|
|
|
|
return
|
|
|
|
|
2022-09-19 23:10:57 +02:00
|
|
|
grab_focus()
|
|
|
|
if event.pressed:
|
|
|
|
if cell in edited_cells:
|
|
|
|
if !Input.is_key_pressed(KEY_CONTROL):
|
|
|
|
deselect_cell(cell)
|
|
|
|
|
|
|
|
else:
|
|
|
|
deselect_all_cells()
|
|
|
|
select_cell(cell)
|
|
|
|
|
|
|
|
else:
|
|
|
|
if !(Input.is_key_pressed(KEY_SHIFT) or Input.is_key_pressed(KEY_CONTROL)):
|
|
|
|
deselect_all_cells()
|
|
|
|
|
|
|
|
select_cell(cell)
|
|
|
|
|
|
|
|
|
|
|
|
func _gui_input(event : InputEvent):
|
|
|
|
if event is InputEventMouseButton:
|
2022-09-22 14:53:03 +02:00
|
|
|
if event.button_index != BUTTON_LEFT:
|
|
|
|
return
|
|
|
|
|
2022-09-19 23:10:57 +02:00
|
|
|
grab_focus()
|
|
|
|
if !event.pressed:
|
|
|
|
deselect_all_cells()
|
|
|
|
|
|
|
|
|
|
|
|
func _input(event : InputEvent):
|
2022-09-22 14:53:03 +02:00
|
|
|
if !has_focus() or edited_cells.size() == 0:
|
2022-09-19 23:10:57 +02:00
|
|
|
return
|
2022-09-22 14:53:03 +02:00
|
|
|
|
|
|
|
if !event is InputEventKey or !event.pressed:
|
2022-09-19 23:10:57 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
if column_types[_get_cell_column(edited_cells[0])] == TYPE_OBJECT:
|
|
|
|
return
|
|
|
|
|
2022-09-22 00:55:12 +02:00
|
|
|
if event.scancode == KEY_CONTROL or event.scancode == KEY_SHIFT:
|
2022-09-19 23:10:57 +02:00
|
|
|
# Modifier keys do not get processed.
|
|
|
|
return
|
|
|
|
|
|
|
|
var edited_cells_resources = _get_edited_cells_resources()
|
|
|
|
|
|
|
|
# Ctrl + Z (before, and instead of, committing the action!)
|
|
|
|
if Input.is_key_pressed(KEY_CONTROL) and event.scancode == KEY_Z:
|
|
|
|
if Input.is_key_pressed(KEY_SHIFT):
|
|
|
|
editor_plugin.undo_redo.redo()
|
|
|
|
# Ctrl + z
|
|
|
|
else:
|
|
|
|
editor_plugin.undo_redo.undo()
|
|
|
|
|
|
|
|
return
|
2022-09-21 22:09:50 +02:00
|
|
|
|
|
|
|
# This shortcut is used by Godot as well.
|
|
|
|
if Input.is_key_pressed(KEY_CONTROL) and event.scancode == KEY_Y:
|
2022-09-21 23:06:07 +02:00
|
|
|
editor_plugin.undo_redo.redo()
|
|
|
|
return
|
2022-09-22 14:53:03 +02:00
|
|
|
|
2022-09-19 23:10:57 +02:00
|
|
|
editor_plugin.undo_redo.create_action("Set Cell Value")
|
|
|
|
editor_plugin.undo_redo.add_undo_method(
|
|
|
|
self,
|
|
|
|
"_update_resources",
|
|
|
|
edited_cells_resources.duplicate(),
|
|
|
|
edited_cells.duplicate(),
|
2022-09-21 23:06:07 +02:00
|
|
|
_get_cell_column(edited_cells[0]),
|
2022-09-22 14:53:03 +02:00
|
|
|
get_edited_cells_values()
|
2022-09-19 23:10:57 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
_key_specific_action(event)
|
|
|
|
grab_focus()
|
|
|
|
|
|
|
|
editor_plugin.undo_redo.add_do_method(
|
|
|
|
self,
|
|
|
|
"_update_resources",
|
|
|
|
edited_cells_resources.duplicate(),
|
|
|
|
edited_cells.duplicate(),
|
2022-09-21 23:06:07 +02:00
|
|
|
_get_cell_column(edited_cells[0]),
|
2022-09-22 14:53:03 +02:00
|
|
|
get_edited_cells_values()
|
2022-09-19 23:10:57 +02:00
|
|
|
)
|
|
|
|
editor_plugin.undo_redo.commit_action()
|
|
|
|
editor_interface.get_resource_filesystem().scan()
|
2022-09-21 23:06:07 +02:00
|
|
|
undo_redo_version = editor_plugin.undo_redo.get_version()
|
2022-09-19 23:10:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
func _key_specific_action(event : InputEvent):
|
2022-09-21 22:09:50 +02:00
|
|
|
var column = _get_cell_column(edited_cells[0])
|
2022-09-19 23:10:57 +02:00
|
|
|
var ctrl_pressed := Input.is_key_pressed(KEY_CONTROL)
|
|
|
|
if ctrl_pressed:
|
|
|
|
editor_plugin.hide_bottom_panel()
|
|
|
|
|
|
|
|
# ERASING
|
|
|
|
if event.scancode == KEY_BACKSPACE:
|
2022-09-21 22:09:50 +02:00
|
|
|
TextEditingUtils.multi_erase_left(edited_cells, edit_cursor_positions, column_editors[column], self)
|
2022-09-19 23:10:57 +02:00
|
|
|
|
|
|
|
if event.scancode == KEY_DELETE:
|
2022-09-21 22:09:50 +02:00
|
|
|
TextEditingUtils.multi_erase_right(edited_cells, edit_cursor_positions, column_editors[column], self)
|
2022-09-19 23:10:57 +02:00
|
|
|
get_tree().set_input_as_handled() # Because this is one dangerous action.
|
|
|
|
|
|
|
|
# CURSOR MOVEMENT
|
|
|
|
elif event.scancode == KEY_LEFT:
|
2022-09-21 22:09:50 +02:00
|
|
|
TextEditingUtils.multi_move_left(edited_cells, edit_cursor_positions, column_editors[column])
|
2022-09-19 23:10:57 +02:00
|
|
|
|
|
|
|
elif event.scancode == KEY_RIGHT:
|
2022-09-21 22:09:50 +02:00
|
|
|
TextEditingUtils.multi_move_right(edited_cells, edit_cursor_positions, column_editors[column])
|
2022-09-19 23:10:57 +02:00
|
|
|
|
|
|
|
elif event.scancode == KEY_HOME:
|
|
|
|
for i in edit_cursor_positions.size():
|
|
|
|
edit_cursor_positions[i] = 0
|
|
|
|
|
|
|
|
elif event.scancode == KEY_END:
|
|
|
|
for i in edit_cursor_positions.size():
|
2022-09-21 22:09:50 +02:00
|
|
|
edit_cursor_positions[i] = column_editors[column].get_text_length(edited_cells[i])
|
2022-09-19 23:10:57 +02:00
|
|
|
|
|
|
|
# BETWEEN-CELL NAVIGATION
|
|
|
|
elif event.scancode == KEY_UP:
|
|
|
|
_move_selection_on_grid(0, (-1 if !ctrl_pressed else -10))
|
|
|
|
|
|
|
|
elif event.scancode == KEY_DOWN:
|
|
|
|
_move_selection_on_grid(0, (1 if !ctrl_pressed else 10))
|
|
|
|
|
|
|
|
elif Input.is_key_pressed(KEY_SHIFT) and event.scancode == KEY_TAB:
|
|
|
|
_move_selection_on_grid((-1 if !ctrl_pressed else -10), 0)
|
|
|
|
get_tree().set_input_as_handled()
|
|
|
|
|
|
|
|
elif event.scancode == KEY_TAB:
|
|
|
|
_move_selection_on_grid((1 if !ctrl_pressed else 10), 0)
|
|
|
|
get_tree().set_input_as_handled()
|
|
|
|
|
|
|
|
# Ctrl + C (so you can edit in a proper text editor instead of this wacky nonsense)
|
|
|
|
elif ctrl_pressed and event.scancode == KEY_C:
|
|
|
|
TextEditingUtils.multi_copy(edited_cells)
|
|
|
|
|
|
|
|
# Ctrl + V
|
|
|
|
elif ctrl_pressed and event.scancode == KEY_V:
|
2022-09-21 22:09:50 +02:00
|
|
|
TextEditingUtils.multi_paste(edited_cells, edit_cursor_positions, column_editors[column], self)
|
2022-09-19 23:10:57 +02:00
|
|
|
|
|
|
|
# Line Skip
|
|
|
|
elif event.scancode == KEY_ENTER:
|
2022-09-21 22:09:50 +02:00
|
|
|
TextEditingUtils.multi_linefeed(edited_cells, edit_cursor_positions, column_editors[column], self)
|
2022-09-19 23:10:57 +02:00
|
|
|
|
|
|
|
# And finally, text typing.
|
|
|
|
elif event.unicode != 0 and event.unicode != 127:
|
2022-09-21 22:09:50 +02:00
|
|
|
TextEditingUtils.multi_input(char(event.unicode), edited_cells, edit_cursor_positions, column_editors[column], self)
|
2022-09-19 23:10:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
func _move_selection_on_grid(move_h : int, move_v : int):
|
|
|
|
select_cell(
|
|
|
|
get_node(path_table_root).get_child(
|
|
|
|
edited_cells[0].get_position_in_parent()
|
|
|
|
+ move_h + move_v * columns.size()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
deselect_cell(edited_cells[0])
|
|
|
|
|
|
|
|
|
|
|
|
func set_cell(cell, value):
|
2022-09-21 22:09:50 +02:00
|
|
|
var column = _get_cell_column(cell)
|
|
|
|
if columns[column] == "resource_path":
|
2022-09-19 23:10:57 +02:00
|
|
|
return
|
2022-09-21 22:09:50 +02:00
|
|
|
|
|
|
|
column_editors[column].set_value(cell, value)
|
2022-09-19 23:10:57 +02:00
|
|
|
|
|
|
|
|
2022-09-21 23:06:07 +02:00
|
|
|
func _update_resources(update_rows : Array, update_cells : Array, update_column : int, values : Array):
|
2022-09-19 23:10:57 +02:00
|
|
|
var cells := get_node(path_table_root).get_children()
|
|
|
|
for i in update_rows.size():
|
2022-09-21 23:06:07 +02:00
|
|
|
update_rows[i].set(columns[update_column], values[i])
|
2022-09-19 23:10:57 +02:00
|
|
|
ResourceSaver.save(update_rows[i].resource_path, update_rows[i])
|
2022-09-21 23:06:07 +02:00
|
|
|
if undo_redo_version > editor_plugin.undo_redo.get_version():
|
2022-09-22 16:48:28 +02:00
|
|
|
# Set cell values, but only when undoing/redoing (set_cell() normally fills these in)
|
2022-09-21 23:06:07 +02:00
|
|
|
column_editors[update_column].set_value(update_cells[i], values[i])
|
2022-09-19 23:10:57 +02:00
|
|
|
|
2022-09-22 17:14:56 +02:00
|
|
|
if column_types[update_column] == TYPE_COLOR:
|
|
|
|
for j in columns.size() - update_column:
|
|
|
|
if j != 0 and column_types[j + update_column] == TYPE_COLOR:
|
|
|
|
break
|
|
|
|
|
|
|
|
column_editors[j + update_column].set_color(
|
|
|
|
update_cells[i].get_parent().get_child(
|
|
|
|
(_get_cell_row(update_cells[i]) + 1) * columns.size() + update_column + j
|
|
|
|
),
|
|
|
|
values[i]
|
|
|
|
)
|
|
|
|
|
2022-09-19 23:10:57 +02:00
|
|
|
|
|
|
|
func _get_edited_cells_resources() -> Array:
|
|
|
|
var arr := edited_cells.duplicate()
|
|
|
|
for i in arr.size():
|
2022-09-22 16:48:28 +02:00
|
|
|
arr[i] = rows[_get_cell_row(edited_cells[i])]
|
2022-09-19 23:10:57 +02:00
|
|
|
|
|
|
|
return arr
|
|
|
|
|
|
|
|
|
|
|
|
func _on_SearchCond_text_entered(new_text : String):
|
|
|
|
var new_script := GDScript.new()
|
|
|
|
new_script.source_code = "static func can_show(res, index):\n\treturn " + new_text
|
|
|
|
new_script.reload()
|
|
|
|
|
|
|
|
var new_script_instance = new_script.new()
|
|
|
|
var table_elements = get_node(path_table_root).get_children()
|
|
|
|
|
|
|
|
for i in rows.size():
|
|
|
|
var row_visible = new_script_instance.can_show(rows[i], i)
|
|
|
|
for j in columns.size():
|
|
|
|
table_elements[(i + 1) * columns.size() + j].visible = row_visible
|
2022-09-22 16:48:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
func _on_inspector_property_edited(property : String):
|
|
|
|
if !visible: return
|
|
|
|
if inspector_resource == null: return
|
|
|
|
|
|
|
|
var value = inspector_resource.get(property)
|
2022-09-22 21:27:09 +02:00
|
|
|
var values = []
|
|
|
|
values.resize(edited_cells.size())
|
|
|
|
for i in edited_cells.size():
|
|
|
|
values[i] = value
|
|
|
|
|
|
|
|
var previously_edited = edited_cells
|
|
|
|
if columns[_get_cell_column(edited_cells[0])] != property:
|
|
|
|
previously_edited = previously_edited.duplicate()
|
|
|
|
var new_column := columns.find(property)
|
|
|
|
deselect_all_cells()
|
|
|
|
var index := 0
|
|
|
|
for i in previously_edited.size():
|
|
|
|
index = (_get_cell_row(previously_edited[i]) + 1) * columns.size() + new_column
|
|
|
|
_add_cell_to_selection(get_node(path_table_root).get_child(index))
|
2022-09-22 20:00:21 +02:00
|
|
|
|
2022-09-22 21:27:09 +02:00
|
|
|
set_edited_cells_values(values)
|
2022-09-22 20:00:21 +02:00
|
|
|
_try_open_docks(edited_cells[0])
|