mirror of
https://github.com/Relintai/godot-resources-as-sheets-plugin.git
synced 2025-02-21 08:34:26 +01:00
Add enum and bool editing, improve multi select
This commit is contained in:
parent
a0f3d3fe14
commit
e65190c28f
@ -58,6 +58,7 @@ func _ready():
|
||||
# Load cell editors and instantiate them
|
||||
for x in cell_editor_classes:
|
||||
all_cell_editors.append(x.new())
|
||||
all_cell_editors[all_cell_editors.size() - 1].hint_strings_array = column_hints
|
||||
|
||||
display_folder(recent_paths[0], "resource_name", false, true)
|
||||
|
||||
@ -121,7 +122,7 @@ func _load_resources_from_folder(folderpath : String, sort_by : String, sort_rev
|
||||
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"])
|
||||
column_hints.append(x["hint_string"].split(","))
|
||||
for y in all_cell_editors:
|
||||
if y.can_edit_value(res.get(x["name"]), x["type"], x["hint"]):
|
||||
column_editors.append(y)
|
||||
@ -211,6 +212,7 @@ func _update_column_sizes():
|
||||
get_node(path_columns).get_parent().rect_min_size.y = get_node(path_columns).rect_size.y
|
||||
for i in column_headers.size():
|
||||
cell = table_root.get_child(i)
|
||||
# Skip these 3 and enable header Clip Text to fix misaligned headers
|
||||
column_headers[i].rect_min_size.x = 0
|
||||
cell.rect_min_size.x = 0
|
||||
column_headers[i].rect_size.x = 0
|
||||
@ -323,8 +325,9 @@ func deselect_cell(cell : Control):
|
||||
|
||||
column_editors[_get_cell_column(cell)].set_selected(cell, false)
|
||||
edited_cells.remove(idx)
|
||||
edited_cells_text.remove(idx)
|
||||
edit_cursor_positions.remove(idx)
|
||||
if edited_cells_text.size() != 0:
|
||||
edited_cells_text.remove(idx)
|
||||
edit_cursor_positions.remove(idx)
|
||||
|
||||
|
||||
func select_cell(cell : Control):
|
||||
@ -334,8 +337,10 @@ func select_cell(cell : Control):
|
||||
_try_open_docks(cell)
|
||||
inspector_resource = rows[_get_cell_row(cell)].duplicate()
|
||||
editor_plugin.get_editor_interface().edit_resource(inspector_resource)
|
||||
return
|
||||
|
||||
|
||||
func select_cells_to(cell : Control):
|
||||
var column_index := _get_cell_column(cell)
|
||||
if column_index != _get_cell_column(edited_cells[edited_cells.size() - 1]):
|
||||
return
|
||||
|
||||
@ -467,34 +472,30 @@ func _update_scroll():
|
||||
|
||||
func _on_cell_gui_input(event : InputEvent, cell : Control):
|
||||
if event is InputEventMouseButton:
|
||||
if event.button_index == BUTTON_WHEEL_UP || event.button_index == BUTTON_WHEEL_DOWN:
|
||||
_update_scroll()
|
||||
|
||||
_update_scroll()
|
||||
if event.button_index != BUTTON_LEFT:
|
||||
return
|
||||
|
||||
grab_focus()
|
||||
if event.pressed:
|
||||
if cell in edited_cells:
|
||||
if !Input.is_key_pressed(KEY_CONTROL):
|
||||
if Input.is_key_pressed(KEY_CONTROL):
|
||||
if cell in edited_cells:
|
||||
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()
|
||||
elif Input.is_key_pressed(KEY_SHIFT):
|
||||
select_cells_to(cell)
|
||||
|
||||
else:
|
||||
deselect_all_cells()
|
||||
select_cell(cell)
|
||||
|
||||
|
||||
func _gui_input(event : InputEvent):
|
||||
if event is InputEventMouseButton:
|
||||
if event.button_index == BUTTON_WHEEL_UP || event.button_index == BUTTON_WHEEL_DOWN:
|
||||
_update_scroll()
|
||||
|
||||
_update_scroll()
|
||||
if event.button_index != BUTTON_LEFT:
|
||||
return
|
||||
|
||||
@ -655,6 +656,11 @@ func _update_resources(update_rows : Array, update_cells : Array, update_column
|
||||
|
||||
|
||||
func _try_convert(value, type):
|
||||
if type == TYPE_BOOL:
|
||||
_update_selected_cells_text()
|
||||
# "off" displayed in lowercase, "ON" in uppercase.
|
||||
return value[0] == "o"
|
||||
|
||||
# If it can't convert, returns null.
|
||||
return convert(value, type)
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=15 format=2]
|
||||
[gd_scene load_steps=16 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/cell_editor_string.gd" type="Script" id=2]
|
||||
@ -12,6 +12,7 @@
|
||||
[ext_resource path="res://addons/resources_speadsheet_view/typed_editors/dock_texture.tscn" type="PackedScene" id=10]
|
||||
[ext_resource path="res://addons/resources_speadsheet_view/typed_cells/cell_editor_array.gd" type="Script" id=11]
|
||||
[ext_resource path="res://addons/resources_speadsheet_view/typed_editors/dock_array.tscn" type="PackedScene" id=12]
|
||||
[ext_resource path="res://addons/resources_speadsheet_view/typed_cells/cell_editor_enum.gd" type="Script" id=13]
|
||||
|
||||
[sub_resource type="Image" id=3]
|
||||
data = {
|
||||
@ -49,7 +50,7 @@ __meta__ = {
|
||||
"_edit_lock_": true
|
||||
}
|
||||
table_header_scene = ExtResource( 6 )
|
||||
cell_editor_classes = [ ExtResource( 11 ), ExtResource( 3 ), ExtResource( 5 ), ExtResource( 9 ), ExtResource( 2 ) ]
|
||||
cell_editor_classes = [ ExtResource( 13 ), ExtResource( 11 ), ExtResource( 3 ), ExtResource( 5 ), ExtResource( 9 ), 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")
|
||||
|
@ -5,5 +5,5 @@ description="Edit Many Resources from one Folder as a table.
|
||||
|
||||
Heavily inspired by Multi-Cursor-Editing in text editors, so after selecting multiple cells (in the same column!) using Ctrl+Click or Shift+Click, most Basic-to-Intermediate movements should be available."
|
||||
author="Don Tnowe"
|
||||
version="1.2"
|
||||
version="1.3"
|
||||
script="plugin.gd"
|
||||
|
@ -3,6 +3,8 @@ extends Reference
|
||||
|
||||
const CELL_SCENE_DIR = "res://addons/resources_speadsheet_view/typed_cells/"
|
||||
|
||||
var hint_strings_array := []
|
||||
|
||||
|
||||
# Override to define where the cell should be shown.
|
||||
func can_edit_value(value, type, property_hint) -> bool:
|
||||
|
@ -9,9 +9,8 @@ func set_value(node : Control, value):
|
||||
if value is bool:
|
||||
_set_value_internal(node, value)
|
||||
|
||||
# Does not work properly with new text input system
|
||||
# else:
|
||||
# _set_value_internal(node, !node.text.begins_with("O"))
|
||||
else:
|
||||
_set_value_internal(node, !node.text.begins_with("O"))
|
||||
|
||||
|
||||
func _set_value_internal(node, value):
|
||||
|
@ -0,0 +1,15 @@
|
||||
extends CellEditor
|
||||
|
||||
|
||||
func can_edit_value(value, type, property_hint) -> bool:
|
||||
return type == TYPE_INT and property_hint == PROPERTY_HINT_ENUM
|
||||
|
||||
|
||||
func set_value(node : Control, value):
|
||||
node.text = "<" + hint_strings_array[node.get_position_in_parent() % node.get_parent().columns][value] + ">"
|
||||
node.self_modulate = Color(node.text.hash()) + Color(0.25, 0.25, 0.25, 1.0)
|
||||
node.align = Label.ALIGN_CENTER
|
||||
|
||||
|
||||
func is_text():
|
||||
return false
|
@ -15,7 +15,7 @@ icon = ExtResource( 1 )
|
||||
custom_scene = ExtResource( 2 )
|
||||
color2 = Color( 0.407843, 0.192157, 0.827451, 1 )
|
||||
base_weight = 1.0
|
||||
is_notable = false
|
||||
is_notable = true
|
||||
multiplier_per_tag = "magic 2.0"
|
||||
multiplier_if_tag_present = ""
|
||||
multiplier_if_tag_not_present = ""
|
||||
|
@ -13,7 +13,7 @@ type = 0
|
||||
icon = ExtResource( 1 )
|
||||
color2 = Color( 0.988235, 0.584314, 0.192157, 1 )
|
||||
base_weight = 10.0
|
||||
is_notable = true
|
||||
is_notable = false
|
||||
multiplier_per_tag = "strength 2.0"
|
||||
multiplier_if_tag_present = ""
|
||||
multiplier_if_tag_not_present = ""
|
||||
|
@ -13,7 +13,7 @@ type = 0
|
||||
icon = ExtResource( 1 )
|
||||
color2 = Color( 0.189457, 0.452246, 0.902344, 1 )
|
||||
base_weight = 10.0
|
||||
is_notable = true
|
||||
is_notable = false
|
||||
multiplier_per_tag = "magic 2.0"
|
||||
multiplier_if_tag_present = ""
|
||||
multiplier_if_tag_not_present = ""
|
||||
|
@ -13,7 +13,7 @@ type = 0
|
||||
icon = ExtResource( 1 )
|
||||
color2 = Color( 0.189457, 0.452246, 0.902344, 1 )
|
||||
base_weight = 10.0
|
||||
is_notable = true
|
||||
is_notable = false
|
||||
multiplier_per_tag = "magic 2.0"
|
||||
multiplier_if_tag_present = ""
|
||||
multiplier_if_tag_not_present = ""
|
||||
|
@ -13,7 +13,7 @@ type = 0
|
||||
icon = ExtResource( 1 )
|
||||
color2 = Color( 0.988235, 0.584314, 0.192157, 1 )
|
||||
base_weight = 10.0
|
||||
is_notable = true
|
||||
is_notable = false
|
||||
multiplier_per_tag = "strength 2.0"
|
||||
multiplier_if_tag_present = ""
|
||||
multiplier_if_tag_not_present = ""
|
||||
|
@ -14,11 +14,6 @@ _global_script_classes=[ {
|
||||
"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": "Control",
|
||||
"class": "SheetsDockEditor",
|
||||
"language": "GDScript",
|
||||
@ -41,7 +36,6 @@ _global_script_classes=[ {
|
||||
} ]
|
||||
_global_script_class_icons={
|
||||
"CellEditor": "",
|
||||
"DynamicWheelItem": "",
|
||||
"SheetsDockEditor": "",
|
||||
"TextEditingUtils": "",
|
||||
"ThemeIconButton": "",
|
||||
|
Loading…
Reference in New Issue
Block a user