items.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #include <gui/elements.h>
  2. #include "applications.h"
  3. #include "items_i.h"
  4. const Item TV = {
  5. .layer = 7,
  6. .timeout = 10,
  7. .x = 160,
  8. .y = 34,
  9. .icon = &I_TV_20x24,
  10. .action_name = "Use",
  11. .draw = draw_tv,
  12. .callback = smash_tv};
  13. const Item Painting = {
  14. .layer = 3,
  15. .timeout = 20,
  16. .x = 160,
  17. .y = 10,
  18. .icon = &I_Home_painting_17x20,
  19. .action_name = "Inspect",
  20. .draw = NULL,
  21. .callback = inspect_painting};
  22. const Item Sofa = {
  23. .layer = 4,
  24. .timeout = 100,
  25. .x = 250,
  26. .y = 34,
  27. .icon = &I_Sofa_40x13,
  28. .action_name = "Sit",
  29. .draw = NULL,
  30. .callback = sofa_sit};
  31. const Item PC = {
  32. .layer = 4,
  33. .timeout = 100,
  34. .x = 400,
  35. .y = 10,
  36. .icon = &I_PC_22x29,
  37. .action_name = "Use",
  38. .draw = NULL,
  39. .callback = pc_callback};
  40. const Item* Home[ITEMS_NUM] = {&TV, &Sofa, &Painting, &PC};
  41. const Item** Scenes[1] = {*&Home};
  42. const Item** get_scene(SceneState* state) {
  43. return Scenes[state->scene_id];
  44. }
  45. static void dolphin_scene_start_app(SceneState* state, const FlipperApplication* flipper_app) {
  46. furi_assert(state);
  47. furi_assert(flipper_app);
  48. state->scene_app_thread = furi_thread_alloc();
  49. furi_assert(flipper_app->app);
  50. furi_assert(flipper_app->name);
  51. furi_thread_set_name(state->scene_app_thread, flipper_app->name);
  52. furi_thread_set_stack_size(state->scene_app_thread, flipper_app->stack_size);
  53. furi_thread_set_callback(state->scene_app_thread, flipper_app->app);
  54. furi_thread_start(state->scene_app_thread);
  55. }
  56. const void scene_activate_item_callback(SceneState* state, Canvas* canvas) {
  57. furi_assert(state);
  58. furi_assert(canvas);
  59. const Item* near = is_nearby(state);
  60. if(near && state->use_pending == true) {
  61. state->action_timeout = near->timeout;
  62. near->callback(canvas, state);
  63. state->use_pending = false;
  64. } else if(near) {
  65. near->callback(canvas, state);
  66. }
  67. }
  68. const Item* is_nearby(SceneState* state) {
  69. furi_assert(state);
  70. uint8_t item = 0;
  71. bool found = false;
  72. const Item** current = get_scene(state);
  73. while(item < ITEMS_NUM) {
  74. int32_t rel =
  75. (DOLPHIN_CENTER + DOLPHIN_WIDTH / 2 -
  76. (current[item]->x - state->player_global.x) * PARALLAX(current[item]->layer));
  77. if(abs(rel) <= DOLPHIN_WIDTH / 2) {
  78. found = !found;
  79. break;
  80. }
  81. ++item;
  82. }
  83. return found ? current[item] : NULL;
  84. }
  85. void draw_tv(Canvas* canvas, void* state) {
  86. furi_assert(state);
  87. SceneState* s = state;
  88. canvas_set_color(canvas, ColorWhite);
  89. canvas_draw_box(
  90. canvas, (TV.x + 3 - s->player_global.x) * PARALLAX(TV.layer), TV.y + 4, 16, 20);
  91. canvas_set_color(canvas, ColorBlack);
  92. canvas_set_bitmap_mode(canvas, true);
  93. }
  94. void smash_tv(Canvas* canvas, void* state) {
  95. furi_assert(state);
  96. SceneState* s = state;
  97. s->player_flipped = true;
  98. canvas_set_bitmap_mode(canvas, true);
  99. canvas_draw_icon(
  100. canvas, ((TV.x - 5) - s->player_global.x) * PARALLAX(TV.layer), TV.y - 2, &I_FX_Bang_32x6);
  101. canvas_set_bitmap_mode(canvas, false);
  102. if(s->action_timeout < TV.timeout - 2) {
  103. elements_multiline_text_framed(canvas, 80, 24, "Bang!");
  104. }
  105. }
  106. void sofa_sit(Canvas* canvas, void* state) {
  107. furi_assert(state);
  108. SceneState* s = state;
  109. // temp fix pos
  110. s->player_global.x = 154;
  111. s->dolphin_gfx = &A_FX_Sitting_40x27;
  112. s->dolphin_gfx_b = &I_FX_SittingB_40x27;
  113. }
  114. void inspect_painting(Canvas* canvas, void* state) {
  115. furi_assert(state);
  116. SceneState* s = state;
  117. if(s->use_pending) {
  118. dolphin_scene_start_app(s, &FLIPPER_SCENE_APPS[0]);
  119. }
  120. }
  121. void pc_callback(Canvas* canvas, void* state) {
  122. furi_assert(state);
  123. SceneState* s = state;
  124. if(s->use_pending) {
  125. dolphin_scene_start_app(s, &FLIPPER_SCENE_APPS[1]);
  126. }
  127. }