From bb3f81207bd8a81ca2b878a5653df0ecb09e29aa Mon Sep 17 00:00:00 2001 From: kokekanon <114332266+kokekanon@users.noreply.github.com> Date: Sat, 26 Jul 2025 23:39:23 -0400 Subject: [PATCH 1/3] fix: boundKeyPressCombos [fix: #1000, #1251 , #1231 , #738] --- modules/corelib/keyboard.lua | 3 + modules/corelib/ui/uiwindow.lua | 18 ++--- modules/game_actionbar/game_actionbar.lua | 10 +-- modules/game_healthinfo/healthinfo.lua | 2 +- modules/game_hotkeys/hotkeys_manager.lua | 92 ++++++++++++++++++++--- modules/game_interface/gameinterface.lua | 5 +- modules/game_inventory/inventory.lua | 2 +- modules/game_mainpanel/mainpanel.lua | 2 +- modules/game_minimap/minimap.lua | 4 +- 9 files changed, 100 insertions(+), 38 deletions(-) diff --git a/modules/corelib/keyboard.lua b/modules/corelib/keyboard.lua index cb0eda5e5f..657c0d29ce 100644 --- a/modules/corelib/keyboard.lua +++ b/modules/corelib/keyboard.lua @@ -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 diff --git a/modules/corelib/ui/uiwindow.lua b/modules/corelib/ui/uiwindow.lua index c547884526..42dd980e44 100644 --- a/modules/corelib/ui/uiwindow.lua +++ b/modules/corelib/ui/uiwindow.lua @@ -6,6 +6,7 @@ function UIWindow.create() window:setTextAlign(AlignTopCenter) window:setDraggable(true) window:setAutoFocusPolicy(AutoFocusFirst) + window.hotkeyBlock = false return window end @@ -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 = nil 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 +end \ No newline at end of file diff --git a/modules/game_actionbar/game_actionbar.lua b/modules/game_actionbar/game_actionbar.lua index 20b30fb26a..a98d0ad152 100644 --- a/modules/game_actionbar/game_actionbar.lua +++ b/modules/game_actionbar/game_actionbar.lua @@ -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() @@ -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() @@ -471,7 +469,6 @@ function closeObjectAssignWindow() objectAssignWindow:destroy() objectAssignWindow = nil actionRadioGroup = nil - modules.game_hotkeys.enableHotkeys(true) end function startChooseItem() @@ -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() diff --git a/modules/game_healthinfo/healthinfo.lua b/modules/game_healthinfo/healthinfo.lua index 8c4c2a34c8..b0966ca95c 100644 --- a/modules/game_healthinfo/healthinfo.lua +++ b/modules/game_healthinfo/healthinfo.lua @@ -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 diff --git a/modules/game_hotkeys/hotkeys_manager.lua b/modules/game_hotkeys/hotkeys_manager.lua index 3bef1c9ef6..aa8d636b61 100644 --- a/modules/game_hotkeys/hotkeys_manager.lua +++ b/modules/game_hotkeys/hotkeys_manager.lua @@ -57,7 +57,8 @@ useRadioGroup = nil currentHotkeys = nil boundCombosCallback = {} hotkeysList = {} -disableHotkeysCount = 0 +local hotkeyBlockingSources = {} +local nextSourceId = 1 lastHotkeyTime = g_clock.millis() local hotkeysWindowButton = nil @@ -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 diff --git a/modules/game_interface/gameinterface.lua b/modules/game_interface/gameinterface.lua index 836b378b57..516ae5287b 100644 --- a/modules/game_interface/gameinterface.lua +++ b/modules/game_interface/gameinterface.lua @@ -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()) @@ -1097,13 +1098,11 @@ 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 @@ -1111,8 +1110,6 @@ function moveStackableItem(item, toPos) okButton.onClick = moveFunc cancelButton.onClick = cancelFunc - - modules.game_hotkeys.enableHotkeys(false) end function onSelectPanel(self, checked) diff --git a/modules/game_inventory/inventory.lua b/modules/game_inventory/inventory.lua index ad5870dfe7..f5c6f2492f 100644 --- a/modules/game_inventory/inventory.lua +++ b/modules/game_inventory/inventory.lua @@ -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 diff --git a/modules/game_mainpanel/mainpanel.lua b/modules/game_mainpanel/mainpanel.lua index 503d47d908..4c40ed8486 100644 --- a/modules/game_mainpanel/mainpanel.lua +++ b/modules/game_mainpanel/mainpanel.lua @@ -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 diff --git a/modules/game_minimap/minimap.lua b/modules/game_minimap/minimap.lua index e79de18d6c..b5fa11ee58 100644 --- a/modules/game_minimap/minimap.lua +++ b/modules/game_minimap/minimap.lua @@ -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 @@ -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 From 24030701eca4bf3b4ac6e6e1c87b57141e732cfb Mon Sep 17 00:00:00 2001 From: kokekanon <114332266+kokekanon@users.noreply.github.com> Date: Sun, 27 Jul 2025 03:03:20 -0400 Subject: [PATCH 2/3] Update uiwindow.lua --- modules/corelib/ui/uiwindow.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/corelib/ui/uiwindow.lua b/modules/corelib/ui/uiwindow.lua index 42dd980e44..07639b4e3c 100644 --- a/modules/corelib/ui/uiwindow.lua +++ b/modules/corelib/ui/uiwindow.lua @@ -51,6 +51,6 @@ end function UIWindow:onDestroy() if self.hotkeyBlock then self.hotkeyBlock.release() - self.hotkeyBlock = nil + self.hotkeyBlock = false end end \ No newline at end of file From bb8133d571091c2529ba6c13290831369261d882 Mon Sep 17 00:00:00 2001 From: kokekanon <114332266+kokekanon@users.noreply.github.com> Date: Sun, 27 Jul 2025 03:04:20 -0400 Subject: [PATCH 3/3] Update uiwindow.lua --- modules/corelib/ui/uiwindow.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/corelib/ui/uiwindow.lua b/modules/corelib/ui/uiwindow.lua index 07639b4e3c..f30971e20c 100644 --- a/modules/corelib/ui/uiwindow.lua +++ b/modules/corelib/ui/uiwindow.lua @@ -53,4 +53,4 @@ function UIWindow:onDestroy() self.hotkeyBlock.release() self.hotkeyBlock = false end -end \ No newline at end of file +end