Improve display for Resource arrays and Dicts

Closes #27
This commit is contained in:
don-tnowe 2023-06-23 18:07:33 +03:00
parent 68e99102bd
commit 8ea665f754
6 changed files with 66 additions and 8 deletions

View File

@ -2,6 +2,7 @@ extends SheetsCellEditor
const SettingsGrid := preload("res://addons/resources_spreadsheet_view/settings_grid.gd")
func can_edit_value(value, type, property_hint, column_index) -> bool:
return type == TYPE_PACKED_STRING_ARRAY or type == TYPE_ARRAY
@ -25,17 +26,24 @@ func set_value(node : Control, value):
else:
children[i].visible = true
_write_value_to_child(value[i], column_hints, children[i], colored)
_write_value_to_child(value[i], value[i], column_hints, children[i], colored)
func _write_value_to_child(value, hint_arr : PackedStringArray, child : Label, colored : bool):
func _write_value_to_child(value, key, hint_arr : PackedStringArray, child : Label, colored : bool):
if value is Resource:
value = _resource_to_string(value)
child.text = str(value)
child.self_modulate = (
Color.WHITE
if !colored else
Color(str(value).hash()) + Color(0.25, 0.25, 0.25, 1.0)
Color(str(key).hash()) + Color(0.25, 0.25, 0.25, 1.0)
)
func _resource_to_string(res : Resource):
return res.resource_name if res.resource_name != "" else res.resource_path.get_file()
func is_text():
return false

View File

@ -0,0 +1,37 @@
extends "res://addons/resources_spreadsheet_view/typed_cells/cell_editor_array.gd"
func can_edit_value(value, type, property_hint, column_index) -> bool:
return type == TYPE_DICTIONARY
func create_cell(caller : Control) -> Control:
return load(CELL_SCENE_DIR + "array.tscn").instantiate()
func set_value(node : Control, value):
var children = node.get_node("Box").get_children()
node.custom_minimum_size.x = ProjectSettings.get_setting(SettingsGrid.SETTING_PREFIX + "array_min_width")
var colored = ProjectSettings.get_setting(SettingsGrid.SETTING_PREFIX + "color_arrays")
while children.size() < value.size():
children.append(Label.new())
node.get_node("Box").add_child(children[children.size() - 1])
var column_hints = hint_strings_array[node.get_index() % hint_strings_array.size()]
var values : Array = value.values()
var keys : Array = value.keys()
for i in children.size():
if i >= values.size():
children[i].visible = false
else:
children[i].visible = true
if values[i] is Resource: values[i] = _resource_to_string(values[i])
if keys[i] is Resource: keys[i] = _resource_to_string(keys[i])
_write_value_to_child("%s%s" % [keys[i], values[i]], keys[i], column_hints, children[i], colored)
func is_text():
return false

View File

@ -12,11 +12,14 @@ func can_edit_value(value, type, property_hint, column_index) -> bool:
return hint_strings_array[column_index][0].begins_with("2/2:")
func _write_value_to_child(value, hint_arr : PackedStringArray, child : Label, colored : bool):
func _write_value_to_child(value, key, hint_arr : PackedStringArray, child : Label, colored : bool):
var value_str : String
if value == 0:
# Enum array hints have "2/3:" before list.
var found := hint_arr[0].find(":") + 1
super._write_value_to_child(hint_arr[0].substr(hint_arr[0].find(":") + 1), hint_arr, child, colored)
value_str = hint_arr[0].substr(hint_arr[0].find(":") + 1)
else:
super._write_value_to_child(hint_arr[value], hint_arr, child, colored)
value_str = hint_arr[value]
super(value_str, value_str, hint_arr, child, colored)

View File

@ -1,4 +1,5 @@
@tool
class_name UpgradeData
extends Resource
enum Attributes {
@ -16,6 +17,7 @@ enum Attributes {
@export var attributes : Array[Attributes]
@export var icon : Texture
@export var custom_scene : PackedScene
@export var prerequisites : Array[UpgradeData]
@export var color2 := Color.WHITE
@export var base_weight := 10.0
@export var is_notable := false

View File

@ -1,7 +1,10 @@
[gd_resource type="Resource" load_steps=3 format=3 uid="uid://2totlbwc40e8"]
[gd_resource type="Resource" script_class="UpgradeData" load_steps=6 format=3 uid="uid://2totlbwc40e8"]
[ext_resource type="Texture2D" uid="uid://djjpa8lluue1g" path="res://example/Random Upgrades/icons/all_icons/all_icons_5.tres" id="1_ardng"]
[ext_resource type="Script" path="res://example/Random Upgrades/upgrade_data.gd" id="2"]
[ext_resource type="Resource" uid="uid://rjxr4qtfc6qd" path="res://example/Random Upgrades/upgrades/weapon_fireball.tres" id="2_485ad"]
[ext_resource type="Resource" uid="uid://djqq1lqaevth5" path="res://example/Random Upgrades/upgrades/weapon_blizzard.tres" id="3_xnxxn"]
[ext_resource type="Resource" uid="uid://b0kdw067vtgvn" path="res://example/Random Upgrades/upgrades/weapon_lightning.tres" id="4_kn0kg"]
[resource]
resource_name = "Mastery: Magic"
@ -12,6 +15,7 @@ tags = Array[String](["magic", "mastery"])
type = 2
attributes = Array[int]([1, 1, 4])
icon = ExtResource("1_ardng")
prerequisites = Array[ExtResource("2")]([ExtResource("2_485ad"), ExtResource("3_xnxxn"), ExtResource("4_kn0kg")])
color2 = Color(0.407843, 0.192157, 0.827451, 1)
base_weight = 1.0
is_notable = true

View File

@ -1,7 +1,10 @@
[gd_resource type="Resource" load_steps=3 format=3 uid="uid://d1suh8iai43st"]
[gd_resource type="Resource" script_class="UpgradeData" load_steps=6 format=3 uid="uid://d1suh8iai43st"]
[ext_resource type="Texture2D" uid="uid://dfpwu4ra3fxgx" path="res://example/Random Upgrades/icons/all_icons/all_icons_2.tres" id="1_442ey"]
[ext_resource type="Script" path="res://example/Random Upgrades/upgrade_data.gd" id="2"]
[ext_resource type="Resource" uid="uid://cux4x0qopwiqk" path="res://example/Random Upgrades/upgrades/weapon_dagger.tres" id="2_kb33p"]
[ext_resource type="Resource" uid="uid://b78jqcpgef2ud" path="res://example/Random Upgrades/upgrades/weapon_axe.tres" id="3_tt25f"]
[ext_resource type="Resource" uid="uid://xl0yx8uq6bfp" path="res://example/Random Upgrades/upgrades/weapon_spear.tres" id="4_kpsn8"]
[resource]
resource_name = "Mastery: Strength"
@ -12,6 +15,7 @@ tags = Array[String](["strength", "mastery"])
type = 2
attributes = Array[int]([0, 0, 4])
icon = ExtResource("1_442ey")
prerequisites = Array[ExtResource("2")]([ExtResource("2_kb33p"), ExtResource("3_tt25f"), ExtResource("4_kpsn8")])
color2 = Color(0.992157, 0.941176, 0.2, 1)
base_weight = 1.0
is_notable = true