2021-12-07 16:13:07 +03:00
|
|
|
#include "assets_icons.h"
|
|
|
|
#include "dolphin/helpers/dolphin_state.h"
|
2022-07-20 13:56:33 +03:00
|
|
|
#include <core/check.h>
|
|
|
|
#include <core/record.h>
|
2021-12-07 16:13:07 +03:00
|
|
|
#include <furi.h>
|
|
|
|
#include <gui/gui.h>
|
2022-01-05 19:10:18 +03:00
|
|
|
#include <furi_hal_version.h>
|
2021-12-07 16:13:07 +03:00
|
|
|
#include "dolphin/dolphin.h"
|
|
|
|
#include "math.h"
|
|
|
|
|
|
|
|
#define MOODS_TOTAL 3
|
|
|
|
#define BUTTHURT_MAX 3
|
|
|
|
|
2022-02-13 22:24:03 +03:00
|
|
|
static const Icon* const portrait_happy[BUTTHURT_MAX] = {
|
2021-12-07 16:13:07 +03:00
|
|
|
&I_passport_happy1_46x49,
|
|
|
|
&I_passport_happy2_46x49,
|
|
|
|
&I_passport_happy3_46x49};
|
2022-02-13 22:24:03 +03:00
|
|
|
static const Icon* const portrait_ok[BUTTHURT_MAX] = {
|
2021-12-07 16:13:07 +03:00
|
|
|
&I_passport_okay1_46x49,
|
|
|
|
&I_passport_okay2_46x49,
|
|
|
|
&I_passport_okay3_46x49};
|
2022-02-13 22:24:03 +03:00
|
|
|
static const Icon* const portrait_bad[BUTTHURT_MAX] = {
|
2021-12-07 16:13:07 +03:00
|
|
|
&I_passport_bad1_46x49,
|
|
|
|
&I_passport_bad2_46x49,
|
|
|
|
&I_passport_bad3_46x49};
|
2022-02-13 22:24:03 +03:00
|
|
|
|
|
|
|
static const Icon* const* portraits[MOODS_TOTAL] = {portrait_happy, portrait_ok, portrait_bad};
|
2021-12-07 16:13:07 +03:00
|
|
|
|
|
|
|
static void input_callback(InputEvent* input, void* ctx) {
|
2022-07-20 13:56:33 +03:00
|
|
|
FuriSemaphore* semaphore = ctx;
|
2021-12-07 16:13:07 +03:00
|
|
|
|
|
|
|
if((input->type == InputTypeShort) && (input->key == InputKeyBack)) {
|
2022-07-20 13:56:33 +03:00
|
|
|
furi_semaphore_release(semaphore);
|
2021-12-07 16:13:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void render_callback(Canvas* canvas, void* ctx) {
|
|
|
|
DolphinStats* stats = ctx;
|
|
|
|
|
|
|
|
char level_str[20];
|
|
|
|
char mood_str[32];
|
|
|
|
uint8_t mood = 0;
|
|
|
|
|
|
|
|
if(stats->butthurt <= 4) {
|
|
|
|
mood = 0;
|
|
|
|
snprintf(mood_str, 20, "Mood: Happy");
|
|
|
|
} else if(stats->butthurt <= 9) {
|
|
|
|
mood = 1;
|
|
|
|
snprintf(mood_str, 20, "Mood: Ok");
|
|
|
|
} else {
|
|
|
|
mood = 2;
|
|
|
|
snprintf(mood_str, 20, "Mood: Angry");
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t xp_progress = 0;
|
|
|
|
uint32_t xp_to_levelup = dolphin_state_xp_to_levelup(stats->icounter);
|
|
|
|
uint32_t xp_for_current_level =
|
|
|
|
xp_to_levelup + dolphin_state_xp_above_last_levelup(stats->icounter);
|
|
|
|
if(stats->level == 3) {
|
|
|
|
xp_progress = 0;
|
|
|
|
} else {
|
|
|
|
xp_progress = xp_to_levelup * 64 / xp_for_current_level;
|
|
|
|
}
|
|
|
|
|
|
|
|
// multipass
|
|
|
|
canvas_draw_icon(canvas, 0, 0, &I_passport_left_6x46);
|
|
|
|
canvas_draw_icon(canvas, 0, 46, &I_passport_bottom_128x18);
|
|
|
|
canvas_draw_line(canvas, 6, 0, 125, 0);
|
|
|
|
canvas_draw_line(canvas, 127, 2, 127, 47);
|
|
|
|
canvas_draw_dot(canvas, 126, 1);
|
|
|
|
|
|
|
|
// portrait
|
|
|
|
furi_assert((stats->level > 0) && (stats->level <= 3));
|
|
|
|
canvas_draw_icon(canvas, 9, 5, portraits[mood][stats->level - 1]);
|
|
|
|
canvas_draw_line(canvas, 58, 16, 123, 16);
|
|
|
|
canvas_draw_line(canvas, 58, 30, 123, 30);
|
|
|
|
canvas_draw_line(canvas, 58, 44, 123, 44);
|
|
|
|
|
|
|
|
const char* my_name = furi_hal_version_get_name_ptr();
|
|
|
|
snprintf(level_str, 20, "Level: %hu", stats->level);
|
|
|
|
canvas_draw_str(canvas, 58, 12, my_name ? my_name : "Unknown");
|
|
|
|
canvas_draw_str(canvas, 58, 26, mood_str);
|
|
|
|
canvas_draw_str(canvas, 58, 40, level_str);
|
|
|
|
|
|
|
|
canvas_set_color(canvas, ColorWhite);
|
|
|
|
canvas_draw_box(canvas, 123 - xp_progress, 47, xp_progress + 1, 6);
|
|
|
|
canvas_set_color(canvas, ColorBlack);
|
|
|
|
canvas_draw_line(canvas, 123, 47, 123, 52);
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t passport_app(void* p) {
|
2022-05-06 16:37:10 +03:00
|
|
|
UNUSED(p);
|
2022-07-20 13:56:33 +03:00
|
|
|
FuriSemaphore* semaphore = furi_semaphore_alloc(1, 0);
|
2021-12-07 16:13:07 +03:00
|
|
|
furi_assert(semaphore);
|
|
|
|
|
|
|
|
ViewPort* view_port = view_port_alloc();
|
|
|
|
|
2022-07-26 15:21:51 +03:00
|
|
|
Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN);
|
2021-12-07 16:13:07 +03:00
|
|
|
DolphinStats stats = dolphin_stats(dolphin);
|
2022-07-26 15:21:51 +03:00
|
|
|
furi_record_close(RECORD_DOLPHIN);
|
2021-12-07 16:13:07 +03:00
|
|
|
view_port_draw_callback_set(view_port, render_callback, &stats);
|
|
|
|
view_port_input_callback_set(view_port, input_callback, semaphore);
|
2022-07-26 15:21:51 +03:00
|
|
|
Gui* gui = furi_record_open(RECORD_GUI);
|
2021-12-07 16:13:07 +03:00
|
|
|
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
|
|
|
|
view_port_update(view_port);
|
|
|
|
|
2022-07-20 13:56:33 +03:00
|
|
|
furi_check(furi_semaphore_acquire(semaphore, FuriWaitForever) == FuriStatusOk);
|
2021-12-07 16:13:07 +03:00
|
|
|
|
|
|
|
gui_remove_view_port(gui, view_port);
|
|
|
|
view_port_free(view_port);
|
2022-07-26 15:21:51 +03:00
|
|
|
furi_record_close(RECORD_GUI);
|
2022-07-20 13:56:33 +03:00
|
|
|
furi_semaphore_free(semaphore);
|
2021-12-07 16:13:07 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|