mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
Merge pull request #8747 from iwubcode/map-freelook
Support controlling Free Look via input bindings (motion controls, gamepad, etc!)
This commit is contained in:
@ -122,6 +122,8 @@ add_executable(dolphin-emu
|
||||
Config/LogWidget.h
|
||||
Config/Mapping/FreeLookGeneral.cpp
|
||||
Config/Mapping/FreeLookGeneral.h
|
||||
Config/Mapping/FreeLookRotation.cpp
|
||||
Config/Mapping/FreeLookRotation.h
|
||||
Config/Mapping/GCKeyboardEmu.cpp
|
||||
Config/Mapping/GCKeyboardEmu.h
|
||||
Config/Mapping/GCMicrophone.cpp
|
||||
|
62
Source/Core/DolphinQt/Config/Mapping/FreeLookRotation.cpp
Normal file
62
Source/Core/DolphinQt/Config/Mapping/FreeLookRotation.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
// Copyright 2021 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "DolphinQt/Config/Mapping/FreeLookRotation.h"
|
||||
|
||||
#include <QGridLayout>
|
||||
#include <QGroupBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
|
||||
#include "Core/FreeLookManager.h"
|
||||
#include "DolphinQt/Config/ControllerInterface/ControllerInterfaceWindow.h"
|
||||
#include "InputCommon/InputConfig.h"
|
||||
|
||||
FreeLookRotation::FreeLookRotation(MappingWindow* window) : MappingWidget(window)
|
||||
{
|
||||
CreateMainLayout();
|
||||
}
|
||||
|
||||
void FreeLookRotation::CreateMainLayout()
|
||||
{
|
||||
m_main_layout = new QGridLayout;
|
||||
|
||||
auto* alternate_input_layout = new QHBoxLayout();
|
||||
auto* note_label = new QLabel(
|
||||
tr("Note: motion input may require configuring alternate input sources before use."));
|
||||
note_label->setWordWrap(true);
|
||||
auto* alternate_input_sources_button = new QPushButton(tr("Alternate Input Sources"));
|
||||
alternate_input_layout->addWidget(note_label, 1);
|
||||
alternate_input_layout->addWidget(alternate_input_sources_button, 0, Qt::AlignRight);
|
||||
connect(alternate_input_sources_button, &QPushButton::clicked, this, [this] {
|
||||
ControllerInterfaceWindow* window = new ControllerInterfaceWindow(this);
|
||||
window->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
window->setWindowModality(Qt::WindowModality::WindowModal);
|
||||
window->show();
|
||||
});
|
||||
m_main_layout->addLayout(alternate_input_layout, 0, 0, 1, -1);
|
||||
|
||||
m_main_layout->addWidget(
|
||||
CreateGroupBox(tr("Incremental Rotation (rad/sec)"),
|
||||
FreeLook::GetInputGroup(GetPort(), FreeLookGroup::Rotation)),
|
||||
1, 0);
|
||||
|
||||
setLayout(m_main_layout);
|
||||
}
|
||||
|
||||
InputConfig* FreeLookRotation::GetConfig()
|
||||
{
|
||||
return FreeLook::GetInputConfig();
|
||||
}
|
||||
|
||||
void FreeLookRotation::LoadSettings()
|
||||
{
|
||||
FreeLook::LoadInputConfig();
|
||||
}
|
||||
|
||||
void FreeLookRotation::SaveSettings()
|
||||
{
|
||||
FreeLook::GetInputConfig()->SaveConfig();
|
||||
}
|
26
Source/Core/DolphinQt/Config/Mapping/FreeLookRotation.h
Normal file
26
Source/Core/DolphinQt/Config/Mapping/FreeLookRotation.h
Normal file
@ -0,0 +1,26 @@
|
||||
// Copyright 2021 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DolphinQt/Config/Mapping/MappingWidget.h"
|
||||
|
||||
class QGridLayout;
|
||||
|
||||
class FreeLookRotation final : public MappingWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FreeLookRotation(MappingWindow* window);
|
||||
|
||||
InputConfig* GetConfig() override;
|
||||
|
||||
private:
|
||||
void LoadSettings() override;
|
||||
void SaveSettings() override;
|
||||
void CreateMainLayout();
|
||||
|
||||
// Main
|
||||
QGridLayout* m_main_layout;
|
||||
};
|
@ -23,6 +23,7 @@
|
||||
#include "Common/StringUtil.h"
|
||||
|
||||
#include "DolphinQt/Config/Mapping/FreeLookGeneral.h"
|
||||
#include "DolphinQt/Config/Mapping/FreeLookRotation.h"
|
||||
#include "DolphinQt/Config/Mapping/GCKeyboardEmu.h"
|
||||
#include "DolphinQt/Config/Mapping/GCMicrophone.h"
|
||||
#include "DolphinQt/Config/Mapping/GCPadEmu.h"
|
||||
@ -436,6 +437,7 @@ void MappingWindow::SetMappingType(MappingWindow::Type type)
|
||||
{
|
||||
widget = new FreeLookGeneral(this);
|
||||
AddWidget(tr("General"), widget);
|
||||
AddWidget(tr("Rotation"), new FreeLookRotation(this));
|
||||
setWindowTitle(tr("Free Look Controller %1").arg(GetPort() + 1));
|
||||
}
|
||||
break;
|
||||
|
@ -80,6 +80,7 @@
|
||||
<ClCompile Include="Config\LogConfigWidget.cpp" />
|
||||
<ClCompile Include="Config\LogWidget.cpp" />
|
||||
<ClCompile Include="Config\Mapping\FreeLookGeneral.cpp" />
|
||||
<ClCompile Include="Config\Mapping\FreeLookRotation.cpp" />
|
||||
<ClCompile Include="Config\Mapping\GCKeyboardEmu.cpp" />
|
||||
<ClCompile Include="Config\Mapping\GCMicrophone.cpp" />
|
||||
<ClCompile Include="Config\Mapping\GCPadEmu.cpp" />
|
||||
@ -254,6 +255,7 @@
|
||||
<QtMoc Include="Config\LogConfigWidget.h" />
|
||||
<QtMoc Include="Config\LogWidget.h" />
|
||||
<QtMoc Include="Config\Mapping\FreeLookGeneral.h" />
|
||||
<QtMoc Include="Config\Mapping\FreeLookRotation.h" />
|
||||
<QtMoc Include="Config\Mapping\GCKeyboardEmu.h" />
|
||||
<QtMoc Include="Config\Mapping\GCMicrophone.h" />
|
||||
<QtMoc Include="Config\Mapping\GCPadEmu.h" />
|
||||
|
@ -139,10 +139,14 @@ void HotkeyScheduler::Run()
|
||||
|
||||
while (!m_stop_requested.IsSet())
|
||||
{
|
||||
Common::SleepCurrentThread(1000 / 60);
|
||||
Common::SleepCurrentThread(5);
|
||||
|
||||
if (Core::GetState() == Core::State::Uninitialized || Core::GetState() == Core::State::Paused)
|
||||
g_controller_interface.UpdateInput();
|
||||
g_controller_interface.SetCurrentInputChannel(ciface::InputChannel::FreeLook);
|
||||
g_controller_interface.UpdateInput();
|
||||
FreeLook::UpdateInput();
|
||||
|
||||
g_controller_interface.SetCurrentInputChannel(ciface::InputChannel::Host);
|
||||
g_controller_interface.UpdateInput();
|
||||
|
||||
if (!HotkeyManagerEmu::IsEnabled())
|
||||
continue;
|
||||
@ -546,8 +550,6 @@ void HotkeyScheduler::Run()
|
||||
OSD::AddMessage(StringFromFormat("Free Look: %s", new_value ? "Enabled" : "Disabled"));
|
||||
}
|
||||
|
||||
FreeLook::UpdateInput();
|
||||
|
||||
// Savestates
|
||||
for (u32 i = 0; i < State::NUM_STATES; i++)
|
||||
{
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/Flag.h"
|
||||
#include "InputCommon/InputProfile.h"
|
||||
|
||||
|
@ -32,9 +32,7 @@
|
||||
#include "DolphinQt/Resources.h"
|
||||
#include "DolphinQt/Settings.h"
|
||||
|
||||
#include "VideoCommon/FreeLookCamera.h"
|
||||
#include "VideoCommon/RenderBase.h"
|
||||
#include "VideoCommon/VertexShaderManager.h"
|
||||
#include "VideoCommon/VideoConfig.h"
|
||||
|
||||
RenderWidget::RenderWidget(QWidget* parent) : QWidget(parent)
|
||||
@ -180,11 +178,6 @@ bool RenderWidget::event(QEvent* event)
|
||||
|
||||
break;
|
||||
}
|
||||
case QEvent::MouseMove:
|
||||
if (g_freelook_camera.IsActive())
|
||||
OnFreeLookMouseMove(static_cast<QMouseEvent*>(event));
|
||||
[[fallthrough]];
|
||||
|
||||
case QEvent::MouseButtonPress:
|
||||
if (!Settings::Instance().GetHideCursor() && isActiveWindow())
|
||||
{
|
||||
@ -237,23 +230,6 @@ bool RenderWidget::event(QEvent* event)
|
||||
return QWidget::event(event);
|
||||
}
|
||||
|
||||
void RenderWidget::OnFreeLookMouseMove(QMouseEvent* event)
|
||||
{
|
||||
const auto mouse_move = event->pos() - m_last_mouse;
|
||||
m_last_mouse = event->pos();
|
||||
|
||||
if (event->buttons() & Qt::RightButton)
|
||||
{
|
||||
// Camera Pitch and Yaw:
|
||||
g_freelook_camera.Rotate(Common::Vec3{mouse_move.y() / 200.f, mouse_move.x() / 200.f, 0.f});
|
||||
}
|
||||
else if (event->buttons() & Qt::MiddleButton)
|
||||
{
|
||||
// Camera Roll:
|
||||
g_freelook_camera.Rotate({0.f, 0.f, mouse_move.x() / 200.f});
|
||||
}
|
||||
}
|
||||
|
||||
void RenderWidget::PassEventToImGui(const QEvent* event)
|
||||
{
|
||||
if (!Core::IsRunningAndStarted())
|
||||
|
@ -33,7 +33,6 @@ private:
|
||||
void HandleCursorTimer();
|
||||
void OnHideCursorChanged();
|
||||
void OnKeepOnTopChanged(bool top);
|
||||
void OnFreeLookMouseMove(QMouseEvent* event);
|
||||
void PassEventToImGui(const QEvent* event);
|
||||
void SetImGuiKeyMap();
|
||||
void dragEnterEvent(QDragEnterEvent* event) override;
|
||||
|
Reference in New Issue
Block a user