diff options
author | Albert Kharisov <albkharisov@gmail.com> | 2021-12-07 16:13:07 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-07 16:13:07 +0300 |
commit | 604d80aed4ed6f74d94b9e66747d88cad1e16aee (patch) | |
tree | b7bf0d87317548f31a830c7b1e544bbd5b056664 /applications/dolphin | |
parent | 185647a09af129a82b50e39002b4e63adf2db84b (diff) |
[FL-2083] Bring Passport back (#868)
* [FL-2083] Bring Passport back
* Move Passport to Settings
* Hide icounter editing
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
Diffstat (limited to 'applications/dolphin')
-rw-r--r-- | applications/dolphin/helpers/dolphin_state.c | 12 | ||||
-rw-r--r-- | applications/dolphin/helpers/dolphin_state.h | 2 | ||||
-rw-r--r-- | applications/dolphin/passport/passport.c | 115 |
3 files changed, 129 insertions, 0 deletions
diff --git a/applications/dolphin/helpers/dolphin_state.c b/applications/dolphin/helpers/dolphin_state.c index 2878edf5..016d8a50 100644 --- a/applications/dolphin/helpers/dolphin_state.c +++ b/applications/dolphin/helpers/dolphin_state.c @@ -102,6 +102,18 @@ uint8_t dolphin_get_level(uint32_t icounter) { } } +uint32_t dolphin_state_xp_above_last_levelup(uint32_t icounter) { + uint32_t threshold = 0; + if(icounter <= LEVEL2_THRESHOLD) { + threshold = 0; + } else if(icounter <= LEVEL3_THRESHOLD) { + threshold = LEVEL2_THRESHOLD + 1; + } else { + threshold = LEVEL3_THRESHOLD + 1; + } + return icounter - threshold; +} + uint32_t dolphin_state_xp_to_levelup(uint32_t icounter) { uint32_t threshold = 0; if(icounter <= LEVEL2_THRESHOLD) { diff --git a/applications/dolphin/helpers/dolphin_state.h b/applications/dolphin/helpers/dolphin_state.h index 25d2d9d2..1196e256 100644 --- a/applications/dolphin/helpers/dolphin_state.h +++ b/applications/dolphin/helpers/dolphin_state.h @@ -42,6 +42,8 @@ void dolphin_state_butthurted(DolphinState* dolphin_state); uint32_t dolphin_state_xp_to_levelup(uint32_t icounter); +uint32_t dolphin_state_xp_above_last_levelup(uint32_t icounter); + bool dolphin_state_is_levelup(uint32_t icounter); void dolphin_state_increase_level(DolphinState* dolphin_state); diff --git a/applications/dolphin/passport/passport.c b/applications/dolphin/passport/passport.c new file mode 100644 index 00000000..4be35566 --- /dev/null +++ b/applications/dolphin/passport/passport.c @@ -0,0 +1,115 @@ +#include "assets_icons.h" +#include "cmsis_os2.h" +#include "dolphin/helpers/dolphin_state.h" +#include "furi/check.h" +#include "furi/record.h" +#include <furi.h> +#include <gui/gui.h> +#include <furi-hal-version.h> +#include "dolphin/dolphin.h" +#include "math.h" + +#define MOODS_TOTAL 3 +#define BUTTHURT_MAX 3 + +static const Icon* portrait_happy[BUTTHURT_MAX] = { + &I_passport_happy1_46x49, + &I_passport_happy2_46x49, + &I_passport_happy3_46x49}; +static const Icon* portrait_ok[BUTTHURT_MAX] = { + &I_passport_okay1_46x49, + &I_passport_okay2_46x49, + &I_passport_okay3_46x49}; +static const Icon* portrait_bad[BUTTHURT_MAX] = { + &I_passport_bad1_46x49, + &I_passport_bad2_46x49, + &I_passport_bad3_46x49}; +static const Icon** portraits[MOODS_TOTAL] = {portrait_happy, portrait_ok, portrait_bad}; + +static void input_callback(InputEvent* input, void* ctx) { + osSemaphoreId_t semaphore = ctx; + + if((input->type == InputTypeShort) && (input->key == InputKeyBack)) { + osSemaphoreRelease(semaphore); + } +} + +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) { + osSemaphoreId_t semaphore = osSemaphoreNew(1, 0, NULL); + furi_assert(semaphore); + + ViewPort* view_port = view_port_alloc(); + + Dolphin* dolphin = furi_record_open("dolphin"); + DolphinStats stats = dolphin_stats(dolphin); + furi_record_close("dolphin"); + view_port_draw_callback_set(view_port, render_callback, &stats); + view_port_input_callback_set(view_port, input_callback, semaphore); + Gui* gui = furi_record_open("gui"); + gui_add_view_port(gui, view_port, GuiLayerFullscreen); + view_port_update(view_port); + + osStatus_t status = osSemaphoreAcquire(semaphore, osWaitForever); + furi_assert(status == osOK); + + gui_remove_view_port(gui, view_port); + view_port_free(view_port); + furi_record_close("gui"); + osSemaphoreDelete(semaphore); + + return 0; +} |