@@ -19,28 +19,12 @@ VoxelInstanceLibraryEditorPlugin::VoxelInstanceLibraryEditorPlugin() {}
19
19
20
20
// TODO GDX: Can't initialize EditorPlugins in their constructor when they access EditorNode.
21
21
// See https://github.com/godotengine/godot-cpp/issues/1179
22
- void VoxelInstanceLibraryEditorPlugin::init () {
23
- Control *base_control = get_editor_interface ()->get_base_control ();
22
+ void VoxelInstanceLibraryEditorPlugin::init () {}
24
23
25
- _confirmation_dialog = memnew (ConfirmationDialog);
26
- _confirmation_dialog->connect (
27
- " confirmed" , callable_mp (this , &VoxelInstanceLibraryEditorPlugin::_on_remove_item_confirmed)
28
- );
29
- base_control->add_child (_confirmation_dialog);
30
-
31
- _info_dialog = memnew (AcceptDialog);
32
- base_control->add_child (_info_dialog);
33
-
34
- _open_scene_dialog = memnew (EditorFileDialog);
35
- PackedStringArray extensions = godot::get_recognized_extensions_for_type (PackedScene::get_class_static ());
36
- for (int i = 0 ; i < extensions.size (); ++i) {
37
- _open_scene_dialog->add_filter (" *." + extensions[i]);
38
- }
39
- _open_scene_dialog->set_file_mode (EditorFileDialog::FILE_MODE_OPEN_FILE);
40
- base_control->add_child (_open_scene_dialog);
41
- _open_scene_dialog->connect (
42
- " file_selected" , callable_mp (this , &VoxelInstanceLibraryEditorPlugin::_on_open_scene_dialog_file_selected)
43
- );
24
+ EditorUndoRedoManager &VoxelInstanceLibraryEditorPlugin::get_undo_redo2 () {
25
+ EditorUndoRedoManager *ur = get_undo_redo ();
26
+ ZN_ASSERT (ur != nullptr );
27
+ return *ur;
44
28
}
45
29
46
30
bool VoxelInstanceLibraryEditorPlugin::_zn_handles (const Object *p_object) const {
@@ -49,8 +33,8 @@ bool VoxelInstanceLibraryEditorPlugin::_zn_handles(const Object *p_object) const
49
33
}
50
34
51
35
void VoxelInstanceLibraryEditorPlugin::_zn_edit (Object *p_object) {
52
- VoxelInstanceLibrary *lib = Object::cast_to<VoxelInstanceLibrary>(p_object);
53
- _library.reference_ptr (lib);
36
+ // VoxelInstanceLibrary *lib = Object::cast_to<VoxelInstanceLibrary>(p_object);
37
+ // _library.reference_ptr(lib);
54
38
}
55
39
56
40
void VoxelInstanceLibraryEditorPlugin::_notification (int p_what) {
@@ -59,7 +43,7 @@ void VoxelInstanceLibraryEditorPlugin::_notification(int p_what) {
59
43
60
44
Control *base_control = get_editor_interface ()->get_base_control ();
61
45
_inspector_plugin.instantiate ();
62
- _inspector_plugin->button_listener = this ;
46
+ _inspector_plugin->plugin = this ;
63
47
_inspector_plugin->icon_provider = base_control;
64
48
// TODO Why can other Godot plugins do this in the constructor??
65
49
// I found I could not put this in the constructor,
@@ -71,142 +55,6 @@ void VoxelInstanceLibraryEditorPlugin::_notification(int p_what) {
71
55
}
72
56
}
73
57
74
- void VoxelInstanceLibraryEditorPlugin::_on_add_item_button_pressed (int id) {
75
- _on_button_pressed (id);
76
- }
77
-
78
- void VoxelInstanceLibraryEditorPlugin::_on_remove_item_button_pressed () {
79
- _on_button_pressed (VoxelInstanceLibraryInspectorPlugin::BUTTON_REMOVE_ITEM);
80
- }
81
-
82
- void VoxelInstanceLibraryEditorPlugin::_on_button_pressed (int id) {
83
- _last_used_button = id;
84
-
85
- switch (id) {
86
- case VoxelInstanceLibraryInspectorPlugin::BUTTON_ADD_MULTIMESH_ITEM: {
87
- ERR_FAIL_COND (_library.is_null ());
88
-
89
- Ref<VoxelInstanceLibraryMultiMeshItem> item;
90
- item.instantiate ();
91
- // Setup some defaults
92
- Ref<BoxMesh> mesh;
93
- mesh.instantiate ();
94
- item->set_mesh (mesh, 0 );
95
-
96
- // We could decide to use a different default here if we can detect that the instancer the library is used
97
- // into is child of a terrain with LOD or no LOD. At the very least it should always be 0 if there is no LOD
98
- // support, otherwise things look broken. 0 is the default.
99
- // item->set_lod_index(2);
100
-
101
- Ref<VoxelInstanceGenerator> generator;
102
- generator.instantiate ();
103
- item->set_generator (generator);
104
-
105
- const int item_id = _library->get_next_available_id ();
106
-
107
- EditorUndoRedoManager &ur = *get_undo_redo ();
108
- ur.create_action (" Add multimesh item" );
109
- ur.add_do_method (*_library, " add_item" , item_id, item);
110
- ur.add_undo_method (*_library, " remove_item" , item_id);
111
- ur.commit_action ();
112
- } break ;
113
-
114
- case VoxelInstanceLibraryInspectorPlugin::BUTTON_ADD_SCENE_ITEM: {
115
- _open_scene_dialog->popup_centered_ratio ();
116
- } break ;
117
-
118
- case VoxelInstanceLibraryInspectorPlugin::BUTTON_REMOVE_ITEM: {
119
- ERR_FAIL_COND (_library.is_null ());
120
- const int item_id = try_get_selected_item_id ();
121
- if (item_id != -1 ) {
122
- _item_id_to_remove = item_id;
123
- _confirmation_dialog->set_text (ZN_TTR (" Remove item {0}?" ).format (varray (_item_id_to_remove)));
124
- _confirmation_dialog->popup_centered ();
125
- }
126
- } break ;
127
-
128
- default :
129
- ERR_PRINT (" Unknown menu item" );
130
- break ;
131
- }
132
- }
133
-
134
- // TODO This function does not modify anything, but cannot be `const` because get_editor_interface() is not...
135
- int VoxelInstanceLibraryEditorPlugin::try_get_selected_item_id () {
136
- String path = get_editor_interface ()->get_inspector ()->get_selected_path ();
137
- String prefix = " item_" ;
138
-
139
- if (path.begins_with (prefix)) {
140
- const int id = path.substr (prefix.length ()).to_int ();
141
- return id;
142
-
143
- } else {
144
- // The inspector won't let us know which item the current resource is stored into...
145
- // Gridmap works because it simulates every item as properties of the library,
146
- // but our current resource does not do that,
147
- // and I don't want to modify the API just because the built-in inspector is bad.
148
- _info_dialog->set_text (
149
- ZN_TTR (String (" Could not determine selected item from property path: `{0}`.\n "
150
- " You must select the `item_X` property label of the item you want to remove." ))
151
- .format (varray (path))
152
- );
153
- _info_dialog->popup_centered ();
154
- return -1 ;
155
- }
156
- }
157
-
158
- void VoxelInstanceLibraryEditorPlugin::_on_remove_item_confirmed () {
159
- ERR_FAIL_COND (_library.is_null ());
160
- ERR_FAIL_COND (_item_id_to_remove == -1 );
161
-
162
- Ref<VoxelInstanceLibraryItem> item = _library->get_item (_item_id_to_remove);
163
-
164
- EditorUndoRedoManager &ur = *get_undo_redo ();
165
- ur.create_action (" Remove item" );
166
- ur.add_do_method (*_library, " remove_item" , _item_id_to_remove);
167
- ur.add_undo_method (*_library, " add_item" , _item_id_to_remove, item);
168
- ur.commit_action ();
169
-
170
- _item_id_to_remove = -1 ;
171
- }
172
-
173
- void VoxelInstanceLibraryEditorPlugin::_on_open_scene_dialog_file_selected (String fpath) {
174
- switch (_last_used_button) {
175
- case VoxelInstanceLibraryInspectorPlugin::BUTTON_ADD_SCENE_ITEM:
176
- add_scene_item (fpath);
177
- break ;
178
-
179
- default :
180
- ERR_PRINT (" Invalid menu option" );
181
- break ;
182
- }
183
- }
184
-
185
- void VoxelInstanceLibraryEditorPlugin::add_scene_item (String fpath) {
186
- ERR_FAIL_COND (_library.is_null ());
187
-
188
- Ref<PackedScene> scene = godot::load_resource (fpath);
189
- ERR_FAIL_COND (scene.is_null ());
190
-
191
- Ref<VoxelInstanceLibrarySceneItem> item;
192
- item.instantiate ();
193
- // Setup some defaults
194
- item->set_lod_index (2 );
195
- item->set_scene (scene);
196
- Ref<VoxelInstanceGenerator> generator;
197
- generator.instantiate ();
198
- generator->set_density (0 .01f ); // Low density for scenes because that's heavier
199
- item->set_generator (generator);
200
-
201
- const int item_id = _library->get_next_available_id ();
202
-
203
- EditorUndoRedoManager &ur = *get_undo_redo ();
204
- ur.create_action (" Add scene item" );
205
- ur.add_do_method (_library.ptr (), " add_item" , item_id, item);
206
- ur.add_undo_method (_library.ptr (), " remove_item" , item_id);
207
- ur.commit_action ();
208
- }
209
-
210
58
void VoxelInstanceLibraryEditorPlugin::_bind_methods () {}
211
59
212
60
} // namespace zylann::voxel
0 commit comments