2021-04-13 18:06:25 +00:00
|
|
|
#include <gui/elements.h>
|
|
|
|
#include "applications.h"
|
2021-04-26 12:19:14 +00:00
|
|
|
#include "items_i.h"
|
2021-04-13 18:06:25 +00:00
|
|
|
|
|
|
|
const Item TV = {
|
|
|
|
.layer = 7,
|
|
|
|
.timeout = 10,
|
|
|
|
.x = 160,
|
|
|
|
.y = 34,
|
2021-07-07 08:57:49 +00:00
|
|
|
.icon = &I_TV_20x24,
|
2021-04-13 18:06:25 +00:00
|
|
|
.action_name = "Use",
|
|
|
|
.draw = draw_tv,
|
|
|
|
.callback = smash_tv};
|
|
|
|
|
|
|
|
const Item Painting = {
|
|
|
|
.layer = 3,
|
|
|
|
.timeout = 20,
|
|
|
|
.x = 160,
|
|
|
|
.y = 10,
|
2021-07-07 08:57:49 +00:00
|
|
|
.icon = &I_Home_painting_17x20,
|
2021-04-13 18:06:25 +00:00
|
|
|
.action_name = "Inspect",
|
|
|
|
.draw = NULL,
|
|
|
|
.callback = inspect_painting};
|
|
|
|
|
|
|
|
const Item Sofa = {
|
|
|
|
.layer = 4,
|
|
|
|
.timeout = 100,
|
|
|
|
.x = 250,
|
|
|
|
.y = 34,
|
2021-07-07 08:57:49 +00:00
|
|
|
.icon = &I_Sofa_40x13,
|
2021-04-13 18:06:25 +00:00
|
|
|
.action_name = "Sit",
|
|
|
|
.draw = NULL,
|
|
|
|
.callback = sofa_sit};
|
|
|
|
|
|
|
|
const Item PC = {
|
|
|
|
.layer = 4,
|
|
|
|
.timeout = 100,
|
|
|
|
.x = 400,
|
|
|
|
.y = 10,
|
2021-07-07 08:57:49 +00:00
|
|
|
.icon = &I_PC_22x29,
|
2021-04-13 18:06:25 +00:00
|
|
|
.action_name = "Use",
|
|
|
|
.draw = NULL,
|
|
|
|
.callback = pc_callback};
|
|
|
|
|
|
|
|
const Item* Home[ITEMS_NUM] = {&TV, &Sofa, &Painting, &PC};
|
|
|
|
const Item** Scenes[1] = {*&Home};
|
|
|
|
|
|
|
|
const Item** get_scene(SceneState* state) {
|
|
|
|
return Scenes[state->scene_id];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dolphin_scene_start_app(SceneState* state, const FlipperApplication* flipper_app) {
|
|
|
|
furi_assert(state);
|
|
|
|
furi_assert(flipper_app);
|
|
|
|
|
2021-04-15 16:39:15 +00:00
|
|
|
state->scene_app_thread = furi_thread_alloc();
|
2021-04-13 18:06:25 +00:00
|
|
|
|
|
|
|
furi_assert(flipper_app->app);
|
|
|
|
furi_assert(flipper_app->name);
|
|
|
|
|
2021-04-15 16:39:15 +00:00
|
|
|
furi_thread_set_name(state->scene_app_thread, flipper_app->name);
|
|
|
|
furi_thread_set_stack_size(state->scene_app_thread, flipper_app->stack_size);
|
|
|
|
furi_thread_set_callback(state->scene_app_thread, flipper_app->app);
|
|
|
|
furi_thread_start(state->scene_app_thread);
|
2021-04-13 18:06:25 +00:00
|
|
|
}
|
|
|
|
|
2021-04-26 12:19:14 +00:00
|
|
|
const void scene_activate_item_callback(SceneState* state, Canvas* canvas) {
|
|
|
|
furi_assert(state);
|
|
|
|
furi_assert(canvas);
|
|
|
|
|
|
|
|
const Item* near = is_nearby(state);
|
|
|
|
if(near && state->use_pending == true) {
|
|
|
|
state->action_timeout = near->timeout;
|
|
|
|
near->callback(canvas, state);
|
|
|
|
state->use_pending = false;
|
|
|
|
} else if(near) {
|
|
|
|
near->callback(canvas, state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-13 18:06:25 +00:00
|
|
|
const Item* is_nearby(SceneState* state) {
|
|
|
|
furi_assert(state);
|
|
|
|
uint8_t item = 0;
|
|
|
|
bool found = false;
|
|
|
|
const Item** current = get_scene(state);
|
|
|
|
while(item < ITEMS_NUM) {
|
|
|
|
int32_t rel =
|
|
|
|
(DOLPHIN_CENTER + DOLPHIN_WIDTH / 2 -
|
|
|
|
(current[item]->x - state->player_global.x) * PARALLAX(current[item]->layer));
|
|
|
|
if(abs(rel) <= DOLPHIN_WIDTH / 2) {
|
|
|
|
found = !found;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++item;
|
|
|
|
}
|
|
|
|
return found ? current[item] : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void draw_tv(Canvas* canvas, void* state) {
|
|
|
|
furi_assert(state);
|
|
|
|
SceneState* s = state;
|
|
|
|
canvas_set_color(canvas, ColorWhite);
|
|
|
|
canvas_draw_box(
|
|
|
|
canvas, (TV.x + 3 - s->player_global.x) * PARALLAX(TV.layer), TV.y + 4, 16, 20);
|
|
|
|
canvas_set_color(canvas, ColorBlack);
|
|
|
|
canvas_set_bitmap_mode(canvas, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void smash_tv(Canvas* canvas, void* state) {
|
|
|
|
furi_assert(state);
|
|
|
|
SceneState* s = state;
|
|
|
|
s->player_flipped = true;
|
|
|
|
canvas_set_bitmap_mode(canvas, true);
|
2021-07-07 08:57:49 +00:00
|
|
|
canvas_draw_icon(
|
|
|
|
canvas, ((TV.x - 5) - s->player_global.x) * PARALLAX(TV.layer), TV.y - 2, &I_FX_Bang_32x6);
|
2021-04-13 18:06:25 +00:00
|
|
|
canvas_set_bitmap_mode(canvas, false);
|
|
|
|
if(s->action_timeout < TV.timeout - 2) {
|
|
|
|
elements_multiline_text_framed(canvas, 80, 24, "Bang!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void sofa_sit(Canvas* canvas, void* state) {
|
|
|
|
furi_assert(state);
|
|
|
|
SceneState* s = state;
|
|
|
|
// temp fix pos
|
|
|
|
s->player_global.x = 154;
|
2021-07-07 08:57:49 +00:00
|
|
|
s->dolphin_gfx = &A_FX_Sitting_40x27;
|
|
|
|
s->dolphin_gfx_b = &I_FX_SittingB_40x27;
|
2021-04-13 18:06:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void inspect_painting(Canvas* canvas, void* state) {
|
|
|
|
furi_assert(state);
|
|
|
|
SceneState* s = state;
|
|
|
|
if(s->use_pending) {
|
|
|
|
dolphin_scene_start_app(s, &FLIPPER_SCENE_APPS[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void pc_callback(Canvas* canvas, void* state) {
|
|
|
|
furi_assert(state);
|
|
|
|
SceneState* s = state;
|
|
|
|
if(s->use_pending) {
|
|
|
|
dolphin_scene_start_app(s, &FLIPPER_SCENE_APPS[1]);
|
|
|
|
}
|
2021-04-26 12:19:14 +00:00
|
|
|
}
|