[FL-2183] [FL-2209] Dolphin Deeds, Level up, assets generation, refactoring (#965)
* Desktop: cleanup headers * Get loader pubsub via record * [FL-2183] Dolphin refactoring 2022.01 * Restruct animations assets structure * Rename assets * Cleanup headers * Update Recording animation * Add BadBattery animation * Provide loader's pubsub via record * Fix load/unload animations * Scripts: add flipper format support, initial dolphin packager rework. Assets: internal and external dolphin. * Sync internal meta.txt and manifest.txt * Reorder, rename dolphin assets * Split essential generated assets * Add ReadMe for dolphin assets * Separate essential blocking animations * Scripts: full dolphin validation before packaging * Assets, Scripts: dolphin external resources packer * Github: update codeowners * Scripts: proper slots handling in dolphin animation meta * Scripts: correct frames enumeration and fix compiled assets. * [FL-2209] Add Dolphin Deeds points and many more * Remove excess frame_rate * Change dolphin assets directory * Scripts: add internal resource support to dolphin compiler * Scripts: add internal assets generation, renaming * Scripts: correct assert, renaming * Code cleanup, documentation, fixes * Update Levelup animations * Rename essential -> blocking * Fix Unlocked hint * Scripts: rewrite Templite compiller, replace regexps with token parser, split block types into code and variable blocks. Update dolphin templates. * Documentation: add key combos description and use information * Scripts: cleanup templit, more debug info and add dev comment Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -1,23 +1,19 @@
|
||||
|
||||
#include "cmsis_os2.h"
|
||||
#include "../animation_manager.h"
|
||||
#include "../animation_storage.h"
|
||||
#include "furi_hal_delay.h"
|
||||
#include "furi_hal_resources.h"
|
||||
#include "furi/check.h"
|
||||
#include "furi/memmgr.h"
|
||||
#include "gui/canvas.h"
|
||||
#include "gui/elements.h"
|
||||
#include "gui/view.h"
|
||||
#include "input/input.h"
|
||||
#include "bubble_animation_view.h"
|
||||
|
||||
#include <furi_hal.h>
|
||||
#include <furi.h>
|
||||
#include "portmacro.h"
|
||||
#include <gui/icon.h>
|
||||
#include <gui/canvas.h>
|
||||
#include <gui/elements.h>
|
||||
#include <gui/view.h>
|
||||
#include <gui/icon_i.h>
|
||||
#include <input/input.h>
|
||||
#include <stdint.h>
|
||||
#include <FreeRTOS.h>
|
||||
#include <timers.h>
|
||||
#include "bubble_animation_view.h"
|
||||
#include <gui/icon_i.h>
|
||||
#include <furi/dangerous_defines.h>
|
||||
|
||||
#define ACTIVE_SHIFT 2
|
||||
|
||||
@@ -43,7 +39,7 @@ struct BubbleAnimationView {
|
||||
static void bubble_animation_activate(BubbleAnimationView* view, bool force);
|
||||
static void bubble_animation_activate_right_now(BubbleAnimationView* view);
|
||||
|
||||
static uint8_t bubble_animation_get_icon_index(BubbleAnimationViewModel* model) {
|
||||
static uint8_t bubble_animation_get_frame_index(BubbleAnimationViewModel* model) {
|
||||
furi_assert(model);
|
||||
uint8_t icon_index = 0;
|
||||
const BubbleAnimation* animation = model->current;
|
||||
@@ -57,7 +53,7 @@ static uint8_t bubble_animation_get_icon_index(BubbleAnimationViewModel* model)
|
||||
}
|
||||
furi_assert(icon_index < (animation->passive_frames + animation->active_frames));
|
||||
|
||||
return icon_index;
|
||||
return animation->frame_order[icon_index];
|
||||
}
|
||||
|
||||
static void bubble_animation_draw_callback(Canvas* canvas, void* model_) {
|
||||
@@ -79,23 +75,26 @@ static void bubble_animation_draw_callback(Canvas* canvas, void* model_) {
|
||||
|
||||
furi_assert(model->current_frame < 255);
|
||||
|
||||
const Icon* icon = animation->icons[bubble_animation_get_icon_index(model)];
|
||||
furi_assert(icon);
|
||||
uint8_t y_offset = canvas_height(canvas) - icon_get_height(icon);
|
||||
canvas_draw_icon(canvas, 0, y_offset, icon);
|
||||
uint8_t index = bubble_animation_get_frame_index(model);
|
||||
uint8_t width = icon_get_width(&animation->icon_animation);
|
||||
uint8_t height = icon_get_height(&animation->icon_animation);
|
||||
uint8_t y_offset = canvas_height(canvas) - height;
|
||||
canvas_draw_bitmap(
|
||||
canvas, 0, y_offset, width, height, animation->icon_animation.frames[index]);
|
||||
|
||||
const FrameBubble* bubble = model->current_bubble;
|
||||
if(bubble) {
|
||||
if((model->current_frame >= bubble->starts_at_frame) &&
|
||||
(model->current_frame <= bubble->ends_at_frame)) {
|
||||
if((model->current_frame >= bubble->start_frame) &&
|
||||
(model->current_frame <= bubble->end_frame)) {
|
||||
const Bubble* b = &bubble->bubble;
|
||||
elements_bubble_str(canvas, b->x, b->y, b->str, b->horizontal, b->vertical);
|
||||
elements_bubble_str(canvas, b->x, b->y, b->text, b->align_h, b->align_v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static FrameBubble* bubble_animation_pick_bubble(BubbleAnimationViewModel* model, bool active) {
|
||||
FrameBubble* bubble = NULL;
|
||||
static const FrameBubble*
|
||||
bubble_animation_pick_bubble(BubbleAnimationViewModel* model, bool active) {
|
||||
const FrameBubble* bubble = NULL;
|
||||
|
||||
if((model->active_bubbles == 0) && (model->passive_bubbles == 0)) {
|
||||
return NULL;
|
||||
@@ -104,10 +103,11 @@ static FrameBubble* bubble_animation_pick_bubble(BubbleAnimationViewModel* model
|
||||
uint8_t index = random() % (active ? model->active_bubbles : model->passive_bubbles);
|
||||
const BubbleAnimation* animation = model->current;
|
||||
|
||||
for(int i = 0; i < animation->frame_bubbles_count; ++i) {
|
||||
if((animation->frame_bubbles[i]->starts_at_frame < animation->passive_frames) ^ active) {
|
||||
for(int i = 0; i < animation->frame_bubble_sequences_count; ++i) {
|
||||
if((animation->frame_bubble_sequences[i]->start_frame < animation->passive_frames) ^
|
||||
active) {
|
||||
if(!index) {
|
||||
bubble = animation->frame_bubbles[i];
|
||||
bubble = animation->frame_bubble_sequences[i];
|
||||
}
|
||||
--index;
|
||||
}
|
||||
@@ -135,10 +135,6 @@ static bool bubble_animation_input_callback(InputEvent* event, void* context) {
|
||||
animation_view->interact_callback(animation_view->interact_callback_context);
|
||||
}
|
||||
}
|
||||
} else if(event->key == InputKeyBack) {
|
||||
/* Prevent back button to fall down to common handler - leaving
|
||||
* application, so consume */
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
@@ -190,7 +186,7 @@ static void bubble_animation_activate_right_now(BubbleAnimationView* view) {
|
||||
if(model->current && (model->current->active_frames > 0) && (!model->freeze_frame)) {
|
||||
model->current_frame = model->current->passive_frames;
|
||||
model->current_bubble = bubble_animation_pick_bubble(model, true);
|
||||
frame_rate = model->current->frame_rate;
|
||||
frame_rate = model->current->icon_animation.frame_rate;
|
||||
}
|
||||
view_commit_model(view->view, true);
|
||||
|
||||
@@ -222,7 +218,7 @@ static void bubble_animation_next_frame(BubbleAnimationViewModel* model) {
|
||||
}
|
||||
|
||||
if(model->current_bubble) {
|
||||
if(model->current_frame > model->current_bubble->ends_at_frame) {
|
||||
if(model->current_frame > model->current_bubble->end_frame) {
|
||||
model->current_bubble = model->current_bubble->next_bubble;
|
||||
}
|
||||
}
|
||||
@@ -251,7 +247,11 @@ static void bubble_animation_timer_callback(void* context) {
|
||||
}
|
||||
}
|
||||
|
||||
static Icon* bubble_animation_clone_frame(const Icon* icon_orig) {
|
||||
/* always freeze first passive frame, because
|
||||
* animation is always activated at unfreezing and played
|
||||
* passive frame first, and 2 frames after - active
|
||||
*/
|
||||
static Icon* bubble_animation_clone_first_frame(const Icon* icon_orig) {
|
||||
furi_assert(icon_orig);
|
||||
furi_assert(icon_orig->frames);
|
||||
furi_assert(icon_orig->frames[0]);
|
||||
@@ -268,6 +268,7 @@ static Icon* bubble_animation_clone_frame(const Icon* icon_orig) {
|
||||
size_t max_bitmap_size = ROUND_UP_TO(icon_orig->width, 8) * icon_orig->height + 1;
|
||||
icon_clone->frames[0] = furi_alloc(max_bitmap_size);
|
||||
memcpy((void*)icon_clone->frames[0], icon_orig->frames[0], max_bitmap_size);
|
||||
FURI_CONST_ASSIGN(icon_clone->frame_count, 1);
|
||||
|
||||
return icon_clone;
|
||||
}
|
||||
@@ -288,7 +289,7 @@ static void bubble_animation_enter(void* context) {
|
||||
bubble_animation_activate(view, false);
|
||||
|
||||
BubbleAnimationViewModel* model = view_get_model(view->view);
|
||||
uint8_t frame_rate = model->current->frame_rate;
|
||||
uint8_t frame_rate = model->current->icon_animation.frame_rate;
|
||||
view_commit_model(view->view, false);
|
||||
|
||||
if(frame_rate) {
|
||||
@@ -353,8 +354,8 @@ void bubble_animation_view_set_animation(
|
||||
model->active_ended_at = xTaskGetTickCount() - (model->current->active_cooldown * 1000);
|
||||
model->active_bubbles = 0;
|
||||
model->passive_bubbles = 0;
|
||||
for(int i = 0; i < new_animation->frame_bubbles_count; ++i) {
|
||||
if(new_animation->frame_bubbles[i]->starts_at_frame < new_animation->passive_frames) {
|
||||
for(int i = 0; i < new_animation->frame_bubble_sequences_count; ++i) {
|
||||
if(new_animation->frame_bubble_sequences[i]->start_frame < new_animation->passive_frames) {
|
||||
++model->passive_bubbles;
|
||||
} else {
|
||||
++model->active_bubbles;
|
||||
@@ -367,7 +368,7 @@ void bubble_animation_view_set_animation(
|
||||
model->active_cycle = 0;
|
||||
view_commit_model(view->view, true);
|
||||
|
||||
osTimerStart(view->timer, 1000 / new_animation->frame_rate);
|
||||
osTimerStart(view->timer, 1000 / new_animation->icon_animation.frame_rate);
|
||||
}
|
||||
|
||||
void bubble_animation_freeze(BubbleAnimationView* view) {
|
||||
@@ -376,12 +377,7 @@ void bubble_animation_freeze(BubbleAnimationView* view) {
|
||||
BubbleAnimationViewModel* model = view_get_model(view->view);
|
||||
furi_assert(model->current);
|
||||
furi_assert(!model->freeze_frame);
|
||||
/* always freeze first passive frame, because
|
||||
* animation is always activated at unfreezing and played
|
||||
* passive frame first, and 2 frames after - active
|
||||
*/
|
||||
uint8_t icon_index = 0;
|
||||
model->freeze_frame = bubble_animation_clone_frame(model->current->icons[icon_index]);
|
||||
model->freeze_frame = bubble_animation_clone_first_frame(&model->current->icon_animation);
|
||||
model->current = NULL;
|
||||
view_commit_model(view->view, false);
|
||||
osTimerStop(view->timer);
|
||||
@@ -395,8 +391,7 @@ void bubble_animation_unfreeze(BubbleAnimationView* view) {
|
||||
furi_assert(model->freeze_frame);
|
||||
bubble_animation_release_frame(&model->freeze_frame);
|
||||
furi_assert(model->current);
|
||||
furi_assert(model->current->icons);
|
||||
frame_rate = model->current->frame_rate;
|
||||
frame_rate = model->current->icon_animation.frame_rate;
|
||||
view_commit_model(view->view, true);
|
||||
|
||||
osTimerStart(view->timer, 1000 / frame_rate);
|
||||
|
130
applications/desktop/animations/views/one_shot_animation_view.c
Normal file
130
applications/desktop/animations/views/one_shot_animation_view.c
Normal file
@@ -0,0 +1,130 @@
|
||||
|
||||
#include "one_shot_animation_view.h"
|
||||
#include <furi.h>
|
||||
#include <portmacro.h>
|
||||
#include <gui/canvas.h>
|
||||
#include <gui/view.h>
|
||||
#include <gui/icon_i.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef void (*OneShotInteractCallback)(void*);
|
||||
|
||||
struct OneShotView {
|
||||
View* view;
|
||||
TimerHandle_t update_timer;
|
||||
OneShotInteractCallback interact_callback;
|
||||
void* interact_callback_context;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
const Icon* icon;
|
||||
uint32_t index;
|
||||
bool block_input;
|
||||
} OneShotViewModel;
|
||||
|
||||
static void one_shot_view_update_timer_callback(TimerHandle_t xTimer) {
|
||||
OneShotView* view = (void*)pvTimerGetTimerID(xTimer);
|
||||
|
||||
OneShotViewModel* model = view_get_model(view->view);
|
||||
if((model->index + 1) < model->icon->frame_count) {
|
||||
++model->index;
|
||||
} else {
|
||||
model->block_input = false;
|
||||
model->index = model->icon->frame_count - 2;
|
||||
}
|
||||
view_commit_model(view->view, true);
|
||||
}
|
||||
|
||||
static void one_shot_view_draw(Canvas* canvas, void* model_) {
|
||||
furi_assert(canvas);
|
||||
furi_assert(model_);
|
||||
|
||||
OneShotViewModel* model = model_;
|
||||
furi_check(model->index < model->icon->frame_count);
|
||||
uint8_t y_offset = canvas_height(canvas) - model->icon->height;
|
||||
canvas_draw_bitmap(
|
||||
canvas,
|
||||
0,
|
||||
y_offset,
|
||||
model->icon->width,
|
||||
model->icon->height,
|
||||
model->icon->frames[model->index]);
|
||||
}
|
||||
|
||||
static bool one_shot_view_input(InputEvent* event, void* context) {
|
||||
furi_assert(context);
|
||||
furi_assert(event);
|
||||
|
||||
OneShotView* view = context;
|
||||
bool consumed = false;
|
||||
|
||||
OneShotViewModel* model = view_get_model(view->view);
|
||||
consumed = model->block_input;
|
||||
view_commit_model(view->view, false);
|
||||
|
||||
if(!consumed) {
|
||||
if(event->key == InputKeyRight) {
|
||||
/* Right button reserved for animation activation, so consume */
|
||||
consumed = true;
|
||||
if(event->type == InputTypeShort) {
|
||||
if(view->interact_callback) {
|
||||
view->interact_callback(view->interact_callback_context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
OneShotView* one_shot_view_alloc(void) {
|
||||
OneShotView* view = furi_alloc(sizeof(OneShotView));
|
||||
view->view = view_alloc();
|
||||
view->update_timer =
|
||||
xTimerCreate("Update timer", 1000, pdTRUE, view, one_shot_view_update_timer_callback);
|
||||
|
||||
view_allocate_model(view->view, ViewModelTypeLocking, sizeof(OneShotViewModel));
|
||||
view_set_context(view->view, view);
|
||||
view_set_draw_callback(view->view, one_shot_view_draw);
|
||||
view_set_input_callback(view->view, one_shot_view_input);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
void one_shot_view_free(OneShotView* view) {
|
||||
furi_assert(view);
|
||||
|
||||
xTimerDelete(view->update_timer, portMAX_DELAY);
|
||||
view_free(view->view);
|
||||
view->view = NULL;
|
||||
free(view);
|
||||
}
|
||||
|
||||
void one_shot_view_set_interact_callback(
|
||||
OneShotView* view,
|
||||
OneShotInteractCallback callback,
|
||||
void* context) {
|
||||
furi_assert(view);
|
||||
|
||||
view->interact_callback_context = context;
|
||||
view->interact_callback = callback;
|
||||
}
|
||||
|
||||
void one_shot_view_start_animation(OneShotView* view, const Icon* icon) {
|
||||
furi_assert(view);
|
||||
furi_assert(icon);
|
||||
furi_check(icon->frame_count >= 2);
|
||||
|
||||
OneShotViewModel* model = view_get_model(view->view);
|
||||
model->index = 0;
|
||||
model->icon = icon;
|
||||
model->block_input = true;
|
||||
view_commit_model(view->view, true);
|
||||
xTimerChangePeriod(view->update_timer, 1000 / model->icon->frame_rate, portMAX_DELAY);
|
||||
}
|
||||
|
||||
View* one_shot_view_get_view(OneShotView* view) {
|
||||
furi_assert(view);
|
||||
|
||||
return view->view;
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <furi.h>
|
||||
#include <gui/view.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef void (*OneShotInteractCallback)(void*);
|
||||
typedef struct OneShotView OneShotView;
|
||||
|
||||
OneShotView* one_shot_view_alloc(void);
|
||||
void one_shot_view_free(OneShotView* view);
|
||||
void one_shot_view_set_interact_callback(
|
||||
OneShotView* view,
|
||||
OneShotInteractCallback callback,
|
||||
void* context);
|
||||
void one_shot_view_start_animation(OneShotView* view, const Icon* icon);
|
||||
View* one_shot_view_get_view(OneShotView* view);
|
Reference in New Issue
Block a user