--[[ Author: Jarth Filename: MementoBar_Hotkeys.lua ]] -- ------------------------------------------------------------------------------------------------- -- VARIABLES -- ------------------------------------------------------------------------------------------------- local baseModule = MementoBar ------------------------------------------------------------------------------------------------- -- PUBLIC FUNCTIONS -- ------------------------------------------------------------------------------------------------- function MementoBar_KeyBindingPressed(keyId) local control = baseModule.WM:GetMouseOverControl() if control ~= nil then for collectibleId, _ in pairs(baseModule.Saved.SelectedMementos) do if baseModule.Buttons[collectibleId] == control then baseModule:HotkeyUpdate(keyId, collectibleId) baseModule:InitializeButtons() return end end end if baseModule.Saved.KeyBindings[keyId] > 0 then baseModule.ButtonOnClicked(baseModule.Buttons[baseModule.Saved.KeyBindings[keyId]]) end end ------------------------------------------------------------------------------------------------- -- PRIVATE FUNCTIONS -- ------------------------------------------------------------------------------------------------- function baseModule:HoykeyCreateSelections() for key, value in ipairs(baseModule.Saved.KeyBindings) do ZO_CreateStringId("SI_BINDING_NAME_MementoBar_" .. key, "MementoBar_" .. key) end end function baseModule:HotkeyUpdate(newKeyId, newCollectibleId) baseModule.Global.ReverseKeyBindings = {} for keyId, collectibleId in ipairs(baseModule.Saved.KeyBindings) do if newCollectibleId and newKeyId == keyId then baseModule.Saved.KeyBindings[keyId] = newCollectibleId baseModule.Global.ReverseKeyBindings[newCollectibleId] = keyId elseif newCollectibleId == collectibleId and newKeyId ~= keyId then baseModule.Saved.KeyBindings[keyId] = 0 elseif collectibleId > 0 and not baseModule.Saved.SelectedMementos[collectibleId] then baseModule.Saved.KeyBindings[keyId] = 0 elseif collectibleId > 0 then baseModule.Global.ReverseKeyBindings[collectibleId] = keyId end end end function baseModule:HoykeyGetKey(button, collectibleId) local result = "" local keyId = baseModule.Global.ReverseKeyBindings[collectibleId] if keyId then local keyBindingTable = {GetHighestPriorityActionBindingInfoFromName("MementoBar_" .. keyId)} for _, keyValue in pairs(keyBindingTable) do if keyValue > 0 then result = baseModule:HotkeyGetKeyName(result, keyValue) end end end return result end function baseModule:HotkeyGetKeyName(result, keyValue) if keyValue > 0 then if result ~= "" then result = string.format("%s+%s", result, GetKeyName(keyValue)) else result = GetKeyName(keyValue) end end return result end function baseModule:HotkeyUpdateColor(frame) local fontColor = baseModule.Saved.FontColor frame:SetColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a) end function baseModule:HotKeyGetLocationValue(value) local result if value == "bottom" then result = BOTTOM elseif value == "bottomleft" then result = BOTTOMLEFT elseif value == "bottomright" then result = BOTTOMRIGHT elseif value == "center" then result = CENTER elseif value == "left" then result = LEFT elseif value == "right" then result = RIGHT elseif value == "top" then result = TOP elseif value == "topleft" then result = TOPLEFT elseif value == "topright" then result = TOPRIGHT end return result end function baseModule:HotKeyGetLocationText(value) local result if value == BOTTOM then result = "bottom" elseif value == BOTTOMLEFT then result = "bottomleft" elseif value == BOTTOMRIGHT then result = "bottomright" elseif value == CENTER then result = "center" elseif value == LEFT then result = "left" elseif value == RIGHT then result = "right" elseif value == TOP then result = "top" elseif value == TOPLEFT then result = "topleft" elseif value == TOPRIGHT then result = "topright" end return result end