hook up most of the stuff

This commit is contained in:
Nadia Holmquist Pedersen 2023-07-29 18:09:31 +02:00
parent 1d3d9cd150
commit 2894d9100d
8 changed files with 309 additions and 31 deletions

View File

@ -34,6 +34,15 @@ int HKJoyMapping[HK_MAX];
int JoystickID;
int JoyTouchMode;
int JoyTouchMovementStyle;
int JoyTouchStick;
int JoyTouchButton;
int JoyTouchRecenterButton;
std::string JoyTouchCursorColor;
int JoyTouchCursorHideDelay;
int JoyTouchSensitivity;
int WindowWidth;
int WindowHeight;
bool WindowMaximized;
@ -211,6 +220,15 @@ ConfigEntry ConfigFile[] =
{"JoystickID", 0, &JoystickID, 0, true},
{"JoyTouchMode", 0, &JoyTouchMode, 0, true},
{"JoyTouchMovementStyle", 0, &JoyTouchMovementStyle, 0, true},
{"JoyTouchStick", 0, &JoyTouchStick, 0, true},
{"JoyTouchButton", 0, &JoyTouchButton, -1, true},
{"JoyTouchRecenterButton", 0, &JoyTouchRecenterButton, -1, true},
{"JoyTouchSensitivity", 0, &JoyTouchSensitivity, 100, true},
{"JoyTouchCursorColor", 2, &JoyTouchCursorColor, (std::string)"#FF0000", true},
{"JoyTouchCursorHideDelay", 0, &JoyTouchCursorHideDelay, 5, true},
{"WindowWidth", 0, &WindowWidth, 256, true},
{"WindowHeight", 0, &WindowHeight, 384, true},
{"WindowMax", 1, &WindowMaximized, false, true},

View File

@ -91,6 +91,15 @@ extern int HKJoyMapping[HK_MAX];
extern int JoystickID;
extern int JoyTouchMode;
extern int JoyTouchMovementStyle;
extern int JoyTouchStick;
extern int JoyTouchButton;
extern int JoyTouchRecenterButton;
extern std::string JoyTouchCursorColor;
extern int JoyTouchCursorHideDelay;
extern int JoyTouchSensitivity;
extern int WindowWidth;
extern int WindowHeight;
extern bool WindowMaximized;

View File

@ -242,12 +242,12 @@ bool JoystickTouchModeAvailable(JoystickTouchMode mode)
bool SetJoystickTouchMode(JoystickTouchMode mode)
{
JoystickTouch = mode;
if (!JoystickTouchModeAvailable(mode))
return false;
SDL_GameControllerSetSensorEnabled(GameController, SDL_SENSOR_GYRO, mode.mode == JoystickTouchMode::gyroscope ? SDL_TRUE : SDL_FALSE);
JoystickTouch = mode;
return true;
}
@ -437,6 +437,33 @@ void Process()
UpdateJoystickTouch();
}
void SaveJoystickTouchMode()
{
using Mode = JoystickTouchMode;
Mode mode = JoystickTouch;
Config::JoyTouchMode = mode.mode;
Config::JoyTouchMovementStyle = mode.style;
Config::JoyTouchStick = mode.stick;
Config::JoyTouchButton = mode.touchButton;
Config::JoyTouchRecenterButton = mode.recenterButton;
Config::JoyTouchSensitivity = (int) std::round(mode.sensitivity * 100.f);
}
void LoadJoystickTouchMode()
{
using Mode = JoystickTouchMode;
Mode mode = {
.mode = (Mode::Mode) Config::JoyTouchMode,
.style = (Mode::Style) Config::JoyTouchMovementStyle,
.stick = (Mode::AnalogStick) Config::JoyTouchStick,
.sensitivity = ((float) Config::JoyTouchSensitivity) / 100.f,
.touchButton = Config::JoyTouchButton,
.recenterButton = Config::JoyTouchRecenterButton
};
SetJoystickTouchMode(mode);
}
bool HotkeyDown(int id) { return HotkeyMask & (1<<id); }
bool HotkeyPressed(int id) { return HotkeyPress & (1<<id); }

View File

@ -19,6 +19,8 @@
#ifndef INPUT_H
#define INPUT_H
#include <SDL2/SDL.h>
#include "types.h"
namespace Input
@ -44,6 +46,7 @@ struct JoystickTouchMode {
float sensitivity;
int touchButton;
int recenterButton;
};
extern JoystickTouchMode JoystickTouch;
@ -57,7 +60,10 @@ void CloseJoystick();
void KeyPress(QKeyEvent* event);
void KeyRelease(QKeyEvent* event);
bool JoystickTouchModeAvailable(JoystickTouchMode mode);
bool SetJoystickTouchMode(JoystickTouchMode mode);
void SaveJoystickTouchMode();
void LoadJoystickTouchMode();
void Process();

View File

@ -90,6 +90,16 @@ InputConfigDialog::InputConfigDialog(QWidget* parent) : QDialog(parent), ui(new
ui->lblInstanceNum->setText(QString("Configuring mappings for instance %1").arg(inst+1));
else
ui->lblInstanceNum->hide();
QLayout* layout = ui->btnJoyTouchPress->parentWidget()->layout();
recenterBtn = new JoyMapButton(&recenterMapping, false);
joyPressBtn = new JoyMapButton(&joyPressMapping, false);
layout->replaceWidget(ui->btnJoyTouchRecenter, recenterBtn);
layout->replaceWidget(ui->btnJoyTouchPress, joyPressBtn);
joyTouchModeToUI(Input::JoystickTouch);
updateJoyTouchOptions();
}
InputConfigDialog::~InputConfigDialog()
@ -196,6 +206,10 @@ void InputConfigDialog::on_InputConfigDialog_accepted()
}
Config::JoystickID = Input::JoystickID;
Input::SetJoystickTouchMode(joyTouchModeFromUI());
Input::SaveJoystickTouchMode();
Config::Save();
closeDlg();
@ -226,4 +240,126 @@ void InputConfigDialog::on_cbxJoystick_currentIndexChanged(int id)
Input::JoystickID = id;
Input::OpenJoystick();
updateJoyTouchOptions();
}
Input::JoystickTouchMode InputConfigDialog::joyTouchModeFromUI()
{
using Mode = Input::JoystickTouchMode;
Mode mode = {};
QAbstractButton* uiMode = ui->grpJoyTouchInput->checkedButton();
QAbstractButton* uiStyle = ui->grpJoyTouchStyle->checkedButton();
QAbstractButton* uiStick = ui->grpJoyTouchStick->checkedButton();
if (uiMode == ui->rbTouchNone)
mode.mode = Mode::none;
else if (uiMode == ui->rbTouchAnalog)
mode.mode = Mode::analogStick;
else if (uiMode == ui->rbTouchTouchpad)
mode.mode = Mode::touchpad;
else if (uiMode == ui->rbTouchGyro)
mode.mode = Mode::gyroscope;
mode.style = uiStyle == ui->rbTouchAbsolute ? Mode::absolute : Mode::relative;
mode.stick = uiStick == ui->rbStickLeft ? Mode::leftStick : Mode::rightStick;
mode.touchButton = joyPressMapping;
mode.recenterButton = recenterMapping;
return mode;
}
void InputConfigDialog::joyTouchModeToUI(Input::JoystickTouchMode mode)
{
using Mode = Input::JoystickTouchMode;
switch (mode.mode)
{
case Mode::none:
ui->rbTouchNone->setChecked(true);
break;
case Mode::analogStick:
ui->rbTouchAnalog->setChecked(true);
break;
case Mode::touchpad:
ui->rbTouchTouchpad->setChecked(true);
break;
case Mode::gyroscope:
ui->rbTouchGyro->setChecked(true);
break;
}
if (mode.style == Mode::relative)
ui->rbTouchRelative->setChecked(true);
else
ui->rbTouchAbsolute->setChecked(true);
if (mode.stick == Mode::leftStick)
ui->rbStickLeft->setChecked(true);
else
ui->rbStickRight->setChecked(true);
recenterMapping = mode.recenterButton;
joyPressMapping = mode.touchButton;
}
void InputConfigDialog::updateJoyTouchOptions()
{
using namespace Input;
using Mode = JoystickTouchMode;
JoystickTouchMode tempMode = {};
QAbstractButton* currentMode = ui->grpJoyTouchInput->checkedButton();
bool relative = ui->grpJoyTouchStyle->checkedButton() == ui->rbTouchRelative;
JoystickTouchMode analogMode = { .mode = JoystickTouchMode::gyroscope };
bool currentAvailable = JoystickTouchModeAvailable(JoystickTouch);
bool styleEnabled = (currentMode == ui->rbTouchAnalog || currentMode == ui->rbTouchTouchpad) && currentAvailable;
bool stickEnabled = currentMode == ui->rbTouchAnalog && currentAvailable;
bool recenterEnabled = (currentMode == ui->rbTouchGyro || relative) && currentAvailable;
bool pressEnabled = currentMode != ui->rbTouchNone && currentAvailable;
tempMode.mode = Mode::analogStick;
tempMode.stick = Mode::leftStick;
bool leftAvailable = JoystickTouchModeAvailable(tempMode);
tempMode.stick = Mode::rightStick;
bool rightAvailable = JoystickTouchModeAvailable(tempMode);
tempMode.mode = Mode::touchpad;
bool touchpadAvailable = JoystickTouchModeAvailable(tempMode);
tempMode.mode = Mode::gyroscope;
bool gyroAvailable = JoystickTouchModeAvailable(tempMode);
ui->rbTouchAnalog->setEnabled(leftAvailable || rightAvailable);
ui->rbTouchTouchpad->setEnabled(touchpadAvailable);
ui->rbTouchGyro->setEnabled(gyroAvailable);
ui->lblJoyTouchStyle->setEnabled(styleEnabled);
ui->rbTouchRelative->setEnabled(styleEnabled);
ui->rbTouchAbsolute->setEnabled(styleEnabled);
ui->lblAnalogStick->setEnabled(stickEnabled && (leftAvailable || rightAvailable));
ui->rbStickLeft->setEnabled(stickEnabled && leftAvailable);
ui->rbStickRight->setEnabled(stickEnabled && rightAvailable);
ui->lblRecenter->setEnabled(recenterEnabled);
ui->lblJoyTouchPress->setEnabled(pressEnabled);
recenterBtn->setEnabled(recenterEnabled);
joyPressBtn->setEnabled(pressEnabled);
}
void InputConfigDialog::on_grpJoyTouchInput_buttonClicked(QAbstractButton* btn)
{
updateJoyTouchOptions();
}
void InputConfigDialog::on_grpJoyTouchStyle_buttonClicked(QAbstractButton* btn)
{
updateJoyTouchOptions();
}

View File

@ -21,9 +21,12 @@
#include <QDialog>
#include <QPushButton>
#include <QRadioButton>
#include <initializer_list>
#include "Config.h"
#include "Input.h"
#include "MapButton.h"
static constexpr int keypad_num = 12;
@ -115,17 +118,28 @@ private slots:
void on_btnJoyMapSwitch_clicked();
void on_cbxJoystick_currentIndexChanged(int id);
void on_grpJoyTouchInput_buttonClicked(QAbstractButton* btn);
void on_grpJoyTouchStyle_buttonClicked(QAbstractButton* btn);
private:
void populatePage(QWidget* page,
const std::initializer_list<const char*>& labels,
int* keymap, int* joymap);
void setupKeypadPage();
void updateJoyTouchOptions();
Input::JoystickTouchMode joyTouchModeFromUI();
void joyTouchModeToUI(Input::JoystickTouchMode mode);
Ui::InputConfigDialog* ui;
int keypadKeyMap[12], keypadJoyMap[12];
int addonsKeyMap[hk_addons.size()], addonsJoyMap[hk_addons.size()];
int hkGeneralKeyMap[hk_general.size()], hkGeneralJoyMap[hk_general.size()];
int recenterMapping;
int joyPressMapping;
JoyMapButton* recenterBtn;
JoyMapButton* joyPressBtn;
};

View File

@ -55,6 +55,9 @@
<property name="text">
<string>Joystick:</string>
</property>
<property name="buddy">
<cstring>cbxJoystick</cstring>
</property>
</widget>
</item>
<item>
@ -2371,10 +2374,13 @@
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_32">
<widget class="QLabel" name="lblJoyTouchInput">
<property name="text">
<string>Controller input</string>
</property>
<property name="buddy">
<cstring>rbTouchNone</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
@ -2396,41 +2402,56 @@
<number>0</number>
</property>
<item>
<widget class="QRadioButton" name="radioButton">
<widget class="QRadioButton" name="rbTouchNone">
<property name="text">
<string>None (mouse only)</string>
</property>
<attribute name="buttonGroup">
<string notr="true">grpJoyTouchInput</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_2">
<widget class="QRadioButton" name="rbTouchAnalog">
<property name="text">
<string>Analog stick</string>
</property>
<attribute name="buttonGroup">
<string notr="true">grpJoyTouchInput</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_3">
<widget class="QRadioButton" name="rbTouchTouchpad">
<property name="text">
<string>Touchpad</string>
</property>
<attribute name="buttonGroup">
<string notr="true">grpJoyTouchInput</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_4">
<widget class="QRadioButton" name="rbTouchGyro">
<property name="text">
<string>Gyroscope</string>
</property>
<attribute name="buttonGroup">
<string notr="true">grpJoyTouchInput</string>
</attribute>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_36">
<widget class="QLabel" name="lblJoyTouchStyle">
<property name="text">
<string>Movement style</string>
</property>
<property name="buddy">
<cstring>rbTouchRelative</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
@ -2458,41 +2479,36 @@
<number>0</number>
</property>
<item>
<widget class="QRadioButton" name="radioButton_5">
<widget class="QRadioButton" name="rbTouchRelative">
<property name="text">
<string>Relative</string>
</property>
<attribute name="buttonGroup">
<string notr="true">grpJoyTouchStyle</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_6">
<widget class="QRadioButton" name="rbTouchAbsolute">
<property name="text">
<string>Absolute</string>
</property>
<attribute name="buttonGroup">
<string notr="true">grpJoyTouchStyle</string>
</attribute>
</widget>
</item>
</layout>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_37">
<property name="text">
<string>Recenter</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>[PLACEHOLDER]</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_38">
<widget class="QLabel" name="lblAnalogStick">
<property name="text">
<string>Analog stick</string>
</property>
<property name="buddy">
<cstring>rbStickLeft</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
@ -2520,22 +2536,62 @@
<number>0</number>
</property>
<item>
<widget class="QRadioButton" name="radioButton_7">
<widget class="QRadioButton" name="rbStickLeft">
<property name="text">
<string>Left</string>
</property>
<attribute name="buttonGroup">
<string notr="true">grpJoyTouchStick</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_8">
<widget class="QRadioButton" name="rbStickRight">
<property name="text">
<string>Right</string>
</property>
<attribute name="buttonGroup">
<string notr="true">grpJoyTouchStick</string>
</attribute>
</widget>
</item>
</layout>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="lblRecenter">
<property name="text">
<string>Recenter</string>
</property>
<property name="buddy">
<cstring>btnJoyTouchRecenter</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="btnJoyTouchRecenter">
<property name="text">
<string>[PLACEHOLDER]</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="lblJoyTouchPress">
<property name="text">
<string>Touch</string>
</property>
<property name="buddy">
<cstring>btnJoyTouchPress</cstring>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QPushButton" name="btnJoyTouchPress">
<property name="text">
<string>[PLACEHOLDER]</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@ -2568,6 +2624,9 @@
<property name="text">
<string>Color</string>
</property>
<property name="buddy">
<cstring>pushButton</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
@ -2582,6 +2641,9 @@
<property name="text">
<string>Hide after</string>
</property>
<property name="buddy">
<cstring>spinBox</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
@ -2677,8 +2739,8 @@
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
<x>496</x>
<y>763</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
@ -2693,8 +2755,8 @@
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
<x>564</x>
<y>763</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
@ -2703,4 +2765,9 @@
</hints>
</connection>
</connections>
<buttongroups>
<buttongroup name="grpJoyTouchStyle"/>
<buttongroup name="grpJoyTouchStick"/>
<buttongroup name="grpJoyTouchInput"/>
</buttongroups>
</ui>

View File

@ -3312,6 +3312,7 @@ int main(int argc, char** argv)
Input::JoystickID = Config::JoystickID;
Input::OpenJoystick();
Input::LoadJoystickTouchMode();
mainWindow = new MainWindow();
if (options->fullscreen)