diff options
Diffstat (limited to 'src/citra_qt/config/controller_config.cpp')
| -rw-r--r-- | src/citra_qt/config/controller_config.cpp | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/src/citra_qt/config/controller_config.cpp b/src/citra_qt/config/controller_config.cpp new file mode 100644 index 000000000..52dfb627c --- /dev/null +++ b/src/citra_qt/config/controller_config.cpp | |||
| @@ -0,0 +1,91 @@ | |||
| 1 | #include <QDialogButtonBox> | ||
| 2 | |||
| 3 | #include "controller_config.hxx" | ||
| 4 | #include "controller_config_util.hxx" | ||
| 5 | |||
| 6 | /* TODO(bunnei): ImplementMe | ||
| 7 | |||
| 8 | using common::Config; | ||
| 9 | |||
| 10 | GControllerConfig::GControllerConfig(common::Config::ControllerPort* initial_config, QWidget* parent) : QWidget(parent) | ||
| 11 | { | ||
| 12 | ui.setupUi(this); | ||
| 13 | ((QGridLayout*)ui.mainStickTab->layout())->addWidget(new GStickConfig(Config::ANALOG_LEFT, Config::ANALOG_RIGHT, Config::ANALOG_UP, Config::ANALOG_DOWN, this, this), 1, 1); | ||
| 14 | ((QGridLayout*)ui.cStickTab->layout())->addWidget(new GStickConfig(Config::C_LEFT, Config::C_RIGHT, Config::C_UP, Config::C_DOWN, this, this), 1, 1); | ||
| 15 | ((QGridLayout*)ui.dPadTab->layout())->addWidget(new GStickConfig(Config::DPAD_LEFT, Config::DPAD_RIGHT, Config::DPAD_UP, Config::DPAD_DOWN, this, this), 1, 1); | ||
| 16 | |||
| 17 | // TODO: Arrange these more compactly? | ||
| 18 | QVBoxLayout* layout = (QVBoxLayout*)ui.buttonsTab->layout(); | ||
| 19 | layout->addWidget(new GButtonConfigGroup("A Button", Config::BUTTON_A, this, ui.buttonsTab)); | ||
| 20 | layout->addWidget(new GButtonConfigGroup("B Button", Config::BUTTON_B, this, ui.buttonsTab)); | ||
| 21 | layout->addWidget(new GButtonConfigGroup("X Button", Config::BUTTON_X, this, ui.buttonsTab)); | ||
| 22 | layout->addWidget(new GButtonConfigGroup("Y Button", Config::BUTTON_Y, this, ui.buttonsTab)); | ||
| 23 | layout->addWidget(new GButtonConfigGroup("Z Button", Config::BUTTON_Z, this, ui.buttonsTab)); | ||
| 24 | layout->addWidget(new GButtonConfigGroup("L Trigger", Config::TRIGGER_L, this, ui.buttonsTab)); | ||
| 25 | layout->addWidget(new GButtonConfigGroup("R Trigger", Config::TRIGGER_R, this, ui.buttonsTab)); | ||
| 26 | layout->addWidget(new GButtonConfigGroup("Start Button", Config::BUTTON_START, this, ui.buttonsTab)); | ||
| 27 | |||
| 28 | memcpy(config, initial_config, sizeof(config)); | ||
| 29 | |||
| 30 | emit ActivePortChanged(config[0]); | ||
| 31 | } | ||
| 32 | |||
| 33 | void GControllerConfig::OnKeyConfigChanged(common::Config::Control id, int key, const QString& name) | ||
| 34 | { | ||
| 35 | if (InputSourceJoypad()) | ||
| 36 | { | ||
| 37 | config[GetActiveController()].pads.key_code[id] = key; | ||
| 38 | } | ||
| 39 | else | ||
| 40 | { | ||
| 41 | config[GetActiveController()].keys.key_code[id] = key; | ||
| 42 | } | ||
| 43 | emit ActivePortChanged(config[GetActiveController()]); | ||
| 44 | } | ||
| 45 | |||
| 46 | int GControllerConfig::GetActiveController() | ||
| 47 | { | ||
| 48 | return ui.activeControllerCB->currentIndex(); | ||
| 49 | } | ||
| 50 | |||
| 51 | bool GControllerConfig::InputSourceJoypad() | ||
| 52 | { | ||
| 53 | return ui.inputSourceCB->currentIndex() == 1; | ||
| 54 | } | ||
| 55 | |||
| 56 | GControllerConfigDialog::GControllerConfigDialog(common::Config::ControllerPort* controller_ports, QWidget* parent) : QDialog(parent), config_ptr(controller_ports) | ||
| 57 | { | ||
| 58 | setWindowTitle(tr("Input configuration")); | ||
| 59 | |||
| 60 | QVBoxLayout* layout = new QVBoxLayout(this); | ||
| 61 | config_widget = new GControllerConfig(controller_ports, this); | ||
| 62 | layout->addWidget(config_widget); | ||
| 63 | |||
| 64 | QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); | ||
| 65 | layout->addWidget(buttons); | ||
| 66 | |||
| 67 | connect(buttons, SIGNAL(rejected()), this, SLOT(reject())); | ||
| 68 | connect(buttons, SIGNAL(accepted()), this, SLOT(accept())); | ||
| 69 | |||
| 70 | connect(this, SIGNAL(accepted()), this, SLOT(EnableChanges())); | ||
| 71 | |||
| 72 | layout->setSizeConstraint(QLayout::SetFixedSize); | ||
| 73 | setLayout(layout); | ||
| 74 | setModal(true); | ||
| 75 | show(); | ||
| 76 | } | ||
| 77 | |||
| 78 | void GControllerConfigDialog::EnableChanges() | ||
| 79 | { | ||
| 80 | for (unsigned int i = 0; i < 4; ++i) | ||
| 81 | { | ||
| 82 | memcpy(&config_ptr[i], &config_widget->GetControllerConfig(i), sizeof(common::Config::ControllerPort)); | ||
| 83 | |||
| 84 | if (common::g_config) { | ||
| 85 | // Apply changes if running a game | ||
| 86 | memcpy(&common::g_config->controller_ports(i), &config_widget->GetControllerConfig(i), sizeof(common::Config::ControllerPort)); | ||
| 87 | } | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | */ \ No newline at end of file | ||