diff options
author | 2021-10-09 12:16:17 +1100 | |
---|---|---|
committer | 2021-10-09 12:16:17 +1100 | |
commit | 38082ccbee749d650ccea886ae376a5d1dec337c (patch) | |
tree | 9ba9a900ba826bda58832834278025ced17f42f5 /src/frontend/mame/ui/custui.cpp | |
parent | 34b3bf701098082feb9077db49987507962c1578 (diff) |
Overdue internal UI enhancements (#8674)
* frontend: Added support for message context to localisations.
* frontend: Added string_view versions of the message lookup functions.
* frontend: Added a few more folder options to the internal UI.
* emu/softlist.cpp: Use more appropriate containers.
* Switched to Python 3 by default - this will become a requirement.
* Updated msgfmt.py for message context support.
* frontend: Show all software item info in the internal UI.
* frontend: Search alternate titles in software selection menu.
* 3rdparty/utf8proc: Updated to v2.6.1 (has several fixes).
* frontend: Added software filters for common info fields.
* frontend: Allow UI manager to hold onto persistent session data.
* frontend: Cache software lists for eight machines.
* frontend: Added support for loading localised system names.
* frontend: Add UI for selecting localised system names.
Diffstat (limited to 'src/frontend/mame/ui/custui.cpp')
-rw-r--r-- | src/frontend/mame/ui/custui.cpp | 213 |
1 files changed, 153 insertions, 60 deletions
diff --git a/src/frontend/mame/ui/custui.cpp b/src/frontend/mame/ui/custui.cpp index c748bee1e7c..9b06465f9f8 100644 --- a/src/frontend/mame/ui/custui.cpp +++ b/src/frontend/mame/ui/custui.cpp @@ -30,10 +30,10 @@ namespace ui { const char *const menu_custom_ui::HIDE_STATUS[] = { - __("Show All"), - __("Hide Filters"), - __("Hide Info/Image"), - __("Hide Both") }; + N_("Show All"), + N_("Hide Filters"), + N_("Hide Info/Image"), + N_("Hide Both") }; //------------------------------------------------- // ctor @@ -43,30 +43,10 @@ menu_custom_ui::menu_custom_ui(mame_ui_manager &mui, render_container &container : menu(mui, container) , m_handler(std::move(handler)) , m_currlang(0) + , m_currsysnames(0) { - // load languages - file_enumerator path(mui.machine().options().language_path()); - const char *const lang = mui.machine().options().language(); - const osd::directory::entry *dirent; - std::string name; - while ((dirent = path.next())) - { - if (dirent->type == osd::directory::entry::entry_type::DIR && strcmp(dirent->name, ".") != 0 && strcmp(dirent->name, "..") != 0) - { - name = dirent->name; - auto i = strreplace(name, "_", " ("); - if (i > 0) - name.append(")"); - m_lang.emplace_back(std::move(name)); - } - } - std::sort( - m_lang.begin(), - m_lang.end(), - [] (const std::string &x, const std::string &y) { return 0 > core_stricmp(x.c_str(), y.c_str()); }); - const auto found = std::lower_bound(m_lang.begin(), m_lang.end(), lang, [] (std::string const &x, const char *y) { return 0 > core_stricmp(x.c_str(), y); }); - if ((m_lang.end() != found) && !core_stricmp(found->c_str(), lang)) - m_currlang = std::distance(m_lang.begin(), found); + find_languages(); + find_sysnames(); } //------------------------------------------------- @@ -76,11 +56,12 @@ menu_custom_ui::menu_custom_ui(mame_ui_manager &mui, render_container &container menu_custom_ui::~menu_custom_ui() { ui().options().set_value(OPTION_HIDE_PANELS, ui_globals::panels_status, OPTION_PRIORITY_CMDLINE); - if (!m_lang.empty()) - { - machine().options().set_value(OPTION_LANGUAGE, m_lang[m_currlang], OPTION_PRIORITY_CMDLINE); - load_translation(machine().options()); - } + + machine().options().set_value(OPTION_LANGUAGE, m_currlang ? m_languages[m_currlang] : "", OPTION_PRIORITY_CMDLINE); + load_translation(machine().options()); + + ui().options().set_value(OPTION_SYSTEM_NAMES, m_currsysnames ? m_sysnames[m_currsysnames] : "", OPTION_PRIORITY_CMDLINE); + ui_globals::reset = true; if (m_handler) @@ -96,7 +77,7 @@ void menu_custom_ui::handle() bool changed = false; // process the menu - const event *menu_event = process(0); + const event *menu_event = process(PROCESS_LR_REPEAT); if (menu_event != nullptr && menu_event->itemref != nullptr) { @@ -140,13 +121,16 @@ void menu_custom_ui::handle() 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--; + if (menu_event->iptkey == IPT_UI_LEFT) + m_currlang = (m_currlang ? m_currlang : m_languages.size())- 1; + else if (++m_currlang >= m_languages.size()) + m_currlang = 0; } 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, + ui(), container(), std::vector<std::string>(m_languages), m_currlang, [this] (int selection) { m_currlang = selection; @@ -154,6 +138,27 @@ void menu_custom_ui::handle() }); } break; + case SYSNAMES_MENU: + if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT) + { + changed = true; + if (menu_event->iptkey == IPT_UI_LEFT) + m_currsysnames = (m_currsysnames ? m_currsysnames : m_sysnames.size())- 1; + else if (++m_currsysnames >= m_sysnames.size()) + m_currsysnames = 0; + } + else if (menu_event->iptkey == IPT_UI_SELECT) + { + // copying list of file names - expensive + menu::stack_push<menu_selector>( + ui(), container(), std::vector<std::string>(m_sysnames), m_currsysnames, + [this] (int selection) + { + m_currsysnames = selection; + reset(reset_options::REMEMBER_REF); + }); + } + break; } } @@ -171,11 +176,11 @@ void menu_custom_ui::populate(float &customtop, float &custombottom) item_append(_("Fonts"), 0, (void *)(uintptr_t)FONT_MENU); item_append(_("Colors"), 0, (void *)(uintptr_t)COLORS_MENU); - if (!m_lang.empty()) - { - arrow_flags = get_arrow_flags<std::uint16_t>(0, m_lang.size() - 1, m_currlang); - item_append(_("Language"), m_lang[m_currlang], arrow_flags, (void *)(uintptr_t)LANGUAGE_MENU); - } + arrow_flags = get_arrow_flags<std::size_t>(0, m_languages.size() - 1, m_currlang); + item_append(_("Language"), m_languages[m_currlang], arrow_flags, (void *)(uintptr_t)LANGUAGE_MENU); + + arrow_flags = get_arrow_flags<std::size_t>(0, m_sysnames.size() - 1, m_currsysnames); + item_append(_("System Names"), m_sysnames[m_currsysnames], arrow_flags, (void *)(uintptr_t)SYSNAMES_MENU); arrow_flags = get_arrow_flags<uint16_t>(0, HIDE_BOTH, ui_globals::panels_status); item_append(_("Show side panels"), _(HIDE_STATUS[ui_globals::panels_status]), arrow_flags, (void *)(uintptr_t)HIDE_MENU); @@ -190,7 +195,7 @@ void menu_custom_ui::populate(float &customtop, float &custombottom) void menu_custom_ui::custom_render(void *selectedref, float top, float bottom, float origx1, float origy1, float origx2, float origy2) { - char const *const text[] = { _("Custom UI Settings") }; + char const *const text[] = { _("UI Customization Settings") }; draw_text_box( std::begin(text), std::end(text), origx1, origx2, origy1 - top, origy1 - ui().box_tb_border(), @@ -199,6 +204,94 @@ void menu_custom_ui::custom_render(void *selectedref, float top, float bottom, f } //------------------------------------------------- +// find UI translation files +//------------------------------------------------- + +void menu_custom_ui::find_languages() +{ + m_languages.emplace_back(_("[built-in]")); + + file_enumerator path(machine().options().language_path()); + osd::directory::entry const *dirent; + std::string name; + while ((dirent = path.next())) + { + if (dirent->type == osd::directory::entry::entry_type::DIR && strcmp(dirent->name, ".") != 0 && strcmp(dirent->name, "..") != 0) + { + name = dirent->name; + auto i = strreplace(name, "_", " ("); + if (i > 0) + name.append(")"); + m_languages.emplace_back(std::move(name)); + } + } + std::sort( + std::next(m_languages.begin()), + m_languages.end(), + [] (std::string const &x, std::string const &y) { return 0 > core_stricmp(x.c_str(), y.c_str()); }); + + char const *const lang = machine().options().language(); + if (*lang) + { + auto const found = std::lower_bound( + std::next(m_languages.begin()), + m_languages.end(), + lang, + [] (std::string const &x, char const *y) { return 0 > core_stricmp(x.c_str(), y); }); + if ((m_languages.end() != found) && !core_stricmp(found->c_str(), lang)) + m_currlang = std::distance(m_languages.begin(), found); + } + else + { + m_currlang = 0; + } +} + +//------------------------------------------------- +// find translated system names +//------------------------------------------------- + +void menu_custom_ui::find_sysnames() +{ + m_sysnames.emplace_back(_("[built-in]")); + + path_iterator search(ui().options().history_path()); + std::string path; + while (search.next(path)) + { + file_enumerator dir(path); + osd::directory::entry const *dirent; + while ((dirent = dir.next())) + { + if (dirent->type == osd::directory::entry::entry_type::FILE && core_filename_ends_with(dirent->name, ".lst")) + m_sysnames.emplace_back(dirent->name); + } + } + std::sort( + m_sysnames.begin(), + m_sysnames.end(), + [] (std::string const &x, std::string const &y) { return 0 > core_stricmp(x.c_str(), y.c_str()); }); + + char const *const names = ui().options().system_names(); + if (*names) + { + auto const found = std::lower_bound( + std::next(m_sysnames.begin()), + m_sysnames.end(), + names, + [] (std::string const &x, char const *y) { return 0 > core_stricmp(x.c_str(), y); }); + m_currsysnames = std::distance(m_sysnames.begin(), found); + if ((m_sysnames.end() == found) || core_stricmp(found->c_str(), names)) + m_sysnames.emplace(found, names); + } + else + { + m_currsysnames = 0; + } +} + + +//------------------------------------------------- // ctor //------------------------------------------------- @@ -781,34 +874,34 @@ void menu_rgb_ui::populate(float &customtop, float &custombottom) if (m_lock_ref != RGB_ALPHA) { arrow_flags = get_arrow_flags<uint8_t>(0, 255, m_color->a()); - item_append(_("Alpha"), string_format("%3u", m_color->a()), arrow_flags, (void *)(uintptr_t)RGB_ALPHA); + item_append(_("color-channel", "Alpha"), string_format("%3u", m_color->a()), arrow_flags, (void *)(uintptr_t)RGB_ALPHA); } else - item_append(_("Alpha"), s_text, 0, (void *)(uintptr_t)RGB_ALPHA); + item_append(_("color-channel", "Alpha"), s_text, 0, (void *)(uintptr_t)RGB_ALPHA); if (m_lock_ref != RGB_RED) { arrow_flags = get_arrow_flags<uint8_t>(0, 255, m_color->r()); - item_append(_("Red"), string_format("%3u", m_color->r()), arrow_flags, (void *)(uintptr_t)RGB_RED); + item_append(_("color-channel", "Red"), string_format("%3u", m_color->r()), arrow_flags, (void *)(uintptr_t)RGB_RED); } else - item_append(_("Red"), s_text, 0, (void *)(uintptr_t)RGB_RED); + item_append(_("color-channel", "Red"), s_text, 0, (void *)(uintptr_t)RGB_RED); if (m_lock_ref != RGB_GREEN) { arrow_flags = get_arrow_flags<uint8_t>(0, 255, m_color->g()); - item_append(_("Green"), string_format("%3u", m_color->g()), arrow_flags, (void *)(uintptr_t)RGB_GREEN); + item_append(_("color-channel", "Green"), string_format("%3u", m_color->g()), arrow_flags, (void *)(uintptr_t)RGB_GREEN); } else - item_append(_("Green"), s_text, 0, (void *)(uintptr_t)RGB_GREEN); + item_append(_("color-channel", "Green"), s_text, 0, (void *)(uintptr_t)RGB_GREEN); if (m_lock_ref != RGB_BLUE) { arrow_flags = get_arrow_flags<uint8_t>(0, 255, m_color->b()); - item_append(_("Blue"), string_format("%3u", m_color->b()), arrow_flags, (void *)(uintptr_t)RGB_BLUE); + item_append(_("color-channel", "Blue"), string_format("%3u", m_color->b()), arrow_flags, (void *)(uintptr_t)RGB_BLUE); } else - item_append(_("Blue"), s_text, 0, (void *)(uintptr_t)RGB_BLUE); + item_append(_("color-channel", "Blue"), s_text, 0, (void *)(uintptr_t)RGB_BLUE); item_append(menu_item_type::SEPARATOR); item_append(_("Choose from palette"), 0, (void *)(uintptr_t)PALETTE_CHOOSE); @@ -931,16 +1024,16 @@ void menu_rgb_ui::inkey_special(const event *menu_event) } std::pair<const char *, const char *> const menu_palette_sel::s_palette[] = { - { __("White"), "FFFFFFFF" }, - { __("Silver"), "FFC0C0C0" }, - { __("Gray"), "FF808080" }, - { __("Black"), "FF000000" }, - { __("Red"), "FFFF0000" }, - { __("Orange"), "FFFFA500" }, - { __("Yellow"), "FFFFFF00" }, - { __("Green"), "FF00FF00" }, - { __("Blue"), "FF0000FF" }, - { __("Violet"), "FF8F00FF" } + { N_p("color-preset", "White"), "FFFFFFFF" }, + { N_p("color-preset", "Silver"), "FFC0C0C0" }, + { N_p("color-preset", "Gray"), "FF808080" }, + { N_p("color-preset", "Black"), "FF000000" }, + { N_p("color-preset", "Red"), "FFFF0000" }, + { N_p("color-preset", "Orange"), "FFFFA500" }, + { N_p("color-preset", "Yellow"), "FFFFFF00" }, + { N_p("color-preset", "Green"), "FF00FF00" }, + { N_p("color-preset", "Blue"), "FF0000FF" }, + { N_p("color-preset", "Violet"), "FF8F00FF" } }; //------------------------------------------------- @@ -986,7 +1079,7 @@ void menu_palette_sel::handle() void menu_palette_sel::populate(float &customtop, float &custombottom) { for (unsigned x = 0; x < std::size(s_palette); ++x) - item_append(_(s_palette[x].first), s_palette[x].second, FLAG_COLOR_BOX, (void *)(uintptr_t)(x + 1)); + item_append(_("color-preset", s_palette[x].first), s_palette[x].second, FLAG_COLOR_BOX, (void *)(uintptr_t)(x + 1)); item_append(menu_item_type::SEPARATOR); } |