2022-04-23 10:59:50 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2020-08-21 13:39:24 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <memory>
|
|
|
|
#include <QDialog>
|
|
|
|
#include "core/frontend/applets/controller.h"
|
|
|
|
|
|
|
|
class GMainWindow;
|
|
|
|
class QCheckBox;
|
|
|
|
class QComboBox;
|
|
|
|
class QDialogButtonBox;
|
|
|
|
class QGroupBox;
|
|
|
|
class QLabel;
|
|
|
|
|
2020-10-26 08:28:03 +01:00
|
|
|
class InputProfiles;
|
|
|
|
|
2020-08-21 13:39:24 +02:00
|
|
|
namespace InputCommon {
|
|
|
|
class InputSubsystem;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
class QtControllerSelectorDialog;
|
|
|
|
}
|
|
|
|
|
2021-09-21 03:19:28 +02:00
|
|
|
namespace Core {
|
|
|
|
class System;
|
|
|
|
}
|
|
|
|
|
2021-10-21 00:53:14 +02:00
|
|
|
namespace Core::HID {
|
2021-11-28 06:26:51 +01:00
|
|
|
class HIDCore;
|
2021-11-04 19:08:54 +01:00
|
|
|
enum class NpadStyleIndex : u8;
|
2021-11-28 06:26:51 +01:00
|
|
|
} // namespace Core::HID
|
2021-10-21 00:53:14 +02:00
|
|
|
|
2020-08-21 13:39:24 +02:00
|
|
|
class QtControllerSelectorDialog final : public QDialog {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit QtControllerSelectorDialog(QWidget* parent,
|
|
|
|
Core::Frontend::ControllerParameters parameters_,
|
2021-09-03 03:40:55 +02:00
|
|
|
InputCommon::InputSubsystem* input_subsystem_,
|
|
|
|
Core::System& system_);
|
2020-08-21 13:39:24 +02:00
|
|
|
~QtControllerSelectorDialog() override;
|
|
|
|
|
2020-09-27 17:18:07 +02:00
|
|
|
int exec() override;
|
|
|
|
|
2020-08-21 13:39:24 +02:00
|
|
|
private:
|
|
|
|
// Applies the current configuration.
|
|
|
|
void ApplyConfiguration();
|
|
|
|
|
2020-08-27 09:52:26 +02:00
|
|
|
// Loads the current input configuration into the frontend applet.
|
|
|
|
void LoadConfiguration();
|
|
|
|
|
2020-10-17 15:38:12 +02:00
|
|
|
// Initializes the "Configure Vibration" Dialog.
|
|
|
|
void CallConfigureVibrationDialog();
|
|
|
|
|
2021-04-13 16:05:07 +02:00
|
|
|
// Initializes the "Configure Motion / Touch" Dialog.
|
|
|
|
void CallConfigureMotionTouchDialog();
|
|
|
|
|
2020-10-26 08:28:03 +01:00
|
|
|
// Initializes the "Create Input Profile" Dialog.
|
|
|
|
void CallConfigureInputProfileDialog();
|
2020-08-21 13:39:24 +02:00
|
|
|
|
2020-09-27 17:18:07 +02:00
|
|
|
// Checks the current configuration against the given parameters.
|
|
|
|
// This sets and returns the value of parameters_met.
|
|
|
|
bool CheckIfParametersMet();
|
2020-08-21 13:39:24 +02:00
|
|
|
|
|
|
|
// Sets the controller icons for "Supported Controller Types".
|
|
|
|
void SetSupportedControllers();
|
|
|
|
|
2020-11-20 17:04:27 +01:00
|
|
|
// Sets the emulated controllers per player.
|
|
|
|
void SetEmulatedControllers(std::size_t player_index);
|
|
|
|
|
|
|
|
// Gets the Controller Type for a given controller combobox index per player.
|
2021-11-04 19:08:54 +01:00
|
|
|
Core::HID::NpadStyleIndex GetControllerTypeFromIndex(int index, std::size_t player_index) const;
|
2020-11-20 17:04:27 +01:00
|
|
|
|
|
|
|
// Gets the controller combobox index for a given Controller Type per player.
|
2021-11-04 19:08:54 +01:00
|
|
|
int GetIndexFromControllerType(Core::HID::NpadStyleIndex type, std::size_t player_index) const;
|
2020-11-20 17:04:27 +01:00
|
|
|
|
2020-08-21 13:39:24 +02:00
|
|
|
// Updates the controller icons per player.
|
|
|
|
void UpdateControllerIcon(std::size_t player_index);
|
|
|
|
|
|
|
|
// Updates the controller state (type and connection status) per player.
|
|
|
|
void UpdateControllerState(std::size_t player_index);
|
|
|
|
|
|
|
|
// Updates the LED pattern per player.
|
|
|
|
void UpdateLEDPattern(std::size_t player_index);
|
|
|
|
|
|
|
|
// Updates the border color per player.
|
|
|
|
void UpdateBorderColor(std::size_t player_index);
|
|
|
|
|
2020-08-27 07:21:48 +02:00
|
|
|
// Sets the "Explain Text" per player.
|
|
|
|
void SetExplainText(std::size_t player_index);
|
|
|
|
|
2020-08-21 13:39:24 +02:00
|
|
|
// Updates the console mode.
|
|
|
|
void UpdateDockedState(bool is_handheld);
|
|
|
|
|
|
|
|
// Disables and disconnects unsupported players based on the given parameters.
|
|
|
|
void DisableUnsupportedPlayers();
|
|
|
|
|
|
|
|
std::unique_ptr<Ui::QtControllerSelectorDialog> ui;
|
|
|
|
|
|
|
|
// Parameters sent in from the backend HLE applet.
|
|
|
|
Core::Frontend::ControllerParameters parameters;
|
|
|
|
|
|
|
|
InputCommon::InputSubsystem* input_subsystem;
|
|
|
|
|
2020-10-26 08:28:03 +01:00
|
|
|
std::unique_ptr<InputProfiles> input_profiles;
|
|
|
|
|
2021-09-03 03:40:55 +02:00
|
|
|
Core::System& system;
|
|
|
|
|
2020-08-21 13:39:24 +02:00
|
|
|
// This is true if and only if all parameters are met. Otherwise, this is false.
|
2020-08-27 07:46:14 +02:00
|
|
|
// This determines whether the "OK" button can be clicked to exit the applet.
|
2020-08-21 13:39:24 +02:00
|
|
|
bool parameters_met{false};
|
|
|
|
|
2020-08-27 07:46:14 +02:00
|
|
|
static constexpr std::size_t NUM_PLAYERS = 8;
|
|
|
|
|
2020-08-21 13:39:24 +02:00
|
|
|
// Widgets encapsulating the groupboxes and comboboxes per player.
|
2020-08-27 07:46:14 +02:00
|
|
|
std::array<QWidget*, NUM_PLAYERS> player_widgets;
|
2020-08-21 13:39:24 +02:00
|
|
|
|
|
|
|
// Groupboxes encapsulating the controller icons and LED patterns per player.
|
2020-08-27 07:46:14 +02:00
|
|
|
std::array<QGroupBox*, NUM_PLAYERS> player_groupboxes;
|
2020-08-21 13:39:24 +02:00
|
|
|
|
|
|
|
// Icons for currently connected controllers/players.
|
2020-08-27 07:46:14 +02:00
|
|
|
std::array<QWidget*, NUM_PLAYERS> connected_controller_icons;
|
2020-08-21 13:39:24 +02:00
|
|
|
|
|
|
|
// Labels that represent the player numbers in place of the controller icons.
|
2020-08-27 07:46:14 +02:00
|
|
|
std::array<QLabel*, NUM_PLAYERS> player_labels;
|
2020-08-21 13:39:24 +02:00
|
|
|
|
|
|
|
// LED patterns for currently connected controllers/players.
|
2020-08-27 07:46:14 +02:00
|
|
|
std::array<std::array<QCheckBox*, 4>, NUM_PLAYERS> led_patterns_boxes;
|
2020-08-21 13:39:24 +02:00
|
|
|
|
2020-08-27 07:21:48 +02:00
|
|
|
// Labels representing additional information known as "Explain Text" per player.
|
2020-08-27 07:46:14 +02:00
|
|
|
std::array<QLabel*, NUM_PLAYERS> explain_text_labels;
|
2020-08-27 07:21:48 +02:00
|
|
|
|
2020-08-21 13:39:24 +02:00
|
|
|
// Comboboxes with a list of emulated controllers per player.
|
2020-08-27 07:46:14 +02:00
|
|
|
std::array<QComboBox*, NUM_PLAYERS> emulated_controllers;
|
2020-08-21 13:39:24 +02:00
|
|
|
|
2020-11-20 17:04:27 +01:00
|
|
|
/// Pairs of emulated controller index and Controller Type enum per player.
|
2021-11-04 19:08:54 +01:00
|
|
|
std::array<std::vector<std::pair<int, Core::HID::NpadStyleIndex>>, NUM_PLAYERS>
|
2020-11-20 17:04:27 +01:00
|
|
|
index_controller_type_pairs;
|
|
|
|
|
2020-08-21 13:39:24 +02:00
|
|
|
// Labels representing the number of connected controllers
|
|
|
|
// above the "Connected Controllers" checkboxes.
|
2020-08-27 07:46:14 +02:00
|
|
|
std::array<QLabel*, NUM_PLAYERS> connected_controller_labels;
|
2020-08-21 13:39:24 +02:00
|
|
|
|
|
|
|
// Checkboxes representing the "Connected Controllers".
|
2020-08-27 07:46:14 +02:00
|
|
|
std::array<QCheckBox*, NUM_PLAYERS> connected_controller_checkboxes;
|
2020-08-21 13:39:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class QtControllerSelector final : public QObject, public Core::Frontend::ControllerApplet {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit QtControllerSelector(GMainWindow& parent);
|
|
|
|
~QtControllerSelector() override;
|
|
|
|
|
2023-03-25 18:29:08 +01:00
|
|
|
void Close() const override;
|
2020-10-27 00:36:58 +01:00
|
|
|
void ReconfigureControllers(
|
2022-12-06 00:59:13 +01:00
|
|
|
ReconfigureCallback callback_,
|
2020-10-27 00:36:58 +01:00
|
|
|
const Core::Frontend::ControllerParameters& parameters) const override;
|
2020-08-21 13:39:24 +02:00
|
|
|
|
|
|
|
signals:
|
2020-10-27 00:36:58 +01:00
|
|
|
void MainWindowReconfigureControllers(
|
|
|
|
const Core::Frontend::ControllerParameters& parameters) const;
|
2023-03-25 18:29:08 +01:00
|
|
|
void MainWindowRequestExit() const;
|
2020-08-21 13:39:24 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
void MainWindowReconfigureFinished();
|
|
|
|
|
2022-12-06 00:59:13 +01:00
|
|
|
mutable ReconfigureCallback callback;
|
2020-08-21 13:39:24 +02:00
|
|
|
};
|