tiny refactoring around the input config dialog
This commit is contained in:
parent
ca221381e9
commit
4ba7a2c5e6
|
@ -25,7 +25,6 @@
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "Platform.h"
|
#include "Platform.h"
|
||||||
#include "Config.h"
|
|
||||||
|
|
||||||
#include "MapButton.h"
|
#include "MapButton.h"
|
||||||
#include "Input.h"
|
#include "Input.h"
|
||||||
|
@ -38,51 +37,6 @@ InputConfigDialog* InputConfigDialog::currentDlg = nullptr;
|
||||||
const int dskeyorder[12] = {0, 1, 10, 11, 5, 4, 6, 7, 9, 8, 2, 3};
|
const int dskeyorder[12] = {0, 1, 10, 11, 5, 4, 6, 7, 9, 8, 2, 3};
|
||||||
const char* dskeylabels[12] = {"A", "B", "X", "Y", "Left", "Right", "Up", "Down", "L", "R", "Select", "Start"};
|
const char* dskeylabels[12] = {"A", "B", "X", "Y", "Left", "Right", "Up", "Down", "L", "R", "Select", "Start"};
|
||||||
|
|
||||||
const int hk_addons[] =
|
|
||||||
{
|
|
||||||
HK_SolarSensorIncrease,
|
|
||||||
HK_SolarSensorDecrease,
|
|
||||||
};
|
|
||||||
|
|
||||||
const char* hk_addons_labels[] =
|
|
||||||
{
|
|
||||||
"[Boktai] Sunlight + ",
|
|
||||||
"[Boktai] Sunlight - ",
|
|
||||||
};
|
|
||||||
|
|
||||||
const int hk_general[] =
|
|
||||||
{
|
|
||||||
HK_Pause,
|
|
||||||
HK_Reset,
|
|
||||||
HK_FrameStep,
|
|
||||||
HK_FastForward,
|
|
||||||
HK_FastForwardToggle,
|
|
||||||
HK_FullscreenToggle,
|
|
||||||
HK_Lid,
|
|
||||||
HK_Mic,
|
|
||||||
HK_SwapScreens,
|
|
||||||
HK_SwapScreenEmphasis
|
|
||||||
};
|
|
||||||
|
|
||||||
const char* hk_general_labels[] =
|
|
||||||
{
|
|
||||||
"Pause/resume",
|
|
||||||
"Reset",
|
|
||||||
"Frame step",
|
|
||||||
"Fast forward",
|
|
||||||
"Toggle FPS limit",
|
|
||||||
"Toggle fullscreen",
|
|
||||||
"Close/open lid",
|
|
||||||
"Microphone",
|
|
||||||
"Swap screens",
|
|
||||||
"Swap screen emphasis"
|
|
||||||
};
|
|
||||||
|
|
||||||
const int keypad_num = 12;
|
|
||||||
const int hk_addons_num = 2;
|
|
||||||
const int hk_general_num = 10;
|
|
||||||
|
|
||||||
|
|
||||||
InputConfigDialog::InputConfigDialog(QWidget* parent) : QDialog(parent), ui(new Ui::InputConfigDialog)
|
InputConfigDialog::InputConfigDialog(QWidget* parent) : QDialog(parent), ui(new Ui::InputConfigDialog)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
@ -94,20 +48,24 @@ InputConfigDialog::InputConfigDialog(QWidget* parent) : QDialog(parent), ui(new
|
||||||
keypadJoyMap[i] = Config::JoyMapping[dskeyorder[i]];
|
keypadJoyMap[i] = Config::JoyMapping[dskeyorder[i]];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < hk_addons_num; i++)
|
int i = 0;
|
||||||
|
for (int hotkey : hk_addons)
|
||||||
{
|
{
|
||||||
addonsKeyMap[i] = Config::HKKeyMapping[hk_addons[i]];
|
addonsKeyMap[i] = Config::HKKeyMapping[hotkey];
|
||||||
addonsJoyMap[i] = Config::HKJoyMapping[hk_addons[i]];
|
addonsJoyMap[i] = Config::HKJoyMapping[hotkey];
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < hk_general_num; i++)
|
i = 0;
|
||||||
|
for (int hotkey : hk_general)
|
||||||
{
|
{
|
||||||
hkGeneralKeyMap[i] = Config::HKKeyMapping[hk_general[i]];
|
hkGeneralKeyMap[i] = Config::HKKeyMapping[hotkey];
|
||||||
hkGeneralJoyMap[i] = Config::HKJoyMapping[hk_general[i]];
|
hkGeneralJoyMap[i] = Config::HKJoyMapping[hotkey];
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
populatePage(ui->tabAddons, hk_addons_num, hk_addons_labels, addonsKeyMap, addonsJoyMap);
|
populatePage(ui->tabAddons, hk_addons_labels, addonsKeyMap, addonsJoyMap);
|
||||||
populatePage(ui->tabHotkeysGeneral, hk_general_num, hk_general_labels, hkGeneralKeyMap, hkGeneralJoyMap);
|
populatePage(ui->tabHotkeysGeneral, hk_general_labels, hkGeneralKeyMap, hkGeneralJoyMap);
|
||||||
|
|
||||||
int njoy = SDL_NumJoysticks();
|
int njoy = SDL_NumJoysticks();
|
||||||
if (njoy > 0)
|
if (njoy > 0)
|
||||||
|
@ -162,7 +120,9 @@ void InputConfigDialog::setupKeypadPage()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputConfigDialog::populatePage(QWidget* page, int num, const char** labels, int* keymap, int* joymap)
|
void InputConfigDialog::populatePage(QWidget* page,
|
||||||
|
const std::initializer_list<const char*>& labels,
|
||||||
|
int* keymap, int* joymap)
|
||||||
{
|
{
|
||||||
// kind of a hack
|
// kind of a hack
|
||||||
bool ishotkey = (page != ui->tabInput);
|
bool ishotkey = (page != ui->tabInput);
|
||||||
|
@ -176,15 +136,17 @@ void InputConfigDialog::populatePage(QWidget* page, int num, const char** labels
|
||||||
main_layout->addWidget(group);
|
main_layout->addWidget(group);
|
||||||
group_layout = new QGridLayout();
|
group_layout = new QGridLayout();
|
||||||
group_layout->setSpacing(1);
|
group_layout->setSpacing(1);
|
||||||
for (int i = 0; i < num; i++)
|
int i = 0;
|
||||||
|
for (const char* labelStr : labels)
|
||||||
{
|
{
|
||||||
QLabel* label = new QLabel(QString(labels[i])+":");
|
QLabel* label = new QLabel(QString(labelStr)+":");
|
||||||
KeyMapButton* btn = new KeyMapButton(&keymap[i], ishotkey);
|
KeyMapButton* btn = new KeyMapButton(&keymap[i], ishotkey);
|
||||||
|
|
||||||
group_layout->addWidget(label, i, 0);
|
group_layout->addWidget(label, i, 0);
|
||||||
group_layout->addWidget(btn, i, 1);
|
group_layout->addWidget(btn, i, 1);
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
group_layout->setRowStretch(num, 1);
|
group_layout->setRowStretch(labels.size(), 1);
|
||||||
group->setLayout(group_layout);
|
group->setLayout(group_layout);
|
||||||
group->setMinimumWidth(275);
|
group->setMinimumWidth(275);
|
||||||
|
|
||||||
|
@ -192,15 +154,17 @@ void InputConfigDialog::populatePage(QWidget* page, int num, const char** labels
|
||||||
main_layout->addWidget(group);
|
main_layout->addWidget(group);
|
||||||
group_layout = new QGridLayout();
|
group_layout = new QGridLayout();
|
||||||
group_layout->setSpacing(1);
|
group_layout->setSpacing(1);
|
||||||
for (int i = 0; i < num; i++)
|
i = 0;
|
||||||
|
for (const char* labelStr : labels)
|
||||||
{
|
{
|
||||||
QLabel* label = new QLabel(QString(labels[i])+":");
|
QLabel* label = new QLabel(QString(labelStr)+":");
|
||||||
JoyMapButton* btn = new JoyMapButton(&joymap[i], ishotkey);
|
JoyMapButton* btn = new JoyMapButton(&joymap[i], ishotkey);
|
||||||
|
|
||||||
group_layout->addWidget(label, i, 0);
|
group_layout->addWidget(label, i, 0);
|
||||||
group_layout->addWidget(btn, i, 1);
|
group_layout->addWidget(btn, i, 1);
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
group_layout->setRowStretch(num, 1);
|
group_layout->setRowStretch(labels.size(), 1);
|
||||||
group->setLayout(group_layout);
|
group->setLayout(group_layout);
|
||||||
group->setMinimumWidth(275);
|
group->setMinimumWidth(275);
|
||||||
|
|
||||||
|
@ -215,16 +179,20 @@ void InputConfigDialog::on_InputConfigDialog_accepted()
|
||||||
Config::JoyMapping[dskeyorder[i]] = keypadJoyMap[i];
|
Config::JoyMapping[dskeyorder[i]] = keypadJoyMap[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < hk_addons_num; i++)
|
int i = 0;
|
||||||
|
for (int hotkey : hk_addons)
|
||||||
{
|
{
|
||||||
Config::HKKeyMapping[hk_addons[i]] = addonsKeyMap[i];
|
Config::HKKeyMapping[hotkey] = addonsKeyMap[i];
|
||||||
Config::HKJoyMapping[hk_addons[i]] = addonsJoyMap[i];
|
Config::HKJoyMapping[hotkey] = addonsJoyMap[i];
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < hk_general_num; i++)
|
i = 0;
|
||||||
|
for (int hotkey : hk_general)
|
||||||
{
|
{
|
||||||
Config::HKKeyMapping[hk_general[i]] = hkGeneralKeyMap[i];
|
Config::HKKeyMapping[hotkey] = hkGeneralKeyMap[i];
|
||||||
Config::HKJoyMapping[hk_general[i]] = hkGeneralJoyMap[i];
|
Config::HKJoyMapping[hotkey] = hkGeneralJoyMap[i];
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
Config::JoystickID = Input::JoystickID;
|
Config::JoystickID = Input::JoystickID;
|
||||||
|
|
|
@ -21,6 +21,56 @@
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <initializer_list>
|
||||||
|
|
||||||
|
#include "Config.h"
|
||||||
|
|
||||||
|
static constexpr int keypad_num = 12;
|
||||||
|
|
||||||
|
static constexpr std::initializer_list<int> hk_addons =
|
||||||
|
{
|
||||||
|
HK_SolarSensorIncrease,
|
||||||
|
HK_SolarSensorDecrease,
|
||||||
|
};
|
||||||
|
|
||||||
|
static constexpr std::initializer_list<const char*> hk_addons_labels =
|
||||||
|
{
|
||||||
|
"[Boktai] Sunlight + ",
|
||||||
|
"[Boktai] Sunlight - ",
|
||||||
|
};
|
||||||
|
|
||||||
|
static_assert(hk_addons.size() == hk_addons_labels.size());
|
||||||
|
|
||||||
|
static constexpr std::initializer_list<int> hk_general =
|
||||||
|
{
|
||||||
|
HK_Pause,
|
||||||
|
HK_Reset,
|
||||||
|
HK_FrameStep,
|
||||||
|
HK_FastForward,
|
||||||
|
HK_FastForwardToggle,
|
||||||
|
HK_FullscreenToggle,
|
||||||
|
HK_Lid,
|
||||||
|
HK_Mic,
|
||||||
|
HK_SwapScreens,
|
||||||
|
HK_SwapScreenEmphasis
|
||||||
|
};
|
||||||
|
|
||||||
|
static constexpr std::initializer_list<const char*> hk_general_labels =
|
||||||
|
{
|
||||||
|
"Pause/resume",
|
||||||
|
"Reset",
|
||||||
|
"Frame step",
|
||||||
|
"Fast forward",
|
||||||
|
"Toggle FPS limit",
|
||||||
|
"Toggle fullscreen",
|
||||||
|
"Close/open lid",
|
||||||
|
"Microphone",
|
||||||
|
"Swap screens",
|
||||||
|
"Swap screen emphasis"
|
||||||
|
};
|
||||||
|
|
||||||
|
static_assert(hk_general.size() == hk_general_labels.size());
|
||||||
|
|
||||||
|
|
||||||
namespace Ui { class InputConfigDialog; }
|
namespace Ui { class InputConfigDialog; }
|
||||||
class InputConfigDialog;
|
class InputConfigDialog;
|
||||||
|
@ -60,14 +110,16 @@ private slots:
|
||||||
void on_cbxJoystick_currentIndexChanged(int id);
|
void on_cbxJoystick_currentIndexChanged(int id);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void populatePage(QWidget* page, int num, const char** labels, int* keymap, int* joymap);
|
void populatePage(QWidget* page,
|
||||||
|
const std::initializer_list<const char*>& labels,
|
||||||
|
int* keymap, int* joymap);
|
||||||
void setupKeypadPage();
|
void setupKeypadPage();
|
||||||
|
|
||||||
Ui::InputConfigDialog* ui;
|
Ui::InputConfigDialog* ui;
|
||||||
|
|
||||||
int keypadKeyMap[12], keypadJoyMap[12];
|
int keypadKeyMap[12], keypadJoyMap[12];
|
||||||
int addonsKeyMap[2], addonsJoyMap[2];
|
int addonsKeyMap[hk_addons.size()], addonsJoyMap[hk_addons.size()];
|
||||||
int hkGeneralKeyMap[9], hkGeneralJoyMap[9];
|
int hkGeneralKeyMap[hk_general.size()], hkGeneralJoyMap[hk_general.size()];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue