replication_editor.cpp 21 KB

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