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

[WIP] Qt/Mapping: Visual GCPad configuration #8063

Draft
wants to merge 1 commit 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
16 changes: 15 additions & 1 deletion Source/Core/DolphinQt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@ if (NOT Qt5_DIR AND MSVC)
endif()
endif()

find_package(Qt5 5.9 REQUIRED COMPONENTS Gui Widgets)
find_package(Qt5 5.9 REQUIRED COMPONENTS Gui Widgets Quick QuickWidgets)
find_package(Qt5 CONFIG QUIET OPTIONAL_COMPONENTS QuickCompiler)

set_property(TARGET Qt5::Core PROPERTY INTERFACE_COMPILE_FEATURES "")
message(STATUS "Found Qt version ${Qt5Core_VERSION}")

set(CMAKE_AUTOMOC ON)

if (NOT Qt5QuickCompiler_DIR STREQUAL "Qt5QuickCompiler_DIR-NOTFOUND")
message(STATUS "Found Qt Quick Compiler")
qtquick_compiler_add_resources(RCC_SOURCES Resources/Resources.qrc)
endif()
set_property(SOURCE ${RCC_SOURCES} PROPERTY SKIP_AUTOMOC ON)

add_executable(dolphin-emu
AboutDialog.cpp
AboutDialog.h
Expand Down Expand Up @@ -142,6 +149,7 @@ add_executable(dolphin-emu
Config/Mapping/MappingWidget.h
Config/Mapping/MappingWindow.cpp
Config/Mapping/MappingWindow.h
Config/Mapping/Visual/GCMappingWidget.cpp
Config/Mapping/WiimoteEmuExtension.cpp
Config/Mapping/WiimoteEmuExtension.h
Config/Mapping/WiimoteEmuExtensionMotionInput.cpp
Expand Down Expand Up @@ -266,6 +274,7 @@ add_executable(dolphin-emu
TAS/IRWidget.h
Updater.cpp
Updater.h
${RCC_SOURCES}
)

if (NOT WIN32)
Expand All @@ -286,12 +295,16 @@ target_include_directories(dolphin-emu
PRIVATE
${CMAKE_CURRENT_BINARY_DIR}
${Qt5Gui_PRIVATE_INCLUDE_DIRS}
${Qt5Quick_PRIVATE_INCLUDE_DIRS}
${Qt5QuickWidgets_PRIVATE_INCLUDE_DIRS}
)

target_link_libraries(dolphin-emu
PRIVATE
core
Qt5::Widgets
Qt5::Quick
Qt5::QuickWidgets
uicommon
imgui
)
Expand Down Expand Up @@ -348,6 +361,7 @@ if(WIN32)
COMMAND "${CMAKE_COMMAND}" -E env PATH="${QT_BINARY_DIRECTORY}"
"${WINDEPLOYQT_EXE}" --libdir="${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
--plugindir="${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/QtPlugins"
--qmldir="${CMAKE_CURRENT_SOURCE_DIR}/Resources"
$<IF:$<CONFIG:Debug>,--debug,--release>
--no-translations
--no-compiler-runtime
Expand Down
5 changes: 5 additions & 0 deletions Source/Core/DolphinQt/Config/Mapping/MappingButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ void MappingButton::Clicked()

QString expression;

const auto old_text = text();
setText(QStringLiteral("..."));

if (m_parent->GetParent()->IsMappingAllDevices())
{
expression = MappingCommon::DetectExpression(this, g_controller_interface,
Expand All @@ -106,6 +109,8 @@ void MappingButton::Clicked()
default_device_qualifier);
}

setText(old_text);

if (expression.isEmpty())
return;

Expand Down
29 changes: 13 additions & 16 deletions Source/Core/DolphinQt/Config/Mapping/MappingCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <QTimer>

#include "DolphinQt/QtUtils/BlockUserInputFilter.h"
#include "DolphinQt/QtUtils/QueueOnObject.h"
#include "InputCommon/ControlReference/ControlReference.h"
#include "InputCommon/ControllerInterface/Device.h"

Expand Down Expand Up @@ -49,18 +50,16 @@ QString GetExpressionForControl(const QString& control_name,
return expr;
}

QString DetectExpression(QPushButton* button, ciface::Core::DeviceContainer& device_container,
QString DetectExpression(QWidget* widget, ciface::Core::DeviceContainer& device_container,
const std::vector<std::string>& device_strings,
const ciface::Core::DeviceQualifier& default_device, Quote quote)
{
const auto filter = new BlockUserInputFilter(button);

button->installEventFilter(filter);
button->grabKeyboard();
button->grabMouse();

const auto old_text = button->text();
button->setText(QStringLiteral("..."));
const auto filter = new BlockUserInputFilter(widget);
QueueOnObject(widget, [widget, filter] {
widget->installEventFilter(filter);
widget->grabKeyboard();
widget->grabMouse();
});

// The button text won't be updated if we don't process events here
QApplication::processEvents();
Expand All @@ -70,19 +69,17 @@ QString DetectExpression(QPushButton* button, ciface::Core::DeviceContainer& dev

const auto [device, input] = device_container.DetectInput(INPUT_DETECT_TIME, device_strings);

const auto timer = new QTimer(button);
const auto timer = new QTimer(widget);

button->connect(timer, &QTimer::timeout, [button, filter] {
button->releaseMouse();
button->releaseKeyboard();
button->removeEventFilter(filter);
widget->connect(timer, &QTimer::timeout, [widget, filter] {
widget->releaseMouse();
widget->releaseKeyboard();
widget->removeEventFilter(filter);
});

// Prevent mappings of "space", "return", or mouse clicks from re-activating detection.
timer->start(500);

button->setText(old_text);

if (!input)
return {};

Expand Down
7 changes: 5 additions & 2 deletions Source/Core/DolphinQt/Config/Mapping/MappingCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
#include <string>
#include <vector>

class QString;
class OutputReference;
class QPushButton;
class QString;
class QWidget;

constexpr int INDICATOR_UPDATE_FREQ = 30;

namespace ciface::Core
{
Expand All @@ -30,7 +33,7 @@ QString GetExpressionForControl(const QString& control_name,
const ciface::Core::DeviceQualifier& default_device,
Quote quote = Quote::On);

QString DetectExpression(QPushButton* button, ciface::Core::DeviceContainer& device_container,
QString DetectExpression(QWidget* widget, ciface::Core::DeviceContainer& device_container,
const std::vector<std::string>& device_strings,
const ciface::Core::DeviceQualifier& default_device,
Quote quote = Quote::On);
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinQt/Config/Mapping/MappingIndicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
#include "InputCommon/ControllerInterface/Device.h"

#include "DolphinQt/Config/Mapping/MappingWidget.h"
#include "DolphinQt/Config/Mapping/MappingCommon.h"
#include "DolphinQt/QtUtils/ModalMessageBox.h"

namespace
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DolphinQt/Config/Mapping/MappingWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "DolphinQt/Config/Mapping/IOWindow.h"
#include "DolphinQt/Config/Mapping/MappingButton.h"
#include "DolphinQt/Config/Mapping/MappingCommon.h"
#include "DolphinQt/Config/Mapping/MappingIndicator.h"
#include "DolphinQt/Config/Mapping/MappingNumeric.h"
#include "DolphinQt/Config/Mapping/MappingWindow.h"
Expand Down
2 changes: 0 additions & 2 deletions Source/Core/DolphinQt/Config/Mapping/MappingWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ class EmulatedController;
class NumericSettingBase;
} // namespace ControllerEmu

constexpr int INDICATOR_UPDATE_FREQ = 30;

class MappingWidget : public QWidget
{
Q_OBJECT
Expand Down
6 changes: 6 additions & 0 deletions Source/Core/DolphinQt/Config/Mapping/MappingWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "DolphinQt/Config/Mapping/HotkeyStatesOther.h"
#include "DolphinQt/Config/Mapping/HotkeyTAS.h"
#include "DolphinQt/Config/Mapping/HotkeyWii.h"
#include "DolphinQt/Config/Mapping/Visual/GCMappingWidget.h"
#include "DolphinQt/Config/Mapping/WiimoteEmuExtension.h"
#include "DolphinQt/Config/Mapping/WiimoteEmuExtensionMotionInput.h"
#include "DolphinQt/Config/Mapping/WiimoteEmuExtensionMotionSimulation.h"
Expand All @@ -49,6 +50,7 @@
#include "InputCommon/InputConfig.h"

constexpr const char* PROFILES_DIR = "Profiles/";
constexpr int INDICATOR_UPDATE_FREQ = 30;

MappingWindow::MappingWindow(QWidget* parent, Type type, int port_num)
: QDialog(parent), m_port(port_num)
Expand Down Expand Up @@ -346,10 +348,14 @@ void MappingWindow::SetMappingType(MappingWindow::Type type)
case Type::MAPPING_GC_STEERINGWHEEL:
case Type::MAPPING_GC_DANCEMAT:
case Type::MAPPING_GCPAD:
{
widget = new GCPadEmu(this);
auto* visual = new VisualGCMappingWidget(this, GetPort());
setWindowTitle(tr("GameCube Controller at Port %1").arg(GetPort() + 1));
AddWidget(tr("GameCube Controller"), widget);
AddWidget(tr("Visual Configuration"), visual);
break;
}
case Type::MAPPING_GC_MICROPHONE:
widget = new GCMicrophone(this);
setWindowTitle(tr("GameCube Microphone Slot %1")
Expand Down
Loading