Merge pull request #4940 from german77/nativeGC

HID: Implement GC controller in game
This commit is contained in:
bunnei
2021-02-15 10:32:19 -08:00
committed by GitHub
8 changed files with 209 additions and 6 deletions

View File

@ -67,6 +67,8 @@ bool IsControllerCompatible(Settings::ControllerType controller_type,
return parameters.allow_right_joycon;
case Settings::ControllerType::Handheld:
return parameters.enable_single_mode && parameters.allow_handheld;
case Settings::ControllerType::GameCube:
return parameters.allow_gamecube_controller;
default:
return false;
}
@ -370,7 +372,7 @@ void QtControllerSelectorDialog::SetSupportedControllers() {
QStringLiteral("image: url(:/controller/applet_joycon_right%0_disabled); ").arg(theme));
}
if (parameters.allow_pro_controller) {
if (parameters.allow_pro_controller || parameters.allow_gamecube_controller) {
ui->controllerSupported5->setStyleSheet(
QStringLiteral("image: url(:/controller/applet_pro_controller%0); ").arg(theme));
} else {
@ -420,6 +422,10 @@ void QtControllerSelectorDialog::SetEmulatedControllers(std::size_t player_index
Settings::ControllerType::Handheld);
emulated_controllers[player_index]->addItem(tr("Handheld"));
}
pairs.emplace_back(emulated_controllers[player_index]->count(),
Settings::ControllerType::GameCube);
emulated_controllers[player_index]->addItem(tr("GameCube Controller"));
}
Settings::ControllerType QtControllerSelectorDialog::GetControllerTypeFromIndex(
@ -461,6 +467,7 @@ void QtControllerSelectorDialog::UpdateControllerIcon(std::size_t player_index)
switch (GetControllerTypeFromIndex(emulated_controllers[player_index]->currentIndex(),
player_index)) {
case Settings::ControllerType::ProController:
case Settings::ControllerType::GameCube:
return QStringLiteral("image: url(:/controller/applet_pro_controller%0); ");
case Settings::ControllerType::DualJoyconDetached:
return QStringLiteral("image: url(:/controller/applet_dual_joycon%0); ");

View File

@ -467,10 +467,14 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
UpdateControllerIcon();
UpdateControllerAvailableButtons();
UpdateControllerEnabledButtons();
UpdateControllerButtonNames();
UpdateMotionButtons();
connect(ui->comboControllerType, qOverload<int>(&QComboBox::currentIndexChanged), [this](int) {
UpdateControllerIcon();
UpdateControllerAvailableButtons();
UpdateControllerEnabledButtons();
UpdateControllerButtonNames();
UpdateMotionButtons();
});
@ -558,9 +562,6 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
&ConfigureInputPlayer::SaveProfile);
LoadConfiguration();
// TODO(wwylele): enable this when we actually emulate it
ui->buttonHome->setEnabled(false);
ui->controllerFrame->SetPlayerInput(player_index, buttons_param, analogs_param);
ui->controllerFrame->SetConnectedStatus(ui->groupConnectedController->isChecked());
}
@ -924,6 +925,12 @@ void ConfigureInputPlayer::SetConnectableControllers() {
Settings::ControllerType::Handheld);
ui->comboControllerType->addItem(tr("Handheld"));
}
if (enable_all || npad_style_set.gamecube == 1) {
index_controller_type_pairs.emplace_back(ui->comboControllerType->count(),
Settings::ControllerType::GameCube);
ui->comboControllerType->addItem(tr("GameCube Controller"));
}
};
Core::System& system{Core::System::GetInstance()};
@ -1014,7 +1021,7 @@ void ConfigureInputPlayer::UpdateControllerAvailableButtons() {
// List of all the widgets that will be hidden by any of the following layouts that need
// "unhidden" after the controller type changes
const std::array<QWidget*, 9> layout_show = {
const std::array<QWidget*, 11> layout_show = {
ui->buttonShoulderButtonsSLSR,
ui->horizontalSpacerShoulderButtonsWidget,
ui->horizontalSpacerShoulderButtonsWidget2,
@ -1024,6 +1031,8 @@ void ConfigureInputPlayer::UpdateControllerAvailableButtons() {
ui->buttonShoulderButtonsRight,
ui->buttonMiscButtonsPlusHome,
ui->bottomRight,
ui->buttonMiscButtonsMinusGroup,
ui->buttonMiscButtonsScreenshotGroup,
};
for (auto* widget : layout_show) {
@ -1056,6 +1065,14 @@ void ConfigureInputPlayer::UpdateControllerAvailableButtons() {
ui->bottomLeft,
};
break;
case Settings::ControllerType::GameCube:
layout_hidden = {
ui->buttonShoulderButtonsSLSR,
ui->horizontalSpacerShoulderButtonsWidget2,
ui->buttonMiscButtonsMinusGroup,
ui->buttonMiscButtonsScreenshotGroup,
};
break;
}
for (auto* widget : layout_hidden) {
@ -1063,6 +1080,52 @@ void ConfigureInputPlayer::UpdateControllerAvailableButtons() {
}
}
void ConfigureInputPlayer::UpdateControllerEnabledButtons() {
auto layout = GetControllerTypeFromIndex(ui->comboControllerType->currentIndex());
if (debug) {
layout = Settings::ControllerType::ProController;
}
// List of all the widgets that will be disabled by any of the following layouts that need
// "enabled" after the controller type changes
const std::array<QWidget*, 4> layout_enable = {
ui->buttonHome,
ui->buttonLStickPressedGroup,
ui->groupRStickPressed,
ui->buttonShoulderButtonsButtonLGroup,
};
for (auto* widget : layout_enable) {
widget->setEnabled(true);
}
std::vector<QWidget*> layout_disable;
switch (layout) {
case Settings::ControllerType::ProController:
case Settings::ControllerType::DualJoyconDetached:
case Settings::ControllerType::Handheld:
case Settings::ControllerType::LeftJoycon:
case Settings::ControllerType::RightJoycon:
// TODO(wwylele): enable this when we actually emulate it
layout_disable = {
ui->buttonHome,
};
break;
case Settings::ControllerType::GameCube:
layout_disable = {
ui->buttonHome,
ui->buttonLStickPressedGroup,
ui->groupRStickPressed,
ui->buttonShoulderButtonsButtonLGroup,
};
break;
}
for (auto* widget : layout_disable) {
widget->setEnabled(false);
}
}
void ConfigureInputPlayer::UpdateMotionButtons() {
if (debug) {
// Motion isn't used with the debug controller, hide both groupboxes.
@ -1085,6 +1148,11 @@ void ConfigureInputPlayer::UpdateMotionButtons() {
ui->buttonMotionLeftGroup->hide();
ui->buttonMotionRightGroup->show();
break;
case Settings::ControllerType::GameCube:
// Hide both "Motion 1/2".
ui->buttonMotionLeftGroup->hide();
ui->buttonMotionRightGroup->hide();
break;
case Settings::ControllerType::DualJoyconDetached:
default:
// Show both "Motion 1/2".
@ -1094,6 +1162,36 @@ void ConfigureInputPlayer::UpdateMotionButtons() {
}
}
void ConfigureInputPlayer::UpdateControllerButtonNames() {
auto layout = GetControllerTypeFromIndex(ui->comboControllerType->currentIndex());
if (debug) {
layout = Settings::ControllerType::ProController;
}
switch (layout) {
case Settings::ControllerType::ProController:
case Settings::ControllerType::DualJoyconDetached:
case Settings::ControllerType::Handheld:
case Settings::ControllerType::LeftJoycon:
case Settings::ControllerType::RightJoycon:
ui->buttonMiscButtonsPlusGroup->setTitle(tr("Plus"));
ui->buttonShoulderButtonsButtonZLGroup->setTitle(tr("ZL"));
ui->buttonShoulderButtonsZRGroup->setTitle(tr("ZR"));
ui->buttonShoulderButtonsRGroup->setTitle(tr("R"));
ui->LStick->setTitle(tr("Left Stick"));
ui->RStick->setTitle(tr("Right Stick"));
break;
case Settings::ControllerType::GameCube:
ui->buttonMiscButtonsPlusGroup->setTitle(tr("Start / Pause"));
ui->buttonShoulderButtonsButtonZLGroup->setTitle(tr("L"));
ui->buttonShoulderButtonsZRGroup->setTitle(tr("R"));
ui->buttonShoulderButtonsRGroup->setTitle(tr("Z"));
ui->LStick->setTitle(tr("Control Stick"));
ui->RStick->setTitle(tr("C-Stick"));
break;
}
}
void ConfigureInputPlayer::UpdateMappingWithDefaults() {
if (ui->comboDevices->currentIndex() == 0) {
return;

View File

@ -143,9 +143,15 @@ private:
/// Hides and disables controller settings based on the current controller type.
void UpdateControllerAvailableButtons();
/// Disables controller settings based on the current controller type.
void UpdateControllerEnabledButtons();
/// Shows or hides motion groupboxes based on the current controller type.
void UpdateMotionButtons();
/// Alters the button names based on the current controller type.
void UpdateControllerButtonNames();
/// Gets the default controller mapping for this device and auto configures the input to match.
void UpdateMappingWithDefaults();

View File

@ -227,6 +227,9 @@ void PlayerControlPreview::paintEvent(QPaintEvent* event) {
case Settings::ControllerType::RightJoycon:
DrawRightController(p, center);
break;
case Settings::ControllerType::GameCube:
DrawGCController(p, center);
break;
case Settings::ControllerType::ProController:
default:
DrawProController(p, center);