mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-12 09:48:37 +12:00
Qt/Input: add disconnected label to the devicenames
This commit is contained in:
parent
bdb5606317
commit
6dcf66b064
11 changed files with 119 additions and 53 deletions
|
@ -90,13 +90,14 @@ pad_settings_dialog::pad_settings_dialog(QWidget *parent)
|
|||
connect(ui->chooseHandler, &QComboBox::currentTextChanged, this, &pad_settings_dialog::ChangeInputType);
|
||||
|
||||
// Combobox: Devices
|
||||
connect(ui->chooseDevice, &QComboBox::currentTextChanged, [this](const QString& dev)
|
||||
connect(ui->chooseDevice, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index)
|
||||
{
|
||||
if (dev.isEmpty())
|
||||
if (index < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
m_device_name = sstr(dev);
|
||||
const pad_info info = ui->chooseDevice->itemData(index).value<pad_info>();
|
||||
m_device_name = info.name;
|
||||
if (!g_cfg_input.player[m_tabs->currentIndex()]->device.from_string(m_device_name))
|
||||
{
|
||||
// Something went wrong
|
||||
|
@ -316,8 +317,10 @@ void pad_settings_dialog::InitButtons()
|
|||
});
|
||||
|
||||
// Enable Button Remapping
|
||||
const auto& callback = [=](u16 val, std::string name, int preview_values[6])
|
||||
const auto& callback = [=](u16 val, std::string name, std::string pad_name, int preview_values[6])
|
||||
{
|
||||
SwitchPadInfo(pad_name, true);
|
||||
|
||||
if (!m_enable_buttons && !m_timer.isActive())
|
||||
{
|
||||
SwitchButtons(true);
|
||||
|
@ -354,8 +357,9 @@ void pad_settings_dialog::InitButtons()
|
|||
};
|
||||
|
||||
// Disable Button Remapping
|
||||
const auto& fail_callback = [this]()
|
||||
const auto& fail_callback = [this](const std::string& pad_name)
|
||||
{
|
||||
SwitchPadInfo(pad_name, false);
|
||||
if (m_enable_buttons)
|
||||
{
|
||||
SwitchButtons(false);
|
||||
|
@ -374,6 +378,35 @@ void pad_settings_dialog::InitButtons()
|
|||
};
|
||||
m_handler->GetNextButtonPress(m_device_name, callback, fail_callback, false, buttons);
|
||||
});
|
||||
|
||||
// Use timer to refresh pad connection status
|
||||
connect(&m_timer_pad_refresh, &QTimer::timeout, [this]()
|
||||
{
|
||||
for (int i = 0; i < ui->chooseDevice->count(); i++)
|
||||
{
|
||||
if (!ui->chooseDevice->itemData(i).canConvert<pad_info>())
|
||||
{
|
||||
LOG_FATAL(GENERAL, "Cannot convert itemData for index %d and itemText %s", i, sstr(ui->chooseDevice->itemText(i)));
|
||||
continue;
|
||||
}
|
||||
const pad_info info = ui->chooseDevice->itemData(i).value<pad_info>();
|
||||
m_handler->GetNextButtonPress(info.name, [=](u16 val, std::string name, std::string pad_name, int preview_values[6]) { SwitchPadInfo(pad_name, true); }, [=](std::string pad_name) { SwitchPadInfo(pad_name, false); }, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void pad_settings_dialog::SwitchPadInfo(const std::string& pad_name, bool is_connected)
|
||||
{
|
||||
for (int i = 0; i < ui->chooseDevice->count(); i++)
|
||||
{
|
||||
const pad_info info = ui->chooseDevice->itemData(i).value<pad_info>();
|
||||
if (info.name == pad_name && info.is_connected != is_connected)
|
||||
{
|
||||
ui->chooseDevice->setItemData(i, QVariant::fromValue(pad_info{ pad_name, is_connected }));
|
||||
ui->chooseDevice->setItemText(i, is_connected ? qstr(pad_name) : (qstr(pad_name) + Disconnected_suffix));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void pad_settings_dialog::ReloadButtons()
|
||||
|
@ -785,7 +818,7 @@ void pad_settings_dialog::ChangeInputType()
|
|||
|
||||
// Get this player's current handler and it's currently available devices
|
||||
m_handler = GetHandler(g_cfg_input.player[player]->handler);
|
||||
const std::vector<std::string> list_devices = m_handler->ListDevices();
|
||||
const auto device_list = m_handler->ListDevices();
|
||||
|
||||
// Refill the device combobox with currently available devices
|
||||
switch (m_handler->m_type)
|
||||
|
@ -797,7 +830,8 @@ void pad_settings_dialog::ChangeInputType()
|
|||
const QString name_string = qstr(m_handler->name_string());
|
||||
for (int i = 1; i <= m_handler->max_devices(); i++) // Controllers 1-n in GUI
|
||||
{
|
||||
ui->chooseDevice->addItem(name_string + QString::number(i), i);
|
||||
const QString device_name = name_string + QString::number(i);
|
||||
ui->chooseDevice->addItem(device_name, QVariant::fromValue(pad_info{ sstr(device_name), false }));
|
||||
}
|
||||
force_enable = true;
|
||||
break;
|
||||
|
@ -805,21 +839,34 @@ void pad_settings_dialog::ChangeInputType()
|
|||
#endif
|
||||
default:
|
||||
{
|
||||
for (int i = 0; i < list_devices.size(); i++)
|
||||
for (int i = 0; i < device_list.size(); i++)
|
||||
{
|
||||
ui->chooseDevice->addItem(qstr(list_devices[i]), i);
|
||||
ui->chooseDevice->addItem(qstr(device_list[i]), QVariant::fromValue(pad_info{ device_list[i], true }));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle empty device list
|
||||
bool config_enabled = force_enable || (m_handler->m_type != pad_handler::null && list_devices.size() > 0);
|
||||
bool config_enabled = force_enable || (m_handler->m_type != pad_handler::null && ui->chooseDevice->count() > 0);
|
||||
ui->chooseDevice->setEnabled(config_enabled);
|
||||
|
||||
if (config_enabled)
|
||||
{
|
||||
ui->chooseDevice->setCurrentText(qstr(device));
|
||||
for (int i = 0; i < ui->chooseDevice->count(); i++)
|
||||
{
|
||||
if (!ui->chooseDevice->itemData(i).canConvert<pad_info>())
|
||||
{
|
||||
LOG_FATAL(GENERAL, "Cannot convert itemData for index %d and itemText %s", i, sstr(ui->chooseDevice->itemText(i)));
|
||||
continue;
|
||||
}
|
||||
const pad_info info = ui->chooseDevice->itemData(i).value<pad_info>();
|
||||
m_handler->GetNextButtonPress(info.name, [=](u16 val, std::string name, std::string pad_name, int preview_values[6]) { SwitchPadInfo(pad_name, true); }, [=](std::string pad_name) { SwitchPadInfo(pad_name, false); }, false);
|
||||
if (info.name == device)
|
||||
{
|
||||
ui->chooseDevice->setCurrentIndex(i);
|
||||
}
|
||||
}
|
||||
|
||||
QString profile_dir = qstr(PadHandlerBase::get_config_dir(m_handler->m_type));
|
||||
QStringList profiles = gui::utils::get_dir_entries(QDir(profile_dir), QStringList() << "*.yml");
|
||||
|
@ -852,7 +899,7 @@ void pad_settings_dialog::ChangeInputType()
|
|||
}
|
||||
|
||||
// enable configuration and profile list if possible
|
||||
SwitchButtons(false || config_enabled && m_handler->m_type == pad_handler::keyboard);
|
||||
SwitchButtons(config_enabled && m_handler->m_type == pad_handler::keyboard);
|
||||
ui->b_addProfile->setEnabled(config_enabled);
|
||||
ui->chooseProfile->setEnabled(config_enabled);
|
||||
}
|
||||
|
@ -873,6 +920,10 @@ void pad_settings_dialog::ChangeProfile()
|
|||
{
|
||||
m_timer_input.stop();
|
||||
}
|
||||
if (m_timer_pad_refresh.isActive())
|
||||
{
|
||||
m_timer_pad_refresh.stop();
|
||||
}
|
||||
|
||||
// Change handler
|
||||
const std::string cfg_name = PadHandlerBase::get_config_dir(m_handler->m_type) + m_profile + ".yml";
|
||||
|
@ -917,6 +968,7 @@ void pad_settings_dialog::ChangeProfile()
|
|||
if (ui->chooseDevice->isEnabled() && ui->chooseDevice->currentIndex() >= 0)
|
||||
{
|
||||
m_timer_input.start(1);
|
||||
m_timer_pad_refresh.start(1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue