ttt_multi.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include "ttt_multi.h"
  2. bool ttt_multi_custom_event_callback(void* context, uint32_t event) {
  3. furi_assert(context);
  4. TttMultiApp* ttt_multi = context;
  5. return scene_manager_handle_custom_event(ttt_multi->scene_manager, event);
  6. }
  7. bool ttt_multi_back_event_callback(void* context) {
  8. furi_assert(context);
  9. TttMultiApp* ttt_multi = context;
  10. return scene_manager_handle_back_event(ttt_multi->scene_manager);
  11. }
  12. void ttt_multi_tick_event_callback(void* context) {
  13. furi_assert(context);
  14. TttMultiApp* ttt_multi = context;
  15. scene_manager_handle_tick_event(ttt_multi->scene_manager);
  16. }
  17. TttMultiApp* ttt_multi_alloc() {
  18. TttMultiApp* ttt_multi = malloc(sizeof(TttMultiApp));
  19. ttt_multi->view_dispatcher = view_dispatcher_alloc();
  20. ttt_multi->scene_manager = scene_manager_alloc(&ttt_multi_scene_handlers, ttt_multi);
  21. view_dispatcher_enable_queue(ttt_multi->view_dispatcher);
  22. view_dispatcher_set_event_callback_context(ttt_multi->view_dispatcher, ttt_multi);
  23. view_dispatcher_set_custom_event_callback(
  24. ttt_multi->view_dispatcher, ttt_multi_custom_event_callback);
  25. view_dispatcher_set_navigation_event_callback(
  26. ttt_multi->view_dispatcher, ttt_multi_back_event_callback);
  27. view_dispatcher_set_tick_event_callback(
  28. ttt_multi->view_dispatcher, ttt_multi_tick_event_callback, 100);
  29. ttt_multi->gui = furi_record_open(RECORD_GUI);
  30. view_dispatcher_attach_to_gui(
  31. ttt_multi->view_dispatcher, ttt_multi->gui, ViewDispatcherTypeFullscreen);
  32. ttt_multi->notifications = furi_record_open(RECORD_NOTIFICATION);
  33. ttt_multi->game_view = ttt_multi_game_view_alloc();
  34. view_dispatcher_add_view(
  35. ttt_multi->view_dispatcher,
  36. TttMultiViewGame,
  37. ttt_multi_game_get_view(ttt_multi->game_view));
  38. ttt_multi->submenu = submenu_alloc();
  39. view_dispatcher_add_view(
  40. ttt_multi->view_dispatcher, TttMultiViewMenu, submenu_get_view(ttt_multi->submenu));
  41. return ttt_multi;
  42. }
  43. void ttt_multi_free(TttMultiApp* ttt_multi) {
  44. furi_assert(ttt_multi);
  45. notification_message(ttt_multi->notifications, &sequence_blink_stop);
  46. furi_record_close(RECORD_NOTIFICATION);
  47. ttt_multi->notifications = NULL;
  48. view_dispatcher_remove_view(ttt_multi->view_dispatcher, TttMultiViewGame);
  49. ttt_multi_game_view_free(ttt_multi->game_view);
  50. view_dispatcher_remove_view(ttt_multi->view_dispatcher, TttMultiViewMenu);
  51. submenu_free(ttt_multi->submenu);
  52. scene_manager_free(ttt_multi->scene_manager);
  53. view_dispatcher_free(ttt_multi->view_dispatcher);
  54. furi_record_close(RECORD_GUI);
  55. ttt_multi->gui = NULL;
  56. free(ttt_multi);
  57. }
  58. int32_t ttt_multi_app(void* p) {
  59. UNUSED(p);
  60. TttMultiApp* ttt_multi = ttt_multi_alloc();
  61. scene_manager_next_scene(ttt_multi->scene_manager, TttMultiSceneStart);
  62. view_dispatcher_run(ttt_multi->view_dispatcher);
  63. ttt_multi_free(ttt_multi);
  64. return 0;
  65. }