This commit is contained in:
Dentomologist 2024-12-21 09:24:41 +01:00 committed by GitHub
commit d671dc3f32
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 105 additions and 32 deletions

View File

@ -604,7 +604,7 @@ ExtensionNumber Wiimote::GetActiveExtensionNumber() const
bool Wiimote::IsMotionPlusAttached() const
{
return m_is_motion_plus_attached;
return m_motion_plus_setting.GetValue();
}
} // namespace WiimoteEmu

View File

@ -15,6 +15,7 @@
#include "DolphinQt/Config/Mapping/MappingWindow.h"
#include "DolphinQt/Config/Mapping/WiimoteEmuExtension.h"
#include "DolphinQt/Settings.h"
#include "InputCommon/ControllerEmu/ControlGroup/Attachments.h"
#include "InputCommon/InputConfig.h"
@ -88,6 +89,8 @@ void WiimoteEmuGeneral::OnAttachmentChanged(int extension)
GetParent()->ShowExtensionMotionTabs(extension == WiimoteEmu::ExtensionNumber::NUNCHUK);
m_extension_widget->ChangeExtensionType(extension);
Settings::Instance().UpdateWiimoteExtension(GetPort(), extension);
}
void WiimoteEmuGeneral::OnAttachmentSelected(int extension)
@ -110,6 +113,7 @@ void WiimoteEmuGeneral::ConfigChanged()
m_extension_combo_dynamic_indicator->setVisible(
!ce_extension->GetSelectionSetting().IsSimpleValue());
OnMotionPlusUpdate();
}
void WiimoteEmuGeneral::Update()
@ -128,9 +132,18 @@ void WiimoteEmuGeneral::LoadSettings()
void WiimoteEmuGeneral::SaveSettings()
{
Wiimote::GetConfig()->SaveConfig();
OnMotionPlusUpdate();
}
InputConfig* WiimoteEmuGeneral::GetConfig()
{
return Wiimote::GetConfig();
}
void WiimoteEmuGeneral::OnMotionPlusUpdate()
{
const int port = GetPort();
const WiimoteEmu::Wiimote* const wiimote =
static_cast<WiimoteEmu::Wiimote*>(Wiimote::GetConfig()->GetController(port));
Settings::Instance().UpdateWiimoteMotionPlus(port, wiimote->IsMotionPlusAttached());
}

View File

@ -27,6 +27,7 @@ private:
void OnAttachmentChanged(int index);
// Selection chosen by user.
void OnAttachmentSelected(int index);
void OnMotionPlusUpdate();
void ConfigChanged();
void Update();

View File

@ -116,6 +116,9 @@ static bool QtMsgAlertHandler(const char* caption, const char* text, bool yes_no
int main(int argc, char* argv[])
{
// IF THIS COMMENT IS IN A NON-TESTING PR I'VE MADE A MISTAKE. It exists to prevent my testing PR
// from getting automerged by Github if its contents would be the same as a merged actual PR.
#ifdef _WIN32
const bool console_attached = AttachConsole(ATTACH_PARENT_PROCESS) != FALSE;
HANDLE stdout_handle = ::GetStdHandle(STD_OUTPUT_HANDLE);

View File

@ -519,6 +519,15 @@ void MainWindow::CreateComponents()
&MemoryWidget::SetAddress);
connect(m_cheats_manager, &CheatsManager::ShowMemory, m_memory_widget, &MemoryWidget::SetAddress);
connect(m_cheats_manager, &CheatsManager::RequestWatch, request_watch);
connect(&Settings::Instance(), &Settings::UpdateWiimoteExtension,
[this](const int controller_number, const int extension_index) {
m_wii_tas_input_windows[controller_number]->UpdateExtension(extension_index);
});
connect(&Settings::Instance(), &Settings::UpdateWiimoteMotionPlus,
[this](const int controller_number, const bool attached) {
m_wii_tas_input_windows[controller_number]->UpdateMotionPlus(attached);
});
}
void MainWindow::ConnectMenuBar()

View File

@ -224,6 +224,8 @@ signals:
void USBKeyboardConnectionChanged(bool connected);
void EnableGfxModsChanged(bool enabled);
void HardcoreStateChanged();
void UpdateWiimoteExtension(int controller_number, int extension_index);
void UpdateWiimoteMotionPlus(int controller_number, bool attached);
private:
Settings();

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,60 @@ 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()
{
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(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();
}
void WiiTASInputWindow::UpdateControlVisibility()
{
if (m_active_extension == WiimoteEmu::ExtensionNumber::NUNCHUK)
{
@ -451,17 +478,30 @@ void WiiTASInputWindow::UpdateExt()
m_nunchuk_buttons_box->hide();
m_classic_buttons_box->hide();
}
// Without this, switching between attachments can leave the Stick/IR widgets excessively large
adjustSize();
resize(sizeHint());
}
void WiiTASInputWindow::hideEvent(QHideEvent* event)
void WiiTASInputWindow::hideEvent(QHideEvent* const event)
{
GetWiimote()->ClearInputOverrideFunction();
GetExtension()->ClearInputOverrideFunction();
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());

View File

@ -34,12 +34,17 @@ public:
void hideEvent(QHideEvent* event) override;
void showEvent(QShowEvent* event) override;
void UpdateExtension(int extension);
void UpdateMotionPlus(bool attached);
private:
WiimoteEmu::Wiimote* GetWiimote();
ControllerEmu::Attachments* GetAttachments();
WiimoteEmu::Extension* GetExtension();
void UpdateExt();
void LoadExtensionAndMotionPlus();
void UpdateControlVisibility();
void UpdateInputOverrideFunction();
WiimoteEmu::ExtensionNumber m_active_extension;
bool m_is_motion_plus_attached;