2020-07-22 16:35:15 +00:00
|
|
|
#pragma once
|
|
|
|
#include "common/types.h"
|
2020-08-29 12:19:28 +00:00
|
|
|
#include "core/controller.h"
|
2020-07-22 16:35:15 +00:00
|
|
|
#include "ui_inputbindingdialog.h"
|
|
|
|
#include <QtWidgets/QDialog>
|
2020-08-29 12:19:28 +00:00
|
|
|
#include <optional>
|
2020-07-22 16:35:15 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
class QtHostInterface;
|
|
|
|
|
|
|
|
class InputBindingDialog : public QDialog
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
InputBindingDialog(QtHostInterface* host_interface, std::string section_name, std::string key_name,
|
|
|
|
std::vector<std::string> bindings, QWidget* parent);
|
|
|
|
~InputBindingDialog();
|
|
|
|
|
|
|
|
protected Q_SLOTS:
|
2020-11-15 13:56:52 +00:00
|
|
|
void bindToControllerAxis(int controller_index, int axis_index, bool inverted,
|
|
|
|
std::optional<bool> half_axis_positive);
|
2020-08-29 12:19:28 +00:00
|
|
|
void bindToControllerButton(int controller_index, int button_index);
|
2020-11-15 13:56:52 +00:00
|
|
|
void bindToControllerHat(int controller_index, int hat_index, const QString& hat_direction);
|
2020-07-22 16:35:15 +00:00
|
|
|
void onAddBindingButtonClicked();
|
|
|
|
void onRemoveBindingButtonClicked();
|
|
|
|
void onClearBindingsButtonClicked();
|
|
|
|
void onInputListenTimerTimeout();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
enum : u32
|
|
|
|
{
|
|
|
|
TIMEOUT_FOR_BINDING = 5
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual bool eventFilter(QObject* watched, QEvent* event) override;
|
|
|
|
|
|
|
|
virtual void startListeningForInput(u32 timeout_in_seconds);
|
|
|
|
virtual void stopListeningForInput();
|
|
|
|
|
|
|
|
bool isListeningForInput() const { return m_input_listen_timer != nullptr; }
|
|
|
|
void addNewBinding(std::string new_binding);
|
|
|
|
|
|
|
|
void updateList();
|
|
|
|
void saveListToSettings();
|
|
|
|
|
|
|
|
Ui::InputBindingDialog m_ui;
|
|
|
|
|
|
|
|
QtHostInterface* m_host_interface;
|
|
|
|
|
|
|
|
std::string m_section_name;
|
|
|
|
std::string m_key_name;
|
|
|
|
std::vector<std::string> m_bindings;
|
|
|
|
std::string m_new_binding_value;
|
|
|
|
|
|
|
|
QTimer* m_input_listen_timer = nullptr;
|
|
|
|
u32 m_input_listen_remaining_seconds = 0;
|
|
|
|
};
|
|
|
|
|
2020-08-29 12:19:28 +00:00
|
|
|
class InputButtonBindingDialog final : public InputBindingDialog
|
2020-07-22 16:35:15 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
InputButtonBindingDialog(QtHostInterface* host_interface, std::string section_name, std::string key_name,
|
|
|
|
std::vector<std::string> bindings, QWidget* parent);
|
|
|
|
~InputButtonBindingDialog();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void startListeningForInput(u32 timeout_in_seconds) override;
|
|
|
|
void stopListeningForInput() override;
|
|
|
|
void hookControllerInput();
|
|
|
|
void unhookControllerInput();
|
|
|
|
};
|
|
|
|
|
2020-08-29 12:19:28 +00:00
|
|
|
class InputAxisBindingDialog final : public InputBindingDialog
|
2020-07-22 16:35:15 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
InputAxisBindingDialog(QtHostInterface* host_interface, std::string section_name, std::string key_name,
|
2020-08-29 12:19:28 +00:00
|
|
|
std::vector<std::string> bindings, Controller::AxisType axis_type, QWidget* parent);
|
2020-07-22 16:35:15 +00:00
|
|
|
~InputAxisBindingDialog();
|
|
|
|
|
|
|
|
protected:
|
2020-08-29 12:19:28 +00:00
|
|
|
bool eventFilter(QObject* watched, QEvent* event) override;
|
2020-07-22 16:35:15 +00:00
|
|
|
void startListeningForInput(u32 timeout_in_seconds) override;
|
|
|
|
void stopListeningForInput() override;
|
|
|
|
void hookControllerInput();
|
|
|
|
void unhookControllerInput();
|
2020-08-29 12:19:28 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Controller::AxisType m_axis_type;
|
2020-07-22 16:35:15 +00:00
|
|
|
};
|