Added spoilers and entity/entity-array properties to property grid.
This commit is contained in:
@@ -74,11 +74,14 @@ func __sort_children():
|
||||
rows[rows.size() - 1].append(child)
|
||||
|
||||
child.rect_size = child.get_combined_minimum_size()
|
||||
column_widths[col] = max(column_widths[col], child.rect_size.x)
|
||||
|
||||
var full_size : Vector2 = child.rect_size + Vector2(constraints.padding_left + constraints.padding_right, \
|
||||
constraints.padding_top + constraints.padding_bottom)
|
||||
column_widths[col] = max(column_widths[col], full_size.x)
|
||||
|
||||
if child.size_flags_horizontal & Control.SIZE_EXPAND:
|
||||
column_expand[col] = max(column_expand[col], child.size_flags_stretch_ratio)
|
||||
row_width += child.rect_size.x
|
||||
row_width += full_size.x
|
||||
|
||||
col = col + constraints.colspan
|
||||
|
||||
@@ -100,22 +103,24 @@ func __sort_children():
|
||||
col = 0
|
||||
for child in row:
|
||||
var constraints := _get_constraints(child)
|
||||
child.rect_position = pos
|
||||
child.rect_position = pos + Vector2(constraints.padding_left, constraints.padding_top)
|
||||
|
||||
var width := 0.0
|
||||
for i in range(min(constraints.colspan, columns - col)):
|
||||
width += column_widths[col + i]
|
||||
|
||||
if child.size_flags_horizontal & Control.SIZE_FILL:
|
||||
child.rect_size.x = width
|
||||
child.rect_size.x = width - (constraints.padding_left + constraints.padding_right)
|
||||
pos.x += width
|
||||
|
||||
row_height = max(row_height, child.rect_size.y)
|
||||
var full_height : float = child.rect_size.y + constraints.padding_top + constraints.padding_bottom
|
||||
row_height = max(row_height, full_height)
|
||||
col = col + constraints.colspan
|
||||
|
||||
for child in row:
|
||||
if child.size_flags_vertical & Control.SIZE_FILL:
|
||||
child.rect_size.y = row_height
|
||||
var constraints := _get_constraints(child)
|
||||
child.rect_size.y = row_height - (constraints.padding_top + constraints.padding_bottom)
|
||||
|
||||
pos.y += row_height
|
||||
pos.x = 0.0
|
||||
|
||||
@@ -14,12 +14,10 @@ onready var __selected_entity_adapter := get_node_or_null(selected_entity_adapte
|
||||
func _ready():
|
||||
create_item() # invisible root
|
||||
hide_root = true
|
||||
columns = column_ids.size()
|
||||
select_mode = SELECT_ROW
|
||||
set_column_titles_visible(true)
|
||||
|
||||
for col in range(min(columns, column_titles.size())):
|
||||
set_column_title(col, column_titles[col])
|
||||
__update_columns()
|
||||
|
||||
connect("item_selected", self, "_on_item_selected")
|
||||
if __selected_entity_adapter != null:
|
||||
@@ -33,6 +31,9 @@ func add_entity(entity : Object) -> void:
|
||||
printerr("UIB_EntityTree: attempted to add invalid entity")
|
||||
return
|
||||
|
||||
if !column_ids:
|
||||
__columns_from_entity(entity)
|
||||
|
||||
var itm := create_item()
|
||||
itm.set_metadata(0, entity)
|
||||
var col := 0
|
||||
@@ -101,6 +102,24 @@ func __update_row(entity : Object, column := ""):
|
||||
|
||||
itm.set_text(col_idx, GDB_Property.get_prop_value_as_string(prop))
|
||||
|
||||
func __columns_from_entity(entity : Object) -> void:
|
||||
column_ids = []
|
||||
column_titles = []
|
||||
|
||||
for prop_id in GDB_Entity.get_entity_property_ids(entity):
|
||||
var prop : Object = entity.get_property_by_id(prop_id)
|
||||
if prop && prop.get_type() in [TYPE_STRING, TYPE_INT, TYPE_REAL, TYPE_BOOL] \
|
||||
&& !(GDB_Property.get_prop_flags(prop) & GDB_Property.FLAG_HIDDEN):
|
||||
column_ids.append(prop_id)
|
||||
column_titles.append(prop.get_name())
|
||||
|
||||
__update_columns()
|
||||
|
||||
func __update_columns() -> void:
|
||||
columns = max(1, column_ids.size())
|
||||
for col in range(min(columns, column_titles.size())):
|
||||
set_column_title(col, column_titles[col])
|
||||
|
||||
############
|
||||
# handlers #
|
||||
############
|
||||
|
||||
@@ -2,6 +2,8 @@ extends UIB_DynamicGridContainer
|
||||
|
||||
class_name UIB_PropertyList
|
||||
|
||||
const COLUMNS = 2
|
||||
|
||||
export(NodePath) var entity_adapter := ""
|
||||
|
||||
var entity : Object = null setget _set_entity
|
||||
@@ -13,7 +15,7 @@ onready var __entity_adapter := get_node_or_null(entity_adapter) as GDB_DataAdap
|
||||
# overrides #
|
||||
#############
|
||||
func _ready() -> void:
|
||||
self.columns = 2
|
||||
self.columns = COLUMNS
|
||||
|
||||
if __entity_adapter != null:
|
||||
__entity_adapter.connect("data_changed", self, "_on_entity_adapter_data_changed")
|
||||
@@ -22,13 +24,20 @@ func _ready() -> void:
|
||||
# overridables #
|
||||
################
|
||||
func _make_controls(property : Object) -> Array:
|
||||
if GDB_Property.get_prop_flags(property) & GDB_Property.FLAG_HIDDEN:
|
||||
return []
|
||||
|
||||
match property.get_type():
|
||||
GDB_Property.TYPE_HEADER:
|
||||
return _make_header(property)
|
||||
GDB_Property.TYPE_ENTITY:
|
||||
return _make_controls_entity(property)
|
||||
TYPE_INT, TYPE_REAL, TYPE_STRING:
|
||||
return _make_controls_simple(property)
|
||||
TYPE_BOOL:
|
||||
return _make_controls_bool(property)
|
||||
TYPE_ARRAY:
|
||||
return _make_controls_array(property)
|
||||
_:
|
||||
return []
|
||||
|
||||
@@ -37,9 +46,17 @@ func _make_header(property : Object) -> Array:
|
||||
var header := preload("res://addons/de.mewin.gduibasics/scenes/property_list/header.tscn").instance()
|
||||
header.label = property.get_name()
|
||||
header.texture = GDB_Property.get_prop_icon(property)
|
||||
get_constraints(header).colspan = self.columns
|
||||
get_constraints(header).colspan = COLUMNS
|
||||
return [header]
|
||||
|
||||
func _make_controls_entity(property : Object) -> Array:
|
||||
var spoiler := preload("res://addons/de.mewin.gduibasics/scenes/property_list/entity_spoiler.tscn").instance()
|
||||
spoiler.label = property.get_name()
|
||||
spoiler.entity = property.get_value()
|
||||
get_constraints(spoiler).colspan = COLUMNS
|
||||
get_constraints(spoiler).padding_left = 5
|
||||
return [spoiler]
|
||||
|
||||
func _make_controls_simple(property : Object) -> Array:
|
||||
var label := preload("res://addons/de.mewin.gduibasics/scenes/property_list/property_label.tscn").instance()
|
||||
label.label = property.get_name()
|
||||
@@ -57,11 +74,29 @@ func _make_controls_bool(property : Object) -> Array:
|
||||
var checkbox := UIB_PropertyCheckBox.new()
|
||||
checkbox.property = property
|
||||
checkbox.size_flags_horizontal |= SIZE_EXPAND
|
||||
checkbox.disabled = !(GDB_Property.get_prop_flags(property) & GDB_Property.FLAG_READONLY)
|
||||
get_constraints(checkbox).colspan = self.columns
|
||||
return [
|
||||
checkbox
|
||||
]
|
||||
|
||||
func _make_controls_array(property : Object) -> Array:
|
||||
match GDB_Property.get_prop_content_type(property):
|
||||
GDB_Property.TYPE_ENTITY:
|
||||
return _make_controls_entity_array(property)
|
||||
_:
|
||||
return []
|
||||
|
||||
func _make_controls_entity_array(property : Object) -> Array:
|
||||
var spoiler := preload("res://addons/de.mewin.gduibasics/scenes/property_list/entity_tree_spoiler.tscn").instance()
|
||||
spoiler.label = property.get_name()
|
||||
for entity in property.get_value():
|
||||
spoiler.add_entity(entity)
|
||||
spoiler.connect("child_created", self, "_on_entity_array_tree_created")
|
||||
get_constraints(spoiler).colspan = COLUMNS
|
||||
get_constraints(spoiler).padding_left = 5
|
||||
return [spoiler]
|
||||
|
||||
################
|
||||
# public stuff #
|
||||
################
|
||||
@@ -139,6 +174,9 @@ func __init_entity() -> void:
|
||||
if entity == null:
|
||||
return
|
||||
|
||||
var title_property := GDB_Entity.make_entity_title_property(entity)
|
||||
if title_property:
|
||||
pass
|
||||
for property in entity.get_properties():
|
||||
add_property(property)
|
||||
|
||||
@@ -162,6 +200,14 @@ func _set_entity(entity_ : Object) -> void:
|
||||
func _on_entity_adapter_data_changed() -> void:
|
||||
_set_entity(__entity_adapter.data)
|
||||
|
||||
func _on_entity_array_tree_created(tree : UIB_EntityTree) -> void:
|
||||
tree.connect("item_activated", self, "_on_entity_array_tree_item_activated", [tree])
|
||||
|
||||
func _on_entity_array_tree_item_activated(tree : UIB_EntityTree) -> void:
|
||||
var entity : Object = tree.get_selected_entity()
|
||||
if entity:
|
||||
_set_entity(entity)
|
||||
|
||||
###########
|
||||
# signals #
|
||||
###########
|
||||
|
||||
@@ -21,7 +21,7 @@ func _gui_input(event : InputEvent) -> void:
|
||||
#################
|
||||
func __init_property() -> void:
|
||||
text = __text_from_property()
|
||||
editable = (property != null)
|
||||
editable = (property != null && !(GDB_Property.get_prop_flags(property) & GDB_Property.FLAG_READONLY))
|
||||
__validate_text()
|
||||
|
||||
if property != null:
|
||||
|
||||
Reference in New Issue
Block a user