2017-02-09 03:15:43 +00:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2017-02-09 03:15:43 +00:00
|
|
|
|
|
|
|
#include "InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.h"
|
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#include "Common/Common.h"
|
|
|
|
#include "InputCommon/ControlReference/ControlReference.h"
|
|
|
|
#include "InputCommon/ControllerEmu/Control/Control.h"
|
|
|
|
#include "InputCommon/ControllerEmu/Control/Input.h"
|
2017-02-26 20:00:24 +00:00
|
|
|
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
|
2017-02-09 03:15:43 +00:00
|
|
|
#include "VideoCommon/OnScreenDisplay.h"
|
|
|
|
|
|
|
|
namespace ControllerEmu
|
|
|
|
{
|
|
|
|
ModifySettingsButton::ModifySettingsButton(std::string button_name)
|
|
|
|
: Buttons(std::move(button_name))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModifySettingsButton::AddInput(std::string button_name, bool toggle)
|
|
|
|
{
|
2023-05-29 23:31:19 +00:00
|
|
|
ControlGroup::AddInput(Translatability::Translate, std::move(button_name));
|
2021-05-04 20:48:55 +00:00
|
|
|
m_threshold_exceeded.emplace_back(false);
|
|
|
|
m_associated_settings.emplace_back(false);
|
|
|
|
m_associated_settings_toggle.emplace_back(toggle);
|
2017-02-09 03:15:43 +00:00
|
|
|
}
|
|
|
|
|
2021-05-04 20:48:55 +00:00
|
|
|
void ModifySettingsButton::UpdateState()
|
2017-02-09 03:15:43 +00:00
|
|
|
{
|
|
|
|
for (size_t i = 0; i < controls.size(); ++i)
|
|
|
|
{
|
2020-02-09 02:36:26 +00:00
|
|
|
const bool state = controls[i]->GetState<bool>();
|
2017-02-09 03:15:43 +00:00
|
|
|
|
2021-05-04 20:48:55 +00:00
|
|
|
if (!m_associated_settings_toggle[i])
|
2017-02-09 03:15:43 +00:00
|
|
|
{
|
|
|
|
// not toggled
|
2021-05-04 20:48:55 +00:00
|
|
|
m_associated_settings[i] = state;
|
2017-02-09 03:15:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// toggle (loading savestates does not en-/disable toggle)
|
|
|
|
// after we passed the threshold, we en-/disable. but after that, we don't change it
|
|
|
|
// anymore
|
2021-05-04 20:48:55 +00:00
|
|
|
if (!m_threshold_exceeded[i] && state)
|
2017-02-09 03:15:43 +00:00
|
|
|
{
|
2021-05-04 20:48:55 +00:00
|
|
|
m_associated_settings[i] = !m_associated_settings[i];
|
2017-02-09 03:15:43 +00:00
|
|
|
|
2021-05-04 20:48:55 +00:00
|
|
|
if (m_associated_settings[i])
|
2017-04-30 12:53:33 +00:00
|
|
|
OSD::AddMessage(controls[i]->ui_name + ": on");
|
2017-02-09 03:15:43 +00:00
|
|
|
else
|
2017-04-30 12:53:33 +00:00
|
|
|
OSD::AddMessage(controls[i]->ui_name + ": off");
|
2017-02-09 03:15:43 +00:00
|
|
|
|
2021-05-04 20:48:55 +00:00
|
|
|
m_threshold_exceeded[i] = true;
|
2017-02-09 03:15:43 +00:00
|
|
|
}
|
|
|
|
|
2019-10-18 19:54:02 +00:00
|
|
|
if (!state)
|
2021-05-04 20:48:55 +00:00
|
|
|
m_threshold_exceeded[i] = false;
|
2017-02-09 03:15:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-04 20:48:55 +00:00
|
|
|
const std::vector<bool>& ModifySettingsButton::IsSettingToggled() const
|
2017-02-09 03:15:43 +00:00
|
|
|
{
|
2021-05-04 20:48:55 +00:00
|
|
|
return m_associated_settings_toggle;
|
2017-02-09 03:15:43 +00:00
|
|
|
}
|
|
|
|
|
2021-05-04 20:48:55 +00:00
|
|
|
const std::vector<bool>& ModifySettingsButton::GetSettingsModifier() const
|
2017-02-09 03:15:43 +00:00
|
|
|
{
|
2021-05-04 20:48:55 +00:00
|
|
|
return m_associated_settings;
|
2017-02-09 03:15:43 +00:00
|
|
|
}
|
|
|
|
} // namespace ControllerEmu
|