Trigger keyup even if another control is active (version 2)

Add support for ControlHost to call OnHoverKeyUp on hovered controls even if another control is focused.
This is needed to support pressing f1 when ex. the item db filter box is selected.
Implement OnHoverKeyUp in several controls instead of calling wiki code in OnKeyUp.
This commit is contained in:
BlueManiac
2021-10-16 19:55:51 +02:00
parent e1f9dc3801
commit 6cb235be2f
7 changed files with 64 additions and 40 deletions

View File

@@ -53,12 +53,22 @@ function ControlHostClass:ProcessControlsInput(inputEvents, viewPort)
end
inputEvents[id] = nil
elseif isMouseInRegion(viewPort) then
local mOverControl = self:GetMouseOverControl(viewPort)
if mOverControl and mOverControl.OnKeyUp then
if mOverControl:OnKeyUp(event.key) then
inputEvents[id] = nil
end
end
local mOverControl = self:GetMouseOverControl(viewPort)
-- Avoid calculating isMouseInRegion as much as possible as it's expensive
if not mOverControl or (self.selControl and not mOverControl.OnHoverKeyUp) then
return
end
if isMouseInRegion(viewPort) then
if not self.selControl and mOverControl.OnKeyUp and mOverControl:OnKeyUp(event.key) then
inputEvents[id] = nil
end
if mOverControl.OnHoverKeyUp then
mOverControl:OnHoverKeyUp(event.key)
end
end
elseif event.type == "Char" then

View File

@@ -8,7 +8,7 @@ local m_min = math.min
local m_max = math.max
local m_floor = math.floor
local DropDownClass = newClass("DropDownControl", "Control", "ControlHost", "TooltipHost", "SearchHost", function(self, anchor, x, y, width, height, list, selFunc, tooltipText, hoverKeyUpFunc)
local DropDownClass = newClass("DropDownControl", "Control", "ControlHost", "TooltipHost", "SearchHost", function(self, anchor, x, y, width, height, list, selFunc, tooltipText)
self.Control(anchor, x, y, width, height)
self.ControlHost()
self.TooltipHost(tooltipText)
@@ -33,7 +33,6 @@ local DropDownClass = newClass("DropDownControl", "Control", "ControlHost", "Too
self.list = list or { }
self.selIndex = 1
self.selFunc = selFunc
self.hoverKeyUpFunc = hoverKeyUpFunc
end)
-- maps the actual dropdown row index (after eventual filtering) to the original (unfiltered) list index
@@ -433,14 +432,13 @@ function DropDownClass:OnKeyUp(key)
self:ScrollSelIntoView()
return self
end
if self.hoverKeyUpFunc then
local index
if self.hoverSel then
index = self.hoverSel
else
index = self.selIndex
end
self.hoverKeyUpFunc(key, index, self.list[index])
end
return self.dropped and self
end
function DropDownClass:GetHoverIndex(key)
if self.hoverSel then
return self.hoverSel
end
return self.selIndex
end

View File

@@ -331,10 +331,12 @@ function ItemDBClass:OnSelCopy(index, item)
Copy(item.raw:gsub("\n","\r\n"))
end
function ItemDBClass:OnHoverKeyUp(index, itemId, key)
function ItemDBClass:OnHoverKeyUp(key)
if itemLib.wiki.matchesKey(key) then
local item = self.list[index]
local item = self.ListControl:GetHoverValue()
itemLib.wiki.openItem(item)
if item then
itemLib.wiki.openItem(item)
end
end
end

View File

@@ -143,8 +143,14 @@ function ItemListClass:OnSelDelete(index, itemId)
end
end
function ItemListClass:OnHoverKeyUp(index, itemId, key)
if itemLib.wiki.matchesKey(key) then
function ItemListClass:OnHoverKeyUp(key)
if not itemLib.wiki.matchesKey(key) then
return
end
local itemId = self.ListControl:GetHoverValue()
if itemId then
local item = self.itemsTab.items[itemId]
itemLib.wiki.openItem(item)

View File

@@ -15,8 +15,6 @@ local ItemSlotClass = newClass("ItemSlotControl", "DropDownControl", function(se
itemsTab:AddUndoState()
itemsTab.build.buildFlag = true
end
end, nil, function(key, index, value)
self:OnHoverKeyUp(key, index)
end)
self.anchor.collapse = true
self.enabled = function()
@@ -165,8 +163,14 @@ function ItemSlotClass:OnKeyDown(key)
return self.DropDownControl:OnKeyDown(key)
end
function ItemSlotClass:OnHoverKeyUp(key, index)
if itemLib.wiki.matchesKey(key) then
function ItemSlotClass:OnHoverKeyUp(key)
if not itemLib.wiki.matchesKey(key) then
return
end
local index = self.DropDownControl:GetHoverIndex()
if index then
local itemIndex = self.items[index]
local item = self.itemsTab.items[itemIndex]

View File

@@ -19,7 +19,6 @@
-- :OnSelCopy(index, value) [Called when Ctrl+C is pressed while a list value is selected]
-- :OnSelDelete(index, value) [Called when backspace or delete is pressed while a list value is selected]
-- :OnSelKeyDown(index, value) [Called when any other key is pressed while a list value is selected]
-- :OnHoverKeyUp(index, value, key) [Called when any other key is pressed while hovering a list value]
--
local ipairs = ipairs
local t_insert = table.insert
@@ -416,17 +415,18 @@ function ListClass:OnKeyUp(key)
end
end
end
if self.OnHoverKeyUp then
local x, y = self:GetPos()
local cursorX, cursorY = GetCursorPos()
local rowRegion = self:GetRowRegion()
if cursorX >= x + rowRegion.x and cursorY >= y + rowRegion.y and cursorX < x + rowRegion.x + rowRegion.width and cursorY < y + rowRegion.y + rowRegion.height then
local index = math.floor((cursorY - y - rowRegion.y + self.controls.scrollBarV.offset) / self.rowHeight) + 1
local value = self.list[index]
if value then
self:OnHoverKeyUp(index, value, key)
end
return self
end
function ListClass:GetHoverValue(key)
local x, y = self:GetPos()
local cursorX, cursorY = GetCursorPos()
local rowRegion = self:GetRowRegion()
if cursorX >= x + rowRegion.x and cursorY >= y + rowRegion.y and cursorX < x + rowRegion.x + rowRegion.width and cursorY < y + rowRegion.y + rowRegion.height then
local index = math.floor((cursorY - y - rowRegion.y + self.controls.scrollBarV.offset) / self.rowHeight) + 1
local value = self.list[index]
if value then
return value
end
end
return self
end

View File

@@ -105,9 +105,13 @@ function SkillListClass:OnSelDelete(index, socketGroup)
end
end
function SkillListClass:OnHoverKeyUp(index, itemId, key)
function SkillListClass:OnHoverKeyUp(key)
if itemLib.wiki.matchesKey(key) then
local item = self.list[index]
local item = self.ListControl:GetHoverValue()
if not item then
return
end
-- Get the first gem in the group
local gem = item.gemList[1]