Implement resource cell editing

This commit is contained in:
don-tnowe 2022-09-22 19:18:09 +03:00
parent 48bfd7ebd3
commit 1ffa77166a
28 changed files with 281 additions and 27 deletions

View File

@ -180,7 +180,7 @@ func _update_row(row_index : int):
var next_color := Color.white
for i in columns.size():
if root_node.get_child_count() <= (row_index + 1) * columns.size() + i:
current_node = column_editors[i].create_cell()
current_node = column_editors[i].create_cell(self)
current_node.connect("gui_input", self, "_on_cell_gui_input", [current_node])
root_node.add_child(current_node)
@ -400,10 +400,6 @@ func _on_cell_gui_input(event : InputEvent, cell : Control):
select_cell(cell)
if event is InputEventMouseMotion:
if Input.is_mouse_button_pressed(BUTTON_LEFT):
select_cell(cell)
func _gui_input(event : InputEvent):
if event is InputEventMouseButton:

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=11 format=2]
[gd_scene load_steps=12 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]
@ -8,6 +8,7 @@
[ext_resource path="res://addons/resources_speadsheet_view/table_header.tscn" type="PackedScene" id=6]
[ext_resource path="res://addons/resources_speadsheet_view/typed_editors/dock_color.tscn" type="PackedScene" id=7]
[ext_resource path="res://addons/resources_speadsheet_view/typed_editors/dock_number.tscn" type="PackedScene" id=8]
[ext_resource path="res://addons/resources_speadsheet_view/typed_cells/cell_editor_resource.gd" type="Script" id=9]
[sub_resource type="Image" id=3]
data = {
@ -45,7 +46,7 @@ __meta__ = {
"_edit_lock_": true
}
table_header_scene = ExtResource( 6 )
cell_editor_classes = [ ExtResource( 3 ), ExtResource( 5 ), ExtResource( 2 ) ]
cell_editor_classes = [ 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")

View File

@ -9,7 +9,8 @@ func can_edit_value(value, type, 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:
# Caller is an instance of `editor_view.tscn`.
func create_cell(caller : Control) -> Control:
return load(CELL_SCENE_DIR + "basic.tscn").instance()
# Override to change behaviour when the cell is clicked to be selected.

View File

@ -3,7 +3,7 @@ extends CellEditor
var _cached_color := Color.white
func create_cell() -> Control:
func create_cell(caller : Control) -> Control:
var node = load(CELL_SCENE_DIR + "basic.tscn").instance()
var color = ColorRect.new()
node.align = Label.ALIGN_RIGHT

View File

@ -0,0 +1,52 @@
extends CellEditor
var previewer : EditorResourcePreview
func can_edit_value(value, type, property_hint) -> bool:
return type == TYPE_OBJECT
func create_cell(caller : Control) -> Control:
if previewer == null:
previewer = caller.editor_plugin.get_editor_interface().get_resource_previewer()
var node = load(CELL_SCENE_DIR + "resource.tscn").instance()
return node
func set_value(node : Control, value):
if value == null:
node.get_node("Box/Tex").visible = false
node.get_node("Box/Label").text = "[empty]"
node.editor_description = ""
if !value is Resource: return
node.editor_description = value.resource_path
node.get_node("Box/Label").text = value.resource_name + "[" + value.resource_path.get_file() + "]"
if value is Texture:
node.get_node("Box/Tex").visible = true
node.get_node("Box/Tex").texture = value
else:
node.get_node("Box/Tex").visible = false
previewer.queue_resource_preview(value.resource_path, self, "_on_preview_loaded", node)
func get_value(node : Control):
if node.editor_description == "": return null
return load(node.editor_description)
func set_color(node : Control, color : Color):
node.get_node("Back").modulate = color * 0.6 if node.editor_description == "" else color
func get_text_length(node : Control):
return -1
func _on_preview_loaded(path : String, preview : Texture, thumbnail_preview : Texture, node):
node.get_node("Box/Tex").visible = true
node.get_node("Box/Tex").texture = preview

View File

@ -0,0 +1,60 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://icon.png" type="Texture" id=1]
[sub_resource type="DynamicFont" id=1]
size = 8
[node name="Label" type="MarginContainer"]
margin_right = 58.0
margin_bottom = 14.0
size_flags_vertical = 9
__meta__ = {
"_edit_lock_": true
}
[node name="Back" type="LineEdit" parent="."]
show_behind_parent = true
margin_right = 85.0
margin_bottom = 32.0
focus_mode = 0
mouse_filter = 2
custom_fonts/font = SubResource( 1 )
editable = false
expand_to_text_length = true
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
margin_right = 85.0
margin_bottom = 32.0
mouse_filter = 2
color = Color( 1, 1, 1, 0.247059 )
[node name="Box" type="HBoxContainer" parent="."]
margin_right = 85.0
margin_bottom = 32.0
[node name="Tex" type="TextureRect" parent="Box"]
margin_right = 32.0
margin_bottom = 32.0
rect_min_size = Vector2( 32, 32 )
texture = ExtResource( 1 )
expand = true
stretch_mode = 6
[node name="Label" type="Label" parent="Box"]
margin_left = 36.0
margin_top = 9.0
margin_right = 85.0
margin_bottom = 23.0
size_flags_horizontal = 3
text = "res.tres"
align = 1
valign = 1

8
example/icons/1.tres Normal file
View File

@ -0,0 +1,8 @@
[gd_resource type="AtlasTexture" load_steps=2 format=2]
[ext_resource path="res://example/icons/all_icons.png" type="Texture" id=1]
[resource]
flags = 4
atlas = ExtResource( 1 )
region = Rect2( 64, 0, 64, 64 )

8
example/icons/2.tres Normal file
View File

@ -0,0 +1,8 @@
[gd_resource type="AtlasTexture" load_steps=2 format=2]
[ext_resource path="res://example/icons/all_icons.png" type="Texture" id=1]
[resource]
flags = 4
atlas = ExtResource( 1 )
region = Rect2( 0, 0, 64, 64 )

8
example/icons/3.tres Normal file
View File

@ -0,0 +1,8 @@
[gd_resource type="AtlasTexture" load_steps=2 format=2]
[ext_resource path="res://example/icons/all_icons.png" type="Texture" id=1]
[resource]
flags = 4
atlas = ExtResource( 1 )
region = Rect2( 128, 0, 64, 64 )

8
example/icons/4.tres Normal file
View File

@ -0,0 +1,8 @@
[gd_resource type="AtlasTexture" load_steps=2 format=2]
[ext_resource path="res://example/icons/all_icons.png" type="Texture" id=1]
[resource]
flags = 4
atlas = ExtResource( 1 )
region = Rect2( 192, 0, 64, 64 )

8
example/icons/5.tres Normal file
View File

@ -0,0 +1,8 @@
[gd_resource type="AtlasTexture" load_steps=2 format=2]
[ext_resource path="res://example/icons/all_icons.png" type="Texture" id=1]
[resource]
flags = 4
atlas = ExtResource( 1 )
region = Rect2( 0, 64, 64, 64 )

8
example/icons/6.tres Normal file
View File

@ -0,0 +1,8 @@
[gd_resource type="AtlasTexture" load_steps=2 format=2]
[ext_resource path="res://example/icons/all_icons.png" type="Texture" id=1]
[resource]
flags = 4
atlas = ExtResource( 1 )
region = Rect2( 64, 64, 64, 64 )

BIN
example/icons/all_icons.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/all_icons.png-81c01fb40e0103e1eb894edd007b8876.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://example/icons/all_icons.png"
dest_files=[ "res://.import/all_icons.png-81c01fb40e0103e1eb894edd007b8876.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

View File

@ -5,16 +5,18 @@ extends Resource
export var color1 := Color.white
export var max_duplicates := 0
export var tags := "tag_1 tag_2 tag_3"
export var icon : Texture
export var custom_scene : PackedScene
export var color2 := Color.white
export(String) var tag_delimeter = " "
export 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 := ""
export(String, MULTILINE) var max_tags_present := ""
export(String) var list_item_delimeter = " "
export(String) var list_row_delimeter = ";"
export var list_item_delimeter := " "
export var list_row_delimeter := ";"
var is_cached := false
var tag_array := []

34
example/new scene.tscn Normal file
View File

@ -0,0 +1,34 @@
[gd_scene format=2]
[node name="Node2D" type="Node2D"]
[node name="ColorRect" type="ColorRect" parent="."]
margin_left = 51.0
margin_top = 54.0
margin_right = 374.0
margin_bottom = 371.0
rect_rotation = -15.0
color = Color( 0, 1, 0.0156863, 1 )
[node name="ColorRect2" type="ColorRect" parent="."]
margin_left = 484.0
margin_top = 66.0
margin_right = 807.0
margin_bottom = 383.0
rect_rotation = 15.0
color = Color( 0, 0.905882, 1, 1 )
[node name="ColorRect3" type="ColorRect" parent="."]
margin_left = -39.0
margin_top = 324.0
margin_right = 284.0
margin_bottom = 641.0
rect_rotation = -30.0
color = Color( 0, 0.0156863, 1, 1 )
[node name="ColorRect4" type="ColorRect" parent="."]
margin_left = 271.0
margin_top = 219.0
margin_right = 594.0
margin_bottom = 536.0
color = Color( 0.686275, 0, 1, 1 )

View File

@ -1,6 +1,7 @@
[gd_resource type="Resource" load_steps=2 format=2]
[gd_resource type="Resource" load_steps=3 format=2]
[ext_resource path="res://example/my_custom_resource.gd" type="Script" id=1]
[ext_resource path="res://example/icons/6.tres" type="Texture" id=2]
[resource]
resource_name = "Upgrade: Elemental Damage"
@ -8,7 +9,7 @@ script = ExtResource( 1 )
color1 = Color( 1, 1, 1, 1 )
max_duplicates = 9
tags = "elemental"
requires_one_of_tags = ""
icon = ExtResource( 2 )
color2 = Color( 0.964706, 0.298039, 0.298039, 1 )
tag_delimeter = " "
base_weight = 10.0

View File

@ -1,6 +1,7 @@
[gd_resource type="Resource" load_steps=2 format=2]
[gd_resource type="Resource" load_steps=3 format=2]
[ext_resource path="res://example/my_custom_resource.gd" type="Script" id=1]
[ext_resource path="res://example/icons/2.tres" type="Texture" id=2]
[resource]
resource_name = "Upgrade: Health"
@ -8,7 +9,7 @@ script = ExtResource( 1 )
color1 = Color( 1, 1, 1, 1 )
max_duplicates = 9
tags = "health melee"
requires_one_of_tags = ""
icon = ExtResource( 2 )
color2 = Color( 0.129412, 1, 0.243137, 1 )
tag_delimeter = " "
base_weight = 10.0

View File

@ -1,6 +1,7 @@
[gd_resource type="Resource" load_steps=2 format=2]
[gd_resource type="Resource" load_steps=3 format=2]
[ext_resource path="res://example/my_custom_resource.gd" type="Script" id=1]
[ext_resource path="res://example/icons/6.tres" type="Texture" id=2]
[resource]
resource_name = "Upgrade: Area of Effect"
@ -8,7 +9,7 @@ script = ExtResource( 1 )
color1 = Color( 1, 1, 1, 1 )
max_duplicates = 4
tags = "aoe"
requires_one_of_tags = ""
icon = ExtResource( 2 )
color2 = Color( 0.964706, 0.298039, 0.298039, 1 )
tag_delimeter = " "
base_weight = 10.0

View File

@ -1,6 +1,7 @@
[gd_resource type="Resource" load_steps=2 format=2]
[gd_resource type="Resource" load_steps=3 format=2]
[ext_resource path="res://example/my_custom_resource.gd" type="Script" id=1]
[ext_resource path="res://example/icons/5.tres" type="Texture" id=2]
[resource]
resource_name = "Upgrade: Magic"
@ -8,6 +9,7 @@ script = ExtResource( 1 )
color1 = Color( 1, 1, 1, 1 )
max_duplicates = 9
tags = "magic"
icon = ExtResource( 2 )
color2 = Color( 0.189457, 0.452246, 0.902344, 1 )
tag_delimeter = " "
base_weight = 10.0

View File

@ -1,6 +1,7 @@
[gd_resource type="Resource" load_steps=2 format=2]
[gd_resource type="Resource" load_steps=3 format=2]
[ext_resource path="res://example/my_custom_resource.gd" type="Script" id=1]
[ext_resource path="res://example/icons/1.tres" type="Texture" id=2]
[resource]
resource_name = "Upgrade: Strength"
@ -8,6 +9,7 @@ script = ExtResource( 1 )
color1 = Color( 1, 1, 1, 1 )
max_duplicates = 9
tags = "strength"
icon = ExtResource( 2 )
color2 = Color( 0.988235, 0.584314, 0.192157, 1 )
tag_delimeter = " "
base_weight = 10.0

View File

@ -1,6 +1,7 @@
[gd_resource type="Resource" load_steps=2 format=2]
[gd_resource type="Resource" load_steps=3 format=2]
[ext_resource path="res://example/my_custom_resource.gd" type="Script" id=1]
[ext_resource path="res://example/icons/3.tres" type="Texture" id=2]
[resource]
resource_name = "Weapon: Axe"
@ -8,6 +9,7 @@ script = ExtResource( 1 )
color1 = Color( 1, 1, 0.2, 1 )
max_duplicates = 1
tags = "weapon strength aoe melee"
icon = ExtResource( 2 )
color2 = Color( 0.988235, 0.584314, 0.192157, 1 )
tag_delimeter = " "
base_weight = 10.0

View File

@ -1,6 +1,7 @@
[gd_resource type="Resource" load_steps=2 format=2]
[gd_resource type="Resource" load_steps=3 format=2]
[ext_resource path="res://example/my_custom_resource.gd" type="Script" id=1]
[ext_resource path="res://example/icons/4.tres" type="Texture" id=2]
[resource]
resource_name = "Weapon: Blizzard"
@ -8,6 +9,7 @@ script = ExtResource( 1 )
color1 = Color( 1, 1, 0.2, 1 )
max_duplicates = 1
tags = "weapon magic aoe elemental"
icon = ExtResource( 2 )
color2 = Color( 0.189457, 0.452246, 0.902344, 1 )
tag_delimeter = " "
base_weight = 10.0

View File

@ -1,6 +1,8 @@
[gd_resource type="Resource" load_steps=2 format=2]
[gd_resource type="Resource" load_steps=4 format=2]
[ext_resource path="res://example/my_custom_resource.gd" type="Script" id=1]
[ext_resource path="res://example/icons/4.tres" type="Texture" id=2]
[ext_resource path="res://example/new scene.tscn" type="PackedScene" id=3]
[resource]
resource_name = "Weapon: Chaos Blast"
@ -8,6 +10,8 @@ script = ExtResource( 1 )
color1 = Color( 1, 1, 0.2, 1 )
max_duplicates = 1
tags = "weapon magic legendary chaosblast aoe"
icon = ExtResource( 2 )
custom_scene = ExtResource( 3 )
color2 = Color( 0.40631, 0.190945, 0.832031, 1 )
tag_delimeter = " "
base_weight = 1.0

View File

@ -1,6 +1,7 @@
[gd_resource type="Resource" load_steps=2 format=2]
[gd_resource type="Resource" load_steps=3 format=2]
[ext_resource path="res://example/my_custom_resource.gd" type="Script" id=1]
[ext_resource path="res://example/icons/3.tres" type="Texture" id=2]
[resource]
resource_name = "Weapon: Daggers"
@ -8,6 +9,7 @@ script = ExtResource( 1 )
color1 = Color( 1, 1, 0.2, 1 )
max_duplicates = 1
tags = "weapon strength dagger projectile"
icon = ExtResource( 2 )
color2 = Color( 0.988235, 0.584314, 0.192157, 1 )
tag_delimeter = " "
base_weight = 10.0

View File

@ -1,6 +1,8 @@
[gd_resource type="Resource" load_steps=2 format=2]
[gd_resource type="Resource" load_steps=4 format=2]
[ext_resource path="res://example/my_custom_resource.gd" type="Script" id=1]
[ext_resource path="res://example/icons/3.tres" type="Texture" id=2]
[ext_resource path="res://example/new scene.tscn" type="PackedScene" id=3]
[resource]
resource_name = "Weapon: Giga Sword"
@ -8,6 +10,8 @@ script = ExtResource( 1 )
color1 = Color( 1, 1, 0.2, 1 )
max_duplicates = 1
tags = "weapon strength legendary gigasword melee"
icon = ExtResource( 2 )
custom_scene = ExtResource( 3 )
color2 = Color( 0.988235, 0.93848, 0.192157, 1 )
tag_delimeter = " "
base_weight = 1.0

View File

@ -1,6 +1,7 @@
[gd_resource type="Resource" load_steps=2 format=2]
[gd_resource type="Resource" load_steps=3 format=2]
[ext_resource path="res://example/my_custom_resource.gd" type="Script" id=1]
[ext_resource path="res://example/icons/4.tres" type="Texture" id=2]
[resource]
resource_name = "Weapon: Lightning"
@ -8,6 +9,7 @@ script = ExtResource( 1 )
color1 = Color( 1, 1, 0.2, 1 )
max_duplicates = 1
tags = "weapon magic lightning elemental"
icon = ExtResource( 2 )
color2 = Color( 0.189457, 0.452246, 0.902344, 1 )
tag_delimeter = " "
base_weight = 10.0

View File

@ -1,6 +1,7 @@
[gd_resource type="Resource" load_steps=2 format=2]
[gd_resource type="Resource" load_steps=3 format=2]
[ext_resource path="res://example/my_custom_resource.gd" type="Script" id=1]
[ext_resource path="res://example/icons/3.tres" type="Texture" id=2]
[resource]
resource_name = "Weapon: Spear"
@ -8,6 +9,7 @@ script = ExtResource( 1 )
color1 = Color( 1, 1, 0.2, 1 )
max_duplicates = 1
tags = "weapon strength spear melee"
icon = ExtResource( 2 )
color2 = Color( 0.988235, 0.584314, 0.192157, 1 )
tag_delimeter = " "
base_weight = 10.0