Skip to content

Commit

Permalink
Framework Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Tercioo committed Oct 4, 2024
1 parent a5e211f commit f94c1f5
Show file tree
Hide file tree
Showing 11 changed files with 858 additions and 549 deletions.
10 changes: 5 additions & 5 deletions Libs/DF/cooltip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1992,17 +1992,17 @@ function DF:CreateCoolTip()

function gameCooltip:SetSpellByID(spellId, bShowDescriptionOnly) --~spell
if (type(spellId) == "number") then
spellId = C_SpellBook.GetOverrideSpell(spellId)
spellId = C_Spell.GetOverrideSpell(spellId)
local spellName, spellRank, spellIcon, castTime, minRange, maxRange = GetSpellInfo(spellId)
--castTime zero represents an instant cast or a channeled cast
if (spellName) then
local spellDescription = GetSpellDescription(spellId)
local spellDescription = C_Spell.GetSpellDescription(spellId)
local cooldownTime, globalCooldown = GetSpellBaseCooldown(spellId)
--local cooldown = cooldownTime / 1000
local bIsPassive = IsPassiveSpell(spellId, SPELLBOOK_BANK_PLAYER)
local bIsPassive = C_Spell.IsSpellPassive(spellId, SPELLBOOK_BANK_PLAYER)
local chargesAvailable, maxCharges, chargeCooldownStart, rechargeTime, chargeModRate = GetSpellCharges(spellId)

local tResourceCost = GetSpellPowerCost(spellId)
local tResourceCost = C_Spell.GetSpellPowerCost(spellId)
--[=[
hasRequiredAura=false,
type=0,
Expand All @@ -2022,7 +2022,7 @@ function DF:CreateCoolTip()
gameCooltip:AddIcon(spellIcon, 1, 1, 20, 20, .1, .9, .1, .9)

if (not bShowDescriptionOnly) then
if (tResourceCost.cost and tResourceCost.cost > 0) then
if (tResourceCost and tResourceCost.cost and tResourceCost.cost > 0) then
if (maxRange and maxRange > 0) then
gameCooltip:AddLine(tResourceCost.cost .. " " .. (_G[tResourceCost.name] or tResourceCost.name), string.format(_G.SPELL_RANGE, math.floor(maxRange)), 1, 1, 1, 1, nil, 12)
else
Expand Down
2 changes: 2 additions & 0 deletions Libs/DF/definitions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@
---@field GetRoleTCoordsAndTexture fun(self:table, roleID:number) : number, number, number, number, string
---@field AddColorToText fun(self:table, text:string, color:any) : string wrap text with a color
---@field AddClassColorToText fun(self:table, text:string, className:string) : string wrap text with a class color
---@field CreateSimplePanel fun(self:table, parent:frame, width:number?, height:number?, title:string?, frameName:string?, panelOptions:table?, savedVariableTable:table?) : simplepanel
---@field MakeDraggable fun(self:table, frame:frame) : nil


--[=[
Expand Down
3 changes: 3 additions & 0 deletions Libs/DF/editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,9 @@ detailsFramework.EditorMixin = {
moverFrame.MovingInfo.restingX = x
moverFrame.MovingInfo.restingY = y
moverFrame:SetScript("OnUpdate", onTickNotMoving)

moverFrame:GetScript("OnMouseDown")(moverFrame)
moverFrame:GetScript("OnMouseUp")(moverFrame)
end

self.ObjectBackgroundTexture:SetPoint("topleft", object, "topleft", 0, 0)
Expand Down
64 changes: 37 additions & 27 deletions Libs/DF/fw.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


local dversion = 571
local dversion = 572
local major, minor = "DetailsFramework-1.0", dversion
local DF, oldminor = LibStub:NewLibrary(major, minor)

Expand Down Expand Up @@ -40,6 +40,7 @@ local SPELLBOOK_BANK_PET = Enum.SpellBookSpellBank and Enum.SpellBookSpellBank.P
local IsPassiveSpell = IsPassiveSpell or C_Spell.IsSpellPassive
local GetOverrideSpell = C_SpellBook and C_SpellBook.GetOverrideSpell or C_Spell.GetOverrideSpell or GetOverrideSpell
local HasPetSpells = HasPetSpells or C_SpellBook.HasPetSpells
local spellBookPetEnum = Enum.SpellBookSpellBank and Enum.SpellBookSpellBank.Pet or "pet"

SMALL_NUMBER = 0.000001
ALPHA_BLEND_AMOUNT = 0.8400251
Expand Down Expand Up @@ -929,8 +930,11 @@ end
function DF.table.deploy(t1, t2)
for key, value in pairs(t2) do
if (type(value) == "table") then
t1[key] = t1[key] or {}
DF.table.deploy(t1[key], t2[key])
--check the t1 type as sometimes the key isn't the same type on both tables
if (t1[key] == nil or type(t1[key]) == "table") then
t1[key] = t1[key] or {}
DF.table.deploy(t1[key], t2[key])
end
elseif (t1[key] == nil) then
t1[key] = value
end
Expand Down Expand Up @@ -1865,7 +1869,7 @@ function DF:GetAvailableSpells()
local completeListOfSpells = {}

--this line might not be compatible with classic
--local specId, specName, _, specIconTexture = GetSpecializationInfo(GetSpecialization())
local specId, specName, _, specIconTexture = GetSpecializationInfo(GetSpecialization())
--local classNameLoc, className, classId = UnitClass("player") --not in use
local locPlayerRace, playerRace, playerRaceId = UnitRace("player")

Expand Down Expand Up @@ -1904,44 +1908,50 @@ function DF:GetAvailableSpells()
end
end

local spellBookPlayerEnum = Enum.SpellBookSpellBank and Enum.SpellBookSpellBank.Player or "player"

--get spells from the Spec spellbook
local amountOfTabs = GetNumSpellTabs()
for i = 2, amountOfTabs-1 do --starting at index 2 to ignore the general tab
for i = 1, GetNumSpellTabs() do --called "lines" in new v11 api
local tabName, tabTexture, offset, numSpells, isGuild, offSpecId, shouldHide, specID = GetSpellTabInfo(i)
local bIsOffSpec = offSpecId ~= 0
offset = offset + 1
local tabEnd = offset + numSpells
for entryOffset = offset, tabEnd - 1 do
local spellType, spellId = GetSpellBookItemInfo(entryOffset, SPELLBOOK_BANK_PLAYER)
if (spellId) then
if (spellType == "SPELL") then
spellId = GetOverrideSpell(spellId)
local spellName = GetSpellInfo(spellId)
local bIsPassive = IsPassiveSpell(spellId, SPELLBOOK_BANK_PLAYER)
if (spellName and not bIsPassive) then
completeListOfSpells[spellId] = bIsOffSpec == false
if (tabTexture == specIconTexture) then
offset = offset + 1
local tabEnd = offset + numSpells
--local bIsOffSpec = offSpecId ~= 0
for entryOffset = offset, tabEnd - 1 do
local spellType, spellId = GetSpellBookItemInfo(entryOffset, spellBookPlayerEnum)
if (spellId) then
if (spellType == "SPELL" or spellType == 1) then
spellId = GetOverrideSpell(spellId)
local spellName = GetSpellInfo(spellId)
local bIsPassive = IsPassiveSpell(entryOffset, spellBookPlayerEnum)
if (spellName and not bIsPassive) then
completeListOfSpells[spellId] = true --bIsOffSpec == false
end
end
end
end
end
end

local CONST_SPELLBOOK_CLASSSPELLS_TABID = 2
local CONST_SPELLBOOK_GENERAL_TABID = 1

--get class shared spells from the spell book
--[=[
local tabName, tabTexture, offset, numSpells, isGuild, offSpecId = GetSpellTabInfo(2)
local bIsOffSpec = offSpecId ~= 0
--[=
local tabName, tabTexture, offset, numSpells, isGuild, offSpecId = GetSpellTabInfo(CONST_SPELLBOOK_CLASSSPELLS_TABID)
offset = offset + 1
local tabEnd = offset + numSpells
--local bIsOffSpec = offSpecId ~= 0
for entryOffset = offset, tabEnd - 1 do
local spellType, spellId = GetSpellBookItemInfo(entryOffset, "player")
local spellType, spellId = GetSpellBookItemInfo(entryOffset, spellBookPlayerEnum)
if (spellId) then
if (spellType == "SPELL") then
if (spellType == "SPELL" or spellType == 1) then
spellId = GetOverrideSpell(spellId)
local spellName = GetSpellInfo(spellId)
local bIsPassive = IsPassiveSpell(spellId, "player")
local bIsPassive = IsPassiveSpell(spellId, spellBookPlayerEnum)

if (spellName and not bIsPassive) then
completeListOfSpells[spellId] = bIsOffSpec == false
completeListOfSpells[spellId] = true --bIsOffSpec == false
end
end
end
Expand All @@ -1957,10 +1967,10 @@ function DF:GetAvailableSpells()
local numPetSpells = getNumPetSpells()
if (numPetSpells) then
for i = 1, numPetSpells do
local spellName, _, unmaskedSpellId = GetSpellBookItemName(i, SPELLBOOK_BANK_PET)
local spellName, _, unmaskedSpellId = GetSpellBookItemName(i, spellBookPetEnum)
if (unmaskedSpellId) then
unmaskedSpellId = GetOverrideSpell(unmaskedSpellId)
local bIsPassive = IsPassiveSpell(unmaskedSpellId, SPELLBOOK_BANK_PET)
local bIsPassive = IsPassiveSpell(i, spellBookPetEnum)
if (spellName and not bIsPassive) then
completeListOfSpells[unmaskedSpellId] = true
end
Expand Down
1 change: 1 addition & 0 deletions Libs/DF/keybind.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,7 @@ detailsFramework.KeybindMixin = {
if (self.options.show_spells) then
--the a list of all spells
local allPlayerSpells = detailsFramework:GetAvailableSpells()

--bIsAvailable is a boolean that tells if the spell is from the spec the player is currently using (spells grayed out on the spellbook would be false here)
for spellId, bIsAvailable in pairs(allPlayerSpells) do
local spellName, _, spellIcon = GetSpellInfo(spellId)
Expand Down
19 changes: 19 additions & 0 deletions Libs/DF/panel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1986,6 +1986,25 @@ end

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

local on_drag_start = function(self)
if (not self.bIsDragging) then
self.bIsDragging = true
self:StartMoving()
end
end

local on_drag_stop = function(self)
self.bIsDragging = false
self:StopMovingOrSizing()
end

function detailsFramework:MakeDraggable(frame)
frame:SetMovable(true)
frame:EnableMouse(true)
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart", on_drag_start)
frame:SetScript("OnDragStop", on_drag_stop)
end

local simple_panel_mouse_down = function(self, button)
if (button == "RightButton") then
Expand Down
79 changes: 52 additions & 27 deletions Libs/DF/tabcontainer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ local PixelUtil = PixelUtil
---@field AllFramesByName table<string, df_tabcontainerframe>
---@field AllButtonsByName table<string, df_tabcontainerbutton>
---@field hookList table
---@field options df_tabcontaineroptions
---@field CurrentIndex number
---@field IsContainer boolean
---@field ButtonSelectedBorderColor table
---@field ButtonNotSelectedBorderColor table
---@field CanCloseWithRightClick boolean
---@field CallOnEachTab fun(self: df_tabcontainer, callback: function, ...)
---@field SetIndex fun(self: df_tabcontainer, index: number)
---@field SelectTabByIndex fun(self: df_tabcontainer, menuIndex: number)
---@field SelectTabByName fun(self: df_tabcontainer, name: string)
Expand Down Expand Up @@ -54,6 +56,12 @@ local tabTemplate = detailsFramework.table.copy({}, detailsFramework:GetTemplate
tabTemplate.backdropbordercolor = nil

detailsFramework.TabContainerMixin = {
CallOnEachTab = function(self, callback, ...)
for _, tabFrame in ipairs(self.AllFrames) do
detailsFramework:Dispatch(callback, tabFrame, ...)
end
end,

---@param self df_tabcontainer
---@param tabIndex number
---@return df_tabcontainerframe
Expand Down Expand Up @@ -125,6 +133,10 @@ detailsFramework.TabContainerMixin = {
---@type df_tabcontainerframe
local tabFrame = tabContainer.AllFrames[menuIndex]

if (not tabFrame) then
return
end

--hide all tab frame and hide the selection glow from tab buttons
for i = 1, #tabContainer.AllFrames do
---@type df_tabcontainerframe
Expand Down Expand Up @@ -191,31 +203,33 @@ detailsFramework.TabContainerFrameMixin = {
---@param self df_tabcontainerframe
---@param button string
OnMouseDown = function(self, button)
--search for UIParent
---@type frame
local highestParent = detailsFramework:FindHighestParent(self)
local tabContainer = self:GetParent()
---@cast tabContainer df_tabcontainer

if (button == "LeftButton") then
if (not highestParent.IsMoving and highestParent:IsMovable()) then
highestParent:StartMoving()
highestParent.IsMoving = true
end
if (self:GetParent().options.can_move_parent) then
--search for UIParent
---@type frame
local highestParent = detailsFramework:FindHighestParent(self)
local tabContainer = self:GetParent()
---@cast tabContainer df_tabcontainer

if (button == "LeftButton") then
if (not highestParent.IsMoving and highestParent:IsMovable()) then
highestParent:StartMoving()
highestParent.IsMoving = true
end

elseif (button == "RightButton") then
if (not highestParent.IsMoving and tabContainer.IsContainer) then
if (self.bIsFrontPage) then
if (tabContainer.CanCloseWithRightClick) then
if (highestParent["CloseFunction"]) then
highestParent["CloseFunction"](highestParent)
else
highestParent:Hide()
elseif (button == "RightButton") then
if (not highestParent.IsMoving and tabContainer.IsContainer) then
if (self.bIsFrontPage) then
if (tabContainer.CanCloseWithRightClick) then
if (highestParent["CloseFunction"]) then
highestParent["CloseFunction"](highestParent)
else
highestParent:Hide()
end
end
else
--goes back to front page
tabContainer:SelectTabByIndex(1)
end
else
--goes back to front page
tabContainer:SelectTabByIndex(1)
end
end
end
Expand All @@ -224,10 +238,12 @@ detailsFramework.TabContainerFrameMixin = {
---@param self df_tabcontainerframe
---@param button string
OnMouseUp = function(self, button)
local frame = detailsFramework:FindHighestParent(self)
if (frame.IsMoving) then
frame:StopMovingOrSizing()
frame.IsMoving = false
if (self:GetParent().options.can_move_parent) then
local frame = detailsFramework:FindHighestParent(self)
if (frame.IsMoving) then
frame:StopMovingOrSizing()
frame.IsMoving = false
end
end
end,
}
Expand All @@ -249,6 +265,7 @@ detailsFramework.TabContainerFrameMixin = {
---@field button_y number?
---@field button_text_size number?
---@field container_width_offset number?
---@field can_move_parent boolean?

---creates a frame called tabContainer which is used as base for the tab container object
---the function receives a table called tabList which contains sub tables with two keys 'name' and 'text', name is the frame name and text is the text displayed on the button
Expand All @@ -274,13 +291,18 @@ function detailsFramework:CreateTabContainer(parent, title, frameName, tabList,
local buttonTextSize = optionsTable.button_text_size or 10
local containerWidthOffset = optionsTable.container_width_offset or 0

if (optionsTable.can_move_parent == nil) then
optionsTable.can_move_parent = true
end

local bFirstTabIsCreateOnDemand = false

--create the base frame
---@type df_tabcontainer
local tabContainer = CreateFrame("frame", frameName, parent["widget"] or parent, "BackdropTemplate")
tabContainer.hookList = hookList or {}
tabContainer:SetSize(optionsTable.width or 750, optionsTable.height or 450)
tabContainer.options = optionsTable

detailsFramework:Mixin(tabContainer, detailsFramework.TabContainerMixin)

Expand Down Expand Up @@ -396,7 +418,10 @@ function detailsFramework:CreateTabContainer(parent, title, frameName, tabList,
local allocatedSpaceForButtons = parentFrameWidth - ((#tabList - 2) * spaceBetweenButtons) - buttonAnchorX + containerWidthOffset
local amountButtonsPerRow = math.floor(allocatedSpaceForButtons / buttonWidth)

tabContainer.AllButtons[1]:SetPoint("topleft", mainTitle, "topleft", x, y)
if (tabContainer.AllButtons[1]) then
tabContainer.AllButtons[1]:SetPoint("topleft", mainTitle, "topleft", x, y)
end

x = x + buttonWidth + 2

for i = 2, #tabContainer.AllButtons do
Expand Down
Loading

0 comments on commit f94c1f5

Please sign in to comment.