settings: Disable controller preview if controller is not active

This commit is contained in:
german77 2021-05-30 10:57:20 -05:00
parent e41c8b6780
commit ac48e059bc
3 changed files with 25 additions and 2 deletions

View file

@ -85,6 +85,8 @@ void PlayerControlPreview::SetConnectedStatus(bool checked) {
led_color[1] = led_pattern.position2 ? colors.led_on : colors.led_off; led_color[1] = led_pattern.position2 ? colors.led_on : colors.led_off;
led_color[2] = led_pattern.position3 ? colors.led_on : colors.led_off; led_color[2] = led_pattern.position3 ? colors.led_on : colors.led_off;
led_color[3] = led_pattern.position4 ? colors.led_on : colors.led_off; led_color[3] = led_pattern.position4 ? colors.led_on : colors.led_off;
is_enabled = checked;
ResetInputs();
} }
void PlayerControlPreview::SetControllerType(const Settings::ControllerType type) { void PlayerControlPreview::SetControllerType(const Settings::ControllerType type) {
@ -108,6 +110,7 @@ void PlayerControlPreview::EndMapping() {
analog_mapping_index = Settings::NativeAnalog::NumAnalogs; analog_mapping_index = Settings::NativeAnalog::NumAnalogs;
mapping_active = false; mapping_active = false;
blink_counter = 0; blink_counter = 0;
ResetInputs();
} }
void PlayerControlPreview::UpdateColors() { void PlayerControlPreview::UpdateColors() {
@ -156,7 +159,23 @@ void PlayerControlPreview::UpdateColors() {
// colors.right = QColor(Settings::values.players.GetValue()[player_index].body_color_right); // colors.right = QColor(Settings::values.players.GetValue()[player_index].body_color_right);
} }
void PlayerControlPreview::ResetInputs() {
for (std::size_t index = 0; index < button_values.size(); ++index) {
button_values[index] = false;
}
for (std::size_t index = 0; index < axis_values.size(); ++index) {
axis_values[index].properties = {0, 1, 0};
axis_values[index].value = {0, 0};
axis_values[index].raw_value = {0, 0};
}
update();
}
void PlayerControlPreview::UpdateInput() { void PlayerControlPreview::UpdateInput() {
if (!is_enabled && !mapping_active) {
return;
}
bool input_changed = false; bool input_changed = false;
const auto& button_state = buttons; const auto& button_state = buttons;
for (std::size_t index = 0; index < button_values.size(); ++index) { for (std::size_t index = 0; index < button_values.size(); ++index) {

View file

@ -100,6 +100,7 @@ private:
static LedPattern GetColorPattern(std::size_t index, bool player_on); static LedPattern GetColorPattern(std::size_t index, bool player_on);
void UpdateColors(); void UpdateColors();
void ResetInputs();
// Draw controller functions // Draw controller functions
void DrawHandheldController(QPainter& p, QPointF center); void DrawHandheldController(QPainter& p, QPointF center);
@ -176,6 +177,7 @@ private:
using StickArray = using StickArray =
std::array<std::unique_ptr<Input::AnalogDevice>, Settings::NativeAnalog::NUM_STICKS_HID>; std::array<std::unique_ptr<Input::AnalogDevice>, Settings::NativeAnalog::NUM_STICKS_HID>;
bool is_enabled{};
bool mapping_active{}; bool mapping_active{};
int blink_counter{}; int blink_counter{};
QColor button_color{}; QColor button_color{};

View file

@ -28,6 +28,7 @@ ControllerDialog::ControllerDialog(QWidget* parent) : QWidget(parent, Qt::Dialog
// Configure focus so that widget is focusable and the dialog automatically forwards focus to // Configure focus so that widget is focusable and the dialog automatically forwards focus to
// it. // it.
setFocusProxy(widget); setFocusProxy(widget);
widget->SetConnectedStatus(false);
widget->setFocusPolicy(Qt::StrongFocus); widget->setFocusPolicy(Qt::StrongFocus);
widget->setFocus(); widget->setFocus();
} }
@ -36,9 +37,8 @@ void ControllerDialog::refreshConfiguration() {
const auto& players = Settings::values.players.GetValue(); const auto& players = Settings::values.players.GetValue();
constexpr std::size_t player = 0; constexpr std::size_t player = 0;
widget->SetPlayerInputRaw(player, players[player].buttons, players[player].analogs); widget->SetPlayerInputRaw(player, players[player].buttons, players[player].analogs);
widget->SetConnectedStatus(players[player].connected);
widget->SetControllerType(players[player].controller_type); widget->SetControllerType(players[player].controller_type);
widget->repaint(); widget->SetConnectedStatus(players[player].connected);
} }
QAction* ControllerDialog::toggleViewAction() { QAction* ControllerDialog::toggleViewAction() {
@ -56,6 +56,7 @@ void ControllerDialog::showEvent(QShowEvent* ev) {
if (toggle_view_action) { if (toggle_view_action) {
toggle_view_action->setChecked(isVisible()); toggle_view_action->setChecked(isVisible());
} }
refreshConfiguration();
QWidget::showEvent(ev); QWidget::showEvent(ev);
} }
@ -63,5 +64,6 @@ void ControllerDialog::hideEvent(QHideEvent* ev) {
if (toggle_view_action) { if (toggle_view_action) {
toggle_view_action->setChecked(isVisible()); toggle_view_action->setChecked(isVisible());
} }
widget->SetConnectedStatus(false);
QWidget::hideEvent(ev); QWidget::hideEvent(ev);
} }