replication_editor.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. /**************************************************************************/
  2. /* replication_editor.cpp */
  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. #include "replication_editor.h"
  31. #include "../multiplayer_synchronizer.h"
  32. #include "editor/editor_node.h"
  33. #include "editor/editor_scale.h"
  34. #include "editor/editor_settings.h"
  35. #include "editor/editor_string_names.h"
  36. #include "editor/editor_undo_redo_manager.h"
  37. #include "editor/gui/scene_tree_editor.h"
  38. #include "editor/inspector_dock.h"
  39. #include "editor/property_selector.h"
  40. #include "scene/gui/dialogs.h"
  41. #include "scene/gui/separator.h"
  42. #include "scene/gui/tree.h"
  43. void ReplicationEditor::_pick_node_filter_text_changed(const String &p_newtext) {
  44. TreeItem *root_item = pick_node->get_scene_tree()->get_scene_tree()->get_root();
  45. Vector<Node *> select_candidates;
  46. Node *to_select = nullptr;
  47. String filter = pick_node->get_filter_line_edit()->get_text();
  48. _pick_node_select_recursive(root_item, filter, select_candidates);
  49. if (!select_candidates.is_empty()) {
  50. for (int i = 0; i < select_candidates.size(); ++i) {
  51. Node *candidate = select_candidates[i];
  52. if (((String)candidate->get_name()).to_lower().begins_with(filter.to_lower())) {
  53. to_select = candidate;
  54. break;
  55. }
  56. }
  57. if (!to_select) {
  58. to_select = select_candidates[0];
  59. }
  60. }
  61. pick_node->get_scene_tree()->set_selected(to_select);
  62. }
  63. void ReplicationEditor::_pick_node_select_recursive(TreeItem *p_item, const String &p_filter, Vector<Node *> &p_select_candidates) {
  64. if (!p_item) {
  65. return;
  66. }
  67. NodePath np = p_item->get_metadata(0);
  68. Node *node = get_node(np);
  69. if (!p_filter.is_empty() && ((String)node->get_name()).findn(p_filter) != -1) {
  70. p_select_candidates.push_back(node);
  71. }
  72. TreeItem *c = p_item->get_first_child();
  73. while (c) {
  74. _pick_node_select_recursive(c, p_filter, p_select_candidates);
  75. c = c->get_next();
  76. }
  77. }
  78. void ReplicationEditor::_pick_node_filter_input(const Ref<InputEvent> &p_ie) {
  79. Ref<InputEventKey> k = p_ie;
  80. if (k.is_valid()) {
  81. switch (k->get_keycode()) {
  82. case Key::UP:
  83. case Key::DOWN:
  84. case Key::PAGEUP:
  85. case Key::PAGEDOWN: {
  86. pick_node->get_scene_tree()->get_scene_tree()->gui_input(k);
  87. pick_node->get_filter_line_edit()->accept_event();
  88. } break;
  89. default:
  90. break;
  91. }
  92. }
  93. }
  94. void ReplicationEditor::_pick_node_selected(NodePath p_path) {
  95. Node *root = current->get_node(current->get_root_path());
  96. ERR_FAIL_COND(!root);
  97. Node *node = get_node(p_path);
  98. ERR_FAIL_COND(!node);
  99. NodePath path_to = root->get_path_to(node);
  100. adding_node_path = path_to;
  101. prop_selector->select_property_from_instance(node);
  102. }
  103. void ReplicationEditor::_pick_new_property() {
  104. if (current == nullptr) {
  105. EditorNode::get_singleton()->show_warning(TTR("Select a replicator node in order to pick a property to add to it."));
  106. return;
  107. }
  108. Node *root = current->get_node(current->get_root_path());
  109. if (!root) {
  110. EditorNode::get_singleton()->show_warning(TTR("Not possible to add a new property to synchronize without a root."));
  111. return;
  112. }
  113. pick_node->popup_scenetree_dialog();
  114. pick_node->get_filter_line_edit()->clear();
  115. pick_node->get_filter_line_edit()->grab_focus();
  116. }
  117. void ReplicationEditor::_add_sync_property(String p_path) {
  118. config = current->get_replication_config();
  119. if (config.is_valid() && config->has_property(p_path)) {
  120. EditorNode::get_singleton()->show_warning(TTR("Property is already being synchronized."));
  121. return;
  122. }
  123. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  124. undo_redo->create_action(TTR("Add property to synchronizer"));
  125. if (config.is_null()) {
  126. config.instantiate();
  127. current->set_replication_config(config);
  128. undo_redo->add_do_method(current, "set_replication_config", config);
  129. undo_redo->add_undo_method(current, "set_replication_config", Ref<SceneReplicationConfig>());
  130. _update_config();
  131. }
  132. undo_redo->add_do_method(config.ptr(), "add_property", p_path);
  133. undo_redo->add_undo_method(config.ptr(), "remove_property", p_path);
  134. undo_redo->add_do_method(this, "_update_config");
  135. undo_redo->add_undo_method(this, "_update_config");
  136. undo_redo->commit_action();
  137. }
  138. void ReplicationEditor::_pick_node_property_selected(String p_name) {
  139. String adding_prop_path = String(adding_node_path) + ":" + p_name;
  140. _add_sync_property(adding_prop_path);
  141. }
  142. /// ReplicationEditor
  143. ReplicationEditor::ReplicationEditor() {
  144. set_v_size_flags(SIZE_EXPAND_FILL);
  145. set_custom_minimum_size(Size2(0, 200) * EDSCALE);
  146. delete_dialog = memnew(ConfirmationDialog);
  147. delete_dialog->connect("canceled", callable_mp(this, &ReplicationEditor::_dialog_closed).bind(false));
  148. delete_dialog->connect("confirmed", callable_mp(this, &ReplicationEditor::_dialog_closed).bind(true));
  149. add_child(delete_dialog);
  150. VBoxContainer *vb = memnew(VBoxContainer);
  151. vb->set_v_size_flags(SIZE_EXPAND_FILL);
  152. add_child(vb);
  153. pick_node = memnew(SceneTreeDialog);
  154. add_child(pick_node);
  155. pick_node->register_text_enter(pick_node->get_filter_line_edit());
  156. pick_node->set_title(TTR("Pick a node to synchronize:"));
  157. pick_node->connect("selected", callable_mp(this, &ReplicationEditor::_pick_node_selected));
  158. pick_node->get_filter_line_edit()->connect("text_changed", callable_mp(this, &ReplicationEditor::_pick_node_filter_text_changed));
  159. pick_node->get_filter_line_edit()->connect("gui_input", callable_mp(this, &ReplicationEditor::_pick_node_filter_input));
  160. prop_selector = memnew(PropertySelector);
  161. add_child(prop_selector);
  162. // Filter out properties that cannot be synchronized.
  163. // * RIDs do not match across network.
  164. // * Objects are too large for replication.
  165. Vector<Variant::Type> types = {
  166. Variant::BOOL,
  167. Variant::INT,
  168. Variant::FLOAT,
  169. Variant::STRING,
  170. Variant::VECTOR2,
  171. Variant::VECTOR2I,
  172. Variant::RECT2,
  173. Variant::RECT2I,
  174. Variant::VECTOR3,
  175. Variant::VECTOR3I,
  176. Variant::TRANSFORM2D,
  177. Variant::VECTOR4,
  178. Variant::VECTOR4I,
  179. Variant::PLANE,
  180. Variant::QUATERNION,
  181. Variant::AABB,
  182. Variant::BASIS,
  183. Variant::TRANSFORM3D,
  184. Variant::PROJECTION,
  185. Variant::COLOR,
  186. Variant::STRING_NAME,
  187. Variant::NODE_PATH,
  188. // Variant::RID,
  189. // Variant::OBJECT,
  190. Variant::SIGNAL,
  191. Variant::DICTIONARY,
  192. Variant::ARRAY,
  193. Variant::PACKED_BYTE_ARRAY,
  194. Variant::PACKED_INT32_ARRAY,
  195. Variant::PACKED_INT64_ARRAY,
  196. Variant::PACKED_FLOAT32_ARRAY,
  197. Variant::PACKED_FLOAT64_ARRAY,
  198. Variant::PACKED_STRING_ARRAY,
  199. Variant::PACKED_VECTOR2_ARRAY,
  200. Variant::PACKED_VECTOR3_ARRAY,
  201. Variant::PACKED_COLOR_ARRAY
  202. };
  203. prop_selector->set_type_filter(types);
  204. prop_selector->connect("selected", callable_mp(this, &ReplicationEditor::_pick_node_property_selected));
  205. HBoxContainer *hb = memnew(HBoxContainer);
  206. vb->add_child(hb);
  207. add_pick_button = memnew(Button);
  208. add_pick_button->connect("pressed", callable_mp(this, &ReplicationEditor::_pick_new_property));
  209. add_pick_button->set_text(TTR("Add property to sync..."));
  210. hb->add_child(add_pick_button);
  211. VSeparator *vs = memnew(VSeparator);
  212. vs->set_custom_minimum_size(Size2(30 * EDSCALE, 0));
  213. hb->add_child(vs);
  214. hb->add_child(memnew(Label(TTR("Path:"))));
  215. np_line_edit = memnew(LineEdit);
  216. np_line_edit->set_placeholder(":property");
  217. np_line_edit->set_h_size_flags(SIZE_EXPAND_FILL);
  218. np_line_edit->connect("text_submitted", callable_mp(this, &ReplicationEditor::_np_text_submitted));
  219. hb->add_child(np_line_edit);
  220. add_from_path_button = memnew(Button);
  221. add_from_path_button->connect("pressed", callable_mp(this, &ReplicationEditor::_add_pressed));
  222. add_from_path_button->set_text(TTR("Add from path"));
  223. hb->add_child(add_from_path_button);
  224. vs = memnew(VSeparator);
  225. vs->set_custom_minimum_size(Size2(30 * EDSCALE, 0));
  226. hb->add_child(vs);
  227. pin = memnew(Button);
  228. pin->set_theme_type_variation("FlatButton");
  229. pin->set_toggle_mode(true);
  230. hb->add_child(pin);
  231. tree = memnew(Tree);
  232. tree->set_hide_root(true);
  233. tree->set_columns(4);
  234. tree->set_column_titles_visible(true);
  235. tree->set_column_title(0, TTR("Properties"));
  236. tree->set_column_expand(0, true);
  237. tree->set_column_title(1, TTR("Spawn"));
  238. tree->set_column_expand(1, false);
  239. tree->set_column_custom_minimum_width(1, 100);
  240. tree->set_column_title(2, TTR("Replicate"));
  241. tree->set_column_custom_minimum_width(2, 100);
  242. tree->set_column_expand(2, false);
  243. tree->set_column_expand(3, false);
  244. tree->create_item();
  245. tree->connect("button_clicked", callable_mp(this, &ReplicationEditor::_tree_button_pressed));
  246. tree->connect("item_edited", callable_mp(this, &ReplicationEditor::_tree_item_edited));
  247. tree->set_v_size_flags(SIZE_EXPAND_FILL);
  248. vb->add_child(tree);
  249. drop_label = memnew(Label);
  250. drop_label->set_text(TTR("Add properties using the options above, or\ndrag them them from the inspector and drop them here."));
  251. drop_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  252. drop_label->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
  253. tree->add_child(drop_label);
  254. drop_label->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
  255. SET_DRAG_FORWARDING_CDU(tree, ReplicationEditor);
  256. }
  257. void ReplicationEditor::_bind_methods() {
  258. ClassDB::bind_method(D_METHOD("_update_config"), &ReplicationEditor::_update_config);
  259. ClassDB::bind_method(D_METHOD("_update_value", "property", "column", "value"), &ReplicationEditor::_update_value);
  260. }
  261. bool ReplicationEditor::_can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  262. Dictionary d = p_data;
  263. if (!d.has("type")) {
  264. return false;
  265. }
  266. String t = d["type"];
  267. if (t != "obj_property") {
  268. return false;
  269. }
  270. Object *obj = d["object"];
  271. if (!obj) {
  272. return false;
  273. }
  274. Node *node = Object::cast_to<Node>(obj);
  275. if (!node) {
  276. return false;
  277. }
  278. return true;
  279. }
  280. void ReplicationEditor::_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  281. if (current == nullptr) {
  282. EditorNode::get_singleton()->show_warning(TTR("Select a replicator node in order to pick a property to add to it."));
  283. return;
  284. }
  285. Node *root = current->get_node(current->get_root_path());
  286. if (!root) {
  287. EditorNode::get_singleton()->show_warning(TTR("Not possible to add a new property to synchronize without a root."));
  288. return;
  289. }
  290. Dictionary d = p_data;
  291. if (!d.has("type")) {
  292. return;
  293. }
  294. String t = d["type"];
  295. if (t != "obj_property") {
  296. return;
  297. }
  298. Object *obj = d["object"];
  299. if (!obj) {
  300. return;
  301. }
  302. Node *node = Object::cast_to<Node>(obj);
  303. if (!node) {
  304. return;
  305. }
  306. String path = root->get_path_to(node);
  307. path += ":" + String(d["property"]);
  308. _add_sync_property(path);
  309. }
  310. void ReplicationEditor::_notification(int p_what) {
  311. switch (p_what) {
  312. case NOTIFICATION_ENTER_TREE:
  313. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  314. add_theme_style_override("panel", EditorNode::get_singleton()->get_editor_theme()->get_stylebox(SNAME("panel"), SNAME("Panel")));
  315. add_pick_button->set_icon(get_theme_icon(SNAME("Add"), EditorStringName(EditorIcons)));
  316. pin->set_icon(get_theme_icon(SNAME("Pin"), EditorStringName(EditorIcons)));
  317. } break;
  318. }
  319. }
  320. void ReplicationEditor::_add_pressed() {
  321. if (!current) {
  322. EditorNode::get_singleton()->show_warning(TTR("Please select a MultiplayerSynchronizer first."));
  323. return;
  324. }
  325. if (current->get_root_path().is_empty()) {
  326. EditorNode::get_singleton()->show_warning(TTR("The MultiplayerSynchronizer needs a root path."));
  327. return;
  328. }
  329. String np_text = np_line_edit->get_text();
  330. if (np_text.is_empty()) {
  331. EditorNode::get_singleton()->show_warning(TTR("Property/path must not be empty."));
  332. return;
  333. }
  334. int idx = np_text.find(":");
  335. if (idx == -1) {
  336. np_text = ".:" + np_text;
  337. } else if (idx == 0) {
  338. np_text = "." + np_text;
  339. }
  340. NodePath path = NodePath(np_text);
  341. if (path.is_empty()) {
  342. EditorNode::get_singleton()->show_warning(vformat(TTR("Invalid property path: '%s'"), np_text));
  343. return;
  344. }
  345. _add_sync_property(path);
  346. }
  347. void ReplicationEditor::_np_text_submitted(const String &p_newtext) {
  348. _add_pressed();
  349. }
  350. void ReplicationEditor::_tree_item_edited() {
  351. TreeItem *ti = tree->get_edited();
  352. if (!ti || config.is_null()) {
  353. return;
  354. }
  355. int column = tree->get_edited_column();
  356. ERR_FAIL_COND(column < 1 || column > 2);
  357. const NodePath prop = ti->get_metadata(0);
  358. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  359. if (column == 1) {
  360. undo_redo->create_action(TTR("Set spawn property"));
  361. bool value = ti->is_checked(column);
  362. undo_redo->add_do_method(config.ptr(), "property_set_spawn", prop, value);
  363. undo_redo->add_undo_method(config.ptr(), "property_set_spawn", prop, !value);
  364. undo_redo->add_do_method(this, "_update_value", prop, column, value ? 1 : 0);
  365. undo_redo->add_undo_method(this, "_update_value", prop, column, value ? 1 : 0);
  366. undo_redo->commit_action();
  367. } else if (column == 2) {
  368. undo_redo->create_action(TTR("Set sync property"));
  369. int value = ti->get_range(column);
  370. int old_value = config->property_get_replication_mode(prop);
  371. // We have a hard limit of 64 watchable properties per synchronizer.
  372. if (value == SceneReplicationConfig::REPLICATION_MODE_ON_CHANGE && config->get_watch_properties().size() >= 64) {
  373. EditorNode::get_singleton()->show_warning(TTR("Each MultiplayerSynchronizer can have no more than 64 watched properties."));
  374. ti->set_range(column, old_value);
  375. return;
  376. }
  377. undo_redo->add_do_method(config.ptr(), "property_set_replication_mode", prop, value);
  378. undo_redo->add_undo_method(config.ptr(), "property_set_replication_mode", prop, old_value);
  379. undo_redo->add_do_method(this, "_update_value", prop, column, value);
  380. undo_redo->add_undo_method(this, "_update_value", prop, column, old_value);
  381. undo_redo->commit_action();
  382. } else {
  383. ERR_FAIL();
  384. }
  385. }
  386. void ReplicationEditor::_tree_button_pressed(Object *p_item, int p_column, int p_id, MouseButton p_button) {
  387. if (p_button != MouseButton::LEFT) {
  388. return;
  389. }
  390. TreeItem *ti = Object::cast_to<TreeItem>(p_item);
  391. if (!ti) {
  392. return;
  393. }
  394. deleting = ti->get_metadata(0);
  395. delete_dialog->set_text(TTR("Delete Property?") + "\n\"" + ti->get_text(0) + "\"");
  396. delete_dialog->popup_centered();
  397. }
  398. void ReplicationEditor::_dialog_closed(bool p_confirmed) {
  399. if (deleting.is_empty() || config.is_null()) {
  400. return;
  401. }
  402. if (p_confirmed) {
  403. const NodePath prop = deleting;
  404. int idx = config->property_get_index(prop);
  405. bool spawn = config->property_get_spawn(prop);
  406. SceneReplicationConfig::ReplicationMode mode = config->property_get_replication_mode(prop);
  407. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  408. undo_redo->create_action(TTR("Remove Property"));
  409. undo_redo->add_do_method(config.ptr(), "remove_property", prop);
  410. undo_redo->add_undo_method(config.ptr(), "add_property", prop, idx);
  411. undo_redo->add_undo_method(config.ptr(), "property_set_spawn", prop, spawn);
  412. undo_redo->add_undo_method(config.ptr(), "property_set_replication_mode", prop, mode);
  413. undo_redo->add_do_method(this, "_update_config");
  414. undo_redo->add_undo_method(this, "_update_config");
  415. undo_redo->commit_action();
  416. }
  417. deleting = NodePath();
  418. }
  419. void ReplicationEditor::_update_value(const NodePath &p_prop, int p_column, int p_value) {
  420. if (!tree->get_root()) {
  421. return;
  422. }
  423. TreeItem *ti = tree->get_root()->get_first_child();
  424. while (ti) {
  425. if (ti->get_metadata(0).operator NodePath() == p_prop) {
  426. if (p_column == 1) {
  427. ti->set_checked(p_column, p_value != 0);
  428. } else if (p_column == 2) {
  429. ti->set_range(p_column, p_value);
  430. }
  431. return;
  432. }
  433. ti = ti->get_next();
  434. }
  435. }
  436. void ReplicationEditor::_update_config() {
  437. deleting = NodePath();
  438. tree->clear();
  439. tree->create_item();
  440. drop_label->set_visible(true);
  441. if (!config.is_valid()) {
  442. return;
  443. }
  444. TypedArray<NodePath> props = config->get_properties();
  445. if (props.size()) {
  446. drop_label->set_visible(false);
  447. }
  448. for (int i = 0; i < props.size(); i++) {
  449. const NodePath path = props[i];
  450. _add_property(path, config->property_get_spawn(path), config->property_get_replication_mode(path));
  451. }
  452. }
  453. void ReplicationEditor::edit(MultiplayerSynchronizer *p_sync) {
  454. if (current == p_sync) {
  455. return;
  456. }
  457. current = p_sync;
  458. if (current) {
  459. config = current->get_replication_config();
  460. } else {
  461. config.unref();
  462. }
  463. _update_config();
  464. }
  465. Ref<Texture2D> ReplicationEditor::_get_class_icon(const Node *p_node) {
  466. if (!p_node || !has_theme_icon(p_node->get_class(), EditorStringName(EditorIcons))) {
  467. return get_theme_icon(SNAME("ImportFail"), EditorStringName(EditorIcons));
  468. }
  469. return get_theme_icon(p_node->get_class(), EditorStringName(EditorIcons));
  470. }
  471. static bool can_sync(const Variant &p_var) {
  472. switch (p_var.get_type()) {
  473. case Variant::RID:
  474. case Variant::OBJECT:
  475. return false;
  476. case Variant::ARRAY: {
  477. const Array &arr = p_var;
  478. if (arr.is_typed()) {
  479. const uint32_t type = arr.get_typed_builtin();
  480. return (type != Variant::RID) && (type != Variant::OBJECT);
  481. }
  482. return true;
  483. }
  484. default:
  485. return true;
  486. }
  487. }
  488. void ReplicationEditor::_add_property(const NodePath &p_property, bool p_spawn, SceneReplicationConfig::ReplicationMode p_mode) {
  489. String prop = String(p_property);
  490. TreeItem *item = tree->create_item();
  491. item->set_selectable(0, false);
  492. item->set_selectable(1, false);
  493. item->set_selectable(2, false);
  494. item->set_selectable(3, false);
  495. item->set_text(0, prop);
  496. item->set_metadata(0, prop);
  497. Node *root_node = current && !current->get_root_path().is_empty() ? current->get_node(current->get_root_path()) : nullptr;
  498. Ref<Texture2D> icon = _get_class_icon(root_node);
  499. if (root_node) {
  500. String path = prop.substr(0, prop.find(":"));
  501. String subpath = prop.substr(path.size());
  502. Node *node = root_node->get_node_or_null(path);
  503. if (!node) {
  504. node = root_node;
  505. }
  506. item->set_text(0, String(node->get_name()) + ":" + subpath);
  507. icon = _get_class_icon(node);
  508. bool valid = false;
  509. Variant value = node->get(subpath, &valid);
  510. if (valid && !can_sync(value)) {
  511. item->set_icon(0, get_theme_icon(SNAME("StatusWarning"), EditorStringName(EditorIcons)));
  512. item->set_tooltip_text(0, TTR("Property of this type not supported."));
  513. } else {
  514. item->set_icon(0, icon);
  515. }
  516. } else {
  517. item->set_icon(0, icon);
  518. }
  519. item->add_button(3, get_theme_icon(SNAME("Remove"), EditorStringName(EditorIcons)));
  520. item->set_text_alignment(1, HORIZONTAL_ALIGNMENT_CENTER);
  521. item->set_cell_mode(1, TreeItem::CELL_MODE_CHECK);
  522. item->set_checked(1, p_spawn);
  523. item->set_editable(1, true);
  524. item->set_text_alignment(2, HORIZONTAL_ALIGNMENT_CENTER);
  525. item->set_cell_mode(2, TreeItem::CELL_MODE_RANGE);
  526. item->set_range_config(2, 0, 2, 1);
  527. item->set_text(2, "Never,Always,On Change");
  528. item->set_range(2, (int)p_mode);
  529. item->set_editable(2, true);
  530. }