summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon
diff options
context:
space:
mode:
authoriwubcode <iwubcode@users.noreply.github.com>2018-04-13 23:51:32 -0500
committeriwubcode <iwubcode@users.noreply.github.com>2018-07-07 12:39:08 -0500
commit3969bf6d1c83acb7e3699bcd3c2715d5b85e2ea0 (patch)
treeec9481f55fbe76a24e0b993ecb68aa7daeeb03b5 /Source/Core/InputCommon
parent29b71fb9ce5d28e84a7aaabc1a3a65f2a551d42d (diff)
Input: Add hotkey to cycle the wiimote profile forward or backward
Co-authored-by: Barath Kannan <barathsotd@gmail.com>
Diffstat (limited to 'Source/Core/InputCommon')
-rw-r--r--Source/Core/InputCommon/CMakeLists.txt1
-rw-r--r--Source/Core/InputCommon/InputCommon.vcxproj2
-rw-r--r--Source/Core/InputCommon/InputCommon.vcxproj.filters2
-rw-r--r--Source/Core/InputCommon/InputConfig.cpp5
-rw-r--r--Source/Core/InputCommon/InputConfig.h1
-rw-r--r--Source/Core/InputCommon/InputProfile.cpp100
-rw-r--r--Source/Core/InputCommon/InputProfile.h39
7 files changed, 150 insertions, 0 deletions
diff --git a/Source/Core/InputCommon/CMakeLists.txt b/Source/Core/InputCommon/CMakeLists.txt
index 99cf2f9679..a3ef2722d8 100644
--- a/Source/Core/InputCommon/CMakeLists.txt
+++ b/Source/Core/InputCommon/CMakeLists.txt
@@ -1,5 +1,6 @@
add_library(inputcommon
InputConfig.cpp
+ InputProfile.cpp
ControllerEmu/ControllerEmu.cpp
ControllerEmu/Control/Control.cpp
ControllerEmu/Control/Input.cpp
diff --git a/Source/Core/InputCommon/InputCommon.vcxproj b/Source/Core/InputCommon/InputCommon.vcxproj
index 84ad406de1..6d0efb2c91 100644
--- a/Source/Core/InputCommon/InputCommon.vcxproj
+++ b/Source/Core/InputCommon/InputCommon.vcxproj
@@ -71,6 +71,7 @@
<DisableSpecificWarnings>4200;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
<ClCompile Include="InputConfig.cpp" />
+ <ClCompile Include="InputProfile.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="ControllerEmu\ControllerEmu.h" />
@@ -105,6 +106,7 @@
<ClInclude Include="GCAdapter.h" />
<ClInclude Include="GCPadStatus.h" />
<ClInclude Include="InputConfig.h" />
+ <ClInclude Include="InputProfile.h" />
</ItemGroup>
<ItemGroup>
<Text Include="CMakeLists.txt" />
diff --git a/Source/Core/InputCommon/InputCommon.vcxproj.filters b/Source/Core/InputCommon/InputCommon.vcxproj.filters
index 600a77727d..c67333497c 100644
--- a/Source/Core/InputCommon/InputCommon.vcxproj.filters
+++ b/Source/Core/InputCommon/InputCommon.vcxproj.filters
@@ -110,6 +110,7 @@
<ClCompile Include="ControlReference\ControlReference.cpp">
<Filter>ControllerInterface</Filter>
</ClCompile>
+ <ClCompile Include="InputProfile.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="GCAdapter.h" />
@@ -202,6 +203,7 @@
<ClInclude Include="ControlReference\ControlReference.h">
<Filter>ControllerInterface</Filter>
</ClInclude>
+ <ClInclude Include="InputProfile.h" />
</ItemGroup>
<ItemGroup>
<Text Include="CMakeLists.txt" />
diff --git a/Source/Core/InputCommon/InputConfig.cpp b/Source/Core/InputCommon/InputConfig.cpp
index 2a5766fbbe..989c1bdce9 100644
--- a/Source/Core/InputCommon/InputConfig.cpp
+++ b/Source/Core/InputCommon/InputConfig.cpp
@@ -128,6 +128,11 @@ bool InputConfig::ControllersNeedToBeCreated() const
return m_controllers.empty();
}
+std::size_t InputConfig::GetControllerCount() const
+{
+ return m_controllers.size();
+}
+
bool InputConfig::IsControllerControlledByGamepadDevice(int index) const
{
if (static_cast<size_t>(index) >= m_controllers.size())
diff --git a/Source/Core/InputCommon/InputConfig.h b/Source/Core/InputCommon/InputConfig.h
index a993a412b1..004e4be8bb 100644
--- a/Source/Core/InputCommon/InputConfig.h
+++ b/Source/Core/InputCommon/InputConfig.h
@@ -38,6 +38,7 @@ public:
std::string GetGUIName() const { return m_gui_name; }
std::string GetProfileName() const { return m_profile_name; }
+ std::size_t GetControllerCount() const;
private:
std::vector<std::unique_ptr<ControllerEmu::EmulatedController>> m_controllers;
diff --git a/Source/Core/InputCommon/InputProfile.cpp b/Source/Core/InputCommon/InputProfile.cpp
new file mode 100644
index 0000000000..87d8c5bcab
--- /dev/null
+++ b/Source/Core/InputCommon/InputProfile.cpp
@@ -0,0 +1,100 @@
+// Copyright 2018 Dolphin Emulator Project
+// Licensed under GPLv2+
+// Refer to the license.txt file included.
+
+#include "Common/FileSearch.h"
+#include "Common/FileUtil.h"
+
+#include "Core/Core.h"
+#include "Core/HW/Wiimote.h"
+#include "Core/HotkeyManager.h"
+
+#include "InputCommon/ControllerInterface/ControllerInterface.h"
+#include "InputCommon/InputConfig.h"
+#include "InputCommon/InputProfile.h"
+
+namespace InputProfile
+{
+
+ namespace
+ {
+ constexpr int display_message_ms = 3000;
+ }
+
+ std::vector<std::string> ProfileCycler::GetProfilesForDevice(InputConfig* device_configuration)
+ {
+ const std::string device_profile_root_location(File::GetUserPath(D_CONFIG_IDX) + "Profiles/" + device_configuration->GetProfileName());
+ return Common::DoFileSearch({ device_profile_root_location }, { ".ini" });
+ }
+
+ std::string ProfileCycler::GetProfile(CycleDirection cycle_direction, int& profile_index, const std::vector<std::string>& profiles)
+ {
+ // update the index and bind it to the number of available strings
+ auto positive_modulo = [](int& i, int n) {i = (i % n + n) % n;};
+ profile_index += static_cast<int>(cycle_direction);
+ positive_modulo(profile_index, static_cast<int>(profiles.size()));
+
+ return profiles[profile_index];
+ }
+
+ void ProfileCycler::UpdateToProfile(const std::string& profile_filename, const std::vector<ControllerEmu::EmulatedController*>& controllers)
+ {
+ std::string base;
+ SplitPath(profile_filename, nullptr, &base, nullptr);
+
+ IniFile ini_file;
+ if (ini_file.Load(profile_filename))
+ {
+ Core::DisplayMessage("Loading input profile: " + base, display_message_ms);
+
+ for (auto* controller : controllers)
+ {
+ controller->LoadConfig(ini_file.GetOrCreateSection("Profile"));
+ controller->UpdateReferences(g_controller_interface);
+ }
+ }
+ else
+ {
+ Core::DisplayMessage("Unable to load input profile: " + base, display_message_ms);
+ }
+ }
+
+ std::vector<ControllerEmu::EmulatedController*> ProfileCycler::GetControllersForDevice(InputConfig* device_configuration)
+ {
+ const std::size_t size = device_configuration->GetControllerCount();
+
+ std::vector<ControllerEmu::EmulatedController*> result(size);
+
+ for (int i = 0; i < static_cast<int>(size); i++)
+ {
+ result[i] = device_configuration->GetController(i);
+ }
+
+ return result;
+ }
+
+ void ProfileCycler::CycleProfile(CycleDirection cycle_direction,
+ InputConfig* device_configuration, int& profile_index)
+ {
+ const auto& profiles = GetProfilesForDevice(device_configuration);
+ if (profiles.empty())
+ {
+ Core::DisplayMessage("No input profiles found", display_message_ms);
+ return;
+ }
+ const std::string profile = GetProfile(cycle_direction, profile_index, profiles);
+
+ const auto& controllers = GetControllersForDevice(device_configuration);
+ UpdateToProfile(profile, controllers);
+ }
+
+ void ProfileCycler::NextWiimoteProfile()
+ {
+ CycleProfile(CycleDirection::Forward, Wiimote::GetConfig(), m_wiimote_profile_index);
+ }
+
+ void ProfileCycler::PreviousWiimoteProfile()
+ {
+ CycleProfile(CycleDirection::Backward, Wiimote::GetConfig(), m_wiimote_profile_index);
+ }
+}
diff --git a/Source/Core/InputCommon/InputProfile.h b/Source/Core/InputCommon/InputProfile.h
new file mode 100644
index 0000000000..09b617c398
--- /dev/null
+++ b/Source/Core/InputCommon/InputProfile.h
@@ -0,0 +1,39 @@
+// Copyright 2018 Dolphin Emulator Project
+// Licensed under GPLv2+
+// Refer to the license.txt file included.
+
+#pragma once
+
+class InputConfig;
+
+namespace ControllerEmu
+{
+ class EmulatedController;
+}
+
+#include <string>
+#include <vector>
+
+namespace InputProfile
+{
+ enum class CycleDirection : int
+ {
+ Forward = 1,
+ Backward = -1
+ };
+
+ class ProfileCycler
+ {
+ public:
+ void NextWiimoteProfile();
+ void PreviousWiimoteProfile();
+ private:
+ void CycleProfile(CycleDirection cycle_direction, InputConfig* device_configuration, int& profile_index);
+ std::vector<std::string> GetProfilesForDevice(InputConfig* device_configuration);
+ std::string GetProfile(CycleDirection cycle_direction, int& profile_index, const std::vector<std::string>& profiles);
+ void UpdateToProfile(const std::string& profile_filename, const std::vector<ControllerEmu::EmulatedController*>& controllers);
+ std::vector<ControllerEmu::EmulatedController*> GetControllersForDevice(InputConfig* device_configuration);
+
+ int m_wiimote_profile_index = 0;
+ };
+}