mirror of
https://github.com/holub/mame
synced 2025-07-09 03:38:23 +03:00
emu/ioport.cpp: Improved initial keyboard enable settings when changing slot options.
This commit is contained in:
parent
7565bc2956
commit
a52c2f2ca5
@ -2125,20 +2125,58 @@ void ioport_manager::load_config(config_type cfg_type, util::xml::data_node cons
|
||||
// load keyboard enable/disable state
|
||||
if (cfg_type == config_type::GAME)
|
||||
{
|
||||
std::vector<bool> kbd_enable_set;
|
||||
bool keyboard_enabled = false, missing_enabled = false;
|
||||
for (util::xml::data_node const *kbdnode = parentnode->get_child("keyboard"); kbdnode; kbdnode = kbdnode->get_next_sibling("keyboard"))
|
||||
{
|
||||
char const *const tag = kbdnode->get_attribute_string("tag", nullptr);
|
||||
int const enabled = kbdnode->get_attribute_int("enabled", -1);
|
||||
if (tag && (0 <= enabled))
|
||||
{
|
||||
for (size_t i = 0; natkeyboard().keyboard_count() > i; ++i)
|
||||
size_t i;
|
||||
for (i = 0; natkeyboard().keyboard_count() > i; ++i)
|
||||
{
|
||||
if (!strcmp(natkeyboard().keyboard_device(i).tag(), tag))
|
||||
{
|
||||
if (kbd_enable_set.empty())
|
||||
kbd_enable_set.resize(natkeyboard().keyboard_count(), false);
|
||||
kbd_enable_set[i] = true;
|
||||
if (enabled)
|
||||
{
|
||||
if (!natkeyboard().keyboard_is_keypad(i))
|
||||
keyboard_enabled = true;
|
||||
natkeyboard().enable_keyboard(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
natkeyboard().disable_keyboard(i);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
missing_enabled = missing_enabled || (enabled && (natkeyboard().keyboard_count() <= i));
|
||||
}
|
||||
}
|
||||
|
||||
// if keyboard enable configuration was loaded, patch it up for principle of least surprise
|
||||
if (!kbd_enable_set.empty())
|
||||
{
|
||||
for (size_t i = 0; natkeyboard().keyboard_count() > i; ++i)
|
||||
{
|
||||
if (!natkeyboard().keyboard_is_keypad(i))
|
||||
{
|
||||
if (!keyboard_enabled && missing_enabled)
|
||||
{
|
||||
natkeyboard().enable_keyboard(i);
|
||||
keyboard_enabled = true;
|
||||
}
|
||||
else if (!kbd_enable_set[i])
|
||||
{
|
||||
if (keyboard_enabled)
|
||||
natkeyboard().disable_keyboard(i);
|
||||
else
|
||||
natkeyboard().enable_keyboard(i);
|
||||
keyboard_enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -323,6 +323,7 @@ natural_keyboard::natural_keyboard(running_machine &machine)
|
||||
, m_in_use(false)
|
||||
, m_bufbegin(0)
|
||||
, m_bufend(0)
|
||||
, m_current_code(nullptr)
|
||||
, m_fieldnum(0)
|
||||
, m_status_keydown(false)
|
||||
, m_last_cr(false)
|
||||
|
@ -53,8 +53,9 @@ public:
|
||||
void configure(ioport_queue_chars_delegate queue_chars, ioport_accept_char_delegate accept_char, ioport_charqueue_empty_delegate charqueue_empty);
|
||||
void set_in_use(bool usage);
|
||||
size_t keyboard_count() const { return m_keyboards.size(); }
|
||||
device_t &keyboard_device(size_t n) { return m_keyboards[n].device; }
|
||||
bool keyboard_enabled(size_t n) { return m_keyboards[n].enabled; }
|
||||
device_t &keyboard_device(size_t n) const { return m_keyboards[n].device; }
|
||||
bool keyboard_is_keypad(size_t n) const { return !m_keyboards[n].keyboard; }
|
||||
bool keyboard_enabled(size_t n) const { return m_keyboards[n].enabled; }
|
||||
void enable_keyboard(size_t n) { set_keyboard_enabled(n, true); }
|
||||
void disable_keyboard(size_t n) { set_keyboard_enabled(n, false); }
|
||||
|
||||
|
@ -50,7 +50,7 @@ void menu_keyboard_mode::populate(float &customtop, float &custombottom)
|
||||
bool const enabled(natkbd.keyboard_enabled(i));
|
||||
item_append(
|
||||
util::string_format(
|
||||
kbddev.owner() ? _("%1$s [root%2$s]") : _("[root%2$s"),
|
||||
kbddev.owner() ? _("%1$s [root%2$s]") : _("[root%2$s]"),
|
||||
kbddev.type().fullname(),
|
||||
kbddev.tag()),
|
||||
enabled ? _("Enabled") : _("Disabled"),
|
||||
|
Loading…
Reference in New Issue
Block a user