mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
InputConfig: Clean up controller management
This commit is contained in:
@ -2,10 +2,15 @@
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "Common/CommonPaths.h"
|
||||
#include <vector>
|
||||
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/IniFile.h"
|
||||
#include "Core/ConfigManager.h"
|
||||
#include "Core/HW/Wiimote.h"
|
||||
#include "InputCommon/ControllerEmu.h"
|
||||
#include "InputCommon/InputConfig.h"
|
||||
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
||||
|
||||
bool InputConfig::LoadConfig(bool isGC)
|
||||
{
|
||||
@ -52,25 +57,25 @@ bool InputConfig::LoadConfig(bool isGC)
|
||||
}
|
||||
}
|
||||
|
||||
if (inifile.Load(File::GetUserPath(D_CONFIG_IDX) + ini_name + ".ini"))
|
||||
if (inifile.Load(File::GetUserPath(D_CONFIG_IDX) + m_ini_name + ".ini"))
|
||||
{
|
||||
int n = 0;
|
||||
for (ControllerEmu* pad : controllers)
|
||||
for (auto& controller : m_controllers)
|
||||
{
|
||||
// Load settings from ini
|
||||
if (useProfile[n])
|
||||
{
|
||||
IniFile profile_ini;
|
||||
profile_ini.Load(File::GetUserPath(D_CONFIG_IDX) + path + profile[n] + ".ini");
|
||||
pad->LoadConfig(profile_ini.GetOrCreateSection("Profile"));
|
||||
controller->LoadConfig(profile_ini.GetOrCreateSection("Profile"));
|
||||
}
|
||||
else
|
||||
{
|
||||
pad->LoadConfig(inifile.GetOrCreateSection(pad->GetName()));
|
||||
controller->LoadConfig(inifile.GetOrCreateSection(controller->GetName()));
|
||||
}
|
||||
|
||||
// Update refs
|
||||
pad->UpdateReferences(g_controller_interface);
|
||||
controller->UpdateReferences(g_controller_interface);
|
||||
|
||||
// Next profile
|
||||
n++;
|
||||
@ -79,21 +84,36 @@ bool InputConfig::LoadConfig(bool isGC)
|
||||
}
|
||||
else
|
||||
{
|
||||
controllers[0]->LoadDefaults(g_controller_interface);
|
||||
controllers[0]->UpdateReferences(g_controller_interface);
|
||||
m_controllers[0]->LoadDefaults(g_controller_interface);
|
||||
m_controllers[0]->UpdateReferences(g_controller_interface);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void InputConfig::SaveConfig()
|
||||
{
|
||||
std::string ini_filename = File::GetUserPath(D_CONFIG_IDX) + ini_name + ".ini";
|
||||
std::string ini_filename = File::GetUserPath(D_CONFIG_IDX) + m_ini_name + ".ini";
|
||||
|
||||
IniFile inifile;
|
||||
inifile.Load(ini_filename);
|
||||
|
||||
for (ControllerEmu* pad : controllers)
|
||||
pad->SaveConfig(inifile.GetOrCreateSection(pad->GetName()));
|
||||
for (auto& controller : m_controllers)
|
||||
controller->SaveConfig(inifile.GetOrCreateSection(controller->GetName()));
|
||||
|
||||
inifile.Save(ini_filename);
|
||||
}
|
||||
|
||||
ControllerEmu* InputConfig::GetController(int index)
|
||||
{
|
||||
return m_controllers.at(index).get();
|
||||
}
|
||||
|
||||
void InputConfig::ClearControllers()
|
||||
{
|
||||
m_controllers.clear();
|
||||
}
|
||||
|
||||
bool InputConfig::ControllersNeedToBeCreated() const
|
||||
{
|
||||
return m_controllers.empty();
|
||||
}
|
||||
|
@ -4,29 +4,40 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/IniFile.h"
|
||||
#include "Common/Thread.h"
|
||||
|
||||
#include "InputCommon/ControllerEmu.h"
|
||||
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
||||
class ControllerEmu;
|
||||
|
||||
class InputConfig
|
||||
{
|
||||
public:
|
||||
InputConfig(const char* const _ini_name, const char* const _gui_name,
|
||||
const char* const _profile_name)
|
||||
: ini_name(_ini_name), gui_name(_gui_name), profile_name(_profile_name) {}
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
bool LoadConfig(bool isGC);
|
||||
void SaveConfig();
|
||||
|
||||
std::vector<ControllerEmu*> controllers;
|
||||
template <typename T, typename... Args>
|
||||
void CreateController(Args&&... args)
|
||||
{
|
||||
m_controllers.emplace_back(std::make_unique<T>(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
const char* const ini_name;
|
||||
const char* const gui_name;
|
||||
const char* const profile_name;
|
||||
ControllerEmu* GetController(int index);
|
||||
void ClearControllers();
|
||||
bool ControllersNeedToBeCreated() const;
|
||||
|
||||
std::string GetGUIName() const { return m_gui_name; }
|
||||
std::string GetProfileName() const { return m_profile_name; }
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<ControllerEmu>> m_controllers;
|
||||
const std::string m_ini_name;
|
||||
const std::string m_gui_name;
|
||||
const std::string m_profile_name;
|
||||
};
|
||||
|
Reference in New Issue
Block a user