mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-15 04:19:26 -07:00
Move xtreme app to main menu
This commit is contained in:
13
applications/main/xtreme_app/application.fam
Normal file
13
applications/main/xtreme_app/application.fam
Normal file
@@ -0,0 +1,13 @@
|
||||
App(
|
||||
appid="xtreme_app",
|
||||
name="Xtreme FW",
|
||||
apptype=FlipperAppType.APP,
|
||||
entry_point="xtreme_app",
|
||||
requires=[
|
||||
"gui",
|
||||
"xtreme",
|
||||
],
|
||||
stack_size=2 * 1024,
|
||||
icon="A_Plugins_14",
|
||||
order=90,
|
||||
)
|
||||
30
applications/main/xtreme_app/scenes/xtreme_app_scene.c
Normal file
30
applications/main/xtreme_app/scenes/xtreme_app_scene.c
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "xtreme_app_scene.h"
|
||||
|
||||
// Generate scene on_enter handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
|
||||
void (*const xtreme_app_on_enter_handlers[])(void*) = {
|
||||
#include "xtreme_app_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_event handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
|
||||
bool (*const xtreme_app_on_event_handlers[])(void* context, SceneManagerEvent event) = {
|
||||
#include "xtreme_app_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_exit handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
|
||||
void (*const xtreme_app_on_exit_handlers[])(void* context) = {
|
||||
#include "xtreme_app_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Initialize scene handlers configuration structure
|
||||
const SceneManagerHandlers xtreme_app_scene_handlers = {
|
||||
.on_enter_handlers = xtreme_app_on_enter_handlers,
|
||||
.on_event_handlers = xtreme_app_on_event_handlers,
|
||||
.on_exit_handlers = xtreme_app_on_exit_handlers,
|
||||
.scene_num = XtremeAppSceneNum,
|
||||
};
|
||||
29
applications/main/xtreme_app/scenes/xtreme_app_scene.h
Normal file
29
applications/main/xtreme_app/scenes/xtreme_app_scene.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/scene_manager.h>
|
||||
|
||||
// Generate scene id and total number
|
||||
#define ADD_SCENE(prefix, name, id) XtremeAppScene##id,
|
||||
typedef enum {
|
||||
#include "xtreme_app_scene_config.h"
|
||||
XtremeAppSceneNum,
|
||||
} XtremeAppScene;
|
||||
#undef ADD_SCENE
|
||||
|
||||
extern const SceneManagerHandlers xtreme_app_scene_handlers;
|
||||
|
||||
// Generate scene on_enter handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
|
||||
#include "xtreme_app_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_event handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) \
|
||||
bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event);
|
||||
#include "xtreme_app_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_exit handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context);
|
||||
#include "xtreme_app_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
@@ -0,0 +1,7 @@
|
||||
ADD_SCENE(xtreme_app, start, Start)
|
||||
ADD_SCENE(xtreme_app, graphics, Graphics)
|
||||
ADD_SCENE(xtreme_app, statusbar, Statusbar)
|
||||
ADD_SCENE(xtreme_app, protocols, Protocols)
|
||||
ADD_SCENE(xtreme_app, dolphin, Dolphin)
|
||||
ADD_SCENE(xtreme_app, misc, Misc)
|
||||
ADD_SCENE(xtreme_app, misc_rename, MiscRename)
|
||||
@@ -0,0 +1,78 @@
|
||||
#include "../xtreme_app.h"
|
||||
|
||||
static void xtreme_app_scene_dolphin_xp_level_changed(VariableItem* item) {
|
||||
XtremeApp* app = variable_item_get_context(item);
|
||||
app->dolphin_level = variable_item_get_current_value_index(item) + 1;
|
||||
char level_str[4];
|
||||
snprintf(level_str, 4, "%i", app->dolphin_level);
|
||||
variable_item_set_current_value_text(item, level_str);
|
||||
app->save_level = true;
|
||||
}
|
||||
|
||||
const char* const butthurt_timer_names[] = {
|
||||
"OFF",
|
||||
"30 M",
|
||||
"1 H",
|
||||
"2 H",
|
||||
"4 H",
|
||||
"6 H",
|
||||
"8 H",
|
||||
"12 H",
|
||||
"24 H",
|
||||
"48 H"};
|
||||
const int32_t butthurt_timer_values[COUNT_OF(butthurt_timer_names)] =
|
||||
{-1, 1800, 3600, 7200, 14400, 21600, 28800, 43200, 86400, 172800};
|
||||
static void xtreme_app_scene_dolphin_butthurt_timer_changed(VariableItem* item) {
|
||||
XtremeApp* app = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
variable_item_set_current_value_text(item, butthurt_timer_names[index]);
|
||||
XTREME_SETTINGS()->butthurt_timer = butthurt_timer_values[index];
|
||||
app->save_settings = true;
|
||||
app->require_reboot = true;
|
||||
}
|
||||
|
||||
void xtreme_app_scene_dolphin_on_enter(void* context) {
|
||||
XtremeApp* app = context;
|
||||
XtremeSettings* xtreme_settings = XTREME_SETTINGS();
|
||||
VariableItemList* var_item_list = app->var_item_list;
|
||||
VariableItem* item;
|
||||
uint8_t value_index;
|
||||
|
||||
char level_str[4];
|
||||
snprintf(level_str, 4, "%i", app->dolphin_level);
|
||||
item = variable_item_list_add(
|
||||
var_item_list,
|
||||
"XP Level",
|
||||
DOLPHIN_LEVEL_COUNT + 1,
|
||||
xtreme_app_scene_dolphin_xp_level_changed,
|
||||
app);
|
||||
variable_item_set_current_value_index(item, app->dolphin_level - 1);
|
||||
variable_item_set_current_value_text(item, level_str);
|
||||
|
||||
item = variable_item_list_add(
|
||||
var_item_list,
|
||||
"Butthurt Timer",
|
||||
COUNT_OF(butthurt_timer_names),
|
||||
xtreme_app_scene_dolphin_butthurt_timer_changed,
|
||||
app);
|
||||
value_index = value_index_int32(
|
||||
xtreme_settings->butthurt_timer, butthurt_timer_values, COUNT_OF(butthurt_timer_names));
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, butthurt_timer_names[value_index]);
|
||||
|
||||
variable_item_list_set_selected_item(var_item_list, 0);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, XtremeAppViewVarItemList);
|
||||
}
|
||||
|
||||
bool xtreme_app_scene_dolphin_on_event(void* context, SceneManagerEvent event) {
|
||||
UNUSED(context);
|
||||
UNUSED(event);
|
||||
bool consumed = false;
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void xtreme_app_scene_dolphin_on_exit(void* context) {
|
||||
XtremeApp* app = context;
|
||||
variable_item_list_reset(app->var_item_list);
|
||||
}
|
||||
120
applications/main/xtreme_app/scenes/xtreme_app_scene_graphics.c
Normal file
120
applications/main/xtreme_app/scenes/xtreme_app_scene_graphics.c
Normal file
@@ -0,0 +1,120 @@
|
||||
#include "../xtreme_app.h"
|
||||
|
||||
static void xtreme_app_scene_graphics_asset_pack_changed(VariableItem* item) {
|
||||
XtremeApp* app = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
variable_item_set_current_value_text(
|
||||
item, index == 0 ? "SFW" : *asset_packs_get(app->asset_packs, index - 1));
|
||||
strlcpy(
|
||||
XTREME_SETTINGS()->asset_pack,
|
||||
index == 0 ? "" : *asset_packs_get(app->asset_packs, index - 1),
|
||||
MAX_PACK_NAME_LEN);
|
||||
app->asset_pack = index;
|
||||
app->save_settings = true;
|
||||
app->require_reboot = true;
|
||||
}
|
||||
|
||||
const char* const anim_speed_names[] =
|
||||
{"25%", "50%", "75%", "100%", "125%", "150%", "175%", "200%", "225%", "250%", "275%", "300%"};
|
||||
const int32_t anim_speed_values[COUNT_OF(anim_speed_names)] =
|
||||
{25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300};
|
||||
static void xtreme_app_scene_graphics_anim_speed_changed(VariableItem* item) {
|
||||
XtremeApp* app = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
variable_item_set_current_value_text(item, anim_speed_names[index]);
|
||||
XTREME_SETTINGS()->anim_speed = anim_speed_values[index];
|
||||
app->save_settings = true;
|
||||
}
|
||||
|
||||
const char* const cycle_anims_names[] = {
|
||||
"OFF",
|
||||
"Meta.txt",
|
||||
"30 S",
|
||||
"1 M",
|
||||
"5 M",
|
||||
"10 M",
|
||||
"15 M",
|
||||
"30 M",
|
||||
"1 H",
|
||||
"2 H",
|
||||
"6 H",
|
||||
"12 H",
|
||||
"24 H"};
|
||||
const int32_t cycle_anims_values[COUNT_OF(cycle_anims_names)] =
|
||||
{-1, 0, 30, 60, 300, 600, 900, 1800, 3600, 7200, 21600, 43200, 86400};
|
||||
static void xtreme_app_scene_graphics_cycle_anims_changed(VariableItem* item) {
|
||||
XtremeApp* app = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
variable_item_set_current_value_text(item, cycle_anims_names[index]);
|
||||
XTREME_SETTINGS()->cycle_anims = cycle_anims_values[index];
|
||||
app->save_settings = true;
|
||||
}
|
||||
|
||||
static void xtreme_app_scene_graphics_unlock_anims_changed(VariableItem* item) {
|
||||
XtremeApp* app = variable_item_get_context(item);
|
||||
bool value = variable_item_get_current_value_index(item);
|
||||
variable_item_set_current_value_text(item, value ? "ON" : "OFF");
|
||||
XTREME_SETTINGS()->unlock_anims = value;
|
||||
app->save_settings = true;
|
||||
}
|
||||
|
||||
void xtreme_app_scene_graphics_on_enter(void* context) {
|
||||
XtremeApp* app = context;
|
||||
XtremeSettings* xtreme_settings = XTREME_SETTINGS();
|
||||
VariableItemList* var_item_list = app->var_item_list;
|
||||
VariableItem* item;
|
||||
uint8_t value_index;
|
||||
|
||||
item = variable_item_list_add(
|
||||
var_item_list,
|
||||
"Asset Pack",
|
||||
asset_packs_size(app->asset_packs) + 1,
|
||||
xtreme_app_scene_graphics_asset_pack_changed,
|
||||
app);
|
||||
variable_item_set_current_value_index(item, app->asset_pack);
|
||||
variable_item_set_current_value_text(
|
||||
item, app->asset_pack == 0 ? "SFW" : *asset_packs_get(app->asset_packs, app->asset_pack - 1));
|
||||
|
||||
item = variable_item_list_add(
|
||||
var_item_list,
|
||||
"Anim Speed",
|
||||
COUNT_OF(anim_speed_names),
|
||||
xtreme_app_scene_graphics_anim_speed_changed,
|
||||
app);
|
||||
value_index = value_index_int32(
|
||||
xtreme_settings->anim_speed, anim_speed_values, COUNT_OF(anim_speed_names));
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, anim_speed_names[value_index]);
|
||||
|
||||
item = variable_item_list_add(
|
||||
var_item_list,
|
||||
"Cycle Anims",
|
||||
COUNT_OF(cycle_anims_names),
|
||||
xtreme_app_scene_graphics_cycle_anims_changed,
|
||||
app);
|
||||
value_index = value_index_int32(
|
||||
xtreme_settings->cycle_anims, cycle_anims_values, COUNT_OF(cycle_anims_names));
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, cycle_anims_names[value_index]);
|
||||
|
||||
item = variable_item_list_add(
|
||||
var_item_list, "Unlock Anims", 2, xtreme_app_scene_graphics_unlock_anims_changed, app);
|
||||
variable_item_set_current_value_index(item, xtreme_settings->unlock_anims);
|
||||
variable_item_set_current_value_text(item, xtreme_settings->unlock_anims ? "ON" : "OFF");
|
||||
|
||||
variable_item_list_set_selected_item(var_item_list, 0);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, XtremeAppViewVarItemList);
|
||||
}
|
||||
|
||||
bool xtreme_app_scene_graphics_on_event(void* context, SceneManagerEvent event) {
|
||||
UNUSED(context);
|
||||
UNUSED(event);
|
||||
bool consumed = false;
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void xtreme_app_scene_graphics_on_exit(void* context) {
|
||||
XtremeApp* app = context;
|
||||
variable_item_list_reset(app->var_item_list);
|
||||
}
|
||||
67
applications/main/xtreme_app/scenes/xtreme_app_scene_misc.c
Normal file
67
applications/main/xtreme_app/scenes/xtreme_app_scene_misc.c
Normal file
@@ -0,0 +1,67 @@
|
||||
#include "../xtreme_app.h"
|
||||
|
||||
enum VarItemListIndex {
|
||||
VarItemListIndexSortDirsFirst,
|
||||
VarItemListIndexChangeDeviceName,
|
||||
};
|
||||
|
||||
void xtreme_app_scene_misc_var_item_list_callback(void* context, uint32_t index) {
|
||||
XtremeApp* app = context;
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, index);
|
||||
}
|
||||
|
||||
static void xtreme_app_scene_misc_sort_folders_before_changed(VariableItem* item) {
|
||||
XtremeApp* app = variable_item_get_context(item);
|
||||
bool value = variable_item_get_current_value_index(item);
|
||||
variable_item_set_current_value_text(item, value ? "ON" : "OFF");
|
||||
XTREME_SETTINGS()->sort_dirs_first = value;
|
||||
app->save_settings = true;
|
||||
}
|
||||
|
||||
void xtreme_app_scene_misc_on_enter(void* context) {
|
||||
XtremeApp* app = context;
|
||||
XtremeSettings* xtreme_settings = XTREME_SETTINGS();
|
||||
VariableItemList* var_item_list = app->var_item_list;
|
||||
VariableItem* item;
|
||||
|
||||
item = variable_item_list_add(
|
||||
var_item_list,
|
||||
"Sort Dirs First",
|
||||
2,
|
||||
xtreme_app_scene_misc_sort_folders_before_changed,
|
||||
app);
|
||||
variable_item_set_current_value_index(item, xtreme_settings->sort_dirs_first);
|
||||
variable_item_set_current_value_text(item, xtreme_settings->sort_dirs_first ? "ON" : "OFF");
|
||||
|
||||
variable_item_list_add(var_item_list, "Change Device Name", 0, NULL, app);
|
||||
|
||||
variable_item_list_set_enter_callback(var_item_list, xtreme_app_scene_misc_var_item_list_callback, app);
|
||||
|
||||
variable_item_list_set_selected_item(var_item_list, scene_manager_get_scene_state(app->scene_manager, XtremeAppSceneMisc));
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, XtremeAppViewVarItemList);
|
||||
}
|
||||
|
||||
bool xtreme_app_scene_misc_on_event(void* context, SceneManagerEvent event) {
|
||||
XtremeApp* app = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
scene_manager_set_scene_state(app->scene_manager, XtremeAppSceneMisc, event.event);
|
||||
consumed = true;
|
||||
switch(event.event) {
|
||||
case VarItemListIndexChangeDeviceName:
|
||||
scene_manager_next_scene(app->scene_manager, XtremeAppSceneMiscRename);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void xtreme_app_scene_misc_on_exit(void* context) {
|
||||
XtremeApp* app = context;
|
||||
variable_item_list_reset(app->var_item_list);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
#include "../xtreme_app.h"
|
||||
|
||||
enum TextInputIndex {
|
||||
TextInputIndexResult,
|
||||
};
|
||||
|
||||
static void xtreme_app_scene_misc_rename_text_input_callback(void* context) {
|
||||
XtremeApp* app = context;
|
||||
|
||||
app->save_name = true;
|
||||
app->require_reboot = true;
|
||||
view_dispatcher_send_custom_event(
|
||||
app->view_dispatcher, TextInputIndexResult);
|
||||
}
|
||||
|
||||
void xtreme_app_scene_misc_rename_on_enter(void* context) {
|
||||
XtremeApp* app = context;
|
||||
TextInput* text_input = app->text_input;
|
||||
|
||||
text_input_set_header_text(text_input, "Leave empty for default");
|
||||
|
||||
text_input_set_result_callback(
|
||||
text_input,
|
||||
xtreme_app_scene_misc_rename_text_input_callback,
|
||||
app,
|
||||
app->device_name,
|
||||
NAMECHANGER_TEXT_STORE_SIZE,
|
||||
true);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, XtremeAppViewTextInput);
|
||||
}
|
||||
|
||||
bool xtreme_app_scene_misc_rename_on_event(void* context, SceneManagerEvent event) {
|
||||
XtremeApp* app = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
consumed = true;
|
||||
switch(event.event) {
|
||||
case TextInputIndexResult:
|
||||
scene_manager_previous_scene(app->scene_manager);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void xtreme_app_scene_misc_rename_on_exit(void* context) {
|
||||
XtremeApp* app = context;
|
||||
text_input_reset(app->text_input);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
#include "../xtreme_app.h"
|
||||
|
||||
static void xtreme_app_scene_protocols_bad_bk_mode_changed(VariableItem* item) {
|
||||
XtremeApp* app = variable_item_get_context(item);
|
||||
bool value = variable_item_get_current_value_index(item);
|
||||
variable_item_set_current_value_text(item, value ? "BT" : "USB");
|
||||
XTREME_SETTINGS()->bad_bt = value;
|
||||
app->save_settings = true;
|
||||
}
|
||||
|
||||
static void xtreme_app_scene_protocols_subghz_extend_changed(VariableItem* item) {
|
||||
XtremeApp* app = variable_item_get_context(item);
|
||||
app->subghz_extend = variable_item_get_current_value_index(item);
|
||||
variable_item_set_current_value_text(item, app->subghz_extend ? "ON" : "OFF");
|
||||
app->save_subghz = true;
|
||||
}
|
||||
|
||||
static void xtreme_app_scene_protocols_subghz_bypass_changed(VariableItem* item) {
|
||||
XtremeApp* app = variable_item_get_context(item);
|
||||
app->subghz_bypass = variable_item_get_current_value_index(item);
|
||||
variable_item_set_current_value_text(item, app->subghz_bypass ? "ON" : "OFF");
|
||||
app->save_subghz = true;
|
||||
}
|
||||
|
||||
void xtreme_app_scene_protocols_on_enter(void* context) {
|
||||
XtremeApp* app = context;
|
||||
XtremeSettings* xtreme_settings = XTREME_SETTINGS();
|
||||
VariableItemList* var_item_list = app->var_item_list;
|
||||
VariableItem* item;
|
||||
|
||||
item = variable_item_list_add(
|
||||
var_item_list, "Bad KB Mode", 2, xtreme_app_scene_protocols_bad_bk_mode_changed, app);
|
||||
variable_item_set_current_value_index(item, xtreme_settings->bad_bt);
|
||||
variable_item_set_current_value_text(item, xtreme_settings->bad_bt ? "BT" : "USB");
|
||||
|
||||
item = variable_item_list_add(
|
||||
var_item_list, "SubGHz Extend", 2, xtreme_app_scene_protocols_subghz_extend_changed, app);
|
||||
variable_item_set_current_value_index(item, app->subghz_extend);
|
||||
variable_item_set_current_value_text(item, app->subghz_extend ? "ON" : "OFF");
|
||||
|
||||
item = variable_item_list_add(
|
||||
var_item_list, "SubGHz Bypass", 2, xtreme_app_scene_protocols_subghz_bypass_changed, app);
|
||||
variable_item_set_current_value_index(item, app->subghz_bypass);
|
||||
variable_item_set_current_value_text(item, app->subghz_bypass ? "ON" : "OFF");
|
||||
|
||||
variable_item_list_set_selected_item(var_item_list, 0);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, XtremeAppViewVarItemList);
|
||||
}
|
||||
|
||||
bool xtreme_app_scene_protocols_on_event(void* context, SceneManagerEvent event) {
|
||||
UNUSED(context);
|
||||
UNUSED(event);
|
||||
bool consumed = false;
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void xtreme_app_scene_protocols_on_exit(void* context) {
|
||||
XtremeApp* app = context;
|
||||
variable_item_list_reset(app->var_item_list);
|
||||
}
|
||||
69
applications/main/xtreme_app/scenes/xtreme_app_scene_start.c
Normal file
69
applications/main/xtreme_app/scenes/xtreme_app_scene_start.c
Normal file
@@ -0,0 +1,69 @@
|
||||
#include "../xtreme_app.h"
|
||||
|
||||
enum VarItemListIndex {
|
||||
VarItemListIndexGraphics,
|
||||
VarItemListIndexStatusbar,
|
||||
VarItemListIndexProtocols,
|
||||
VarItemListIndexDolphin,
|
||||
VarItemListIndexMisc,
|
||||
};
|
||||
|
||||
void xtreme_app_scene_start_var_item_list_callback(void* context, uint32_t index) {
|
||||
XtremeApp* app = context;
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, index);
|
||||
}
|
||||
|
||||
void xtreme_app_scene_start_on_enter(void* context) {
|
||||
XtremeApp* app = context;
|
||||
VariableItemList* var_item_list = app->var_item_list;
|
||||
|
||||
variable_item_list_add(var_item_list, "Graphics", 0, NULL, app);
|
||||
variable_item_list_add(var_item_list, "Statusbar", 0, NULL, app);
|
||||
variable_item_list_add(var_item_list, "Protocols", 0, NULL, app);
|
||||
variable_item_list_add(var_item_list, "Dolphin", 0, NULL, app);
|
||||
variable_item_list_add(var_item_list, "Misc", 0, NULL, app);
|
||||
|
||||
variable_item_list_add(var_item_list, furi_string_get_cstr(app->version_tag), 0, NULL, app);
|
||||
|
||||
variable_item_list_set_enter_callback(var_item_list, xtreme_app_scene_start_var_item_list_callback, app);
|
||||
|
||||
variable_item_list_set_selected_item(var_item_list, scene_manager_get_scene_state(app->scene_manager, XtremeAppSceneStart));
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, XtremeAppViewVarItemList);
|
||||
}
|
||||
|
||||
bool xtreme_app_scene_start_on_event(void* context, SceneManagerEvent event) {
|
||||
XtremeApp* app = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
scene_manager_set_scene_state(app->scene_manager, XtremeAppSceneStart, event.event);
|
||||
consumed = true;
|
||||
switch(event.event) {
|
||||
case VarItemListIndexGraphics:
|
||||
scene_manager_next_scene(app->scene_manager, XtremeAppSceneGraphics);
|
||||
break;
|
||||
case VarItemListIndexStatusbar:
|
||||
scene_manager_next_scene(app->scene_manager, XtremeAppSceneStatusbar);
|
||||
break;
|
||||
case VarItemListIndexProtocols:
|
||||
scene_manager_next_scene(app->scene_manager, XtremeAppSceneProtocols);
|
||||
break;
|
||||
case VarItemListIndexDolphin:
|
||||
scene_manager_next_scene(app->scene_manager, XtremeAppSceneDolphin);
|
||||
break;
|
||||
case VarItemListIndexMisc:
|
||||
scene_manager_next_scene(app->scene_manager, XtremeAppSceneMisc);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void xtreme_app_scene_start_on_exit(void* context) {
|
||||
XtremeApp* app = context;
|
||||
variable_item_list_reset(app->var_item_list);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
#include "../xtreme_app.h"
|
||||
|
||||
const char* const battery_icon_names[] =
|
||||
{"OFF", "Bar", "%", "Inv. %", "Retro 3", "Retro 5", "Bar %"};
|
||||
static void xtreme_app_scene_statusbar_battery_icon_changed(VariableItem* item) {
|
||||
XtremeApp* app = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
variable_item_set_current_value_text(item, battery_icon_names[index]);
|
||||
XTREME_SETTINGS()->battery_icon = index;
|
||||
app->save_settings = true;
|
||||
}
|
||||
|
||||
static void xtreme_app_scene_statusbar_status_icons_changed(VariableItem* item) {
|
||||
XtremeApp* app = variable_item_get_context(item);
|
||||
bool value = variable_item_get_current_value_index(item);
|
||||
variable_item_set_current_value_text(item, value ? "ON" : "OFF");
|
||||
XTREME_SETTINGS()->status_icons = value;
|
||||
app->save_settings = true;
|
||||
}
|
||||
|
||||
static void xtreme_app_scene_statusbar_bar_borders_changed(VariableItem* item) {
|
||||
XtremeApp* app = variable_item_get_context(item);
|
||||
bool value = variable_item_get_current_value_index(item);
|
||||
variable_item_set_current_value_text(item, value ? "ON" : "OFF");
|
||||
XTREME_SETTINGS()->bar_borders = value;
|
||||
app->save_settings = true;
|
||||
}
|
||||
|
||||
static void xtreme_app_scene_statusbar_bar_background_changed(VariableItem* item) {
|
||||
XtremeApp* app = variable_item_get_context(item);
|
||||
bool value = variable_item_get_current_value_index(item);
|
||||
variable_item_set_current_value_text(item, value ? "ON" : "OFF");
|
||||
XTREME_SETTINGS()->bar_background = value;
|
||||
app->save_settings = true;
|
||||
}
|
||||
|
||||
void xtreme_app_scene_statusbar_on_enter(void* context) {
|
||||
XtremeApp* app = context;
|
||||
XtremeSettings* xtreme_settings = XTREME_SETTINGS();
|
||||
VariableItemList* var_item_list = app->var_item_list;
|
||||
VariableItem* item;
|
||||
|
||||
item = variable_item_list_add(
|
||||
var_item_list,
|
||||
"Battery Icon",
|
||||
BatteryIconCount,
|
||||
xtreme_app_scene_statusbar_battery_icon_changed,
|
||||
app);
|
||||
variable_item_set_current_value_index(item, xtreme_settings->battery_icon);
|
||||
variable_item_set_current_value_text(item, battery_icon_names[xtreme_settings->battery_icon]);
|
||||
|
||||
item = variable_item_list_add(
|
||||
var_item_list, "Status Icons", 2, xtreme_app_scene_statusbar_status_icons_changed, app);
|
||||
variable_item_set_current_value_index(item, xtreme_settings->status_icons);
|
||||
variable_item_set_current_value_text(item, xtreme_settings->status_icons ? "ON" : "OFF");
|
||||
|
||||
item = variable_item_list_add(
|
||||
var_item_list, "Bar Borders", 2, xtreme_app_scene_statusbar_bar_borders_changed, app);
|
||||
variable_item_set_current_value_index(item, xtreme_settings->bar_borders);
|
||||
variable_item_set_current_value_text(item, xtreme_settings->bar_borders ? "ON" : "OFF");
|
||||
|
||||
item = variable_item_list_add(
|
||||
var_item_list, "Bar Background", 2, xtreme_app_scene_statusbar_bar_background_changed, app);
|
||||
variable_item_set_current_value_index(item, xtreme_settings->bar_background);
|
||||
variable_item_set_current_value_text(item, xtreme_settings->bar_background ? "ON" : "OFF");
|
||||
|
||||
variable_item_list_set_selected_item(var_item_list, 0);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, XtremeAppViewVarItemList);
|
||||
}
|
||||
|
||||
bool xtreme_app_scene_statusbar_on_event(void* context, SceneManagerEvent event) {
|
||||
UNUSED(context);
|
||||
UNUSED(event);
|
||||
bool consumed = false;
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void xtreme_app_scene_statusbar_on_exit(void* context) {
|
||||
XtremeApp* app = context;
|
||||
variable_item_list_reset(app->var_item_list);
|
||||
}
|
||||
213
applications/main/xtreme_app/xtreme_app.c
Normal file
213
applications/main/xtreme_app/xtreme_app.c
Normal file
@@ -0,0 +1,213 @@
|
||||
#include "xtreme_app.h"
|
||||
|
||||
static bool xtreme_app_custom_event_callback(void* context, uint32_t event) {
|
||||
furi_assert(context);
|
||||
XtremeApp* app = context;
|
||||
return scene_manager_handle_custom_event(app->scene_manager, event);
|
||||
}
|
||||
|
||||
void xtreme_app_reboot(void* context) {
|
||||
UNUSED(context);
|
||||
power_reboot(PowerBootModeNormal);
|
||||
}
|
||||
|
||||
static bool xtreme_app_back_event_callback(void* context) {
|
||||
furi_assert(context);
|
||||
XtremeApp* app = context;
|
||||
|
||||
if(!scene_manager_has_previous_scene(app->scene_manager, XtremeAppSceneStart)) {
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
if(app->save_subghz) {
|
||||
FlipperFormat* subghz_range = flipper_format_file_alloc(storage);
|
||||
if(flipper_format_file_open_existing(subghz_range, "/ext/subghz/assets/extend_range.txt")) {
|
||||
flipper_format_insert_or_update_bool(
|
||||
subghz_range, "use_ext_range_at_own_risk", &app->subghz_extend, 1);
|
||||
flipper_format_insert_or_update_bool(
|
||||
subghz_range, "ignore_default_tx_region", &app->subghz_bypass, 1);
|
||||
}
|
||||
flipper_format_free(subghz_range);
|
||||
}
|
||||
|
||||
if(app->save_level) {
|
||||
Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN);
|
||||
int xp = app->dolphin_level > 1 ? dolphin_get_levels()[app->dolphin_level - 2] : 0;
|
||||
dolphin->state->data.icounter = xp + 1;
|
||||
dolphin->state->dirty = true;
|
||||
dolphin_state_save(dolphin->state);
|
||||
furi_record_close(RECORD_DOLPHIN);
|
||||
}
|
||||
|
||||
if(app->save_name) {
|
||||
if(strcmp(app->device_name, "") == 0) {
|
||||
storage_simply_remove(storage, NAMECHANGER_PATH);
|
||||
} else {
|
||||
FlipperFormat* file = flipper_format_file_alloc(storage);
|
||||
|
||||
do {
|
||||
if(!flipper_format_file_open_always(file, NAMECHANGER_PATH)) break;
|
||||
|
||||
if(!flipper_format_write_header_cstr(file, NAMECHANGER_HEADER, 1)) break;
|
||||
|
||||
if(!flipper_format_write_comment_cstr(file, "Changing the value below will change your FlipperZero device name.")) break;
|
||||
if(!flipper_format_write_comment_cstr(file, "Note: This is limited to 8 characters using the following: a-z, A-Z, 0-9, and _")) break;
|
||||
if(!flipper_format_write_comment_cstr(file, "It cannot contain any other characters.")) break;
|
||||
|
||||
if(!flipper_format_write_string_cstr(file, "Name", app->device_name)) break;
|
||||
|
||||
} while(0);
|
||||
|
||||
flipper_format_free(file);
|
||||
}
|
||||
}
|
||||
|
||||
if(app->save_settings) {
|
||||
XTREME_SETTINGS_SAVE();
|
||||
}
|
||||
|
||||
if(app->require_reboot) {
|
||||
popup_set_header(app->popup, "Rebooting...", 64, 26, AlignCenter, AlignCenter);
|
||||
popup_set_text(app->popup, "Applying changes...", 64, 40, AlignCenter, AlignCenter);
|
||||
popup_set_callback(app->popup, xtreme_app_reboot);
|
||||
popup_set_context(app->popup, app);
|
||||
popup_set_timeout(app->popup, 1000);
|
||||
popup_enable_timeout(app->popup);
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, XtremeAppViewPopup);
|
||||
return true;
|
||||
}
|
||||
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
return scene_manager_handle_back_event(app->scene_manager);
|
||||
}
|
||||
|
||||
XtremeApp* xtreme_app_alloc() {
|
||||
XtremeApp* app = malloc(sizeof(XtremeApp));
|
||||
app->gui = furi_record_open(RECORD_GUI);
|
||||
|
||||
// View Dispatcher and Scene Manager
|
||||
app->view_dispatcher = view_dispatcher_alloc();
|
||||
app->scene_manager = scene_manager_alloc(&xtreme_app_scene_handlers, app);
|
||||
view_dispatcher_enable_queue(app->view_dispatcher);
|
||||
view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
|
||||
|
||||
view_dispatcher_set_custom_event_callback(
|
||||
app->view_dispatcher, xtreme_app_custom_event_callback);
|
||||
view_dispatcher_set_navigation_event_callback(
|
||||
app->view_dispatcher, xtreme_app_back_event_callback);
|
||||
|
||||
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
|
||||
|
||||
// Gui Modules
|
||||
app->var_item_list = variable_item_list_alloc();
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher,
|
||||
XtremeAppViewVarItemList,
|
||||
variable_item_list_get_view(app->var_item_list));
|
||||
|
||||
app->text_input = text_input_alloc();
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher,
|
||||
XtremeAppViewTextInput,
|
||||
text_input_get_view(app->text_input));
|
||||
|
||||
app->popup = popup_alloc();
|
||||
view_dispatcher_add_view(app->view_dispatcher, XtremeAppViewPopup, popup_get_view(app->popup));
|
||||
|
||||
// Settings init
|
||||
|
||||
XtremeSettings* xtreme_settings = XTREME_SETTINGS();
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* subghz_range = flipper_format_file_alloc(storage);
|
||||
app->subghz_extend = false;
|
||||
app->subghz_bypass = false;
|
||||
if(flipper_format_file_open_existing(subghz_range, "/ext/subghz/assets/extend_range.txt")) {
|
||||
flipper_format_read_bool(subghz_range, "use_ext_range_at_own_risk", &app->subghz_extend, 1);
|
||||
flipper_format_read_bool(subghz_range, "ignore_default_tx_region", &app->subghz_bypass, 1);
|
||||
}
|
||||
flipper_format_free(subghz_range);
|
||||
|
||||
Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN);
|
||||
DolphinStats stats = dolphin_stats(dolphin);
|
||||
app->dolphin_level = stats.level;
|
||||
furi_record_close(RECORD_DOLPHIN);
|
||||
|
||||
strlcpy(app->device_name, furi_hal_version_get_name_ptr(), NAMECHANGER_TEXT_STORE_SIZE);
|
||||
|
||||
app->asset_pack = 0;
|
||||
asset_packs_init(app->asset_packs);
|
||||
File* folder = storage_file_alloc(storage);
|
||||
FileInfo info;
|
||||
char* name = malloc(MAX_PACK_NAME_LEN);
|
||||
if(storage_dir_open(folder, PACKS_DIR)) {
|
||||
while(storage_dir_read(folder, &info, name, MAX_PACK_NAME_LEN)) {
|
||||
if(info.flags & FSF_DIRECTORY) {
|
||||
char* copy = malloc(MAX_PACK_NAME_LEN);
|
||||
strlcpy(copy, name, MAX_PACK_NAME_LEN);
|
||||
uint idx = 0;
|
||||
if(strcmp(copy, "NSFW") != 0) {
|
||||
for(; idx < asset_packs_size(app->asset_packs); idx++) {
|
||||
char* comp = *asset_packs_get(app->asset_packs, idx);
|
||||
if(strcasecmp(copy, comp) < 0 && strcmp(comp, "NSFW") != 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
asset_packs_push_at(app->asset_packs, idx, copy);
|
||||
if(app->asset_pack != 0) {
|
||||
if(idx < app->asset_pack) app->asset_pack++;
|
||||
} else {
|
||||
if(strcmp(copy, xtreme_settings->asset_pack) == 0) app->asset_pack = idx + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
free(name);
|
||||
storage_file_free(folder);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
app->version_tag = furi_string_alloc_printf("%s %s", version_get_gitbranchnum(NULL), version_get_builddate(NULL));
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
void xtreme_app_free(XtremeApp* app) {
|
||||
furi_assert(app);
|
||||
|
||||
// Gui modules
|
||||
view_dispatcher_remove_view(app->view_dispatcher, XtremeAppViewVarItemList);
|
||||
variable_item_list_free(app->var_item_list);
|
||||
view_dispatcher_remove_view(app->view_dispatcher, XtremeAppViewTextInput);
|
||||
text_input_free(app->text_input);
|
||||
view_dispatcher_remove_view(app->view_dispatcher, XtremeAppViewPopup);
|
||||
popup_free(app->popup);
|
||||
|
||||
// View Dispatcher and Scene Manager
|
||||
view_dispatcher_free(app->view_dispatcher);
|
||||
scene_manager_free(app->scene_manager);
|
||||
|
||||
// Settings deinit
|
||||
|
||||
asset_packs_it_t it;
|
||||
for(asset_packs_it(it, app->asset_packs); !asset_packs_end_p(it); asset_packs_next(it)) {
|
||||
free(*asset_packs_cref(it));
|
||||
}
|
||||
asset_packs_clear(app->asset_packs);
|
||||
|
||||
furi_string_free(app->version_tag);
|
||||
|
||||
// Records
|
||||
furi_record_close(RECORD_GUI);
|
||||
free(app);
|
||||
}
|
||||
|
||||
extern int32_t xtreme_app(void* p) {
|
||||
UNUSED(p);
|
||||
XtremeApp* app = xtreme_app_alloc();
|
||||
scene_manager_next_scene(app->scene_manager, XtremeAppSceneStart);
|
||||
view_dispatcher_run(app->view_dispatcher);
|
||||
xtreme_app_free(app);
|
||||
return 0;
|
||||
}
|
||||
50
applications/main/xtreme_app/xtreme_app.h
Normal file
50
applications/main/xtreme_app/xtreme_app.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
|
||||
#include <furi.h>
|
||||
#include <gui/gui.h>
|
||||
#include <gui/view.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
#include <gui/scene_manager.h>
|
||||
#include <assets_icons.h>
|
||||
#include <gui/modules/variable_item_list.h>
|
||||
#include <gui/modules/text_input.h>
|
||||
#include <gui/modules/popup.h>
|
||||
#include <lib/toolbox/value_index.h>
|
||||
#include <namechangersrv/namechangersrv.h>
|
||||
#include "scenes/xtreme_app_scene.h"
|
||||
#include "dolphin/helpers/dolphin_state.h"
|
||||
#include "dolphin/dolphin.h"
|
||||
#include "dolphin/dolphin_i.h"
|
||||
#include <lib/flipper_format/flipper_format.h>
|
||||
#include <m-array.h>
|
||||
#include "xtreme/settings.h"
|
||||
#include "xtreme/assets.h"
|
||||
|
||||
ARRAY_DEF(asset_packs, char*)
|
||||
|
||||
typedef struct {
|
||||
Gui* gui;
|
||||
SceneManager* scene_manager;
|
||||
ViewDispatcher* view_dispatcher;
|
||||
VariableItemList* var_item_list;
|
||||
TextInput* text_input;
|
||||
Popup* popup;
|
||||
bool subghz_extend;
|
||||
bool subghz_bypass;
|
||||
int dolphin_level;
|
||||
char device_name[NAMECHANGER_TEXT_STORE_SIZE];
|
||||
uint asset_pack;
|
||||
asset_packs_t asset_packs;
|
||||
FuriString* version_tag;
|
||||
bool save_subghz;
|
||||
bool save_level;
|
||||
bool save_name;
|
||||
bool save_settings;
|
||||
bool require_reboot;
|
||||
} XtremeApp;
|
||||
|
||||
typedef enum {
|
||||
XtremeAppViewVarItemList,
|
||||
XtremeAppViewTextInput,
|
||||
XtremeAppViewPopup,
|
||||
} XtremeAppView;
|
||||
Reference in New Issue
Block a user