mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-07-03 18:51:16 +00:00
Updated dialogic
This commit is contained in:
parent
1d11462073
commit
cbb82512ee
483 changed files with 5743 additions and 2177 deletions
|
|
@ -6,12 +6,13 @@ extends DialogicVisualEditorField
|
|||
## SETTINGS
|
||||
@export var placeholder_text := "Select Resource"
|
||||
@export var empty_text := ""
|
||||
enum Modes {PURE_STRING, PRETTY_PATH, IDENTIFIER}
|
||||
enum Modes {PURE_STRING, PRETTY_PATH, IDENTIFIER, ANY_VALID_STRING}
|
||||
@export var mode := Modes.PURE_STRING
|
||||
@export var fit_text_length := true
|
||||
var collapse_when_empty := false
|
||||
var valid_file_drop_extension := ""
|
||||
var get_suggestions_func: Callable
|
||||
var suggestions_func: Callable
|
||||
var validation_func: Callable
|
||||
|
||||
var resource_icon: Texture = null:
|
||||
get:
|
||||
|
|
@ -21,8 +22,13 @@ var resource_icon: Texture = null:
|
|||
%Icon.texture = new_icon
|
||||
|
||||
## STATE
|
||||
var current_value: String
|
||||
var current_value: String:
|
||||
set(value):
|
||||
if current_value != value:
|
||||
current_value = value
|
||||
current_value_updated = true
|
||||
var current_selected := 0
|
||||
var current_value_updated := false
|
||||
|
||||
## SUGGESTIONS ITEM LIST
|
||||
var _v_separation := 0
|
||||
|
|
@ -38,12 +44,15 @@ var _max_height := 200 * DialogicUtil.get_editor_scale()
|
|||
func _set_value(value:Variant) -> void:
|
||||
if value == null or value.is_empty():
|
||||
%Search.text = empty_text
|
||||
update_error_tooltip('')
|
||||
else:
|
||||
match mode:
|
||||
Modes.PRETTY_PATH:
|
||||
%Search.text = DialogicUtil.pretty_name(value)
|
||||
Modes.IDENTIFIER when value.begins_with("res://"):
|
||||
%Search.text = DialogicResourceUtil.get_unique_identifier(value)
|
||||
%Search.text = DialogicResourceUtil.get_unique_identifier_by_path(value)
|
||||
Modes.ANY_VALID_STRING when validation_func:
|
||||
%Search.text = validation_func.call(value).get('valid_text', value)
|
||||
_:
|
||||
%Search.text = str(value)
|
||||
|
||||
|
|
@ -51,11 +60,11 @@ func _set_value(value:Variant) -> void:
|
|||
current_value = str(value)
|
||||
|
||||
|
||||
|
||||
func _load_display_info(info:Dictionary) -> void:
|
||||
valid_file_drop_extension = info.get('file_extension', '')
|
||||
collapse_when_empty = info.get('collapse_when_empty', false)
|
||||
get_suggestions_func = info.get('suggestions_func', get_suggestions_func)
|
||||
suggestions_func = info.get('suggestions_func', suggestions_func)
|
||||
validation_func = info.get('validation_func', validation_func)
|
||||
empty_text = info.get('empty_text', '')
|
||||
placeholder_text = info.get('placeholder', 'Select Resource')
|
||||
mode = info.get("mode", 0)
|
||||
|
|
@ -101,16 +110,59 @@ func _ready() -> void:
|
|||
if resource_icon == null:
|
||||
self.resource_icon = null
|
||||
|
||||
var error_label_style := StyleBoxFlat.new()
|
||||
error_label_style.bg_color = get_theme_color('background', 'Editor')
|
||||
error_label_style.border_color = get_theme_color('error_color', 'Editor')
|
||||
error_label_style.set_border_width_all(1)
|
||||
error_label_style.set_corner_radius_all(4)
|
||||
error_label_style.set_content_margin_all(6)
|
||||
|
||||
%ErrorTooltip.add_theme_stylebox_override('normal', error_label_style)
|
||||
|
||||
|
||||
func change_to_empty() -> void:
|
||||
update_error_tooltip('')
|
||||
value_changed.emit(property_name, "")
|
||||
|
||||
|
||||
func validate() -> void:
|
||||
if mode == Modes.ANY_VALID_STRING and validation_func:
|
||||
var validation_result: Dictionary = validation_func.call(current_value)
|
||||
current_value = validation_result.get('valid_text', current_value)
|
||||
update_error_tooltip(validation_result.get('error_tooltip', ''))
|
||||
|
||||
|
||||
func update_error_tooltip(text: String) -> void:
|
||||
%ErrorTooltip.text = text
|
||||
if text.is_empty():
|
||||
%ErrorTooltip.hide()
|
||||
%Search.remove_theme_color_override("font_color")
|
||||
else:
|
||||
%ErrorTooltip.reset_size()
|
||||
%ErrorTooltip.global_position = global_position - Vector2(0, %ErrorTooltip.size.y + 4)
|
||||
%ErrorTooltip.show()
|
||||
%Search.add_theme_color_override("font_color", get_theme_color('error_color', 'Editor'))
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region SEARCH & SUGGESTION POPUP
|
||||
################################################################################
|
||||
|
||||
func _on_Search_text_entered(new_text:String) -> void:
|
||||
if mode == Modes.ANY_VALID_STRING:
|
||||
if validation_func:
|
||||
var validation_result: Dictionary = validation_func.call(new_text)
|
||||
new_text = validation_result.get('valid_text', new_text)
|
||||
update_error_tooltip(validation_result.get('error_tooltip', ''))
|
||||
|
||||
set_value(new_text)
|
||||
|
||||
value_changed.emit(property_name, current_value)
|
||||
current_value_updated = false
|
||||
hide_suggestions()
|
||||
return
|
||||
|
||||
if %Suggestions.get_item_count():
|
||||
if %Suggestions.is_anything_selected():
|
||||
suggestion_selected(%Suggestions.get_selected_items()[0])
|
||||
|
|
@ -123,21 +175,41 @@ func _on_Search_text_entered(new_text:String) -> void:
|
|||
func _on_Search_text_changed(new_text:String, just_update:bool = false) -> void:
|
||||
%Suggestions.clear()
|
||||
|
||||
if new_text == "" and !just_update:
|
||||
if new_text == "" and not just_update:
|
||||
change_to_empty()
|
||||
else:
|
||||
%Search.show()
|
||||
|
||||
var suggestions: Dictionary = get_suggestions_func.call(new_text)
|
||||
if mode == Modes.ANY_VALID_STRING and !just_update:
|
||||
if validation_func:
|
||||
var validation_result: Dictionary = validation_func.call(new_text)
|
||||
new_text = validation_result.get('valid_text', new_text)
|
||||
update_error_tooltip(validation_result.get('error_tooltip', ''))
|
||||
|
||||
current_value = new_text
|
||||
|
||||
if just_update and new_text.is_empty() and %Search.text.ends_with("."):
|
||||
new_text = %Search.text
|
||||
|
||||
var suggestions: Dictionary = suggestions_func.call(new_text)
|
||||
|
||||
var line_length := 0
|
||||
var idx := 0
|
||||
|
||||
if new_text and mode == Modes.ANY_VALID_STRING and not new_text in suggestions.keys():
|
||||
%Suggestions.add_item(new_text, get_theme_icon('GuiScrollArrowRight', 'EditorIcons'))
|
||||
%Suggestions.set_item_metadata(idx, new_text)
|
||||
line_length = get_theme_font('font', 'Label').get_string_size(
|
||||
new_text, HORIZONTAL_ALIGNMENT_LEFT, -1, get_theme_font_size("font_size", 'Label')
|
||||
).x + %Suggestions.fixed_icon_size.x * %Suggestions.get_icon_scale() + _icon_margin * 2 + _h_separation
|
||||
idx += 1
|
||||
|
||||
for element in suggestions:
|
||||
if new_text.is_empty() or new_text.to_lower() in element.to_lower() or new_text.to_lower() in str(suggestions[element].value).to_lower() or new_text.to_lower() in suggestions[element].get('tooltip', '').to_lower():
|
||||
var curr_line_length: int = 0
|
||||
curr_line_length = get_theme_font('font', 'Label').get_string_size(
|
||||
curr_line_length = int(get_theme_font('font', 'Label').get_string_size(
|
||||
element, HORIZONTAL_ALIGNMENT_LEFT, -1, get_theme_font_size("font_size", 'Label')
|
||||
).x
|
||||
).x)
|
||||
|
||||
%Suggestions.add_item(element)
|
||||
if suggestions[element].has('icon'):
|
||||
|
|
@ -166,7 +238,7 @@ func _on_Search_text_changed(new_text:String, just_update:bool = false) -> void:
|
|||
|
||||
var total_height: int = 0
|
||||
for item in %Suggestions.item_count:
|
||||
total_height += _line_height * DialogicUtil.get_editor_scale() + _v_separation
|
||||
total_height += int(_line_height * DialogicUtil.get_editor_scale() + _v_separation)
|
||||
total_height += _v_separation * 2
|
||||
if total_height > _max_height:
|
||||
line_length += %Suggestions.get_v_scroll_bar().get_minimum_size().x
|
||||
|
|
@ -182,7 +254,7 @@ func _on_Search_text_changed(new_text:String, just_update:bool = false) -> void:
|
|||
%Suggestions.size.x = max(%PanelContainer.size.x, line_length)
|
||||
|
||||
|
||||
func suggestion_selected(index: int, position := Vector2(), button_index := MOUSE_BUTTON_LEFT) -> void:
|
||||
func suggestion_selected(index: int, _position := Vector2(), button_index := MOUSE_BUTTON_LEFT) -> void:
|
||||
if button_index != MOUSE_BUTTON_LEFT:
|
||||
return
|
||||
if %Suggestions.is_item_disabled(index):
|
||||
|
|
@ -196,10 +268,12 @@ func suggestion_selected(index: int, position := Vector2(), button_index := MOUS
|
|||
else:
|
||||
current_value = %Suggestions.get_item_metadata(index)
|
||||
|
||||
update_error_tooltip('')
|
||||
hide_suggestions()
|
||||
|
||||
grab_focus()
|
||||
value_changed.emit(property_name, current_value)
|
||||
current_value_updated = false
|
||||
|
||||
|
||||
func _input(event:InputEvent) -> void:
|
||||
|
|
@ -256,12 +330,17 @@ func _on_search_focus_entered() -> void:
|
|||
_on_Search_text_changed("")
|
||||
%Search.call_deferred('select_all')
|
||||
%Focus.show()
|
||||
validate()
|
||||
|
||||
|
||||
func _on_search_focus_exited() -> void:
|
||||
%Focus.hide()
|
||||
if !%Suggestions.get_global_rect().has_point(get_global_mouse_position()):
|
||||
hide_suggestions()
|
||||
validate()
|
||||
if current_value_updated:
|
||||
value_changed.emit(property_name, current_value)
|
||||
current_value_updated = false
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
@ -269,7 +348,7 @@ func _on_search_focus_exited() -> void:
|
|||
#region DRAG AND DROP
|
||||
################################################################################
|
||||
|
||||
func _can_drop_data(position:Vector2, data:Variant) -> bool:
|
||||
func _can_drop_data(_position:Vector2, data:Variant) -> bool:
|
||||
if typeof(data) == TYPE_DICTIONARY and data.has('files') and len(data.files) == 1:
|
||||
if valid_file_drop_extension:
|
||||
if data.files[0].ends_with(valid_file_drop_extension):
|
||||
|
|
@ -279,11 +358,12 @@ func _can_drop_data(position:Vector2, data:Variant) -> bool:
|
|||
return false
|
||||
|
||||
|
||||
func _drop_data(position:Vector2, data:Variant) -> void:
|
||||
func _drop_data(_position:Vector2, data:Variant) -> void:
|
||||
var path := str(data.files[0])
|
||||
if mode == Modes.IDENTIFIER:
|
||||
path = DialogicResourceUtil.get_unique_identifier(path)
|
||||
path = DialogicResourceUtil.get_unique_identifier_by_path(path)
|
||||
_set_value(path)
|
||||
value_changed.emit(property_name, path)
|
||||
current_value_updated = false
|
||||
|
||||
#endregion
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue