configure_input: Add frontend text for GC adapter

Also streamlines some of the frontend text logic.
This commit is contained in:
ameerj 2021-03-08 19:00:18 -05:00
parent 700fa6b96a
commit 32f8a565f3

View File

@ -56,12 +56,12 @@ static QString ButtonToText(const Common::ParamPackage& param) {
if (!param.Has("engine")) { if (!param.Has("engine")) {
return QObject::tr("[not set]"); return QObject::tr("[not set]");
} }
const auto engine_str = param.Get("engine", "");
if (param.Get("engine", "") == "keyboard") { if (engine_str == "keyboard") {
return GetKeyName(param.Get("code", 0)); return GetKeyName(param.Get("code", 0));
} }
if (param.Get("engine", "") == "sdl") { if (engine_str == "sdl") {
if (param.Has("hat")) { if (param.Has("hat")) {
const QString hat_str = QString::fromStdString(param.Get("hat", "")); const QString hat_str = QString::fromStdString(param.Get("hat", ""));
const QString direction_str = QString::fromStdString(param.Get("direction", "")); const QString direction_str = QString::fromStdString(param.Get("direction", ""));
@ -85,7 +85,7 @@ static QString ButtonToText(const Common::ParamPackage& param) {
return {}; return {};
} }
if (param.Get("engine", "") == "gcpad") { if (engine_str == "gcpad") {
if (param.Has("axis")) { if (param.Has("axis")) {
const QString axis_str = QString::fromStdString(param.Get("axis", "")); const QString axis_str = QString::fromStdString(param.Get("axis", ""));
const QString direction_str = QString::fromStdString(param.Get("direction", "")); const QString direction_str = QString::fromStdString(param.Get("direction", ""));
@ -107,47 +107,31 @@ static QString AnalogToText(const Common::ParamPackage& param, const std::string
return QObject::tr("[not set]"); return QObject::tr("[not set]");
} }
if (param.Get("engine", "") == "analog_from_button") { const auto engine_str = param.Get("engine", "");
if (engine_str == "analog_from_button") {
return ButtonToText(Common::ParamPackage{param.Get(dir, "")}); return ButtonToText(Common::ParamPackage{param.Get(dir, "")});
} }
if (param.Get("engine", "") == "sdl") { const QString axis_x_str{QString::fromStdString(param.Get("axis_x", ""))};
const QString axis_y_str{QString::fromStdString(param.Get("axis_y", ""))};
static const QString plus_str{QString::fromStdString("+")};
static const QString minus_str{QString::fromStdString("-")};
if (engine_str == "sdl" || engine_str == "gcpad") {
if (dir == "modifier") { if (dir == "modifier") {
return QObject::tr("[unused]"); return QObject::tr("[unused]");
} }
if (dir == "left") {
if (dir == "left" || dir == "right") { return QObject::tr("Axis %1%2").arg(axis_x_str, minus_str);
const QString axis_x_str = QString::fromStdString(param.Get("axis_x", ""));
return QObject::tr("Axis %1").arg(axis_x_str);
} }
if (dir == "right") {
if (dir == "up" || dir == "down") { return QObject::tr("Axis %1%2").arg(axis_x_str, plus_str);
const QString axis_y_str = QString::fromStdString(param.Get("axis_y", ""));
return QObject::tr("Axis %1").arg(axis_y_str);
} }
if (dir == "up") {
return {}; return QObject::tr("Axis %1%2").arg(axis_y_str, plus_str);
}
if (param.Get("engine", "") == "gcpad") {
if (dir == "modifier") {
return QObject::tr("[unused]");
} }
if (dir == "down") {
if (dir == "left" || dir == "right") { return QObject::tr("Axis %1%2").arg(axis_y_str, minus_str);
const QString axis_x_str = QString::fromStdString(param.Get("axis_x", ""));
return QObject::tr("GC Axis %1").arg(axis_x_str);
} }
if (dir == "up" || dir == "down") {
const QString axis_y_str = QString::fromStdString(param.Get("axis_y", ""));
return QObject::tr("GC Axis %1").arg(axis_y_str);
}
return {}; return {};
} }
return QObject::tr("[unknown]"); return QObject::tr("[unknown]");
@ -456,21 +440,16 @@ void ConfigureInput::UpdateButtonLabels() {
if (!param.Has("deadzone")) { if (!param.Has("deadzone")) {
param.Set("deadzone", 0.1f); param.Set("deadzone", 0.1f);
} }
const auto slider_value = static_cast<int>(param.Get("deadzone", 0.1f) * 100);
analog_stick_slider->setValue(static_cast<int>(param.Get("deadzone", 0.1f) * 100)); analog_stick_slider_label->setText(tr("Deadzone: %1%").arg(slider_value));
if (analog_stick_slider->value() == 0) { analog_stick_slider->setValue(slider_value);
analog_stick_slider_label->setText(tr("Deadzone: 0%"));
}
} else { } else {
if (!param.Has("modifier_scale")) { if (!param.Has("modifier_scale")) {
param.Set("modifier_scale", 0.5f); param.Set("modifier_scale", 0.5f);
} }
const auto slider_value = static_cast<int>(param.Get("modifier_scale", 0.5f) * 100);
analog_stick_slider->setValue( analog_stick_slider_label->setText(tr("Modifier Scale: %1%").arg(slider_value));
static_cast<int>(param.Get("modifier_scale", 0.5f) * 100)); analog_stick_slider->setValue(slider_value);
if (analog_stick_slider->value() == 0) {
analog_stick_slider_label->setText(tr("Modifier Scale: 0%"));
}
} }
} }
} }