|
4 | 4 | #include <stdio.h> |
5 | 5 | #include <type_database.h> |
6 | 6 | #include <game/game_object_info.h> |
| 7 | +#include <game/model.h> |
| 8 | +#include <game/skeleton.h> |
7 | 9 | #include <io/log.h> |
| 10 | +#include <io/filesystem.h> |
8 | 11 | #include <ui/theme.h> |
9 | 12 | #include <ui/editor_ui.h> |
10 | 13 | #include <ui/world_inspector.h> |
@@ -235,6 +238,31 @@ on_button_pilot_camera_clicked(te_button_widget* button) { |
235 | 238 | property_inspector_hide(inspector); |
236 | 239 | } |
237 | 240 |
|
| 241 | +static void on_preview_animation_selected(void* custom, const char* absolute_path_to_file) { |
| 242 | + te_property_inspector* inspector = custom; |
| 243 | + |
| 244 | + te_model* model = inspector->obj; |
| 245 | + te_skeleton* skeleton = model_get_skeleton(model); |
| 246 | + |
| 247 | + char* relative_path_to_anim = filesystem_convert_path_to_relative(absolute_path_to_file); |
| 248 | + |
| 249 | + skeleton_load_animations(skeleton, relative_path_to_anim); |
| 250 | + |
| 251 | + const char* filename = filesystem_find_filename(relative_path_to_anim, false, NULL); |
| 252 | + skeleton_play_animation(skeleton, filename, true); |
| 253 | + |
| 254 | + free(relative_path_to_anim); |
| 255 | +} |
| 256 | + |
| 257 | +static void |
| 258 | +on_button_preview_animation_clicked(te_button_widget* button) { |
| 259 | + te_property_inspector* inspector = widget_get_custom_ptr(button_widget_get_widget(button)); |
| 260 | + |
| 261 | + te_editor* editor = editor_ui_get_editor(inspector->ui); |
| 262 | + editor_show_file_dialog( |
| 263 | + editor, inspector, on_preview_animation_selected, NULL, TE_FDM_SELECT_EXISTING_FILE); |
| 264 | +} |
| 265 | + |
238 | 266 | void |
239 | 267 | property_inspector_show(te_property_inspector* inspector, void* obj, const char* obj_type_id) { |
240 | 268 | if (inspector->obj == obj) { |
@@ -274,46 +302,90 @@ property_inspector_show(te_property_inspector* inspector, void* obj, const char* |
274 | 302 | pos[0] = hpadding; |
275 | 303 | pos[1] = theme_get_vertical_padding() / 2.0f; |
276 | 304 |
|
277 | | - if (type_info->get_game_object_info != NULL && type_info->get_game_object_info(obj)->type == TE_GOT_CAMERA) { |
278 | | - // Add a button to pilot the camera. |
279 | | - te_button_widget* button = button_widget_create(); |
280 | | - { |
281 | | - te_widget* widget = button_widget_get_widget(button); |
282 | | - widget_set_custom_ptr(widget, inspector); |
283 | | - widget_set_parent(widget, inspector->right_panel); |
284 | | - widget_set_relative_position(widget, pos); |
285 | | - widget_set_relative_size(widget, size); |
286 | | - } |
| 305 | + if (type_info->get_game_object_info != NULL) { |
| 306 | + if (type_info->get_game_object_info(obj)->type == TE_GOT_CAMERA) { |
| 307 | + // Add a button to pilot the camera. |
| 308 | + te_button_widget* button = button_widget_create(); |
| 309 | + { |
| 310 | + te_widget* widget = button_widget_get_widget(button); |
| 311 | + widget_set_custom_ptr(widget, inspector); |
| 312 | + widget_set_parent(widget, inspector->right_panel); |
| 313 | + widget_set_relative_position(widget, pos); |
| 314 | + widget_set_relative_size(widget, size); |
| 315 | + } |
287 | 316 |
|
288 | | - vec4 color; |
289 | | - theme_get_button_color(color); |
290 | | - button_widget_set_color(button, color); |
| 317 | + vec4 color; |
| 318 | + theme_get_button_color(color); |
| 319 | + button_widget_set_color(button, color); |
291 | 320 |
|
292 | | - theme_get_button_color_hovered(color); |
293 | | - button_widget_set_color_hovered(button, color); |
| 321 | + theme_get_button_color_hovered(color); |
| 322 | + button_widget_set_color_hovered(button, color); |
294 | 323 |
|
295 | | - theme_get_button_color_pressed(color); |
296 | | - button_widget_set_color_pressed(button, color); |
| 324 | + theme_get_button_color_pressed(color); |
| 325 | + button_widget_set_color_pressed(button, color); |
297 | 326 |
|
298 | | - button_widget_set_on_clicked(button, on_button_pilot_camera_clicked); |
| 327 | + button_widget_set_on_clicked(button, on_button_pilot_camera_clicked); |
299 | 328 |
|
300 | | - // Button text. |
| 329 | + // Button text. |
301 | 330 |
|
302 | | - te_text_widget* text_widget = text_widget_create(); |
303 | | - { |
304 | | - te_widget* widget = text_widget_get_widget(text_widget); |
305 | | - widget_set_parent(widget, button_widget_get_widget(button)); |
306 | | - widget_set_relative_position(widget, (vec2){hpadding, 0.0f}); |
307 | | - widget_set_relative_size(widget, (vec2){1.0f - hpadding, 1.0f}); |
308 | | - } |
| 331 | + te_text_widget* text_widget = text_widget_create(); |
| 332 | + { |
| 333 | + te_widget* widget = text_widget_get_widget(text_widget); |
| 334 | + widget_set_parent(widget, button_widget_get_widget(button)); |
| 335 | + widget_set_relative_position(widget, (vec2){hpadding, 0.0f}); |
| 336 | + widget_set_relative_size(widget, (vec2){1.0f - hpadding, 1.0f}); |
| 337 | + } |
309 | 338 |
|
310 | | - text_widget_set_text_height(text_widget, theme_get_text_height()); |
| 339 | + text_widget_set_text_height(text_widget, theme_get_text_height()); |
| 340 | + |
| 341 | + unsigned int text_len; |
| 342 | + wchar_t* text = wchar_from_char("Pilot camera", &text_len); |
| 343 | + text_widget_set_text_own(text_widget, text, text_len); |
| 344 | + |
| 345 | + pos[1] += size[1]; |
| 346 | + } else if ( |
| 347 | + type_info->get_game_object_info(obj)->type == TE_GOT_MODEL |
| 348 | + && model_get_skeleton(obj) != NULL) { |
| 349 | + // Add a button to preview skeleton animation. |
| 350 | + te_button_widget* button = button_widget_create(); |
| 351 | + { |
| 352 | + te_widget* widget = button_widget_get_widget(button); |
| 353 | + widget_set_custom_ptr(widget, inspector); |
| 354 | + widget_set_parent(widget, inspector->right_panel); |
| 355 | + widget_set_relative_position(widget, pos); |
| 356 | + widget_set_relative_size(widget, size); |
| 357 | + } |
311 | 358 |
|
312 | | - unsigned int text_len; |
313 | | - wchar_t* text = wchar_from_char("Pilot camera", &text_len); |
314 | | - text_widget_set_text_own(text_widget, text, text_len); |
| 359 | + vec4 color; |
| 360 | + theme_get_button_color(color); |
| 361 | + button_widget_set_color(button, color); |
315 | 362 |
|
316 | | - pos[1] += size[1]; |
| 363 | + theme_get_button_color_hovered(color); |
| 364 | + button_widget_set_color_hovered(button, color); |
| 365 | + |
| 366 | + theme_get_button_color_pressed(color); |
| 367 | + button_widget_set_color_pressed(button, color); |
| 368 | + |
| 369 | + button_widget_set_on_clicked(button, on_button_preview_animation_clicked); |
| 370 | + |
| 371 | + // Button text. |
| 372 | + |
| 373 | + te_text_widget* text_widget = text_widget_create(); |
| 374 | + { |
| 375 | + te_widget* widget = text_widget_get_widget(text_widget); |
| 376 | + widget_set_parent(widget, button_widget_get_widget(button)); |
| 377 | + widget_set_relative_position(widget, (vec2){hpadding, 0.0f}); |
| 378 | + widget_set_relative_size(widget, (vec2){1.0f - hpadding, 1.0f}); |
| 379 | + } |
| 380 | + |
| 381 | + text_widget_set_text_height(text_widget, theme_get_text_height()); |
| 382 | + |
| 383 | + unsigned int text_len; |
| 384 | + wchar_t* text = wchar_from_char("Preview animation", &text_len); |
| 385 | + text_widget_set_text_own(text_widget, text, text_len); |
| 386 | + |
| 387 | + pos[1] += size[1]; |
| 388 | + } |
317 | 389 | } |
318 | 390 |
|
319 | 391 | for (unsigned int var_idx = 0; var_idx < type_info->variable_count; var_idx++) { |
@@ -585,6 +657,18 @@ property_inspector_show(te_property_inspector* inspector, void* obj, const char* |
585 | 657 |
|
586 | 658 | void |
587 | 659 | property_inspector_hide(te_property_inspector* inspector) { |
| 660 | + { |
| 661 | + // Check if we have a model with skeleton animation preview playing. |
| 662 | + const te_type_info* type_info = type_database_get_type_info(inspector->obj_type_id); |
| 663 | + if (type_info != NULL && type_info->get_game_object_info != NULL |
| 664 | + && type_info->get_game_object_info(inspector->obj)->type == TE_GOT_MODEL) { |
| 665 | + te_skeleton* skeleton = model_get_skeleton(inspector->obj); |
| 666 | + if (skeleton != NULL) { |
| 667 | + skeleton_unload_animations(skeleton); |
| 668 | + } |
| 669 | + } |
| 670 | + } |
| 671 | + |
588 | 672 | inspector->obj = NULL; |
589 | 673 | inspector->obj_type_id = NULL; |
590 | 674 |
|
|
0 commit comments