mirror of
https://github.com/holub/mame
synced 2025-05-01 20:27:02 +03:00
A better solution for sorting of the favorites list. (nw)
This commit is contained in:
parent
1d378e65d2
commit
60b2ccdb9f
@ -150,7 +150,6 @@ favorite_manager::favorite_manager(running_machine &machine, ui_options &moption
|
|||||||
: m_machine(machine)
|
: m_machine(machine)
|
||||||
, m_options(moptions)
|
, m_options(moptions)
|
||||||
{
|
{
|
||||||
m_current = -1;
|
|
||||||
parse_favorite();
|
parse_favorite();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +159,7 @@ favorite_manager::favorite_manager(running_machine &machine, ui_options &moption
|
|||||||
|
|
||||||
void favorite_manager::add_favorite_game(const game_driver *driver)
|
void favorite_manager::add_favorite_game(const game_driver *driver)
|
||||||
{
|
{
|
||||||
m_list.emplace_back(driver->name, driver->description, "", "", "", 0, "", driver, "", "", "", 1, "", "", "", true);
|
m_list.emplace(driver->description, ui_software_info{ driver->name, driver->description, "", "", "", 0, "", driver, "", "", "", 1, "", "", "", true });
|
||||||
save_favorite_games();
|
save_favorite_games();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,7 +169,7 @@ void favorite_manager::add_favorite_game(const game_driver *driver)
|
|||||||
|
|
||||||
void favorite_manager::add_favorite_game(ui_software_info &swinfo)
|
void favorite_manager::add_favorite_game(ui_software_info &swinfo)
|
||||||
{
|
{
|
||||||
m_list.push_back(swinfo);
|
m_list.emplace(swinfo.longname, swinfo);
|
||||||
save_favorite_games();
|
save_favorite_games();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,7 +228,7 @@ void favorite_manager::add_favorite_game()
|
|||||||
tmpmatches.devicetype = strensure(image.image_type_name());
|
tmpmatches.devicetype = strensure(image.image_type_name());
|
||||||
tmpmatches.available = true;
|
tmpmatches.available = true;
|
||||||
software_avail = true;
|
software_avail = true;
|
||||||
m_list.push_back(tmpmatches);
|
m_list.emplace(tmpmatches.longname, tmpmatches);
|
||||||
save_favorite_games();
|
save_favorite_games();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -244,7 +243,13 @@ void favorite_manager::add_favorite_game()
|
|||||||
|
|
||||||
void favorite_manager::remove_favorite_game(ui_software_info &swinfo)
|
void favorite_manager::remove_favorite_game(ui_software_info &swinfo)
|
||||||
{
|
{
|
||||||
m_list.erase(std::remove(m_list.begin(), m_list.end(), swinfo), m_list.end());
|
for (auto e = m_list.begin(); e != m_list.end(); ++e)
|
||||||
|
if (e->second == swinfo)
|
||||||
|
{
|
||||||
|
m_list.erase(e);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
m_current = m_list.begin();
|
||||||
save_favorite_games();
|
save_favorite_games();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,7 +259,8 @@ void favorite_manager::remove_favorite_game(ui_software_info &swinfo)
|
|||||||
|
|
||||||
void favorite_manager::remove_favorite_game()
|
void favorite_manager::remove_favorite_game()
|
||||||
{
|
{
|
||||||
m_list.erase(m_list.begin() + m_current);
|
m_list.erase(m_current);
|
||||||
|
m_current = m_list.begin();
|
||||||
save_favorite_games();
|
save_favorite_games();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,9 +281,9 @@ bool favorite_manager::isgame_favorite()
|
|||||||
if (image.exists() && swinfo != nullptr)
|
if (image.exists() && swinfo != nullptr)
|
||||||
{
|
{
|
||||||
image_loaded = true;
|
image_loaded = true;
|
||||||
for (size_t current = 0; current < m_list.size(); current++)
|
for (auto current = m_list.begin(); current != m_list.end(); ++current)
|
||||||
if (m_list[current].shortname == swinfo->shortname() &&
|
if (current->second.shortname == swinfo->shortname() &&
|
||||||
m_list[current].listname == image.software_list_name())
|
current->second.listname == image.software_list_name())
|
||||||
{
|
{
|
||||||
m_current = current;
|
m_current = current;
|
||||||
return true;
|
return true;
|
||||||
@ -288,7 +294,7 @@ bool favorite_manager::isgame_favorite()
|
|||||||
if (!image_loaded)
|
if (!image_loaded)
|
||||||
return isgame_favorite(&machine().system());
|
return isgame_favorite(&machine().system());
|
||||||
|
|
||||||
m_current = -1;
|
m_current = m_list.begin();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,14 +304,12 @@ bool favorite_manager::isgame_favorite()
|
|||||||
|
|
||||||
bool favorite_manager::isgame_favorite(const game_driver *driver)
|
bool favorite_manager::isgame_favorite(const game_driver *driver)
|
||||||
{
|
{
|
||||||
for (size_t x = 0; x < m_list.size(); x++)
|
for (auto current = m_list.begin(); current != m_list.end(); ++current)
|
||||||
if (m_list[x].driver == driver && m_list[x].shortname == driver->name)
|
if (current->second.driver == driver && current->second.shortname == driver->name)
|
||||||
{
|
{
|
||||||
m_current = x;
|
m_current = current;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_current = -1;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -315,14 +319,12 @@ bool favorite_manager::isgame_favorite(const game_driver *driver)
|
|||||||
|
|
||||||
bool favorite_manager::isgame_favorite(ui_software_info const &swinfo)
|
bool favorite_manager::isgame_favorite(ui_software_info const &swinfo)
|
||||||
{
|
{
|
||||||
for (size_t x = 0; x < m_list.size(); x++)
|
for (auto current = m_list.begin(); current != m_list.end(); ++current)
|
||||||
if (m_list[x] == swinfo)
|
if (current->second == swinfo)
|
||||||
{
|
{
|
||||||
m_current = x;
|
m_current = current;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_current = -1;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -378,7 +380,7 @@ void favorite_manager::parse_favorite()
|
|||||||
tmpmatches.devicetype = chartrimcarriage(readbuf);
|
tmpmatches.devicetype = chartrimcarriage(readbuf);
|
||||||
file.gets(readbuf, 1024);
|
file.gets(readbuf, 1024);
|
||||||
tmpmatches.available = atoi(readbuf);
|
tmpmatches.available = atoi(readbuf);
|
||||||
m_list.push_back(tmpmatches);
|
m_list.emplace(tmpmatches.longname, tmpmatches);
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
@ -404,8 +406,9 @@ void favorite_manager::save_favorite_games()
|
|||||||
// generate the favorite INI
|
// generate the favorite INI
|
||||||
std::ostringstream text;
|
std::ostringstream text;
|
||||||
text << "[ROOT_FOLDER]\n[Favorite]\n\n";
|
text << "[ROOT_FOLDER]\n[Favorite]\n\n";
|
||||||
for (auto & elem : m_list)
|
for (auto & e : m_list)
|
||||||
{
|
{
|
||||||
|
auto elem = e.second;
|
||||||
text << elem.shortname << '\n';
|
text << elem.shortname << '\n';
|
||||||
text << elem.longname << '\n';
|
text << elem.longname << '\n';
|
||||||
text << elem.parentname << '\n';
|
text << elem.parentname << '\n';
|
||||||
|
@ -84,7 +84,7 @@ public:
|
|||||||
favorite_manager(running_machine &machine, ui_options &moptions);
|
favorite_manager(running_machine &machine, ui_options &moptions);
|
||||||
|
|
||||||
// favorite indices
|
// favorite indices
|
||||||
std::vector<ui_software_info> m_list;
|
std::multimap<std::string, ui_software_info> m_list;
|
||||||
|
|
||||||
// getters
|
// getters
|
||||||
running_machine &machine() const { return m_machine; }
|
running_machine &machine() const { return m_machine; }
|
||||||
@ -110,7 +110,7 @@ private:
|
|||||||
const char *favorite_filename = "favorites.ini";
|
const char *favorite_filename = "favorites.ini";
|
||||||
|
|
||||||
// current
|
// current
|
||||||
int m_current;
|
std::multimap<std::string, ui_software_info>::iterator m_current;
|
||||||
|
|
||||||
// parse file ui_favorite
|
// parse file ui_favorite
|
||||||
void parse_favorite();
|
void parse_favorite();
|
||||||
|
@ -691,7 +691,7 @@ menu_machine_configure::menu_machine_configure(mame_ui_manager &mui, render_cont
|
|||||||
|
|
||||||
menu_machine_configure::~menu_machine_configure()
|
menu_machine_configure::~menu_machine_configure()
|
||||||
{
|
{
|
||||||
if (m_fav_reset && main_filters::actual == FILTER_FAVORITE)
|
if (m_fav_reset)
|
||||||
reset_topmost(reset_options::SELECT_FIRST);
|
reset_topmost(reset_options::SELECT_FIRST);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -729,7 +729,12 @@ void menu_machine_configure::handle()
|
|||||||
break;
|
break;
|
||||||
case DELFAV:
|
case DELFAV:
|
||||||
mame_machine_manager::instance()->favorite().remove_favorite_game();
|
mame_machine_manager::instance()->favorite().remove_favorite_game();
|
||||||
|
if (main_filters::actual == FILTER_FAVORITE)
|
||||||
|
{
|
||||||
m_fav_reset = true;
|
m_fav_reset = true;
|
||||||
|
menu::stack_pop();
|
||||||
|
}
|
||||||
|
else
|
||||||
reset(reset_options::REMEMBER_POSITION);
|
reset(reset_options::REMEMBER_POSITION);
|
||||||
break;
|
break;
|
||||||
case CONTROLLER:
|
case CONTROLLER:
|
||||||
|
@ -555,37 +555,31 @@ void menu_select_game::populate()
|
|||||||
m_search[0] = '\0';
|
m_search[0] = '\0';
|
||||||
int curitem = 0;
|
int curitem = 0;
|
||||||
|
|
||||||
// sort favorites list by longname (description)
|
|
||||||
std::multimap<std::string, ui_software_info*> sorted;
|
|
||||||
for (auto & e : mame_machine_manager::instance()->favorite().m_list)
|
|
||||||
sorted.emplace(e.longname, &e);
|
|
||||||
|
|
||||||
// iterate over entries
|
// iterate over entries
|
||||||
for (auto & favmap : sorted)
|
for (auto & favmap : mame_machine_manager::instance()->favorite().m_list)
|
||||||
{
|
{
|
||||||
auto &mfavorite = *favmap.second;
|
|
||||||
auto flags = flags_ui | FLAG_UI_FAVORITE;
|
auto flags = flags_ui | FLAG_UI_FAVORITE;
|
||||||
if (mfavorite.startempty == 1)
|
if (favmap.second.startempty == 1)
|
||||||
{
|
{
|
||||||
if (old_item_selected == -1 && mfavorite.shortname == reselect_last::driver)
|
if (old_item_selected == -1 && favmap.second.shortname == reselect_last::driver)
|
||||||
old_item_selected = curitem;
|
old_item_selected = curitem;
|
||||||
|
|
||||||
bool cloneof = strcmp(mfavorite.driver->parent, "0");
|
bool cloneof = strcmp(favmap.second.driver->parent, "0");
|
||||||
if (cloneof)
|
if (cloneof)
|
||||||
{
|
{
|
||||||
int cx = driver_list::find(mfavorite.driver->parent);
|
int cx = driver_list::find(favmap.second.driver->parent);
|
||||||
if (cx != -1 && ((driver_list::driver(cx).flags & MACHINE_IS_BIOS_ROOT) != 0))
|
if (cx != -1 && ((driver_list::driver(cx).flags & MACHINE_IS_BIOS_ROOT) != 0))
|
||||||
cloneof = false;
|
cloneof = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
item_append(mfavorite.longname, "", (cloneof) ? (flags | FLAG_INVERT) : flags, (void *)&mfavorite);
|
item_append(favmap.second.longname, "", (cloneof) ? (flags | FLAG_INVERT) : flags, (void *)&favmap.second);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (old_item_selected == -1 && mfavorite.shortname == reselect_last::driver)
|
if (old_item_selected == -1 && favmap.second.shortname == reselect_last::driver)
|
||||||
old_item_selected = curitem;
|
old_item_selected = curitem;
|
||||||
item_append(mfavorite.longname, mfavorite.devicetype,
|
item_append(favmap.second.longname, favmap.second.devicetype,
|
||||||
mfavorite.parentname.empty() ? flags : (FLAG_INVERT | flags), (void *)&mfavorite);
|
favmap.second.parentname.empty() ? flags : (FLAG_INVERT | flags), (void *)&favmap.second);
|
||||||
}
|
}
|
||||||
curitem++;
|
curitem++;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user