GE Lua Documentation

Press F to search!

onModifierChanged

Definition


-- @/lua/ge/extensions/ui/bindingsLegend.lua:530

local function onModifierChanged(newModifiers)
  local modifierNames = {}
  if bit.band(newModifiers, MODIFIER_L_SHIFT) == MODIFIER_L_SHIFT or bit.band(newModifiers, MODIFIER_R_SHIFT) == MODIFIER_R_SHIFT then table.insert(modifierNames, "shift") end
  if bit.band(newModifiers, MODIFIER_L_CTRL) == MODIFIER_L_CTRL or bit.band(newModifiers, MODIFIER_R_CTRL) == MODIFIER_R_CTRL then table.insert(modifierNames, "ctrl") end
  if bit.band(newModifiers, MODIFIER_L_ALT) == MODIFIER_L_ALT or bit.band(newModifiers, MODIFIER_R_ALT) == MODIFIER_R_ALT then table.insert(modifierNames, "alt") end
  if bit.band(newModifiers, MODIFIER1) == MODIFIER1 then table.insert(modifierNames, "modifier1") end
  if bit.band(newModifiers, MODIFIER2) == MODIFIER2 then table.insert(modifierNames, "modifier2") end
  if bit.band(newModifiers, MODIFIER3) == MODIFIER3 then table.insert(modifierNames, "modifier3") end
  if bit.band(newModifiers, MODIFIER4) == MODIFIER4 then table.insert(modifierNames, "modifier4") end
  if bit.band(newModifiers, MODIFIER5) == MODIFIER5 then table.insert(modifierNames, "modifier5") end
  if bit.band(newModifiers, MODIFIER6) == MODIFIER6 then table.insert(modifierNames, "modifier6") end

  local actions = {}
  local bindingsByAction = {}

  if not tableIsEmpty(modifierNames) then
    local activeActions = core_input_actions.getActiveActions()
    for _, deviceName in ipairs(core_input_bindings.getRecentDevices()) do
      local bindingsByDevice = getBindingsByDeviceName(deviceName)
      for _, binding in ipairs(bindingsByDevice or {}) do
        local actionInfo = activeActions[binding.action]

        if actionInfo and actionInfo.title and not isActionFilteredOut(actionInfo, binding.action) then
          -- Check if binding.control contains exactly these modifiers
          local bindingModifiers = getModifiersFromControl(binding.control)

          -- Check if modifiers match exactly
          local modifiersMatch = #bindingModifiers == #modifierNames
          if modifiersMatch then
            for _, modifier in ipairs(modifierNames) do
              if not tableContains(bindingModifiers, modifier) then
                modifiersMatch = false
                break
              end
            end
          end

          if modifiersMatch and #modifierNames > 0 then
            -- Get the title from the action definition
            if (not actionInfo.actionMap or isActionMapActive(actionInfo.actionMap)) then
              if not bindingsByAction[binding.action] then
                local action = deepcopy(actionInfo)
                action.action = binding.action
                action.label = actionInfo.title
                action.order = actionInfo.order or 999  -- fallback to 999 if no order defined
                action.hidden = isModifierCombinationFilteredOut(modifierNames)
                action.direction = parseActionDirection(action)
                bindingsByAction[binding.action] = {{device = deviceName, control = binding.control:match("([^ ]+)$")}} -- remove the modifiers from the controls in this case
                action.bindings = bindingsByAction[binding.action]
                table.insert(actions, action)
              end
            end
          end
        end
      end
    end
  end

  local previousModifierCount = tableSize(modifiersActive)
  table.clear(modifiersActive)
  for _, modifier in ipairs(modifierNames) do
    modifiersActive[modifier] = true
  end
  local newModifierCount = tableSize(modifiersActive)
  if hideVehicleSpecificActionsOnModifierPressed and newModifierCount > previousModifierCount then
    hideVehicleSpecificActionsOnModifierPressed = nil
    removeActionCategoryByLabel("vehicleSpecific")
  end

  local additionalData = {
    modifiersActive = modifiersActive,
    priority = 9
  }

  addActions("modified", actions, additionalData)
end

Callers

@/lua/ge/extensions/ui/bindingsLegend.lua
      if debugModifierStates.modifier6 then newModifiers = bit.bor(newModifiers, MODIFIER6) end
      M.onModifierChanged(newModifiers)
    end