| 1 | // Copyright 2017 Dolphin Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | |
| 4 | #include "InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.h" |
| 5 | |
| 6 | #include <cstddef> |
| 7 | #include <memory> |
| 8 | #include <string> |
| 9 | #include <utility> |
| 10 | |
| 11 | #include "InputCommon/ControllerEmu/Control/Control.h" |
| 12 | #include "VideoCommon/OnScreenDisplay.h" |
| 13 | |
| 14 | namespace ControllerEmu |
| 15 | { |
| 16 | ModifySettingsButton::ModifySettingsButton(const std::string& button_name) : Buttons(button_name) |
| 17 | { |
| 18 | } |
| 19 | |
| 20 | void ModifySettingsButton::AddInput(std::string button_name, bool toggle) |
| 21 | { |
| 22 | ControlGroup::AddInput(Translatability::Translate, std::move(button_name)); |
| 23 | m_threshold_exceeded.emplace_back(false); |
| 24 | m_associated_settings.emplace_back(false); |
| 25 | m_associated_settings_toggle.emplace_back(toggle); |
| 26 | } |
| 27 | |
| 28 | void ModifySettingsButton::UpdateState() |
| 29 | { |
| 30 | for (size_t i = 0; i < controls.size(); ++i) |
| 31 | { |
| 32 | const bool state = controls[i]->GetState<bool>(); |
| 33 | |
| 34 | if (!m_associated_settings_toggle[i]) |
| 35 | { |
| 36 | // not toggled |
| 37 | m_associated_settings[i] = state; |
| 38 | } |
| 39 | else |
| 40 | { |
| 41 | // toggle (loading savestates does not en-/disable toggle) |
| 42 | // after we passed the threshold, we en-/disable. but after that, we don't change it |
| 43 | // anymore |
| 44 | if (!m_threshold_exceeded[i] && state) |
| 45 | { |
| 46 | m_associated_settings[i] = !m_associated_settings[i]; |
| 47 | |
| 48 | if (m_associated_settings[i]) |
| 49 | OSD::AddMessage(controls[i]->ui_name + ": on"); |
| 50 | else |
| 51 | OSD::AddMessage(controls[i]->ui_name + ": off"); |
| 52 | |
| 53 | m_threshold_exceeded[i] = true; |
| 54 | } |
| 55 | |
| 56 | if (!state) |
| 57 | m_threshold_exceeded[i] = false; |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | const std::vector<bool>& ModifySettingsButton::IsSettingToggled() const |
| 63 | { |
| 64 | return m_associated_settings_toggle; |
| 65 | } |
| 66 | |
| 67 | const std::vector<bool>& ModifySettingsButton::GetSettingsModifier() const |
| 68 | { |
| 69 | return m_associated_settings; |
| 70 | } |
| 71 | } // namespace ControllerEmu |