scene_gfx.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. #include <furi.h>
  2. #include "scene.h"
  3. #include "assets/emotes.h"
  4. #include "assets/items.h"
  5. #include <gui/elements.h>
  6. const char* action_str[] = {"Sleep", "Idle", "Walk", "Emote", "Use", "MC"};
  7. static void scene_draw_hint(SceneState* state, Canvas* canvas, bool glitching) {
  8. furi_assert(state);
  9. furi_assert(canvas);
  10. char buf[32];
  11. const Item* near = is_nearby(state);
  12. if(near) {
  13. int32_t hint_pos_x = (near->x - state->player_global.x) * PARALLAX(near->layer) + 25;
  14. int8_t hint_pos_y = near->y < 15 ? near->y + 4 : near->y - 16;
  15. strcpy(buf, near->action_name);
  16. if(glitching) {
  17. for(size_t g = 0; g != state->action_timeout; g++) {
  18. buf[(g * 23) % strlen(buf)] = ' ' + (random() % g * 17) % ('z' - ' ');
  19. }
  20. }
  21. canvas_draw_str(canvas, hint_pos_x, hint_pos_y, buf);
  22. }
  23. }
  24. static void scene_draw_current_emote(SceneState* state, Canvas* canvas) {
  25. furi_assert(state);
  26. furi_assert(canvas);
  27. elements_multiline_text_framed(canvas, 80, 20, (char*)emotes_list[state->emote_id]);
  28. }
  29. static void scene_draw_sleep_emote(SceneState* state, Canvas* canvas) {
  30. furi_assert(state);
  31. furi_assert(canvas);
  32. char dialog_str[] = "zZzZ...";
  33. char buf[64];
  34. // 2do - sofa x pos getter
  35. if(state->player_global.x == 154 && state->action_timeout % 100 < 30) {
  36. if(state->dialog_progress < strlen(dialog_str)) {
  37. if(state->action_timeout % 5 == 0) state->dialog_progress++;
  38. dialog_str[state->dialog_progress] = '\0';
  39. snprintf(buf, state->dialog_progress, dialog_str);
  40. // bubble vs just text?
  41. //elements_multiline_text_framed(canvas, 80, 20, buf);
  42. canvas_draw_str(canvas, 80, 20, buf);
  43. }
  44. } else {
  45. state->dialog_progress = 0;
  46. }
  47. }
  48. static void scene_draw_dialog(SceneState* state, Canvas* canvas) {
  49. furi_assert(state);
  50. furi_assert(canvas);
  51. char dialog_str[64];
  52. char buf[64];
  53. strcpy(dialog_str, (char*)dialogues_list[state->dialogue_id]);
  54. if(state->dialog_progress <= strlen(dialog_str)) {
  55. if(state->action_timeout % 2 == 0) state->dialog_progress++;
  56. dialog_str[state->dialog_progress] = '\0';
  57. snprintf(buf, state->dialog_progress, dialog_str);
  58. } else {
  59. snprintf(buf, 64, dialog_str);
  60. }
  61. elements_multiline_text_framed(canvas, 68, 16, buf);
  62. }
  63. /*
  64. static void draw_idle_emote(SceneState* state, Canvas* canvas){
  65. if(state->action_timeout % 50 < 40 && state->prev_action == MINDCONTROL){
  66. elements_multiline_text_framed(canvas, 68, 16, "WUT?!");
  67. }
  68. }
  69. */
  70. void dolphin_scene_render_dolphin(SceneState* state, Canvas* canvas) {
  71. furi_assert(state);
  72. furi_assert(canvas);
  73. if(state->scene_zoom == SCENE_ZOOM) {
  74. state->dolphin_gfx = I_DolphinExcited_64x63;
  75. } else if(state->action == SLEEP && state->player_global.x == 154) { // 2do - sofa x pos getter
  76. state->dolphin_gfx = A_FX_Sitting_40x27;
  77. state->dolphin_gfx_b = I_FX_SittingB_40x27;
  78. } else if(state->action != INTERACT) {
  79. if(state->player_v.x < 0 || state->player_flipped) {
  80. if(state->player_anim == 0) {
  81. state->dolphin_gfx = I_WalkL1_32x32;
  82. state->dolphin_gfx_b = I_WalkLB1_32x32;
  83. } else {
  84. state->dolphin_gfx = I_WalkL2_32x32;
  85. state->dolphin_gfx_b = I_WalkLB2_32x32;
  86. }
  87. } else if(state->player_v.x > 0 || !state->player_flipped) {
  88. if(state->player_anim == 0) {
  89. state->dolphin_gfx = I_WalkR1_32x32;
  90. state->dolphin_gfx_b = I_WalkRB1_32x32;
  91. } else {
  92. state->dolphin_gfx = I_WalkR2_32x32;
  93. state->dolphin_gfx_b = I_WalkRB2_32x32;
  94. }
  95. }
  96. }
  97. canvas_set_bitmap_mode(canvas, true);
  98. canvas_set_color(canvas, ColorWhite);
  99. canvas_draw_icon_name(canvas, state->player.x, state->player.y, state->dolphin_gfx_b);
  100. canvas_set_color(canvas, ColorBlack);
  101. canvas_draw_icon_name(canvas, state->player.x, state->player.y, state->dolphin_gfx);
  102. canvas_set_bitmap_mode(canvas, false);
  103. }
  104. static bool item_screen_bounds(int32_t pos) {
  105. return pos > -SCREEN_WIDTH && pos < (SCREEN_WIDTH * 2);
  106. }
  107. void dolphin_scene_render(SceneState* state, Canvas* canvas, uint32_t t) {
  108. furi_assert(state);
  109. furi_assert(canvas);
  110. canvas_set_font(canvas, FontSecondary);
  111. canvas_set_color(canvas, ColorBlack);
  112. const Item** current_scene = get_scene(state);
  113. for(uint8_t l = 0; l < LAYERS; l++) {
  114. if(state->scene_zoom < SCENE_ZOOM) {
  115. for(uint8_t i = 0; i < ITEMS_NUM; i++) {
  116. int32_t item_pos = (current_scene[i]->x - state->player_global.x);
  117. if(item_screen_bounds(item_pos)) {
  118. if(current_scene[i]->draw) current_scene[i]->draw(canvas, state);
  119. if(l == current_scene[i]->layer) {
  120. canvas_draw_icon_name(
  121. canvas,
  122. item_pos * PARALLAX(l),
  123. current_scene[i]->y,
  124. current_scene[i]->icon);
  125. canvas_set_bitmap_mode(canvas, false);
  126. }
  127. }
  128. }
  129. if(l == 0) canvas_draw_line(canvas, 0, 42, 128, 42);
  130. }
  131. if(l == DOLPHIN_LAYER) dolphin_scene_render_dolphin(state, canvas);
  132. }
  133. }
  134. void dolphin_scene_render_state(SceneState* state, Canvas* canvas) {
  135. furi_assert(state);
  136. furi_assert(canvas);
  137. char buf[64];
  138. canvas_set_font(canvas, FontSecondary);
  139. canvas_set_color(canvas, ColorBlack);
  140. // dolphin_scene_debug
  141. if(state->debug) {
  142. sprintf(
  143. buf,
  144. "x:%ld>%d %ld %s",
  145. state->player_global.x,
  146. state->poi,
  147. state->action_timeout,
  148. action_str[state->action]);
  149. canvas_draw_str(canvas, 0, 13, buf);
  150. }
  151. if(state->scene_zoom == SCENE_ZOOM)
  152. scene_draw_dialog(state, canvas);
  153. else if(state->action == EMOTE)
  154. scene_draw_current_emote(state, canvas);
  155. else if(state->action == MINDCONTROL)
  156. scene_draw_hint(state, canvas, state->action_timeout > 45);
  157. else if(state->action == INTERACT)
  158. scene_activate_item_callback(state, canvas);
  159. else if(state->action == SLEEP)
  160. scene_draw_sleep_emote(state, canvas);
  161. /*
  162. else if(state->action == IDLE)
  163. draw_idle_emote(state, canvas);
  164. */
  165. }