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"
|
|
|
|
#include "InputCommon/ControllerEmu/ControlGroup/Extension.h"
|
|
|
|
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
2017-02-26 20:00:24 +00:00
|
|
|
#include "InputCommon/ControllerEmu/Setting/BooleanSetting.h"
|
|
|
|
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
|
2017-02-09 03:15:43 +00:00
|
|
|
|
|
|
|
namespace ControllerEmu
|
|
|
|
{
|
2017-02-25 05:35:02 +00:00
|
|
|
ControlGroup::ControlGroup(const std::string& name_, const GroupType type_)
|
2017-02-09 03:15:43 +00:00
|
|
|
: name(name_), ui_name(name_), type(type_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-02-25 05:35:02 +00:00
|
|
|
ControlGroup::ControlGroup(const std::string& name_, const std::string& ui_name_,
|
|
|
|
const GroupType type_)
|
2017-02-09 03:15:43 +00:00
|
|
|
: name(name_), ui_name(ui_name_), type(type_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ControlGroup::~ControlGroup() = default;
|
|
|
|
|
|
|
|
void ControlGroup::LoadConfig(IniFile::Section* sec, const std::string& defdev,
|
|
|
|
const std::string& base)
|
|
|
|
{
|
|
|
|
std::string group(base + name + "/");
|
|
|
|
|
|
|
|
// settings
|
|
|
|
for (auto& s : numeric_settings)
|
|
|
|
{
|
|
|
|
if (s->m_type == SettingType::VIRTUAL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sec->Get(group + s->m_name, &s->m_value, s->m_default_value * 100);
|
|
|
|
s->m_value /= 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& s : boolean_settings)
|
|
|
|
{
|
|
|
|
if (s->m_type == SettingType::VIRTUAL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sec->Get(group + s->m_name, &s->m_value, s->m_default_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2017-02-25 05:35:02 +00:00
|
|
|
if (type == GroupType::Extension)
|
2017-02-09 03:15:43 +00:00
|
|
|
{
|
|
|
|
Extension* const ext = (Extension*)this;
|
|
|
|
|
|
|
|
ext->switch_extension = 0;
|
|
|
|
u32 n = 0;
|
|
|
|
std::string extname;
|
|
|
|
sec->Get(base + name, &extname, "");
|
|
|
|
|
|
|
|
for (auto& ai : ext->attachments)
|
|
|
|
{
|
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)
|
|
|
|
ext->switch_extension = n;
|
|
|
|
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControlGroup::SaveConfig(IniFile::Section* sec, const std::string& defdev,
|
|
|
|
const std::string& base)
|
|
|
|
{
|
|
|
|
std::string group(base + name + "/");
|
|
|
|
|
|
|
|
for (auto& s : numeric_settings)
|
|
|
|
{
|
|
|
|
if (s->m_type == SettingType::VIRTUAL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sec->Set(group + s->m_name, s->m_value * 100.0, s->m_default_value * 100.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& s : boolean_settings)
|
|
|
|
{
|
|
|
|
if (s->m_type == SettingType::VIRTUAL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sec->Set(group + s->m_name, s->m_value, s->m_default_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2017-02-25 05:35:02 +00:00
|
|
|
if (type == GroupType::Extension)
|
2017-02-09 03:15:43 +00:00
|
|
|
{
|
|
|
|
Extension* const ext = (Extension*)this;
|
|
|
|
sec->Set(base + name, ext->attachments[ext->switch_extension]->GetName(), "None");
|
|
|
|
|
|
|
|
for (auto& ai : ext->attachments)
|
|
|
|
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
|