replication_editor.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  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_string_names.h"
  34. #include "editor/editor_undo_redo_manager.h"
  35. #include "editor/inspector/property_selector.h"
  36. #include "editor/scene/scene_tree_editor.h"
  37. #include "editor/settings/editor_settings.h"
  38. #include "editor/themes/editor_scale.h"
  39. #include "editor/themes/editor_theme_manager.h"
  40. #include "scene/gui/dialogs.h"
  41. #include "scene/gui/line_edit.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(TTRC("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(TTRC("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(TTRC("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(TTRC("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(TTRC("Add property to sync...")));
  192. add_pick_button->connect(SceneStringName(pressed), callable_mp(this, &ReplicationEditor::_pick_new_property));
  193. hb->add_child(add_pick_button);
  194. VSeparator *vs = memnew(VSeparator);
  195. vs->set_custom_minimum_size(Size2(30 * EDSCALE, 0));
  196. hb->add_child(vs);
  197. hb->add_child(memnew(Label(TTRC("Path:"))));
  198. np_line_edit = memnew(LineEdit);
  199. np_line_edit->set_placeholder(":property");
  200. np_line_edit->set_accessibility_name(TTRC("Path:"));
  201. np_line_edit->set_h_size_flags(SIZE_EXPAND_FILL);
  202. np_line_edit->connect(SceneStringName(text_submitted), callable_mp(this, &ReplicationEditor::_np_text_submitted));
  203. hb->add_child(np_line_edit);
  204. add_from_path_button = memnew(Button(TTRC("Add from path")));
  205. add_from_path_button->connect(SceneStringName(pressed), callable_mp(this, &ReplicationEditor::_add_pressed));
  206. hb->add_child(add_from_path_button);
  207. vs = memnew(VSeparator);
  208. vs->set_custom_minimum_size(Size2(30 * EDSCALE, 0));
  209. hb->add_child(vs);
  210. pin = memnew(Button);
  211. pin->set_theme_type_variation(SceneStringName(FlatButton));
  212. pin->set_toggle_mode(true);
  213. pin->set_tooltip_text(TTRC("Pin replication editor"));
  214. hb->add_child(pin);
  215. tree = memnew(Tree);
  216. tree->set_hide_root(true);
  217. tree->set_columns(4);
  218. tree->set_column_titles_visible(true);
  219. tree->set_column_title(0, TTRC("Properties"));
  220. tree->set_column_expand(0, true);
  221. tree->set_column_title(1, TTRC("Spawn"));
  222. tree->set_column_expand(1, false);
  223. tree->set_column_custom_minimum_width(1, 100);
  224. tree->set_column_title(2, TTRC("Replicate"));
  225. tree->set_column_custom_minimum_width(2, 100);
  226. tree->set_column_expand(2, false);
  227. tree->set_column_expand(3, false);
  228. tree->create_item();
  229. tree->connect("button_clicked", callable_mp(this, &ReplicationEditor::_tree_button_pressed));
  230. tree->connect("item_edited", callable_mp(this, &ReplicationEditor::_tree_item_edited));
  231. tree->set_v_size_flags(SIZE_EXPAND_FILL);
  232. vb->add_child(tree);
  233. drop_label = memnew(Label(TTRC("Add properties using the options above, or\ndrag them from the inspector and drop them here.")));
  234. drop_label->set_focus_mode(FOCUS_ACCESSIBILITY);
  235. drop_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  236. drop_label->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
  237. tree->add_child(drop_label);
  238. drop_label->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
  239. SET_DRAG_FORWARDING_CDU(tree, ReplicationEditor);
  240. }
  241. void ReplicationEditor::_bind_methods() {
  242. ClassDB::bind_method(D_METHOD("_update_config"), &ReplicationEditor::_update_config);
  243. ClassDB::bind_method(D_METHOD("_update_value", "property", "column", "value"), &ReplicationEditor::_update_value);
  244. }
  245. bool ReplicationEditor::_can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  246. Dictionary d = p_data;
  247. if (!d.has("type")) {
  248. return false;
  249. }
  250. String t = d["type"];
  251. if (t != "obj_property") {
  252. return false;
  253. }
  254. Object *obj = d["object"];
  255. if (!obj) {
  256. return false;
  257. }
  258. Node *node = Object::cast_to<Node>(obj);
  259. if (!node) {
  260. return false;
  261. }
  262. return true;
  263. }
  264. void ReplicationEditor::_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  265. if (current == nullptr) {
  266. EditorNode::get_singleton()->show_warning(TTRC("Select a replicator node in order to pick a property to add to it."));
  267. return;
  268. }
  269. Node *root = current->get_node(current->get_root_path());
  270. if (!root) {
  271. EditorNode::get_singleton()->show_warning(TTRC("Not possible to add a new property to synchronize without a root."));
  272. return;
  273. }
  274. Dictionary d = p_data;
  275. if (!d.has("type")) {
  276. return;
  277. }
  278. String t = d["type"];
  279. if (t != "obj_property") {
  280. return;
  281. }
  282. Object *obj = d["object"];
  283. if (!obj) {
  284. return;
  285. }
  286. Node *node = Object::cast_to<Node>(obj);
  287. if (!node) {
  288. return;
  289. }
  290. String path = String(root->get_path_to(node));
  291. path += ":" + String(d["property"]);
  292. _add_sync_property(path);
  293. }
  294. void _set_replication_mode_options(TreeItem *p_item) {
  295. p_item->set_text(2, TTR("Never", "Replication Mode") + "," + TTR("Always", "Replication Mode") + "," + TTR("On Change", "Replication Mode"));
  296. }
  297. void ReplicationEditor::_notification(int p_what) {
  298. switch (p_what) {
  299. case NOTIFICATION_TRANSLATION_CHANGED: {
  300. TreeItem *root = tree->get_root();
  301. if (root) {
  302. for (TreeItem *ti = root->get_first_child(); ti; ti = ti->get_next()) {
  303. _set_replication_mode_options(ti);
  304. }
  305. }
  306. } break;
  307. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  308. if (!EditorThemeManager::is_generated_theme_outdated()) {
  309. break;
  310. }
  311. [[fallthrough]];
  312. }
  313. case NOTIFICATION_ENTER_TREE: {
  314. add_theme_style_override(SceneStringName(panel), EditorNode::get_singleton()->get_editor_theme()->get_stylebox(SceneStringName(panel), SNAME("Panel")));
  315. add_pick_button->set_button_icon(get_theme_icon(SNAME("Add"), EditorStringName(EditorIcons)));
  316. pin->set_button_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(TTRC("Please select a MultiplayerSynchronizer first."));
  323. return;
  324. }
  325. if (current->get_root_path().is_empty()) {
  326. EditorNode::get_singleton()->show_warning(TTRC("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(TTRC("Property/path must not be empty."));
  332. return;
  333. }
  334. int idx = np_text.find_char(':');
  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(String(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 ? 0 : 1);
  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(TTRC("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_null()) {
  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_auto_translate_mode(0, AUTO_TRANSLATE_MODE_DISABLED);
  497. item->set_metadata(0, prop);
  498. Node *root_node = current && !current->get_root_path().is_empty() ? current->get_node(current->get_root_path()) : nullptr;
  499. Ref<Texture2D> icon = _get_class_icon(root_node);
  500. if (root_node) {
  501. String path = prop.substr(0, prop.find_char(':'));
  502. String subpath = prop.substr(path.size());
  503. Node *node = root_node->get_node_or_null(path);
  504. if (!node) {
  505. node = root_node;
  506. }
  507. item->set_text(0, String(node->get_name()) + ":" + subpath);
  508. icon = _get_class_icon(node);
  509. bool valid = false;
  510. Variant value = node->get(subpath, &valid);
  511. if (valid && !can_sync(value)) {
  512. item->set_icon(0, get_theme_icon(SNAME("StatusWarning"), EditorStringName(EditorIcons)));
  513. item->set_tooltip_text(0, TTRC("Property of this type not supported."));
  514. } else {
  515. item->set_icon(0, icon);
  516. }
  517. } else {
  518. item->set_icon(0, icon);
  519. }
  520. item->add_button(3, get_theme_icon(SNAME("Remove"), EditorStringName(EditorIcons)));
  521. item->set_text_alignment(1, HORIZONTAL_ALIGNMENT_CENTER);
  522. item->set_cell_mode(1, TreeItem::CELL_MODE_CHECK);
  523. item->set_checked(1, p_spawn);
  524. item->set_editable(1, true);
  525. item->set_text_alignment(2, HORIZONTAL_ALIGNMENT_CENTER);
  526. item->set_cell_mode(2, TreeItem::CELL_MODE_RANGE);
  527. item->set_range_config(2, 0, 2, 1);
  528. item->set_auto_translate_mode(2, AUTO_TRANSLATE_MODE_DISABLED);
  529. _set_replication_mode_options(item);
  530. item->set_range(2, (int)p_mode);
  531. item->set_editable(2, true);
  532. }