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/ControlGroup.h"
|
|
|
|
|
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
#include "Common/IniFile.h"
|
|
|
|
|
|
|
|
#include "InputCommon/ControlReference/ControlReference.h"
|
|
|
|
#include "InputCommon/ControllerEmu/Control/Control.h"
|
2019-01-01 14:32:39 +00:00
|
|
|
#include "InputCommon/ControllerEmu/ControlGroup/Attachments.h"
|
2017-02-09 03:15:43 +00:00
|
|
|
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
2017-02-26 20:00:24 +00:00
|
|
|
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
|
2017-02-09 03:15:43 +00:00
|
|
|
|
|
|
|
namespace ControllerEmu
|
|
|
|
{
|
2019-04-20 17:53:13 +00:00
|
|
|
ControlGroup::ControlGroup(std::string name_, const GroupType type_)
|
|
|
|
: name(name_), ui_name(std::move(name_)), type(type_)
|
2017-02-09 03:15:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-04-20 17:53:13 +00:00
|
|
|
ControlGroup::ControlGroup(std::string name_, std::string ui_name_, const GroupType type_)
|
|
|
|
: name(std::move(name_)), ui_name(std::move(ui_name_)), type(type_)
|
2017-02-09 03:15:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-03-27 00:31:03 +00:00
|
|
|
void ControlGroup::AddDeadzoneSetting(SettingValue<double>* value, double maximum_deadzone)
|
|
|
|
{
|
|
|
|
AddSetting(value,
|
|
|
|
{_trans("Dead Zone"),
|
|
|
|
// i18n: The percent symbol.
|
|
|
|
_trans("%"),
|
|
|
|
// i18n: Refers to the dead-zone setting of gamepad inputs.
|
|
|
|
_trans("Input strength to ignore.")},
|
|
|
|
0, 0, maximum_deadzone);
|
|
|
|
}
|
|
|
|
|
2017-02-09 03:15:43 +00:00
|
|
|
ControlGroup::~ControlGroup() = default;
|
|
|
|
|
|
|
|
void ControlGroup::LoadConfig(IniFile::Section* sec, const std::string& defdev,
|
|
|
|
const std::string& base)
|
|
|
|
{
|
2019-03-27 00:31:03 +00:00
|
|
|
const std::string group(base + name + "/");
|
2017-02-09 03:15:43 +00:00
|
|
|
|
2019-03-27 00:31:03 +00:00
|
|
|
for (auto& setting : numeric_settings)
|
|
|
|
setting->LoadFromIni(*sec, group);
|
2017-02-09 03:15:43 +00:00
|
|
|
|
|
|
|
for (auto& c : controls)
|
|
|
|
{
|
2017-06-08 02:02:16 +00:00
|
|
|
{
|
|
|
|
// control expression
|
|
|
|
std::string expression;
|
|
|
|
sec->Get(group + c->name, &expression, "");
|
|
|
|
c->control_ref->SetExpression(std::move(expression));
|
|
|
|
}
|
2017-02-09 03:15:43 +00:00
|
|
|
|
|
|
|
// range
|
|
|
|
sec->Get(group + c->name + "/Range", &c->control_ref->range, 100.0);
|
|
|
|
c->control_ref->range /= 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
// extensions
|
2019-01-01 14:32:39 +00:00
|
|
|
if (type == GroupType::Attachments)
|
2017-02-09 03:15:43 +00:00
|
|
|
{
|
2019-01-01 14:32:39 +00:00
|
|
|
auto* const ext = static_cast<Attachments*>(this);
|
2017-02-09 03:15:43 +00:00
|
|
|
|
2019-01-01 14:32:39 +00:00
|
|
|
ext->SetSelectedAttachment(0);
|
2017-02-09 03:15:43 +00:00
|
|
|
u32 n = 0;
|
|
|
|
std::string extname;
|
|
|
|
sec->Get(base + name, &extname, "");
|
|
|
|
|
2019-01-01 14:32:39 +00:00
|
|
|
for (auto& ai : ext->GetAttachmentList())
|
2017-02-09 03:15:43 +00:00
|
|
|
{
|
2017-11-04 21:08:26 +00:00
|
|
|
ai->SetDefaultDevice(defdev);
|
2017-02-09 03:15:43 +00:00
|
|
|
ai->LoadConfig(sec, base + ai->GetName() + "/");
|
|
|
|
|
|
|
|
if (ai->GetName() == extname)
|
2019-01-01 14:32:39 +00:00
|
|
|
ext->SetSelectedAttachment(n);
|
2017-02-09 03:15:43 +00:00
|
|
|
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControlGroup::SaveConfig(IniFile::Section* sec, const std::string& defdev,
|
|
|
|
const std::string& base)
|
|
|
|
{
|
2019-03-27 00:31:03 +00:00
|
|
|
const std::string group(base + name + "/");
|
2017-02-09 03:15:43 +00:00
|
|
|
|
2019-03-27 00:31:03 +00:00
|
|
|
for (auto& setting : numeric_settings)
|
|
|
|
setting->SaveToIni(*sec, group);
|
2017-02-09 03:15:43 +00:00
|
|
|
|
|
|
|
for (auto& c : controls)
|
|
|
|
{
|
|
|
|
// control expression
|
2017-06-08 02:02:16 +00:00
|
|
|
sec->Set(group + c->name, c->control_ref->GetExpression(), "");
|
2017-02-09 03:15:43 +00:00
|
|
|
|
|
|
|
// range
|
|
|
|
sec->Set(group + c->name + "/Range", c->control_ref->range * 100.0, 100.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// extensions
|
2019-01-01 14:32:39 +00:00
|
|
|
if (type == GroupType::Attachments)
|
2017-02-09 03:15:43 +00:00
|
|
|
{
|
2019-01-01 14:32:39 +00:00
|
|
|
auto* const ext = static_cast<Attachments*>(this);
|
|
|
|
sec->Set(base + name, ext->GetAttachmentList()[ext->GetSelectedAttachment()]->GetName(),
|
|
|
|
"None");
|
2017-02-09 03:15:43 +00:00
|
|
|
|
2019-01-01 14:32:39 +00:00
|
|
|
for (auto& ai : ext->GetAttachmentList())
|
2017-02-09 03:15:43 +00:00
|
|
|
ai->SaveConfig(sec, base + ai->GetName() + "/");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControlGroup::SetControlExpression(int index, const std::string& expression)
|
|
|
|
{
|
2017-06-08 02:02:16 +00:00
|
|
|
controls.at(index)->control_ref->SetExpression(expression);
|
2017-02-09 03:15:43 +00:00
|
|
|
}
|
|
|
|
} // namespace ControllerEmu
|