Controller: Use std::span
This commit is contained in:
@ -875,9 +875,7 @@ const Controller::ControllerInfo AnalogController::INFO = {ControllerType::Analo
|
||||
"AnalogController",
|
||||
TRANSLATE_NOOP("ControllerType", "Analog Controller"),
|
||||
s_binding_info,
|
||||
countof(s_binding_info),
|
||||
s_settings,
|
||||
countof(s_settings),
|
||||
Controller::VibrationCapabilities::LargeSmallMotors};
|
||||
|
||||
void AnalogController::LoadSettings(SettingsInterface& si, const char* section)
|
||||
|
||||
@ -407,9 +407,7 @@ const Controller::ControllerInfo AnalogJoystick::INFO = {ControllerType::AnalogJ
|
||||
"AnalogJoystick",
|
||||
TRANSLATE_NOOP("ControllerType", "Analog Joystick"),
|
||||
s_binding_info,
|
||||
countof(s_binding_info),
|
||||
s_settings,
|
||||
countof(s_settings),
|
||||
Controller::VibrationCapabilities::NoVibration};
|
||||
|
||||
void AnalogJoystick::LoadSettings(SettingsInterface& si, const char* section)
|
||||
|
||||
@ -15,10 +15,8 @@
|
||||
static const Controller::ControllerInfo s_none_info = {ControllerType::None,
|
||||
"None",
|
||||
TRANSLATE_NOOP("ControllerType", "Not Connected"),
|
||||
nullptr,
|
||||
0,
|
||||
nullptr,
|
||||
0,
|
||||
{},
|
||||
{},
|
||||
Controller::VibrationCapabilities::NoVibration};
|
||||
|
||||
static const Controller::ControllerInfo* s_controller_info[] = {
|
||||
@ -144,53 +142,13 @@ std::vector<std::pair<std::string, std::string>> Controller::GetControllerTypeNa
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<std::string> Controller::GetControllerBinds(const std::string_view& type)
|
||||
{
|
||||
std::vector<std::string> ret;
|
||||
|
||||
const ControllerInfo* info = GetControllerInfo(type);
|
||||
if (info)
|
||||
{
|
||||
for (u32 i = 0; i < info->num_bindings; i++)
|
||||
{
|
||||
const ControllerBindingInfo& bi = info->bindings[i];
|
||||
if (bi.type == InputBindingInfo::Type::Unknown || bi.type == InputBindingInfo::Type::Motor)
|
||||
continue;
|
||||
|
||||
ret.emplace_back(info->bindings[i].name);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<std::string> Controller::GetControllerBinds(ControllerType type)
|
||||
{
|
||||
std::vector<std::string> ret;
|
||||
|
||||
const ControllerInfo* info = GetControllerInfo(type);
|
||||
if (info)
|
||||
{
|
||||
for (u32 i = 0; i < info->num_bindings; i++)
|
||||
{
|
||||
const ControllerBindingInfo& bi = info->bindings[i];
|
||||
if (bi.type == InputBindingInfo::Type::Unknown || bi.type == InputBindingInfo::Type::Motor)
|
||||
continue;
|
||||
|
||||
ret.emplace_back(info->bindings[i].name);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::optional<u32> Controller::GetBindIndex(ControllerType type, const std::string_view& bind_name)
|
||||
{
|
||||
const ControllerInfo* info = GetControllerInfo(type);
|
||||
if (!info)
|
||||
return std::nullopt;
|
||||
|
||||
for (u32 i = 0; i < info->num_bindings; i++)
|
||||
for (u32 i = 0; i < static_cast<u32>(info->bindings.size()); i++)
|
||||
{
|
||||
if (bind_name == info->bindings[i].name)
|
||||
return i;
|
||||
|
||||
@ -1,13 +1,17 @@
|
||||
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
||||
|
||||
#pragma once
|
||||
#include "common/image.h"
|
||||
|
||||
#include "input_types.h"
|
||||
#include "settings.h"
|
||||
#include "types.h"
|
||||
|
||||
#include "common/image.h"
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <tuple>
|
||||
@ -42,10 +46,8 @@ public:
|
||||
ControllerType type;
|
||||
const char* name;
|
||||
const char* display_name;
|
||||
const ControllerBindingInfo* bindings;
|
||||
u32 num_bindings;
|
||||
const SettingInfo* settings;
|
||||
u32 num_settings;
|
||||
std::span<const ControllerBindingInfo> bindings;
|
||||
std::span<const SettingInfo> settings;
|
||||
VibrationCapabilities vibration_caps;
|
||||
};
|
||||
|
||||
@ -96,10 +98,6 @@ public:
|
||||
/// Returns a list of controller type names. Pair of [name, display name].
|
||||
static std::vector<std::pair<std::string, std::string>> GetControllerTypeNames();
|
||||
|
||||
/// Returns the list of binds for the specified controller type.
|
||||
static std::vector<std::string> GetControllerBinds(const std::string_view& type);
|
||||
static std::vector<std::string> GetControllerBinds(ControllerType type);
|
||||
|
||||
/// Gets the integer code for an axis in the specified controller type.
|
||||
static std::optional<u32> GetBindIndex(ControllerType type, const std::string_view& bind_name);
|
||||
|
||||
|
||||
@ -178,9 +178,7 @@ const Controller::ControllerInfo DigitalController::INFO = {ControllerType::Digi
|
||||
"DigitalController",
|
||||
TRANSLATE_NOOP("ControllerType", "Digital Controller"),
|
||||
s_binding_info,
|
||||
countof(s_binding_info),
|
||||
s_settings,
|
||||
countof(s_settings),
|
||||
Controller::VibrationCapabilities::NoVibration};
|
||||
|
||||
void DigitalController::LoadSettings(SettingsInterface& si, const char* section)
|
||||
|
||||
@ -96,9 +96,9 @@ using ImGuiFullscreen::UIPrimaryLightColor;
|
||||
using ImGuiFullscreen::UIPrimaryLineColor;
|
||||
using ImGuiFullscreen::UIPrimaryTextColor;
|
||||
using ImGuiFullscreen::UISecondaryColor;
|
||||
using ImGuiFullscreen::UISecondaryWeakColor;
|
||||
using ImGuiFullscreen::UISecondaryStrongColor;
|
||||
using ImGuiFullscreen::UISecondaryTextColor;
|
||||
using ImGuiFullscreen::UISecondaryWeakColor;
|
||||
using ImGuiFullscreen::UITextHighlightColor;
|
||||
|
||||
using ImGuiFullscreen::ActiveButton;
|
||||
@ -1114,9 +1114,8 @@ void FullscreenUI::DoToggleAnalogMode()
|
||||
if (!cinfo)
|
||||
continue;
|
||||
|
||||
for (u32 j = 0; j < cinfo->num_bindings; j++)
|
||||
for (const Controller::ControllerBindingInfo& bi : cinfo->bindings)
|
||||
{
|
||||
const Controller::ControllerBindingInfo& bi = cinfo->bindings[j];
|
||||
if (std::strcmp(bi.name, "Analog") == 0)
|
||||
{
|
||||
ctrl->SetBindState(bi.bind_index, 1.0f);
|
||||
@ -3314,7 +3313,7 @@ void FullscreenUI::DrawControllerSettingsPage()
|
||||
});
|
||||
}
|
||||
|
||||
if (!ci || ci->num_bindings == 0)
|
||||
if (!ci || ci->bindings.empty() == 0)
|
||||
continue;
|
||||
|
||||
if (MenuButton(FSUI_ICONSTR(ICON_FA_MAGIC, "Automatic Mapping"),
|
||||
@ -3323,11 +3322,8 @@ void FullscreenUI::DrawControllerSettingsPage()
|
||||
StartAutomaticBinding(global_slot);
|
||||
}
|
||||
|
||||
for (u32 i = 0; i < ci->num_bindings; i++)
|
||||
{
|
||||
const Controller::ControllerBindingInfo& bi = ci->bindings[i];
|
||||
for (const Controller::ControllerBindingInfo& bi : ci->bindings)
|
||||
DrawInputBindingButton(bsi, bi.type, section.c_str(), bi.name, bi.display_name, true);
|
||||
}
|
||||
|
||||
if (mtap_enabled[mtap_port])
|
||||
{
|
||||
@ -3354,9 +3350,8 @@ void FullscreenUI::DrawControllerSettingsPage()
|
||||
{
|
||||
std::vector<std::string_view> buttons_split(StringUtil::SplitString(binds_string, '&', true));
|
||||
ImGuiFullscreen::ChoiceDialogOptions options;
|
||||
for (u32 i = 0; i < ci->num_bindings; i++)
|
||||
for (const Controller::ControllerBindingInfo& bi : ci->bindings)
|
||||
{
|
||||
const Controller::ControllerBindingInfo& bi = ci->bindings[i];
|
||||
if (bi.type != InputBindingInfo::Type::Button && bi.type != InputBindingInfo::Type::Axis &&
|
||||
bi.type != InputBindingInfo::Type::HalfAxis)
|
||||
{
|
||||
@ -3372,9 +3367,8 @@ void FullscreenUI::DrawControllerSettingsPage()
|
||||
[game_settings, section, macro_index, ci](s32 index, const std::string& title, bool checked) {
|
||||
// convert display name back to bind name
|
||||
std::string_view to_modify;
|
||||
for (u32 j = 0; j < ci->num_bindings; j++)
|
||||
for (const Controller::ControllerBindingInfo& bi : ci->bindings)
|
||||
{
|
||||
const Controller::ControllerBindingInfo& bi = ci->bindings[j];
|
||||
if (bi.display_name == title)
|
||||
{
|
||||
to_modify = bi.name;
|
||||
@ -3458,7 +3452,7 @@ void FullscreenUI::DrawControllerSettingsPage()
|
||||
ImGui::PopFont();
|
||||
}
|
||||
|
||||
if (ci->num_settings > 0)
|
||||
if (!ci->settings.empty())
|
||||
{
|
||||
if (mtap_enabled[mtap_port])
|
||||
{
|
||||
@ -3471,9 +3465,8 @@ void FullscreenUI::DrawControllerSettingsPage()
|
||||
mtap_port + 1));
|
||||
}
|
||||
|
||||
for (u32 i = 0; i < ci->num_settings; i++)
|
||||
for (const SettingInfo& si : ci->settings)
|
||||
{
|
||||
const SettingInfo& si = ci->settings[i];
|
||||
TinyString title;
|
||||
title.Fmt(ICON_FA_COG "{}", si.display_name);
|
||||
switch (si.type)
|
||||
@ -4715,8 +4708,7 @@ void FullscreenUI::DrawPauseMenu()
|
||||
subtitle_pos.x -= rp_height;
|
||||
subtitle_pos.y -= rp_height;
|
||||
|
||||
DrawShadowedText(dl, g_medium_font, rp_pos, text_color, rp.data(), rp.data() + rp.size(),
|
||||
wrap_width);
|
||||
DrawShadowedText(dl, g_medium_font, rp_pos, text_color, rp.data(), rp.data() + rp.size(), wrap_width);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -304,9 +304,7 @@ const Controller::ControllerInfo GunCon::INFO = {ControllerType::GunCon,
|
||||
"GunCon",
|
||||
TRANSLATE_NOOP("ControllerType", "GunCon"),
|
||||
s_binding_info,
|
||||
countof(s_binding_info),
|
||||
s_settings,
|
||||
countof(s_settings),
|
||||
Controller::VibrationCapabilities::NoVibration};
|
||||
|
||||
void GunCon::LoadSettings(SettingsInterface& si, const char* section)
|
||||
|
||||
@ -627,9 +627,8 @@ void ImGuiManager::DrawInputsOverlay()
|
||||
|
||||
text.Fmt("P{} |", port + 1u);
|
||||
|
||||
for (u32 bind = 0; bind < cinfo->num_bindings; bind++)
|
||||
for (const Controller::ControllerBindingInfo& bi : cinfo->bindings)
|
||||
{
|
||||
const Controller::ControllerBindingInfo& bi = cinfo->bindings[bind];
|
||||
switch (bi.type)
|
||||
{
|
||||
case InputBindingInfo::Type::Axis:
|
||||
|
||||
@ -269,9 +269,7 @@ const Controller::ControllerInfo NeGcon::INFO = {ControllerType::NeGcon,
|
||||
"NeGcon",
|
||||
TRANSLATE_NOOP("ControllerType", "NeGcon"),
|
||||
s_binding_info,
|
||||
countof(s_binding_info),
|
||||
s_settings,
|
||||
countof(s_settings),
|
||||
Controller::VibrationCapabilities::NoVibration};
|
||||
|
||||
void NeGcon::LoadSettings(SettingsInterface& si, const char* section)
|
||||
|
||||
@ -219,7 +219,5 @@ const Controller::ControllerInfo PlayStationMouse::INFO = {ControllerType::PlayS
|
||||
"PlayStationMouse",
|
||||
TRANSLATE_NOOP("ControllerType", "PlayStation Mouse"),
|
||||
s_binding_info,
|
||||
countof(s_binding_info),
|
||||
s_settings,
|
||||
countof(s_settings),
|
||||
Controller::VibrationCapabilities::NoVibration};
|
||||
Reference in New Issue
Block a user