MNTM Settings: Allow setting Dolphin XP manually

This commit is contained in:
Willy-JL
2024-08-24 02:58:24 +02:00
parent c6a3e684b6
commit 9d39ac13fa
6 changed files with 141 additions and 23 deletions

View File

@@ -101,18 +101,15 @@ bool momentum_app_apply(MomentumApp* app) {
}
if(app->save_dolphin) {
Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN);
if(app->save_level) {
int32_t xp = app->dolphin_level > 1 ? DOLPHIN_LEVELS[app->dolphin_level - 2] : 0;
dolphin->state->data.icounter = xp + 1;
if(app->save_xp) {
app->dolphin->state->data.icounter = app->dolphin_xp;
}
if(app->save_angry) {
dolphin->state->data.butthurt = app->dolphin_angry;
app->dolphin->state->data.butthurt = app->dolphin_angry;
}
dolphin->state->dirty = true;
dolphin_flush(dolphin);
dolphin_reload_state(dolphin);
furi_record_close(RECORD_DOLPHIN);
app->dolphin->state->dirty = true;
dolphin_flush(app->dolphin);
dolphin_reload_state(app->dolphin);
}
if(app->save_backlight) {
@@ -265,6 +262,7 @@ MomentumApp* momentum_app_alloc() {
app->gui = furi_record_open(RECORD_GUI);
app->storage = furi_record_open(RECORD_STORAGE);
app->desktop = furi_record_open(RECORD_DESKTOP);
app->dolphin = furi_record_open(RECORD_DOLPHIN);
app->dialogs = furi_record_open(RECORD_DIALOGS);
app->expansion = furi_record_open(RECORD_EXPANSION);
app->notification = furi_record_open(RECORD_NOTIFICATION);
@@ -387,11 +385,9 @@ MomentumApp* momentum_app_alloc() {
strlcpy(app->device_name, furi_hal_version_get_name_ptr(), FURI_HAL_VERSION_ARRAY_NAME_LENGTH);
Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN);
DolphinStats stats = dolphin_stats(dolphin);
app->dolphin_level = stats.level;
DolphinStats stats = dolphin_stats(app->dolphin);
app->dolphin_xp = stats.icounter;
app->dolphin_angry = stats.butthurt;
furi_record_close(RECORD_DOLPHIN);
// Will be "(version) (commit or date)"
app->version_tag = furi_string_alloc_set(version_get_version(NULL));
@@ -471,6 +467,7 @@ void momentum_app_free(MomentumApp* app) {
furi_record_close(RECORD_NOTIFICATION);
furi_record_close(RECORD_EXPANSION);
furi_record_close(RECORD_DIALOGS);
furi_record_close(RECORD_DOLPHIN);
furi_record_close(RECORD_DESKTOP);
furi_record_close(RECORD_STORAGE);
furi_record_close(RECORD_GUI);

View File

@@ -43,10 +43,13 @@
ARRAY_DEF(CharList, char*)
#define DOLPHIN_MAX_XP (DOLPHIN_LEVELS[DOLPHIN_LEVEL_COUNT - 1] + 1)
typedef struct {
Gui* gui;
Storage* storage;
Desktop* desktop;
Dolphin* dolphin;
DialogsApp* dialogs;
Expansion* expansion;
NotificationApp* notification;
@@ -77,8 +80,8 @@ typedef struct {
RgbColor lcd_color;
RgbColor vgm_color;
char device_name[FURI_HAL_VERSION_ARRAY_NAME_LENGTH];
int32_t dolphin_level;
int32_t dolphin_angry;
uint32_t dolphin_xp;
uint32_t dolphin_angry;
FuriString* version_tag;
bool save_mainmenu_apps;
@@ -86,7 +89,7 @@ typedef struct {
bool save_subghz_freqs;
bool save_subghz;
bool save_name;
bool save_level;
bool save_xp;
bool save_angry;
bool save_dolphin;
bool save_backlight;

View File

@@ -19,6 +19,7 @@ ADD_SCENE(momentum_app, misc, Misc)
ADD_SCENE(momentum_app, misc_screen, MiscScreen)
ADD_SCENE(momentum_app, misc_screen_color, MiscScreenColor)
ADD_SCENE(momentum_app, misc_dolphin, MiscDolphin)
ADD_SCENE(momentum_app, misc_dolphin_xp, MiscDolphinXp)
ADD_SCENE(momentum_app, misc_spoof, MiscSpoof)
ADD_SCENE(momentum_app, misc_spoof_name, MiscSpoofName)
ADD_SCENE(momentum_app, misc_vgm, MiscVgm)

View File

@@ -2,6 +2,7 @@
enum VarItemListIndex {
VarItemListIndexDolphinLevel,
VarItemListIndexDolphinXp,
VarItemListIndexDolphinAngry,
VarItemListIndexButthurtTimer,
};
@@ -13,19 +14,63 @@ void momentum_app_scene_misc_dolphin_var_item_list_callback(void* context, uint3
static void momentum_app_scene_misc_dolphin_dolphin_level_changed(VariableItem* item) {
MomentumApp* app = variable_item_get_context(item);
app->dolphin_level = variable_item_get_current_value_index(item) + 1;
uint8_t index = variable_item_get_current_value_index(item);
uint32_t xp = index > 0 ? DOLPHIN_LEVELS[index - 1] : 0;
app->dolphin_xp = xp + 1; // Prevent levelup animation
uint8_t level = dolphin_get_level(app->dolphin_xp);
char level_str[4];
snprintf(level_str, 4, "%li", app->dolphin_level);
snprintf(level_str, sizeof(level_str), "%u", level);
variable_item_set_current_value_text(item, level_str);
app->save_level = true;
app->save_xp = true;
app->save_dolphin = true;
item = variable_item_list_get(app->var_item_list, VarItemListIndexDolphinXp);
variable_item_set_current_value_index(
item,
app->dolphin_xp == 0 ? 0 :
app->dolphin_xp == DOLPHIN_MAX_XP ? 2 :
1);
char xp_str[6];
snprintf(xp_str, sizeof(xp_str), "%lu", app->dolphin_xp);
variable_item_set_current_value_text(item, xp_str);
}
static void momentum_app_scene_misc_dolphin_dolphin_xp_changed(VariableItem* item) {
MomentumApp* app = variable_item_get_context(item);
// uin8_t index too small for all levels, use 3 fake items to
// show buttons and change values in callback
uint8_t direction = variable_item_get_current_value_index(item);
if(app->dolphin_xp == DOLPHIN_MAX_XP) direction = 0;
if(app->dolphin_xp == 0) direction = 2;
if(direction == 0) app->dolphin_xp--;
if(direction == 2) app->dolphin_xp++;
variable_item_set_current_value_index(
item,
app->dolphin_xp == 0 ? 0 :
app->dolphin_xp == DOLPHIN_MAX_XP ? 2 :
1);
char xp_str[6];
snprintf(xp_str, sizeof(xp_str), "%lu", app->dolphin_xp);
variable_item_set_current_value_text(item, xp_str);
app->save_xp = true;
app->save_dolphin = true;
uint8_t level = dolphin_get_level(app->dolphin_xp);
char level_str[4];
snprintf(level_str, sizeof(level_str), "%u", level);
variable_item_set_current_value_text(
variable_item_list_get(app->var_item_list, VarItemListIndexDolphinLevel), level_str);
}
static void momentum_app_scene_misc_dolphin_dolphin_angry_changed(VariableItem* item) {
MomentumApp* app = variable_item_get_context(item);
app->dolphin_angry = variable_item_get_current_value_index(item);
char angry_str[4];
snprintf(angry_str, 4, "%li", app->dolphin_angry);
snprintf(angry_str, sizeof(angry_str), "%lu", app->dolphin_angry);
variable_item_set_current_value_text(item, angry_str);
app->save_angry = true;
app->save_dolphin = true;
@@ -70,19 +115,33 @@ void momentum_app_scene_misc_dolphin_on_enter(void* context) {
VariableItem* item;
uint8_t value_index;
uint8_t level = dolphin_get_level(app->dolphin_xp);
char level_str[4];
snprintf(level_str, 4, "%li", app->dolphin_level);
snprintf(level_str, sizeof(level_str), "%u", level);
item = variable_item_list_add(
var_item_list,
"Dolphin Level",
DOLPHIN_LEVEL_COUNT + 1,
momentum_app_scene_misc_dolphin_dolphin_level_changed,
app);
variable_item_set_current_value_index(item, app->dolphin_level - 1);
variable_item_set_current_value_index(item, level - 1);
variable_item_set_current_value_text(item, level_str);
char xp_str[6];
snprintf(xp_str, sizeof(xp_str), "%lu", app->dolphin_xp);
// uin8_t index too small for all levels, use 3 fake items to
// show buttons and change values in callback
item = variable_item_list_add(
var_item_list, "Dolphin XP", 3, momentum_app_scene_misc_dolphin_dolphin_xp_changed, app);
variable_item_set_current_value_index(
item,
app->dolphin_xp == 0 ? 0 :
app->dolphin_xp == DOLPHIN_MAX_XP ? 2 :
1);
variable_item_set_current_value_text(item, xp_str);
char angry_str[4];
snprintf(angry_str, 4, "%li", app->dolphin_angry);
snprintf(angry_str, sizeof(angry_str), "%lu", app->dolphin_angry);
item = variable_item_list_add(
var_item_list,
"Dolphin Angry",
@@ -122,6 +181,9 @@ bool momentum_app_scene_misc_dolphin_on_event(void* context, SceneManagerEvent e
app->scene_manager, MomentumAppSceneMiscDolphin, event.event);
consumed = true;
switch(event.event) {
case VarItemListIndexDolphinXp:
scene_manager_next_scene(app->scene_manager, MomentumAppSceneMiscDolphinXp);
break;
default:
break;
}

View File

@@ -0,0 +1,54 @@
#include "../momentum_app.h"
enum NumberInputResult {
NumberInputResultOk,
};
static void
momentum_app_scene_misc_dolphin_xp_number_input_callback(void* context, int32_t number) {
MomentumApp* app = context;
app->dolphin_xp = number;
view_dispatcher_send_custom_event(app->view_dispatcher, NumberInputResultOk);
}
void momentum_app_scene_misc_dolphin_xp_on_enter(void* context) {
MomentumApp* app = context;
NumberInput* number_input = app->number_input;
number_input_set_header_text(number_input, "Enter Dolphin XP value");
number_input_set_result_callback(
number_input,
momentum_app_scene_misc_dolphin_xp_number_input_callback,
app,
0,
0,
DOLPHIN_MAX_XP);
view_dispatcher_switch_to_view(app->view_dispatcher, MomentumAppViewNumberInput);
}
bool momentum_app_scene_misc_dolphin_xp_on_event(void* context, SceneManagerEvent event) {
MomentumApp* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
consumed = true;
switch(event.event) {
case NumberInputResultOk:
scene_manager_previous_scene(app->scene_manager);
break;
default:
break;
}
}
return consumed;
}
void momentum_app_scene_misc_dolphin_xp_on_exit(void* context) {
MomentumApp* app = context;
number_input_set_result_callback(app->number_input, NULL, NULL, 0, 0, 0);
number_input_set_header_text(app->number_input, "");
}