editor_settings_dialog.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /**************************************************************************/
  2. /* editor_settings_dialog.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. #pragma once
  31. #include "editor/inspector/editor_inspector.h"
  32. #include "scene/gui/dialogs.h"
  33. class CheckButton;
  34. class EditorEventSearchBar;
  35. class EventListenerLineEdit;
  36. class InputEventConfigurationDialog;
  37. class PanelContainer;
  38. class SectionedInspector;
  39. class TabContainer;
  40. class TextureRect;
  41. class Tree;
  42. class TreeItem;
  43. class EditorSettingsDialog : public AcceptDialog {
  44. GDCLASS(EditorSettingsDialog, AcceptDialog);
  45. bool updating = false;
  46. TabContainer *tabs = nullptr;
  47. Control *tab_general = nullptr;
  48. Control *tab_shortcuts = nullptr;
  49. LineEdit *search_box = nullptr;
  50. CheckButton *advanced_switch = nullptr;
  51. SectionedInspector *inspector = nullptr;
  52. EditorEventSearchBar *shortcut_search_bar = nullptr;
  53. // Shortcuts
  54. enum ShortcutButton {
  55. SHORTCUT_ADD,
  56. SHORTCUT_EDIT,
  57. SHORTCUT_ERASE,
  58. SHORTCUT_REVERT
  59. };
  60. Tree *shortcuts = nullptr;
  61. InputEventConfigurationDialog *shortcut_editor = nullptr;
  62. bool is_editing_action = false;
  63. String current_edited_identifier;
  64. Array current_events;
  65. int current_event_index = -1;
  66. Timer *timer = nullptr;
  67. virtual void cancel_pressed() override;
  68. virtual void ok_pressed() override;
  69. void _settings_changed();
  70. void _settings_property_edited(const String &p_name);
  71. void _settings_save();
  72. virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
  73. void _notification(int p_what);
  74. void _update_icons();
  75. void _event_config_confirmed();
  76. TreeItem *_create_shortcut_treeitem(TreeItem *p_parent, const String &p_shortcut_identifier, const String &p_display, Array &p_events, bool p_allow_revert, bool p_is_common, bool p_is_collapsed);
  77. Array _event_list_to_array_helper(const List<Ref<InputEvent>> &p_events);
  78. void _update_builtin_action(const String &p_name, const Array &p_events);
  79. void _update_shortcut_events(const String &p_path, const Array &p_events);
  80. Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
  81. bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
  82. void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
  83. void _tabs_tab_changed(int p_tab);
  84. void _focus_current_search_box();
  85. void _advanced_toggled(bool p_button_pressed);
  86. void _update_dynamic_property_hints();
  87. PropertyInfo _create_mouse_shortcut_property_info(const String &p_property_name, const String &p_shortcut_1_name, const String &p_shortcut_2_name);
  88. String _get_shortcut_button_string(const String &p_shortcut_name);
  89. bool _should_display_shortcut(const String &p_name, const Array &p_events, bool p_match_localized_name) const;
  90. void _update_shortcuts();
  91. void _shortcut_button_pressed(Object *p_item, int p_column, int p_idx, MouseButton p_button = MouseButton::LEFT);
  92. void _shortcut_cell_double_clicked();
  93. static void _set_shortcut_input(const String &p_name, Ref<InputEventKey> &p_event);
  94. static void _undo_redo_callback(void *p_self, const String &p_name);
  95. Label *restart_label = nullptr;
  96. TextureRect *restart_icon = nullptr;
  97. PanelContainer *restart_container = nullptr;
  98. Button *restart_close_button = nullptr;
  99. void _editor_restart_request();
  100. void _editor_restart();
  101. void _editor_restart_close();
  102. protected:
  103. static void _bind_methods();
  104. public:
  105. void popup_edit_settings();
  106. static void update_navigation_preset();
  107. EditorSettingsDialog();
  108. };
  109. class EditorSettingsPropertyWrapper : public EditorProperty {
  110. GDCLASS(EditorSettingsPropertyWrapper, EditorProperty);
  111. String property;
  112. EditorProperty *editor_property = nullptr;
  113. BoxContainer *container = nullptr;
  114. HBoxContainer *override_info = nullptr;
  115. Label *override_label = nullptr;
  116. Button *goto_button = nullptr;
  117. Button *remove_button = nullptr;
  118. bool requires_restart = false;
  119. void _update_override();
  120. void _create_override();
  121. void _remove_override();
  122. protected:
  123. void _notification(int p_what);
  124. public:
  125. static inline Callable restart_request_callback;
  126. virtual void update_property() override;
  127. void setup(const String &p_property, EditorProperty *p_editor_property, bool p_requires_restart);
  128. };
  129. class EditorSettingsInspectorPlugin : public EditorInspectorPlugin {
  130. GDCLASS(EditorSettingsInspectorPlugin, EditorInspectorPlugin);
  131. Object *current_object = nullptr;
  132. public:
  133. SectionedInspector *inspector = nullptr;
  134. virtual bool can_handle(Object *p_object) override;
  135. virtual bool parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const BitField<PropertyUsageFlags> p_usage, const bool p_wide = false) override;
  136. };