input_string.gd 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. @tool
  2. class_name ModToolInterfaceInputString
  3. extends ModToolInterfaceInput
  4. @export var is_editable := true: set = set_is_editable
  5. @export var input_text: String: set = set_input_text
  6. @export var input_placeholder: String: set = set_input_placeholder
  7. func set_input_text(new_text: String) -> void:
  8. input_text = new_text
  9. $"%Input".text = new_text
  10. emit_signal("value_changed", new_text, self)
  11. func set_input_placeholder(new_text: String) -> void:
  12. input_placeholder = new_text
  13. $"%Input".placeholder_text = new_text
  14. func set_is_editable(new_is_editable: bool) -> void:
  15. is_editable = new_is_editable
  16. $"%Input".editable = new_is_editable
  17. func get_input_value() -> String:
  18. return $"%Input".text.strip_edges()
  19. # Gets the values of a comma separated string as an Array,
  20. # strips any white space contained in this values.
  21. func get_input_as_array_from_comma_separated_string() -> Array:
  22. var string_split := get_input_value().split(",", false)
  23. var array := []
  24. for string in string_split:
  25. array.append(string.strip_edges())
  26. return array
  27. func validate(condition: bool) -> bool:
  28. # Check if input is required and empty
  29. if is_required and get_input_value() == "":
  30. is_valid = false
  31. return false
  32. # Invalidate field if the condition is not met
  33. self.is_valid = condition
  34. return is_valid
  35. func emit_value_changed() -> void:
  36. emit_signal("value_changed", get_input_value(), self)
  37. func _on_Input_text_changed(new_text: String) -> void:
  38. emit_value_changed()
  39. func _on_Mutiline_Input_text_changed() -> void:
  40. emit_value_changed()