desktop_scene_levelup.c 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include "../desktop_i.h"
  2. #include "../views/desktop_main.h"
  3. #include "applications.h"
  4. #include "assets_icons.h"
  5. #include "desktop/desktop.h"
  6. #include "desktop/helpers/desktop_animation.h"
  7. #include "dolphin/dolphin.h"
  8. #include "furi/pubsub.h"
  9. #include "furi/record.h"
  10. #include "storage/storage-glue.h"
  11. #include <loader/loader.h>
  12. #include <m-list.h>
  13. #define LEVELUP_SCENE_PLAYING 0
  14. #define LEVELUP_SCENE_STOPPED 1
  15. static void desktop_scene_levelup_callback(DesktopMainEvent event, void* context) {
  16. Desktop* desktop = (Desktop*)context;
  17. view_dispatcher_send_custom_event(desktop->view_dispatcher, event);
  18. }
  19. static void desktop_scene_levelup_animation_changed_callback(void* context) {
  20. furi_assert(context);
  21. Desktop* desktop = context;
  22. view_dispatcher_send_custom_event(
  23. desktop->view_dispatcher, DesktopMainEventUpdateOneShotAnimation);
  24. }
  25. void desktop_scene_levelup_on_enter(void* context) {
  26. Desktop* desktop = (Desktop*)context;
  27. DesktopMainView* main_view = desktop->main_view;
  28. desktop_main_set_callback(main_view, desktop_scene_levelup_callback, desktop);
  29. desktop_animation_set_animation_changed_callback(
  30. desktop->animation, desktop_scene_levelup_animation_changed_callback, desktop);
  31. desktop_animation_start_oneshot_levelup(desktop->animation);
  32. const Icon* icon = desktop_animation_get_oneshot_frame(desktop->animation);
  33. desktop_main_switch_dolphin_icon(desktop->main_view, icon);
  34. view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewMain);
  35. scene_manager_set_scene_state(
  36. desktop->scene_manager, DesktopSceneLevelUp, LEVELUP_SCENE_PLAYING);
  37. }
  38. bool desktop_scene_levelup_on_event(void* context, SceneManagerEvent event) {
  39. Desktop* desktop = (Desktop*)context;
  40. bool consumed = false;
  41. DesktopMainEvent main_event = event.event;
  42. if(event.type == SceneManagerEventTypeCustom) {
  43. if(main_event == DesktopMainEventUpdateOneShotAnimation) {
  44. const Icon* icon = desktop_animation_get_oneshot_frame(desktop->animation);
  45. if(icon) {
  46. desktop_main_switch_dolphin_icon(desktop->main_view, icon);
  47. } else {
  48. scene_manager_set_scene_state(
  49. desktop->scene_manager, DesktopSceneLevelUp, LEVELUP_SCENE_STOPPED);
  50. }
  51. consumed = true;
  52. } else {
  53. if(scene_manager_get_scene_state(desktop->scene_manager, DesktopSceneLevelUp) ==
  54. LEVELUP_SCENE_STOPPED) {
  55. scene_manager_previous_scene(desktop->scene_manager);
  56. }
  57. }
  58. }
  59. return consumed;
  60. }
  61. void desktop_scene_levelup_on_exit(void* context) {
  62. Desktop* desktop = (Desktop*)context;
  63. Dolphin* dolphin = furi_record_open("dolphin");
  64. dolphin_upgrade_level(dolphin);
  65. furi_record_close("dolphin");
  66. desktop_animation_set_animation_changed_callback(desktop->animation, NULL, NULL);
  67. desktop_start_new_idle_animation(desktop->animation);
  68. }