2017-02-09 03:15:43 +00:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#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)
|
|
|
|
{
|
2018-04-10 15:22:30 +00:00
|
|
|
controls.emplace_back(std::make_unique<Input>(Translate, std::move(button_name)));
|
2017-02-09 03:15:43 +00:00
|
|
|
threshold_exceeded.emplace_back(false);
|
|
|
|
associated_settings.emplace_back(false);
|
|
|
|
associated_settings_toggle.emplace_back(toggle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModifySettingsButton::GetState()
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < controls.size(); ++i)
|
|
|
|
{
|
|
|
|
ControlState state = controls[i]->control_ref->State();
|
|
|
|
|
|
|
|
if (!associated_settings_toggle[i])
|
|
|
|
{
|
|
|
|
// not toggled
|
2018-12-31 13:31:11 +00:00
|
|
|
associated_settings[i] = state > ACTIVATION_THRESHOLD;
|
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
|
2018-12-31 13:31:11 +00:00
|
|
|
if (!threshold_exceeded[i] && state > ACTIVATION_THRESHOLD)
|
2017-02-09 03:15:43 +00:00
|
|
|
{
|
|
|
|
associated_settings[i] = !associated_settings[i];
|
|
|
|
|
|
|
|
if (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
|
|
|
|
|
|
|
threshold_exceeded[i] = true;
|
|
|
|
}
|
|
|
|
|
2018-12-31 13:31:11 +00:00
|
|
|
if (state < ACTIVATION_THRESHOLD)
|
2017-02-09 03:15:43 +00:00
|
|
|
threshold_exceeded[i] = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<bool>& ModifySettingsButton::isSettingToggled() const
|
|
|
|
{
|
|
|
|
return associated_settings_toggle;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<bool>& ModifySettingsButton::getSettingsModifier() const
|
|
|
|
{
|
|
|
|
return associated_settings;
|
|
|
|
}
|
|
|
|
} // namespace ControllerEmu
|