diff options
author | Vas Crabb <cuavas@users.noreply.github.com> | 2022-06-11 21:47:19 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-11 21:47:19 +1000 |
commit | f47f9c3db3c7d20bea0526425cdbc469d5a10868 (patch) | |
tree | 4dd7ac860eb10169b511521eecb31b8760011434 /src/frontend/mame/ui/selector.cpp | |
parent | 5214d7f31c6e682315a7803484ade265130cfb6b (diff) |
ui, docs: Added menus to fill a couple of gaps, improved consistency. (#9915)
Added menus for controlling toggle inputs, and showing recognised input
devices and control state. Moved input menu options off main menu to a
submenu, as there are a lot of them now.
Moved menu heading drawing into base class, added headings to more
menus, and made headings more consistent with the menu items used to
reach them. Also made terminology more consistent.
Changed the default names for buttons and hat switches/D-pads to use
1-based numbering. DirectInput still returns 0-based button numbers for
some devices.
Removed local copy of MinGW xaudio2.h as it’s now included in the MSYS2
package. Also fixed building the DirectSound sound output module with
the SDL OSD on Windows - the Windows headers are sensitive to include
order.
Started adding documentation for menus, to hopefully help people find
menus they remember seeing but can't recall how to access.
For translators, this makes terminology more consistent. In particular:
* "Settings" is preferred over "configuration" in a number of places, as
the latter can be construed as referring specifically to settings
stored in .cfg files in the cfg_directory folder. Also, references to
saving machine configuration could be interpreted as relating to the
settings on the "Machine Configuration" menu.
* The controls on host input devices (e.g. keys, buttons, joystick axes)
are referred to as "controls", while emulated inputs are referred to
as "inputs".
* The menus for assigning host controls to emulated inputs are called
"input assignments" menus to distinguish them from other input
settings menus.
* Combinations of controls that can be assigned to emulated inputs are
referred to as "combinations" rather than "sequences".
* The potentially confusing term "ROM set" has been removed altogether.
Use "short name" to refer to a device or system's identifier.
* "System" is used in almost places to refer to a complete, runnable
system rather than "Machine".
* "Driver" is now only used to refer to source files where systems or
devices are defined - it is no longer used to refer to individual
systems.
* A few more menus have message context for the messages. This makes it
a bit easier to guess where the messages are used. It also means you
can use different translations in different places if necessary (e.g.
if the same English text should be translated differently as an item
in one menu and as a heading in another).
Diffstat (limited to 'src/frontend/mame/ui/selector.cpp')
-rw-r--r-- | src/frontend/mame/ui/selector.cpp | 71 |
1 files changed, 40 insertions, 31 deletions
diff --git a/src/frontend/mame/ui/selector.cpp b/src/frontend/mame/ui/selector.cpp index 6a583346400..f8791a37887 100644 --- a/src/frontend/mame/ui/selector.cpp +++ b/src/frontend/mame/ui/selector.cpp @@ -27,10 +27,12 @@ namespace ui { menu_selector::menu_selector( mame_ui_manager &mui, render_container &container, + std::string &&title, std::vector<std::string> &&sel, int initial, std::function<void (int)> &&handler) : menu(mui, container) + , m_title(std::move(title)) , m_search() , m_str_items(std::move(sel)) , m_handler(std::move(handler)) @@ -50,30 +52,36 @@ menu_selector::~menu_selector() void menu_selector::handle(event const *ev) { // process the menu - if (ev && ev->itemref) + if (ev) { - if (ev->iptkey == IPT_UI_SELECT) + switch (ev->iptkey) { - int selection(-1); - for (size_t idx = 0; (m_str_items.size() > idx) && (0 > selection); ++idx) - if ((void*)&m_str_items[idx] == ev->itemref) - selection = int(unsigned(idx)); + case IPT_UI_SELECT: + if (ev->itemref) + { + int selection(-1); + for (size_t idx = 0; (m_str_items.size() > idx) && (0 > selection); ++idx) + if ((void*)&m_str_items[idx] == ev->itemref) + selection = int(unsigned(idx)); - m_handler(selection); + m_handler(selection); + stack_pop(); + } + break; - stack_pop(); - } - else if (ev->iptkey == IPT_SPECIAL) - { + case IPT_SPECIAL: if (input_character(m_search, ev->unichar, uchar_is_printable)) reset(reset_options::SELECT_FIRST); - } + break; - // escape pressed with non-empty text clears the text - else if (ev->iptkey == IPT_UI_CANCEL && !m_search.empty()) - { - m_search.clear(); - reset(reset_options::SELECT_FIRST); + case IPT_UI_CANCEL: + if (!m_search.empty()) + { + // escape pressed with non-empty search text clears the search text + m_search.clear(); + reset(reset_options::SELECT_FIRST); + } + break; } } } @@ -84,12 +92,17 @@ void menu_selector::handle(event const *ev) void menu_selector::populate(float &customtop, float &custombottom) { + set_heading(util::string_format(_("menu-selector", "%1$s - Search: %2$s_"), m_title, m_search)); + if (!m_search.empty()) { find_matches(m_search.c_str()); - for (int curitem = 0; m_searchlist[curitem]; ++curitem) + int curitem; + for (curitem = 0; m_searchlist[curitem]; ++curitem) item_append(*m_searchlist[curitem], 0, (void *)m_searchlist[curitem]); + if (!curitem) + item_append(_("menu-selector", "[no matches]"), FLAG_DISABLE, nullptr); } else { @@ -100,10 +113,13 @@ void menu_selector::populate(float &customtop, float &custombottom) item_append(m_str_items[index], 0, (void *)&m_str_items[index]); } + + if (m_str_items.empty()) + item_append(_("menu-selector", "[no choices]"), FLAG_DISABLE, nullptr); // the caller was probably being dumb } item_append(menu_item_type::SEPARATOR); - customtop = custombottom = ui().get_line_height() + 3.0f * ui().box_tb_border(); + custombottom = ui().get_line_height() + 3.0f * ui().box_tb_border(); m_initial = -1; } @@ -113,15 +129,8 @@ void menu_selector::populate(float &customtop, float &custombottom) void menu_selector::custom_render(void *selectedref, float top, float bottom, float origx1, float origy1, float origx2, float origy2) { - std::string tempbuf[1] = { std::string(_("Selection List - Search: ")).append(m_search).append("_") }; - draw_text_box( - std::begin(tempbuf), std::end(tempbuf), - origx1, origx2, origy1 - top, origy1 - ui().box_tb_border(), - text_layout::text_justify::CENTER, text_layout::word_wrapping::TRUNCATE, false, - ui().colors().text_color(), UI_GREEN_COLOR, 1.0f); - // get the text for 'UI Select' - tempbuf[0] = string_format(_("Double-click or press %1$s to select"), ui().get_general_input_setting(IPT_UI_SELECT)); + std::string const tempbuf[] = { util::string_format(_("menu-selector", "Double-click or press %1$s to select"), ui().get_general_input_setting(IPT_UI_SELECT)) }; draw_text_box( std::begin(tempbuf), std::end(tempbuf), origx1, origx2, origy2 + ui().box_tb_border(), origy2 + bottom, @@ -137,7 +146,7 @@ void menu_selector::find_matches(const char *str) { // allocate memory to track the penalty value m_ucs_items.reserve(m_str_items.size()); - std::vector<double> penalty(VISIBLE_GAMES_IN_SEARCH, 1.0); + std::vector<double> penalty(VISIBLE_SEARCH_ITEMS, 2.0); // impossibly high penalty for unpopulated slots std::u32string const search(ustr_from_utf8(normalize_unicode(str, unicode_normalization_form::D, true))); int index = 0; @@ -149,14 +158,14 @@ void menu_selector::find_matches(const char *str) double const curpenalty(util::edit_distance(search, m_ucs_items[index])); // insert into the sorted table of matches - for (int matchnum = VISIBLE_GAMES_IN_SEARCH - 1; matchnum >= 0; --matchnum) + for (int matchnum = VISIBLE_SEARCH_ITEMS - 1; matchnum >= 0; --matchnum) { // stop if we're worse than the current entry if (curpenalty >= penalty[matchnum]) break; // as long as this isn't the last entry, bump this one down - if (matchnum < VISIBLE_GAMES_IN_SEARCH - 1) + if (matchnum < VISIBLE_SEARCH_ITEMS - 1) { penalty[matchnum + 1] = penalty[matchnum]; m_searchlist[matchnum + 1] = m_searchlist[matchnum]; @@ -166,7 +175,7 @@ void menu_selector::find_matches(const char *str) penalty[matchnum] = curpenalty; } } - (index < VISIBLE_GAMES_IN_SEARCH) ? m_searchlist[index] = nullptr : m_searchlist[VISIBLE_GAMES_IN_SEARCH] = nullptr; + (index < VISIBLE_SEARCH_ITEMS) ? m_searchlist[index] = nullptr : m_searchlist[VISIBLE_SEARCH_ITEMS] = nullptr; } } // namespace ui |