replication_editor_plugin.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*************************************************************************/
  2. /* replication_editor_plugin.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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 REPLICATION_EDITOR_PLUGIN_H
  31. #define REPLICATION_EDITOR_PLUGIN_H
  32. #include "editor/editor_plugin.h"
  33. #include "editor/editor_spin_slider.h"
  34. #include "editor/property_selector.h"
  35. #include "../scene_replication_config.h"
  36. class ConfirmationDialog;
  37. class MultiplayerSynchronizer;
  38. class SceneTreeDialog;
  39. class Tree;
  40. class TreeItem;
  41. class ReplicationEditor : public VBoxContainer {
  42. GDCLASS(ReplicationEditor, VBoxContainer);
  43. private:
  44. MultiplayerSynchronizer *current = nullptr;
  45. AcceptDialog *error_dialog = nullptr;
  46. ConfirmationDialog *delete_dialog = nullptr;
  47. Button *add_pick_button = nullptr;
  48. Button *add_from_path_button = nullptr;
  49. LineEdit *np_line_edit = nullptr;
  50. Label *drop_label = nullptr;
  51. Ref<SceneReplicationConfig> config;
  52. NodePath deleting;
  53. Tree *tree = nullptr;
  54. PropertySelector *prop_selector = nullptr;
  55. SceneTreeDialog *pick_node = nullptr;
  56. NodePath adding_node_path;
  57. Button *pin = nullptr;
  58. Ref<Texture2D> _get_class_icon(const Node *p_node);
  59. void _add_pressed();
  60. void _tree_item_edited();
  61. void _tree_button_pressed(Object *p_item, int p_column, int p_id, MouseButton p_button);
  62. void _update_checked(const NodePath &p_prop, int p_column, bool p_checked);
  63. void _update_config();
  64. void _dialog_closed(bool p_confirmed);
  65. void _add_property(const NodePath &p_property, bool p_spawn = true, bool p_sync = true);
  66. void _pick_node_filter_text_changed(const String &p_newtext);
  67. void _pick_node_select_recursive(TreeItem *p_item, const String &p_filter, Vector<Node *> &p_select_candidates);
  68. void _pick_node_filter_input(const Ref<InputEvent> &p_ie);
  69. void _pick_node_selected(NodePath p_path);
  70. void _pick_new_property();
  71. void _pick_node_property_selected(String p_name);
  72. bool _can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
  73. void _drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
  74. void _add_sync_property(String p_path);
  75. protected:
  76. static void _bind_methods();
  77. void _notification(int p_what);
  78. public:
  79. void edit(MultiplayerSynchronizer *p_object);
  80. MultiplayerSynchronizer *get_current() const { return current; }
  81. Button *get_pin() { return pin; }
  82. ReplicationEditor();
  83. ~ReplicationEditor() {}
  84. };
  85. class ReplicationEditorPlugin : public EditorPlugin {
  86. GDCLASS(ReplicationEditorPlugin, EditorPlugin);
  87. private:
  88. Button *button = nullptr;
  89. ReplicationEditor *repl_editor = nullptr;
  90. void _node_removed(Node *p_node);
  91. void _pinned();
  92. protected:
  93. void _notification(int p_what);
  94. public:
  95. virtual void edit(Object *p_object) override;
  96. virtual bool handles(Object *p_object) const override;
  97. virtual void make_visible(bool p_visible) override;
  98. ReplicationEditorPlugin();
  99. ~ReplicationEditorPlugin();
  100. };
  101. #endif // REPLICATION_EDITOR_PLUGIN_H