mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
NumericSetting: Stop values from binding to numbered input names.
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
|
||||
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <fmt/format.h>
|
||||
|
||||
namespace ControllerEmu
|
||||
{
|
||||
@ -11,6 +11,11 @@ NumericSettingBase::NumericSettingBase(const NumericSettingDetails& details) : m
|
||||
{
|
||||
}
|
||||
|
||||
// Explicit instantiations so generic definitions can exist outside of the header.
|
||||
template class NumericSetting<int>;
|
||||
template class NumericSetting<double>;
|
||||
template class NumericSetting<bool>;
|
||||
|
||||
const char* NumericSettingBase::GetININame() const
|
||||
{
|
||||
return m_details.ini_name;
|
||||
@ -36,28 +41,20 @@ SettingVisibility NumericSettingBase::GetVisibility() const
|
||||
return m_details.visibility;
|
||||
}
|
||||
|
||||
template <>
|
||||
void NumericSetting<int>::SetExpressionFromValue()
|
||||
template <typename T>
|
||||
void NumericSetting<T>::SetExpressionFromValue()
|
||||
{
|
||||
m_value.m_input.SetExpression(ValueToString(GetValue()));
|
||||
// Always include -/+ sign to prevent CoalesceExpression binding.
|
||||
// e.g. 1 is a valid input name for keyboard devices, +1 is not.
|
||||
m_value.m_input.SetExpression(fmt::format("{:+g}", ControlState(GetValue())));
|
||||
}
|
||||
|
||||
template <>
|
||||
void NumericSetting<double>::SetExpressionFromValue()
|
||||
template <typename T>
|
||||
void NumericSetting<T>::SimplifyIfPossible()
|
||||
{
|
||||
// We must use a dot decimal separator for expression parser.
|
||||
std::ostringstream ss;
|
||||
ss.imbue(std::locale::classic());
|
||||
ss << GetValue();
|
||||
|
||||
m_value.m_input.SetExpression(ss.str());
|
||||
}
|
||||
|
||||
template <>
|
||||
void NumericSetting<bool>::SetExpressionFromValue()
|
||||
{
|
||||
// Cast bool to prevent "true"/"false" strings.
|
||||
m_value.m_input.SetExpression(ValueToString(int(GetValue())));
|
||||
ValueType value;
|
||||
if (TryParse(std::string(StripWhitespace(m_value.m_input.GetExpression())), &value))
|
||||
m_value.SetValue(value);
|
||||
}
|
||||
|
||||
template <>
|
||||
|
Reference in New Issue
Block a user