mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
DolphinQt: Use input override system for TAS input windows
This lets the TAS input code use a higher-level interface for overriding inputs instead of having to fiddle with raw bits. WiiTASInputWindow in particular was messy with how much controller code it had to re-implement.
This commit is contained in:
@ -3,11 +3,18 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
|
||||
struct GCPadStatus;
|
||||
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
|
||||
#include "InputCommon/ControllerInterface/CoreDevice.h"
|
||||
|
||||
class QBoxLayout;
|
||||
class QCheckBox;
|
||||
class QDialog;
|
||||
@ -16,6 +23,20 @@ class QSpinBox;
|
||||
class QString;
|
||||
class TASCheckBox;
|
||||
|
||||
class InputOverrider final
|
||||
{
|
||||
public:
|
||||
using OverrideFunction = std::function<std::optional<ControlState>(ControlState)>;
|
||||
|
||||
void AddFunction(std::string_view group_name, std::string_view control_name,
|
||||
OverrideFunction function);
|
||||
|
||||
ControllerEmu::InputOverrideFunction GetInputOverrideFunction() const;
|
||||
|
||||
private:
|
||||
std::map<std::pair<std::string_view, std::string_view>, OverrideFunction> m_functions;
|
||||
};
|
||||
|
||||
class TASInputWindow : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -26,19 +47,25 @@ public:
|
||||
int GetTurboReleaseFrames() const;
|
||||
|
||||
protected:
|
||||
TASCheckBox* CreateButton(const QString& name);
|
||||
QGroupBox* CreateStickInputs(QString name, QSpinBox*& x_value, QSpinBox*& y_value, u16 max_x,
|
||||
u16 max_y, Qt::Key x_shortcut_key, Qt::Key y_shortcut_key);
|
||||
QBoxLayout* CreateSliderValuePairLayout(QString name, QSpinBox*& value, int default_, u16 max,
|
||||
Qt::Key shortcut_key, QWidget* shortcut_widget,
|
||||
bool invert = false);
|
||||
TASCheckBox* CreateButton(const QString& text, std::string_view group_name,
|
||||
std::string_view control_name, InputOverrider* overrider);
|
||||
QGroupBox* CreateStickInputs(const QString& text, std::string_view group_name,
|
||||
InputOverrider* overrider, QSpinBox*& x_value, QSpinBox*& y_value,
|
||||
u16 min_x, u16 min_y, u16 max_x, u16 max_y, Qt::Key x_shortcut_key,
|
||||
Qt::Key y_shortcut_key);
|
||||
QBoxLayout* CreateSliderValuePairLayout(const QString& text, std::string_view group_name,
|
||||
std::string_view control_name, InputOverrider* overrider,
|
||||
QSpinBox*& value, u16 zero, int default_, u16 min,
|
||||
u16 max, Qt::Key shortcut_key, QWidget* shortcut_widget,
|
||||
std::optional<ControlState> scale = {});
|
||||
QSpinBox* CreateSliderValuePair(std::string_view group_name, std::string_view control_name,
|
||||
InputOverrider* overrider, QBoxLayout* layout, u16 zero,
|
||||
int default_, u16 min, u16 max,
|
||||
QKeySequence shortcut_key_sequence, Qt::Orientation orientation,
|
||||
QWidget* shortcut_widget, std::optional<ControlState> scale = {});
|
||||
QSpinBox* CreateSliderValuePair(QBoxLayout* layout, int default_, u16 max,
|
||||
QKeySequence shortcut_key_sequence, Qt::Orientation orientation,
|
||||
QWidget* shortcut_widget, bool invert = false);
|
||||
template <typename UX>
|
||||
void GetButton(TASCheckBox* button, UX& pad, UX mask);
|
||||
void GetSpinBoxU8(QSpinBox* spin, u8& controller_value);
|
||||
void GetSpinBoxU16(QSpinBox* spin, u16& controller_value);
|
||||
QWidget* shortcut_widget);
|
||||
|
||||
QGroupBox* m_settings_box;
|
||||
QCheckBox* m_use_controller;
|
||||
@ -46,7 +73,12 @@ protected:
|
||||
QSpinBox* m_turbo_release_frames;
|
||||
|
||||
private:
|
||||
std::optional<ControlState> GetButton(TASCheckBox* checkbox, ControlState controller_state);
|
||||
std::optional<ControlState> GetSpinBox(QSpinBox* spin, u16 zero, u16 min, u16 max,
|
||||
ControlState controller_state);
|
||||
std::optional<ControlState> GetSpinBox(QSpinBox* spin, u16 zero, ControlState controller_state,
|
||||
ControlState scale);
|
||||
|
||||
std::map<TASCheckBox*, bool> m_checkbox_set_by_controller;
|
||||
std::map<QSpinBox*, u8> m_spinbox_most_recent_values_u8;
|
||||
std::map<QSpinBox*, u8> m_spinbox_most_recent_values_u16;
|
||||
std::map<QSpinBox*, u16> m_spinbox_most_recent_values;
|
||||
};
|
||||
|
Reference in New Issue
Block a user