Added favorite removing

Users can remove favorites via the menu
This commit is contained in:
Ross Gouldthorpe 2024-12-08 23:10:26 +00:00
parent 1fecd26f0b
commit 05b17e842d
7 changed files with 113 additions and 49 deletions

View File

@ -33,7 +33,7 @@ void bookkeeping_ini_load_list(bookkeeping_item_t* list, int count, mini_t* ini,
list[i].secondary_path = path_create(mini_get_string(ini, group, buf, "")); list[i].secondary_path = path_create(mini_get_string(ini, group, buf, ""));
sprintf(buf,"%d_type", i); sprintf(buf,"%d_type", i);
list[i].bookkeeping_type = mini_get_int(ini, group, buf, HISTORY_TYPE_EMPTY); list[i].bookkeeping_type = mini_get_int(ini, group, buf, BOOKKEEPING_TYPE_EMPTY);
} }
} }
@ -88,18 +88,30 @@ static bool bookkeeping_item_match(bookkeeping_item_t* left, bookkeeping_item_t*
return false; return false;
} }
static void bookkeeping_clear_item(bookkeeping_item_t* item) { static void bookkeeping_clear_item(bookkeeping_item_t* item, bool leave_null) {
if(item->primary_path != NULL){ if(item->primary_path != NULL){
path_free(item->primary_path); path_free(item->primary_path);
if(leave_null) {
item->primary_path = NULL;
} else {
item->primary_path = path_create("");
}
} }
if(item->secondary_path != NULL){ if(item->secondary_path != NULL){
path_free(item->secondary_path); path_free(item->secondary_path);
if(leave_null) {
item->secondary_path = NULL;
} else {
item->secondary_path = path_create("");
} }
item->bookkeeping_type = HISTORY_TYPE_EMPTY; }
item->bookkeeping_type = BOOKKEEPING_TYPE_EMPTY;
} }
static void bookkeeping_copy_item(bookkeeping_item_t* source, bookkeeping_item_t* destination){ static void bookkeeping_copy_item(bookkeeping_item_t* source, bookkeeping_item_t* destination){
bookkeeping_clear_item(destination); bookkeeping_clear_item(destination, true);
destination->primary_path = path_clone(source->primary_path); destination->primary_path = path_clone(source->primary_path);
destination->secondary_path = source->secondary_path != NULL ? path_clone(source->secondary_path) : path_create(""); destination->secondary_path = source->secondary_path != NULL ? path_clone(source->secondary_path) : path_create("");
@ -120,6 +132,19 @@ static void bookkeeping_move_items_down(bookkeeping_item_t* list, int start, int
} }
static void bookkeeping_move_items_up(bookkeeping_item_t* list, int start, int end) {
int current = start;
do {
if(current > end) {
break;
}
bookkeeping_copy_item(&list[current + 1], &list[current]);
current++;
} while(true);
}
static void bookkeeping_insert_top(bookkeeping_item_t* list, int count, bookkeeping_item_t* new_item) { static void bookkeeping_insert_top(bookkeeping_item_t* list, int count, bookkeeping_item_t* new_item) {
// if it matches the top of the list already then nothing to do // if it matches the top of the list already then nothing to do
@ -128,7 +153,7 @@ static void bookkeeping_insert_top(bookkeeping_item_t* list, int count, bookkeep
} }
// if the top isn't empty then we need to move things around // if the top isn't empty then we need to move things around
if(list[0].bookkeeping_type != HISTORY_TYPE_EMPTY) { if(list[0].bookkeeping_type != BOOKKEEPING_TYPE_EMPTY) {
int found_at = -1; int found_at = -1;
for(int i=1; i < count; i++) { for(int i=1; i < count; i++) {
if(bookkeeping_item_match(&list[i], new_item)){ if(bookkeeping_item_match(&list[i], new_item)){
@ -169,3 +194,13 @@ void bookkeeping_favorite_add(bookkeeping_t *bookkeeping, path_t* primary_path,
bookkeeping_insert_top(bookkeeping->favorite_items, FAVORITES_COUNT, &new_item); bookkeeping_insert_top(bookkeeping->favorite_items, FAVORITES_COUNT, &new_item);
bookkeeping_save(bookkeeping); bookkeeping_save(bookkeeping);
} }
void bookkeeping_favorite_remove(bookkeeping_t *bookkeeping, int selection) {
if(bookkeeping->favorite_items[selection].bookkeeping_type != BOOKKEEPING_TYPE_EMPTY) {
bookkeeping_move_items_up(bookkeeping->favorite_items, selection, FAVORITES_COUNT -1);
bookkeeping_clear_item(&bookkeeping->favorite_items[FAVORITES_COUNT -1], false);
bookkeeping_save(bookkeeping);
}
}

View File

@ -14,9 +14,9 @@
#define HISTORY_COUNT 5 #define HISTORY_COUNT 5
typedef enum { typedef enum {
HISTORY_TYPE_EMPTY, BOOKKEEPING_TYPE_EMPTY,
HISTORY_TYPE_ROM, BOOKKEEPING_TYPE_ROM,
HISTORY_TYPE_DISK, BOOKKEEPING_TYPE_DISK,
} bookkeeping_item_types_t; } bookkeeping_item_types_t;
typedef struct { typedef struct {
@ -51,6 +51,8 @@ void bookkeeping_save (bookkeeping_t *history);
void bookkeeping_history_add(bookkeeping_t *bookkeeping, path_t* primary_path, path_t* secondary_path, bookkeeping_item_types_t type ); void bookkeeping_history_add(bookkeeping_t *bookkeeping, path_t* primary_path, path_t* secondary_path, bookkeeping_item_types_t type );
void bookkeeping_favorite_add(bookkeeping_t *bookkeeping, path_t* primary_path, path_t* secondary_path, bookkeeping_item_types_t type ); void bookkeeping_favorite_add(bookkeeping_t *bookkeeping, path_t* primary_path, path_t* secondary_path, bookkeeping_item_types_t type );
void bookkeeping_favorite_remove(bookkeeping_t *bookkeeping, int selection);
#endif #endif

View File

@ -261,7 +261,7 @@ void ui_components_main_text_draw_location (float x, float y, char *fmt, ...);
/** /**
* *
*/ */
void ui_components_tabs_draw(const char** text, int count, int selected ); void ui_components_tabs_draw(const char** text, int count, int selected, int width );
/** /**
* *

View File

@ -409,14 +409,14 @@ static void draw (menu_t *menu, surface_t *d) {
ui_components_actions_bar_text_draw( ui_components_actions_bar_text_draw(
ALIGN_CENTER, VALIGN_TOP, ALIGN_CENTER, VALIGN_TOP,
"%s" //ctime includes a newline "%s" //ctime includes a newline
"<C Change Tabs C>", "<C Change Tab C>",
ctime(&menu->current_time) ctime(&menu->current_time)
); );
} else { } else {
ui_components_actions_bar_text_draw( ui_components_actions_bar_text_draw(
ALIGN_CENTER, VALIGN_TOP, ALIGN_CENTER, VALIGN_TOP,
"\n" "\n"
"<C Tabs C>" "<C Change Tab C>"
); );
} }

View File

@ -16,12 +16,14 @@ static int selected_item = -1;
static bookkeeping_item_t* item_list; static bookkeeping_item_t* item_list;
static int item_max; static int item_max;
#define IS_FAVORITE (screen_mode == BOOKKEEPING_SCREEN_MODE_FAVORITE)
#define IS_HISTORY (screen_mode == BOOKKEEPING_SCREEN_MODE_HISTORY)
static void reset_selected(menu_t* menu) { static void reset_selected(menu_t* menu) {
selected_item = -1; selected_item = -1;
for(int i=0;i<item_max;i++) { for(int i=0;i<item_max;i++) {
if(item_list[selected_item].bookkeeping_type != HISTORY_TYPE_EMPTY) { if(item_list[selected_item].bookkeeping_type != BOOKKEEPING_TYPE_EMPTY) {
selected_item = i; selected_item = i;
break; break;
} }
@ -40,7 +42,7 @@ static void move_next() {
if(selected_item >= item_max) { if(selected_item >= item_max) {
selected_item = last; selected_item = last;
break; break;
} else if(item_list[selected_item].bookkeeping_type != HISTORY_TYPE_EMPTY) { } else if(item_list[selected_item].bookkeeping_type != BOOKKEEPING_TYPE_EMPTY) {
sound_play_effect(SFX_CURSOR); sound_play_effect(SFX_CURSOR);
break; break;
} }
@ -56,13 +58,15 @@ static void move_back() {
if(selected_item < 0) { if(selected_item < 0) {
selected_item = last; selected_item = last;
break; break;
} else if(item_list[selected_item].bookkeeping_type != HISTORY_TYPE_EMPTY) { } else if(item_list[selected_item].bookkeeping_type != BOOKKEEPING_TYPE_EMPTY) {
sound_play_effect(SFX_CURSOR); sound_play_effect(SFX_CURSOR);
break; break;
} }
} while (true); } while (true);
} }
static void process(menu_t* menu) { static void process(menu_t* menu) {
if(menu->actions.go_down) { if(menu->actions.go_down) {
move_next(); move_next();
@ -70,74 +74,85 @@ static void process(menu_t* menu) {
move_back(); move_back();
} else if(menu->actions.enter && selected_item != -1) { } else if(menu->actions.enter && selected_item != -1) {
if(screen_mode == BOOKKEEPING_SCREEN_MODE_FAVORITE) { if(IS_FAVORITE) {
menu->load.load_favorite = selected_item; menu->load.load_favorite = selected_item;
} else if(screen_mode == BOOKKEEPING_SCREEN_MODE_HISTORY) { } else if(IS_HISTORY) {
menu->load.load_history = selected_item; menu->load.load_history = selected_item;
} }
if(item_list[selected_item].bookkeeping_type == HISTORY_TYPE_DISK) { if(item_list[selected_item].bookkeeping_type == BOOKKEEPING_TYPE_DISK) {
menu->next_mode = MENU_MODE_LOAD_DISK; menu->next_mode = MENU_MODE_LOAD_DISK;
sound_play_effect(SFX_ENTER); sound_play_effect(SFX_ENTER);
} else if(item_list[selected_item].bookkeeping_type == HISTORY_TYPE_ROM) { } else if(item_list[selected_item].bookkeeping_type == BOOKKEEPING_TYPE_ROM) {
menu->next_mode = MENU_MODE_LOAD_ROM; menu->next_mode = MENU_MODE_LOAD_ROM;
sound_play_effect(SFX_ENTER); sound_play_effect(SFX_ENTER);
} }
} else if (menu->actions.previous_tab) { } else if (menu->actions.previous_tab) {
if(screen_mode == BOOKKEEPING_SCREEN_MODE_FAVORITE) { if(IS_FAVORITE) {
menu->next_mode = MENU_MODE_HISTORY; menu->next_mode = MENU_MODE_HISTORY;
} else if(screen_mode == BOOKKEEPING_SCREEN_MODE_HISTORY) { } else if(IS_HISTORY) {
menu->next_mode = MENU_MODE_BROWSER; menu->next_mode = MENU_MODE_BROWSER;
} }
} else if (menu->actions.next_tab) { } else if (menu->actions.next_tab) {
if(screen_mode == BOOKKEEPING_SCREEN_MODE_FAVORITE) { if(IS_FAVORITE) {
menu->next_mode = MENU_MODE_BROWSER; menu->next_mode = MENU_MODE_BROWSER;
} else if(screen_mode == BOOKKEEPING_SCREEN_MODE_HISTORY) { } else if(IS_HISTORY) {
menu->next_mode = MENU_MODE_FAVORITE; menu->next_mode = MENU_MODE_FAVORITE;
} }
}else if(screen_mode == BOOKKEEPING_SCREEN_MODE_FAVORITE && menu->actions.options && selected_item != -1) { }else if(IS_FAVORITE && menu->actions.options && selected_item != -1) {
//history_favorite_remove(&menu->history, selected_item); bookkeeping_favorite_remove(&menu->history, selected_item);
reset_selected(menu); reset_selected(menu);
sound_play_effect(SFX_SETTING); sound_play_effect(SFX_SETTING);
} }
} }
static void draw_favorites(menu_t *menu, surface_t *display) { static void draw_list(menu_t *menu, surface_t *display) {
float y = VISIBLE_AREA_Y0;
float x = 10 + VISIBLE_AREA_X0;
if(selected_item != -1) { if(selected_item != -1) {
float highlight_y = y + (selected_item * 18 * 2); float highlight_y = VISIBLE_AREA_Y0 + TEXT_MARGIN_VERTICAL + TEXT_OFFSET_VERTICAL + (selected_item * 20 * 2);
ui_components_box_draw( ui_components_box_draw(
VISIBLE_AREA_X0, VISIBLE_AREA_X0,
highlight_y, highlight_y,
VISIBLE_AREA_X0 + FILE_LIST_HIGHLIGHT_WIDTH, VISIBLE_AREA_X0 + FILE_LIST_HIGHLIGHT_WIDTH,
highlight_y + 36, highlight_y + 40,
FILE_LIST_HIGHLIGHT_COLOR FILE_LIST_HIGHLIGHT_COLOR
); );
} }
for(int i=0;i < FAVORITES_COUNT; i++) {
char buffer[1024];
buffer[0] = 0;
for(int i=0;i < item_max; i++) {
if(path_has_value(item_list[i].primary_path)) { if(path_has_value(item_list[i].primary_path)) {
ui_components_main_text_draw_location(x, y, "%d : %s",(i+1), path_last_get(item_list[i].primary_path)); sprintf(buffer, "%s%d : %s\n",buffer ,(i+1), path_last_get(item_list[i].primary_path));
} else { } else {
ui_components_main_text_draw_location(x, y, "%d :", (i+1)); sprintf(buffer, "%s%d : \n",buffer ,(i+1));
} }
y += 16;
if(path_has_value(item_list[i].secondary_path)) { if(path_has_value(item_list[i].secondary_path)) {
ui_components_main_text_draw_location(x, y," %s", path_last_get(item_list[i].secondary_path)); sprintf(buffer, "%s %s\n", buffer, path_last_get(item_list[i].secondary_path));
} else {
sprintf(buffer, "%s\n", buffer);
} }
y += 20;
} }
if(screen_mode == BOOKKEEPING_SCREEN_MODE_FAVORITE) { int nbytes = strlen(buffer);
ui_compontents_tabs_common_draw(2); rdpq_text_printn(
} else if(screen_mode == BOOKKEEPING_SCREEN_MODE_HISTORY) { &(rdpq_textparms_t) {
ui_compontents_tabs_common_draw(1); .width = VISIBLE_AREA_WIDTH - (TEXT_MARGIN_HORIZONTAL * 2),
} .height = LAYOUT_ACTIONS_SEPARATOR_Y - OVERSCAN_HEIGHT - (TEXT_MARGIN_VERTICAL * 2),
.align = ALIGN_LEFT,
.valign = VALIGN_TOP,
.wrap = WRAP_ELLIPSES,
.line_spacing = TEXT_OFFSET_VERTICAL,
},
FNT_DEFAULT,
VISIBLE_AREA_X0 + TEXT_MARGIN_HORIZONTAL,
VISIBLE_AREA_Y0 + TEXT_MARGIN_VERTICAL + TEXT_OFFSET_VERTICAL,
buffer,
nbytes
);
} }
static void draw(menu_t *menu, surface_t *display) { static void draw(menu_t *menu, surface_t *display) {
@ -147,7 +162,13 @@ static void draw(menu_t *menu, surface_t *display) {
ui_components_layout_draw(); ui_components_layout_draw();
draw_favorites(menu, display); if(IS_FAVORITE) {
ui_compontents_tabs_common_draw(2);
} else if(IS_HISTORY) {
ui_compontents_tabs_common_draw(1);
}
draw_list(menu, display);
if(selected_item != -1) { if(selected_item != -1) {
ui_components_actions_bar_text_draw( ui_components_actions_bar_text_draw(
@ -155,7 +176,7 @@ static void draw(menu_t *menu, surface_t *display) {
"A: Load Game" "A: Load Game"
); );
if(screen_mode == BOOKKEEPING_SCREEN_MODE_FAVORITE) { if(IS_FAVORITE && selected_item != -1) {
ui_components_actions_bar_text_draw( ui_components_actions_bar_text_draw(
ALIGN_RIGHT, VALIGN_TOP, ALIGN_RIGHT, VALIGN_TOP,
"R: Remove Favorite" "R: Remove Favorite"
@ -163,6 +184,12 @@ static void draw(menu_t *menu, surface_t *display) {
} }
} }
ui_components_actions_bar_text_draw(
ALIGN_CENTER, VALIGN_TOP,
"\n"
"<C Change Tab C>"
);
rdpq_detach_show(); rdpq_detach_show();
} }

View File

@ -139,7 +139,7 @@ static void load (menu_t *menu) {
return; return;
} }
bookkeeping_history_add(&menu->history, menu->load.disk_path, menu->load.rom_path, HISTORY_TYPE_DISK); bookkeeping_history_add(&menu->history, menu->load.disk_path, menu->load.rom_path, BOOKKEEPING_TYPE_DISK);
menu->next_mode = MENU_MODE_BOOT; menu->next_mode = MENU_MODE_BOOT;
if (load_disk_with_rom) { if (load_disk_with_rom) {

View File

@ -159,7 +159,7 @@ static void set_autoload_type (menu_t *menu, void *arg) {
} }
static void add_favorite (menu_t *menu, void *arg) { static void add_favorite (menu_t *menu, void *arg) {
bookkeeping_favorite_add(&menu->history, menu->load.rom_path, NULL, HISTORY_TYPE_ROM); bookkeeping_favorite_add(&menu->history, menu->load.rom_path, NULL, BOOKKEEPING_TYPE_ROM);
} }
static component_context_menu_t set_cic_type_context_menu = { .list = { static component_context_menu_t set_cic_type_context_menu = { .list = {
@ -256,7 +256,7 @@ static void draw (menu_t *menu, surface_t *d) {
"\n" "\n"
"\n" "\n"
"\n" "\n"
"Description:\n None.\n\n\n\n\n\n\n\n" "Description:\n None.\n\n\n\n\n\n\n"
"Expansion PAK: %s\n" "Expansion PAK: %s\n"
"TV type: %s\n" "TV type: %s\n"
"CIC: %s\n" "CIC: %s\n"
@ -341,7 +341,7 @@ static void load (menu_t *menu) {
return; return;
} }
bookkeeping_history_add(&menu->history, menu->load.rom_path, NULL, HISTORY_TYPE_ROM); bookkeeping_history_add(&menu->history, menu->load.rom_path, NULL, BOOKKEEPING_TYPE_ROM);
menu->next_mode = MENU_MODE_BOOT; menu->next_mode = MENU_MODE_BOOT;