Merge pull request #13208 from Dentomologist/wiitasinputwindow_update_on_attachment_change

WiiTASInputWindow: Update controls when attachment changes
This commit is contained in:
Admiral H. Curtiss
2025-02-02 18:02:58 +01:00
committed by GitHub
7 changed files with 192 additions and 39 deletions

View File

@ -347,32 +347,6 @@ WiiTASInputWindow::WiiTASInputWindow(QWidget* parent, int num) : TASInputWindow(
layout->addWidget(m_settings_box);
setLayout(layout);
if (Core::IsRunning(Core::System::GetInstance()))
{
m_active_extension = GetWiimote()->GetActiveExtensionNumber();
m_is_motion_plus_attached = GetWiimote()->IsMotionPlusAttached();
}
else
{
Common::IniFile ini;
ini.Load(File::GetUserPath(D_CONFIG_IDX) + "WiimoteNew.ini");
const std::string section_name = "Wiimote" + std::to_string(num + 1);
std::string extension;
ini.GetIfExists(section_name, "Extension", &extension);
if (extension == "Nunchuk")
m_active_extension = WiimoteEmu::ExtensionNumber::NUNCHUK;
else if (extension == "Classic")
m_active_extension = WiimoteEmu::ExtensionNumber::CLASSIC;
else
m_active_extension = WiimoteEmu::ExtensionNumber::NONE;
m_is_motion_plus_attached = true;
ini.GetIfExists(section_name, "Extension/Attach MotionPlus", &m_is_motion_plus_attached);
}
UpdateExt();
}
WiimoteEmu::Wiimote* WiiTASInputWindow::GetWiimote()
@ -392,7 +366,71 @@ WiimoteEmu::Extension* WiiTASInputWindow::GetExtension()
GetAttachments()->GetAttachmentList()[m_active_extension].get());
}
void WiiTASInputWindow::UpdateExt()
void WiiTASInputWindow::UpdateExtension(const int extension)
{
const auto new_extension = static_cast<WiimoteEmu::ExtensionNumber>(extension);
if (new_extension == m_active_extension)
return;
m_active_extension = new_extension;
UpdateControlVisibility();
UpdateInputOverrideFunction();
}
void WiiTASInputWindow::UpdateMotionPlus(const bool attached)
{
if (attached == m_is_motion_plus_attached)
return;
m_is_motion_plus_attached = attached;
UpdateControlVisibility();
}
void WiiTASInputWindow::LoadExtensionAndMotionPlus()
{
WiimoteEmu::Wiimote* const wiimote = GetWiimote();
if (Core::IsRunning(Core::System::GetInstance()))
{
m_active_extension = wiimote->GetActiveExtensionNumber();
m_is_motion_plus_attached = wiimote->GetMotionPlusSetting().GetValue();
}
else
{
Common::IniFile ini;
ini.Load(File::GetUserPath(D_CONFIG_IDX) + "WiimoteNew.ini");
const std::string section_name = "Wiimote" + std::to_string(m_num + 1);
std::string extension;
ini.GetIfExists(section_name, "Extension", &extension);
if (extension == "Nunchuk")
m_active_extension = WiimoteEmu::ExtensionNumber::NUNCHUK;
else if (extension == "Classic")
m_active_extension = WiimoteEmu::ExtensionNumber::CLASSIC;
else
m_active_extension = WiimoteEmu::ExtensionNumber::NONE;
m_is_motion_plus_attached = true;
ini.GetIfExists(section_name, "Extension/Attach MotionPlus", &m_is_motion_plus_attached);
}
UpdateControlVisibility();
UpdateInputOverrideFunction();
m_motion_plus_callback_id =
wiimote->GetMotionPlusSetting().AddCallback([this](const bool attached) {
QueueOnObject(this, [this, attached] { UpdateMotionPlus(attached); });
});
m_attachment_callback_id =
GetAttachments()->GetAttachmentSetting().AddCallback([this](const int extension_index) {
QueueOnObject(this, [this, extension_index] { UpdateExtension(extension_index); });
});
}
void WiiTASInputWindow::UpdateControlVisibility()
{
if (m_active_extension == WiimoteEmu::ExtensionNumber::NUNCHUK)
{
@ -451,17 +489,36 @@ void WiiTASInputWindow::UpdateExt()
m_nunchuk_buttons_box->hide();
m_classic_buttons_box->hide();
}
// Without these calls, switching between attachments can result in the Stick/IRWidgets being
// surrounded by large amounts of empty space in one dimension.
adjustSize();
resize(sizeHint());
}
void WiiTASInputWindow::hideEvent(QHideEvent* event)
void WiiTASInputWindow::hideEvent(QHideEvent* const event)
{
GetWiimote()->ClearInputOverrideFunction();
WiimoteEmu::Wiimote* const wiimote = GetWiimote();
wiimote->ClearInputOverrideFunction();
wiimote->GetMotionPlusSetting().RemoveCallback(m_motion_plus_callback_id);
GetExtension()->ClearInputOverrideFunction();
GetAttachments()->GetAttachmentSetting().RemoveCallback(m_attachment_callback_id);
TASInputWindow::hideEvent(event);
}
void WiiTASInputWindow::showEvent(QShowEvent* event)
void WiiTASInputWindow::showEvent(QShowEvent* const event)
{
WiimoteEmu::Wiimote* wiimote = GetWiimote();
LoadExtensionAndMotionPlus();
TASInputWindow::showEvent(event);
}
void WiiTASInputWindow::UpdateInputOverrideFunction()
{
WiimoteEmu::Wiimote* const wiimote = GetWiimote();
if (m_active_extension != WiimoteEmu::ExtensionNumber::CLASSIC)
wiimote->SetInputOverrideFunction(m_wiimote_overrider.GetInputOverrideFunction());