Browse Source
Options now only contain the padmapper settings, not the padmapping handling code.pull/7670/head
10 changed files with 164 additions and 132 deletions
@ -0,0 +1,66 @@ |
|||||||
|
#include "controls/padmapper.hpp" |
||||||
|
|
||||||
|
#include <array> |
||||||
|
|
||||||
|
#include "options.h" |
||||||
|
|
||||||
|
namespace devilution { |
||||||
|
|
||||||
|
namespace { |
||||||
|
std::array<const PadmapperOptions::Action *, enum_size<ControllerButton>::value> ButtonToReleaseAction; |
||||||
|
} // namespace
|
||||||
|
|
||||||
|
void PadmapperPress(ControllerButton button, const PadmapperOptions::Action &action) |
||||||
|
{ |
||||||
|
if (action.actionPressed) action.actionPressed(); |
||||||
|
SuppressedButton = action.boundInput.modifier; |
||||||
|
ButtonToReleaseAction[static_cast<size_t>(button)] = &action; |
||||||
|
} |
||||||
|
|
||||||
|
void PadmapperRelease(ControllerButton button, bool invokeAction) |
||||||
|
{ |
||||||
|
if (invokeAction) { |
||||||
|
const PadmapperOptions::Action *action = ButtonToReleaseAction[static_cast<size_t>(button)]; |
||||||
|
if (action == nullptr) |
||||||
|
return; // Ignore unmapped buttons.
|
||||||
|
|
||||||
|
// Check that the action can be triggered.
|
||||||
|
if (action->actionReleased && action->isEnabled()) |
||||||
|
action->actionReleased(); |
||||||
|
} |
||||||
|
ButtonToReleaseAction[static_cast<size_t>(button)] = nullptr; |
||||||
|
} |
||||||
|
|
||||||
|
bool PadmapperIsActionActive(std::string_view actionName) |
||||||
|
{ |
||||||
|
for (const PadmapperOptions::Action &action : GetOptions().Padmapper.actions) { |
||||||
|
if (action.key != actionName) |
||||||
|
continue; |
||||||
|
const PadmapperOptions::Action *releaseAction = ButtonToReleaseAction[static_cast<size_t>(action.boundInput.button)]; |
||||||
|
return releaseAction != nullptr && releaseAction->key == actionName; |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
void PadmapperReleaseAllActiveButtons() |
||||||
|
{ |
||||||
|
for (const PadmapperOptions::Action *action : ButtonToReleaseAction) { |
||||||
|
if (action != nullptr) { |
||||||
|
PadmapperRelease(action->boundInput.button, /*invokeAction=*/true); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
std::string_view PadmapperActionNameTriggeredByButtonEvent(ControllerButtonEvent ctrlEvent) |
||||||
|
{ |
||||||
|
if (!ctrlEvent.up) { |
||||||
|
const PadmapperOptions::Action *pressAction = GetOptions().Padmapper.findAction(ctrlEvent.button, IsControllerButtonPressed); |
||||||
|
if (pressAction == nullptr) return {}; |
||||||
|
return pressAction->key; |
||||||
|
} |
||||||
|
const PadmapperOptions::Action *releaseAction = ButtonToReleaseAction[static_cast<size_t>(ctrlEvent.button)]; |
||||||
|
if (releaseAction == nullptr) return {}; |
||||||
|
return releaseAction->key; |
||||||
|
} |
||||||
|
|
||||||
|
} // namespace devilution
|
||||||
@ -0,0 +1,16 @@ |
|||||||
|
#pragma once |
||||||
|
|
||||||
|
#include <string_view> |
||||||
|
|
||||||
|
#include "controls/controller_buttons.h" |
||||||
|
#include "options.h" |
||||||
|
|
||||||
|
namespace devilution { |
||||||
|
|
||||||
|
void PadmapperPress(ControllerButton button, const PadmapperOptions::Action &action); |
||||||
|
void PadmapperRelease(ControllerButton button, bool invokeAction); |
||||||
|
void PadmapperReleaseAllActiveButtons(); |
||||||
|
[[nodiscard]] bool PadmapperIsActionActive(std::string_view actionName); |
||||||
|
[[nodiscard]] std::string_view PadmapperActionNameTriggeredByButtonEvent(ControllerButtonEvent ctrlEvent); |
||||||
|
|
||||||
|
} // namespace devilution
|
||||||
Loading…
Reference in new issue