scene.c 5.3 KB

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