Cleanup of slot code

Added device_slot_interface::has_selectable_options() to calculate whether a particular slot has selectable options
This commit is contained in:
Nathan Woods 2017-02-26 19:24:36 -05:00
parent 995388d469
commit f407afa013
4 changed files with 30 additions and 12 deletions

View File

@ -77,6 +77,17 @@ device_t* device_slot_interface::get_card_device()
return dev;
}
bool device_slot_interface::has_selectable_options() const
{
if (!fixed())
{
for (auto &option : option_list())
if (option.second->selectable())
return true;
}
return false;
}
device_slot_card_interface::device_slot_card_interface(const machine_config &mconfig, device_t &device)
: device_interface(device, "slot")

View File

@ -110,6 +110,7 @@ public:
static void static_set_option_device_input_defaults(device_t &device, const char *option, const input_device_default *default_input) { static_option(device, option)->m_input_device_defaults = default_input; }
static void static_set_option_clock(device_t &device, const char *option, u32 default_clock) { static_option(device, option)->m_clock = default_clock; }
bool fixed() const { return m_fixed; }
bool has_selectable_options() const;
const char *default_option() const { return m_default_option; }
const std::unordered_map<std::string, std::unique_ptr<device_slot_option>> &option_list() const { return m_options; }
device_slot_option *option(const char *name) const { if (name) { auto search = m_options.find(name); if (search != m_options.end()) return search->second.get(); else return nullptr; } else return nullptr; }

View File

@ -38,8 +38,8 @@ bool mame_options::add_slot_options(emu_options &options, std::function<void(emu
int starting_count = options.options_count();
for (const device_slot_interface &slot : slot_interface_iterator(config.root_device()))
{
// skip fixed slots
if (slot.fixed())
// skip slots without selectable options
if (!slot.has_selectable_options())
continue;
// retrieve info about the device instance

View File

@ -153,22 +153,28 @@ menu_slot_devices::menu_slot_devices(mame_ui_manager &mui, render_container &con
void menu_slot_devices::populate(float &customtop, float &custombottom)
{
/* cycle through all devices for this system */
// cycle through all devices for this system
for (device_slot_interface &slot : slot_interface_iterator(machine().root_device()))
{
/* record the menu item */
// does this slot have any selectable options?
bool has_selectable_options = slot.has_selectable_options();
// name this option
std::string opt_name("------");
const device_slot_option *option = slot_get_current_option(slot);
std::string opt_name;
if (option == nullptr)
opt_name.assign("------");
else
if (option)
{
opt_name.assign(option->name());
if (slot.fixed() || slot_get_length(slot) == 0)
opt_name.append(_(" [internal]"));
opt_name = has_selectable_options
? option->name()
: string_format(_("%s [internal]"), option->name());
}
item_append(slot.device().tag() + 1, opt_name, (slot.fixed() || slot_get_length(slot) == 0) ? 0 : (FLAG_LEFT_ARROW | FLAG_RIGHT_ARROW), (void *)&slot);
// choose item flags
uint32_t item_flags = has_selectable_options
? FLAG_LEFT_ARROW | FLAG_RIGHT_ARROW
: FLAG_DISABLE;
item_append(slot.device().tag() + 1, opt_name, item_flags, (void *)&slot);
}
item_append(menu_item_type::SEPARATOR);
item_append(_("Reset"), "", 0, (void *)1);