mirror of
https://github.com/Polprzewodnikowy/N64FlashcartMenu.git
synced 2024-12-25 17:51:50 +01:00
Added favorite removing
Users can remove favorites via the menu
This commit is contained in:
parent
1fecd26f0b
commit
05b17e842d
@ -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, ""));
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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){
|
||||
path_free(item->primary_path);
|
||||
|
||||
if(leave_null) {
|
||||
item->primary_path = NULL;
|
||||
} else {
|
||||
item->primary_path = path_create("");
|
||||
}
|
||||
}
|
||||
if(item->secondary_path != NULL){
|
||||
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){
|
||||
bookkeeping_clear_item(destination);
|
||||
bookkeeping_clear_item(destination, true);
|
||||
|
||||
destination->primary_path = path_clone(source->primary_path);
|
||||
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) {
|
||||
// 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(list[0].bookkeeping_type != HISTORY_TYPE_EMPTY) {
|
||||
if(list[0].bookkeeping_type != BOOKKEEPING_TYPE_EMPTY) {
|
||||
int found_at = -1;
|
||||
for(int i=1; i < count; i++) {
|
||||
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_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);
|
||||
}
|
||||
}
|
@ -14,9 +14,9 @@
|
||||
#define HISTORY_COUNT 5
|
||||
|
||||
typedef enum {
|
||||
HISTORY_TYPE_EMPTY,
|
||||
HISTORY_TYPE_ROM,
|
||||
HISTORY_TYPE_DISK,
|
||||
BOOKKEEPING_TYPE_EMPTY,
|
||||
BOOKKEEPING_TYPE_ROM,
|
||||
BOOKKEEPING_TYPE_DISK,
|
||||
} bookkeeping_item_types_t;
|
||||
|
||||
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_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
|
@ -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 );
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -409,14 +409,14 @@ static void draw (menu_t *menu, surface_t *d) {
|
||||
ui_components_actions_bar_text_draw(
|
||||
ALIGN_CENTER, VALIGN_TOP,
|
||||
"%s" //ctime includes a newline
|
||||
"<C Change Tabs C>",
|
||||
"<C Change Tab C>",
|
||||
ctime(&menu->current_time)
|
||||
);
|
||||
} else {
|
||||
ui_components_actions_bar_text_draw(
|
||||
ALIGN_CENTER, VALIGN_TOP,
|
||||
"\n"
|
||||
"<C Tabs C>"
|
||||
"<C Change Tab C>"
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -16,12 +16,14 @@ static int selected_item = -1;
|
||||
static bookkeeping_item_t* item_list;
|
||||
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) {
|
||||
selected_item = -1;
|
||||
|
||||
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;
|
||||
break;
|
||||
}
|
||||
@ -40,7 +42,7 @@ static void move_next() {
|
||||
if(selected_item >= item_max) {
|
||||
selected_item = last;
|
||||
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);
|
||||
break;
|
||||
}
|
||||
@ -56,13 +58,15 @@ static void move_back() {
|
||||
if(selected_item < 0) {
|
||||
selected_item = last;
|
||||
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);
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void process(menu_t* menu) {
|
||||
if(menu->actions.go_down) {
|
||||
move_next();
|
||||
@ -70,74 +74,85 @@ static void process(menu_t* menu) {
|
||||
move_back();
|
||||
} else if(menu->actions.enter && selected_item != -1) {
|
||||
|
||||
if(screen_mode == BOOKKEEPING_SCREEN_MODE_FAVORITE) {
|
||||
if(IS_FAVORITE) {
|
||||
menu->load.load_favorite = selected_item;
|
||||
} else if(screen_mode == BOOKKEEPING_SCREEN_MODE_HISTORY) {
|
||||
} else if(IS_HISTORY) {
|
||||
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;
|
||||
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;
|
||||
sound_play_effect(SFX_ENTER);
|
||||
}
|
||||
} else if (menu->actions.previous_tab) {
|
||||
if(screen_mode == BOOKKEEPING_SCREEN_MODE_FAVORITE) {
|
||||
if(IS_FAVORITE) {
|
||||
menu->next_mode = MENU_MODE_HISTORY;
|
||||
} else if(screen_mode == BOOKKEEPING_SCREEN_MODE_HISTORY) {
|
||||
} else if(IS_HISTORY) {
|
||||
menu->next_mode = MENU_MODE_BROWSER;
|
||||
}
|
||||
} else if (menu->actions.next_tab) {
|
||||
if(screen_mode == BOOKKEEPING_SCREEN_MODE_FAVORITE) {
|
||||
if(IS_FAVORITE) {
|
||||
menu->next_mode = MENU_MODE_BROWSER;
|
||||
} else if(screen_mode == BOOKKEEPING_SCREEN_MODE_HISTORY) {
|
||||
} else if(IS_HISTORY) {
|
||||
menu->next_mode = MENU_MODE_FAVORITE;
|
||||
}
|
||||
}else if(screen_mode == BOOKKEEPING_SCREEN_MODE_FAVORITE && menu->actions.options && selected_item != -1) {
|
||||
//history_favorite_remove(&menu->history, selected_item);
|
||||
}else if(IS_FAVORITE && menu->actions.options && selected_item != -1) {
|
||||
bookkeeping_favorite_remove(&menu->history, selected_item);
|
||||
reset_selected(menu);
|
||||
sound_play_effect(SFX_SETTING);
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_favorites(menu_t *menu, surface_t *display) {
|
||||
|
||||
float y = VISIBLE_AREA_Y0;
|
||||
float x = 10 + VISIBLE_AREA_X0;
|
||||
|
||||
static void draw_list(menu_t *menu, surface_t *display) {
|
||||
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(
|
||||
VISIBLE_AREA_X0,
|
||||
highlight_y,
|
||||
VISIBLE_AREA_X0 + FILE_LIST_HIGHLIGHT_WIDTH,
|
||||
highlight_y + 36,
|
||||
highlight_y + 40,
|
||||
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)) {
|
||||
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 {
|
||||
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)) {
|
||||
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) {
|
||||
ui_compontents_tabs_common_draw(2);
|
||||
} else if(screen_mode == BOOKKEEPING_SCREEN_MODE_HISTORY) {
|
||||
ui_compontents_tabs_common_draw(1);
|
||||
}
|
||||
int nbytes = strlen(buffer);
|
||||
rdpq_text_printn(
|
||||
&(rdpq_textparms_t) {
|
||||
.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) {
|
||||
@ -147,7 +162,13 @@ static void draw(menu_t *menu, surface_t *display) {
|
||||
|
||||
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) {
|
||||
ui_components_actions_bar_text_draw(
|
||||
@ -155,7 +176,7 @@ static void draw(menu_t *menu, surface_t *display) {
|
||||
"A: Load Game"
|
||||
);
|
||||
|
||||
if(screen_mode == BOOKKEEPING_SCREEN_MODE_FAVORITE) {
|
||||
if(IS_FAVORITE && selected_item != -1) {
|
||||
ui_components_actions_bar_text_draw(
|
||||
ALIGN_RIGHT, VALIGN_TOP,
|
||||
"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();
|
||||
}
|
||||
|
||||
|
@ -139,7 +139,7 @@ static void load (menu_t *menu) {
|
||||
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;
|
||||
|
||||
if (load_disk_with_rom) {
|
||||
|
@ -159,7 +159,7 @@ static void set_autoload_type (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 = {
|
||||
@ -256,7 +256,7 @@ static void draw (menu_t *menu, surface_t *d) {
|
||||
"\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"
|
||||
"TV type: %s\n"
|
||||
"CIC: %s\n"
|
||||
@ -341,7 +341,7 @@ static void load (menu_t *menu) {
|
||||
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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user