Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Testing branch ignore #13199

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/Core/Core/HW/WiimoteEmu/EmuSubroutines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions Source/Core/DolphinQt/Config/Mapping/WiimoteEmuGeneral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -110,6 +113,7 @@ void WiimoteEmuGeneral::ConfigChanged()

m_extension_combo_dynamic_indicator->setVisible(
!ce_extension->GetSelectionSetting().IsSimpleValue());
OnMotionPlusUpdate();
}

void WiimoteEmuGeneral::Update()
Expand All @@ -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());
}
1 change: 1 addition & 0 deletions Source/Core/DolphinQt/Config/Mapping/WiimoteEmuGeneral.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class WiimoteEmuGeneral final : public MappingWidget
void OnAttachmentChanged(int index);
// Selection chosen by user.
void OnAttachmentSelected(int index);
void OnMotionPlusUpdate();

void ConfigChanged();
void Update();
Expand Down
3 changes: 3 additions & 0 deletions Source/Core/DolphinQt/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions Source/Core/DolphinQt/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/DolphinQt/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ class Settings final : public QObject
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();
Expand Down
84 changes: 62 additions & 22 deletions Source/Core/DolphinQt/TAS/WiiTASInputWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,49 @@ WiiTASInputWindow::WiiTASInputWindow(QWidget* parent, int num) : TASInputWindow(
layout->addWidget(m_settings_box);

setLayout(layout);
}

WiimoteEmu::Wiimote* WiiTASInputWindow::GetWiimote()
{
return static_cast<WiimoteEmu::Wiimote*>(Wiimote::GetConfig()->GetController(m_num));
}

ControllerEmu::Attachments* WiiTASInputWindow::GetAttachments()
{
return static_cast<ControllerEmu::Attachments*>(
GetWiimote()->GetWiimoteGroup(WiimoteEmu::WiimoteGroup::Attachments));
}

WiimoteEmu::Extension* WiiTASInputWindow::GetExtension()
{
return static_cast<WiimoteEmu::Extension*>(
GetAttachments()->GetAttachmentList()[m_active_extension].get());
}

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();
Expand All @@ -357,7 +399,7 @@ WiiTASInputWindow::WiiTASInputWindow(QWidget* parent, int num) : TASInputWindow(
{
Common::IniFile ini;
ini.Load(File::GetUserPath(D_CONFIG_IDX) + "WiimoteNew.ini");
const std::string section_name = "Wiimote" + std::to_string(num + 1);
const std::string section_name = "Wiimote" + std::to_string(m_num + 1);

std::string extension;
ini.GetIfExists(section_name, "Extension", &extension);
Expand All @@ -372,27 +414,12 @@ WiiTASInputWindow::WiiTASInputWindow(QWidget* parent, int num) : TASInputWindow(
m_is_motion_plus_attached = true;
ini.GetIfExists(section_name, "Extension/Attach MotionPlus", &m_is_motion_plus_attached);
}
UpdateExt();
}

WiimoteEmu::Wiimote* WiiTASInputWindow::GetWiimote()
{
return static_cast<WiimoteEmu::Wiimote*>(Wiimote::GetConfig()->GetController(m_num));
UpdateControlVisibility();
UpdateInputOverrideFunction();
}

ControllerEmu::Attachments* WiiTASInputWindow::GetAttachments()
{
return static_cast<ControllerEmu::Attachments*>(
GetWiimote()->GetWiimoteGroup(WiimoteEmu::WiimoteGroup::Attachments));
}

WiimoteEmu::Extension* WiiTASInputWindow::GetExtension()
{
return static_cast<WiimoteEmu::Extension*>(
GetAttachments()->GetAttachmentList()[m_active_extension].get());
}

void WiiTASInputWindow::UpdateExt()
void WiiTASInputWindow::UpdateControlVisibility()
{
if (m_active_extension == WiimoteEmu::ExtensionNumber::NUNCHUK)
{
Expand Down Expand Up @@ -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* const event)
{
LoadExtensionAndMotionPlus();

TASInputWindow::showEvent(event);
}

void WiiTASInputWindow::showEvent(QShowEvent* event)
void WiiTASInputWindow::UpdateInputOverrideFunction()
{
WiimoteEmu::Wiimote* wiimote = GetWiimote();
WiimoteEmu::Wiimote* const wiimote = GetWiimote();

if (m_active_extension != WiimoteEmu::ExtensionNumber::CLASSIC)
wiimote->SetInputOverrideFunction(m_wiimote_overrider.GetInputOverrideFunction());
Expand Down
7 changes: 6 additions & 1 deletion Source/Core/DolphinQt/TAS/WiiTASInputWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,17 @@ class WiiTASInputWindow : public TASInputWindow
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;
Expand Down