2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2010 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 03:09:55 +00:00
|
|
|
// Refer to the license.txt file included.
|
2010-06-03 18:05:08 +00:00
|
|
|
|
2015-10-26 02:28:15 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2021-02-27 22:41:50 +00:00
|
|
|
#include "Common/Config/Config.h"
|
2015-10-26 02:28:15 +00:00
|
|
|
#include "Common/FileUtil.h"
|
|
|
|
#include "Common/IniFile.h"
|
2016-10-07 20:55:13 +00:00
|
|
|
#include "Common/MsgHandler.h"
|
2018-04-22 21:27:10 +00:00
|
|
|
#include "Common/StringUtil.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Core/ConfigManager.h"
|
2018-04-28 18:07:26 +00:00
|
|
|
#include "Core/Core.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Core/HW/Wiimote.h"
|
2017-02-09 03:15:43 +00:00
|
|
|
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
|
2017-01-30 03:32:04 +00:00
|
|
|
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
2019-03-27 00:31:03 +00:00
|
|
|
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
|
2015-10-26 02:28:15 +00:00
|
|
|
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "InputCommon/InputConfig.h"
|
2018-05-26 22:19:13 +00:00
|
|
|
#include "InputCommon/InputProfile.h"
|
2010-06-04 20:03:03 +00:00
|
|
|
|
2017-02-09 03:15:43 +00:00
|
|
|
InputConfig::InputConfig(const std::string& ini_name, const std::string& gui_name,
|
|
|
|
const std::string& profile_name)
|
|
|
|
: m_ini_name(ini_name), m_gui_name(gui_name), m_profile_name(profile_name)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
InputConfig::~InputConfig() = default;
|
|
|
|
|
2014-08-31 04:04:15 +00:00
|
|
|
bool InputConfig::LoadConfig(bool isGC)
|
2010-06-03 18:05:08 +00:00
|
|
|
{
|
|
|
|
IniFile inifile;
|
2013-05-18 12:30:20 +00:00
|
|
|
bool useProfile[MAX_BBMOTES] = {false, false, false, false, false};
|
2019-09-24 04:32:43 +00:00
|
|
|
static constexpr std::array<std::string_view, MAX_BBMOTES> num = {"1", "2", "3", "4", "BB"};
|
2013-05-18 12:30:20 +00:00
|
|
|
std::string profile[MAX_BBMOTES];
|
2013-01-10 01:41:14 +00:00
|
|
|
std::string path;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2018-10-25 01:29:48 +00:00
|
|
|
#if defined(ANDROID)
|
|
|
|
bool use_ir_config = false;
|
|
|
|
std::string ir_values[3];
|
|
|
|
#endif
|
|
|
|
|
2019-08-17 19:40:58 +00:00
|
|
|
m_dynamic_input_tex_config_manager.Load();
|
|
|
|
|
2016-10-29 12:42:43 +00:00
|
|
|
if (SConfig::GetInstance().GetGameID() != "00000000")
|
2013-01-09 20:03:43 +00:00
|
|
|
{
|
|
|
|
std::string type;
|
|
|
|
if (isGC)
|
2013-01-10 01:41:14 +00:00
|
|
|
{
|
2013-01-10 02:56:17 +00:00
|
|
|
type = "Pad";
|
2013-01-10 01:41:14 +00:00
|
|
|
path = "Profiles/GCPad/";
|
|
|
|
}
|
2013-01-09 20:03:43 +00:00
|
|
|
else
|
2013-01-10 01:41:14 +00:00
|
|
|
{
|
2013-01-10 02:56:17 +00:00
|
|
|
type = "Wiimote";
|
2013-01-10 01:41:14 +00:00
|
|
|
path = "Profiles/Wiimote/";
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-06-12 11:56:53 +00:00
|
|
|
IniFile game_ini = SConfig::GetInstance().LoadGameIni();
|
2014-06-16 05:12:43 +00:00
|
|
|
IniFile::Section* control_section = game_ini.GetOrCreateSection("Controls");
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2013-01-09 20:03:43 +00:00
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
2020-11-12 07:29:21 +00:00
|
|
|
const auto profile_name = fmt::format("{}Profile{}", type, num[i]);
|
|
|
|
|
|
|
|
if (control_section->Exists(profile_name))
|
2013-01-09 20:03:43 +00:00
|
|
|
{
|
2018-04-22 21:27:10 +00:00
|
|
|
std::string profile_setting;
|
2020-11-12 07:29:21 +00:00
|
|
|
if (control_section->Get(profile_name, &profile_setting))
|
2013-09-07 21:02:49 +00:00
|
|
|
{
|
2018-05-26 22:19:13 +00:00
|
|
|
auto profiles = InputProfile::GetProfilesFromSetting(
|
|
|
|
profile_setting, File::GetUserPath(D_CONFIG_IDX) + path);
|
2018-04-22 21:27:10 +00:00
|
|
|
|
2018-05-26 22:19:13 +00:00
|
|
|
if (profiles.empty())
|
2014-02-08 05:50:37 +00:00
|
|
|
{
|
2015-02-07 20:27:26 +00:00
|
|
|
// TODO: PanicAlert shouldn't be used for this.
|
2020-11-16 12:28:11 +00:00
|
|
|
PanicAlertFmtT("No profiles found for game setting '{0}'", profile_setting);
|
2018-05-26 22:19:13 +00:00
|
|
|
continue;
|
2014-02-08 05:50:37 +00:00
|
|
|
}
|
2018-05-26 22:19:13 +00:00
|
|
|
|
|
|
|
// Use the first profile by default
|
|
|
|
profile[i] = profiles[0];
|
|
|
|
useProfile[i] = true;
|
2013-09-07 21:02:49 +00:00
|
|
|
}
|
2013-01-09 20:03:43 +00:00
|
|
|
}
|
|
|
|
}
|
2018-10-25 01:29:48 +00:00
|
|
|
#if defined(ANDROID)
|
|
|
|
// For use on android touchscreen IR pointer
|
|
|
|
// Check for IR values
|
2019-03-27 00:31:03 +00:00
|
|
|
if (control_section->Exists("IRTotalYaw") && control_section->Exists("IRTotalPitch") &&
|
|
|
|
control_section->Exists("IRVerticalOffset"))
|
2018-10-25 01:29:48 +00:00
|
|
|
{
|
|
|
|
use_ir_config = true;
|
2019-03-27 00:31:03 +00:00
|
|
|
control_section->Get("IRTotalYaw", &ir_values[0]);
|
|
|
|
control_section->Get("IRTotalPitch", &ir_values[1]);
|
|
|
|
control_section->Get("IRVerticalOffset", &ir_values[2]);
|
2018-10-25 01:29:48 +00:00
|
|
|
}
|
|
|
|
#endif
|
2013-01-09 20:03:43 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2020-09-29 19:49:22 +00:00
|
|
|
if (inifile.Load(File::GetUserPath(D_CONFIG_IDX) + m_ini_name + ".ini") &&
|
|
|
|
!inifile.GetSections().empty())
|
2010-07-10 06:48:24 +00:00
|
|
|
{
|
2014-01-31 00:51:21 +00:00
|
|
|
int n = 0;
|
2021-02-27 22:41:50 +00:00
|
|
|
|
|
|
|
std::vector<std::string> controller_names;
|
2015-10-26 02:28:15 +00:00
|
|
|
for (auto& controller : m_controllers)
|
2010-10-03 04:29:34 +00:00
|
|
|
{
|
2018-10-25 01:29:48 +00:00
|
|
|
IniFile::Section config;
|
2014-01-31 00:51:21 +00:00
|
|
|
// Load settings from ini
|
2013-01-09 20:03:43 +00:00
|
|
|
if (useProfile[n])
|
|
|
|
{
|
2018-04-28 18:07:26 +00:00
|
|
|
std::string base;
|
|
|
|
SplitPath(profile[n], nullptr, &base, nullptr);
|
2018-05-24 03:20:58 +00:00
|
|
|
Core::DisplayMessage("Loading game specific input profile '" + base + "' for device '" +
|
|
|
|
controller->GetName() + "'",
|
2018-04-28 18:07:26 +00:00
|
|
|
6000);
|
|
|
|
|
2021-02-27 22:41:50 +00:00
|
|
|
inifile.Load(profile[n]);
|
|
|
|
config = *inifile.GetOrCreateSection("Profile");
|
2013-01-09 20:03:43 +00:00
|
|
|
}
|
|
|
|
else
|
2013-04-15 02:53:10 +00:00
|
|
|
{
|
2018-10-25 01:29:48 +00:00
|
|
|
config = *inifile.GetOrCreateSection(controller->GetName());
|
2013-04-15 02:53:10 +00:00
|
|
|
}
|
2018-10-25 01:29:48 +00:00
|
|
|
#if defined(ANDROID)
|
|
|
|
// Only set for wii pads
|
|
|
|
if (!isGC && use_ir_config)
|
|
|
|
{
|
2019-03-27 00:31:03 +00:00
|
|
|
config.Set("IR/Total Yaw", ir_values[0]);
|
|
|
|
config.Set("IR/Total Pitch", ir_values[1]);
|
|
|
|
config.Set("IR/Vertical Offset", ir_values[2]);
|
2018-10-25 01:29:48 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
controller->LoadConfig(&config);
|
2015-10-26 02:28:15 +00:00
|
|
|
controller->UpdateReferences(g_controller_interface);
|
2021-02-27 22:41:50 +00:00
|
|
|
controller_names.push_back(controller->GetName());
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-01-31 00:51:21 +00:00
|
|
|
// Next profile
|
|
|
|
n++;
|
2010-10-03 04:29:34 +00:00
|
|
|
}
|
2021-02-27 22:41:50 +00:00
|
|
|
|
|
|
|
m_dynamic_input_tex_config_manager.GenerateTextures(inifile, controller_names);
|
2010-10-03 04:29:34 +00:00
|
|
|
return true;
|
2010-07-10 06:48:24 +00:00
|
|
|
}
|
2010-10-03 04:29:34 +00:00
|
|
|
else
|
2010-07-10 06:48:24 +00:00
|
|
|
{
|
2015-10-26 02:28:15 +00:00
|
|
|
m_controllers[0]->LoadDefaults(g_controller_interface);
|
|
|
|
m_controllers[0]->UpdateReferences(g_controller_interface);
|
2010-10-03 04:29:34 +00:00
|
|
|
return false;
|
2010-06-04 20:03:03 +00:00
|
|
|
}
|
2010-06-03 18:05:08 +00:00
|
|
|
}
|
|
|
|
|
2014-08-31 04:04:15 +00:00
|
|
|
void InputConfig::SaveConfig()
|
2010-06-03 18:05:08 +00:00
|
|
|
{
|
2015-10-26 02:28:15 +00:00
|
|
|
std::string ini_filename = File::GetUserPath(D_CONFIG_IDX) + m_ini_name + ".ini";
|
2010-06-04 20:03:03 +00:00
|
|
|
|
2010-06-03 18:05:08 +00:00
|
|
|
IniFile inifile;
|
2010-07-03 08:04:10 +00:00
|
|
|
inifile.Load(ini_filename);
|
2010-06-03 18:05:08 +00:00
|
|
|
|
2021-02-27 22:41:50 +00:00
|
|
|
std::vector<std::string> controller_names;
|
2015-10-26 02:28:15 +00:00
|
|
|
for (auto& controller : m_controllers)
|
2021-02-27 22:41:50 +00:00
|
|
|
{
|
2015-10-26 02:28:15 +00:00
|
|
|
controller->SaveConfig(inifile.GetOrCreateSection(controller->GetName()));
|
2021-02-27 22:41:50 +00:00
|
|
|
controller_names.push_back(controller->GetName());
|
|
|
|
}
|
|
|
|
|
|
|
|
m_dynamic_input_tex_config_manager.GenerateTextures(inifile, controller_names);
|
2013-09-07 21:02:49 +00:00
|
|
|
|
2010-06-04 20:03:03 +00:00
|
|
|
inifile.Save(ini_filename);
|
2010-06-03 18:05:08 +00:00
|
|
|
}
|
2015-10-26 02:28:15 +00:00
|
|
|
|
2021-05-04 20:47:55 +00:00
|
|
|
ControllerEmu::EmulatedController* InputConfig::GetController(int index) const
|
2015-10-26 02:28:15 +00:00
|
|
|
{
|
|
|
|
return m_controllers.at(index).get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputConfig::ClearControllers()
|
|
|
|
{
|
|
|
|
m_controllers.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputConfig::ControllersNeedToBeCreated() const
|
|
|
|
{
|
|
|
|
return m_controllers.empty();
|
|
|
|
}
|
2016-06-21 13:33:53 +00:00
|
|
|
|
2021-02-13 01:21:48 +00:00
|
|
|
int InputConfig::GetControllerCount() const
|
2018-04-14 04:51:32 +00:00
|
|
|
{
|
2021-02-13 01:21:48 +00:00
|
|
|
return static_cast<int>(m_controllers.size());
|
2018-04-14 04:51:32 +00:00
|
|
|
}
|
|
|
|
|
2019-01-10 15:02:38 +00:00
|
|
|
void InputConfig::RegisterHotplugCallback()
|
|
|
|
{
|
|
|
|
// Update control references on all controllers
|
|
|
|
// as configured devices may have been added or removed.
|
|
|
|
m_hotplug_callback_handle = g_controller_interface.RegisterDevicesChangedCallback([this] {
|
|
|
|
for (auto& controller : m_controllers)
|
|
|
|
controller->UpdateReferences(g_controller_interface);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputConfig::UnregisterHotplugCallback()
|
|
|
|
{
|
|
|
|
g_controller_interface.UnregisterDevicesChangedCallback(m_hotplug_callback_handle);
|
|
|
|
}
|
|
|
|
|
2016-06-21 13:33:53 +00:00
|
|
|
bool InputConfig::IsControllerControlledByGamepadDevice(int index) const
|
|
|
|
{
|
|
|
|
if (static_cast<size_t>(index) >= m_controllers.size())
|
|
|
|
return false;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-11-04 21:08:26 +00:00
|
|
|
const auto& controller = m_controllers.at(index).get()->GetDefaultDevice();
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-06-21 13:33:53 +00:00
|
|
|
// Filter out anything which obviously not a gamepad
|
2017-08-22 16:26:44 +00:00
|
|
|
return !((controller.source == "Quartz") // OSX Quartz Keyboard/Mouse
|
2016-06-21 13:33:53 +00:00
|
|
|
|| (controller.source == "XInput2") // Linux and BSD Keyboard/Mouse
|
|
|
|
|| (controller.source == "Android" &&
|
|
|
|
controller.name == "Touchscreen") // Android Touchscreen
|
|
|
|
|| (controller.source == "DInput" &&
|
|
|
|
controller.name == "Keyboard Mouse")); // Windows Keyboard/Mouse
|
|
|
|
}
|
2021-02-27 22:41:50 +00:00
|
|
|
|
|
|
|
void InputConfig::GenerateControllerTextures(const IniFile& file)
|
|
|
|
{
|
|
|
|
std::vector<std::string> controller_names;
|
|
|
|
for (auto& controller : m_controllers)
|
|
|
|
{
|
|
|
|
controller_names.push_back(controller->GetName());
|
|
|
|
}
|
|
|
|
|
|
|
|
m_dynamic_input_tex_config_manager.GenerateTextures(file, controller_names);
|
|
|
|
}
|