ImGuiOverlays: Change icon colour depending on controller mode

This commit is contained in:
Stenzek 2024-08-18 20:30:45 +10:00
parent f704141749
commit 4a0fd00f72
No known key found for this signature in database
7 changed files with 40 additions and 14 deletions

View File

@ -65,7 +65,7 @@ void AnalogController::Reset()
if (g_settings.controller_disable_analog_mode_forcing || System::IsRunningUnknownGame())
{
Host::AddIconOSDMessage(
fmt::format("Controller{}AnalogMode", m_index), ICON_FA_GAMEPAD,
fmt::format("Controller{}AnalogMode", m_index), ICON_PF_GAMEPAD_ALT,
TRANSLATE_STR("OSDMessage",
"Analog mode forcing is disabled by game settings. Controller will start in digital mode."),
10.0f);
@ -279,6 +279,11 @@ std::optional<u32> AnalogController::GetAnalogInputBytes() const
m_axis_state[static_cast<size_t>(Axis::RightY)] << 8 | m_axis_state[static_cast<size_t>(Axis::RightX)];
}
u32 AnalogController::GetInputOverlayIconColor() const
{
return m_analog_mode ? 0xFF2534F0u : 0xFFCCCCCCu;
}
void AnalogController::ResetTransferState()
{
if (m_analog_toggle_queued)
@ -300,7 +305,7 @@ void AnalogController::SetAnalogMode(bool enabled, bool show_message)
if (show_message)
{
Host::AddIconOSDMessage(
fmt::format("analog_mode_toggle_{}", m_index), ICON_FA_GAMEPAD,
fmt::format("analog_mode_toggle_{}", m_index), ICON_PF_GAMEPAD_ALT,
enabled ? fmt::format(TRANSLATE_FS("Controller", "Controller {} switched to analog mode."), m_index + 1u) :
fmt::format(TRANSLATE_FS("Controller", "Controller {} switched to digital mode."), m_index + 1u));
}
@ -313,7 +318,7 @@ void AnalogController::ProcessAnalogModeToggle()
if (m_analog_locked)
{
Host::AddIconOSDMessage(
fmt::format("Controller{}AnalogMode", m_index), ICON_FA_GAMEPAD,
fmt::format("Controller{}AnalogMode", m_index), ICON_PF_GAMEPAD_ALT,
fmt::format(m_analog_mode ?
TRANSLATE_FS("AnalogController", "Controller {} is locked to analog mode by the game.") :
TRANSLATE_FS("AnalogController", "Controller {} is locked to digital mode by the game."),
@ -875,7 +880,7 @@ static const SettingInfo s_settings[] = {
const Controller::ControllerInfo AnalogController::INFO = {ControllerType::AnalogController,
"AnalogController",
TRANSLATE_NOOP("ControllerType", "Analog Controller"),
ICON_PF_GAMEPAD,
ICON_PF_GAMEPAD_ALT,
s_binding_info,
s_settings,
Controller::VibrationCapabilities::LargeSmallMotors};

View File

@ -75,6 +75,7 @@ public:
void SetBindState(u32 index, float value) override;
u32 GetButtonStateBits() const override;
std::optional<u32> GetAnalogInputBytes() const override;
u32 GetInputOverlayIconColor() const override;
void ResetTransferState() override;
bool Transfer(const u8 data_in, u8* data_out) override;

View File

@ -82,6 +82,11 @@ std::optional<u32> Controller::GetAnalogInputBytes() const
return std::nullopt;
}
u32 Controller::GetInputOverlayIconColor() const
{
return 0xFFFFFFFFu;
}
void Controller::LoadSettings(SettingsInterface& si, const char* section)
{
}

View File

@ -89,6 +89,9 @@ public:
/// Returns analog input bytes packed as a u32. Values are specific to controller type.
virtual std::optional<u32> GetAnalogInputBytes() const;
/// Returns the colour to use in the input overlay.
virtual u32 GetInputOverlayIconColor() const;
/// Loads/refreshes any per-controller settings.
virtual void LoadSettings(SettingsInterface& si, const char* section);

View File

@ -182,7 +182,7 @@ static const SettingInfo s_settings[] = {
const Controller::ControllerInfo DigitalController::INFO = {ControllerType::DigitalController,
"DigitalController",
TRANSLATE_NOOP("ControllerType", "Digital Controller"),
ICON_PF_GAMEPAD,
ICON_PF_GAMEPAD_ALT,
s_binding_info,
s_settings,
Controller::VibrationCapabilities::NoVibration};

View File

@ -648,10 +648,22 @@ void ImGuiManager::DrawInputsOverlay()
if (!cinfo)
continue;
float text_start_x = current_x;
if (cinfo->icon_name)
text.format("{} {}", cinfo->icon_name, port + 1u);
{
const ImVec2 icon_size = font->CalcTextSizeA(font->FontSize, FLT_MAX, 0.0f, cinfo->icon_name);
const u32 icon_color = controller->GetInputOverlayIconColor();
dl->AddText(font, font->FontSize, ImVec2(current_x + shadow_offset, current_y + shadow_offset), shadow_color,
cinfo->icon_name, nullptr, 0.0f, &clip_rect);
dl->AddText(font, font->FontSize, ImVec2(current_x, current_y), icon_color, cinfo->icon_name, nullptr, 0.0f,
&clip_rect);
text_start_x += icon_size.x;
text.format(" {}", port + 1u);
}
else
{
text.format("{} |", port + 1u);
}
for (const Controller::ControllerBindingInfo& bi : cinfo->bindings)
{
@ -687,9 +699,9 @@ void ImGuiManager::DrawInputsOverlay()
}
}
dl->AddText(font, font->FontSize, ImVec2(current_x + shadow_offset, current_y + shadow_offset), shadow_color,
dl->AddText(font, font->FontSize, ImVec2(text_start_x + shadow_offset, current_y + shadow_offset), shadow_color,
text.c_str(), text.end_ptr(), 0.0f, &clip_rect);
dl->AddText(font, font->FontSize, ImVec2(current_x, current_y), text_color, text.c_str(), text.end_ptr(), 0.0f,
dl->AddText(font, font->FontSize, ImVec2(text_start_x, current_y), text_color, text.c_str(), text.end_ptr(), 0.0f,
&clip_rect);
current_y += font->FontSize + spacing;

View File

@ -554,12 +554,12 @@ bool ImGuiManager::AddIconFonts(float size)
0xf5aa, 0xf5aa, 0xf5e7, 0xf5e7, 0xf65d, 0xf65e, 0xf6a9, 0xf6a9, 0xf6cf, 0xf6cf, 0xf70c, 0xf70c, 0xf794, 0xf794,
0xf7a0, 0xf7a0, 0xf7c2, 0xf7c2, 0xf807, 0xf807, 0xf815, 0xf815, 0xf818, 0xf818, 0xf84c, 0xf84c, 0xf8cc, 0xf8cc,
0x0, 0x0};
static constexpr ImWchar range_pf[] = {0x2196, 0x2199, 0x219e, 0x21a1, 0x21b0, 0x21b3, 0x21ba, 0x21c3, 0x21c7, 0x21ca,
0x21d0, 0x21d4, 0x21dc, 0x21dd, 0x21e0, 0x21e3, 0x21ed, 0x21ee, 0x21f7, 0x21f8,
0x21fa, 0x21fb, 0x227a, 0x227f, 0x2284, 0x2284, 0x235e, 0x235e, 0x2360, 0x2361,
0x2364, 0x2366, 0x23b2, 0x23b4, 0x23ce, 0x23ce, 0x23f4, 0x23f7, 0x2427, 0x243a,
0x243c, 0x243e, 0x2460, 0x246b, 0x24f5, 0x24fd, 0x24ff, 0x24ff, 0x2717, 0x2717,
0x278a, 0x278e, 0x27fc, 0x27fc, 0xe001, 0xe001, 0xff21, 0xff3a, 0x0, 0x0};
static constexpr ImWchar range_pf[] = {
0x2196, 0x2199, 0x219e, 0x21a1, 0x21b0, 0x21b3, 0x21ba, 0x21c3, 0x21c7, 0x21ca, 0x21d0, 0x21d4, 0x21dc,
0x21dd, 0x21e0, 0x21e3, 0x21ed, 0x21ee, 0x21f3, 0x21f3, 0x21f7, 0x21f8, 0x21fa, 0x21fb, 0x227a, 0x227f,
0x2284, 0x2284, 0x235e, 0x235e, 0x2360, 0x2361, 0x2364, 0x2366, 0x23b2, 0x23b4, 0x23ce, 0x23ce, 0x23f4,
0x23f7, 0x2427, 0x243a, 0x243c, 0x243e, 0x2460, 0x246b, 0x24f5, 0x24fd, 0x24ff, 0x24ff, 0x2717, 0x2717,
0x278a, 0x278e, 0x27fc, 0x27fc, 0xe001, 0xe001, 0xff21, 0xff3a, 0x0, 0x0};
{
ImFontConfig cfg;