make filter names localisable, fix keyboard navigation of software

filter box, encapsulate a couple more things in selmenu and friends, get
rid of hacks in selector tying it to implementation details of other
menus

(nw) this is an intermediate step - I'm going to turn the filters into
polymorphic objects that will be more manageable and not require so much
copy/pasting when updating APIs
This commit is contained in:
Vas Crabb 2017-08-08 02:21:37 +10:00
parent f758c3abd5
commit 42ed4bda50
15 changed files with 722 additions and 621 deletions

View File

@ -9,8 +9,9 @@
*********************************************************************/ *********************************************************************/
#include "emu.h" #include "emu.h"
#include "ui/ui.h"
#include "ui/custmenu.h" #include "ui/custmenu.h"
#include "ui/ui.h"
#include "ui/selector.h" #include "ui/selector.h"
#include "ui/inifile.h" #include "ui/inifile.h"
@ -18,6 +19,7 @@
namespace ui { namespace ui {
/************************************************** /**************************************************
MENU CUSTOM FILTER MENU CUSTOM FILTER
**************************************************/ **************************************************/
@ -52,61 +54,70 @@ void menu_custom_filter::handle()
{ {
switch ((uintptr_t)menu_event->itemref) switch ((uintptr_t)menu_event->itemref)
{ {
case MAIN_FILTER: case MAIN_FILTER:
if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT) if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT)
{ {
(menu_event->iptkey == IPT_UI_RIGHT) ? custfltr::main++ : custfltr::main--; (menu_event->iptkey == IPT_UI_RIGHT) ? custfltr::main++ : custfltr::main--;
changed = true; changed = true;
} }
break; break;
case ADD_FILTER: case ADD_FILTER:
if (menu_event->iptkey == IPT_UI_SELECT) if (menu_event->iptkey == IPT_UI_SELECT)
{ {
custfltr::numother++; custfltr::numother++;
custfltr::other[custfltr::numother] = FILTER_UNAVAILABLE + 1; custfltr::other[custfltr::numother] = machine_filter::UNAVAILABLE;
m_added = true; ++custfltr::other[custfltr::numother];
} m_added = true;
break; }
break;
case REMOVE_FILTER: case REMOVE_FILTER:
if (menu_event->iptkey == IPT_UI_SELECT) if (menu_event->iptkey == IPT_UI_SELECT)
{ {
custfltr::other[custfltr::numother] = FILTER_UNAVAILABLE + 1; custfltr::other[custfltr::numother] = machine_filter::UNAVAILABLE;
custfltr::numother--; ++custfltr::other[custfltr::numother];
changed = true; custfltr::numother--;
} changed = true;
break; }
break;
} }
if ((uintptr_t)menu_event->itemref >= OTHER_FILTER && (uintptr_t)menu_event->itemref < OTHER_FILTER + MAX_CUST_FILTER) if ((uintptr_t)menu_event->itemref >= OTHER_FILTER && (uintptr_t)menu_event->itemref < OTHER_FILTER + MAX_CUST_FILTER)
{ {
int pos = (int)((uintptr_t)menu_event->itemref - OTHER_FILTER); int pos = (int)((uintptr_t)menu_event->itemref - OTHER_FILTER);
if (menu_event->iptkey == IPT_UI_LEFT && custfltr::other[pos] > FILTER_UNAVAILABLE + 1) if (menu_event->iptkey == IPT_UI_LEFT && custfltr::other[pos] > machine_filter::UNAVAILABLE + 1)
{ {
custfltr::other[pos]--; custfltr::other[pos]--;
for ( ; custfltr::other[pos] > FILTER_UNAVAILABLE && (custfltr::other[pos] == FILTER_CATEGORY for ( ; custfltr::other[pos] > machine_filter::UNAVAILABLE && (custfltr::other[pos] == machine_filter::CATEGORY
|| custfltr::other[pos] == FILTER_FAVORITE); custfltr::other[pos]--) { }; || custfltr::other[pos] == machine_filter::FAVORITE); custfltr::other[pos]--) { };
changed = true; changed = true;
} }
else if (menu_event->iptkey == IPT_UI_RIGHT && custfltr::other[pos] < FILTER_LAST - 1) else if (menu_event->iptkey == IPT_UI_RIGHT && custfltr::other[pos] < machine_filter::LAST - 1)
{ {
custfltr::other[pos]++; custfltr::other[pos]++;
for ( ; custfltr::other[pos] < FILTER_LAST && (custfltr::other[pos] == FILTER_CATEGORY for ( ; custfltr::other[pos] < machine_filter::LAST && (custfltr::other[pos] == machine_filter::CATEGORY
|| custfltr::other[pos] == FILTER_FAVORITE); custfltr::other[pos]++) { }; || custfltr::other[pos] == machine_filter::FAVORITE); custfltr::other[pos]++) { };
changed = true; changed = true;
} }
else if (menu_event->iptkey == IPT_UI_SELECT) else if (menu_event->iptkey == IPT_UI_SELECT)
{ {
size_t total = main_filters::length; std::vector<machine_filter::type> types;
std::vector<std::string> s_sel(total); std::vector<std::string> names;
for (size_t index = 0; index < total; ++index) types.reserve(machine_filter::COUNT);
if (index <= FILTER_UNAVAILABLE || index == FILTER_CATEGORY || index == FILTER_FAVORITE || index == FILTER_CUSTOM) names.reserve(machine_filter::COUNT);
s_sel[index] = "_skip_"; int sel(-1);
else for (machine_filter::type index = machine_filter::FIRST; index < machine_filter::COUNT; ++index)
s_sel[index] = main_filters::text[index]; {
if ((index > machine_filter::UNAVAILABLE) && (index != machine_filter::CATEGORY) && (index != machine_filter::FAVORITE) && (index != machine_filter::CUSTOM))
menu::stack_push<menu_selector>(ui(), container(), s_sel, custfltr::other[pos]); {
if (custfltr::other[pos] == index)
sel = types.size();
types.emplace_back(index);
names.emplace_back(machine_filter::display_name(index));
}
}
menu::stack_push<menu_selector>(ui(), container(), std::move(names), sel, [this, pos, t = std::move(types)] (int selection) { custfltr::other[pos] = t[selection]; reset(reset_options::REMEMBER_REF); });
} }
} }
else if ((uintptr_t)menu_event->itemref >= YEAR_FILTER && (uintptr_t)menu_event->itemref < YEAR_FILTER + MAX_CUST_FILTER) else if ((uintptr_t)menu_event->itemref >= YEAR_FILTER && (uintptr_t)menu_event->itemref < YEAR_FILTER + MAX_CUST_FILTER)
@ -123,7 +134,9 @@ void menu_custom_filter::handle()
changed = true; changed = true;
} }
else if (menu_event->iptkey == IPT_UI_SELECT) else if (menu_event->iptkey == IPT_UI_SELECT)
menu::stack_push<menu_selector>(ui(), container(), c_year::ui, custfltr::year[pos]); {
menu::stack_push<menu_selector>(ui(), container(), std::vector<std::string>(c_year::ui), custfltr::year[pos], [this, pos] (int selection) { custfltr::year[pos] = selection; reset(reset_options::REMEMBER_REF); });
}
} }
else if ((uintptr_t)menu_event->itemref >= MNFCT_FILTER && (uintptr_t)menu_event->itemref < MNFCT_FILTER + MAX_CUST_FILTER) else if ((uintptr_t)menu_event->itemref >= MNFCT_FILTER && (uintptr_t)menu_event->itemref < MNFCT_FILTER + MAX_CUST_FILTER)
{ {
@ -139,7 +152,9 @@ void menu_custom_filter::handle()
changed = true; changed = true;
} }
else if (menu_event->iptkey == IPT_UI_SELECT) else if (menu_event->iptkey == IPT_UI_SELECT)
menu::stack_push<menu_selector>(ui(), container(), c_mnfct::ui, custfltr::mnfct[pos]); {
menu::stack_push<menu_selector>(ui(), container(), std::vector<std::string>(c_mnfct::ui), custfltr::mnfct[pos], [this, pos] (int selection) { custfltr::mnfct[pos] = selection; reset(reset_options::REMEMBER_REF); });
}
} }
} }
@ -155,8 +170,8 @@ void menu_custom_filter::handle()
void menu_custom_filter::populate(float &customtop, float &custombottom) void menu_custom_filter::populate(float &customtop, float &custombottom)
{ {
// add main filter // add main filter
uint32_t arrow_flags = get_arrow_flags<uint16_t>(FILTER_ALL, FILTER_UNAVAILABLE, custfltr::main); uint32_t arrow_flags = get_arrow_flags<uint16_t>(machine_filter::ALL, machine_filter::UNAVAILABLE, custfltr::main);
item_append(_("Main filter"), main_filters::text[custfltr::main], arrow_flags, (void *)(uintptr_t)MAIN_FILTER); item_append(_("Main filter"), machine_filter::display_name(custfltr::main), arrow_flags, (void *)(uintptr_t)MAIN_FILTER);
// add other filters // add other filters
for (int x = 1; x <= custfltr::numother; x++) for (int x = 1; x <= custfltr::numother; x++)
@ -164,14 +179,14 @@ void menu_custom_filter::populate(float &customtop, float &custombottom)
item_append(menu_item_type::SEPARATOR); item_append(menu_item_type::SEPARATOR);
// add filter items // add filter items
arrow_flags = get_arrow_flags<uint16_t>(FILTER_UNAVAILABLE + 1, FILTER_LAST - 1, custfltr::other[x]); arrow_flags = get_arrow_flags<uint16_t>(machine_filter::UNAVAILABLE + 1, machine_filter::LAST - 1, custfltr::other[x]);
item_append(_("Other filter"), main_filters::text[custfltr::other[x]], arrow_flags, (void *)(uintptr_t)(OTHER_FILTER + x)); item_append(_("Other filter"), machine_filter::display_name(custfltr::other[x]), arrow_flags, (void *)(uintptr_t)(OTHER_FILTER + x));
if (m_added) if (m_added)
selected = item.size() - 2; selected = item.size() - 2;
// add manufacturer subitem // add manufacturer subitem
if (custfltr::other[x] == FILTER_MANUFACTURER && c_mnfct::ui.size() > 0) if (custfltr::other[x] == machine_filter::MANUFACTURER && c_mnfct::ui.size() > 0)
{ {
arrow_flags = get_arrow_flags<uint16_t>(0, c_mnfct::ui.size() - 1, custfltr::mnfct[x]); arrow_flags = get_arrow_flags<uint16_t>(0, c_mnfct::ui.size() - 1, custfltr::mnfct[x]);
std::string fbuff(_("^!Manufacturer")); std::string fbuff(_("^!Manufacturer"));
@ -180,7 +195,7 @@ void menu_custom_filter::populate(float &customtop, float &custombottom)
} }
// add year subitem // add year subitem
else if (custfltr::other[x] == FILTER_YEAR && c_year::ui.size() > 0) else if (custfltr::other[x] == machine_filter::YEAR && c_year::ui.size() > 0)
{ {
arrow_flags = get_arrow_flags<uint16_t>(0, c_year::ui.size() - 1, custfltr::year[x]); arrow_flags = get_arrow_flags<uint16_t>(0, c_year::ui.size() - 1, custfltr::year[x]);
std::string fbuff(_("^!Year")); std::string fbuff(_("^!Year"));
@ -227,14 +242,14 @@ void menu_custom_filter::save_custom_filters()
// generate custom filters info // generate custom filters info
std::ostringstream cinfo; std::ostringstream cinfo;
util::stream_format(cinfo, "Total filters = %d\n", (custfltr::numother + 1)); util::stream_format(cinfo, "Total filters = %d\n", (custfltr::numother + 1));
util::stream_format(cinfo, "Main filter = %s\n", main_filters::text[custfltr::main]); util::stream_format(cinfo, "Main filter = %s\n", machine_filter::config_name(custfltr::main));
for (int x = 1; x <= custfltr::numother; x++) for (int x = 1; x <= custfltr::numother; x++)
{ {
util::stream_format(cinfo, "Other filter = %s\n", main_filters::text[custfltr::other[x]]); util::stream_format(cinfo, "Other filter = %s\n", machine_filter::config_name(custfltr::other[x]));
if (custfltr::other[x] == FILTER_MANUFACTURER) if (custfltr::other[x] == machine_filter::MANUFACTURER)
util::stream_format(cinfo, " Manufacturer filter = %s\n", c_mnfct::ui[custfltr::mnfct[x]]); util::stream_format(cinfo, " Manufacturer filter = %s\n", c_mnfct::ui[custfltr::mnfct[x]]);
else if (custfltr::other[x] == FILTER_YEAR) else if (custfltr::other[x] == machine_filter::YEAR)
util::stream_format(cinfo, " Year filter = %s\n", c_year::ui[custfltr::year[x]]); util::stream_format(cinfo, " Year filter = %s\n", c_year::ui[custfltr::year[x]]);
} }
file.puts(cinfo.str().c_str()); file.puts(cinfo.str().c_str());
@ -288,7 +303,8 @@ void menu_swcustom_filter::handle()
if (menu_event->iptkey == IPT_UI_SELECT) if (menu_event->iptkey == IPT_UI_SELECT)
{ {
sw_custfltr::numother++; sw_custfltr::numother++;
sw_custfltr::other[sw_custfltr::numother] = UI_SW_UNAVAILABLE + 1; sw_custfltr::other[sw_custfltr::numother] = software_filter::UNAVAILABLE;
++sw_custfltr::other[sw_custfltr::numother];
m_added = true; m_added = true;
} }
break; break;
@ -296,7 +312,8 @@ void menu_swcustom_filter::handle()
case REMOVE_FILTER: case REMOVE_FILTER:
if (menu_event->iptkey == IPT_UI_SELECT) if (menu_event->iptkey == IPT_UI_SELECT)
{ {
sw_custfltr::other[sw_custfltr::numother] = UI_SW_UNAVAILABLE + 1; sw_custfltr::other[sw_custfltr::numother] = software_filter::UNAVAILABLE;
++sw_custfltr::other[sw_custfltr::numother];
sw_custfltr::numother--; sw_custfltr::numother--;
changed = true; changed = true;
} }
@ -306,27 +323,34 @@ void menu_swcustom_filter::handle()
if ((uintptr_t)menu_event->itemref >= OTHER_FILTER && (uintptr_t)menu_event->itemref < OTHER_FILTER + MAX_CUST_FILTER) if ((uintptr_t)menu_event->itemref >= OTHER_FILTER && (uintptr_t)menu_event->itemref < OTHER_FILTER + MAX_CUST_FILTER)
{ {
int pos = (int)((uintptr_t)menu_event->itemref - OTHER_FILTER); int pos = (int)((uintptr_t)menu_event->itemref - OTHER_FILTER);
if (menu_event->iptkey == IPT_UI_LEFT && sw_custfltr::other[pos] > UI_SW_UNAVAILABLE + 1) if (menu_event->iptkey == IPT_UI_LEFT && sw_custfltr::other[pos] > software_filter::UNAVAILABLE + 1)
{ {
sw_custfltr::other[pos]--; sw_custfltr::other[pos]--;
changed = true; changed = true;
} }
else if (menu_event->iptkey == IPT_UI_RIGHT && sw_custfltr::other[pos] < UI_SW_LAST - 1) else if (menu_event->iptkey == IPT_UI_RIGHT && sw_custfltr::other[pos] < software_filter::LAST - 1)
{ {
sw_custfltr::other[pos]++; sw_custfltr::other[pos]++;
changed = true; changed = true;
} }
else if (menu_event->iptkey == IPT_UI_SELECT) else if (menu_event->iptkey == IPT_UI_SELECT)
{ {
size_t total = sw_filters::length; std::vector<software_filter::type> types;
std::vector<std::string> s_sel(total); std::vector<std::string> names;
for (size_t index = 0; index < total; ++index) types.reserve(software_filter::COUNT);
if (index <= UI_SW_UNAVAILABLE|| index == UI_SW_CUSTOM) names.reserve(software_filter::COUNT);
s_sel[index] = "_skip_"; uint16_t sel(0);
else for (software_filter::type index = software_filter::FIRST; index < software_filter::COUNT; ++index)
s_sel[index] = sw_filters::text[index]; {
if ((index >= software_filter::UNAVAILABLE) && (index != software_filter::CUSTOM))
menu::stack_push<menu_selector>(ui(), container(), s_sel, sw_custfltr::other[pos]); {
if (sw_custfltr::other[pos] == index)
sel = types.size();
types.emplace_back(index);
names.emplace_back(software_filter::display_name(index));
}
}
menu::stack_push<menu_selector>(ui(), container(), std::move(names), sel, [this, pos, t = std::move(types)] (int selection) { sw_custfltr::other[pos] = t[selection]; reset(reset_options::REMEMBER_REF); });
} }
} }
else if ((uintptr_t)menu_event->itemref >= YEAR_FILTER && (uintptr_t)menu_event->itemref < YEAR_FILTER + MAX_CUST_FILTER) else if ((uintptr_t)menu_event->itemref >= YEAR_FILTER && (uintptr_t)menu_event->itemref < YEAR_FILTER + MAX_CUST_FILTER)
@ -343,7 +367,9 @@ void menu_swcustom_filter::handle()
changed = true; changed = true;
} }
else if (menu_event->iptkey == IPT_UI_SELECT) else if (menu_event->iptkey == IPT_UI_SELECT)
menu::stack_push<menu_selector>(ui(), container(), m_filter.year.ui, sw_custfltr::year[pos]); {
menu::stack_push<menu_selector>(ui(), container(), std::vector<std::string>(m_filter.year.ui), sw_custfltr::year[pos], [this, pos] (int selection) { sw_custfltr::year[pos] = selection; reset(reset_options::REMEMBER_REF); });
}
} }
else if ((uintptr_t)menu_event->itemref >= TYPE_FILTER && (uintptr_t)menu_event->itemref < TYPE_FILTER + MAX_CUST_FILTER) else if ((uintptr_t)menu_event->itemref >= TYPE_FILTER && (uintptr_t)menu_event->itemref < TYPE_FILTER + MAX_CUST_FILTER)
{ {
@ -359,7 +385,9 @@ void menu_swcustom_filter::handle()
changed = true; changed = true;
} }
else if (menu_event->iptkey == IPT_UI_SELECT) else if (menu_event->iptkey == IPT_UI_SELECT)
menu::stack_push<menu_selector>(ui(), container(), m_filter.type.ui, sw_custfltr::type[pos]); {
menu::stack_push<menu_selector>(ui(), container(), std::vector<std::string>(m_filter.type.ui), sw_custfltr::type[pos], [this, pos] (int selection) { sw_custfltr::type[pos] = selection; reset(reset_options::REMEMBER_REF); });
}
} }
else if ((uintptr_t)menu_event->itemref >= MNFCT_FILTER && (uintptr_t)menu_event->itemref < MNFCT_FILTER + MAX_CUST_FILTER) else if ((uintptr_t)menu_event->itemref >= MNFCT_FILTER && (uintptr_t)menu_event->itemref < MNFCT_FILTER + MAX_CUST_FILTER)
{ {
@ -375,7 +403,9 @@ void menu_swcustom_filter::handle()
changed = true; changed = true;
} }
else if (menu_event->iptkey == IPT_UI_SELECT) else if (menu_event->iptkey == IPT_UI_SELECT)
menu::stack_push<menu_selector>(ui(), container(), m_filter.publisher.ui, sw_custfltr::mnfct[pos]); {
menu::stack_push<menu_selector>(ui(), container(), std::vector<std::string>(m_filter.publisher.ui), sw_custfltr::mnfct[pos], [this, pos] (int selection) { sw_custfltr::mnfct[pos] = selection; reset(reset_options::REMEMBER_REF); });
}
} }
else if ((uintptr_t)menu_event->itemref >= REGION_FILTER && (uintptr_t)menu_event->itemref < REGION_FILTER + MAX_CUST_FILTER) else if ((uintptr_t)menu_event->itemref >= REGION_FILTER && (uintptr_t)menu_event->itemref < REGION_FILTER + MAX_CUST_FILTER)
{ {
@ -391,7 +421,9 @@ void menu_swcustom_filter::handle()
changed = true; changed = true;
} }
else if (menu_event->iptkey == IPT_UI_SELECT) else if (menu_event->iptkey == IPT_UI_SELECT)
menu::stack_push<menu_selector>(ui(), container(), m_filter.region.ui, sw_custfltr::region[pos]); {
menu::stack_push<menu_selector>(ui(), container(), std::vector<std::string>(m_filter.region.ui), sw_custfltr::region[pos], [this, pos] (int selection) { sw_custfltr::region[pos] = selection; reset(reset_options::REMEMBER_REF); });
}
} }
else if ((uintptr_t)menu_event->itemref >= LIST_FILTER && (uintptr_t)menu_event->itemref < LIST_FILTER + MAX_CUST_FILTER) else if ((uintptr_t)menu_event->itemref >= LIST_FILTER && (uintptr_t)menu_event->itemref < LIST_FILTER + MAX_CUST_FILTER)
{ {
@ -407,7 +439,9 @@ void menu_swcustom_filter::handle()
changed = true; changed = true;
} }
else if (menu_event->iptkey == IPT_UI_SELECT) else if (menu_event->iptkey == IPT_UI_SELECT)
menu::stack_push<menu_selector>(ui(), container(), m_filter.swlist.description, sw_custfltr::list[pos]); {
menu::stack_push<menu_selector>(ui(), container(), std::vector<std::string>(m_filter.swlist.description), sw_custfltr::list[pos], [this, pos] (int selection) { sw_custfltr::list[pos] = selection; reset(reset_options::REMEMBER_REF); });
}
} }
} }
@ -423,8 +457,8 @@ void menu_swcustom_filter::handle()
void menu_swcustom_filter::populate(float &customtop, float &custombottom) void menu_swcustom_filter::populate(float &customtop, float &custombottom)
{ {
// add main filter // add main filter
uint32_t arrow_flags = get_arrow_flags<uint16_t>(UI_SW_ALL, UI_SW_UNAVAILABLE, sw_custfltr::main); uint32_t arrow_flags = get_arrow_flags<uint16_t>(software_filter::ALL, software_filter::UNAVAILABLE, sw_custfltr::main);
item_append(_("Main filter"), sw_filters::text[sw_custfltr::main], arrow_flags, (void *)(uintptr_t)MAIN_FILTER); item_append(_("Main filter"), software_filter::display_name(sw_custfltr::main), arrow_flags, (void *)(uintptr_t)MAIN_FILTER);
// add other filters // add other filters
for (int x = 1; x <= sw_custfltr::numother; x++) for (int x = 1; x <= sw_custfltr::numother; x++)
@ -432,14 +466,14 @@ void menu_swcustom_filter::populate(float &customtop, float &custombottom)
item_append(menu_item_type::SEPARATOR); item_append(menu_item_type::SEPARATOR);
// add filter items // add filter items
arrow_flags = get_arrow_flags<uint16_t>(UI_SW_UNAVAILABLE + 1, UI_SW_LAST - 1, sw_custfltr::other[x]); arrow_flags = get_arrow_flags<uint16_t>(software_filter::UNAVAILABLE + 1, software_filter::LAST - 1, sw_custfltr::other[x]);
item_append(_("Other filter"), sw_filters::text[sw_custfltr::other[x]], arrow_flags, (void *)(uintptr_t)(OTHER_FILTER + x)); item_append(_("Other filter"), software_filter::display_name(sw_custfltr::other[x]), arrow_flags, (void *)(uintptr_t)(OTHER_FILTER + x));
if (m_added) if (m_added)
selected = item.size() - 2; selected = item.size() - 2;
// add publisher subitem // add publisher subitem
if (sw_custfltr::other[x] == UI_SW_PUBLISHERS && m_filter.publisher.ui.size() > 0) if (sw_custfltr::other[x] == software_filter::PUBLISHERS && m_filter.publisher.ui.size())
{ {
arrow_flags = get_arrow_flags<uint16_t>(0, m_filter.publisher.ui.size() - 1, sw_custfltr::mnfct[x]); arrow_flags = get_arrow_flags<uint16_t>(0, m_filter.publisher.ui.size() - 1, sw_custfltr::mnfct[x]);
std::string fbuff(_("^!Publisher")); std::string fbuff(_("^!Publisher"));
@ -448,7 +482,7 @@ void menu_swcustom_filter::populate(float &customtop, float &custombottom)
} }
// add year subitem // add year subitem
else if (sw_custfltr::other[x] == UI_SW_YEARS && m_filter.year.ui.size() > 0) else if (sw_custfltr::other[x] == software_filter::YEARS && m_filter.year.ui.size())
{ {
arrow_flags = get_arrow_flags<uint16_t>(0, m_filter.year.ui.size() - 1, sw_custfltr::year[x]); arrow_flags = get_arrow_flags<uint16_t>(0, m_filter.year.ui.size() - 1, sw_custfltr::year[x]);
std::string fbuff(_("^!Year")); std::string fbuff(_("^!Year"));
@ -457,7 +491,7 @@ void menu_swcustom_filter::populate(float &customtop, float &custombottom)
} }
// add year subitem // add year subitem
else if (sw_custfltr::other[x] == UI_SW_LIST && m_filter.swlist.name.size() > 0) else if (sw_custfltr::other[x] == software_filter::LIST && m_filter.swlist.name.size())
{ {
arrow_flags = get_arrow_flags<uint16_t>(0, m_filter.swlist.name.size() - 1, sw_custfltr::list[x]); arrow_flags = get_arrow_flags<uint16_t>(0, m_filter.swlist.name.size() - 1, sw_custfltr::list[x]);
std::string fbuff(_("^!Software List")); std::string fbuff(_("^!Software List"));
@ -466,7 +500,7 @@ void menu_swcustom_filter::populate(float &customtop, float &custombottom)
} }
// add device type subitem // add device type subitem
else if (sw_custfltr::other[x] == UI_SW_TYPE && m_filter.type.ui.size() > 0) else if (sw_custfltr::other[x] == software_filter::DEVICE_TYPE && m_filter.type.ui.size())
{ {
arrow_flags = get_arrow_flags<uint16_t>(0, m_filter.type.ui.size() - 1, sw_custfltr::type[x]); arrow_flags = get_arrow_flags<uint16_t>(0, m_filter.type.ui.size() - 1, sw_custfltr::type[x]);
std::string fbuff(_("^!Device type")); std::string fbuff(_("^!Device type"));
@ -475,7 +509,7 @@ void menu_swcustom_filter::populate(float &customtop, float &custombottom)
} }
// add region subitem // add region subitem
else if (sw_custfltr::other[x] == UI_SW_REGION && m_filter.region.ui.size() > 0) else if (sw_custfltr::other[x] == software_filter::REGION && m_filter.region.ui.size())
{ {
arrow_flags = get_arrow_flags<uint16_t>(0, m_filter.region.ui.size() - 1, sw_custfltr::region[x]); arrow_flags = get_arrow_flags<uint16_t>(0, m_filter.region.ui.size() - 1, sw_custfltr::region[x]);
std::string fbuff(_("^!Region")); std::string fbuff(_("^!Region"));
@ -523,20 +557,20 @@ void menu_swcustom_filter::save_sw_custom_filters()
// generate custom filters info // generate custom filters info
std::ostringstream cinfo; std::ostringstream cinfo;
util::stream_format(cinfo, "Total filters = %d\n", (sw_custfltr::numother + 1)); util::stream_format(cinfo, "Total filters = %d\n", (sw_custfltr::numother + 1));
util::stream_format(cinfo, "Main filter = %s\n", sw_filters::text[sw_custfltr::main]); util::stream_format(cinfo, "Main filter = %s\n", software_filter::config_name(sw_custfltr::main));
for (int x = 1; x <= sw_custfltr::numother; x++) for (int x = 1; x <= sw_custfltr::numother; x++)
{ {
util::stream_format(cinfo, "Other filter = %s\n", sw_filters::text[sw_custfltr::other[x]]); util::stream_format(cinfo, "Other filter = %s\n", software_filter::config_name(sw_custfltr::other[x]));
if (sw_custfltr::other[x] == UI_SW_PUBLISHERS) if (sw_custfltr::other[x] == software_filter::PUBLISHERS)
util::stream_format(cinfo, " Manufacturer filter = %s\n", m_filter.publisher.ui[sw_custfltr::mnfct[x]]); util::stream_format(cinfo, " Manufacturer filter = %s\n", m_filter.publisher.ui[sw_custfltr::mnfct[x]]);
else if (sw_custfltr::other[x] == UI_SW_LIST) else if (sw_custfltr::other[x] == software_filter::LIST)
util::stream_format(cinfo, " Software List filter = %s\n", m_filter.swlist.name[sw_custfltr::list[x]]); util::stream_format(cinfo, " Software List filter = %s\n", m_filter.swlist.name[sw_custfltr::list[x]]);
else if (sw_custfltr::other[x] == UI_SW_YEARS) else if (sw_custfltr::other[x] == software_filter::YEARS)
util::stream_format(cinfo, " Year filter = %s\n", m_filter.year.ui[sw_custfltr::year[x]]); util::stream_format(cinfo, " Year filter = %s\n", m_filter.year.ui[sw_custfltr::year[x]]);
else if (sw_custfltr::other[x] == UI_SW_TYPE) else if (sw_custfltr::other[x] == software_filter::DEVICE_TYPE)
util::stream_format(cinfo, " Type filter = %s\n", m_filter.type.ui[sw_custfltr::type[x]]); util::stream_format(cinfo, " Type filter = %s\n", m_filter.type.ui[sw_custfltr::type[x]]);
else if (sw_custfltr::other[x] == UI_SW_REGION) else if (sw_custfltr::other[x] == software_filter::REGION)
util::stream_format(cinfo, " Region filter = %s\n", m_filter.region.ui[sw_custfltr::region[x]]); util::stream_format(cinfo, " Region filter = %s\n", m_filter.region.ui[sw_custfltr::region[x]]);
} }
file.puts(cinfo.str().c_str()); file.puts(cinfo.str().c_str());

View File

@ -26,11 +26,12 @@
namespace ui { namespace ui {
const char *const menu_custom_ui::HIDE_STATUS[] = { const char *const menu_custom_ui::HIDE_STATUS[] = {
__("Show All"), __("Show All"),
__("Hide Filters"), __("Hide Filters"),
__("Hide Info/Image"), __("Hide Info/Image"),
__("Hide Both") }; __("Hide Both") };
//------------------------------------------------- //-------------------------------------------------
// ctor // ctor
@ -88,42 +89,51 @@ void menu_custom_ui::handle()
{ {
switch ((uintptr_t)menu_event->itemref) switch ((uintptr_t)menu_event->itemref)
{ {
case FONT_MENU: case FONT_MENU:
if (menu_event->iptkey == IPT_UI_SELECT) if (menu_event->iptkey == IPT_UI_SELECT)
menu::stack_push<menu_font_ui>(ui(), container()); menu::stack_push<menu_font_ui>(ui(), container());
break; break;
case COLORS_MENU: case COLORS_MENU:
if (menu_event->iptkey == IPT_UI_SELECT) if (menu_event->iptkey == IPT_UI_SELECT)
menu::stack_push<menu_colors_ui>(ui(), container()); menu::stack_push<menu_colors_ui>(ui(), container());
break; break;
case HIDE_MENU: case HIDE_MENU:
if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT)
{ {
if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT) changed = true;
{ (menu_event->iptkey == IPT_UI_RIGHT) ? ui_globals::panels_status++ : ui_globals::panels_status--;
changed = true;
(menu_event->iptkey == IPT_UI_RIGHT) ? ui_globals::panels_status++ : ui_globals::panels_status--;
}
else if (menu_event->iptkey == IPT_UI_SELECT)
{
std::vector<std::string> s_sel(ARRAY_LENGTH(HIDE_STATUS));
std::transform(std::begin(HIDE_STATUS), std::end(HIDE_STATUS), s_sel.begin(), [](auto &s) { return _(s); });
menu::stack_push<menu_selector>(ui(), container(), std::move(s_sel), ui_globals::panels_status);
}
break;
} }
case LANGUAGE_MENU: else if (menu_event->iptkey == IPT_UI_SELECT)
{ {
if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT) std::vector<std::string> s_sel(ARRAY_LENGTH(HIDE_STATUS));
{ std::transform(std::begin(HIDE_STATUS), std::end(HIDE_STATUS), s_sel.begin(), [](auto &s) { return _(s); });
changed = true; menu::stack_push<menu_selector>(
(menu_event->iptkey == IPT_UI_RIGHT) ? m_currlang++ : m_currlang--; ui(), container(), std::move(s_sel), ui_globals::panels_status,
} [this] (int selection)
else if (menu_event->iptkey == IPT_UI_SELECT) {
{ ui_globals::panels_status = selection;
menu::stack_push<menu_selector>(ui(), container(), m_lang, m_currlang); reset(reset_options::REMEMBER_REF);
} });
break;
} }
break;
case LANGUAGE_MENU:
if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT)
{
changed = true;
(menu_event->iptkey == IPT_UI_RIGHT) ? m_currlang++ : m_currlang--;
}
else if (menu_event->iptkey == IPT_UI_SELECT)
{
// copying list of language names - expensive
menu::stack_push<menu_selector>(
ui(), container(), std::vector<std::string>(m_lang), m_currlang,
[this] (int selection)
{
m_currlang = selection;
reset(reset_options::REMEMBER_REF);
});
}
break;
} }
} }
@ -278,8 +288,15 @@ void menu_font_ui::handle()
{ {
std::vector<std::string> display_names; std::vector<std::string> display_names;
display_names.reserve(m_fonts.size()); display_names.reserve(m_fonts.size());
for (auto const &font : m_fonts) display_names.emplace_back(font.second); for (auto const &font : m_fonts)
menu::stack_push<menu_selector>(ui(), container(), std::move(display_names), m_actual); display_names.emplace_back(font.second);
menu::stack_push<menu_selector>(
ui(), container(), std::move(display_names), m_actual,
[this] (int selection)
{
m_actual = selection;
reset(reset_options::REMEMBER_REF);
});
changed = true; changed = true;
} }
break; break;

View File

@ -132,8 +132,6 @@ protected:
std::vector<menu_item> item; // array of items std::vector<menu_item> item; // array of items
int top_line; // main box top line int top_line; // main box top line
int l_sw_hover;
int l_hover;
int skip_main_items; int skip_main_items;
int selected; // which item is selected int selected; // which item is selected

View File

@ -720,7 +720,7 @@ 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) if (main_filters::actual == machine_filter::FAVORITE)
{ {
m_fav_reset = true; m_fav_reset = true;
menu::stack_pop(); menu::stack_pop();

View File

@ -9,7 +9,6 @@
*********************************************************************/ *********************************************************************/
#include "emu.h" #include "emu.h"
#include "ui/optsmenu.h" #include "ui/optsmenu.h"
#include "ui/ui.h" #include "ui/ui.h"
@ -27,6 +26,7 @@
#include "rendfont.h" #include "rendfont.h"
namespace ui { namespace ui {
//------------------------------------------------- //-------------------------------------------------
// ctor // ctor
//------------------------------------------------- //-------------------------------------------------
@ -42,7 +42,7 @@ menu_game_options::menu_game_options(mame_ui_manager &mui, render_container &con
menu_game_options::~menu_game_options() menu_game_options::~menu_game_options()
{ {
main_filters::actual = m_main; main_filters::actual = machine_filter::type(m_main);
reset_topmost(reset_options::SELECT_FIRST); reset_topmost(reset_options::SELECT_FIRST);
ui().save_ui_options(); ui().save_ui_options();
ui_globals::switch_image = true; ui_globals::switch_image = true;
@ -80,12 +80,17 @@ void menu_game_options::handle()
} }
else if (menu_event->iptkey == IPT_UI_SELECT) else if (menu_event->iptkey == IPT_UI_SELECT)
{ {
int total = main_filters::length; std::vector<std::string> s_sel(machine_filter::COUNT);
std::vector<std::string> s_sel(total); for (unsigned index = 0; index < s_sel.size(); ++index)
for (int index = 0; index < total; ++index) s_sel[index] = machine_filter::display_name(machine_filter::type(index));
s_sel[index] = main_filters::text[index];
menu::stack_push<menu_selector>(ui(), container(), s_sel, m_main); menu::stack_push<menu_selector>(
ui(), container(), std::move(s_sel), m_main,
[this] (int selection)
{
m_main = selection;
reset(reset_options::REMEMBER_REF);
});
} }
break; break;
} }
@ -110,7 +115,14 @@ void menu_game_options::handle()
for (size_t index = 0; index < total; ++index) for (size_t index = 0; index < total; ++index)
s_sel[index] = ifile.get_file(index); s_sel[index] = ifile.get_file(index);
menu::stack_push<menu_selector>(ui(), container(), s_sel, ifile.cur_file(), menu_selector::INIFILE); menu::stack_push<menu_selector>(
ui(), container(), std::move(s_sel), ifile.cur_file(),
[this] (int selection)
{
mame_machine_manager::instance()->inifile().set_file(selection);
mame_machine_manager::instance()->inifile().set_cat(0);
reset(reset_options::REMEMBER_REF);
});
} }
break; break;
} }
@ -134,7 +146,14 @@ void menu_game_options::handle()
for (int index = 0; index < total; ++index) for (int index = 0; index < total; ++index)
s_sel[index] = ifile.get_category(index); s_sel[index] = ifile.get_category(index);
menu::stack_push<menu_selector>(ui(), container(), s_sel, ifile.cur_cat(), menu_selector::CATEGORY); menu::stack_push<menu_selector>(
ui(), container(), std::move(s_sel), ifile.cur_cat(),
[this] (int selection)
{
mame_machine_manager::instance()->inifile().cur_cat() = selection;
mame_machine_manager::instance()->inifile().set_cat(selection);
reset(reset_options::REMEMBER_REF);
});
} }
break; break;
} }
@ -145,7 +164,15 @@ void menu_game_options::handle()
changed = true; changed = true;
} }
else if (menu_event->iptkey == IPT_UI_SELECT) else if (menu_event->iptkey == IPT_UI_SELECT)
menu::stack_push<menu_selector>(ui(), container(), c_mnfct::ui, c_mnfct::actual); {
menu::stack_push<menu_selector>(
ui(), container(), std::vector<std::string>(c_mnfct::ui), c_mnfct::actual,
[this] (int selection)
{
c_mnfct::actual = selection;
reset(reset_options::REMEMBER_REF);
});
}
break; break;
case YEAR_CAT_FILTER: case YEAR_CAT_FILTER:
@ -155,7 +182,15 @@ void menu_game_options::handle()
changed = true; changed = true;
} }
else if (menu_event->iptkey == IPT_UI_SELECT) else if (menu_event->iptkey == IPT_UI_SELECT)
menu::stack_push<menu_selector>(ui(), container(), c_year::ui, c_year::actual); {
menu::stack_push<menu_selector>(
ui(), container(), std::vector<std::string>(c_year::ui), c_year::actual,
[this] (int selection)
{
c_year::actual = selection;
reset(reset_options::REMEMBER_REF);
});
}
break; break;
case CONF_DIR: case CONF_DIR:
@ -228,11 +263,11 @@ void menu_game_options::populate(float &customtop, float &custombottom)
std::string fbuff; std::string fbuff;
// add filter item // add filter item
uint32_t arrow_flags = get_arrow_flags<uint16_t>(FILTER_FIRST, FILTER_LAST, m_main); uint32_t arrow_flags = get_arrow_flags<uint16_t>(machine_filter::FIRST, machine_filter::LAST, m_main);
item_append(_("Filter"), main_filters::text[m_main], arrow_flags, (void *)(uintptr_t)FILTER_MENU); item_append(_("Filter"), machine_filter::display_name(machine_filter::type(m_main)), arrow_flags, (void *)(uintptr_t)FILTER_MENU);
// add category subitem // add category subitem
if (m_main == FILTER_CATEGORY && mame_machine_manager::instance()->inifile().total() > 0) if (m_main == machine_filter::CATEGORY && mame_machine_manager::instance()->inifile().total() > 0)
{ {
inifile_manager &inif = mame_machine_manager::instance()->inifile(); inifile_manager &inif = mame_machine_manager::instance()->inifile();
@ -247,7 +282,7 @@ void menu_game_options::populate(float &customtop, float &custombottom)
item_append(fbuff, inif.get_category(), arrow_flags, (void *)(uintptr_t)CATEGORY_FILTER); item_append(fbuff, inif.get_category(), arrow_flags, (void *)(uintptr_t)CATEGORY_FILTER);
} }
// add manufacturer subitem // add manufacturer subitem
else if (m_main == FILTER_MANUFACTURER && c_mnfct::ui.size() > 0) else if (m_main == machine_filter::MANUFACTURER && c_mnfct::ui.size() > 0)
{ {
arrow_flags = get_arrow_flags(uint16_t(0), uint16_t(c_mnfct::ui.size() - 1), c_mnfct::actual); arrow_flags = get_arrow_flags(uint16_t(0), uint16_t(c_mnfct::ui.size() - 1), c_mnfct::actual);
fbuff = _("^!Manufacturer"); fbuff = _("^!Manufacturer");
@ -255,7 +290,7 @@ void menu_game_options::populate(float &customtop, float &custombottom)
item_append(fbuff, c_mnfct::ui[c_mnfct::actual], arrow_flags, (void *)(uintptr_t)MANUFACT_CAT_FILTER); item_append(fbuff, c_mnfct::ui[c_mnfct::actual], arrow_flags, (void *)(uintptr_t)MANUFACT_CAT_FILTER);
} }
// add year subitem // add year subitem
else if (m_main == FILTER_YEAR && c_year::ui.size() > 0) else if (m_main == machine_filter::YEAR && c_year::ui.size() > 0)
{ {
arrow_flags = get_arrow_flags(uint16_t(0), uint16_t(c_year::ui.size() - 1), c_year::actual); arrow_flags = get_arrow_flags(uint16_t(0), uint16_t(c_year::ui.size() - 1), c_year::actual);
fbuff.assign(_("^!Year")); fbuff.assign(_("^!Year"));
@ -263,7 +298,7 @@ void menu_game_options::populate(float &customtop, float &custombottom)
item_append(fbuff, c_year::ui[c_year::actual], arrow_flags, (void *)(uintptr_t)YEAR_CAT_FILTER); item_append(fbuff, c_year::ui[c_year::actual], arrow_flags, (void *)(uintptr_t)YEAR_CAT_FILTER);
} }
// add custom subitem // add custom subitem
else if (m_main == FILTER_CUSTOM) else if (m_main == machine_filter::CUSTOM)
{ {
fbuff = _("^!Setup custom filter"); fbuff = _("^!Setup custom filter");
convert_command_glyph(fbuff); convert_command_glyph(fbuff);

View File

@ -9,38 +9,29 @@
*********************************************************************/ *********************************************************************/
#include "emu.h" #include "emu.h"
#include "ui/selector.h" #include "ui/selector.h"
#include "ui/ui.h"
#include "ui/inifile.h"
#include "mame.h" #include "ui/ui.h"
#include "ui/utils.h"
namespace ui { namespace ui {
//------------------------------------------------- //-------------------------------------------------
// ctor / dtor // ctor / dtor
//------------------------------------------------- //-------------------------------------------------
menu_selector::menu_selector(mame_ui_manager &mui, render_container &container, std::vector<std::string> const &s_sel, uint16_t &s_actual, int category, int _hover) menu_selector::menu_selector(
mame_ui_manager &mui,
render_container &container,
std::vector<std::string> &&sel,
int initial,
std::function<void (int)> &&handler)
: menu(mui, container) : menu(mui, container)
, m_search() , m_search()
, m_selector(s_actual) , m_str_items(std::move(sel))
, m_category(category) , m_handler(std::move(handler))
, m_hover(_hover) , m_initial(initial)
, m_first_pass(true)
, m_str_items(s_sel)
{
m_searchlist[0] = nullptr;
}
menu_selector::menu_selector(mame_ui_manager &mui, render_container &container, std::vector<std::string> &&s_sel, uint16_t &s_actual, int category, int _hover)
: menu(mui, container)
, m_search()
, m_selector(s_actual)
, m_category(category)
, m_hover(_hover)
, m_first_pass(true)
, m_str_items(std::move(s_sel))
{ {
m_searchlist[0] = nullptr; m_searchlist[0] = nullptr;
} }
@ -62,37 +53,12 @@ void menu_selector::handle()
{ {
if (menu_event->iptkey == IPT_UI_SELECT) if (menu_event->iptkey == IPT_UI_SELECT)
{ {
for (size_t idx = 0; idx < m_str_items.size(); ++idx) int selection(-1);
for (size_t idx = 0; (m_str_items.size() > idx) && (0 > selection); ++idx)
if ((void*)&m_str_items[idx] == menu_event->itemref) if ((void*)&m_str_items[idx] == menu_event->itemref)
m_selector = idx; selection = int(unsigned(idx));
switch (m_category) m_handler(selection);
{
case INIFILE:
mame_machine_manager::instance()->inifile().set_file(m_selector);
mame_machine_manager::instance()->inifile().set_cat(0);
reset_parent(reset_options::REMEMBER_REF);
break;
case CATEGORY:
mame_machine_manager::instance()->inifile().set_cat(m_selector);
reset_parent(reset_options::REMEMBER_REF);
break;
case GAME:
main_filters::actual = m_hover;
reset_parent(reset_options::SELECT_FIRST);
break;
case SOFTWARE:
sw_filters::actual = m_hover;
reset_parent(reset_options::SELECT_FIRST);
break;
default:
reset_parent(reset_options::REMEMBER_REF);
break;
}
ui_globals::switch_image = true; ui_globals::switch_image = true;
stack_pop(); stack_pop();
@ -127,20 +93,18 @@ void menu_selector::populate(float &customtop, float &custombottom)
} }
else else
{ {
for (size_t index = 0, added = 0; index < m_str_items.size(); ++index) for (size_t index = 0; index < m_str_items.size(); ++index)
if (m_str_items[index] != "_skip_") {
{ if ((0 <= m_initial) && (unsigned(m_initial) == index))
if (m_first_pass && m_selector == index) selected = index;
selected = added;
added++; item_append(m_str_items[index], "", 0, (void *)&m_str_items[index]);
item_append(m_str_items[index], "", 0, (void *)&m_str_items[index]); }
}
} }
item_append(menu_item_type::SEPARATOR); item_append(menu_item_type::SEPARATOR);
customtop = custombottom = ui().get_line_height() + 3.0f * UI_BOX_TB_BORDER; customtop = custombottom = ui().get_line_height() + 3.0f * UI_BOX_TB_BORDER;
m_first_pass = false; m_initial = -1;
} }
//------------------------------------------------- //-------------------------------------------------
@ -161,7 +125,7 @@ void menu_selector::custom_render(void *selectedref, float top, float bottom, fl
draw_text_box( draw_text_box(
std::begin(tempbuf), std::end(tempbuf), std::begin(tempbuf), std::end(tempbuf),
origx1, origx2, origy2 + UI_BOX_TB_BORDER, origy2 + bottom, origx1, origx2, origy2 + UI_BOX_TB_BORDER, origy2 + bottom,
ui::text_layout::CENTER, ui::text_layout::TRUNCATE, false, ui::text_layout::CENTER, ui::text_layout::NEVER, false,
UI_TEXT_COLOR, UI_RED_COLOR, 1.0f); UI_TEXT_COLOR, UI_RED_COLOR, 1.0f);
} }
@ -177,9 +141,6 @@ void menu_selector::find_matches(const char *str)
for (; index < m_str_items.size(); ++index) for (; index < m_str_items.size(); ++index)
{ {
if (m_str_items[index] == "_skip_")
continue;
int curpenalty = fuzzy_substring(str, m_str_items[index]); int curpenalty = fuzzy_substring(str, m_str_items[index]);
// insert into the sorted table of matches // insert into the sorted table of matches

View File

@ -16,6 +16,7 @@
#include "ui/menu.h" #include "ui/menu.h"
namespace ui { namespace ui {
//------------------------------------------------- //-------------------------------------------------
// class selector menu // class selector menu
//------------------------------------------------- //-------------------------------------------------
@ -23,16 +24,12 @@ namespace ui {
class menu_selector : public menu class menu_selector : public menu
{ {
public: public:
enum menu_selector(
{ mame_ui_manager &mui,
INIFILE = 1, render_container &container,
CATEGORY, std::vector<std::string> &&sel,
GAME, int initial,
SOFTWARE std::function<void (int)> &&handler);
};
menu_selector(mame_ui_manager &mui, render_container &container, std::vector<std::string> const &_sel, uint16_t &_actual, int _category = 0, int _hover = 0);
menu_selector(mame_ui_manager &mui, render_container &container, std::vector<std::string> &&_sel, uint16_t &_actual, int _category = 0, int _hover = 0);
virtual ~menu_selector() override; virtual ~menu_selector() override;
protected: protected:
@ -48,10 +45,9 @@ private:
void find_matches(const char *str); void find_matches(const char *str);
std::string m_search; std::string m_search;
uint16_t &m_selector;
int m_category, m_hover;
bool m_first_pass;
std::vector<std::string> m_str_items; std::vector<std::string> m_str_items;
std::function<void (int)> m_handler;
int m_initial;
std::string *m_searchlist[VISIBLE_GAMES_IN_SEARCH + 1]; std::string *m_searchlist[VISIBLE_GAMES_IN_SEARCH + 1];
}; };

View File

@ -9,7 +9,6 @@
*********************************************************************/ *********************************************************************/
#include "emu.h" #include "emu.h"
#include "ui/selgame.h" #include "ui/selgame.h"
#include "ui/ui.h" #include "ui/ui.h"
@ -34,9 +33,11 @@
#include "uiinput.h" #include "uiinput.h"
#include "luaengine.h" #include "luaengine.h"
extern const char UI_VERSION_TAG[]; extern const char UI_VERSION_TAG[];
namespace ui { namespace ui {
bool menu_select_game::first_start = true; bool menu_select_game::first_start = true;
std::vector<const game_driver *> menu_select_game::m_sortedlist; std::vector<const game_driver *> menu_select_game::m_sortedlist;
int menu_select_game::m_isabios = 0; int menu_select_game::m_isabios = 0;
@ -89,23 +90,25 @@ menu_select_game::menu_select_game(mame_ui_manager &mui, render_container &conta
sub_filter = tmp.substr(found + 1); sub_filter = tmp.substr(found + 1);
} }
main_filters::actual = FILTER_ALL; main_filters::actual = machine_filter::ALL;
for (size_t ind = 0; ind < main_filters::length; ++ind) for (machine_filter::type ind = machine_filter::FIRST; ind < machine_filter::COUNT; ++ind)
if (last_filter == main_filters::text[ind]) {
if (last_filter == machine_filter::config_name(ind))
{ {
main_filters::actual = ind; main_filters::actual = ind;
break; break;
} }
}
if (main_filters::actual == FILTER_CATEGORY) if (main_filters::actual == machine_filter::CATEGORY)
main_filters::actual = FILTER_ALL; main_filters::actual = machine_filter::ALL;
else if (main_filters::actual == FILTER_MANUFACTURER) else if (main_filters::actual == machine_filter::MANUFACTURER)
{ {
for (size_t id = 0; id < c_mnfct::ui.size(); ++id) for (size_t id = 0; id < c_mnfct::ui.size(); ++id)
if (sub_filter == c_mnfct::ui[id]) if (sub_filter == c_mnfct::ui[id])
c_mnfct::actual = id; c_mnfct::actual = id;
} }
else if (main_filters::actual == FILTER_YEAR) else if (main_filters::actual == machine_filter::YEAR)
{ {
for (size_t id = 0; id < c_year::ui.size(); ++id) for (size_t id = 0; id < c_year::ui.size(); ++id)
if (sub_filter == c_year::ui[id]) if (sub_filter == c_year::ui[id])
@ -148,10 +151,10 @@ menu_select_game::~menu_select_game()
else if (swinfo && m_prev_selected) else if (swinfo && m_prev_selected)
last_driver = reinterpret_cast<ui_software_info *>(m_prev_selected)->shortname; last_driver = reinterpret_cast<ui_software_info *>(m_prev_selected)->shortname;
std::string filter(main_filters::text[main_filters::actual]); std::string filter(machine_filter::config_name(main_filters::actual));
if (main_filters::actual == FILTER_MANUFACTURER) if (main_filters::actual == machine_filter::MANUFACTURER)
filter.append(",").append(c_mnfct::ui[c_mnfct::actual]); filter.append(",").append(c_mnfct::ui[c_mnfct::actual]);
else if (main_filters::actual == FILTER_YEAR) else if (main_filters::actual == machine_filter::YEAR)
filter.append(",").append(c_year::ui[c_year::actual]); filter.append(",").append(c_year::ui[c_year::actual]);
ui_options &mopt = ui().options(); ui_options &mopt = ui().options();
@ -271,12 +274,12 @@ void menu_select_game::handle()
change_info_pane(1); change_info_pane(1);
} }
} }
else if (menu_event->iptkey == IPT_UI_UP_FILTER && highlight > FILTER_FIRST) else if (menu_event->iptkey == IPT_UI_UP_FILTER && highlight > machine_filter::FIRST)
{ {
// handle UI_UP_FILTER // handle UI_UP_FILTER
highlight--; highlight--;
} }
else if (menu_event->iptkey == IPT_UI_DOWN_FILTER && highlight < FILTER_LAST) else if (menu_event->iptkey == IPT_UI_DOWN_FILTER && highlight < machine_filter::LAST)
{ {
// handle UI_DOWN_FILTER // handle UI_DOWN_FILTER
highlight++; highlight++;
@ -401,12 +404,12 @@ void menu_select_game::handle()
l_hover = highlight; l_hover = highlight;
check_filter = true; check_filter = true;
} }
else if (menu_event->iptkey == IPT_UI_UP_FILTER && highlight > FILTER_FIRST) else if (menu_event->iptkey == IPT_UI_UP_FILTER && highlight > machine_filter::FIRST)
{ {
// handle UI_UP_FILTER // handle UI_UP_FILTER
highlight--; highlight--;
} }
else if (menu_event->iptkey == IPT_UI_DOWN_FILTER && highlight < FILTER_LAST) else if (menu_event->iptkey == IPT_UI_DOWN_FILTER && highlight < machine_filter::LAST)
{ {
// handle UI_DOWN_FILTER // handle UI_DOWN_FILTER
highlight++; highlight++;
@ -420,24 +423,42 @@ void menu_select_game::handle()
if (check_filter) if (check_filter)
{ {
m_search.clear(); m_search.clear();
if (l_hover == FILTER_CATEGORY) if (l_hover == machine_filter::CATEGORY)
{ {
main_filters::actual = l_hover; main_filters::actual = machine_filter::type(l_hover);
menu::stack_push<menu_game_options>(ui(), container()); menu::stack_push<menu_game_options>(ui(), container());
} }
else if (l_hover == FILTER_CUSTOM) else if (l_hover == machine_filter::CUSTOM)
{ {
main_filters::actual = l_hover; main_filters::actual = machine_filter::type(l_hover);
menu::stack_push<menu_custom_filter>(ui(), container(), true); menu::stack_push<menu_custom_filter>(ui(), container(), true);
} }
else if (l_hover == FILTER_MANUFACTURER) else if (l_hover == machine_filter::MANUFACTURER)
menu::stack_push<menu_selector>(ui(), container(), c_mnfct::ui, c_mnfct::actual, menu_selector::GAME, l_hover); {
else if (l_hover == FILTER_YEAR) menu::stack_push<menu_selector>(
menu::stack_push<menu_selector>(ui(), container(), c_year::ui, c_year::actual, menu_selector::GAME, l_hover); ui(), container(), std::vector<std::string>(c_mnfct::ui), c_mnfct::actual,
[this] (int selection)
{
c_mnfct::actual = selection;
main_filters::actual = machine_filter::type(l_hover);
reset(reset_options::SELECT_FIRST);
});
}
else if (l_hover == machine_filter::YEAR)
{
menu::stack_push<menu_selector>(
ui(), container(), std::vector<std::string>(c_year::ui), c_year::actual,
[this] (int selection)
{
c_year::actual = selection;
main_filters::actual = machine_filter::type(l_hover);
reset(reset_options::SELECT_FIRST);
});
}
else else
{ {
if (l_hover >= FILTER_ALL) if (l_hover >= machine_filter::ALL)
main_filters::actual = l_hover; main_filters::actual = machine_filter::type(l_hover);
reset(reset_options::SELECT_FIRST); reset(reset_options::SELECT_FIRST);
} }
} }
@ -468,21 +489,21 @@ void menu_select_game::populate(float &customtop, float &custombottom)
// if filter is set on category, build category list // if filter is set on category, build category list
switch (main_filters::actual) switch (main_filters::actual)
{ {
case FILTER_CATEGORY: case machine_filter::CATEGORY:
build_category(); build_category();
break; break;
case FILTER_MANUFACTURER: case machine_filter::MANUFACTURER:
build_list(c_mnfct::ui[c_mnfct::actual].c_str()); build_list(c_mnfct::ui[c_mnfct::actual].c_str());
break; break;
case FILTER_YEAR: case machine_filter::YEAR:
build_list(c_year::ui[c_year::actual].c_str()); build_list(c_year::ui[c_year::actual].c_str());
break; break;
case FILTER_CUSTOM: case machine_filter::CUSTOM:
build_custom(); build_custom();
break; break;
default: default:
build_list(); build_list();
break; break;
} }
// iterate over entries // iterate over entries
@ -868,7 +889,7 @@ void menu_select_game::inkey_select_favorite(const event *menu_event)
inline bool menu_select_game::isfavorite() const inline bool menu_select_game::isfavorite() const
{ {
return (main_filters::actual == FILTER_FAVORITE); return (main_filters::actual == machine_filter::FAVORITE);
} }
//------------------------------------------------- //-------------------------------------------------
@ -894,9 +915,9 @@ void menu_select_game::build_list(const char *filter_text, int filter, bool bios
if (s_drivers.empty()) if (s_drivers.empty())
{ {
filter = main_filters::actual; filter = main_filters::actual;
if (filter == FILTER_AVAILABLE) if (filter == machine_filter::AVAILABLE)
s_drivers = m_availsortedlist; s_drivers = m_availsortedlist;
else if (filter == FILTER_UNAVAILABLE) else if (filter == machine_filter::UNAVAILABLE)
s_drivers = m_unavailsortedlist; s_drivers = m_unavailsortedlist;
else else
s_drivers = m_sortedlist; s_drivers = m_sortedlist;
@ -904,34 +925,34 @@ void menu_select_game::build_list(const char *filter_text, int filter, bool bios
for (auto & s_driver : s_drivers) for (auto & s_driver : s_drivers)
{ {
if (!bioscheck && filter != FILTER_BIOS && (s_driver->flags & machine_flags::IS_BIOS_ROOT) != 0) if (!bioscheck && filter != machine_filter::BIOS && (s_driver->flags & machine_flags::IS_BIOS_ROOT) != 0)
continue; continue;
switch (filter) switch (filter)
{ {
case FILTER_ALL: case machine_filter::ALL:
case FILTER_AVAILABLE: case machine_filter::AVAILABLE:
case FILTER_UNAVAILABLE: case machine_filter::UNAVAILABLE:
m_displaylist.push_back(s_driver); m_displaylist.push_back(s_driver);
break; break;
case FILTER_WORKING: case machine_filter::WORKING:
if (!(s_driver->flags & machine_flags::NOT_WORKING)) if (!(s_driver->flags & machine_flags::NOT_WORKING))
m_displaylist.push_back(s_driver); m_displaylist.push_back(s_driver);
break; break;
case FILTER_NOT_MECHANICAL: case machine_filter::NOT_MECHANICAL:
if (!(s_driver->flags & machine_flags::MECHANICAL)) if (!(s_driver->flags & machine_flags::MECHANICAL))
m_displaylist.push_back(s_driver); m_displaylist.push_back(s_driver);
break; break;
case FILTER_BIOS: case machine_filter::BIOS:
if (s_driver->flags & machine_flags::IS_BIOS_ROOT) if (s_driver->flags & machine_flags::IS_BIOS_ROOT)
m_displaylist.push_back(s_driver); m_displaylist.push_back(s_driver);
break; break;
case FILTER_PARENT: case machine_filter::PARENT:
case FILTER_CLONES: case machine_filter::CLONES:
{ {
bool cloneof = strcmp(s_driver->parent, "0"); bool cloneof = strcmp(s_driver->parent, "0");
if (cloneof) if (cloneof)
@ -941,55 +962,55 @@ void menu_select_game::build_list(const char *filter_text, int filter, bool bios
cloneof = false; cloneof = false;
} }
if (filter == FILTER_CLONES && cloneof) if (filter == machine_filter::CLONES && cloneof)
m_displaylist.push_back(s_driver); m_displaylist.push_back(s_driver);
else if (filter == FILTER_PARENT && !cloneof) else if (filter == machine_filter::PARENT && !cloneof)
m_displaylist.push_back(s_driver); m_displaylist.push_back(s_driver);
} }
break; break;
case FILTER_NOT_WORKING: case machine_filter::NOT_WORKING:
if (s_driver->flags & machine_flags::NOT_WORKING) if (s_driver->flags & machine_flags::NOT_WORKING)
m_displaylist.push_back(s_driver); m_displaylist.push_back(s_driver);
break; break;
case FILTER_MECHANICAL: case machine_filter::MECHANICAL:
if (s_driver->flags & machine_flags::MECHANICAL) if (s_driver->flags & machine_flags::MECHANICAL)
m_displaylist.push_back(s_driver); m_displaylist.push_back(s_driver);
break; break;
case FILTER_SAVE: case machine_filter::SAVE:
if (s_driver->flags & machine_flags::SUPPORTS_SAVE) if (s_driver->flags & machine_flags::SUPPORTS_SAVE)
m_displaylist.push_back(s_driver); m_displaylist.push_back(s_driver);
break; break;
case FILTER_NOSAVE: case machine_filter::NOSAVE:
if (!(s_driver->flags & machine_flags::SUPPORTS_SAVE)) if (!(s_driver->flags & machine_flags::SUPPORTS_SAVE))
m_displaylist.push_back(s_driver); m_displaylist.push_back(s_driver);
break; break;
case FILTER_YEAR: case machine_filter::YEAR:
if (!core_stricmp(filter_text, s_driver->year)) if (!core_stricmp(filter_text, s_driver->year))
m_displaylist.push_back(s_driver); m_displaylist.push_back(s_driver);
break; break;
case FILTER_VERTICAL: case machine_filter::VERTICAL:
if (s_driver->flags & ORIENTATION_SWAP_XY) if (s_driver->flags & ORIENTATION_SWAP_XY)
m_displaylist.push_back(s_driver); m_displaylist.push_back(s_driver);
break; break;
case FILTER_HORIZONTAL: case machine_filter::HORIZONTAL:
if (!(s_driver->flags & ORIENTATION_SWAP_XY)) if (!(s_driver->flags & ORIENTATION_SWAP_XY))
m_displaylist.push_back(s_driver); m_displaylist.push_back(s_driver);
break; break;
case FILTER_MANUFACTURER: case machine_filter::MANUFACTURER:
{ {
std::string name = c_mnfct::getname(s_driver->manufacturer); std::string name = c_mnfct::getname(s_driver->manufacturer);
if (!core_stricmp(filter_text, name.c_str())) if (!core_stricmp(filter_text, name.c_str()))
m_displaylist.push_back(s_driver); m_displaylist.push_back(s_driver);
} }
break; break;
case FILTER_CHD: case machine_filter::CHD:
{ {
auto entries = rom_build_entries(s_driver->rom); auto entries = rom_build_entries(s_driver->rom);
for (const rom_entry &rom : entries) for (const rom_entry &rom : entries)
@ -1000,7 +1021,7 @@ void menu_select_game::build_list(const char *filter_text, int filter, bool bios
} }
} }
break; break;
case FILTER_NOCHD: case machine_filter::NOCHD:
{ {
auto entries = rom_build_entries(s_driver->rom); auto entries = rom_build_entries(s_driver->rom);
bool found = false; bool found = false;
@ -1062,9 +1083,9 @@ void menu_select_game::build_custom()
std::vector<const game_driver *> s_drivers; std::vector<const game_driver *> s_drivers;
bool bioscheck = false; bool bioscheck = false;
if (custfltr::main == FILTER_AVAILABLE) if (custfltr::main == machine_filter::AVAILABLE)
s_drivers = m_availsortedlist; s_drivers = m_availsortedlist;
else if (custfltr::main == FILTER_UNAVAILABLE) else if (custfltr::main == machine_filter::UNAVAILABLE)
s_drivers = m_unavailsortedlist; s_drivers = m_unavailsortedlist;
else else
s_drivers = m_sortedlist; s_drivers = m_sortedlist;
@ -1077,7 +1098,7 @@ void menu_select_game::build_custom()
for (int count = 1; count <= custfltr::numother; ++count) for (int count = 1; count <= custfltr::numother; ++count)
{ {
int filter = custfltr::other[count]; int filter = custfltr::other[count];
if (filter == FILTER_BIOS) if (filter == machine_filter::BIOS)
bioscheck = true; bioscheck = true;
} }
@ -1089,15 +1110,15 @@ void menu_select_game::build_custom()
switch (filter) switch (filter)
{ {
case FILTER_YEAR: case machine_filter::YEAR:
build_list(c_year::ui[custfltr::year[count]].c_str(), filter, bioscheck, s_drivers); build_list(c_year::ui[custfltr::year[count]].c_str(), filter, bioscheck, s_drivers);
break; break;
case FILTER_MANUFACTURER: case machine_filter::MANUFACTURER:
build_list(c_mnfct::ui[custfltr::mnfct[count]].c_str(), filter, bioscheck, s_drivers); build_list(c_mnfct::ui[custfltr::mnfct[count]].c_str(), filter, bioscheck, s_drivers);
break; break;
default: default:
build_list(nullptr, filter, bioscheck, s_drivers); build_list(nullptr, filter, bioscheck, s_drivers);
break; break;
} }
} }
} }
@ -1451,22 +1472,27 @@ void menu_select_game::load_custom_filters()
file.gets(buffer, MAX_CHAR_INFO); file.gets(buffer, MAX_CHAR_INFO);
pb = strchr(buffer, '=') + 2; pb = strchr(buffer, '=') + 2;
for (int y = 0; y < main_filters::length; ++y) for (machine_filter::type y = machine_filter::FIRST; y < machine_filter::COUNT; ++y)
if (!strncmp(pb, main_filters::text[y], strlen(main_filters::text[y]))) {
char const *const name(machine_filter::config_name(y));
if (!strncmp(pb, name, strlen(name)))
{ {
custfltr::main = y; custfltr::main = y;
break; break;
} }
}
for (int x = 1; x <= custfltr::numother; ++x) for (int x = 1; x <= custfltr::numother; ++x)
{ {
file.gets(buffer, MAX_CHAR_INFO); file.gets(buffer, MAX_CHAR_INFO);
char *cb = strchr(buffer, '=') + 2; char *cb = strchr(buffer, '=') + 2;
for (int y = 0; y < main_filters::length; ++y) for (machine_filter::type y = machine_filter::FIRST; y < machine_filter::COUNT; ++y)
if (!strncmp(cb, main_filters::text[y], strlen(main_filters::text[y]))) {
char const *const name(machine_filter::config_name(y));
if (!strncmp(cb, name, strlen(name)))
{ {
custfltr::other[x] = y; custfltr::other[x] = y;
if (y == FILTER_MANUFACTURER) if (y == machine_filter::MANUFACTURER)
{ {
file.gets(buffer, MAX_CHAR_INFO); file.gets(buffer, MAX_CHAR_INFO);
char *ab = strchr(buffer, '=') + 2; char *ab = strchr(buffer, '=') + 2;
@ -1474,7 +1500,7 @@ void menu_select_game::load_custom_filters()
if (!strncmp(ab, c_mnfct::ui[z].c_str(), c_mnfct::ui[z].length())) if (!strncmp(ab, c_mnfct::ui[z].c_str(), c_mnfct::ui[z].length()))
custfltr::mnfct[x] = z; custfltr::mnfct[x] = z;
} }
else if (y == FILTER_YEAR) else if (y == machine_filter::YEAR)
{ {
file.gets(buffer, MAX_CHAR_INFO); file.gets(buffer, MAX_CHAR_INFO);
char *db = strchr(buffer, '=') + 2; char *db = strchr(buffer, '=') + 2;
@ -1483,6 +1509,7 @@ void menu_select_game::load_custom_filters()
custfltr::year[x] = z; custfltr::year[x] = z;
} }
} }
}
} }
file.close(); file.close();
} }
@ -1505,26 +1532,25 @@ float menu_select_game::draw_left_panel(float x1, float y1, float x2, float y2)
float text_size = ui().options().infos_size(); float text_size = ui().options().infos_size();
float line_height_max = line_height * text_size; float line_height_max = line_height * text_size;
float left_width = 0.0f; float left_width = 0.0f;
int text_lenght = main_filters::length; int line_count = machine_filter::COUNT;
int afilter = main_filters::actual; int afilter = main_filters::actual;
int phover = HOVER_FILTER_FIRST; int phover = HOVER_FILTER_FIRST;
const char **text = main_filters::text;
float sc = y2 - y1 - (2.0f * UI_BOX_TB_BORDER); float sc = y2 - y1 - (2.0f * UI_BOX_TB_BORDER);
if ((text_lenght * line_height_max) > sc) if ((line_count * line_height_max) > sc)
{ {
float lm = sc / (text_lenght); float lm = sc / (line_count);
text_size = lm / line_height; text_size = lm / line_height;
line_height_max = line_height * text_size; line_height_max = line_height * text_size;
} }
float text_sign = ui().get_string_width("_# ", text_size); float text_sign = ui().get_string_width("_# ", text_size);
for (int x = 0; x < text_lenght; ++x) for (machine_filter::type x = machine_filter::FIRST; x < machine_filter::COUNT; ++x)
{ {
float total_width; float total_width;
// compute width of left hand side // compute width of left hand side
total_width = ui().get_string_width(text[x], text_size); total_width = ui().get_string_width(machine_filter::display_name(x), text_size);
total_width += text_sign; total_width += text_sign;
// track the maximum // track the maximum
@ -1541,9 +1567,9 @@ float menu_select_game::draw_left_panel(float x1, float y1, float x2, float y2)
y1 += UI_BOX_TB_BORDER; y1 += UI_BOX_TB_BORDER;
y2 -= UI_BOX_TB_BORDER; y2 -= UI_BOX_TB_BORDER;
for (int filter = 0; filter < text_lenght; ++filter) for (machine_filter::type filter = machine_filter::FIRST; filter < machine_filter::COUNT; ++filter)
{ {
std::string str(text[filter]); std::string str(machine_filter::display_name(filter));
rgb_t bgcolor = UI_TEXT_BG_COLOR; rgb_t bgcolor = UI_TEXT_BG_COLOR;
rgb_t fgcolor = UI_TEXT_COLOR; rgb_t fgcolor = UI_TEXT_COLOR;
@ -1564,11 +1590,11 @@ float menu_select_game::draw_left_panel(float x1, float y1, float x2, float y2)
} }
float x1t = x1 + text_sign; float x1t = x1 + text_sign;
if (afilter == FILTER_CUSTOM) if (afilter == machine_filter::CUSTOM)
{ {
if (filter == custfltr::main) if (filter == custfltr::main)
{ {
str.assign("@custom1 ").append(text[filter]); str = std::string("@custom1 ") + str;
x1t -= text_sign; x1t -= text_sign;
} }
else else
@ -1578,7 +1604,7 @@ float menu_select_game::draw_left_panel(float x1, float y1, float x2, float y2)
int cfilter = custfltr::other[count]; int cfilter = custfltr::other[count];
if (cfilter == filter) if (cfilter == filter)
{ {
str = string_format("@custom%d %s", count + 1, text[filter]); str = string_format("@custom%d %s", count + 1, str);
x1t -= text_sign; x1t -= text_sign;
break; break;
} }
@ -1588,7 +1614,7 @@ float menu_select_game::draw_left_panel(float x1, float y1, float x2, float y2)
} }
else if (filter == main_filters::actual) else if (filter == main_filters::actual)
{ {
str.assign("_> ").append(text[filter]); str = std::string("_> ") + str;
x1t -= text_sign; x1t -= text_sign;
convert_command_glyph(str); convert_command_glyph(str);
} }
@ -1680,23 +1706,23 @@ void menu_select_game::make_topbox_text(std::string &line0, std::string &line1,
m_isabios); m_isabios);
std::string filtered; std::string filtered;
if (main_filters::actual == FILTER_CATEGORY && inifile.total() > 0) if (main_filters::actual == machine_filter::CATEGORY && inifile.total() > 0)
{ {
filtered = string_format(_("%1$s (%2$s - %3$s) - "), filtered = string_format(_("%1$s (%2$s - %3$s) - "),
main_filters::text[main_filters::actual], machine_filter::display_name(main_filters::actual),
inifile.get_file(), inifile.get_file(),
inifile.get_category()); inifile.get_category());
} }
else if (main_filters::actual == FILTER_MANUFACTURER) else if (main_filters::actual == machine_filter::MANUFACTURER)
{ {
filtered = string_format(_("%1$s (%2$s) - "), filtered = string_format(_("%1$s (%2$s) - "),
main_filters::text[main_filters::actual], machine_filter::display_name(main_filters::actual),
c_mnfct::ui[c_mnfct::actual]); c_mnfct::ui[c_mnfct::actual]);
} }
else if (main_filters::actual == FILTER_YEAR) else if (main_filters::actual == machine_filter::YEAR)
{ {
filtered = string_format(_("%1$s (%2$s) - "), filtered = string_format(_("%1$s (%2$s) - "),
main_filters::text[main_filters::actual], machine_filter::display_name(main_filters::actual),
c_year::ui[c_year::actual]); c_year::ui[c_year::actual]);
} }

View File

@ -9,7 +9,6 @@
***************************************************************************/ ***************************************************************************/
#include "emu.h" #include "emu.h"
#include "ui/selmenu.h" #include "ui/selmenu.h"
#include "ui/icorender.h" #include "ui/icorender.h"

View File

@ -117,6 +117,7 @@ protected:
template <typename T> bool select_bios(T const &driver, bool inlist); template <typename T> bool select_bios(T const &driver, bool inlist);
bool select_part(software_info const &info, ui_software_info const &ui_info); bool select_part(software_info const &info, ui_software_info const &ui_info);
int l_hover, l_sw_hover;
int visible_items; int visible_items;
void *m_prev_selected; void *m_prev_selected;
int m_total_lines; int m_total_lines;

View File

@ -9,7 +9,6 @@
***************************************************************************/ ***************************************************************************/
#include "emu.h" #include "emu.h"
#include "ui/selsoft.h" #include "ui/selsoft.h"
#include "ui/ui.h" #include "ui/ui.h"
@ -90,10 +89,10 @@ bool compare_software(ui_software_info a, ui_software_info b)
menu_select_software::menu_select_software(mame_ui_manager &mui, render_container &container, const game_driver *driver) menu_select_software::menu_select_software(mame_ui_manager &mui, render_container &container, const game_driver *driver)
: menu_select_launch(mui, container, true) : menu_select_launch(mui, container, true)
, m_filter_type(software_filter::ALL)
{ {
reselect_last::reselect(false); reselect_last::reselect(false);
sw_filters::actual = 0;
highlight = 0; highlight = 0;
m_driver = driver; m_driver = driver;
@ -132,8 +131,7 @@ void menu_select_software::handle()
// process the menu // process the menu
const event *menu_event = process(PROCESS_LR_REPEAT); const event *menu_event = process(PROCESS_LR_REPEAT);
if (menu_event)
if (menu_event && menu_event->itemref)
{ {
if (dismiss_error()) if (dismiss_error())
{ {
@ -142,16 +140,16 @@ void menu_select_software::handle()
else if (menu_event->iptkey == IPT_UI_SELECT) else if (menu_event->iptkey == IPT_UI_SELECT)
{ {
// handle selections // handle selections
if (get_focus() == focused_menu::MAIN) if (get_focus() == focused_menu::LEFT)
{
inkey_select(menu_event);
}
else if (get_focus() == focused_menu::LEFT)
{ {
l_sw_hover = highlight; l_sw_hover = highlight;
check_filter = true; check_filter = true;
m_prev_selected = nullptr; m_prev_selected = nullptr;
} }
else if ((get_focus() == focused_menu::MAIN) && menu_event->itemref)
{
inkey_select(menu_event);
}
} }
else if (menu_event->iptkey == IPT_UI_LEFT) else if (menu_event->iptkey == IPT_UI_LEFT)
{ {
@ -187,26 +185,6 @@ void menu_select_software::handle()
m_topline_datsview = 0; m_topline_datsview = 0;
} }
} }
else if (menu_event->iptkey == IPT_UI_UP_FILTER && highlight > UI_SW_FIRST)
{
// handle UI_UP_FILTER
highlight--;
}
else if (menu_event->iptkey == IPT_UI_DOWN_FILTER && highlight < UI_SW_LAST)
{
// handle UI_DOWN_FILTER
highlight++;
}
else if (menu_event->iptkey == IPT_UI_DATS)
{
// handle UI_DATS
ui_software_info *ui_swinfo = (ui_software_info *)menu_event->itemref;
if (ui_swinfo->startempty == 1 && mame_machine_manager::instance()->lua()->call_plugin_check<const char *>("data_list", ui_swinfo->driver->name, true))
menu::stack_push<menu_dats_view>(ui(), container(), ui_swinfo->driver);
else if (mame_machine_manager::instance()->lua()->call_plugin_check<const char *>("data_list", std::string(ui_swinfo->shortname).append(1, ',').append(ui_swinfo->listname).c_str()) || !ui_swinfo->usage.empty())
menu::stack_push<menu_dats_view>(ui(), container(), ui_swinfo);
}
else if (menu_event->iptkey == IPT_UI_LEFT_PANEL) else if (menu_event->iptkey == IPT_UI_LEFT_PANEL)
{ {
// handle UI_LEFT_PANEL // handle UI_LEFT_PANEL
@ -217,37 +195,15 @@ void menu_select_software::handle()
// handle UI_RIGHT_PANEL // handle UI_RIGHT_PANEL
ui_globals::rpanel = RP_INFOS; ui_globals::rpanel = RP_INFOS;
} }
else if (menu_event->iptkey == IPT_UI_CANCEL && !m_search.empty()) else if (menu_event->iptkey == IPT_UI_UP_FILTER && highlight > software_filter::FIRST)
{ {
// escape pressed with non-empty text clears the text // handle UI_UP_FILTER
m_search.clear(); highlight--;
reset(reset_options::SELECT_FIRST);
} }
else if (menu_event->iptkey == IPT_UI_FAVORITES) else if (menu_event->iptkey == IPT_UI_DOWN_FILTER && highlight < software_filter::LAST)
{ {
// handle UI_FAVORITES // handle UI_DOWN_FILTER
ui_software_info *swinfo = (ui_software_info *)menu_event->itemref; highlight++;
if ((uintptr_t)swinfo > 2)
{
favorite_manager &mfav = mame_machine_manager::instance()->favorite();
if (!mfav.isgame_favorite(*swinfo))
{
mfav.add_favorite_game(*swinfo);
machine().popmessage(_("%s\n added to favorites list."), swinfo->longname.c_str());
}
else
{
machine().popmessage(_("%s\n removed from favorites list."), swinfo->longname.c_str());
mfav.remove_favorite_game();
}
}
}
else if (menu_event->iptkey == IPT_SPECIAL)
{
// typed characters append to the buffer
inkey_special(menu_event);
} }
else if (menu_event->iptkey == IPT_OTHER) else if (menu_event->iptkey == IPT_OTHER)
{ {
@ -259,74 +215,51 @@ void menu_select_software::handle()
{ {
inkey_navigation(); inkey_navigation();
} }
} else if (menu_event->itemref)
{
if (menu_event->iptkey == IPT_UI_DATS)
{
// handle UI_DATS
ui_software_info *ui_swinfo = (ui_software_info *)menu_event->itemref;
if (menu_event && !menu_event->itemref) if (ui_swinfo->startempty == 1 && mame_machine_manager::instance()->lua()->call_plugin_check<const char *>("data_list", ui_swinfo->driver->name, true))
{ menu::stack_push<menu_dats_view>(ui(), container(), ui_swinfo->driver);
if (menu_event->iptkey == IPT_UI_CONFIGURE) else if (mame_machine_manager::instance()->lua()->call_plugin_check<const char *>("data_list", std::string(ui_swinfo->shortname).append(1, ',').append(ui_swinfo->listname).c_str()) || !ui_swinfo->usage.empty())
{ menu::stack_push<menu_dats_view>(ui(), container(), ui_swinfo);
inkey_navigation();
}
else if (menu_event->iptkey == IPT_UI_LEFT)
{
// handle UI_LEFT
if (ui_globals::rpanel == RP_IMAGES && ui_globals::curimage_view > FIRST_VIEW)
{
// Images
ui_globals::curimage_view--;
ui_globals::switch_image = true;
ui_globals::default_image = false;
} }
else if (ui_globals::rpanel == RP_INFOS && ui_globals::cur_sw_dats_view > 0) else if (menu_event->iptkey == IPT_UI_CANCEL && !m_search.empty())
{ {
// Infos // escape pressed with non-empty text clears the text
ui_globals::cur_sw_dats_view--; m_search.clear();
m_topline_datsview = 0; reset(reset_options::SELECT_FIRST);
} }
} else if (menu_event->iptkey == IPT_UI_FAVORITES)
else if (menu_event->iptkey == IPT_UI_RIGHT)
{
// handle UI_RIGHT
if (ui_globals::rpanel == RP_IMAGES && ui_globals::curimage_view < LAST_VIEW)
{ {
// Images // handle UI_FAVORITES
ui_globals::curimage_view++; ui_software_info *swinfo = (ui_software_info *)menu_event->itemref;
ui_globals::switch_image = true;
ui_globals::default_image = false; if ((uintptr_t)swinfo > 2)
{
favorite_manager &mfav = mame_machine_manager::instance()->favorite();
if (!mfav.isgame_favorite(*swinfo))
{
mfav.add_favorite_game(*swinfo);
machine().popmessage(_("%s\n added to favorites list."), swinfo->longname.c_str());
}
else
{
machine().popmessage(_("%s\n removed from favorites list."), swinfo->longname.c_str());
mfav.remove_favorite_game();
}
}
} }
else if (ui_globals::rpanel == RP_INFOS && ui_globals::cur_sw_dats_view < ui_globals::cur_sw_dats_total) else if (menu_event->iptkey == IPT_SPECIAL)
{ {
// Infos // typed characters append to the buffer
ui_globals::cur_sw_dats_view++; inkey_special(menu_event);
m_topline_datsview = 0;
} }
} }
else if (menu_event->iptkey == IPT_UI_LEFT_PANEL)
{
// handle UI_LEFT_PANEL
ui_globals::rpanel = RP_IMAGES;
}
else if (menu_event->iptkey == IPT_UI_RIGHT_PANEL)
{
// handle UI_RIGHT_PANEL
ui_globals::rpanel = RP_INFOS;
}
else if (menu_event->iptkey == IPT_UI_UP_FILTER && highlight > UI_SW_FIRST)
{
// handle UI_UP_FILTER
highlight--;
}
else if (menu_event->iptkey == IPT_UI_DOWN_FILTER && highlight < UI_SW_LAST)
{
// handle UI_DOWN_FILTER
highlight++;
}
else if (menu_event->iptkey == IPT_OTHER && get_focus() == focused_menu::LEFT)
{
l_sw_hover = highlight;
check_filter = true;
m_prev_selected = nullptr;
}
} }
// if we're in an error state, overlay an error message // if we're in an error state, overlay an error message
@ -336,29 +269,38 @@ void menu_select_software::handle()
if (check_filter) if (check_filter)
{ {
m_search.clear(); m_search.clear();
auto handler =
[this] (uint16_t &actual, int selection)
{
actual = selection;
m_filter_type = software_filter::type(l_sw_hover);
reset(reset_options::SELECT_FIRST);
};
using std::placeholders::_1;
switch (l_sw_hover) switch (l_sw_hover)
{ {
case UI_SW_REGION: case software_filter::REGION:
menu::stack_push<menu_selector>(ui(), container(), m_filter.region.ui, m_filter.region.actual, menu_selector::SOFTWARE, l_sw_hover); menu::stack_push<menu_selector>(ui(), container(), std::vector<std::string>(m_filter.region.ui), m_filter.region.actual, std::bind(handler, std::ref(m_filter.region.actual), _1));
break; break;
case UI_SW_YEARS: case software_filter::YEARS:
menu::stack_push<menu_selector>(ui(), container(), m_filter.year.ui, m_filter.year.actual, menu_selector::SOFTWARE, l_sw_hover); menu::stack_push<menu_selector>(ui(), container(), std::vector<std::string>(m_filter.year.ui), m_filter.year.actual, std::bind(handler, std::ref(m_filter.year.actual), _1));
break; break;
case UI_SW_LIST: case software_filter::LIST:
menu::stack_push<menu_selector>(ui(), container(), m_filter.swlist.description, m_filter.swlist.actual, menu_selector::SOFTWARE, l_sw_hover); menu::stack_push<menu_selector>(ui(), container(), std::vector<std::string>(m_filter.swlist.description), m_filter.swlist.actual, std::bind(handler, std::ref(m_filter.swlist.actual), _1));
break; break;
case UI_SW_TYPE: case software_filter::DEVICE_TYPE:
menu::stack_push<menu_selector>(ui(), container(), m_filter.type.ui, m_filter.type.actual, menu_selector::SOFTWARE, l_sw_hover); menu::stack_push<menu_selector>(ui(), container(), std::vector<std::string>(m_filter.type.ui), m_filter.type.actual, std::bind(handler, std::ref(m_filter.type.actual), _1));
break; break;
case UI_SW_PUBLISHERS: case software_filter::PUBLISHERS:
menu::stack_push<menu_selector>(ui(), container(), m_filter.publisher.ui, m_filter.publisher.actual, menu_selector::SOFTWARE, l_sw_hover); menu::stack_push<menu_selector>(ui(), container(), std::vector<std::string>(m_filter.publisher.ui), m_filter.publisher.actual, std::bind(handler, std::ref(m_filter.publisher.actual), _1));
break; break;
case UI_SW_CUSTOM: case software_filter::CUSTOM:
sw_filters::actual = l_sw_hover; m_filter_type = software_filter::type(l_sw_hover);
menu::stack_push<menu_swcustom_filter>(ui(), container(), m_driver, m_filter); menu::stack_push<menu_swcustom_filter>(ui(), container(), m_driver, m_filter);
break; break;
default: default:
sw_filters::actual = l_sw_hover; m_filter_type = software_filter::type(l_sw_hover);
reset(reset_options::SELECT_FIRST); reset(reset_options::SELECT_FIRST);
break; break;
} }
@ -393,35 +335,35 @@ void menu_select_software::populate(float &customtop, float &custombottom)
m_displaylist.clear(); m_displaylist.clear();
m_tmp.clear(); m_tmp.clear();
switch (sw_filters::actual) switch (m_filter_type)
{ {
case UI_SW_PUBLISHERS: case software_filter::PUBLISHERS:
build_list(m_tmp, m_filter.publisher.ui[m_filter.publisher.actual].c_str()); build_list(m_tmp, m_filter.publisher.ui[m_filter.publisher.actual].c_str());
break; break;
case UI_SW_LIST: case software_filter::LIST:
build_list(m_tmp, m_filter.swlist.name[m_filter.swlist.actual].c_str()); build_list(m_tmp, m_filter.swlist.name[m_filter.swlist.actual].c_str());
break; break;
case UI_SW_YEARS: case software_filter::YEARS:
build_list(m_tmp, m_filter.year.ui[m_filter.year.actual].c_str()); build_list(m_tmp, m_filter.year.ui[m_filter.year.actual].c_str());
break; break;
case UI_SW_TYPE: case software_filter::DEVICE_TYPE:
build_list(m_tmp, m_filter.type.ui[m_filter.type.actual].c_str()); build_list(m_tmp, m_filter.type.ui[m_filter.type.actual].c_str());
break; break;
case UI_SW_REGION: case software_filter::REGION:
build_list(m_tmp, m_filter.region.ui[m_filter.region.actual].c_str()); build_list(m_tmp, m_filter.region.ui[m_filter.region.actual].c_str());
break; break;
case UI_SW_CUSTOM: case software_filter::CUSTOM:
build_custom(); build_custom();
break; break;
default: default:
build_list(m_tmp); build_list(m_tmp);
break; break;
} }
// iterate over entries // iterate over entries
@ -665,23 +607,27 @@ void menu_select_software::load_sw_custom_filters()
file.gets(buffer, MAX_CHAR_INFO); file.gets(buffer, MAX_CHAR_INFO);
pb = strchr(buffer, '=') + 2; pb = strchr(buffer, '=') + 2;
for (int y = 0; y < sw_filters::length; ++y) for (software_filter::type y = software_filter::FIRST; y < software_filter::COUNT; ++y)
if (!strncmp(pb, sw_filters::text[y], strlen(sw_filters::text[y]))) {
char const *const name(software_filter::config_name(y));
if (!strncmp(pb, name, strlen(name)))
{ {
sw_custfltr::main = y; sw_custfltr::main = y;
break; break;
} }
}
for (int x = 1; x <= sw_custfltr::numother; ++x) for (int x = 1; x <= sw_custfltr::numother; ++x)
{ {
file.gets(buffer, MAX_CHAR_INFO); file.gets(buffer, MAX_CHAR_INFO);
char *cb = strchr(buffer, '=') + 2; char *cb = strchr(buffer, '=') + 2;
for (int y = 0; y < sw_filters::length; y++) for (software_filter::type y = software_filter::FIRST; y < software_filter::COUNT; ++y)
{ {
if (!strncmp(cb, sw_filters::text[y], strlen(sw_filters::text[y]))) char const *const name(software_filter::config_name(y));
if (!strncmp(cb, name, strlen(name)))
{ {
sw_custfltr::other[x] = y; sw_custfltr::other[x] = y;
if (y == UI_SW_PUBLISHERS) if (y == software_filter::PUBLISHERS)
{ {
file.gets(buffer, MAX_CHAR_INFO); file.gets(buffer, MAX_CHAR_INFO);
char *ab = strchr(buffer, '=') + 2; char *ab = strchr(buffer, '=') + 2;
@ -689,7 +635,7 @@ void menu_select_software::load_sw_custom_filters()
if (!strncmp(ab, m_filter.publisher.ui[z].c_str(), m_filter.publisher.ui[z].length())) if (!strncmp(ab, m_filter.publisher.ui[z].c_str(), m_filter.publisher.ui[z].length()))
sw_custfltr::mnfct[x] = z; sw_custfltr::mnfct[x] = z;
} }
else if (y == UI_SW_YEARS) else if (y == software_filter::YEARS)
{ {
file.gets(buffer, MAX_CHAR_INFO); file.gets(buffer, MAX_CHAR_INFO);
char *db = strchr(buffer, '=') + 2; char *db = strchr(buffer, '=') + 2;
@ -697,7 +643,7 @@ void menu_select_software::load_sw_custom_filters()
if (!strncmp(db, m_filter.year.ui[z].c_str(), m_filter.year.ui[z].length())) if (!strncmp(db, m_filter.year.ui[z].c_str(), m_filter.year.ui[z].length()))
sw_custfltr::year[x] = z; sw_custfltr::year[x] = z;
} }
else if (y == UI_SW_LIST) else if (y == software_filter::LIST)
{ {
file.gets(buffer, MAX_CHAR_INFO); file.gets(buffer, MAX_CHAR_INFO);
char *gb = strchr(buffer, '=') + 2; char *gb = strchr(buffer, '=') + 2;
@ -705,7 +651,7 @@ void menu_select_software::load_sw_custom_filters()
if (!strncmp(gb, m_filter.swlist.name[z].c_str(), m_filter.swlist.name[z].length())) if (!strncmp(gb, m_filter.swlist.name[z].c_str(), m_filter.swlist.name[z].length()))
sw_custfltr::list[x] = z; sw_custfltr::list[x] = z;
} }
else if (y == UI_SW_TYPE) else if (y == software_filter::DEVICE_TYPE)
{ {
file.gets(buffer, MAX_CHAR_INFO); file.gets(buffer, MAX_CHAR_INFO);
char *fb = strchr(buffer, '=') + 2; char *fb = strchr(buffer, '=') + 2;
@ -713,7 +659,7 @@ void menu_select_software::load_sw_custom_filters()
if (!strncmp(fb, m_filter.type.ui[z].c_str(), m_filter.type.ui[z].length())) if (!strncmp(fb, m_filter.type.ui[z].c_str(), m_filter.type.ui[z].length()))
sw_custfltr::type[x] = z; sw_custfltr::type[x] = z;
} }
else if (y == UI_SW_REGION) else if (y == software_filter::REGION)
{ {
file.gets(buffer, MAX_CHAR_INFO); file.gets(buffer, MAX_CHAR_INFO);
char *eb = strchr(buffer, '=') + 2; char *eb = strchr(buffer, '=') + 2;
@ -813,7 +759,7 @@ void menu_select_software::build_list(std::vector<ui_software_info *> &s_drivers
{ {
if (s_drivers.empty() && filter == -1) if (s_drivers.empty() && filter == -1)
{ {
filter = sw_filters::actual; filter = m_filter_type;
s_drivers = m_sortedlist; s_drivers = m_sortedlist;
} }
@ -822,42 +768,42 @@ void menu_select_software::build_list(std::vector<ui_software_info *> &s_drivers
{ {
switch (filter) switch (filter)
{ {
case UI_SW_PARENTS: case software_filter::PARENTS:
if (s_driver->parentname.empty()) if (s_driver->parentname.empty())
m_displaylist.push_back(s_driver); m_displaylist.push_back(s_driver);
break; break;
case UI_SW_CLONES: case software_filter::CLONES:
if (!s_driver->parentname.empty()) if (!s_driver->parentname.empty())
m_displaylist.push_back(s_driver); m_displaylist.push_back(s_driver);
break; break;
case UI_SW_AVAILABLE: case software_filter::AVAILABLE:
if (s_driver->available) if (s_driver->available)
m_displaylist.push_back(s_driver); m_displaylist.push_back(s_driver);
break; break;
case UI_SW_UNAVAILABLE: case software_filter::UNAVAILABLE:
if (!s_driver->available) if (!s_driver->available)
m_displaylist.push_back(s_driver); m_displaylist.push_back(s_driver);
break; break;
case UI_SW_SUPPORTED: case software_filter::SUPPORTED:
if (s_driver->supported == SOFTWARE_SUPPORTED_YES) if (s_driver->supported == SOFTWARE_SUPPORTED_YES)
m_displaylist.push_back(s_driver); m_displaylist.push_back(s_driver);
break; break;
case UI_SW_PARTIAL_SUPPORTED: case software_filter::PARTIAL_SUPPORTED:
if (s_driver->supported == SOFTWARE_SUPPORTED_PARTIAL) if (s_driver->supported == SOFTWARE_SUPPORTED_PARTIAL)
m_displaylist.push_back(s_driver); m_displaylist.push_back(s_driver);
break; break;
case UI_SW_UNSUPPORTED: case software_filter::UNSUPPORTED:
if (s_driver->supported == SOFTWARE_SUPPORTED_NO) if (s_driver->supported == SOFTWARE_SUPPORTED_NO)
m_displaylist.push_back(s_driver); m_displaylist.push_back(s_driver);
break; break;
case UI_SW_REGION: case software_filter::REGION:
{ {
std::string name = m_filter.region.getname(s_driver->longname); std::string name = m_filter.region.getname(s_driver->longname);
@ -866,7 +812,7 @@ void menu_select_software::build_list(std::vector<ui_software_info *> &s_drivers
} }
break; break;
case UI_SW_PUBLISHERS: case software_filter::PUBLISHERS:
{ {
std::string name = m_filter.publisher.getname(s_driver->publisher); std::string name = m_filter.publisher.getname(s_driver->publisher);
@ -875,17 +821,17 @@ void menu_select_software::build_list(std::vector<ui_software_info *> &s_drivers
} }
break; break;
case UI_SW_YEARS: case software_filter::YEARS:
if(s_driver->year == filter_text) if(s_driver->year == filter_text)
m_displaylist.push_back(s_driver); m_displaylist.push_back(s_driver);
break; break;
case UI_SW_LIST: case software_filter::LIST:
if(s_driver->listname == filter_text) if(s_driver->listname == filter_text)
m_displaylist.push_back(s_driver); m_displaylist.push_back(s_driver);
break; break;
case UI_SW_TYPE: case software_filter::DEVICE_TYPE:
if(s_driver->devicetype == filter_text) if(s_driver->devicetype == filter_text)
m_displaylist.push_back(s_driver); m_displaylist.push_back(s_driver);
break; break;
@ -947,30 +893,30 @@ void menu_select_software::build_custom()
for (int count = 1; count <= sw_custfltr::numother; ++count) for (int count = 1; count <= sw_custfltr::numother; ++count)
{ {
int filter = sw_custfltr::other[count]; software_filter::type filter = sw_custfltr::other[count];
s_drivers = m_displaylist; s_drivers = m_displaylist;
m_displaylist.clear(); m_displaylist.clear();
switch (filter) switch (filter)
{ {
case UI_SW_YEARS: case software_filter::YEARS:
build_list(s_drivers, m_filter.year.ui[sw_custfltr::year[count]].c_str(), filter); build_list(s_drivers, m_filter.year.ui[sw_custfltr::year[count]].c_str(), filter);
break; break;
case UI_SW_LIST: case software_filter::LIST:
build_list(s_drivers, m_filter.swlist.name[sw_custfltr::list[count]].c_str(), filter); build_list(s_drivers, m_filter.swlist.name[sw_custfltr::list[count]].c_str(), filter);
break; break;
case UI_SW_TYPE: case software_filter::DEVICE_TYPE:
build_list(s_drivers, m_filter.type.ui[sw_custfltr::type[count]].c_str(), filter); build_list(s_drivers, m_filter.type.ui[sw_custfltr::type[count]].c_str(), filter);
break; break;
case UI_SW_PUBLISHERS: case software_filter::PUBLISHERS:
build_list(s_drivers, m_filter.publisher.ui[sw_custfltr::mnfct[count]].c_str(), filter); build_list(s_drivers, m_filter.publisher.ui[sw_custfltr::mnfct[count]].c_str(), filter);
break; break;
case UI_SW_REGION: case software_filter::REGION:
build_list(s_drivers, m_filter.region.ui[sw_custfltr::region[count]].c_str(), filter); build_list(s_drivers, m_filter.region.ui[sw_custfltr::region[count]].c_str(), filter);
break; break;
default: default:
build_list(s_drivers, nullptr, filter); build_list(s_drivers, nullptr, filter);
break; break;
} }
} }
} }
@ -989,26 +935,24 @@ float menu_select_software::draw_left_panel(float x1, float y1, float x2, float
float l_height = ui().get_line_height(); float l_height = ui().get_line_height();
float line_height = l_height * text_size; float line_height = l_height * text_size;
float left_width = 0.0f; float left_width = 0.0f;
int text_lenght = sw_filters::length; int line_count = software_filter::COUNT;
int afilter = sw_filters::actual;
int phover = HOVER_SW_FILTER_FIRST; int phover = HOVER_SW_FILTER_FIRST;
const char **text = sw_filters::text;
float sc = y2 - y1 - (2.0f * UI_BOX_TB_BORDER); float sc = y2 - y1 - (2.0f * UI_BOX_TB_BORDER);
if ((text_lenght * line_height) > sc) if ((line_count * line_height) > sc)
{ {
float lm = sc / (text_lenght); float lm = sc / (line_count);
text_size = lm / l_height; text_size = lm / l_height;
line_height = l_height * text_size; line_height = l_height * text_size;
} }
float text_sign = ui().get_string_width("_# ", text_size); float text_sign = ui().get_string_width("_# ", text_size);
for (int x = 0; x < text_lenght; ++x) for (software_filter::type x = software_filter::FIRST; x < software_filter::COUNT; ++x)
{ {
float total_width; float total_width;
// compute width of left hand side // compute width of left hand side
total_width = ui().get_string_width(text[x], text_size); total_width = ui().get_string_width(software_filter::display_name(x), text_size);
total_width += text_sign; total_width += text_sign;
// track the maximum // track the maximum
@ -1025,9 +969,9 @@ float menu_select_software::draw_left_panel(float x1, float y1, float x2, float
y1 += UI_BOX_TB_BORDER; y1 += UI_BOX_TB_BORDER;
y2 -= UI_BOX_TB_BORDER; y2 -= UI_BOX_TB_BORDER;
for (int filter = 0; filter < text_lenght; ++filter) for (software_filter::type filter = software_filter::FIRST; filter < software_filter::COUNT; ++filter)
{ {
std::string str(text[filter]); std::string str(software_filter::display_name(filter));
rgb_t bgcolor = UI_TEXT_BG_COLOR; rgb_t bgcolor = UI_TEXT_BG_COLOR;
rgb_t fgcolor = UI_TEXT_COLOR; rgb_t fgcolor = UI_TEXT_COLOR;
@ -1051,11 +995,11 @@ float menu_select_software::draw_left_panel(float x1, float y1, float x2, float
} }
float x1t = x1 + text_sign; float x1t = x1 + text_sign;
if (afilter == UI_SW_CUSTOM) if (m_filter_type == software_filter::CUSTOM)
{ {
if (filter == sw_custfltr::main) if (filter == sw_custfltr::main)
{ {
str.assign("@custom1 ").append(text[filter]); str = std::string("@custom1 ") + str;
x1t -= text_sign; x1t -= text_sign;
} }
else else
@ -1065,7 +1009,7 @@ float menu_select_software::draw_left_panel(float x1, float y1, float x2, float
int cfilter = sw_custfltr::other[count]; int cfilter = sw_custfltr::other[count];
if (cfilter == filter) if (cfilter == filter)
{ {
str = string_format("@custom%d %s", count + 1, text[filter]); str = string_format("@custom%d %s", count + 1, str);
x1t -= text_sign; x1t -= text_sign;
break; break;
} }
@ -1073,9 +1017,9 @@ float menu_select_software::draw_left_panel(float x1, float y1, float x2, float
} }
convert_command_glyph(str); convert_command_glyph(str);
} }
else if (filter == sw_filters::actual) else if (filter == m_filter_type)
{ {
str.assign("_> ").append(text[filter]); str = std::string("_> ") + str;
x1t -= text_sign; x1t -= text_sign;
convert_command_glyph(str); convert_command_glyph(str);
} }
@ -1154,15 +1098,15 @@ void menu_select_software::make_topbox_text(std::string &line0, std::string &lin
line1 = string_format(_("Driver: \"%1$s\" software list "), m_driver->type.fullname()); line1 = string_format(_("Driver: \"%1$s\" software list "), m_driver->type.fullname());
std::string filtered; std::string filtered;
if (sw_filters::actual == UI_SW_REGION && m_filter.region.ui.size() != 0) if (m_filter_type == software_filter::REGION && m_filter.region.ui.size())
filtered = string_format(_("Region: %1$s -"), m_filter.region.ui[m_filter.region.actual]); filtered = string_format(_("Region: %1$s -"), m_filter.region.ui[m_filter.region.actual]);
else if (sw_filters::actual == UI_SW_PUBLISHERS) else if (m_filter_type == software_filter::PUBLISHERS)
filtered = string_format(_("Publisher: %1$s -"), m_filter.publisher.ui[m_filter.publisher.actual]); filtered = string_format(_("Publisher: %1$s -"), m_filter.publisher.ui[m_filter.publisher.actual]);
else if (sw_filters::actual == UI_SW_YEARS) else if (m_filter_type == software_filter::YEARS)
filtered = string_format(_("Year: %1$s -"), m_filter.year.ui[m_filter.year.actual]); filtered = string_format(_("Year: %1$s -"), m_filter.year.ui[m_filter.year.actual]);
else if (sw_filters::actual == UI_SW_LIST) else if (m_filter_type == software_filter::LIST)
filtered = string_format(_("Software List: %1$s -"), m_filter.swlist.description[m_filter.swlist.actual]); filtered = string_format(_("Software List: %1$s -"), m_filter.swlist.description[m_filter.swlist.actual]);
else if (sw_filters::actual == UI_SW_TYPE) else if (m_filter_type == software_filter::DEVICE_TYPE)
filtered = string_format(_("Device type: %1$s -"), m_filter.type.ui[m_filter.type.actual]); filtered = string_format(_("Device type: %1$s -"), m_filter.type.ui[m_filter.type.actual]);
line2 = string_format(_("%s Search: %s_"), filtered, m_search); line2 = string_format(_("%s Search: %s_"), filtered, m_search);

View File

@ -30,11 +30,12 @@ protected:
private: private:
enum { VISIBLE_GAMES_IN_SEARCH = 200 }; enum { VISIBLE_GAMES_IN_SEARCH = 200 };
std::string m_search; std::string m_search;
const game_driver *m_driver; const game_driver *m_driver;
bool m_has_empty_start; bool m_has_empty_start;
s_filter m_filter; s_filter m_filter;
int highlight; software_filter::type m_filter_type;
int highlight;
virtual void populate(float &customtop, float &custombottom) override; virtual void populate(float &customtop, float &custombottom) override;
virtual void handle() override; virtual void handle() override;

View File

@ -97,7 +97,13 @@ void menu_sound_options::handle()
for (int index = 0; index < total; index++) for (int index = 0; index < total; index++)
s_sel[index] = std::to_string(m_sound_rate[index]); s_sel[index] = std::to_string(m_sound_rate[index]);
menu::stack_push<menu_selector>(ui(), container(), s_sel, m_cur_rates); menu::stack_push<menu_selector>(
ui(), container(), std::move(s_sel), m_cur_rates,
[this] (int selection)
{
m_cur_rates = selection;
reset(reset_options::REMEMBER_REF);
});
} }
break; break;

View File

@ -11,9 +11,85 @@
#include "emu.h" #include "emu.h"
#include "ui/utils.h" #include "ui/utils.h"
#include "language.h"
#include "softlist.h" #include "softlist.h"
namespace ui {
namespace {
constexpr char const *machine_filter_names[machine_filter::COUNT] = {
__("Unfiltered"),
__("Available"),
__("Unavailable"),
__("Working"),
__("Not Working"),
__("Mechanical"),
__("Not Mechanical"),
__("Category"),
__("Favorites"),
__("BIOS"),
__("Parents"),
__("Clones"),
__("Manufacturers"),
__("Release Years"),
__("Save Supported"),
__("Save Unsupported"),
__("CHD Required"),
__("No CHD Required"),
__("Vertical Screen"),
__("Horizontal Screen"),
__("Custom Filter") };
constexpr char const *software_filter_names[software_filter::COUNT] = {
__("Unfiltered"),
__("Available"),
__("Unavailable"),
__("Parents"),
__("Clones"),
__("Release Years"),
__("Publishers"),
__("Supported"),
__("Partially Supported"),
__("Unsupported"),
__("Release Region"),
__("Device Type"),
__("Software List"),
__("Custom Filter") };
} // anonymous namespace
char const *machine_filter::config_name(type n)
{
assert(COUNT > n);
return machine_filter_names[n];
}
char const *machine_filter::display_name(type n)
{
assert(COUNT > n);
return _(machine_filter_names[n]);
}
char const *software_filter::config_name(type n)
{
assert(COUNT > n);
return software_filter_names[n];
}
char const *software_filter::display_name(type n)
{
assert(COUNT > n);
return _(software_filter_names[n]);
}
} // namesapce ui
extern const char UI_VERSION_TAG[]; extern const char UI_VERSION_TAG[];
const char UI_VERSION_TAG[] = "# UI INFO "; const char UI_VERSION_TAG[] = "# UI INFO ";
@ -27,17 +103,7 @@ std::vector<std::string> c_mnfct::ui;
std::unordered_map<std::string, int> c_mnfct::uimap; std::unordered_map<std::string, int> c_mnfct::uimap;
// Main filters // Main filters
uint16_t main_filters::actual = 0; ui::machine_filter::type main_filters::actual = ui::machine_filter::ALL;
const char *main_filters::text[] = { "All", "Available", "Unavailable", "Working", "Not Working", "Mechanical", "Not Mechanical",
"Category", "Favorites", "BIOS", "Parents", "Clones", "Manufacturers", "Years", "Support Save",
"Not Support Save", "CHD", "No CHD", "Vertical", "Horizontal", "Custom" };
size_t main_filters::length = ARRAY_LENGTH(main_filters::text);
// Software filters
uint16_t sw_filters::actual = 0;
const char *sw_filters::text[] = { "All", "Available", "Unavailable", "Parents", "Clones", "Years", "Publishers", "Supported",
"Partial Supported", "Unsupported", "Region", "Device Type", "Software List", "Custom" };
size_t sw_filters::length = ARRAY_LENGTH(sw_filters::text);
// Globals // Globals
uint8_t ui_globals::rpanel = 0; uint8_t ui_globals::rpanel = 0;
@ -56,17 +122,17 @@ uint16_t ui_globals::panels_status = 0;
bool ui_globals::has_icons = false; bool ui_globals::has_icons = false;
// Custom filter // Custom filter
uint16_t custfltr::main = 0; ui::machine_filter::type custfltr::main = ui::machine_filter::ALL;
uint16_t custfltr::numother = 0; uint16_t custfltr::numother = 0;
uint16_t custfltr::other[MAX_CUST_FILTER]; ui::machine_filter::type custfltr::other[MAX_CUST_FILTER];
uint16_t custfltr::mnfct[MAX_CUST_FILTER]; uint16_t custfltr::mnfct[MAX_CUST_FILTER];
uint16_t custfltr::year[MAX_CUST_FILTER]; uint16_t custfltr::year[MAX_CUST_FILTER];
uint16_t custfltr::screen[MAX_CUST_FILTER]; uint16_t custfltr::screen[MAX_CUST_FILTER];
// Custom filter // Custom filter
uint16_t sw_custfltr::main = 0; ui::software_filter::type sw_custfltr::main = ui::software_filter::ALL;
uint16_t sw_custfltr::numother = 0; uint16_t sw_custfltr::numother = 0;
uint16_t sw_custfltr::other[MAX_CUST_FILTER]; ui::software_filter::type sw_custfltr::other[MAX_CUST_FILTER];
uint16_t sw_custfltr::mnfct[MAX_CUST_FILTER]; uint16_t sw_custfltr::mnfct[MAX_CUST_FILTER];
uint16_t sw_custfltr::year[MAX_CUST_FILTER]; uint16_t sw_custfltr::year[MAX_CUST_FILTER];
uint16_t sw_custfltr::region[MAX_CUST_FILTER]; uint16_t sw_custfltr::region[MAX_CUST_FILTER];

View File

@ -7,45 +7,91 @@
Internal UI user interface. Internal UI user interface.
***************************************************************************/ ***************************************************************************/
#ifndef MAME_FRONTEND_UI_UTILS_H
#define MAME_FRONTEND_UI_UTILS_H
#pragma once #pragma once
#ifndef __UI_UTILS_H__
#define __UI_UTILS_H__
#include "unicode.h" #include "unicode.h"
namespace ui {
class machine_filter
{
public:
enum type : uint16_t
{
ALL = 0,
AVAILABLE,
UNAVAILABLE,
WORKING,
NOT_WORKING,
MECHANICAL,
NOT_MECHANICAL,
CATEGORY,
FAVORITE,
BIOS,
PARENT,
CLONES,
MANUFACTURER,
YEAR,
SAVE,
NOSAVE,
CHD,
NOCHD,
VERTICAL,
HORIZONTAL,
CUSTOM,
COUNT,
FIRST = 0,
LAST = COUNT - 1
};
static char const *config_name(type n);
static char const *display_name(type n);
};
DECLARE_ENUM_INCDEC_OPERATORS(machine_filter::type)
class software_filter
{
public:
enum type : uint16_t
{
ALL = 0,
AVAILABLE,
UNAVAILABLE,
PARENTS,
CLONES,
YEARS,
PUBLISHERS,
SUPPORTED,
PARTIAL_SUPPORTED,
UNSUPPORTED,
REGION,
DEVICE_TYPE,
LIST,
CUSTOM,
COUNT,
FIRST = 0,
LAST = COUNT - 1
};
static char const *config_name(type n);
static char const *display_name(type n);
};
DECLARE_ENUM_INCDEC_OPERATORS(software_filter::type)
} // namespace ui
#define MAX_CHAR_INFO 256 #define MAX_CHAR_INFO 256
#define MAX_CUST_FILTER 8 #define MAX_CUST_FILTER 8
// GLOBAL ENUMERATORS
enum : uint16_t
{
FILTER_FIRST = 0,
FILTER_ALL = FILTER_FIRST,
FILTER_AVAILABLE,
FILTER_UNAVAILABLE,
FILTER_WORKING,
FILTER_NOT_WORKING,
FILTER_MECHANICAL,
FILTER_NOT_MECHANICAL,
FILTER_CATEGORY,
FILTER_FAVORITE,
FILTER_BIOS,
FILTER_PARENT,
FILTER_CLONES,
FILTER_MANUFACTURER,
FILTER_YEAR,
FILTER_SAVE,
FILTER_NOSAVE,
FILTER_CHD,
FILTER_NOCHD,
FILTER_VERTICAL,
FILTER_HORIZONTAL,
FILTER_CUSTOM,
FILTER_LAST = FILTER_CUSTOM
};
enum enum
{ {
FIRST_VIEW = 0, FIRST_VIEW = 0,
@ -84,26 +130,6 @@ enum
HIDE_BOTH HIDE_BOTH
}; };
enum : uint16_t
{
UI_SW_FIRST = 0,
UI_SW_ALL = UI_SW_FIRST,
UI_SW_AVAILABLE,
UI_SW_UNAVAILABLE,
UI_SW_PARENTS,
UI_SW_CLONES,
UI_SW_YEARS,
UI_SW_PUBLISHERS,
UI_SW_SUPPORTED,
UI_SW_PARTIAL_SUPPORTED,
UI_SW_UNSUPPORTED,
UI_SW_REGION,
UI_SW_TYPE,
UI_SW_LIST,
UI_SW_CUSTOM,
UI_SW_LAST = UI_SW_CUSTOM
};
enum enum
{ {
HOVER_DAT_UP = -1000, HOVER_DAT_UP = -1000,
@ -118,9 +144,9 @@ enum
HOVER_RPANEL_ARROW, HOVER_RPANEL_ARROW,
HOVER_LPANEL_ARROW, HOVER_LPANEL_ARROW,
HOVER_FILTER_FIRST, HOVER_FILTER_FIRST,
HOVER_FILTER_LAST = (HOVER_FILTER_FIRST) + 1 + FILTER_LAST, HOVER_FILTER_LAST = (HOVER_FILTER_FIRST) + ui::machine_filter::COUNT,
HOVER_SW_FILTER_FIRST, HOVER_SW_FILTER_FIRST,
HOVER_SW_FILTER_LAST = (HOVER_SW_FILTER_FIRST) + 1 + UI_SW_LAST, HOVER_SW_FILTER_LAST = (HOVER_SW_FILTER_FIRST) + ui::software_filter::COUNT,
HOVER_RP_FIRST, HOVER_RP_FIRST,
HOVER_RP_LAST = (HOVER_RP_FIRST) + 1 + RP_LAST HOVER_RP_LAST = (HOVER_RP_FIRST) + 1 + RP_LAST
}; };
@ -203,23 +229,14 @@ struct ui_globals
static bool has_icons; static bool has_icons;
}; };
#define main_struct(name) \ struct main_filters { static ui::machine_filter::type actual; };
struct name##_filters \
{ \
static uint16_t actual; \
static const char *text[]; \
static size_t length; \
};
main_struct(main);
main_struct(sw);
// Custom filter // Custom filter
struct custfltr struct custfltr
{ {
static uint16_t main; static ui::machine_filter::type main;
static uint16_t numother; static uint16_t numother;
static uint16_t other[MAX_CUST_FILTER]; static ui::machine_filter::type other[MAX_CUST_FILTER];
static uint16_t mnfct[MAX_CUST_FILTER]; static uint16_t mnfct[MAX_CUST_FILTER];
static uint16_t screen[MAX_CUST_FILTER]; static uint16_t screen[MAX_CUST_FILTER];
static uint16_t year[MAX_CUST_FILTER]; static uint16_t year[MAX_CUST_FILTER];
@ -228,9 +245,9 @@ struct custfltr
// Software custom filter // Software custom filter
struct sw_custfltr struct sw_custfltr
{ {
static uint16_t main; static ui::software_filter::type main;
static uint16_t numother; static uint16_t numother;
static uint16_t other[MAX_CUST_FILTER]; static ui::software_filter::type other[MAX_CUST_FILTER];
static uint16_t mnfct[MAX_CUST_FILTER]; static uint16_t mnfct[MAX_CUST_FILTER];
static uint16_t year[MAX_CUST_FILTER]; static uint16_t year[MAX_CUST_FILTER];
static uint16_t region[MAX_CUST_FILTER]; static uint16_t region[MAX_CUST_FILTER];
@ -295,4 +312,4 @@ bool input_character(std::string &buffer, char32_t unichar, F &&filter)
} }
#endif /* __UI_UTILS_H__ */ #endif // MAME_FRONTEND_UI_UTILS_H