replication_editor.cpp 20 KB

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