editor_autoload_settings.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /**************************************************************************/
  2. /* editor_autoload_settings.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef EDITOR_AUTOLOAD_SETTINGS_H
  31. #define EDITOR_AUTOLOAD_SETTINGS_H
  32. #include "scene/gui/box_container.h"
  33. #include "scene/gui/button.h"
  34. #include "scene/gui/tree.h"
  35. class EditorFileDialog;
  36. class EditorAutoloadSettings : public VBoxContainer {
  37. GDCLASS(EditorAutoloadSettings, VBoxContainer);
  38. enum {
  39. BUTTON_OPEN,
  40. BUTTON_MOVE_UP,
  41. BUTTON_MOVE_DOWN,
  42. BUTTON_DELETE
  43. };
  44. String path = "res://";
  45. String autoload_changed = "autoload_changed";
  46. struct AutoloadInfo {
  47. String name;
  48. String path;
  49. bool is_singleton = false;
  50. bool in_editor = false;
  51. int order = 0;
  52. Node *node = nullptr;
  53. bool operator==(const AutoloadInfo &p_info) const {
  54. return order == p_info.order;
  55. }
  56. };
  57. List<AutoloadInfo> autoload_cache;
  58. bool updating_autoload = false;
  59. String selected_autoload;
  60. Tree *tree = nullptr;
  61. LineEdit *autoload_add_name = nullptr;
  62. Button *add_autoload = nullptr;
  63. LineEdit *autoload_add_path = nullptr;
  64. Label *error_message = nullptr;
  65. Button *browse_button = nullptr;
  66. EditorFileDialog *file_dialog = nullptr;
  67. bool _autoload_name_is_valid(const String &p_name, String *r_error = nullptr);
  68. void _autoload_add();
  69. void _autoload_selected();
  70. void _autoload_edited();
  71. void _autoload_button_pressed(Object *p_item, int p_column, int p_button, MouseButton p_mouse_button);
  72. void _autoload_activated();
  73. void _autoload_path_text_changed(const String &p_path);
  74. void _autoload_text_submitted(const String &p_name);
  75. void _autoload_text_changed(const String &p_name);
  76. void _autoload_open(const String &fpath);
  77. void _autoload_file_callback(const String &p_path);
  78. Node *_create_autoload(const String &p_path);
  79. void _script_created(Ref<Script> p_script);
  80. Variant get_drag_data_fw(const Point2 &p_point, Control *p_control);
  81. bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_control) const;
  82. void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_control);
  83. void _set_autoload_add_path(const String &p_text);
  84. void _browse_autoload_add_path();
  85. protected:
  86. void _notification(int p_what);
  87. static void _bind_methods();
  88. public:
  89. void init_autoloads();
  90. void update_autoload();
  91. bool autoload_add(const String &p_name, const String &p_path);
  92. void autoload_remove(const String &p_name);
  93. LineEdit *get_path_box() const;
  94. EditorAutoloadSettings();
  95. ~EditorAutoloadSettings();
  96. };
  97. #endif // EDITOR_AUTOLOAD_SETTINGS_H