action_map_editor.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /**************************************************************************/
  2. /* action_map_editor.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 ACTION_MAP_EDITOR_H
  31. #define ACTION_MAP_EDITOR_H
  32. #include "scene/gui/control.h"
  33. class Button;
  34. class HBoxContainer;
  35. class EventListenerLineEdit;
  36. class LineEdit;
  37. class CheckButton;
  38. class AcceptDialog;
  39. class InputEventConfigurationDialog;
  40. class Tree;
  41. class ActionMapEditor : public Control {
  42. GDCLASS(ActionMapEditor, Control);
  43. public:
  44. struct ActionInfo {
  45. String name;
  46. Dictionary action;
  47. bool has_initial = false;
  48. Dictionary action_initial;
  49. Ref<Texture2D> icon = Ref<Texture2D>();
  50. bool editable = true;
  51. };
  52. private:
  53. enum ItemButton {
  54. BUTTON_ADD_EVENT,
  55. BUTTON_EDIT_EVENT,
  56. BUTTON_REMOVE_ACTION,
  57. BUTTON_REMOVE_EVENT,
  58. BUTTON_REVERT_ACTION,
  59. };
  60. Vector<ActionInfo> actions_cache;
  61. Tree *action_tree = nullptr;
  62. // Storing which action/event is currently being edited in the InputEventConfigurationDialog.
  63. Dictionary current_action;
  64. String current_action_name;
  65. int current_action_event_index = -1;
  66. // Popups
  67. InputEventConfigurationDialog *event_config_dialog = nullptr;
  68. AcceptDialog *message = nullptr;
  69. // Filtering and Adding actions
  70. bool show_builtin_actions = false;
  71. CheckButton *show_builtin_actions_checkbutton = nullptr;
  72. LineEdit *action_list_search = nullptr;
  73. EventListenerLineEdit *action_list_search_by_event = nullptr;
  74. HBoxContainer *add_hbox = nullptr;
  75. LineEdit *add_edit = nullptr;
  76. Button *add_button = nullptr;
  77. void _event_config_confirmed();
  78. void _add_action_pressed();
  79. void _add_edit_text_changed(const String &p_name);
  80. String _check_new_action_name(const String &p_name);
  81. bool _has_action(const String &p_name) const;
  82. void _add_action(const String &p_name);
  83. void _action_edited();
  84. void _tree_button_pressed(Object *p_item, int p_column, int p_id, MouseButton p_button);
  85. void _tree_item_activated();
  86. void _search_term_updated(const String &p_search_term);
  87. void _search_by_event(const Ref<InputEvent> &p_event);
  88. bool _should_display_action(const String &p_name, const Array &p_events) const;
  89. Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
  90. bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
  91. void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
  92. void _on_filter_focused();
  93. void _on_filter_unfocused();
  94. protected:
  95. void _notification(int p_what);
  96. static void _bind_methods();
  97. public:
  98. LineEdit *get_search_box() const;
  99. InputEventConfigurationDialog *get_configuration_dialog();
  100. // Dictionary represents an Action with "events" (Array) and "deadzone" (float) items. Pass with no param to update list from cached action map.
  101. void update_action_list(const Vector<ActionInfo> &p_action_infos = Vector<ActionInfo>());
  102. void show_message(const String &p_message);
  103. void set_show_builtin_actions(bool p_show);
  104. void use_external_search_box(LineEdit *p_searchbox);
  105. ActionMapEditor();
  106. };
  107. #endif // ACTION_MAP_EDITOR_H