accept 🎮 in mod bindings

This commit is contained in:
Kae 2024-07-25 08:56:00 +10:00
parent 323364f0af
commit a6ac154b94
3 changed files with 71 additions and 24 deletions

View File

@ -29,14 +29,18 @@ local function getMods(key)
if bindMods[1] then return bindMods end
end
local function finishBind(type, value)
local function finishBind(a, b)
widget.blur("snare")
snared = false
snareFinished{ type = type, value = value, mods = getMods(value) }
if (type(a) == "table") then
snareFinished(a)
else
snareFinished{ type = a, value = b, mods = getMods(value) }
for i, mod in ipairs(mods) do
mod.active = false
end
end
end
local function scanInputEvents()
local events = input.events()
@ -50,6 +54,8 @@ local function scanInputEvents()
return finishBind("key", data.key)
elseif type == "MouseButtonDown" then
return finishBind("mouse", data.mouseButton)
elseif type == "ControllerButtonDown" then
return finishBind{ type = "controller", value = data.controllerButton, controller = data.controller }
end
end
end
@ -127,9 +133,9 @@ function bindsToString(binds)
str = str .. v .. " + "
end
end
if bind.type == "key" then
str = str .. bind.value
elseif bind.type == "mouse" then
if bind.type == "controller" then
str = str .. "🎮 " .. bind.value
else
str = str .. bind.value
end
local _i = (i - 1) * 2
@ -362,7 +368,7 @@ local function initCallbacks()
end
function init()
--log = sb.logInfo
--log = chat and chat.addMessage or sb.logInfo
widget.clearListItems(CATEGORY_LIST_WIDGET)
initCallbacks()

View File

@ -301,11 +301,9 @@ void ClientApplication::processInput(InputEvent const& event) {
m_controllerRightStick[1] = cAxis->controllerAxisValue;
}
if (!m_errorScreen->accepted() && m_errorScreen->handleInputEvent(event))
return;
bool processed = false;
bool processed = !m_errorScreen->accepted() && m_errorScreen->handleInputEvent(event);
if (!processed) {
if (m_state == MainAppState::Splash) {
processed = m_cinematicOverlay->handleInputEvent(event);
} else if (m_state == MainAppState::Title) {
@ -316,6 +314,7 @@ void ClientApplication::processInput(InputEvent const& event) {
if (!(processed = m_cinematicOverlay->handleInputEvent(event)))
processed = m_mainInterface->handleInputEvent(event);
}
}
m_input->handleInput(event, processed);
}

View File

@ -122,6 +122,22 @@ Json Input::inputEventToJson(InputEvent const& input) {
{"mouseMove", jsonFromVec2I(mouseMove->mouseMove)},
{"mousePosition", jsonFromVec2I(mouseMove->mousePosition)}
};
} else if (auto controllerDown = input.ptr<ControllerButtonDownEvent>()) {
type = "ControllerButtonDown";
data = JsonObject{
{"controllerButton", ControllerButtonNames.getRight(controllerDown->controllerButton)},
{"controller", controllerDown->controller}};
} else if (auto controllerUp = input.ptr<ControllerButtonUpEvent>()) {
type = "ControllerButtonUp";
data = JsonObject{
{"controllerButton", ControllerButtonNames.getRight(controllerUp->controllerButton)},
{"controller", controllerUp->controller}};
} else if (auto controllerAxis = input.ptr<ControllerAxisEvent>()) {
type = "ControllerAxis";
data = JsonObject{
{"controllerAxis", ControllerAxisNames.getRight(controllerAxis->controllerAxis)},
{"controllerAxisValue", controllerAxis->controllerAxisValue},
{"controller", controllerAxis->controller}};
}
if (data) {
@ -186,7 +202,8 @@ Json Input::bindToJson(Bind const& bind) {
else if (auto controllerBind = bind.ptr<ControllerBind>()) {
return JsonObject{
{"type", "controller"},
{"value", ControllerButtonNames.getRight(controllerBind->button)}
{"value", ControllerButtonNames.getRight(controllerBind->button)},
{"controller", controllerBind->controller}
};
}
@ -392,7 +409,8 @@ bool Input::handleInput(InputEvent const& input, bool gameProcessed) {
m_bindStates[bind].press();
}
}
} else if (auto keyUp = input.ptr<KeyUpEvent>()) {
}
else if (auto keyUp = input.ptr<KeyUpEvent>()) {
auto keyToMod = KeysToMods.rightPtr(keyUp->key);
if (keyToMod)
m_pressedMods &= ~*keyToMod;
@ -410,7 +428,8 @@ bool Input::handleInput(InputEvent const& input, bool gameProcessed) {
state->release();
}
}
} else if (auto mouseDown = input.ptr<MouseButtonDownEvent>()) {
}
else if (auto mouseDown = input.ptr<MouseButtonDownEvent>()) {
m_mousePosition = mouseDown->mousePosition;
if (!gameProcessed) {
auto& state = m_mouseStates[mouseDown->mouseButton];
@ -422,7 +441,8 @@ bool Input::handleInput(InputEvent const& input, bool gameProcessed) {
m_bindStates[bind].press();
}
}
} else if (auto mouseUp = input.ptr<MouseButtonUpEvent>()) {
}
else if (auto mouseUp = input.ptr<MouseButtonUpEvent>()) {
m_mousePosition = mouseUp->mousePosition;
if (auto state = m_mouseStates.ptr(mouseUp->mouseButton)) {
state->releasePositions.append(mouseUp->mousePosition);
@ -439,6 +459,28 @@ bool Input::handleInput(InputEvent const& input, bool gameProcessed) {
else if (auto mouseMove = input.ptr<MouseMoveEvent>()) {
m_mousePosition = mouseMove->mousePosition;
}
else if (auto controllerDown = input.ptr<ControllerButtonDownEvent>()) {
if (!gameProcessed) {
auto& state = m_controllerStates[controllerDown->controllerButton];
state.press();
if (auto binds = m_bindMappings.ptr(controllerDown->controllerButton)) {
for (auto bind : filterBindEntries(*binds, m_pressedMods))
m_bindStates[bind].press();
}
}
}
else if (auto controllerUp = input.ptr<ControllerButtonUpEvent>()) {
if (auto state = m_controllerStates.ptr(controllerUp->controllerButton))
state->release();
if (auto binds = m_bindMappings.ptr(controllerUp->controllerButton)) {
for (auto& bind : *binds) {
if (auto state = m_bindStates.ptr(bind.entry))
state->release();
}
}
}
return false;
}