Input: Add hotkey to cycle the wiimote profile forward or backward

Co-authored-by:  Barath Kannan <barathsotd@gmail.com>
This commit is contained in:
iwubcode 2018-04-13 23:51:32 -05:00
parent 29b71fb9ce
commit 3969bf6d1c
16 changed files with 237 additions and 0 deletions

View File

@ -69,6 +69,9 @@ constexpr std::array<const char*, 114> s_hotkey_labels{{
_trans("Connect Wii Remote 4"),
_trans("Connect Balance Board"),
_trans("Next Wii Remote Profile"),
_trans("Previous Wii Remote Profile"),
_trans("Toggle Crop"),
_trans("Toggle Aspect Ratio"),
_trans("Toggle EFB Copies"),
@ -255,6 +258,7 @@ constexpr std::array<HotkeyGroupInfo, NUM_HOTKEY_GROUPS> s_groups_info = {
{_trans("Program Counter"), HK_SHOW_PC, HK_SET_PC},
{_trans("Breakpoint"), HK_BP_TOGGLE, HK_MBP_ADD},
{_trans("Wii"), HK_TRIGGER_SYNC_BUTTON, HK_BALANCEBOARD_CONNECT},
{_trans("Controller Profile"), HK_NEXT_WIIMOTE_PROFILE, HK_PREV_WIIMOTE_PROFILE},
{_trans("Graphics Toggles"), HK_TOGGLE_CROP, HK_TOGGLE_TEXTURES},
{_trans("Internal Resolution"), HK_INCREASE_IR, HK_DECREASE_IR},
{_trans("Freelook"), HK_FREELOOK_DECREASE_SPEED, HK_FREELOOK_RESET},

View File

@ -67,6 +67,9 @@ enum Hotkey
HK_WIIMOTE4_CONNECT,
HK_BALANCEBOARD_CONNECT,
HK_NEXT_WIIMOTE_PROFILE,
HK_PREV_WIIMOTE_PROFILE,
HK_TOGGLE_CROP,
HK_TOGGLE_AR,
HK_TOGGLE_EFBCOPIES,
@ -166,6 +169,7 @@ enum HotkeyGroup : int
HKGP_PC,
HKGP_BREAKPOINT,
HKGP_WII,
HKGP_CONTROLLER_PROFILE,
HKGP_GRAPHICS_TOGGLES,
HKGP_IR,
HKGP_FREELOOK,

View File

@ -50,6 +50,7 @@ add_executable(dolphin-emu
Config/Mapping/GCPadEmu.cpp
Config/Mapping/GCPadWiiUConfigDialog.cpp
Config/Mapping/Hotkey3D.cpp
Config/Mapping/HotkeyControllerProfile.cpp
Config/Mapping/HotkeyDebugging.cpp
Config/Mapping/HotkeyGeneral.cpp
Config/Mapping/HotkeyGraphics.cpp

View File

@ -0,0 +1,39 @@
// Copyright 2018 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "DolphinQt/Config/Mapping/HotkeyControllerProfile.h"
#include <QGroupBox>
#include <QHBoxLayout>
#include "Core/HotkeyManager.h"
HotkeyControllerProfile::HotkeyControllerProfile(MappingWindow* window) : MappingWidget(window)
{
CreateMainLayout();
}
void HotkeyControllerProfile::CreateMainLayout()
{
m_main_layout = new QHBoxLayout();
m_main_layout->addWidget(CreateGroupBox(tr("Controller Profile"), HotkeyManagerEmu::GetHotkeyGroup(HKGP_CONTROLLER_PROFILE)));
setLayout(m_main_layout);
}
InputConfig* HotkeyControllerProfile::GetConfig()
{
return HotkeyManagerEmu::GetConfig();
}
void HotkeyControllerProfile::LoadSettings()
{
HotkeyManagerEmu::LoadConfig();
}
void HotkeyControllerProfile::SaveSettings()
{
HotkeyManagerEmu::GetConfig()->SaveConfig();
}

View File

@ -0,0 +1,26 @@
// Copyright 2018 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include "DolphinQt/Config/Mapping/MappingWidget.h"
class QHBoxLayout;
class HotkeyControllerProfile final : public MappingWidget
{
Q_OBJECT
public:
explicit HotkeyControllerProfile(MappingWindow* window);
InputConfig* GetConfig() override;
private:
void LoadSettings() override;
void SaveSettings() override;
void CreateMainLayout();
// Main
QHBoxLayout* m_main_layout;
};

View File

@ -25,6 +25,7 @@
#include "DolphinQt/Config/Mapping/GCMicrophone.h"
#include "DolphinQt/Config/Mapping/GCPadEmu.h"
#include "DolphinQt/Config/Mapping/Hotkey3D.h"
#include "DolphinQt/Config/Mapping/HotkeyControllerProfile.h"
#include "DolphinQt/Config/Mapping/HotkeyDebugging.h"
#include "DolphinQt/Config/Mapping/HotkeyGeneral.h"
#include "DolphinQt/Config/Mapping/HotkeyGraphics.h"
@ -310,6 +311,7 @@ void MappingWindow::SetMappingType(MappingWindow::Type type)
AddWidget(tr("Debugging"), new HotkeyDebugging(this));
AddWidget(tr("Wii and Wii Remote"), new HotkeyWii(this));
AddWidget(tr("Controller Profile"), new HotkeyControllerProfile(this));
AddWidget(tr("Graphics"), new HotkeyGraphics(this));
AddWidget(tr("3D"), new Hotkey3D(this));
AddWidget(tr("Save and Load State"), new HotkeyStates(this));

View File

@ -70,6 +70,7 @@
<QtMoc Include="Config\Mapping\GCPadEmu.h" />
<QtMoc Include="Config\Mapping\GCPadWiiUConfigDialog.h" />
<QtMoc Include="Config\Mapping\Hotkey3D.h" />
<QtMoc Include="Config\Mapping\HotkeyControllerProfile.h" />
<QtMoc Include="Config\Mapping\HotkeyDebugging.h" />
<QtMoc Include="Config\Mapping\HotkeyGeneral.h" />
<QtMoc Include="Config\Mapping\HotkeyGraphics.h" />
@ -203,6 +204,7 @@
<ClCompile Include="$(QtMocOutPrefix)HacksWidget.cpp" />
<ClCompile Include="$(QtMocOutPrefix)Host.cpp" />
<ClCompile Include="$(QtMocOutPrefix)Hotkey3D.cpp" />
<ClCompile Include="$(QtMocOutPrefix)HotkeyControllerProfile.cpp" />
<ClCompile Include="$(QtMocOutPrefix)HotkeyDebugging.cpp" />
<ClCompile Include="$(QtMocOutPrefix)HotkeyGeneral.cpp" />
<ClCompile Include="$(QtMocOutPrefix)HotkeyGraphics.cpp" />
@ -283,6 +285,7 @@
<ClCompile Include="Config\Mapping\GCPadEmu.cpp" />
<ClCompile Include="Config\Mapping\GCPadWiiUConfigDialog.cpp" />
<ClCompile Include="Config\Mapping\Hotkey3D.cpp" />
<ClCompile Include="Config\Mapping\HotkeyControllerProfile.cpp" />
<ClCompile Include="Config\Mapping\HotkeyDebugging.cpp" />
<ClCompile Include="Config\Mapping\HotkeyGeneral.cpp" />
<ClCompile Include="Config\Mapping\HotkeyGraphics.cpp" />

View File

@ -240,6 +240,11 @@ void HotkeyScheduler::Run()
emit ConnectWiiRemote(wiimote_id);
}
if (IsHotkey(HK_PREV_WIIMOTE_PROFILE))
m_profile_cycler.PreviousWiimoteProfile();
else if (IsHotkey(HK_NEXT_WIIMOTE_PROFILE))
m_profile_cycler.NextWiimoteProfile();
const auto show_msg = [](OSDMessage message) {
if (g_renderer)
g_renderer->ShowOSDMessage(message);

View File

@ -9,6 +9,7 @@
#include <QObject>
#include "Common/Flag.h"
#include "InputCommon/InputProfile.h"
class HotkeyScheduler : public QObject
{
@ -64,4 +65,6 @@ private:
Common::Flag m_stop_requested;
std::thread m_thread;
InputProfile::ProfileCycler m_profile_cycler;
};

View File

@ -1,5 +1,6 @@
add_library(inputcommon
InputConfig.cpp
InputProfile.cpp
ControllerEmu/ControllerEmu.cpp
ControllerEmu/Control/Control.cpp
ControllerEmu/Control/Input.cpp

View File

@ -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" />

View File

@ -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" />

View File

@ -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())

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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;
};
}