Skip to content

Commit

Permalink
Merge pull request #7 from skawo/master
Browse files Browse the repository at this point in the history
Add a way to delete files in the menu.
  • Loading branch information
gameblabla authored Dec 23, 2021
2 parents 8afb574 + 317aaec commit 349869a
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 47 deletions.
2 changes: 2 additions & 0 deletions inc/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
103 changes: 83 additions & 20 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ enum InputMap
mp3,
abort_screen,
control_screen,
delete_prompt,
};
enum InputMap input_mapping = file_manager;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()))
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -4392,6 +4454,7 @@ void handleInput(display_context_t disp, sprite_t *contr)
break;

case mempak_menu:
case delete_prompt:

while (!(disp = display_lock()))
;
Expand Down Expand Up @@ -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()))
Expand Down
29 changes: 2 additions & 27 deletions src/menu_about.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
35 changes: 35 additions & 0 deletions src/menu_controls.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

#include <libdragon.h>
#include <stdio.h>
#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);
}
24 changes: 24 additions & 0 deletions src/menu_delete.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

#include <libdragon.h>
#include <stdio.h>
#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);
}
}

0 comments on commit 349869a

Please sign in to comment.