yuzu: Update frontend

This commit is contained in:
german77 2021-09-20 19:47:45 -05:00 committed by Narr the Reg
parent 967cca10ff
commit c405a19b73
13 changed files with 825 additions and 1013 deletions

View File

@ -11,7 +11,6 @@
#include "core/hle/service/acc/profile_manager.h"
#include "core/hle/service/hid/controllers/npad.h"
#include "input_common/main.h"
#include "input_common/udp/client.h"
#include "yuzu/configuration/config.h"
namespace FS = Common::FS;

View File

@ -73,7 +73,7 @@ ConfigureInput::ConfigureInput(Core::System& system_, QWidget* parent)
ConfigureInput::~ConfigureInput() = default;
void ConfigureInput::Initialize(InputCommon::InputSubsystem* input_subsystem,
void ConfigureInput::Initialize(InputCommon::InputSubsystem* input_subsystem, Core::System& system,
std::size_t max_players) {
player_controllers = {
new ConfigureInputPlayer(this, 0, ui->consoleInputSettings, input_subsystem, profiles.get(),
@ -184,22 +184,8 @@ QList<QWidget*> ConfigureInput::GetSubTabs() const {
void ConfigureInput::ApplyConfiguration() {
for (auto* controller : player_controllers) {
controller->ApplyConfiguration();
controller->TryDisconnectSelectedController();
}
// This emulates a delay between disconnecting and reconnecting controllers as some games
// do not respond to a change in controller type if it was instantaneous.
using namespace std::chrono_literals;
std::this_thread::sleep_for(150ms);
for (auto* controller : player_controllers) {
controller->TryConnectSelectedController();
}
// This emulates a delay between disconnecting and reconnecting controllers as some games
// do not respond to a change in controller type if it was instantaneous.
std::this_thread::sleep_for(150ms);
advanced->ApplyConfiguration();
const bool pre_docked_mode = Settings::values.use_docked_mode.GetValue();

View File

@ -42,7 +42,8 @@ public:
~ConfigureInput() override;
/// Initializes the input dialog with the given input subsystem.
void Initialize(InputCommon::InputSubsystem* input_subsystem_, std::size_t max_players = 8);
void Initialize(InputCommon::InputSubsystem* input_subsystem_, Core::System& system,
std::size_t max_players = 8);
/// Save all button configurations to settings file.
void ApplyConfiguration();

File diff suppressed because it is too large Load Diff

View File

@ -38,14 +38,22 @@ class InputSubsystem;
}
namespace InputCommon::Polling {
class DevicePoller;
enum class DeviceType;
enum class InputType;
} // namespace InputCommon::Polling
namespace Ui {
class ConfigureInputPlayer;
}
namespace Core {
class System;
}
namespace Core::HID {
class EmulatedController;
enum class NpadType : u8;
} // namespace Core::HID
class ConfigureInputPlayer : public QWidget {
Q_OBJECT
@ -59,18 +67,6 @@ public:
/// Save all button configurations to settings file.
void ApplyConfiguration();
/**
* Attempts to connect the currently selected controller in the HID backend.
* This function will not do anything if it is not connected in the frontend.
*/
void TryConnectSelectedController();
/**
* Attempts to disconnect the currently selected controller in the HID backend.
* This function will not do anything if the configuration has not changed.
*/
void TryDisconnectSelectedController();
/// Set the connection state checkbox (used to sync state).
void ConnectPlayer(bool connected);
@ -104,6 +100,10 @@ protected:
void showEvent(QShowEvent* event) override;
private:
QString ButtonToText(const Common::ParamPackage& param);
QString AnalogToText(const Common::ParamPackage& param, const std::string& dir);
void changeEvent(QEvent* event) override;
void RetranslateUI();
@ -113,7 +113,7 @@ private:
/// Called when the button was pressed.
void HandleClick(QPushButton* button, std::size_t button_id,
std::function<void(const Common::ParamPackage&)> new_input_setter,
InputCommon::Polling::DeviceType type);
InputCommon::Polling::InputType type);
/// Finish polling and configure input using the input_setter.
void SetPollingResult(const Common::ParamPackage& params, bool abort);
@ -134,17 +134,14 @@ private:
void SetConnectableControllers();
/// Gets the Controller Type for a given controller combobox index.
Settings::ControllerType GetControllerTypeFromIndex(int index) const;
Core::HID::NpadType GetControllerTypeFromIndex(int index) const;
/// Gets the controller combobox index for a given Controller Type.
int GetIndexFromControllerType(Settings::ControllerType type) const;
int GetIndexFromControllerType(Core::HID::NpadType type) const;
/// Update the available input devices.
void UpdateInputDevices();
/// Update the current controller icon.
void UpdateControllerIcon();
/// Hides and disables controller settings based on the current controller type.
void UpdateControllerAvailableButtons();
@ -185,7 +182,7 @@ private:
std::unique_ptr<QTimer> poll_timer;
/// Stores a pair of "Connected Controllers" combobox index and Controller Type enum.
std::vector<std::pair<int, Settings::ControllerType>> index_controller_type_pairs;
std::vector<std::pair<int, Core::HID::NpadType>> index_controller_type_pairs;
static constexpr int PLAYER_COUNT = 8;
std::array<QCheckBox*, PLAYER_COUNT> player_connected_checkbox;
@ -193,9 +190,7 @@ private:
/// This will be the the setting function when an input is awaiting configuration.
std::optional<std::function<void(const Common::ParamPackage&)>> input_setter;
std::array<Common::ParamPackage, Settings::NativeButton::NumButtons> buttons_param;
std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs> analogs_param;
std::array<Common::ParamPackage, Settings::NativeMotion::NumMotions> motions_param;
Core::HID::EmulatedController* emulated_controller;
static constexpr int ANALOG_SUB_BUTTONS_NUM = 4;
@ -221,15 +216,9 @@ private:
static const std::array<std::string, ANALOG_SUB_BUTTONS_NUM> analog_sub_buttons;
std::vector<std::unique_ptr<InputCommon::Polling::DevicePoller>> device_pollers;
/// A flag to indicate that the "Map Analog Stick" pop-up has been shown and accepted once.
bool map_analog_stick_accepted{};
/// A flag to indicate if keyboard keys are okay when configuring an input. If this is false,
/// keyboard events are ignored.
bool want_keyboard_mouse{};
/// List of physical devices users can map with. If a SDL backed device is selected, then you
/// can use this device to get a default mapping.
std::vector<Common::ParamPackage> input_devices;

View File

@ -148,16 +148,6 @@
<height>21</height>
</size>
</property>
<item>
<property name="text">
<string>Any</string>
</property>
</item>
<item>
<property name="text">
<string>Keyboard/Mouse</string>
</property>
</item>
</widget>
</item>
<item>

File diff suppressed because it is too large Load Diff

View File

@ -7,9 +7,10 @@
#include <array>
#include <QFrame>
#include <QPointer>
#include "common/input.h"
#include "common/settings.h"
#include "core/frontend/input.h"
#include "yuzu/debugger/controller.h"
#include "core/hid/hid_core.h"
#include "core/hid/hid_types.h"
class QLabel;
@ -24,17 +25,12 @@ public:
explicit PlayerControlPreview(QWidget* parent);
~PlayerControlPreview() override;
void SetPlayerInput(std::size_t index, const ButtonParam& buttons_param,
const AnalogParam& analogs_param);
void SetPlayerInputRaw(std::size_t index, const Settings::ButtonsRaw& buttons_,
Settings::AnalogsRaw analogs_);
void SetConnectedStatus(bool checked);
void SetControllerType(Settings::ControllerType type);
void SetController(Core::HID::EmulatedController* controller);
void BeginMappingButton(std::size_t button_id);
void BeginMappingAnalog(std::size_t button_id);
void EndMapping();
void ControllerUpdate(Core::HID::ControllerTriggerType type);
void UpdateInput();
void SetCallBack(ControllerCallback callback_);
protected:
void paintEvent(QPaintEvent* event) override;
@ -63,15 +59,6 @@ private:
SR,
};
struct AxisValue {
QPointF value{};
QPointF raw_value{};
Input::AnalogProperties properties{};
int size{};
QPoint offset{};
bool active{};
};
struct LedPattern {
bool position1;
bool position2;
@ -122,47 +109,66 @@ private:
void DrawGCBody(QPainter& p, QPointF center);
// Draw triggers functions
void DrawProTriggers(QPainter& p, QPointF center, bool left_pressed, bool right_pressed);
void DrawGCTriggers(QPainter& p, QPointF center, bool left_pressed, bool right_pressed);
void DrawHandheldTriggers(QPainter& p, QPointF center, bool left_pressed, bool right_pressed);
void DrawDualTriggers(QPainter& p, QPointF center, bool left_pressed, bool right_pressed);
void DrawDualTriggersTopView(QPainter& p, QPointF center, bool left_pressed,
bool right_pressed);
void DrawDualZTriggersTopView(QPainter& p, QPointF center, bool left_pressed,
bool right_pressed);
void DrawLeftTriggers(QPainter& p, QPointF center, bool left_pressed);
void DrawLeftZTriggers(QPainter& p, QPointF center, bool left_pressed);
void DrawLeftTriggersTopView(QPainter& p, QPointF center, bool left_pressed);
void DrawLeftZTriggersTopView(QPainter& p, QPointF center, bool left_pressed);
void DrawRightTriggers(QPainter& p, QPointF center, bool right_pressed);
void DrawRightZTriggers(QPainter& p, QPointF center, bool right_pressed);
void DrawRightTriggersTopView(QPainter& p, QPointF center, bool right_pressed);
void DrawRightZTriggersTopView(QPainter& p, QPointF center, bool right_pressed);
void DrawProTriggers(QPainter& p, QPointF center, const Input::ButtonStatus& left_pressed,
const Input::ButtonStatus& right_pressed);
void DrawGCTriggers(QPainter& p, QPointF center, Input::TriggerStatus left_trigger,
Input::TriggerStatus right_trigger);
void DrawHandheldTriggers(QPainter& p, QPointF center, const Input::ButtonStatus& left_pressed,
const Input::ButtonStatus& right_pressed);
void DrawDualTriggers(QPainter& p, QPointF center, const Input::ButtonStatus& left_pressed,
const Input::ButtonStatus& right_pressed);
void DrawDualTriggersTopView(QPainter& p, QPointF center,
const Input::ButtonStatus& left_pressed,
const Input::ButtonStatus& right_pressed);
void DrawDualZTriggersTopView(QPainter& p, QPointF center,
const Input::ButtonStatus& left_pressed,
const Input::ButtonStatus& right_pressed);
void DrawLeftTriggers(QPainter& p, QPointF center, const Input::ButtonStatus& left_pressed);
void DrawLeftZTriggers(QPainter& p, QPointF center, const Input::ButtonStatus& left_pressed);
void DrawLeftTriggersTopView(QPainter& p, QPointF center,
const Input::ButtonStatus& left_pressed);
void DrawLeftZTriggersTopView(QPainter& p, QPointF center,
const Input::ButtonStatus& left_pressed);
void DrawRightTriggers(QPainter& p, QPointF center, const Input::ButtonStatus& right_pressed);
void DrawRightZTriggers(QPainter& p, QPointF center, const Input::ButtonStatus& right_pressed);
void DrawRightTriggersTopView(QPainter& p, QPointF center,
const Input::ButtonStatus& right_pressed);
void DrawRightZTriggersTopView(QPainter& p, QPointF center,
const Input::ButtonStatus& right_pressed);
// Draw joystick functions
void DrawJoystick(QPainter& p, QPointF center, float size, bool pressed);
void DrawJoystickSideview(QPainter& p, QPointF center, float angle, float size, bool pressed);
void DrawJoystick(QPainter& p, QPointF center, float size, const Input::ButtonStatus& pressed);
void DrawJoystickSideview(QPainter& p, QPointF center, float angle, float size,
const Input::ButtonStatus& pressed);
void DrawRawJoystick(QPainter& p, QPointF center_left, QPointF center_right);
void DrawJoystickProperties(QPainter& p, QPointF center,
const Input::AnalogProperties& properties);
void DrawJoystickDot(QPainter& p, QPointF center, QPointF value,
const Input::AnalogProperties& properties);
void DrawProJoystick(QPainter& p, QPointF center, QPointF offset, float scalar, bool pressed);
void DrawGCJoystick(QPainter& p, QPointF center, bool pressed);
void DrawJoystickDot(QPainter& p, QPointF center, const Input::StickStatus& stick, bool raw);
void DrawProJoystick(QPainter& p, QPointF center, QPointF offset, float scalar,
const Input::ButtonStatus& pressed);
void DrawGCJoystick(QPainter& p, QPointF center, const Input::ButtonStatus& pressed);
// Draw button functions
void DrawCircleButton(QPainter& p, QPointF center, bool pressed, float button_size);
void DrawRoundButton(QPainter& p, QPointF center, bool pressed, float width, float height,
Direction direction = Direction::None, float radius = 2);
void DrawMinusButton(QPainter& p, QPointF center, bool pressed, int button_size);
void DrawPlusButton(QPainter& p, QPointF center, bool pressed, int button_size);
void DrawGCButtonX(QPainter& p, QPointF center, bool pressed);
void DrawGCButtonY(QPainter& p, QPointF center, bool pressed);
void DrawGCButtonZ(QPainter& p, QPointF center, bool pressed);
void DrawCircleButton(QPainter& p, QPointF center, const Input::ButtonStatus& pressed,
float button_size);
void DrawRoundButton(QPainter& p, QPointF center, const Input::ButtonStatus& pressed,
float width, float height, Direction direction = Direction::None,
float radius = 2);
void DrawMinusButton(QPainter& p, QPointF center, const Input::ButtonStatus& pressed,
int button_size);
void DrawPlusButton(QPainter& p, QPointF center, const Input::ButtonStatus& pressed,
int button_size);
void DrawGCButtonX(QPainter& p, QPointF center, const Input::ButtonStatus& pressed);
void DrawGCButtonY(QPainter& p, QPointF center, const Input::ButtonStatus& pressed);
void DrawGCButtonZ(QPainter& p, QPointF center, const Input::ButtonStatus& pressed);
void DrawArrowButtonOutline(QPainter& p, const QPointF center, float size = 1.0f);
void DrawArrowButton(QPainter& p, QPointF center, Direction direction, bool pressed,
float size = 1.0f);
void DrawTriggerButton(QPainter& p, QPointF center, Direction direction, bool pressed);
void DrawArrowButton(QPainter& p, QPointF center, Direction direction,
const Input::ButtonStatus& pressed, float size = 1.0f);
void DrawTriggerButton(QPainter& p, QPointF center, Direction direction,
const Input::ButtonStatus& pressed);
// Draw battery functions
void DrawBattery(QPainter& p, QPointF center, Input::BatteryLevel battery);
// Draw icon functions
void DrawSymbol(QPainter& p, QPointF center, Symbol symbol, float icon_size);
@ -178,24 +184,23 @@ private:
void SetTextFont(QPainter& p, float text_size,
const QString& font_family = QStringLiteral("sans-serif"));
using ButtonArray =
std::array<std::unique_ptr<Input::ButtonDevice>, Settings::NativeButton::BUTTON_NS_END>;
using StickArray =
std::array<std::unique_ptr<Input::AnalogDevice>, Settings::NativeAnalog::NUM_STICKS_HID>;
bool is_controller_set{};
bool is_connected{};
bool needs_redraw{};
Core::HID::NpadType controller_type;
ControllerCallback controller_callback;
bool is_enabled{};
bool mapping_active{};
int blink_counter{};
int callback_key;
QColor button_color{};
ColorMapping colors{};
std::array<QColor, 4> led_color{};
ButtonArray buttons{};
StickArray sticks{};
std::size_t player_index{};
std::size_t button_mapping_index{Settings::NativeButton::BUTTON_NS_END};
std::size_t analog_mapping_index{Settings::NativeAnalog::NUM_STICKS_HID};
std::array<AxisValue, Settings::NativeAnalog::NUM_STICKS_HID> axis_values{};
std::array<bool, Settings::NativeButton::NumButtons> button_values{};
Settings::ControllerType controller_type{Settings::ControllerType::ProController};
Core::HID::EmulatedController* controller;
std::size_t button_mapping_index{Settings::NativeButton::NumButtons};
std::size_t analog_mapping_index{Settings::NativeAnalog::NumAnalogs};
Core::HID::ButtonValues button_values{};
Core::HID::SticksValues stick_values{};
Core::HID::TriggerValues trigger_values{};
Core::HID::BatteryValues battery_values{};
};

View File

@ -15,9 +15,9 @@
#include "common/logging/log.h"
#include "common/settings.h"
#include "input_common/drivers/udp_client.h"
#include "input_common/helpers/udp_protocol.h"
#include "input_common/main.h"
#include "input_common/udp/client.h"
#include "input_common/udp/udp.h"
#include "ui_configure_motion_touch.h"
#include "yuzu/configuration/configure_motion_touch.h"
#include "yuzu/configuration/configure_touch_from_button.h"

View File

@ -11,8 +11,11 @@
#include "common/assert.h"
#include "common/param_package.h"
#include "input_common/drivers/keyboard.h"
#include "input_common/drivers/mouse.h"
#include "input_common/main.h"
#include "ui_configure_mouse_advanced.h"
#include "yuzu/bootmanager.h"
#include "yuzu/configuration/config.h"
#include "yuzu/configuration/configure_mouse_advanced.h"
@ -101,7 +104,7 @@ ConfigureMouseAdvanced::ConfigureMouseAdvanced(QWidget* parent,
[=, this](const Common::ParamPackage& params) {
buttons_param[button_id] = params;
},
InputCommon::Polling::DeviceType::Button);
InputCommon::Polling::InputType::Button);
});
connect(button, &QPushButton::customContextMenuRequested,
[=, this](const QPoint& menu_location) {
@ -127,14 +130,11 @@ ConfigureMouseAdvanced::ConfigureMouseAdvanced(QWidget* parent,
connect(timeout_timer.get(), &QTimer::timeout, [this] { SetPollingResult({}, true); });
connect(poll_timer.get(), &QTimer::timeout, [this] {
Common::ParamPackage params;
for (auto& poller : device_pollers) {
params = poller->GetNextInput();
const auto& params = input_subsystem->GetNextInput();
if (params.Has("engine")) {
SetPollingResult(params, false);
return;
}
}
});
LoadConfiguration();
@ -196,26 +196,13 @@ void ConfigureMouseAdvanced::UpdateButtonLabels() {
void ConfigureMouseAdvanced::HandleClick(
QPushButton* button, std::function<void(const Common::ParamPackage&)> new_input_setter,
InputCommon::Polling::DeviceType type) {
InputCommon::Polling::InputType type) {
button->setText(tr("[press key]"));
button->setFocus();
// Keyboard keys or mouse buttons can only be used as button devices
want_keyboard_mouse = type == InputCommon::Polling::DeviceType::Button;
if (want_keyboard_mouse) {
const auto iter = std::find(button_map.begin(), button_map.end(), button);
ASSERT(iter != button_map.end());
const auto index = std::distance(button_map.begin(), iter);
ASSERT(index < Settings::NativeButton::NumButtons && index >= 0);
}
input_setter = new_input_setter;
device_pollers = input_subsystem->GetPollers(type);
for (auto& poller : device_pollers) {
poller->Start();
}
input_subsystem->BeginMapping(type);
QWidget::grabMouse();
QWidget::grabKeyboard();
@ -227,9 +214,7 @@ void ConfigureMouseAdvanced::HandleClick(
void ConfigureMouseAdvanced::SetPollingResult(const Common::ParamPackage& params, bool abort) {
timeout_timer->stop();
poll_timer->stop();
for (auto& poller : device_pollers) {
poller->Stop();
}
input_subsystem->StopMapping();
QWidget::releaseMouse();
QWidget::releaseKeyboard();
@ -247,15 +232,8 @@ void ConfigureMouseAdvanced::mousePressEvent(QMouseEvent* event) {
return;
}
if (want_keyboard_mouse) {
SetPollingResult(Common::ParamPackage{InputCommon::GenerateKeyboardParam(event->button())},
false);
} else {
// We don't want any mouse buttons, so don't stop polling
return;
}
SetPollingResult({}, true);
const auto button = GRenderWindow::QtButtonToMouseButton(event->button());
input_subsystem->GetMouse()->PressButton(0, 0, 0, 0, button);
}
void ConfigureMouseAdvanced::keyPressEvent(QKeyEvent* event) {
@ -264,13 +242,6 @@ void ConfigureMouseAdvanced::keyPressEvent(QKeyEvent* event) {
}
if (event->key() != Qt::Key_Escape) {
if (want_keyboard_mouse) {
SetPollingResult(Common::ParamPackage{InputCommon::GenerateKeyboardParam(event->key())},
false);
} else {
// Escape key wasn't pressed and we don't want any keyboard keys, so don't stop polling
return;
input_subsystem->GetKeyboard()->PressKey(event->key());
}
}
SetPollingResult({}, true);
}

View File

@ -46,7 +46,7 @@ private:
/// Called when the button was pressed.
void HandleClick(QPushButton* button,
std::function<void(const Common::ParamPackage&)> new_input_setter,
InputCommon::Polling::DeviceType type);
InputCommon::Polling::InputType type);
/// Finish polling and configure input using the input_setter
void SetPollingResult(const Common::ParamPackage& params, bool abort);
@ -67,12 +67,6 @@ private:
std::array<QPushButton*, Settings::NativeMouseButton::NumMouseButtons> button_map;
std::array<Common::ParamPackage, Settings::NativeMouseButton::NumMouseButtons> buttons_param;
std::vector<std::unique_ptr<InputCommon::Polling::DevicePoller>> device_pollers;
std::unique_ptr<QTimer> timeout_timer;
std::unique_ptr<QTimer> poll_timer;
/// A flag to indicate if keyboard keys are okay when configuring an input. If this is false,
/// keyboard events are ignored.
bool want_keyboard_mouse = false;
};

View File

@ -163,14 +163,11 @@ void ConfigureTouchFromButton::ConnectEvents() {
connect(timeout_timer.get(), &QTimer::timeout, [this]() { SetPollingResult({}, true); });
connect(poll_timer.get(), &QTimer::timeout, [this]() {
Common::ParamPackage params;
for (auto& poller : device_pollers) {
params = poller->GetNextInput();
const auto& params = input_subsystem->GetNextInput();
if (params.Has("engine")) {
SetPollingResult(params, false);
return;
}
}
});
}
@ -248,11 +245,7 @@ void ConfigureTouchFromButton::GetButtonInput(const int row_index, const bool is
}
};
device_pollers = input_subsystem->GetPollers(InputCommon::Polling::DeviceType::Button);
for (auto& poller : device_pollers) {
poller->Start();
}
input_subsystem->BeginMapping(InputCommon::Polling::InputType::Button);
grabKeyboard();
grabMouse();
@ -365,14 +358,14 @@ void ConfigureTouchFromButton::SetCoordinates(const int dot_id, const QPoint& po
void ConfigureTouchFromButton::SetPollingResult(const Common::ParamPackage& params,
const bool cancel) {
timeout_timer->stop();
poll_timer->stop();
input_subsystem->StopMapping();
releaseKeyboard();
releaseMouse();
qApp->restoreOverrideCursor();
timeout_timer->stop();
poll_timer->stop();
for (auto& poller : device_pollers) {
poller->Stop();
}
if (input_setter) {
(*input_setter)(params, cancel);
input_setter.reset();

View File

@ -24,10 +24,6 @@ namespace InputCommon {
class InputSubsystem;
}
namespace InputCommon::Polling {
class DevicePoller;
}
namespace Settings {
struct TouchFromButtonMap;
}
@ -85,7 +81,6 @@ private:
std::unique_ptr<QTimer> timeout_timer;
std::unique_ptr<QTimer> poll_timer;
std::vector<std::unique_ptr<InputCommon::Polling::DevicePoller>> device_pollers;
std::optional<std::function<void(const Common::ParamPackage&, bool)>> input_setter;
static constexpr int DataRoleDot = Qt::ItemDataRole::UserRole + 2;