Skip to content

Commit

Permalink
【Frontend】Got rid of the duplicated game list
Browse files Browse the repository at this point in the history
  • Loading branch information
skylersaleh committed Dec 10, 2023
1 parent db40b7b commit 225d593
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,7 @@ typedef struct {
se_keybind_state_t key;
se_controller_state_t controller;
se_game_info_t recently_loaded_games[SE_NUM_RECENT_PATHS];
se_game_info_t sorted_recently_loaded_games[SE_NUM_RECENT_PATHS];
int num_recently_loaded_games;
int sorted_recently_loaded_games[SE_NUM_RECENT_PATHS];
int recent_games_sort_type;
persistent_settings_t settings;
persistent_settings_t last_saved_settings;
Expand Down Expand Up @@ -1312,24 +1311,27 @@ bool se_load_bios_file(const char* name, const char* base_path, const char* file
free(bios_data);
return loaded_bios;
}
static int game_info_comparator(const void* a, const void* b){
const se_game_info_t* ga = (const se_game_info_t*)a;
const se_game_info_t* gb = (const se_game_info_t*)b;
return strcmp(ga->path,gb->path);
static int se_game_info_alpha_comparator(const void* a, const void* b){
const int ga = *(int*)a;
const int gb = *(int*)b;
return strcmp(gui_state.recently_loaded_games[ga].path,gui_state.recently_loaded_games[gb].path);
}
static int se_game_info_rev_alpha_comparator(const void* a, const void* b){
const int ga = *(int*)a;
const int gb = *(int*)b;
return strcmp(gui_state.recently_loaded_games[gb].path,gui_state.recently_loaded_games[ga].path);
}
static void se_sort_recent_games_list(){
gui_state.num_recently_loaded_games=32;
int size = 0;
for(int i=0;i<SE_NUM_RECENT_PATHS;++i){
memset(gui_state.sorted_recently_loaded_games[i].path,0,SB_FILE_PATH_SIZE);
if(gui_state.recently_loaded_games[i].path[0]==0){gui_state.num_recently_loaded_games=i;break;}
}
for(int i=0;i<gui_state.num_recently_loaded_games;++i){
strncpy(gui_state.sorted_recently_loaded_games[i].path,gui_state.recently_loaded_games[i].path,SB_FILE_PATH_SIZE);
}
qsort(gui_state.sorted_recently_loaded_games,gui_state.num_recently_loaded_games,sizeof(se_game_info_t),game_info_comparator);
for (int i=0;i<gui_state.num_recently_loaded_games;++i){
printf("Sorted recent game %d: %s\n",i,gui_state.sorted_recently_loaded_games[i].path);
if(gui_state.recently_loaded_games[i].path[0]=='\0')gui_state.sorted_recently_loaded_games[i]=-1;
else{
gui_state.sorted_recently_loaded_games[i]=i;
size++;
}
}
if(gui_state.recent_games_sort_type==SE_SORT_ALPHA_ASC)qsort(gui_state.sorted_recently_loaded_games,size,sizeof(int),se_game_info_alpha_comparator);
else if(gui_state.recent_games_sort_type==SE_SORT_ALPHA_DESC)qsort(gui_state.sorted_recently_loaded_games,size,sizeof(int),se_game_info_rev_alpha_comparator);
}
static void se_save_recent_games_list(){
gui_state_t* gui = &gui_state;
Expand Down Expand Up @@ -4604,21 +4606,21 @@ void se_load_rom_overlay(bool visible){
igSameLine(0,5);

const char* icon=ICON_FK_SORT;
se_game_info_t* base = gui_state.recently_loaded_games;
int sign = 1;
switch(gui_state.recent_games_sort_type){
case SE_NO_SORT: icon=ICON_FK_LONG_ARROW_DOWN ICON_FK_CLOCK_O ;break;
case SE_SORT_ALPHA_ASC: icon=ICON_FK_SORT_ALPHA_ASC;base=gui_state.sorted_recently_loaded_games;break;
case SE_SORT_ALPHA_DESC: icon=ICON_FK_SORT_ALPHA_DESC;base=&gui_state.sorted_recently_loaded_games[gui_state.num_recently_loaded_games-1];sign=-1;break;
case SE_NO_SORT: icon=ICON_FK_LONG_ARROW_DOWN ICON_FK_CLOCK_O ;break;
case SE_SORT_ALPHA_ASC: icon=ICON_FK_SORT_ALPHA_ASC;break;
case SE_SORT_ALPHA_DESC:icon=ICON_FK_SORT_ALPHA_DESC;break;
}
if(se_button(icon,(ImVec2){50,0})){
gui_state.recent_games_sort_type++;
if(gui_state.recent_games_sort_type>SE_SORT_ALPHA_DESC)gui_state.recent_games_sort_type=SE_NO_SORT;
se_sort_recent_games_list();
}
igSeparator();
int num_entries=0;
for(int i=0;i<SE_NUM_RECENT_PATHS;++i){
se_game_info_t *info = base+i*sign;
if(gui_state.sorted_recently_loaded_games[i]==-1)break;
se_game_info_t *info = gui_state.recently_loaded_games+gui_state.sorted_recently_loaded_games[i];
if(strcmp(info->path,"")==0)break;
igPushIDInt(i);
const char* base, *file_name, *ext;
Expand Down

0 comments on commit 225d593

Please sign in to comment.