No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

timeline_picker.gd 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. tool
  2. extends EditorProperty
  3. # The main control for editing the property.
  4. var timelines_dropdown = MenuButton.new()
  5. # An internal value of the property.
  6. var current_value = ''
  7. # A guard against internal changes when the property is updated.
  8. var updating = false
  9. func _init():
  10. # Add the control as a direct child of EditorProperty node.
  11. add_child(timelines_dropdown)
  12. # Make sure the control is able to retain the focus.
  13. add_focusable(timelines_dropdown)
  14. # Setup the initial state and connect to the signal to track changes.
  15. timelines_dropdown.connect("about_to_show", self, "_about_to_show_menu")
  16. timelines_dropdown.get_popup().connect("index_pressed", self, '_on_timeline_selected')
  17. func _about_to_show_menu():
  18. # Ignore the signal if the property is currently being updated.
  19. if (updating):
  20. return
  21. # Adding timelines
  22. timelines_dropdown.get_popup().clear()
  23. var index = 0
  24. for c in DialogicUtil.get_timeline_list():
  25. timelines_dropdown.get_popup().add_item(c['name'])
  26. timelines_dropdown.get_popup().set_item_metadata(index, {'file': c['file'], 'color': c['color']})
  27. index += 1
  28. func _on_timeline_selected(index):
  29. var text = timelines_dropdown.get_popup().get_item_text(index)
  30. var metadata = timelines_dropdown.get_popup().get_item_metadata(index)
  31. current_value = metadata['file']
  32. timelines_dropdown.text = text
  33. emit_changed(get_edited_property(), current_value)
  34. func update_property():
  35. # Read the current value from the property.
  36. var new_value = get_edited_object()[get_edited_property()]
  37. if (new_value == current_value):
  38. return
  39. # Update the control with the new value.
  40. updating = true
  41. current_value = new_value
  42. # Checking for the display name
  43. for c in DialogicUtil.get_timeline_list():
  44. if c['file'] == current_value:
  45. timelines_dropdown.text = c['name']
  46. updating = false