add full functionality to add and edit groups in group view

This commit is contained in:
Lera Elvoé 2023-03-08 10:24:34 +03:00
parent f0ce658518
commit 66f0585b3a
Signed by: yagich
SSH Key Fingerprint: SHA256:6xjGb6uA7lAVcULa7byPEN//rQ0wPoG+UzYVMfZnbvc
6 changed files with 62 additions and 9 deletions

View File

@ -61,6 +61,10 @@ func set_text(text: String) -> void:
header_text_label.text = text header_text_label.text = text
func get_text() -> String:
return header_text_label.text
func set_description(text: String) -> void: func set_description(text: String) -> void:
if text == "": if text == "":
description_label.visible = false description_label.visible = false
@ -84,6 +88,8 @@ func set_children_visible(p_visible: bool) -> void:
add_install_button_container.visible = p_visible add_install_button_container.visible = p_visible
inner_separator.visible = p_visible inner_separator.visible = p_visible
description_label.visible = p_visible && !description_label.text.is_empty()
func add_custom(control: Control) -> void: func add_custom(control: Control) -> void:
header_custom_control_container.add_child(control) header_custom_control_container.add_child(control)

View File

@ -33,3 +33,10 @@ func clear() -> void:
func(c: OverrideEditorSettingsMenuItem): func(c: OverrideEditorSettingsMenuItem):
c.queue_free() c.queue_free()
) )
func fill_from_dictionary(overrides: Dictionary) -> void:
for override in overrides:
var item: OverrideEditorSettingsMenuItem = ITEM_SCENE.instantiate()
add_item(item)
item.fill(override, overrides[override])

View File

@ -19,6 +19,11 @@ func _ready() -> void:
func get_property() -> Dictionary: func get_property() -> Dictionary:
var prop_name = property_name_line_edit.text var prop_name = property_name_line_edit.text
var value = str_to_var(prop_name) var value = str_to_var(property_value_line_edit.text)
return {prop_name: value} return {prop_name: value}
func fill(key: String, value: Variant) -> void:
property_name_line_edit.text = key
property_value_line_edit.text = var_to_str(value)

View File

@ -23,3 +23,18 @@ func get_group_metadata() -> GroupMetadata:
group_metadata.settings_overrides = override_editor_settings_menu.get_overrides() group_metadata.settings_overrides = override_editor_settings_menu.get_overrides()
return group_metadata return group_metadata
func fill_from_group_metadata(p_name: String) -> void:
name_line_edit.text = p_name
icon_path_line_edit.text = group_metadata.icon_path
description_text_edit.text = group_metadata.description
override_editor_settings_menu.fill_from_dictionary(group_metadata.settings_overrides)
func clear_ok_button_connections() -> void:
for connection in get_signal_connection_list("confirmed"):
var callable := connection["callable"] as Callable
var _signal := connection["signal"] as Signal
_signal.disconnect(callable)

View File

@ -6,14 +6,14 @@
[node name="GroupEditDialog" type="ConfirmationDialog"] [node name="GroupEditDialog" type="ConfirmationDialog"]
initial_position = 1 initial_position = 1
title = "Edit Group" title = "Edit Group"
size = Vector2i(678, 411) size = Vector2i(678, 419)
script = ExtResource("1_ic3yh") script = ExtResource("1_ic3yh")
[node name="VBoxContainer" type="VBoxContainer" parent="."] [node name="VBoxContainer" type="VBoxContainer" parent="."]
offset_left = 8.0 offset_left = 12.0
offset_top = 8.0 offset_top = 12.0
offset_right = 670.0 offset_right = 666.0
offset_bottom = 362.0 offset_bottom = 366.0
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"] [node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
layout_mode = 2 layout_mode = 2

View File

@ -14,14 +14,16 @@ func _ready() -> void:
new_group_button.pressed.connect(add_new_group) new_group_button.pressed.connect(add_new_group)
group_edit_dialog.canceled.connect(group_edit_dialog.clear_ok_button_connections)
func add_new_group():
func add_new_group() -> void:
group_edit_dialog.clear() group_edit_dialog.clear()
group_edit_dialog.ok_button_text = "Create" group_edit_dialog.ok_button_text = "Create"
group_edit_dialog.confirmed.connect( group_edit_dialog.confirmed.connect(
func(): func():
var gm := group_edit_dialog.group_metadata var gm := group_edit_dialog.get_group_metadata()
# TODO: hack, redo later # TODO: hack, redo later
var group_name := group_edit_dialog.name_line_edit.text var group_name := group_edit_dialog.name_line_edit.text
@ -30,6 +32,24 @@ func add_new_group():
group_menus_container.add_child(group_menu) group_menus_container.add_child(group_menu)
group_menu.setup_from_metadata(group_name, gm) group_menu.setup_from_metadata(group_name, gm)
) group_menu.edit_group_button_pressed.connect(edit_group.bind(group_menu))
, CONNECT_ONE_SHOT)
group_edit_dialog.show()
func edit_group(group_menu: GroupMenu) -> void:
group_edit_dialog.clear()
group_edit_dialog.ok_button_text = "OK"
var group_name := group_menu.get_text()
group_edit_dialog.group_metadata = group_menu.group_metadata
group_edit_dialog.fill_from_group_metadata(group_name)
group_edit_dialog.confirmed.connect(
func():
group_menu.setup_from_metadata(group_name, group_edit_dialog.get_group_metadata())
, CONNECT_ONE_SHOT)
group_edit_dialog.show() group_edit_dialog.show()