Implement custom cell editor types

This commit is contained in:
don-tnowe 2022-09-21 23:09:50 +03:00
parent 1f91293363
commit eac20fb2fb
11 changed files with 265 additions and 169 deletions

View File

@ -22,7 +22,7 @@ Possible inputs:
If clipboard contains as many lines as there are cells selected, each line is pasted into a separate cell.
Support of more data types coming eventually.
To add support of more datatypes, check out the `typed_cells` and `typed_editors` folders. `typed_cells` need to be added in the `editor_view` root's exported array, and `typed_editors` are placed there under the `%PropertyEditors` node.
#

View File

@ -1,13 +1,13 @@
tool
extends Control
export var grid_cell_scene : PackedScene
export var table_header_scene : PackedScene
export(Array, Script) var cell_editor_classes := []
export var path_folder_path := NodePath("")
export var path_recent_paths := NodePath("")
export var path_table_root := NodePath("")
export var editor_stylebox : StyleBox
var editor_interface : EditorInterface
var editor_plugin : EditorPlugin
@ -17,10 +17,14 @@ 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
var is_undo_redoing := false
var all_cell_editors := []
var columns := []
var column_types := []
var column_hints := []
var column_editors := []
var rows := []
var remembered_paths := {}
@ -30,9 +34,11 @@ var edit_cursor_positions := []
func _ready():
get_node(path_recent_paths).clear()
editor_plugin.get_undo_redo().connect("version_changed", self, "_on_undo_redo_version_changed")
editor_interface.get_resource_filesystem()\
.connect("filesystem_changed", self, "_on_filesystem_changed")
# Load saved recent paths
var file := File.new()
if file.file_exists(save_data_path):
file.open(save_data_path, File.READ)
@ -42,7 +48,15 @@ func _ready():
for x in as_var["recent_paths"]:
add_path_to_recent(x, true)
display_folder(recent_paths[0])
# 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
func _on_filesystem_changed():
@ -62,7 +76,16 @@ func display_folder(folderpath : String, sort_by : String = "", sort_reverse : b
if folderpath == "": return # Root folder resources tend to have MANY properties.
if !folderpath.ends_with("/"):
folderpath += "/"
_load_resources_from_folder(folderpath, sort_by, sort_reverse)
if columns.size() == 0: return
get_node(path_folder_path).text = folderpath
_create_table(get_node(path_table_root), force_rebuild || current_path != folderpath)
current_path = folderpath
func _load_resources_from_folder(folderpath : String, sort_by : String, sort_reverse : bool):
var dir := Directory.new()
dir.open(folderpath)
dir.list_dir_begin()
@ -82,11 +105,16 @@ func display_folder(folderpath : String, sort_by : String = "", sort_reverse : b
columns.clear()
column_types.clear()
column_hints.clear()
column_editors.clear()
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"])
for y in all_cell_editors:
if y.can_edit_value(res.get(x["name"]), x["hint"]):
column_editors.append(y)
break
cur_dir_script = res.get_script()
if !(sort_by in res):
@ -97,12 +125,6 @@ func display_folder(folderpath : String, sort_by : String = "", sort_reverse : b
remembered_paths[res.resource_path] = res
filepath = dir.get_next()
if columns.size() == 0: return
get_node(path_folder_path).text = folderpath
_create_table(get_node(path_table_root), force_rebuild || current_path != folderpath)
current_path = folderpath
func _insert_row_sorted(res : Resource, rows : Array, sort_by : String, sort_reverse : bool):
@ -144,7 +166,7 @@ func _create_table(root_node : Control, columns_changed : bool):
for i in rows.size():
for j in columns.size():
if root_node.get_child_count() <= (i + 1) * columns.size() + j:
new_node = grid_cell_scene.instance()
new_node = column_editors[j].create_cell()
new_node.connect("gui_input", self, "_on_cell_gui_input", [new_node])
root_node.add_child(new_node)
@ -152,9 +174,9 @@ func _create_table(root_node : Control, columns_changed : bool):
new_node = root_node.get_child((i + 1) * columns.size() + j)
new_node.hint_tooltip = columns[j] + "\nOf " + rows[i].resource_path.get_file()
new_node.text = TextEditingUtils.show_non_typing(str(rows[i].get(columns[j])))
column_editors[j].set_value(new_node, rows[i].get(columns[j]))
if columns[j] == "resource_path":
new_node.text = new_node.text.get_file()
column_editors[j].set_value(new_node, new_node.text.get_file())
func add_path_to_recent(path : String, is_loading : bool = false):
@ -219,29 +241,29 @@ func _on_FileDialog_dir_selected(dir : String):
func deselect_all_cells():
for x in edited_cells:
x.get_node("Selected").visible = false
column_editors[_get_cell_column(x)].set_selected(x, false)
edited_cells = []
edit_cursor_positions = []
edited_cells.clear()
edit_cursor_positions.clear()
func deselect_cell(cell : Control):
var idx := edited_cells.find(cell)
if idx == -1: return
cell.get_node("Selected").visible = false
column_editors[_get_cell_column(cell)].set_selected(cell, false)
edited_cells.remove(idx)
edit_cursor_positions.remove(idx)
func select_cell(cell : Control):
var column_index := _get_cell_column(cell)
if _can_select_cell(cell):
cell.get_node("Selected").visible = true
column_editors[column_index].set_selected(cell, true)
edited_cells.append(cell)
edit_cursor_positions.append(cell.text.length())
edit_cursor_positions.append(column_editors[column_index].get_text_length(cell))
return
var column_index := _get_cell_column(cell)
if column_index != _get_cell_column(edited_cells[edited_cells.size() - 1]):
return
@ -251,9 +273,9 @@ func select_cell(cell : Control):
for i in range(row_end, row_start, 1 if row_start > row_end else -1):
var cur_cell := table_root.get_child(i * columns.size() + column_index)
cur_cell.get_node("Selected").visible = true
column_editors[column_index].set_selected(cur_cell, true)
edited_cells.append(cur_cell)
edit_cursor_positions.append(cur_cell.text.length())
edit_cursor_positions.append(column_editors[column_index].get_text_length(cur_cell))
func _can_select_cell(cell : Control) -> bool:
@ -335,7 +357,11 @@ func _input(event : InputEvent):
editor_plugin.undo_redo.undo()
return
# This shortcut is used by Godot as well.
if Input.is_key_pressed(KEY_CONTROL) and event.scancode == KEY_Y:
editor_plugin.undo_redo.redo()
editor_plugin.undo_redo.create_action("Set Cell Value")
editor_plugin.undo_redo.add_undo_method(
self,
@ -361,26 +387,26 @@ func _input(event : InputEvent):
editor_interface.get_resource_filesystem().scan()
func _key_specific_action(event : InputEvent):
var column = _get_cell_column(edited_cells[0])
var ctrl_pressed := Input.is_key_pressed(KEY_CONTROL)
if ctrl_pressed:
editor_plugin.hide_bottom_panel()
# ERASING
if event.scancode == KEY_BACKSPACE:
TextEditingUtils.multi_erase_left(edited_cells, edit_cursor_positions, self)
TextEditingUtils.multi_erase_left(edited_cells, edit_cursor_positions, column_editors[column], self)
if event.scancode == KEY_DELETE:
TextEditingUtils.multi_erase_right(edited_cells, edit_cursor_positions, self)
TextEditingUtils.multi_erase_right(edited_cells, edit_cursor_positions, column_editors[column], self)
get_tree().set_input_as_handled() # Because this is one dangerous action.
# CURSOR MOVEMENT
elif event.scancode == KEY_LEFT:
TextEditingUtils.multi_move_left(edited_cells, edit_cursor_positions)
TextEditingUtils.multi_move_left(edited_cells, edit_cursor_positions, column_editors[column])
elif event.scancode == KEY_RIGHT:
TextEditingUtils.multi_move_right(edited_cells, edit_cursor_positions)
TextEditingUtils.multi_move_right(edited_cells, edit_cursor_positions, column_editors[column])
elif event.scancode == KEY_HOME:
for i in edit_cursor_positions.size():
@ -388,7 +414,7 @@ func _key_specific_action(event : InputEvent):
elif event.scancode == KEY_END:
for i in edit_cursor_positions.size():
edit_cursor_positions[i] = edited_cells[i].text.length()
edit_cursor_positions[i] = column_editors[column].get_text_length(edited_cells[i])
# BETWEEN-CELL NAVIGATION
elif event.scancode == KEY_UP:
@ -411,15 +437,15 @@ func _key_specific_action(event : InputEvent):
# Ctrl + V
elif ctrl_pressed and event.scancode == KEY_V:
TextEditingUtils.multi_paste(edited_cells, edit_cursor_positions, self)
TextEditingUtils.multi_paste(edited_cells, edit_cursor_positions, column_editors[column], self)
# Line Skip
elif event.scancode == KEY_ENTER:
TextEditingUtils.multi_linefeed(edited_cells, edit_cursor_positions, self)
TextEditingUtils.multi_linefeed(edited_cells, edit_cursor_positions, column_editors[column], self)
# And finally, text typing.
elif event.unicode != 0 and event.unicode != 127:
TextEditingUtils.multi_input(char(event.unicode), edited_cells, edit_cursor_positions, self)
TextEditingUtils.multi_input(char(event.unicode), edited_cells, edit_cursor_positions, column_editors[column], self)
func _move_selection_on_grid(move_h : int, move_v : int):
@ -433,18 +459,23 @@ func _move_selection_on_grid(move_h : int, move_v : int):
func set_cell(cell, value):
if columns[_get_cell_column(cell)] == "resource_path":
var column = _get_cell_column(cell)
if columns[column] == "resource_path":
return
cell.text = value
column_editors[column].set_value(cell, value)
func _update_resources(update_rows : Array, update_cells : Array, update_column : String, values : Array):
var cells := get_node(path_table_root).get_children()
var cell_editor = column_editors[_get_cell_column(cells[0])]
for i in update_rows.size():
update_rows[i].set(update_column, values[i])
update_cells[i].text = TextEditingUtils.show_non_typing(str(values[i]))
ResourceSaver.save(update_rows[i].resource_path, update_rows[i])
if is_undo_redoing:
cell_editor.set_value(update_cells[i], values[i])
is_undo_redoing = false
func _get_edited_cells_resources() -> Array:
@ -457,8 +488,9 @@ func _get_edited_cells_resources() -> Array:
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] = str2var(TextEditingUtils.revert_non_typing(edited_cells[i].text))
arr[i] = cell_editor.get_value(edited_cells[i])
return arr

View File

@ -1,11 +1,13 @@
[gd_scene load_steps=11 format=2]
[gd_scene load_steps=9 format=2]
[ext_resource path="res://addons/resources_speadsheet_view/editor_view.gd" type="Script" id=1]
[ext_resource path="res://addons/resources_speadsheet_view/typed_cells/basic.tscn" type="PackedScene" id=3]
[ext_resource path="res://addons/resources_speadsheet_view/typed_cells/cell_editor.gd" type="Script" id=2]
[ext_resource path="res://addons/resources_speadsheet_view/typed_cells/cell_editor_color.gd" type="Script" id=3]
[ext_resource path="res://addons/resources_speadsheet_view/editor_icon_button.gd" type="Script" id=4]
[ext_resource path="res://addons/resources_speadsheet_view/typed_cells/cell_editor_bool.gd" type="Script" id=5]
[ext_resource path="res://addons/resources_speadsheet_view/table_header.tscn" type="PackedScene" id=6]
[sub_resource type="Image" id=15]
[sub_resource type="Image" id=3]
data = {
"data": PoolByteArray( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
"format": "LumAlpha8",
@ -14,42 +16,12 @@ data = {
"width": 16
}
[sub_resource type="ImageTexture" id=4]
[sub_resource type="ImageTexture" id=2]
flags = 4
flags = 4
image = SubResource( 15 )
image = SubResource( 3 )
size = Vector2( 16, 16 )
[sub_resource type="StyleBoxTexture" id=5]
texture = SubResource( 4 )
region_rect = Rect2( 0, 0, 16, 16 )
margin_left = 2.0
margin_right = 2.0
margin_top = 2.0
margin_bottom = 2.0
[sub_resource type="Image" id=16]
data = {
"data": PoolByteArray( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
"format": "LumAlpha8",
"height": 16,
"mipmaps": false,
"width": 16
}
[sub_resource type="ImageTexture" id=14]
flags = 4
flags = 4
image = SubResource( 16 )
size = Vector2( 16, 16 )
[sub_resource type="StyleBoxFlat" id=11]
content_margin_left = 3.0
content_margin_right = 3.0
content_margin_top = 3.0
content_margin_bottom = 3.0
bg_color = Color( 0.147059, 0.154412, 0.159314, 1 )
[node name="Control" type="MarginContainer"]
anchor_right = 1.0
anchor_bottom = 1.0
@ -70,12 +42,11 @@ script = ExtResource( 1 )
__meta__ = {
"_edit_lock_": true
}
grid_cell_scene = ExtResource( 3 )
table_header_scene = ExtResource( 6 )
cell_editor_classes = [ ExtResource( 5 ), ExtResource( 3 ), ExtResource( 2 ) ]
path_folder_path = NodePath("HeaderContentSplit/VBoxContainer/HBoxContainer/HBoxContainer/Path")
path_recent_paths = NodePath("HeaderContentSplit/VBoxContainer/HBoxContainer/RecentPaths")
path_table_root = NodePath("HeaderContentSplit/MarginContainer/FooterContentSplit/Panel/Scroll/MarginContainer/TableGrid")
editor_stylebox = SubResource( 5 )
[node name="HeaderContentSplit" type="VBoxContainer" parent="."]
margin_left = 2.0
@ -88,7 +59,8 @@ __meta__ = {
[node name="VBoxContainer" type="VBoxContainer" parent="HeaderContentSplit"]
margin_right = 1020.0
margin_bottom = 42.0
margin_bottom = 40.0
custom_constants/separation = 2
__meta__ = {
"_edit_lock_": true
}
@ -99,9 +71,9 @@ margin_bottom = 14.0
text = "Select Resource Folder:"
[node name="HBoxContainer" type="HBoxContainer" parent="HeaderContentSplit/VBoxContainer"]
margin_top = 18.0
margin_top = 16.0
margin_right = 1020.0
margin_bottom = 42.0
margin_bottom = 40.0
__meta__ = {
"_edit_lock_": true
}
@ -139,7 +111,7 @@ margin_left = 336.0
margin_right = 364.0
margin_bottom = 24.0
hint_tooltip = "Open Folder"
icon = SubResource( 14 )
icon = SubResource( 2 )
script = ExtResource( 4 )
__meta__ = {
"_edit_lock_": true
@ -171,7 +143,7 @@ margin_left = 938.0
margin_right = 966.0
margin_bottom = 24.0
hint_tooltip = "Delete Selected Path"
icon = SubResource( 14 )
icon = SubResource( 2 )
script = ExtResource( 4 )
__meta__ = {
"_edit_lock_": true
@ -188,7 +160,7 @@ __meta__ = {
}
[node name="MarginContainer" type="MarginContainer" parent="HeaderContentSplit"]
margin_top = 46.0
margin_top = 44.0
margin_right = 1020.0
margin_bottom = 596.0
mouse_filter = 2
@ -200,25 +172,32 @@ __meta__ = {
[node name="FooterContentSplit" type="VBoxContainer" parent="HeaderContentSplit/MarginContainer"]
margin_right = 1020.0
margin_bottom = 550.0
margin_bottom = 552.0
size_flags_horizontal = 3
size_flags_vertical = 3
__meta__ = {
"_edit_lock_": true
}
[node name="Panel" type="PanelContainer" parent="HeaderContentSplit/MarginContainer/FooterContentSplit"]
[node name="Panel" type="MarginContainer" parent="HeaderContentSplit/MarginContainer/FooterContentSplit"]
margin_right = 1020.0
margin_bottom = 522.0
margin_bottom = 502.0
mouse_filter = 2
size_flags_vertical = 3
custom_styles/panel = SubResource( 11 )
__meta__ = {
"_edit_lock_": true
}
[node name="Panel" type="Panel" parent="HeaderContentSplit/MarginContainer/FooterContentSplit/Panel"]
margin_right = 1020.0
margin_bottom = 502.0
__meta__ = {
"_edit_lock_": true
}
[node name="Scroll" type="ScrollContainer" parent="HeaderContentSplit/MarginContainer/FooterContentSplit/Panel"]
margin_left = 3.0
margin_top = 3.0
margin_right = 1017.0
margin_bottom = 519.0
margin_right = 1020.0
margin_bottom = 502.0
mouse_filter = 1
size_flags_horizontal = 3
size_flags_vertical = 3
@ -244,27 +223,48 @@ __meta__ = {
}
[node name="Footer" type="VBoxContainer" parent="HeaderContentSplit/MarginContainer/FooterContentSplit"]
margin_top = 526.0
margin_top = 506.0
margin_right = 1020.0
margin_bottom = 550.0
margin_bottom = 552.0
__meta__ = {
"_edit_lock_": true
}
[node name="Search" type="HBoxContainer" parent="HeaderContentSplit/MarginContainer/FooterContentSplit/Footer"]
[node name="PropertyEditors" type="VBoxContainer" parent="HeaderContentSplit/MarginContainer/FooterContentSplit/Footer"]
unique_name_in_owner = true
margin_right = 1020.0
margin_bottom = 24.0
[node name="HBoxContainer" type="HBoxContainer" parent="HeaderContentSplit/MarginContainer/FooterContentSplit/Footer"]
margin_top = 4.0
margin_right = 1020.0
margin_bottom = 18.0
[node name="Label" type="Label" parent="HeaderContentSplit/MarginContainer/FooterContentSplit/Footer/HBoxContainer"]
margin_right = 102.0
margin_bottom = 14.0
text = "GDScript Search"
[node name="HSeparator" type="HSeparator" parent="HeaderContentSplit/MarginContainer/FooterContentSplit/Footer/HBoxContainer"]
margin_left = 106.0
margin_right = 1020.0
margin_bottom = 14.0
size_flags_horizontal = 3
[node name="Search" type="HBoxContainer" parent="HeaderContentSplit/MarginContainer/FooterContentSplit/Footer"]
margin_top = 22.0
margin_right = 1020.0
margin_bottom = 46.0
[node name="Label" type="Label" parent="HeaderContentSplit/MarginContainer/FooterContentSplit/Footer/Search"]
margin_top = 5.0
margin_right = 190.0
margin_right = 65.0
margin_bottom = 19.0
text = "Search by GDScript Condition:"
text = "Condition:"
[node name="Label2" type="Label" parent="HeaderContentSplit/MarginContainer/FooterContentSplit/Footer/Search"]
margin_left = 194.0
margin_left = 69.0
margin_top = 3.0
margin_right = 212.0
margin_right = 87.0
margin_bottom = 21.0
rect_min_size = Vector2( 18, 18 )
hint_tooltip = "Enter an expression. The table only show rows where the expression returns `true`.
@ -282,7 +282,7 @@ text = "(?)"
align = 1
[node name="SearchCond" type="LineEdit" parent="HeaderContentSplit/MarginContainer/FooterContentSplit/Footer/Search"]
margin_left = 216.0
margin_left = 91.0
margin_right = 1020.0
margin_bottom = 24.0
size_flags_horizontal = 3

View File

@ -47,13 +47,13 @@ static func revert_non_typing(text : String) -> String:
return text
static func multi_erase_right(edited_cells : Array, edit_cursor_positions : Array, callback_object : Object):
static func multi_erase_right(edited_cells : Array, edit_cursor_positions : Array, cell_editor : Reference, callback_object : Object):
for i in edited_cells.size():
var cell = edited_cells[i]
var start_pos = edit_cursor_positions[i]
while true:
edit_cursor_positions[i] += 1
if !Input.is_key_pressed(KEY_CONTROL) or is_character_whitespace(cell.text, edit_cursor_positions[i]):
if !Input.is_key_pressed(KEY_CONTROL) or is_character_whitespace(_get_cell_text(cell, cell_editor), edit_cursor_positions[i]):
break
edit_cursor_positions[i] = min(
@ -61,39 +61,39 @@ static func multi_erase_right(edited_cells : Array, edit_cursor_positions : Arra
edited_cells[i].text.length()
)
callback_object.set_cell(cell, (
cell.text.left(start_pos)
+ cell.text.substr(edit_cursor_positions[i])
_get_cell_text(cell, cell_editor).left(start_pos)
+ _get_cell_text(cell, cell_editor).substr(edit_cursor_positions[i])
))
edit_cursor_positions[i] = start_pos
static func multi_erase_left(edited_cells : Array, edit_cursor_positions : Array, callback_object : Object):
static func multi_erase_left(edited_cells : Array, edit_cursor_positions : Array, cell_editor : Reference, callback_object : Object):
for i in edited_cells.size():
var cell = edited_cells[i]
var start_pos = edit_cursor_positions[i]
edit_cursor_positions[i] = _step_cursor(cell.text, edit_cursor_positions[i], -1)
edit_cursor_positions[i] = _step_cursor(_get_cell_text(cell, cell_editor), edit_cursor_positions[i], -1)
var result_text = (
cell.text.substr(0, edit_cursor_positions[i])
+ cell.text.substr(start_pos)
_get_cell_text(cell, cell_editor).substr(0, edit_cursor_positions[i])
+ _get_cell_text(cell, cell_editor).substr(start_pos)
)
callback_object.set_cell(cell, (
cell.text.substr(0, edit_cursor_positions[i])
+ cell.text.substr(start_pos)
_get_cell_text(cell, cell_editor).substr(0, edit_cursor_positions[i])
+ _get_cell_text(cell, cell_editor).substr(start_pos)
))
static func multi_move_left(edited_cells : Array, edit_cursor_positions : Array):
static func multi_move_left(edited_cells : Array, edit_cursor_positions : Array, cell_editor : Reference):
for i in edit_cursor_positions.size():
edit_cursor_positions[i] = _step_cursor(edited_cells[i].text, edit_cursor_positions[i], -1)
static func multi_move_right(edited_cells : Array, edit_cursor_positions : Array):
static func multi_move_right(edited_cells : Array, edit_cursor_positions : Array, cell_editor : Reference):
for i in edit_cursor_positions.size():
edit_cursor_positions[i] = _step_cursor(edited_cells[i].text, edit_cursor_positions[i], 1)
static func multi_paste(edited_cells : Array, edit_cursor_positions : Array, callback_object : Object):
static func multi_paste(edited_cells : Array, edit_cursor_positions : Array, cell_editor : Reference, callback_object : Object):
var pasted_lines := OS.clipboard.split("\n")
var paste_each_line := pasted_lines.size() == edited_cells.size()
@ -106,9 +106,9 @@ static func multi_paste(edited_cells : Array, edit_cursor_positions : Array, cal
var cell = edited_cells[i]
callback_object.set_cell(cell, (
cell.text.left(edit_cursor_positions[i])
_get_cell_text(cell, cell_editor).left(edit_cursor_positions[i])
+ (pasted_lines[i] if paste_each_line else OS.clipboard)
+ cell.text.substr(edit_cursor_positions[i])
+ _get_cell_text(cell, cell_editor).substr(edit_cursor_positions[i])
))
@ -122,26 +122,30 @@ static func multi_copy(edited_cells : Array):
OS.clipboard = copied_text.substr(1)
static func multi_linefeed(edited_cells : Array, edit_cursor_positions : Array, callback_object : Object):
static func multi_linefeed(edited_cells : Array, edit_cursor_positions : Array, cell_editor : Reference, callback_object : Object):
for i in edited_cells.size():
var cell = edited_cells[i]
callback_object.set_cell(cell, (
cell.text.left(edit_cursor_positions[i])
_get_cell_text(cell, cell_editor).left(edit_cursor_positions[i])
+ "\n"
+ cell.text.substr(edit_cursor_positions[i])
+ _get_cell_text(cell, cell_editor).substr(edit_cursor_positions[i])
))
edit_cursor_positions[i] = min(edit_cursor_positions[i] + 1, cell.text.length())
edit_cursor_positions[i] = min(edit_cursor_positions[i] + 1, _get_cell_text(cell, cell_editor).length())
static func multi_input(input_char : String, edited_cells : Array, edit_cursor_positions : Array, callback_object : Object):
static func multi_input(input_char : String, edited_cells : Array, edit_cursor_positions : Array, cell_editor : Reference, callback_object : Object):
for i in edited_cells.size():
var cell = edited_cells[i]
callback_object.set_cell(cell, (
cell.text.left(edit_cursor_positions[i])
_get_cell_text(cell, cell_editor).left(edit_cursor_positions[i])
+ input_char
+ cell.text.substr(edit_cursor_positions[i])
+ _get_cell_text(cell, cell_editor).substr(edit_cursor_positions[i])
))
edit_cursor_positions[i] = min(edit_cursor_positions[i] + 1, cell.text.length())
edit_cursor_positions[i] = min(edit_cursor_positions[i] + 1, _get_cell_text(cell, cell_editor).length())
static func _get_cell_text(cell : Control, cell_editor : Reference):
return cell_editor.get_text_value(cell)
static func _step_cursor(text : String, start : int, step : int = 1) -> int:

View File

@ -9,8 +9,11 @@ margin_bottom = 14.0
rect_min_size = Vector2( 58, 0 )
mouse_filter = 0
size_flags_vertical = 9
__meta__ = {
"_edit_lock_": true
}
[node name="LineEdit" type="LineEdit" parent="."]
[node name="Back" type="LineEdit" parent="."]
show_behind_parent = true
anchor_right = 1.0
anchor_bottom = 1.0
@ -22,6 +25,9 @@ context_menu_enabled = false
virtual_keyboard_enabled = false
caret_blink = true
caret_blink_speed = 0.5
__meta__ = {
"_edit_lock_": true
}
[node name="Selected" type="ColorRect" parent="."]
visible = false

View File

@ -0,0 +1,37 @@
class_name CellEditor
extends Reference
const CELL_SCENE_DIR = "res://addons/resources_speadsheet_view/typed_cells/"
# Override to define where the cell should be shown.
func can_edit_value(value, property_hint) -> bool:
return true
# Override to change how the cell is created; preload a scene or create nodes from code.
func create_cell() -> Control:
return load(CELL_SCENE_DIR + "basic.tscn").instance()
# Override to change behaviour when the cell is clicked to be selected.
func set_selected(node : Control, selected : bool):
node.get_node("Selected").visible = selected
# Override to change behaviour when the cell is edited via keyboard.
func set_value(node : Control, value):
node.text = TextEditingUtils.show_non_typing(str(value))
func get_value(node : Control):
return str2var(TextEditingUtils.revert_non_typing(node.text))
func get_text_value(node : Control):
return node.text
# Override for text-based types to allow multi-editing.
func get_text_length(node : Control):
return node.text.length()
func set_color(node : Control, color : Color):
node.get_node("Back").modulate = color

View File

@ -0,0 +1,22 @@
extends CellEditor
func can_edit_value(value, property_hint) -> bool:
return value is bool
func set_value(node : Control, value):
if value is bool:
_set_value_internal(node, value)
else:
_set_value_internal(node, !node.text.begins_with("O"))
func get_value(node : Control):
return node.text == "ON"
func _set_value_internal(node, value):
node.text = "ON" if value else "off"
node.self_modulate.a = 1.0 if value else 0.2

View File

@ -0,0 +1,25 @@
extends CellEditor
var _cached_color := Color.white
func can_edit_value(value, property_hint) -> bool:
return value is Color
func get_value(node : Control):
var val = TextEditingUtils.revert_non_typing(node.text)
if val.length() == 3 || val.length() == 6 || val.length() == 8:
return Color(val)
else:
return _cached_color
func set_value(node : Control, value):
if value is String:
node.text = TextEditingUtils.show_non_typing(str(value))
else:
node.text = value.to_html(true)
_cached_color = value

View File

@ -0,0 +1 @@
class_name ResourceSpreadsheetEditor

View File

@ -2,11 +2,14 @@ tool
class_name DynamicWheelItem
extends Resource
export var color1 := Color.white
export var max_duplicates := 0
export var tags := "tag_1 tag_2 tag_3"
export var requires_one_of_tags := ""
export var color2 := Color.white
export(String) var tag_delimeter = " "
export var base_weight := 10.0
export var is_notable := false
export(String, MULTILINE) var multiplier_per_tag := ""
export(String, MULTILINE) var multiplier_if_tag_present := ""
export(String, MULTILINE) var multiplier_if_tag_not_present := ""
@ -21,50 +24,3 @@ var multiplier_per_tag_dict := {}
var multiplier_if_tag_present_dict := {}
var multiplier_if_tag_not_present_dict := {}
var max_tags_present_dict := {}
func get_weight(owned_tags : Dictionary) -> float:
if !is_cached:
_cache_lists()
for k in max_tags_present_dict:
if owned_tags.get(k, 0) >= max_tags_present_dict[k]:
return 0.0
var result_weight := base_weight
for k in multiplier_per_tag_dict:
result_weight *= pow(multiplier_per_tag_dict[k], owned_tags.get(k, 0))
for k in multiplier_if_tag_not_present_dict:
if owned_tags.has(k):
result_weight *= multiplier_if_tag_present_dict[k]
for k in multiplier_if_tag_not_present_dict:
if owned_tags.has(k):
result_weight *= multiplier_if_tag_present_dict[k]
return result_weight
func _cache_lists():
tag_array = tags.split(tag_delimeter)
requires_one_of_tags_array = requires_one_of_tags.split(tag_delimeter)
multiplier_per_tag_dict.clear()
multiplier_if_tag_present_dict.clear()
multiplier_if_tag_not_present_dict.clear()
max_tags_present_dict.clear()
_cache_text_into_dictionary(multiplier_per_tag_dict, multiplier_per_tag)
_cache_text_into_dictionary(multiplier_if_tag_present_dict, multiplier_if_tag_present)
_cache_text_into_dictionary(multiplier_if_tag_not_present_dict, multiplier_if_tag_not_present)
_cache_text_into_dictionary(max_tags_present_dict, max_tags_present)
is_cached = true
func _cache_text_into_dictionary(dict : Dictionary, list_string : String):
for x in list_string.split(list_row_delimeter):
dict[x.left(x.find(list_item_delimeter))] = float(x.right(x.rfind(list_item_delimeter) + list_item_delimeter.length()))
print(dict)

View File

@ -9,12 +9,22 @@
config_version=4
_global_script_classes=[ {
"base": "Reference",
"class": "CellEditor",
"language": "GDScript",
"path": "res://addons/resources_speadsheet_view/typed_cells/cell_editor.gd"
}, {
"base": "Resource",
"class": "DynamicWheelItem",
"language": "GDScript",
"path": "res://example/my_custom_resource.gd"
}, {
"base": "Reference",
"class": "ResourceSpreadsheetEditor",
"language": "GDScript",
"path": "res://addons/resources_speadsheet_view/typed_editors/base.gd"
}, {
"base": "Reference",
"class": "TextEditingUtils",
"language": "GDScript",
"path": "res://addons/resources_speadsheet_view/text_editing_utils.gd"
@ -30,7 +40,9 @@ _global_script_classes=[ {
"path": "res://addons/resources_speadsheet_view/editor_stylebox_overrider.gd"
} ]
_global_script_class_icons={
"CellEditor": "",
"DynamicWheelItem": "",
"ResourceSpreadsheetEditor": "",
"TextEditingUtils": "",
"ThemeIconButton": "",
"ThemeStylebox": ""
@ -39,6 +51,7 @@ _global_script_class_icons={
[application]
config/name="Edit Resources as Spreadsheets"
run/main_scene="res://addons/resources_speadsheet_view/editor_view.tscn"
config/icon="res://icon.png"
[editor_plugins]