| 1 | /**************************************************************************/ |
| 2 | /* particle_process_material_editor_plugin.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 | |
| 31 | #include "particle_process_material_editor_plugin.h" |
| 32 | |
| 33 | #include "editor/editor_string_names.h" |
| 34 | #include "editor/gui/editor_spin_slider.h" |
| 35 | #include "editor/settings/editor_settings.h" |
| 36 | #include "editor/themes/editor_theme_manager.h" |
| 37 | #include "scene/gui/box_container.h" |
| 38 | #include "scene/gui/button.h" |
| 39 | #include "scene/resources/particle_process_material.h" |
| 40 | |
| 41 | void ParticleProcessMaterialMinMaxPropertyEditor::_update_sizing() { |
| 42 | edit_size = range_edit_widget->get_size(); |
| 43 | margin = Vector2(range_slider_left_icon->get_width(), (edit_size.y - range_slider_left_icon->get_height()) * 0.5); |
| 44 | usable_area = edit_size - margin * 2; |
| 45 | } |
| 46 | |
| 47 | void ParticleProcessMaterialMinMaxPropertyEditor::_range_edit_draw() { |
| 48 | ERR_FAIL_COND(range_slider_left_icon.is_null()); |
| 49 | ERR_FAIL_COND(range_slider_right_icon.is_null()); |
| 50 | _update_sizing(); |
| 51 | |
| 52 | bool widget_active = mouse_inside || drag != Drag::NONE; |
| 53 | |
| 54 | // FIXME: Need to offset by 1 due to some outline bug. |
| 55 | range_edit_widget->draw_rect(Rect2(margin + Vector2(1, 1), usable_area - Vector2(1, 1)), widget_active ? background_color.lerp(normal_color, 0.3) : background_color, false, 1.0); |
| 56 | |
| 57 | Color draw_color; |
| 58 | |
| 59 | if (widget_active) { |
| 60 | float icon_offset = _get_left_offset() - range_slider_left_icon->get_width() - 1; |
| 61 | |
| 62 | if (drag == Drag::LEFT || drag == Drag::SCALE) { |
| 63 | draw_color = drag_color; |
| 64 | } else if (hover == Hover::LEFT) { |
| 65 | draw_color = hovered_color; |
| 66 | } else { |
| 67 | draw_color = normal_color; |
| 68 | } |
| 69 | range_edit_widget->draw_texture(range_slider_left_icon, Vector2(icon_offset, margin.y), draw_color); |
| 70 | |
| 71 | icon_offset = _get_right_offset(); |
| 72 | |
| 73 | if (drag == Drag::RIGHT || drag == Drag::SCALE) { |
| 74 | draw_color = drag_color; |
| 75 | } else if (hover == Hover::RIGHT) { |
| 76 | draw_color = hovered_color; |
| 77 | } else { |
| 78 | draw_color = normal_color; |
| 79 | } |
| 80 | range_edit_widget->draw_texture(range_slider_right_icon, Vector2(icon_offset, margin.y), draw_color); |
| 81 | } |
| 82 | |
| 83 | if (drag == Drag::MIDDLE || drag == Drag::SCALE) { |
| 84 | draw_color = drag_color; |
| 85 | } else if (hover == Hover::MIDDLE) { |
| 86 | draw_color = hovered_color; |
| 87 | } else { |
| 88 | draw_color = normal_color; |
| 89 | } |
| 90 | range_edit_widget->draw_rect(_get_middle_rect(), draw_color); |
| 91 | |
| 92 | Rect2 midpoint_rect(Vector2(margin.x + usable_area.x * (_get_min_ratio() + _get_max_ratio()) * 0.5 - 1, margin.y + 2), |
| 93 | Vector2(2, usable_area.y - 4)); |
| 94 | |
| 95 | range_edit_widget->draw_rect(midpoint_rect, midpoint_color); |
| 96 | } |
| 97 | |
| 98 | void ParticleProcessMaterialMinMaxPropertyEditor::_range_edit_gui_input(const Ref<InputEvent> &p_event) { |
| 99 | Ref<InputEventMouseButton> mb = p_event; |
| 100 | Ref<InputEventMouseMotion> mm = p_event; |
| 101 | |
| 102 | // Prevent unnecessary computations. |
| 103 | if ((mb.is_null() || mb->get_button_index() != MouseButton::LEFT) && (mm.is_null())) { |
| 104 | return; |
| 105 | } |
| 106 | |
| 107 | ERR_FAIL_COND(range_slider_left_icon.is_null()); |
| 108 | ERR_FAIL_COND(range_slider_right_icon.is_null()); |
| 109 | _update_sizing(); |
| 110 | |
| 111 | if (mb.is_valid()) { |
| 112 | const Drag prev_drag = drag; |
| 113 | |
| 114 | if (mb->is_pressed()) { |
| 115 | if (mb->is_shift_pressed()) { |
| 116 | drag = Drag::SCALE; |
| 117 | drag_from_value = (max_range->get_value() - min_range->get_value()) * 0.5; |
| 118 | drag_midpoint = (max_range->get_value() + min_range->get_value()) * 0.5; |
| 119 | } else if (hover == Hover::LEFT) { |
| 120 | drag = Drag::LEFT; |
| 121 | drag_from_value = min_range->get_value(); |
| 122 | } else if (hover == Hover::RIGHT) { |
| 123 | drag = Drag::RIGHT; |
| 124 | drag_from_value = max_range->get_value(); |
| 125 | } else { |
| 126 | drag = Drag::MIDDLE; |
| 127 | drag_from_value = min_range->get_value(); |
| 128 | } |
| 129 | drag_origin = mb->get_position().x; |
| 130 | } else { |
| 131 | drag = Drag::NONE; |
| 132 | } |
| 133 | |
| 134 | if (drag != prev_drag) { |
| 135 | range_edit_widget->queue_redraw(); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | float property_length = property_range.y - property_range.x; |
| 140 | if (mm.is_valid()) { |
| 141 | switch (drag) { |
| 142 | case Drag::NONE: { |
| 143 | const Hover prev_hover = hover; |
| 144 | float left_icon_offset = _get_left_offset() - range_slider_left_icon->get_width() - 1; |
| 145 | |
| 146 | if (Rect2(Vector2(left_icon_offset, 0), range_slider_left_icon->get_size()).has_point(mm->get_position())) { |
| 147 | hover = Hover::LEFT; |
| 148 | } else if (Rect2(Vector2(_get_right_offset(), 0), range_slider_right_icon->get_size()).has_point(mm->get_position())) { |
| 149 | hover = Hover::RIGHT; |
| 150 | } else if (_get_middle_rect().has_point(mm->get_position())) { |
| 151 | hover = Hover::MIDDLE; |
| 152 | } else { |
| 153 | hover = Hover::NONE; |
| 154 | } |
| 155 | |
| 156 | if (hover != prev_hover) { |
| 157 | range_edit_widget->queue_redraw(); |
| 158 | } |
| 159 | } break; |
| 160 | |
| 161 | case Drag::LEFT: |
| 162 | case Drag::RIGHT: { |
| 163 | float new_value = drag_from_value + (mm->get_position().x - drag_origin) / usable_area.x * property_length; |
| 164 | if (drag == Drag::LEFT) { |
| 165 | new_value = MIN(new_value, max_range->get_value()); |
| 166 | _set_clamped_values(new_value, max_range->get_value()); |
| 167 | } else { |
| 168 | new_value = MAX(new_value, min_range->get_value()); |
| 169 | _set_clamped_values(min_range->get_value(), new_value); |
| 170 | } |
| 171 | } break; |
| 172 | |
| 173 | case Drag::MIDDLE: { |
| 174 | float delta = (mm->get_position().x - drag_origin) / usable_area.x * property_length; |
| 175 | float diff = max_range->get_value() - min_range->get_value(); |
| 176 | delta = CLAMP(drag_from_value + delta, property_range.x, property_range.y - diff) - drag_from_value; |
| 177 | _set_clamped_values(drag_from_value + delta, drag_from_value + delta + diff); |
| 178 | } break; |
| 179 | |
| 180 | case Drag::SCALE: { |
| 181 | float delta = (mm->get_position().x - drag_origin) / usable_area.x * property_length + drag_from_value; |
| 182 | _set_clamped_values(MIN(drag_midpoint, drag_midpoint - delta), MAX(drag_midpoint, drag_midpoint + delta)); |
| 183 | } break; |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | void ParticleProcessMaterialMinMaxPropertyEditor::_set_mouse_inside(bool p_inside) { |
| 189 | mouse_inside = p_inside; |
| 190 | if (!p_inside) { |
| 191 | hover = Hover::NONE; |
| 192 | } |
| 193 | range_edit_widget->queue_redraw(); |
| 194 | } |
| 195 | |
| 196 | float ParticleProcessMaterialMinMaxPropertyEditor::_get_min_ratio() const { |
| 197 | return (min_range->get_value() - property_range.x) / (property_range.y - property_range.x); |
| 198 | } |
| 199 | |
| 200 | float ParticleProcessMaterialMinMaxPropertyEditor::_get_max_ratio() const { |
| 201 | return (max_range->get_value() - property_range.x) / (property_range.y - property_range.x); |
| 202 | } |
| 203 | |
| 204 | float ParticleProcessMaterialMinMaxPropertyEditor::_get_left_offset() const { |
| 205 | return margin.x + usable_area.x * _get_min_ratio(); |
| 206 | } |
| 207 | |
| 208 | float ParticleProcessMaterialMinMaxPropertyEditor::_get_right_offset() const { |
| 209 | return margin.x + usable_area.x * _get_max_ratio(); |
| 210 | } |
| 211 | |
| 212 | Rect2 ParticleProcessMaterialMinMaxPropertyEditor::_get_middle_rect() const { |
| 213 | if (Math::is_equal_approx(min_range->get_value(), max_range->get_value())) { |
| 214 | return Rect2(); |
| 215 | } |
| 216 | |
| 217 | return Rect2( |
| 218 | Vector2(_get_left_offset() - 1, margin.y), |
| 219 | Vector2(usable_area.x * (_get_max_ratio() - _get_min_ratio()) + 1, usable_area.y)); |
| 220 | } |
| 221 | |
| 222 | void ParticleProcessMaterialMinMaxPropertyEditor::_set_clamped_values(float p_min, float p_max) { |
| 223 | // This is required for editing widget in case the properties have or_less or or_greater hint. |
| 224 | min_range->set_value(MAX(p_min, property_range.x)); |
| 225 | max_range->set_value(MIN(p_max, property_range.y)); |
| 226 | _update_slider_values(); |
| 227 | _sync_property(); |
| 228 | } |
| 229 | |
| 230 | void ParticleProcessMaterialMinMaxPropertyEditor::_sync_property() { |
| 231 | const Vector2 value = Vector2(min_range->get_value(), max_range->get_value()); |
| 232 | emit_changed(get_edited_property(), value, "", true); |
| 233 | range_edit_widget->queue_redraw(); |
| 234 | } |
| 235 | |
| 236 | void ParticleProcessMaterialMinMaxPropertyEditor::_update_mode() { |
| 237 | max_edit->set_read_only(false); |
| 238 | |
| 239 | switch (slider_mode) { |
| 240 | case Mode::RANGE: { |
| 241 | min_edit->set_label("min"); |
| 242 | max_edit->set_label("max"); |
| 243 | max_edit->set_block_signals(true); |
| 244 | max_edit->set_min(max_range->get_min()); |
| 245 | max_edit->set_max(max_range->get_max()); |
| 246 | max_edit->set_block_signals(false); |
| 247 | |
| 248 | min_edit->set_allow_lesser(min_range->is_lesser_allowed()); |
| 249 | min_edit->set_allow_greater(min_range->is_greater_allowed()); |
| 250 | max_edit->set_allow_lesser(max_range->is_lesser_allowed()); |
| 251 | max_edit->set_allow_greater(max_range->is_greater_allowed()); |
| 252 | } break; |
| 253 | |
| 254 | case Mode::MIDPOINT: { |
| 255 | min_edit->set_label("val"); |
| 256 | max_edit->set_label(U"±"); |
| 257 | max_edit->set_block_signals(true); |
| 258 | max_edit->set_min(0); |
| 259 | max_edit->set_block_signals(false); |
| 260 | |
| 261 | min_edit->set_allow_lesser(min_range->is_lesser_allowed()); |
| 262 | min_edit->set_allow_greater(max_range->is_greater_allowed()); |
| 263 | max_edit->set_allow_lesser(false); |
| 264 | max_edit->set_allow_greater(min_range->is_lesser_allowed() && max_range->is_greater_allowed()); |
| 265 | } break; |
| 266 | } |
| 267 | _update_slider_values(); |
| 268 | } |
| 269 | |
| 270 | void ParticleProcessMaterialMinMaxPropertyEditor::_toggle_mode(bool p_edit_mode) { |
| 271 | slider_mode = p_edit_mode ? Mode::MIDPOINT : Mode::RANGE; |
| 272 | EditorSettings::get_singleton()->set_project_metadata("editor_metadata", "particle_spin_mode", int(slider_mode)); |
| 273 | _update_mode(); |
| 274 | } |
| 275 | |
| 276 | void ParticleProcessMaterialMinMaxPropertyEditor::_update_slider_values() { |
| 277 | switch (slider_mode) { |
| 278 | case Mode::RANGE: { |
| 279 | min_edit->set_value_no_signal(min_range->get_value()); |
| 280 | max_edit->set_value_no_signal(max_range->get_value()); |
| 281 | } break; |
| 282 | |
| 283 | case Mode::MIDPOINT: { |
| 284 | min_edit->set_value_no_signal((min_range->get_value() + max_range->get_value()) * 0.5); |
| 285 | max_edit->set_value_no_signal((max_range->get_value() - min_range->get_value()) * 0.5); |
| 286 | |
| 287 | max_edit->set_block_signals(true); |
| 288 | max_edit->set_max(_get_max_spread()); |
| 289 | max_edit->set_read_only(max_edit->get_max() == 0); |
| 290 | max_edit->set_block_signals(false); |
| 291 | } break; |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | void ParticleProcessMaterialMinMaxPropertyEditor::_sync_sliders(float, const EditorSpinSlider *p_changed_slider) { |
| 296 | switch (slider_mode) { |
| 297 | case Mode::RANGE: { |
| 298 | if (p_changed_slider == max_edit) { |
| 299 | min_edit->set_value_no_signal(MIN(min_edit->get_value(), max_edit->get_value())); |
| 300 | } |
| 301 | min_range->set_value(min_edit->get_value()); |
| 302 | if (p_changed_slider == min_edit) { |
| 303 | max_edit->set_value_no_signal(MAX(min_edit->get_value(), max_edit->get_value())); |
| 304 | } |
| 305 | max_range->set_value(max_edit->get_value()); |
| 306 | _sync_property(); |
| 307 | } break; |
| 308 | |
| 309 | case Mode::MIDPOINT: { |
| 310 | if (p_changed_slider == min_edit) { |
| 311 | max_edit->set_block_signals(true); // If max changes, value may change. |
| 312 | max_edit->set_max(_get_max_spread()); |
| 313 | max_edit->set_read_only(max_edit->get_max() == 0); |
| 314 | max_edit->set_block_signals(false); |
| 315 | } |
| 316 | min_range->set_value(min_edit->get_value() - max_edit->get_value()); |
| 317 | max_range->set_value(min_edit->get_value() + max_edit->get_value()); |
| 318 | _sync_property(); |
| 319 | } break; |
| 320 | } |
| 321 | |
| 322 | property_range.x = MIN(min_range->get_value(), min_range->get_min()); |
| 323 | property_range.y = MAX(max_range->get_value(), max_range->get_max()); |
| 324 | } |
| 325 | |
| 326 | float ParticleProcessMaterialMinMaxPropertyEditor::_get_max_spread() const { |
| 327 | float max_spread = max_range->get_max() - min_range->get_min(); |
| 328 | |
| 329 | if (max_edit->is_greater_allowed()) { |
| 330 | return max_spread; |
| 331 | } |
| 332 | |
| 333 | if (!min_edit->is_lesser_allowed()) { |
| 334 | max_spread = MIN(max_spread, min_edit->get_value() - min_edit->get_min()); |
| 335 | } |
| 336 | |
| 337 | if (!min_edit->is_greater_allowed()) { |
| 338 | max_spread = MIN(max_spread, min_edit->get_max() - min_edit->get_value()); |
| 339 | } |
| 340 | |
| 341 | return max_spread; |
| 342 | } |
| 343 | |
| 344 | void ParticleProcessMaterialMinMaxPropertyEditor::_notification(int p_what) { |
| 345 | switch (p_what) { |
| 346 | case NOTIFICATION_THEME_CHANGED: { |
| 347 | toggle_mode_button->set_button_icon(get_editor_theme_icon(SNAME("Anchor"))); |
| 348 | range_slider_left_icon = get_editor_theme_icon(SNAME("RangeSliderLeft")); |
| 349 | range_slider_right_icon = get_editor_theme_icon(SNAME("RangeSliderRight")); |
| 350 | |
| 351 | min_edit->add_theme_color_override(SNAME("label_color"), get_theme_color(SNAME("property_color_x"), EditorStringName(Editor))); |
| 352 | max_edit->add_theme_color_override(SNAME("label_color"), get_theme_color(SNAME("property_color_y"), EditorStringName(Editor))); |
| 353 | |
| 354 | const bool dark_theme = EditorThemeManager::is_dark_theme(); |
| 355 | const Color accent_color = get_theme_color(SNAME("accent_color"), EditorStringName(Editor)); |
| 356 | background_color = dark_theme ? Color(0.3, 0.3, 0.3) : Color(0.7, 0.7, 0.7); |
| 357 | normal_color = dark_theme ? Color(0.5, 0.5, 0.5) : Color(0.8, 0.8, 0.8); |
| 358 | hovered_color = dark_theme ? Color(0.8, 0.8, 0.8) : Color(0.6, 0.6, 0.6); |
| 359 | drag_color = hovered_color.lerp(accent_color, 0.8); |
| 360 | midpoint_color = dark_theme ? Color(1, 1, 1) : Color(0, 0, 0); |
| 361 | |
| 362 | range_edit_widget->set_custom_minimum_size(Vector2(0, range_slider_left_icon->get_height() + 8)); |
| 363 | } break; |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | void ParticleProcessMaterialMinMaxPropertyEditor::setup(float p_min, float p_max, float p_step, bool p_allow_less, bool p_allow_greater, bool p_degrees) { |
| 368 | property_range = Vector2(p_min, p_max); |
| 369 | |
| 370 | // Initially all Ranges share properties. |
| 371 | for (Range *range : Vector<Range *>{ min_range, min_edit, max_range, max_edit }) { |
| 372 | range->set_min(p_min); |
| 373 | range->set_max(p_max); |
| 374 | range->set_step(p_step); |
| 375 | range->set_allow_lesser(p_allow_less); |
| 376 | range->set_allow_greater(p_allow_greater); |
| 377 | } |
| 378 | |
| 379 | if (p_degrees) { |
| 380 | min_edit->set_suffix(U" \u00B0"); |
| 381 | max_edit->set_suffix(U" \u00B0"); |
| 382 | } |
| 383 | _update_mode(); |
| 384 | } |
| 385 | |
| 386 | void ParticleProcessMaterialMinMaxPropertyEditor::update_property() { |
| 387 | const Vector2 value = get_edited_property_value(); |
| 388 | min_range->set_value(value.x); |
| 389 | max_range->set_value(value.y); |
| 390 | _update_slider_values(); |
| 391 | range_edit_widget->queue_redraw(); |
| 392 | } |
| 393 | |
| 394 | ParticleProcessMaterialMinMaxPropertyEditor::ParticleProcessMaterialMinMaxPropertyEditor() { |
| 395 | VBoxContainer *content_vb = memnew(VBoxContainer); |
| 396 | content_vb->add_theme_constant_override(SNAME("separation"), 0); |
| 397 | add_child(content_vb); |
| 398 | |
| 399 | // Helper Range objects to keep absolute min and max values. |
| 400 | min_range = memnew(Range); |
| 401 | min_range->hide(); |
| 402 | add_child(min_range); |
| 403 | |
| 404 | max_range = memnew(Range); |
| 405 | max_range->hide(); |
| 406 | add_child(max_range); |
| 407 | |
| 408 | // Range edit widget. |
| 409 | HBoxContainer *hb = memnew(HBoxContainer); |
| 410 | content_vb->add_child(hb); |
| 411 | |
| 412 | range_edit_widget = memnew(Control); |
| 413 | range_edit_widget->set_h_size_flags(SIZE_EXPAND_FILL); |
| 414 | range_edit_widget->set_tooltip_text(TTR("Hold Shift to scale around midpoint instead of moving.")); |
| 415 | hb->add_child(range_edit_widget); |
| 416 | range_edit_widget->connect(SceneStringName(draw), callable_mp(this, &ParticleProcessMaterialMinMaxPropertyEditor::_range_edit_draw)); |
| 417 | range_edit_widget->connect(SceneStringName(gui_input), callable_mp(this, &ParticleProcessMaterialMinMaxPropertyEditor::_range_edit_gui_input)); |
| 418 | range_edit_widget->connect(SceneStringName(mouse_entered), callable_mp(this, &ParticleProcessMaterialMinMaxPropertyEditor::_set_mouse_inside).bind(true)); |
| 419 | range_edit_widget->connect(SceneStringName(mouse_exited), callable_mp(this, &ParticleProcessMaterialMinMaxPropertyEditor::_set_mouse_inside).bind(false)); |
| 420 | |
| 421 | // Range controls for actual editing. Their min/max may depend on editing mode. |
| 422 | hb = memnew(HBoxContainer); |
| 423 | content_vb->add_child(hb); |
| 424 | |
| 425 | min_edit = memnew(EditorSpinSlider); |
| 426 | min_edit->set_h_size_flags(SIZE_EXPAND_FILL); |
| 427 | hb->add_child(min_edit); |
| 428 | min_edit->connect(SceneStringName(value_changed), callable_mp(this, &ParticleProcessMaterialMinMaxPropertyEditor::_sync_sliders).bind(min_edit)); |
| 429 | |
| 430 | max_edit = memnew(EditorSpinSlider); |
| 431 | max_edit->set_h_size_flags(SIZE_EXPAND_FILL); |
| 432 | hb->add_child(max_edit); |
| 433 | max_edit->connect(SceneStringName(value_changed), callable_mp(this, &ParticleProcessMaterialMinMaxPropertyEditor::_sync_sliders).bind(max_edit)); |
| 434 | |
| 435 | toggle_mode_button = memnew(Button); |
| 436 | toggle_mode_button->set_toggle_mode(true); |
| 437 | toggle_mode_button->set_tooltip_text(TTR("Toggle between minimum/maximum and base value/spread modes.")); |
| 438 | hb->add_child(toggle_mode_button); |
| 439 | toggle_mode_button->connect(SceneStringName(toggled), callable_mp(this, &ParticleProcessMaterialMinMaxPropertyEditor::_toggle_mode)); |
| 440 | |
| 441 | set_bottom_editor(content_vb); |
| 442 | } |
| 443 | |
| 444 | bool EditorInspectorParticleProcessMaterialPlugin::can_handle(Object *p_object) { |
| 445 | return Object::cast_to<ParticleProcessMaterial>(p_object); |
| 446 | } |
| 447 | |
| 448 | bool EditorInspectorParticleProcessMaterialPlugin::parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const BitField<PropertyUsageFlags> p_usage, const bool p_wide) { |
| 449 | if (!ParticleProcessMaterial::has_min_max_property(p_path)) { |
| 450 | return false; |
| 451 | } |
| 452 | ERR_FAIL_COND_V(p_hint != PROPERTY_HINT_RANGE, false); |
| 453 | |
| 454 | Ref<ParticleProcessMaterial> mat = Ref<ParticleProcessMaterial>(p_object); |
| 455 | ERR_FAIL_COND_V(mat.is_null(), false); |
| 456 | |
| 457 | PackedStringArray range_hint = p_hint_text.split(","); |
| 458 | float min = range_hint[0].to_float(); |
| 459 | float max = range_hint[1].to_float(); |
| 460 | float step = range_hint[2].to_float(); |
| 461 | bool allow_less = range_hint.find("or_less", 3) > -1; |
| 462 | bool allow_greater = range_hint.find("or_greater", 3) > -1; |
| 463 | bool degrees = range_hint.find("degrees", 3) > -1; |
| 464 | |
| 465 | ParticleProcessMaterialMinMaxPropertyEditor *ed = memnew(ParticleProcessMaterialMinMaxPropertyEditor); |
| 466 | ed->setup(min, max, step, allow_less, allow_greater, degrees); |
| 467 | add_property_editor(p_path, ed); |
| 468 | |
| 469 | return true; |
| 470 | } |