Skip to content

Commit

Permalink
Merge pull request #756 from ESurge/420_gameMenu
Browse files Browse the repository at this point in the history
Fixes for Customizable Games Mode Menu
  • Loading branch information
RogueMaster authored Sep 24, 2023
2 parents 9742c6c + ccccfc3 commit b388581
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 133 deletions.
25 changes: 11 additions & 14 deletions applications/services/gui/modules/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
#include <m-array.h>
#include <cfw.h>
#include <m-string.h>
#include "applications/settings/desktop_settings/desktop_settings_app.h"

struct Menu {
View* view;
FuriTimer* scroll_timer;
bool gamemode;
};

typedef struct {
Expand All @@ -36,6 +36,7 @@ typedef struct {
size_t scroll_counter;
size_t vertical_offset;
MenuStyle my_menu_style;
bool gamemode;
} MenuModel;

static void menu_process_up(Menu* menu);
Expand Down Expand Up @@ -404,17 +405,13 @@ static void menu_draw_callback(Canvas* canvas, void* _model) {
static bool menu_input_callback(InputEvent* event, void* context) {
Menu* menu = context;
bool consumed = true;

// TODO: THIS PROBABLY SHOULD BE REMOVED AND CHANGED
DesktopSettings* desktop_settings = malloc(sizeof(DesktopSettings));
DESKTOP_SETTINGS_LOAD(desktop_settings);

MenuStyle this_menu_style;
if(desktop_settings->is_dumbmode) {
if(menu->gamemode) {
this_menu_style = CFW_SETTINGS()->game_menu_style;
} else {
this_menu_style = CFW_SETTINGS()->menu_style;
}
free(desktop_settings);

if(this_menu_style == MenuStyleVertical &&
furi_hal_rtc_is_flag_set(FuriHalRtcFlagHandOrient)) {
Expand Down Expand Up @@ -509,10 +506,10 @@ static void menu_exit(void* context) {
}

Menu* menu_alloc() {
return menu_pos_alloc(0);
return menu_pos_alloc(0, 0);
}

Menu* menu_pos_alloc(size_t pos) {
Menu* menu_pos_alloc(size_t pos, bool gamemode) {
Menu* menu = malloc(sizeof(Menu));
menu->view = view_alloc(menu->view);
view_set_context(menu->view, menu);
Expand All @@ -523,16 +520,14 @@ Menu* menu_pos_alloc(size_t pos) {
view_set_exit_callback(menu->view, menu_exit);

menu->scroll_timer = furi_timer_alloc(menu_scroll_timer_callback, FuriTimerTypePeriodic, menu);
menu->gamemode = gamemode;

DesktopSettings* desktop_settings = malloc(sizeof(DesktopSettings));
DESKTOP_SETTINGS_LOAD(desktop_settings);
MenuStyle this_menu_style;
if(desktop_settings->is_dumbmode) {
if(menu->gamemode) {
this_menu_style = CFW_SETTINGS()->game_menu_style;
} else {
this_menu_style = CFW_SETTINGS()->menu_style;
}
free(desktop_settings);

with_view_model(
menu->view,
Expand All @@ -541,6 +536,7 @@ Menu* menu_pos_alloc(size_t pos) {
MenuItemArray_init(model->items);
model->position = pos;
model->my_menu_style = this_menu_style;
model->gamemode = menu->gamemode;
},
true);

Expand Down Expand Up @@ -639,8 +635,9 @@ static void menu_process_up(Menu* menu) {
position = model->position;
size_t count = MenuItemArray_size(model->items);
size_t vertical_offset = model->vertical_offset;
MenuStyle my_menu_style = model->my_menu_style;

switch(CFW_SETTINGS()->menu_style) {
switch(my_menu_style) {
case MenuStyleList:
case MenuStyleEurocorp:
if(position > 0) {
Expand Down
3 changes: 2 additions & 1 deletion applications/services/gui/modules/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ Menu* menu_alloc();
*
* @return Menu instance
* @param pos size_t position
* @param gamemode bool gamemode on/off
*/
Menu* menu_pos_alloc(size_t pos);
Menu* menu_pos_alloc(size_t pos, bool gamemode);

/** Free menu
*
Expand Down
4 changes: 2 additions & 2 deletions applications/services/loader/loader_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ static LoaderMenuApp* loader_menu_app_alloc(LoaderMenu* loader_menu) {
furi_record_close(RECORD_LOADER);

uint32_t my_start_point = CLAMP(CFW_SETTINGS()->start_point, APP_COUNT - 1, 0U);
app->primary_menu = menu_pos_alloc((size_t)my_start_point);
app->primary_menu = menu_pos_alloc((size_t)my_start_point, false);
app->settings_menu = submenu_alloc();

loader_menu_build_menu(app, loader_menu);
Expand Down Expand Up @@ -197,7 +197,7 @@ static LoaderMenuApp* loader_gamesmenu_app_alloc(LoaderMenu* loader_menu) {
furi_record_close(RECORD_LOADER);

uint32_t my_start_point = CLAMP(CFW_SETTINGS()->game_start_point, APP_COUNT - 1, 0U);
app->primary_menu = menu_pos_alloc((size_t)my_start_point);
app->primary_menu = menu_pos_alloc((size_t)my_start_point, true);
loader_menu_build_gamesmenu(app, loader_menu);

// Primary menu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ ADD_SCENE(cfw_app, interface_mainmenu_add_main, InterfaceMainmenuAddMain)
ADD_SCENE(cfw_app, interface_mainmenu_reset, InterfaceMainmenuReset)
ADD_SCENE(cfw_app, interface_gamemenu, InterfaceGamemenu)
ADD_SCENE(cfw_app, interface_gamemenu_add, InterfaceGamemenuAdd)
ADD_SCENE(cfw_app, interface_gamemenu_add_main, InterfaceGamemenuAddMain)
ADD_SCENE(cfw_app, interface_gamemenu_reset, InterfaceGamemenuReset)
ADD_SCENE(cfw_app, interface_passport, InterfacePassport)
ADD_SCENE(cfw_app, protocols, Protocols)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ void cfw_app_scene_interface_gamemenu_on_enter(void* context) {
cfw_app_scene_interface_gamemenu_menu_style_changed,
app);
variable_item_set_current_value_index(item, cfw_settings->game_menu_style);
variable_item_set_current_value_text(item, game_menu_style_names[cfw_settings->game_menu_style]);
variable_item_set_current_value_text(
item, game_menu_style_names[cfw_settings->game_menu_style]);

item = variable_item_list_add(
var_item_list,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#include "../cfw_app.h"

enum SubmenuIndex {
SubmenuIndexMainApp,
SubmenuIndexExternalApp,
};
#define GAMES_FOLDER EXT_PATH("apps/Games")

static bool fap_selector_item_callback(
FuriString* file_path,
Expand All @@ -17,34 +14,26 @@ static bool fap_selector_item_callback(
return success;
}

static void cfw_app_scene_interface_gamemenu_add_submenu_callback(void* context, uint32_t index) {
void cfw_app_scene_interface_gamemenu_add_on_enter(void* context) {
CfwApp* app = context;
scene_manager_set_scene_state(app->scene_manager, CfwAppSceneInterfaceGamemenuAdd, index);

switch(index) {
case SubmenuIndexMainApp:
scene_manager_next_scene(app->scene_manager, CfwAppSceneInterfaceGamemenuAddMain);
break;
case SubmenuIndexExternalApp: {
const DialogsFileBrowserOptions browser_options = {
.extension = ".fap",
.icon = &I_unknown_10px,
.skip_assets = true,
.hide_ext = true,
.item_loader_callback = fap_selector_item_callback,
.item_loader_context = app,
.base_path = EXT_PATH("apps"),
};
FuriString* temp_path = furi_string_alloc_set_str(EXT_PATH("apps"));
FuriString* filename = furi_string_alloc();
if(dialog_file_browser_show(app->dialogs, temp_path, temp_path, &browser_options)) {
Storage* storage = furi_record_open(RECORD_STORAGE);
uint8_t* icon_buf = malloc(MENU_ICON_MAX_SIZE);
const DialogsFileBrowserOptions browser_options = {
.extension = ".fap",
.icon = &I_unknown_10px,
.skip_assets = true,
.hide_ext = true,
.hide_dot_files = true,
.item_loader_callback = fap_selector_item_callback,
.item_loader_context = app,
.base_path = GAMES_FOLDER,
};
FuriString* temp_path = furi_string_alloc_set_str(GAMES_FOLDER);
FuriString* filename = furi_string_alloc();
if(dialog_file_browser_show(app->dialogs, temp_path, temp_path, &browser_options)) {
Storage* storage = furi_record_open(RECORD_STORAGE);
uint8_t* icon_buf = malloc(MENU_ICON_MAX_SIZE);

if(!flipper_application_load_name_and_icon(temp_path, storage, &icon_buf, filename)) {
free(icon_buf);
} else {
free(icon_buf);
if(strstr(furi_string_get_cstr(temp_path), GAMES_FOLDER)) {
if(flipper_application_load_name_and_icon(temp_path, storage, &icon_buf, filename)) {
CharList_push_back(
app->gamemenu_app_names, strdup(furi_string_get_cstr(filename)));
CharList_push_back(
Expand All @@ -53,40 +42,14 @@ static void cfw_app_scene_interface_gamemenu_add_submenu_callback(void* context,
app->save_gamemenu_apps = true;
app->require_reboot = true;
}
furi_record_close(RECORD_STORAGE);
furi_string_free(temp_path);
furi_string_free(filename);
}
scene_manager_search_and_switch_to_previous_scene(
app->scene_manager, CfwAppSceneInterfaceGamemenu);
break;
}
default:
break;
free(icon_buf);
furi_record_close(RECORD_STORAGE);
furi_string_free(temp_path);
furi_string_free(filename);
}
}

void cfw_app_scene_interface_gamemenu_add_on_enter(void* context) {
CfwApp* app = context;
Submenu* submenu = app->submenu;

submenu_add_item(
submenu,
"Main App",
SubmenuIndexMainApp,
cfw_app_scene_interface_gamemenu_add_submenu_callback,
app);

submenu_add_item(
submenu,
"External App",
SubmenuIndexExternalApp,
cfw_app_scene_interface_gamemenu_add_submenu_callback,
app);

submenu_set_header(submenu, "Add Game Menu App:");

view_dispatcher_switch_to_view(app->view_dispatcher, CfwAppViewSubmenu);
scene_manager_search_and_switch_to_previous_scene(
app->scene_manager, CfwAppSceneInterfaceGamemenu);
}

bool cfw_app_scene_interface_gamemenu_add_on_event(void* context, SceneManagerEvent event) {
Expand All @@ -101,6 +64,5 @@ bool cfw_app_scene_interface_gamemenu_add_on_event(void* context, SceneManagerEv
}

void cfw_app_scene_interface_gamemenu_add_on_exit(void* context) {
CfwApp* app = context;
submenu_reset(app->submenu);
UNUSED(context);
}

This file was deleted.

6 changes: 3 additions & 3 deletions firmware/targets/f7/api_symbols.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,39.1,,
Version,+,39.2,,
Header,+,applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/cli/cli.h,,
Expand Down Expand Up @@ -1481,7 +1481,6 @@ Function,+,furi_hal_rtc_set_pin_fails,void,uint32_t
Function,+,furi_hal_rtc_set_register,void,"FuriHalRtcRegister, uint32_t"
Function,+,furi_hal_rtc_sync_shadow,void,
Function,+,furi_hal_rtc_validate_datetime,_Bool,FuriHalRtcDateTime*
Function,-,furi_hal_set_is_normal_boot,void,_Bool
Function,+,furi_hal_sd_get_card_state,FuriStatus,
Function,+,furi_hal_sd_info,FuriStatus,FuriHalSdInfo*
Function,+,furi_hal_sd_init,FuriStatus,_Bool
Expand All @@ -1490,6 +1489,7 @@ Function,+,furi_hal_sd_max_mount_retry_count,uint8_t,
Function,+,furi_hal_sd_presence_init,void,
Function,+,furi_hal_sd_read_blocks,FuriStatus,"uint32_t*, uint32_t, uint32_t"
Function,+,furi_hal_sd_write_blocks,FuriStatus,"const uint32_t*, uint32_t, uint32_t"
Function,-,furi_hal_set_is_normal_boot,void,_Bool
Function,+,furi_hal_speaker_acquire,_Bool,uint32_t
Function,-,furi_hal_speaker_deinit,void,
Function,-,furi_hal_speaker_init,void,
Expand Down Expand Up @@ -2098,7 +2098,7 @@ Function,+,menu_add_item,void,"Menu*, const char*, const Icon*, uint32_t, MenuIt
Function,+,menu_alloc,Menu*,
Function,+,menu_free,void,Menu*
Function,+,menu_get_view,View*,Menu*
Function,+,menu_pos_alloc,Menu*,size_t
Function,+,menu_pos_alloc,Menu*,"size_t, _Bool"
Function,+,menu_reset,void,Menu*
Function,+,menu_set_selected_item,void,"Menu*, uint32_t"
Function,-,mf_classic_auth_attempt,_Bool,"FuriHalNfcTxRxContext*, Crypto1*, MfClassicAuthContext*, uint64_t"
Expand Down

0 comments on commit b388581

Please sign in to comment.