From 250ce2fbf71e563e7e11a88d77639a3dcf906bb5 Mon Sep 17 00:00:00 2001 From: Tercio Jose Date: Fri, 22 Sep 2023 13:12:54 -0300 Subject: [PATCH] 10.2 General Implementations and Fixes - Implemented [Pip's Emerald Friendship Badge] trinket buffs. - 10.2 trinket damage spells renamed to the item name. - Framework update. --- Libs/DF/button.lua | 18 +- Libs/DF/definitions.lua | 9 +- Libs/DF/dropdown.lua | 21 + Libs/DF/fw.lua | 70 +- Libs/DF/icongeneric.lua | 16 +- Libs/DF/keybind.lua | 612 ++++++++++++++++++ Libs/DF/label.lua | 2 +- Libs/DF/languages.lua | 1 + Libs/DF/load.xml | 1 + Libs/DF/textentry.lua | 17 +- Libs/DF/unitframe.lua | 3 +- classes/class_damage.lua | 2 + core/parser.lua | 85 ++- functions/spellcache.lua | 49 +- images/spells/elf_face_right.jpg | Bin 0 -> 7256 bytes images/spells/eruption_tier4.jpg | Bin 0 -> 12450 bytes images/spells/lil_dragon_left.jpg | Bin 0 -> 7691 bytes .../spells/spell_druid_bearhug_blackwhite.jpg | Bin 0 -> 7518 bytes 18 files changed, 862 insertions(+), 44 deletions(-) create mode 100644 Libs/DF/keybind.lua create mode 100644 images/spells/elf_face_right.jpg create mode 100644 images/spells/eruption_tier4.jpg create mode 100644 images/spells/lil_dragon_left.jpg create mode 100644 images/spells/spell_druid_bearhug_blackwhite.jpg diff --git a/Libs/DF/button.lua b/Libs/DF/button.lua index ec77f7c5..2fed4404 100644 --- a/Libs/DF/button.lua +++ b/Libs/DF/button.lua @@ -275,6 +275,7 @@ detailsFramework:Mixin(ButtonMetaFunctions, detailsFramework.ScriptHookMixin) --methods ---change the function which will be called when the button is pressed + ---callback function will receive the blizzard button as first parameter, click type as second, param1 and param2 as third and fourth ---@param func function ---@param param1 any ---@param param2 any @@ -887,17 +888,18 @@ end ---@return df_button function detailsFramework:NewButton(parent, container, name, member, width, height, func, param1, param2, texture, text, shortMethod, buttonTemplate, textTemplate) - if (not name) then - name = "DetailsFrameworkButtonNumber" .. detailsFramework.ButtonCounter - detailsFramework.ButtonCounter = detailsFramework.ButtonCounter + 1 - - elseif (not parent) then + if (not parent) then error("Details! FrameWork: parent not found.", 2) end - if (name:find("$parent")) then - local parentName = detailsFramework.GetParentName(parent) - name = name:gsub("$parent", parentName) + if (not name) then + local parentName = parent:GetName() + if (parentName) then + name = parentName .. "Button" .. detailsFramework.ButtonCounter + else + name = "DetailsFrameworkButtonNumber" .. detailsFramework.ButtonCounter + end + detailsFramework.ButtonCounter = detailsFramework.ButtonCounter + 1 end local buttonObject = {type = "button", dframework = true} diff --git a/Libs/DF/definitions.lua b/Libs/DF/definitions.lua index d25d9308..de2f4977 100644 --- a/Libs/DF/definitions.lua +++ b/Libs/DF/definitions.lua @@ -45,6 +45,11 @@ ---@field SplitTextInLines fun(self:table, text:string) : string[] split a text into lines ---@field UnitGroupRolesAssigned fun(unitId: unit, bUseSupport:boolean, specId: specializationid) : string there's no self here ---@field SetAnchor fun(self:table, widget:uiobject, anchorTable:df_anchor, anchorTo:uiobject) ----@field ----@field +---@field AddTextureToText fun(text:string, textureInfo:table, bAddSpace:boolean?, bAddAfterText:boolean) : string textureInfo is a table with .texture .width .height .coords{left, right, top, bottom} +---@field CreateTextureInfo fun(texture:atlasname|texturepath|textureid, width:number?, height:number?, left:number?, right:number?, top:number?, bottom:number?, imageWidthnumber?, imageHeightnumber?) : table +---@field ApplyStandardBackdrop fun(self:table, frame:frame, bUseSolidColor:boolean?, alphaScale:number?) +---@field CreateLabel fun(self:table, parent:frame, text:string, size:number?, color:any?, font:string?, member:string?, name:string?, layer:drawlayer?) : df_label +---@field CreateDropDown fun(self:table, parent:frame, func:function, default:any, width:number?, height:number?, member:string?, name:string?, template:table?) : df_dropdown +---@field CreateTextEntry fun(self:table, parent:frame, textChangedCallback:function, width:number, height:number, member:string?, name:string?, labelText:string?, textentryTemplate:table?, labelTemplate:table?) : df_textentry +---@field ReskinSlider fun(self:table, slider:frame) ---@field diff --git a/Libs/DF/dropdown.lua b/Libs/DF/dropdown.lua index bf16cb99..9a69e10a 100644 --- a/Libs/DF/dropdown.lua +++ b/Libs/DF/dropdown.lua @@ -1083,6 +1083,27 @@ end ------------------------------------------------------------------------------------------------------------ --object constructor +---@class df_dropdown : table, frame +---@field SetTemplate fun(self:df_dropdown, template:table) +---@field BuildDropDownFontList fun(self:df_dropdown, onClick:function, icon:any, iconTexcoord:table?, iconSize:table?):table make a dropdown list with all fonts available, on select a font, call the function onClick +---@field +---@field +---@field +---@field +---@field + + + +---create a dropdown object +---@param parent frame +---@param func function +---@param default any +---@param width number? +---@param height number? +---@param member string? +---@param name string? +---@param template table? +---@return df_dropdown function DF:CreateDropDown(parent, func, default, width, height, member, name, template) return DF:NewDropDown(parent, parent, name, member, width, height, func, default, template) end diff --git a/Libs/DF/fw.lua b/Libs/DF/fw.lua index 5f050f0a..e4365770 100644 --- a/Libs/DF/fw.lua +++ b/Libs/DF/fw.lua @@ -1093,6 +1093,14 @@ function DF:AddClassColorToText(text, className) return text end +---returns the class icon texture coordinates and texture file path +---@param class string +---@return number, number, number, number, string +function DF:GetClassTCoordsAndTexture(class) + local l, r, t, b = unpack(CLASS_ICON_TCOORDS[class]) + return l, r, t, b, [[Interface\WORLDSTATEFRAME\Icons-Classes]] +end + ---create a string with the spell icon and the spell name using |T|t scape codes to add the icon inside the string ---@param self table ---@param spellId any @@ -1105,14 +1113,6 @@ function DF:MakeStringFromSpellId(spellId) return "" end ----returns the class icon texture coordinates and texture file path ----@param class string ----@return number, number, number, number, string -function DF:GetClassTCoordsAndTexture(class) - local l, r, t, b = unpack(CLASS_ICON_TCOORDS[class]) - return l, r, t, b, [[Interface\WORLDSTATEFRAME\Icons-Classes]] -end - ---wrap 'text' with the class icon of 'playerName' using |T|t scape codes ---@param text string ---@param playerName string @@ -1159,6 +1159,58 @@ function DF:AddClassIconToText(text, playerName, englishClassName, useSpec, icon return text end +---create a table with information about a texture +---@param texture any +---@param textureWidth any +---@param textureHeight any +---@param imageWidth any +---@param imageHeight any +---@param left any +---@param right any +---@param top any +---@param bottom any +---@return table +function DF:CreateTextureInfo(texture, textureWidth, textureHeight, left, right, top, bottom, imageWidth, imageHeight) + local textureInfo = { + texture = texture, + width = textureWidth or 16, + height = textureHeight or 16, + coords = {left or 0, right or 1, top or 0, bottom or 1}, + } + + textureInfo.imageWidth = imageWidth or textureInfo.width + textureInfo.imageHeight = imageHeight or textureInfo.height + + return textureInfo +end + +---add a texture to the start or end of a string +---@param text string +---@param textureInfo table +---@param bAddSpace any +---@param bAddAfterText any +---@return string +function DF:AddTextureToText(text, textureInfo, bAddSpace, bAddAfterText) + local texture = textureInfo.texture + local textureWidth = textureInfo.width + local textureHeight = textureInfo.height + local imageWidth = textureInfo.imageWidth or textureWidth + local imageHeight = textureInfo.imageHeight or textureHeight + local left, right, top, bottom = unpack(textureInfo.coords) + left = left or 0 + right = right or 1 + top = top or 0 + bottom = bottom or 1 + + if (bAddAfterText) then + local newString = text .. (bAddSpace and " " or "") .. "|T" .. texture .. ":" .. textureWidth .. ":" .. textureHeight .. ":0:0:" .. imageWidth .. ":" .. imageHeight .. ":" .. (left * imageWidth) .. ":" .. (right * imageWidth) .. ":" .. (top * imageHeight) .. ":" .. (bottom * imageHeight) .. "|t" + return newString + else + local newString = "|T" .. texture .. ":" .. textureWidth .. ":" .. textureHeight .. ":0:0:" .. imageWidth .. ":" .. imageHeight .. ":" .. (left * imageWidth) .. ":" .. (right * imageWidth) .. ":" .. (top * imageHeight) .. ":" .. (bottom * imageHeight) .. "|t" .. (bAddSpace and " " or "") .. text + return newString + end +end + ---return the size of a fontstring ---@param fontString table ---@return number @@ -5633,6 +5685,8 @@ function DF:DebugVisibility(UIObject) local bIsShown = UIObject:IsShown() print("Is Shown:", bIsShown and "|cFF00FF00true|r" or "|cFFFF0000false|r") + print("Alpha > 0:", UIObject:GetAlpha() > 0 and "|cFF00FF00true|r" or "|cFFFF0000false|r") + local bIsVisible = UIObject:IsVisible() print("Is Visible:", bIsVisible and "|cFF00FF00true|r" or "|cFFFF0000false|r") diff --git a/Libs/DF/icongeneric.lua b/Libs/DF/icongeneric.lua index bfc6de6e..645b91a4 100644 --- a/Libs/DF/icongeneric.lua +++ b/Libs/DF/icongeneric.lua @@ -23,6 +23,10 @@ local spellNameCache = {} local emptyTable = {} local white = {1, 1, 1, 1} +local sortIconByShownState = function(i1, i2) + return i1:IsShown() and not i2:IsShown() +end + local iconFrameOnHideScript = function(self) if (self.cooldownLooper) then self.cooldownLooper:Cancel() @@ -161,6 +165,15 @@ detailsFramework.IconGenericMixin = { self:AddSpecificIcon(iconTemplateTable.id, iconTemplateTable.id, nil, iconTemplateTable.startTime, iconTemplateTable.duration, nil, nil, iconTemplateTable.count, nil, nil, nil, nil, nil, nil, iconTemplateTable) end, + IsIconShown = function(self, identifierKey) + if (not identifierKey or identifierKey == "") then + return + end + if (self.AuraCache[identifierKey]) then + return true + end + end, + ---set an icon frame with a template ---@param self df_iconrow the parent frame ---@param aI aurainfo @@ -551,7 +564,8 @@ detailsFramework.IconGenericMixin = { if iconAmount == 0 then self:Hide() else - table.sort(iconPool, function(i1, i2) return i1:IsShown() and not i2:IsShown() end) + table.sort(iconPool, sortIconByShownState) + local shownAmount = 0 for i = 1, iconAmount do if iconPool[i]:IsShown() then diff --git a/Libs/DF/keybind.lua b/Libs/DF/keybind.lua new file mode 100644 index 00000000..b7404d97 --- /dev/null +++ b/Libs/DF/keybind.lua @@ -0,0 +1,612 @@ +---@type detailsframework +local detailsFramework = _G["DetailsFramework"] +if (not detailsFramework or not DetailsFrameworkCanLoad) then + return +end + +local _ +local CreateFrame = CreateFrame + +---@class df_keybindframe : frame, df_optionsmixin +---@field options table +---@field bIsKeybindFrame boolean +---@field CreateSpecButtons fun(self:df_keybindframe) +---@field SwitchSpec fun(self:button, button:string, newSpecId:number) + +local mainStartX, mainStartY, mainHeightSize = 10, -100, 600 + +local default_options = { + width = 800, + height = 600, +} + +local defaultSpecKeybindList = { + ["EVOKER"] = { + [1467] = { + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_interrupt", actiontext = ""}, + {key = "type3", action = "_taunt", actiontext = ""}, + }, + [1468] = { + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_interrupt", actiontext = ""}, + {key = "type3", action = "_taunt", actiontext = ""}, + }, + [1473] = { --aug + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_interrupt", actiontext = ""}, + {key = "type3", action = "_taunt", actiontext = ""}, + }, + }, + + ["DEMONHUNTER"] = { + [577] = {--> havoc demon hunter + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_interrupt", actiontext = ""}, + {key = "type3", action = "_taunt", actiontext = ""}, + }, + [581] = {--> vengeance demon hunter + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_interrupt", actiontext = ""}, + {key = "type3", action = "_taunt", actiontext = ""}, + }, + }, + + ["DEATHKNIGHT"] = { + [250] = { --> blood dk + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_interrupt", actiontext = ""}, + {key = "type3", action = "_taunt", actiontext = ""}, + }, + [251] = { --> frost dk + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_interrupt", actiontext = ""}, + {key = "type3", action = "_taunt", actiontext = ""}, + }, + [252] = { --> unholy dk + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_interrupt", actiontext = ""}, + {key = "type3", action = "_taunt", actiontext = ""}, + }, + }, + + ["WARRIOR"] = { + [71] = { --> warrior arms + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_interrupt", actiontext = ""}, + {key = "type3", action = "_taunt", actiontext = ""}, + }, + [72] = { --> warrior fury + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_interrupt", actiontext = ""}, + {key = "type3", action = "_taunt", actiontext = ""}, + }, + [73] = { --> warrior protect + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_interrupt", actiontext = ""}, + {key = "type3", action = "_taunt", actiontext = ""}, + }, + }, + + ["MAGE"] = { + [62] = { --> mage arcane + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_interrupt", actiontext = ""}, + }, + [63] = { --> mage fire + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_interrupt", actiontext = ""}, + }, + [64] = { --> mage frost + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_interrupt", actiontext = ""}, + }, + }, + + ["ROGUE"] = { + [259] = { --> rogue assassination + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_interrupt", actiontext = ""}, + }, + [260] = { --> rogue combat + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_interrupt", actiontext = ""}, + }, + [261] = { --> rogue sub + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_interrupt", actiontext = ""}, + }, + }, + + ["DRUID"] = { + [102] = { --> druid balance + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_dispel", actiontext = ""}, + }, + [103] = { --> druid feral + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_interrupt", actiontext = ""}, + {key = "type3", action = "_taunt", actiontext = ""}, + }, + [104] = { --> druid guardian + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_interrupt", actiontext = ""}, + {key = "type3", action = "_taunt", actiontext = ""}, + }, + [105] = { --> druid resto + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_dispel", actiontext = ""}, + }, + }, + + ["HUNTER"] = { + [253] = { --> hunter bm + {key = "type1", action = "_target", actiontext = ""}, + }, + [254] = { --> hunter marks + {key = "type1", action = "_target", actiontext = ""}, + }, + [255] = { --> hunter survivor + {key = "type1", action = "_target", actiontext = ""}, + }, + }, + + ["SHAMAN"] = { + [262] = { --> shaman elemental + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_interrupt", actiontext = ""}, + }, + [263] = { --> shamel enhancement + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_interrupt", actiontext = ""}, + }, + [264] = { --> shaman resto + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_interrupt", actiontext = ""}, + }, + }, + + ["PRIEST"] = { + [256] = { --> priest disc + {key = "type1", action = "_target", actiontext = ""}, + }, + [257] = { --> priest holy + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_dispel", actiontext = ""}, + }, + [258] = { --> priest shadow + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_interrupt", actiontext = ""}, + }, + }, + + ["WARLOCK"] = { + [265] = { --> warlock aff + {key = "type1", action = "_target", actiontext = ""}, + }, + [266] = { --> warlock demo + {key = "type1", action = "_target", actiontext = ""}, + }, + [267] = { --> warlock destro + {key = "type1", action = "_target", actiontext = ""}, + }, + }, + + ["PALADIN"] = { + [65] = { --> paladin holy + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_dispel", actiontext = ""}, + }, + [66] = { --> paladin protect + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_interrupt", actiontext = ""}, + {key = "type3", action = "_taunt", actiontext = ""}, + }, + [70] = { --> paladin ret + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_interrupt", actiontext = ""}, + {key = "type3", action = "_taunt", actiontext = ""}, + }, + }, + + ["MONK"] = { + [268] = {--> monk bm + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_interrupt", actiontext = ""}, + {key = "type3", action = "_taunt", actiontext = ""}, + }, + [269] = {--> monk ww + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_interrupt", actiontext = ""}, + {key = "type3", action = "_taunt", actiontext = ""}, + }, + [270] = {--> monk mw + {key = "type1", action = "_target", actiontext = ""}, + {key = "type2", action = "_dispel", actiontext = ""}, + }, + }, +} + +local ignoredKeys = { + ["LSHIFT"] = true, + ["RSHIFT"] = true, + ["LCTRL"] = true, + ["RCTRL"] = true, + ["LALT"] = true, + ["RALT"] = true, + ["UNKNOWN"] = true, +} +local mouseKeys = { + ["LeftButton"] = "type1", + ["RightButton"] = "type2", + ["MiddleButton"] = "type3", + ["Button4"] = "type4", + ["Button5"] = "type5", + ["Button6"] = "type6", + ["Button7"] = "type7", + ["Button8"] = "type8", + ["Button9"] = "type9", + ["Button10"] = "type10", + ["Button11"] = "type11", + ["Button12"] = "type12", + ["Button13"] = "type13", + ["Button14"] = "type14", + ["Button15"] = "type15", + ["Button16"] = "type16", +} +local keysToMouse = { + ["type1"] = "LeftButton", + ["type2"] = "RightButton", + ["type3"] = "MiddleButton", + ["type4"] = "Button4", + ["type5"] = "Button5", + ["type6"] = "Button6", + ["type7"] = "Button7", + ["type8"] = "Button8", + ["type9"] = "Button9", + ["type10"] = "Button10", + ["type11"] = "Button11", + ["type12"] = "Button12", + ["type13"] = "Button13", + ["type14"] = "Button14", + ["type15"] = "Button15", + ["type16"] = "Button16", +} + +local lock_textentry = { + ["_target"] = true, + ["_taunt"] = true, + ["_interrupt"] = true, + ["_dispel"] = true, + ["_spell"] = false, + ["_macro"] = false, +} + +--> helpers +local getMainFrame = function(UIObject) + local parentFrame = UIObject:GetParent() + for i = 1, 5 do + if (parentFrame.bIsKeybindFrame) then + return parentFrame + end + parentFrame = parentFrame:GetParent() + end + return nil +end + +detailsFramework.KeybindMixin = { + IsListening = false, + EditingSpec = 0, + CurrentKeybindEditingSet = {}, + AllSpecButtons = {}, + + SwitchSpec = function(self, button, newSpecId) --switch_spec + self.EditingSpec = newSpecId + self.CurrentKeybindEditingSet = EnemyGridDBChr.KeyBinds[newSpecId] --!need to get from the addon database + + for _, button in ipairs (self.AllSpecButtons) do + button.selectedTexture:Hide() + end + self.MyObject.selectedTexture:Show() + + --quick hide and show as a feedback to the player that the spec was changed + C_Timer.After (.04, function() EnemyGridOptionsPanelFrameKeybindScroill:Hide() end) --!need to defined the scroll frame + C_Timer.After (.06, function() EnemyGridOptionsPanelFrameKeybindScroill:Show() end) --!need to defined the scroll frame + + --atualiza a scroll + EnemyGridOptionsPanelFrameKeybindScroill:UpdateScroll() --!need to defined the scroll frame + end, + + CreateSpecButtons = function(self) + local specsTitle = detailsFramework:CreateLabel(self, "Config keys for spec:", 12, "silver") + specsTitle:SetPoint("topleft", self, "topleft", 10, mainStartY) + + local allSpecButtons = self.AllSpecButtons + + local options_text_template = detailsFramework:GetTemplate("font", "OPTIONS_FONT_TEMPLATE") + local options_dropdown_template = detailsFramework:GetTemplate("dropdown", "OPTIONS_DROPDOWN_TEMPLATE") + local options_switch_template = detailsFramework:GetTemplate("switch", "OPTIONS_CHECKBOX_TEMPLATE") + local options_slider_template = detailsFramework:GetTemplate("slider", "OPTIONS_SLIDER_TEMPLATE") + local options_button_template = detailsFramework:GetTemplate("button", "OPTIONS_BUTTON_TEMPLATE") + + for i = 1, 4 do + local newSpecButton = detailsFramework:CreateButton(self, self.SwitchSpec, 160, 20, "Spec1 Placeholder Text", 1, nil, nil, "specButton" .. i, nil, 0, options_button_template, options_text_template) + table.insert(allSpecButtons, newSpecButton) + self["SpecButton" .. i] = newSpecButton + + newSpecButton:SetPoint("topleft", specsTitle, "bottomleft", 0, -10 + (20*(i-1))) + spec2:SetPoint ("topleft", specsTitle, "bottomleft", 0, -30) + spec3:SetPoint ("topleft", specsTitle, "bottomleft", 0, -50) + if (class == "DRUID") then + spec4:SetPoint ("topleft", specsTitle, "bottomleft", 0, -70) + end + end + + local classLocName, class = UnitClass("player") + local i = 1 + for specId in pairs(defaultSpecKeybindList[class]) do + local button = self["SpecButton" .. i] + local _, specName, _, specIcon = DF.GetSpecializationInfoByID(specId) --classic return nil + + if (specName) then + button.text = specName + button:SetClickFunction(self.SwitchSpec, specId) + button:SetIcon(specIcon) + button.specID = specId + + local selectedTexture = button:CreateTexture(nil, "background") + selectedTexture:SetAllPoints() + selectedTexture:SetColorTexture(1, 1, 1, 0.5) + if (specId ~= self.EditingSpec) then + selectedTexture:Hide() + end + + button.selectedTexture = selectedTexture + i = i + 1 + else + button:Hide() + end + end + + end, + + CreateKeybindListener = function(self) + local enter_the_key = CreateFrame ("frame", nil, self, "BackdropTemplate") + enter_the_key:SetFrameStrata("tooltip") + enter_the_key:SetSize(200, 60) + detailsFramework:ApplyStandardBackdrop(enter_the_key) + enter_the_key.text = detailsFramework:CreateLabel(enter_the_key, "- Press a keyboard key to bind.\n- Click to bind a mouse button.\n- Press escape to cancel.", 11, "orange") + enter_the_key.text:SetPoint("center", enter_the_key, "center", 0, 0) + enter_the_key:Hide() + + + + end, + + set_keybind_key = function(self, button, keybindIndex) + if (keyBindListener.IsListening) then + key = mouseKeys [button] or button + return registerKeybind (keyBindListener, key) + end + keyBindListener.IsListening = true + keyBindListener.keybindIndex = keybindIndex + keyBindListener:SetScript ("OnKeyDown", registerKeybind) + + enter_the_key:Show() + enter_the_key:SetPoint ("bottom", self, "top") + end, + + RefreshKeybindScroll = function(self, data, offset, totalLines) + local keyBindFrame = getMainFrame(self) + local keybinds = keyBindFrame.CurrentKeybindEditingSet + + for i = 1, totalLines do + local index = i + offset + local keybindData = data[index] + + if (keybindData) then + local line = self:GetLine(i) + --index + line.Index.text = index + + --keybind + local keyBindText = keysToMouse[keybindData.key] or keybindData.key + + keyBindText = keyBindText:gsub("type1", "LeftButton") + keyBindText = keyBindText:gsub("type2", "RightButton") + keyBindText = keyBindText:gsub("type3", "MiddleButton") + + line.KeyBind.text = keyBindText + line.KeyBind:SetClickFunction(keyBindFrame.set_keybind_key, index, nil, "left") + line.KeyBind:SetClickFunction(keyBindFrame.set_keybind_key, index, nil, "right") + + --action + line.ActionDrop:SetFixedParameter(index) + line.ActionDrop:Select(keybindData.action) + + --action text + line.ActionText.text = keybindData.actiontext + line.ActionText:SetEnterFunction(set_action_text, index) + line.ActionText.CurIndex = index + + if (lock_textentry[keybindData.action]) then + line.ActionText:Disable() + else + line.ActionText:Enable() + end + + --delete + line.Delete:SetClickFunction(keyBindFrame.delete_keybind, index) + end + end + end, + + delete_keybind = function(self, button, keybindIndex) + local keyBindFrame = getMainFrame(self) + tremove(keyBindFrame.CurrentKeybindEditingSet, keybindIndex) + keyBindFrame.keybindScroll:UpdateScroll() + --EnemyGrid.UpdateKeyBinds() + end, + + change_key_action = function(self, keybindIndex, value) + local keyBindFrame = getMainFrame(self) + local keybind = keyBindFrame.CurrentKeybindEditingSet[keybindIndex] + keybind.action = value + keyBindFrame.keybindScroll:UpdateScroll() + --EnemyGrid.UpdateKeyBinds() + end, + + set_action_on_espace_press = function (textentry, capsule) + local keyBindFrame = getMainFrame(textentry) + capsule = capsule or textentry.MyObject + local keybind = keyBindFrame.CurrentKeybindEditingSet[capsule.CurIndex] + textentry:SetText (keybind.actiontext) + --EnemyGrid.UpdateKeyBinds() + end, + + fill_action_dropdown = function(dropdownObject) + local keyBindFrame = getMainFrame(dropdownObject) + local locClass, class = UnitClass("player") + + local taunt = tauntList[class] and GetSpellInfo(tauntList[class]) or "" + local interrupt = interruptList[class] and GetSpellInfo(interruptList [class]) or "" + local dispel = dispelList[class] + + if (type (dispel) == "table") then + local dispelString = "\n" + for specId, spellid in pairs(dispel) do + local _, specName = GetSpecializationInfoByID(specId) --!classic versions incompatible + local spellName = GetSpellInfo(spellid) + dispelString = dispelString .. "|cFFE5E5E5" .. specName .. "|r: |cFFFFFFFF" .. spellName .. "\n" + end + dispel = dispelString + else + dispel = GetSpellInfo(dispel) or "" + end + + return { + {value = "_target", label = "Target", onclick = keyBindFrame.change_key_action, desc = "Target the unit"}, + {value = "_taunt", label = "Taunt", onclick = keyBindFrame.change_key_action, desc = "Cast the taunt spell for your class\n\n|cFFFFFFFFSpell: " .. taunt}, + {value = "_interrupt", label = "Interrupt", onclick = keyBindFrame.change_key_action, desc = "Cast the interrupt spell for your class\n\n|cFFFFFFFFSpell: " .. interrupt}, + {value = "_dispel", label = "Dispel", onclick = keyBindFrame.change_key_action, desc = "Cast the interrupt spell for your class\n\n|cFFFFFFFFSpell: " .. dispel}, + {value = "_spell", label = "Cast Spell", onclick = keyBindFrame.change_key_action, desc = "Type the spell name in the text box"}, + {value = "_macro", label = "Macro", onclick = keyBindFrame.change_key_action, desc = "Type your macro in the text box"}, + } + end, + + ---@param keyBindFrame df_keybindframe + ---@param index number + CreateKeybindScrollLine = function(keyBindFrame, index) + local line = CreateFrame("frame", "$parentLine" .. index, keybindScroll) + line:SetSize(1009, 20) + line:SetPoint("topleft", keyBindFrame, "topleft", 0, -(index-1)*29) + detailsFramework:ApplyStandardBackdrop(line, index % 2 == 0) + detailsFramework:Mixin(line, detailsFramework.HeaderFunctions) + + local options_text_template = detailsFramework:GetTemplate("font", "OPTIONS_FONT_TEMPLATE") + local options_dropdown_template = detailsFramework:GetTemplate("dropdown", "OPTIONS_DROPDOWN_TEMPLATE") + local options_switch_template = detailsFramework:GetTemplate("switch", "OPTIONS_CHECKBOX_TEMPLATE") + local options_slider_template = detailsFramework:GetTemplate("slider", "OPTIONS_SLIDER_TEMPLATE") + local options_button_template = detailsFramework:GetTemplate("button", "OPTIONS_BUTTON_TEMPLATE") + + line.Index = detailsFramework:CreateLabel(line, "place holder") + line.KeyBind = detailsFramework:CreateButton(line, function()end, 100, 20, "", nil, nil, nil, "SetNewKeybindButton", "$parentSetNewKeybindButton", 0, options_button_template, options_text_template) + line.ActionDrop = detailsFramework:CreateDropDown(line, keyBindFrame.fill_action_dropdown, 0, 120, 20, "ActionDropdown", "$parentActionDropdown", options_dropdown_template) + line.ActionText = detailsFramework:CreateTextEntry(line, function()end, 660, 20, "TextBox", "$parentActionText", nil, options_dropdown_template) + line.Delete = detailsFramework:CreateButton(line, keyBindFrame.delete_keybind, 16, 20, "", nil, nil, nil, "DeleteKeybindButton", "$parentDeleteKeybindButton", 2, options_button_template, options_text_template) + line.Delete:SetIcon([[Interface\Buttons\UI-StopButton]], nil, nil, nil, nil, nil, nil, 4) + line.Delete.tooltip = "erase this keybind" + + --editbox + line.ActionText:SetJustifyH("left") + line.ActionText:SetHook("OnEscapePressed", keyBindFrame.set_action_on_espace_press) + line.ActionText:SetHook("OnEditFocusGained", function() + local playerSpells = {} + local tab, tabTex, offset, numSpells = GetSpellTabInfo(2) + for i = 1, numSpells do + local index = offset + i + local spellType, spellId = GetSpellBookItemInfo(index, "player") + if (spellType == "SPELL") then + local spellName = GetSpellInfo(spellId) + tinsert(playerSpells, spellName) + end + end + line.ActionText.WordList = playerSpells + end) + + line.ActionText:SetAsAutoComplete("WordList") + + line:AddFrameToHeaderAlignment(line.Index) + line:AddFrameToHeaderAlignment(line.KeyBind) + line:AddFrameToHeaderAlignment(line.ActionDrop) + line:AddFrameToHeaderAlignment(line.ActionText) + line:AddFrameToHeaderAlignment(line.Delete) + + line:AlignWithHeader(keyBindFrame.Header, "left") + end, + + ---comment + ---@param self df_keybindframe + CreateKeybindScroll = function(self) + local scroll_width = self.options.width - 10 + local scroll_height = self.options.height - 40 + local scroll_lines = self.options.amount_lines + local scroll_line_height = self.options.line_height + + --header + local headerTable = { + {text = "", width = 20}, --index + {text = "", width = 20}, --spell icon + {text = "Ability Name", width = 120}, + {text = "Keybind", width = 60}, + {text = "Action Type", width = 60}, + {text = "Action Text", width = 45}, + {text = "Clear Keybind", width = 80}, + } + local headerOptions = { + padding = 2, + } + + ---@type df_headerframe + self.Header = DetailsFramework:CreateHeader(self, headerTable, headerOptions) + self.Header:SetPoint("topleft", self, "topleft", 5, -25) + + local keybindScroll = detailsFramework:CreateScrollBox(self, "$parentScrollBox", detailsFramework.KeybindMixin.RefreshKeybindScroll, {}, scroll_width, scroll_height, scroll_lines, scroll_line_height) + detailsFramework:ReskinSlider(keybindScroll) + keybindScroll:SetPoint("topleft", self.Header, "bottomleft", 0, -2) + self.keybindScroll = keybindScroll + + for i = 1, scroll_lines do + keybindScroll:CreateLine(self.CreateKeybindScrollLine) + end + end, +} + + + +---@param parent frame +---@param name string? +---@param options table? +function detailsFramework:CreateKeybindFrame(parent, name, options) + ---@type df_keybindframe + local keyBindFrame = CreateFrame("frame", name, parent, "BackdropTemplate") + keyBindFrame.bIsKeybindFrame = true + + detailsFramework:Mixin(keyBindFrame, detailsFramework.OptionsFunctions) + + options = options or {} + keyBindFrame:BuildOptionsTable(default_options, options) + + keyBindFrame:SetSize(keyBindFrame.options.width, keyBindFrame.options.height) + + keyBindFrame:CreateSpecButtons() + + keyBindFrame:SetScript("OnHide", function() + if (keyBindFrame.IsListening) then + keyBindFrame.IsListening = false + keyBindFrame:SetScript("OnKeyDown", nil) + end + end) + + return keyBindFrame +end diff --git a/Libs/DF/label.lua b/Libs/DF/label.lua index a462993c..71de658f 100644 --- a/Libs/DF/label.lua +++ b/Libs/DF/label.lua @@ -256,7 +256,7 @@ detailsFramework:Mixin(LabelMetaFunctions, detailsFramework.ScriptHookMixin) ------------------------------------------------------------------------------------------------------------ --object constructor ----@class df_label +---@class df_label: uiobject ---@field widget fontstring widget and label points to the same fontstring ---@field label fontstring widget and label points to the same fontstring ---@field align justifyh diff --git a/Libs/DF/languages.lua b/Libs/DF/languages.lua index 6776b981..55e93984 100644 --- a/Libs/DF/languages.lua +++ b/Libs/DF/languages.lua @@ -1628,6 +1628,7 @@ function DF.Language.CreateLanguageSelector(addonId, parent, callback, selectedL local languageLabel = DF:CreateLabel(parent, _G.LANGUAGE .. ":", 10, "silver") languageLabel:SetPoint("right", languageSelector, "left", -3, 0) + languageSelector.languageLabel = languageLabel return languageSelector end diff --git a/Libs/DF/load.xml b/Libs/DF/load.xml index b7674865..a8e9c477 100644 --- a/Libs/DF/load.xml +++ b/Libs/DF/load.xml @@ -40,4 +40,5 @@