From 481a811b04e529172e40ca161075ac50cc663bd9 Mon Sep 17 00:00:00 2001 From: skawo <43761362+skawo@users.noreply.github.com> Date: Sun, 19 Dec 2021 19:02:13 +0100 Subject: [PATCH 1/2] Add a way to delete files in the menu. --- src/main.c | 103 +++++++++++++++++++++++++++++++++++--------- src/menu_about.c | 29 +------------ src/menu_controls.c | 35 +++++++++++++++ src/menu_delete.c | 25 +++++++++++ 4 files changed, 145 insertions(+), 47 deletions(-) create mode 100644 src/menu_controls.c create mode 100644 src/menu_delete.c diff --git a/src/main.c b/src/main.c index e5f120d..80b802d 100755 --- a/src/main.c +++ b/src/main.c @@ -171,6 +171,7 @@ enum InputMap mp3, abort_screen, control_screen, + delete_prompt, }; enum InputMap input_mapping = file_manager; @@ -721,7 +722,10 @@ void drawBoxNumber(display_context_t disp, int box) box_color = graphics_make_color(0x00, 0x60, 0x00, 0xC3); drawBox(20, 24, 277, 193, disp); break; //filebrowser - + case 13: + box_color = graphics_make_color(0x60, 0x00, 0x00, 0xD3); + drawBox(28, 105, 260, 40, disp); + break; //delete default: break; } @@ -1722,14 +1726,14 @@ int saveTypeFromSd(display_context_t disp, char *rom_name, int stype) return 0; } - if (pushSaveToCart(stype, cartsave_data)) - { - printText("transferred save data...", 3, -1, disp); - } - else - { - printText("error transfering save data", 3, -1, disp); - } + if (pushSaveToCart(stype, cartsave_data)) + { + printText("transferred save data...", 3, -1, disp); + } + else + { + printText("error transfering save data", 3, -1, disp); + } return 1; } @@ -1778,13 +1782,13 @@ int saveTypeToSd(display_context_t disp, char *rom_name, int stype) if (getSaveFromCart(stype, cartsave_data)) { UINT bw; - result = f_write ( - &file, /* [IN] Pointer to the file object structure */ - cartsave_data, /* [IN] Pointer to the data to be written */ - size, /* [IN] Number of bytes to write */ - &bw /* [OUT] Pointer to the variable to return number of bytes written */ - ); - f_close(&file); + result = f_write ( + &file, /* [IN] Pointer to the file object structure */ + cartsave_data, /* [IN] Pointer to the data to be written */ + size, /* [IN] Number of bytes to write */ + &bw /* [OUT] Pointer to the variable to return number of bytes written */ + ); + f_close(&file); printText("RAM area copied to SD card.", 3, -1, disp); return 1; @@ -3082,6 +3086,25 @@ void drawSet4(display_context_t disp) graphics_draw_text(disp, 209, 100, "_"); } + +void showDeletePrompt(display_context_t disp) +{ + while (!(disp = display_lock())) + ; + new_scroll_pos(&cursor, &page, MAX_LIST, count); + clearScreen(disp); + display_dir(list, cursor, page, MAX_LIST, count, disp); + drawBoxNumber(disp, 13); + display_show(disp); + + bool isdir = list[cursor].type == DT_DIR; + + if (sound_on) + playSound(2 + isdir); + + menu_delete(disp, isdir); +} + void showAboutScreen(display_context_t disp) { while (!(disp = display_lock())) @@ -3636,7 +3659,7 @@ void handleInput(display_context_t disp, sprite_t *contr) break; } } - else if (keys.c[0].L) + else if (keys.c[0].L && !keys.c[0].R) { switch (input_mapping) { @@ -3688,7 +3711,7 @@ void handleInput(display_context_t disp, sprite_t *contr) break; } } - else if (keys.c[0].R) + else if (keys.c[0].R && !keys.c[0].L) { switch (input_mapping) { @@ -4147,6 +4170,19 @@ void handleInput(display_context_t disp, sprite_t *contr) break; } } + else if (keys.c[0].R && keys.c[0].L) + { + switch (input_mapping) + { + case file_manager: + showDeletePrompt(disp); + input_mapping = delete_prompt; + break; + + default: + break; + } + } else if (keys.c[0].A) { switch (input_mapping) @@ -4313,6 +4349,32 @@ void handleInput(display_context_t disp, sprite_t *contr) input_mapping = file_manager; break; } + case delete_prompt: + { + if (list[cursor].type != DT_DIR) + { + char name_file[256]; + + if (strcmp(pwd, "/") == 0) + sprintf(name_file, "/%s", list[cursor].filename); + else + sprintf(name_file, "%s/%s", pwd, list[cursor].filename); + + f_unlink(name_file); + + while (!(disp = display_lock())) + ; + graphics_set_color(graphics_make_color(0xFF, 0xFF, 0xFF, 0xFF), graphics_make_color(0x00, 0x00, 0x00, 0x00)); + new_scroll_pos(&cursor, &page, MAX_LIST, count); + clearScreen(disp); + display_show(disp); + + input_mapping = file_manager; + readSDcard(disp, pwd); + display_show(disp); + } + break; + } default: break; } @@ -4392,6 +4454,7 @@ void handleInput(display_context_t disp, sprite_t *contr) break; case mempak_menu: + case delete_prompt: while (!(disp = display_lock())) ; @@ -4451,8 +4514,8 @@ void handleInput(display_context_t disp, sprite_t *contr) mp3_Stop(); mp3playing = 0; audio_close(); - free(buf_ptr); - buf_ptr = 0; + free(buf_ptr); + buf_ptr = 0; audio_init(44100, 8); while (!(disp = display_lock())) diff --git a/src/menu_about.c b/src/menu_about.c index 15b3c28..ed42b89 100755 --- a/src/menu_about.c +++ b/src/menu_about.c @@ -29,30 +29,5 @@ void menu_about(display_context_t disp) printText("Conle Z: Page 2", 9, -1, disp); printText("AriaHiro64", 9, -1, disp); printText("moparisthebest", 9, -1, disp); -} //TODO: make scrolling text, should include libraries used. -void menu_controls(display_context_t disp) -{ - printText(" - Controls -", 4, 4, disp); - printText(" ", 4, -1, disp); - printText(" L: brings up the mempak", 4, -1, disp); - printText(" menu", 5, -1, disp); - printText(" ", 4, -1, disp); - printText(" Z: about screen", 4, -1, disp); - printText(" ", 4, -1, disp); - printText(" A: start rom/directory", 4, -1, disp); - printText(" mempak", 4, -1, disp); - printText(" ", 4, -1, disp); - printText(" B: back/cancel", 4, -1, disp); - printText(" ", 4, -1, disp); - printText(" START: start last rom", 4, -1, disp); - printText(" ", 4, -1, disp); - printText(" C-left: rom info/mempak", 4, -1, disp); - printText(" content view", 4, -1, disp); - printText(" ", 4, -1, disp); - printText("C-right: rom config creen", 4, -1, disp); - printText(" ", 4, -1, disp); - printText(" C-up: view full filename", 4, -1, disp); - printText(" ", 4, -1, disp); - printText(" C-down: Toplist 15", 4, -1, disp); - -} + printText("Skawo", 9, -1, disp); +} //TODO: make scrolling text, should include libraries used. \ No newline at end of file diff --git a/src/menu_controls.c b/src/menu_controls.c new file mode 100644 index 0000000..a6d0b1c --- /dev/null +++ b/src/menu_controls.c @@ -0,0 +1,35 @@ + +#include +#include +#include "types.h" +#include "menu.h" +#include "version.h" +#include "main.h" +#include "everdrive.h" + +void menu_controls(display_context_t disp) +{ + printText(" - Controls -", 4, 4, disp); + printText(" ", 4, -1, disp); + printText(" L: show mempak menu", 4, -1, disp); + printText(" ", 4, -1, disp); + printText(" Z: about screen", 4, -1, disp); + printText(" ", 4, -1, disp); + printText(" A: start rom/directory", 4, -1, disp); + printText(" mempak", 4, -1, disp); + printText(" ", 4, -1, disp); + printText(" B: back/cancel", 4, -1, disp); + printText(" ", 4, -1, disp); + printText(" START: start last rom", 4, -1, disp); + printText(" ", 4, -1, disp); + printText(" C-left: rom info/mempak", 4, -1, disp); + printText(" content view", 4, -1, disp); + printText(" ", 4, -1, disp); + printText("C-right: rom config creen", 4, -1, disp); + printText(" ", 4, -1, disp); + printText(" C-up: view full filename", 4, -1, disp); + printText(" ", 4, -1, disp); + printText(" C-down: Toplist 15", 4, -1, disp); + printText(" ", 4, -1, disp); + printText(" R + L: Delete file", 4, -1, disp); +} diff --git a/src/menu_delete.c b/src/menu_delete.c new file mode 100644 index 0000000..daac1a6 --- /dev/null +++ b/src/menu_delete.c @@ -0,0 +1,25 @@ + +#include +#include +#include "types.h" +#include "menu.h" +#include "version.h" +#include "main.h" +#include "everdrive.h" + + +void menu_delete(display_context_t disp, bool isdir) +{ + if (isdir) + { + printText("Cannot delete directories!", 7, 14, disp); + printText("B: Exit", 13, 16, disp); + } + else + { + printText("Delete this file?", 10, 14, disp); + printText("A: Confirm", 13, 16, disp); + printText("B: Cancel", 13, 17, disp); + + } +} From 317aaec5ee373f70fd559b41468f1d5a6e87b6c1 Mon Sep 17 00:00:00 2001 From: skawo <43761362+skawo@users.noreply.github.com> Date: Sun, 19 Dec 2021 19:21:46 +0100 Subject: [PATCH 2/2] Add missing menu function definitions. --- inc/menu.h | 2 ++ src/menu_delete.c | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/inc/menu.h b/inc/menu.h index 4ac1123..95cdf84 100755 --- a/inc/menu.h +++ b/inc/menu.h @@ -11,5 +11,7 @@ extern int text_offset; void printText(char *msg, int x, int y, display_context_t dcon); void menu_about(display_context_t disp); +void menu_controls(display_context_t disp); +void menu_delete(display_context_t disp, bool isdir); #endif diff --git a/src/menu_delete.c b/src/menu_delete.c index daac1a6..21cacce 100644 --- a/src/menu_delete.c +++ b/src/menu_delete.c @@ -20,6 +20,5 @@ void menu_delete(display_context_t disp, bool isdir) printText("Delete this file?", 10, 14, disp); printText("A: Confirm", 13, 16, disp); printText("B: Cancel", 13, 17, disp); - } }