Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions modules/corelib/keyboard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ local function onWidgetKeyPress(widget, keyCode, keyboardModifiers, autoRepeatTi
if keyCode == KeyUnknown then
return false
end
if not widget.boundKeyPressCombos then
return false
end
local callback = widget.boundKeyPressCombos[determineKeyComboDesc(keyCode, keyboardModifiers)]
return signalcall(callback, widget, keyCode, autoRepeatTicks)
end
Expand Down
16 changes: 5 additions & 11 deletions modules/corelib/ui/uiwindow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function UIWindow.create()
window:setTextAlign(AlignTopCenter)
window:setDraggable(true)
window:setAutoFocusPolicy(AutoFocusFirst)
window.hotkeyBlock = false
return window
end

Expand Down Expand Up @@ -47,16 +48,9 @@ function UIWindow:onDragMove(mousePos, mouseMoved)
self:bindRectToParent()
end

function UIWindow:show(dontDisableHotkeys)
if modules.game_hotkeys and not dontDisableHotkeys then
modules.game_hotkeys.enableHotkeys(false)
function UIWindow:onDestroy()
if self.hotkeyBlock then
self.hotkeyBlock.release()
self.hotkeyBlock = false
end
self:setVisible(true)
end

function UIWindow:hide(dontDisableHotkeys)
if modules.game_hotkeys and not dontDisableHotkeys then
modules.game_hotkeys.enableHotkeys(true)
end
self:setVisible(false)
end
10 changes: 3 additions & 7 deletions modules/game_actionbar/game_actionbar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,13 @@ function openSpellAssignWindow()
spellAssignWindow:raise()
spellAssignWindow:focus()
spellAssignWindow:getChildById('filterTextEdit'):focus()
modules.game_hotkeys.enableHotkeys(false)
spellAssignWindow.hotkeyBlock = modules.game_hotkeys.createHotkeyBlock("spell_assign_window")
end

function closeSpellAssignWindow()
spellAssignWindow:destroy()
spellAssignWindow = nil
spellsPanel = nil
modules.game_hotkeys.enableHotkeys(true)
end

function initializeSpelllist()
Expand Down Expand Up @@ -395,13 +394,12 @@ function openTextAssignWindow()
textAssignWindow = g_ui.loadUI('assign_text', g_ui.getRootWidget())
textAssignWindow:raise()
textAssignWindow:focus()
modules.game_hotkeys.enableHotkeys(false)
textAssignWindow.hotkeyBlock = modules.game_hotkeys.createHotkeyBlock("text_assign_window")
end

function closeTextAssignWindow()
textAssignWindow:destroy()
textAssignWindow = nil
modules.game_hotkeys.enableHotkeys(true)
end

function textAssignAccept()
Expand Down Expand Up @@ -471,7 +469,6 @@ function closeObjectAssignWindow()
objectAssignWindow:destroy()
objectAssignWindow = nil
actionRadioGroup = nil
modules.game_hotkeys.enableHotkeys(true)
end

function startChooseItem()
Expand Down Expand Up @@ -627,13 +624,12 @@ function openEditHotkeyWindow()
editHotkeyWindow.onKeyDown = hotkeyCapture
editHotkeyWindow:raise()
editHotkeyWindow:focus()
modules.game_hotkeys.enableHotkeys(false)
editHotkeyWindow.hotkeyBlock = modules.game_hotkeys.createHotkeyBlock("edit_hotkey_window")
end

function closeEditHotkeyWindow()
editHotkeyWindow:destroy()
editHotkeyWindow = nil
modules.game_hotkeys.enableHotkeys(true)
end

function unbindHotkeys()
Expand Down
2 changes: 1 addition & 1 deletion modules/game_healthinfo/healthinfo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function extendedView(extendedView)
if not mainRightPanel:hasChild(healthManaController.ui) then
mainRightPanel:insertChild(2, healthManaController.ui)
end
healthManaController.ui:show(true)
healthManaController.ui:show()
end
healthManaController.ui.moveOnlyToMain = not extendedView
end
Expand Down
92 changes: 82 additions & 10 deletions modules/game_hotkeys/hotkeys_manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ useRadioGroup = nil
currentHotkeys = nil
boundCombosCallback = {}
hotkeysList = {}
disableHotkeysCount = 0
local hotkeyBlockingSources = {}
local nextSourceId = 1
lastHotkeyTime = g_clock.millis()
local hotkeysWindowButton = nil

Expand Down Expand Up @@ -795,23 +796,94 @@ function hotkeyCaptureOk(assignWindow, keyCombo)
assignWindow:destroy()
end

function enableHotkeys(value)
disableHotkeysCount = disableHotkeysCount + (value and -1 or 1)
function enableHotkeys(sourceId)
if sourceId then
hotkeyBlockingSources[sourceId] = nil
end
end

if disableHotkeysCount < 0 then
disableHotkeysCount = 0;
function disableHotkeys(sourceIdentifier)
local sourceId = sourceIdentifier or ("auto_" .. nextSourceId)
nextSourceId = nextSourceId + 1
hotkeyBlockingSources[sourceId] = true
return sourceId
end

local function getCallerModule()
local info = debug.getinfo(3, "S")
if info and info.source then
local source = info.source:gsub("@", "")
local moduleName = source:match("/modules/([^/]+)/") or
source:match("\\modules\\([^\\]+)\\") or
source:match("([^/\\]+)%.lua$") or
"unknown"
return moduleName:gsub("_", "")
end
return "unknown"
end

function createHotkeyBlock(sourceIdentifier)
local callerModule = getCallerModule()
local fullId = sourceIdentifier and
(sourceIdentifier .. "_" .. callerModule) or
("auto_" .. callerModule .. "_" .. nextSourceId)
local blockId = disableHotkeys(fullId)
return {
release = function()
enableHotkeys(blockId)
end,
getId = function()
return fullId
end
}
end

function areHotkeysDisabled()
return disableHotkeysCount > 0
for _ in pairs(hotkeyBlockingSources) do
return true
end
return false
end

function clearAllHotkeyBlocks()
hotkeyBlockingSources = {}
end
function getHotkeyBlockingInfo()
local count = 0
local sources = {}
for sourceId in pairs(hotkeyBlockingSources) do
count = count + 1
table.insert(sources, sourceId)
end
table.sort(sources)
return count, sources
end

function printHotkeyBlockingInfo()
local count, sources = getHotkeyBlockingInfo()
print("=== Hotkey Blocking Info ===")
print("Total blocks: " .. count)
if count > 0 then
print("Active sources:")
for i, source in ipairs(sources) do
print(" " .. i .. ". " .. source)
end
else
print("No active blocks")
end
print("===========================")
end

-- Even if hotkeys are enabled, only the hotkeys containing Ctrl or Alt or F1-F12 will be enabled when
-- chat is opened (no WASD mode). This is made to prevent executing hotkeys while typing...
function canPerformKeyCombo(keyCombo)
return disableHotkeysCount == 0 and
(not modules.game_console:isChatEnabled() or string.match(keyCombo, 'F%d%d?') or
string.match(keyCombo, 'Ctrl%+') or string.match(keyCombo, 'Shift%+..+') or
string.match(keyCombo, 'Alt%+'))
if areHotkeysDisabled() then
return false
end
if not modules.game_console.isChatEnabled() then
return true
end
return string.match(keyCombo, "Ctrl%+") or
string.match(keyCombo, "Alt%+") or
string.match(keyCombo, "F%d+")
end
5 changes: 1 addition & 4 deletions modules/game_interface/gameinterface.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,7 @@ function moveStackableItem(item, toPos)
local count = item:getCount()

countWindow = g_ui.createWidget('CountWindow', rootWidget)
countWindow.hotkeyBlock = modules.game_hotkeys.createHotkeyBlock("stackable_item_dialog")
local itembox = countWindow:getChildById('item')
local scrollbar = countWindow:getChildById('countScrollBar')
itembox:setItemId(item:getId())
Expand Down Expand Up @@ -1097,22 +1098,18 @@ function moveStackableItem(item, toPos)
g_game.move(item, toPos, itembox:getItemCount())
okButton:getParent():destroy()
countWindow = nil
modules.game_hotkeys.enableHotkeys(true)
end
local cancelButton = countWindow:getChildById('buttonCancel')
local cancelFunc = function()
cancelButton:getParent():destroy()
countWindow = nil
modules.game_hotkeys.enableHotkeys(true)
end

countWindow.onEnter = moveFunc
countWindow.onEscape = cancelFunc

okButton.onClick = moveFunc
cancelButton.onClick = cancelFunc

modules.game_hotkeys.enableHotkeys(false)
end

function onSelectPanel(self, checked)
Expand Down
2 changes: 1 addition & 1 deletion modules/game_inventory/inventory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ function extendedView(extendedView)
if not mainRightPanel:hasChild(inventoryController.ui) then
mainRightPanel:insertChild(3, inventoryController.ui)
end
inventoryController.ui:show(true)
inventoryController.ui:show()
end
inventoryController.ui.moveOnlyToMain = not extendedView

Expand Down
2 changes: 1 addition & 1 deletion modules/game_mainpanel/mainpanel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ function toggleExtendedViewButtons(extended)
end
end
end
optionsController.ui:show(true)
optionsController.ui:show()
optionsController.ui:setHeight(28)
local mainRightPanel = modules.game_interface.getMainRightPanel()
if mainRightPanel:hasChild(optionsController.ui) then
Expand Down
4 changes: 2 additions & 2 deletions modules/game_minimap/minimap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ function fullscreen()
fullscreenWidget = nil
minimapWidget:setParent(mapController.ui.minimapBorder)
minimapWidget:fill('parent')
mapController.ui:show(true)
mapController.ui:show()
zoom = minimapWidget.zoomMinimap
g_keyboard.unbindKeyDown('Escape')
minimapWidget.fullMapView = false
Expand Down Expand Up @@ -267,7 +267,7 @@ function extendedView(extendedView)
if not mainRightPanel:hasChild(mapController.ui) then
mainRightPanel:insertChild(1, mapController.ui)
end
mapController.ui:show(true)
mapController.ui:show()

end
mapController.ui.moveOnlyToMain = not extendedView
Expand Down