TileModifierMenu.gd 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. extends PanelContainer
  2. var editing_node: Node = null
  3. var properties := []
  4. var override_scenes := {}
  5. const VALUES := {
  6. TYPE_BOOL: preload("uid://diqn7e5hqpbsk"),
  7. "PackedScene": preload("uid://clfxxcxk3fobh"),
  8. TYPE_INT: preload("uid://4pi0tdru3c4v")
  9. }
  10. var active := false
  11. signal closed
  12. signal open_scene_ref_tile_menu(scene_ref: TilePropertySceneRef)
  13. signal edit_track_path(track_path: TilePropertyTrackPath)
  14. var can_exit := true:
  15. set(value):
  16. can_exit = value
  17. pass
  18. func _ready() -> void:
  19. pass
  20. func _process(_delta: float) -> void:
  21. if active and (Input.is_action_just_pressed("ui_back") or Input.is_action_just_pressed("editor_open_menu")):
  22. print(can_exit)
  23. if can_exit:
  24. close()
  25. else:
  26. pass
  27. func open() -> void:
  28. active = true
  29. size = Vector2.ZERO
  30. add_properties()
  31. show()
  32. func add_properties() -> void:
  33. for i in properties:
  34. var property: TilePropertyContainer = null
  35. if override_scenes.has(i.name):
  36. property = override_scenes[i.name].instantiate()
  37. if i.type == TYPE_STRING:
  38. property = preload("uid://l0lulnbn7v6b").instantiate()
  39. property.editing_start.connect(set_can_exit.bind(false))
  40. property.editing_finished.connect(set_can_exit.bind(true))
  41. if i.hint_string == "PackedScene":
  42. property = preload("uid://clfxxcxk3fobh").instantiate()
  43. if i.hint == PROPERTY_HINT_ENUM:
  44. property = preload("uid://87lcnsa0epi1").instantiate()
  45. var values := {}
  46. var idx := 0
  47. for x in i.hint_string.split(","):
  48. property.values.set(idx, x)
  49. idx += 1
  50. elif (i.type == TYPE_INT or i.type == TYPE_FLOAT) and i.hint_string.contains(","):
  51. if override_scenes.has(i.name):
  52. property = override_scenes[i.name].instantiate()
  53. else: property = preload("uid://4pi0tdru3c4v").instantiate()
  54. var values = i.hint_string.split(",")
  55. property.min_value = float(values[0])
  56. property.max_value = float(values[1])
  57. if values.size() >= 3:
  58. property.property_step = float(values[2])
  59. elif i.type == TYPE_BOOL:
  60. property = preload("uid://diqn7e5hqpbsk").instantiate()
  61. if property != null:
  62. property.exit_changed.connect(set_can_exit)
  63. property.tile_property_name = i["name"]
  64. %Container.add_child(property)
  65. property.owner = self
  66. property.set_starting_value(editing_node.get(property.tile_property_name))
  67. property.value_changed.connect(value_changed)
  68. property.editing_node = editing_node
  69. if property is TilePropertySceneRef:
  70. property.open_tile_menu.connect(open_scene_ref)
  71. await get_tree().physics_frame
  72. $Container.update_minimum_size()
  73. update_minimum_size()
  74. func set_can_exit(new_value := false) -> void:
  75. print(new_value)
  76. if new_value:
  77. pass
  78. can_exit = new_value
  79. func open_scene_ref(scene_ref: TilePropertySceneRef) -> void:
  80. open_scene_ref_tile_menu.emit(scene_ref)
  81. can_exit = false
  82. func value_changed(property, new_value) -> void:
  83. can_exit = true
  84. editing_node.set(property.tile_property_name, new_value)
  85. func close() -> void:
  86. hide()
  87. active = false
  88. await get_tree().create_timer(0.1).timeout
  89. closed.emit()
  90. for i in %Container.get_children():
  91. i.queue_free()