Skip to content

Commit

Permalink
Framework update, preparing to release
Browse files Browse the repository at this point in the history
  • Loading branch information
Tercioo committed Apr 24, 2024
1 parent 3d226db commit 58644cd
Show file tree
Hide file tree
Showing 17 changed files with 358 additions and 56 deletions.
28 changes: 17 additions & 11 deletions Libs/DF/auras.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ local detailsFramework = DF

local _
local tinsert = table.insert
local GetSpellInfo = GetSpellInfo
local GetSpellInfo = GetSpellInfo or function(spellID) if not spellID then return nil end local si = C_Spell.GetSpellInfo(spellID) if si then return si.name, nil, si.iconID, si.castTime, si.minRange, si.maxRange, si.spellID, si.originalIconID end end
local lower = string.lower
local GetSpellBookItemInfo = GetSpellBookItemInfo
local SpellBookItemTypeMap = Enum.SpellBookItemType and {[Enum.SpellBookItemType.Spell] = "SPELL", [Enum.SpellBookItemType.None] = "NONE", [Enum.SpellBookItemType.Flyout] = "FLYOUT", [Enum.SpellBookItemType.FutureSpell] = "FUTURESPELL", [Enum.SpellBookItemType.PetAction] = "PETACTION" } or {}
local GetSpellBookItemInfo = GetSpellBookItemInfo or function(...) local si = C_SpellBook.GetSpellBookItemInfo(...) if si then return SpellBookItemTypeMap[si.itemType] or "NONE", si.spellID end end
local SPELLBOOK_BANK_PLAYER = Enum.SpellBookSpellBank and Enum.SpellBookSpellBank.Player or "player"
local GetNumSpellTabs = GetNumSpellTabs or C_SpellBook.GetNumSpellBookSkillLines
local GetSpellTabInfo = GetSpellTabInfo or function(tabLine) local skillLine = C_SpellBook.GetSpellBookSkillLineInfo(tabLine) if skillLine then return skillLine.name, skillLine.iconID, skillLine.itemIndexOffset, skillLine.numSpellBookItems, skillLine.isGuild, skillLine.offSpecID end end
local unpack = unpack
local CreateFrame = CreateFrame
local GameTooltip = GameTooltip
Expand Down Expand Up @@ -1042,15 +1046,17 @@ end

function DF:GetAllPlayerSpells(include_lower_case)
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)
if (include_lower_case) then
tinsert(playerSpells, lower(spellName))
for i = 1, GetNumSpellTabs() do
local _, _, offset, numSpells = GetSpellTabInfo(i)
for i = 1, numSpells do
local index = offset + i
local spellType, spellId = GetSpellBookItemInfo(index, SPELLBOOK_BANK_PLAYER)
if (spellType == "SPELL") then
local spellName = GetSpellInfo(spellId)
tinsert(playerSpells, spellName)
if (include_lower_case) then
tinsert(playerSpells, lower(spellName))
end
end
end
end
Expand Down
13 changes: 12 additions & 1 deletion Libs/DF/buildmenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ local onWidgetSetInUse = function(widget, widgetTable)
widget.childrenids = widgetTable.childrenids
end
widget.children_follow_enabled = widgetTable.children_follow_enabled

if (widgetTable.disabled) then
widget:Disable()
else
if (not widget:IsEnabled()) then
widget:Enable()
end
end
end

local setWidgetId = function(parent, widgetTable, widgetObject)
Expand Down Expand Up @@ -367,15 +375,18 @@ local setRangeProperties = function(parent, widget, widgetTable, currentXOffset,

widget.bAttachButtonsToLeft = bAttachSliderButtonsToLeft

local currentValue = widgetTable.get()

if (bIsDecimals) then
widget.slider:SetValueStep(0.01)
else
widget.slider:SetValueStep(widgetTable.step or 1)
currentValue = math.floor(currentValue)
end
widget.useDecimals = bIsDecimals

widget.slider:SetMinMaxValues(widgetTable.min, widgetTable.max)
widget.slider:SetValue(widgetTable.get() or 0)
widget.slider:SetValue(currentValue or 0)
widget.ivalue = widget.slider:GetValue()

if (widgetWidth) then
Expand Down
18 changes: 14 additions & 4 deletions Libs/DF/button.lua
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ detailsFramework:Mixin(ButtonMetaFunctions, detailsFramework.ScriptHookMixin)

---add an icon to the left of the button text
---short method truncates the text: false = do nothing, nil = increate the button width, 1 = decrease the font size, 2 = truncate the text
---@param self table
---@param texture any
---@param width number|nil
---@param height number|nil
Expand All @@ -395,7 +396,8 @@ detailsFramework:Mixin(ButtonMetaFunctions, detailsFramework.ScriptHookMixin)
---@param leftPadding number|nil
---@param textHeight number|nil
---@param shortMethod any
function ButtonMetaFunctions:SetIcon(texture, width, height, layout, texcoord, overlay, textDistance, leftPadding, textHeight, shortMethod)
---@param filterMode any
function ButtonMetaFunctions:SetIcon(texture, width, height, layout, texcoord, overlay, textDistance, leftPadding, textHeight, shortMethod, filterMode)
if (not self.icon) then
self.icon = self:CreateTexture(nil, "artwork")
self.icon:SetSize(self.height * 0.8, self.height * 0.8)
Expand Down Expand Up @@ -424,10 +426,10 @@ detailsFramework:Mixin(ButtonMetaFunctions, detailsFramework.ScriptHookMixin)
local r, g, b, a = detailsFramework:ParseColors(texture)
self.icon:SetColorTexture(r, g, b, a)
else
self.icon:SetTexture(texture)
self.icon:SetTexture(texture, nil, nil, filterMode)
end
else
self.icon:SetTexture(texture)
self.icon:SetTexture(texture, nil, nil, filterMode)
end

self.icon:SetSize(width or self.height * 0.8, height or self.height * 0.8)
Expand Down Expand Up @@ -468,6 +470,13 @@ detailsFramework:Mixin(ButtonMetaFunctions, detailsFramework.ScriptHookMixin)
end
end

---@param self df_button
function ButtonMetaFunctions:SetIconFilterMode(filterMode)
if (self.icon) then
self.icon:SetTexture(self.icon:GetTexture(), nil, nil, filterMode)
end
end

---query if the button is enabled or not
---@return boolean
function ButtonMetaFunctions:IsEnabled()
Expand Down Expand Up @@ -888,6 +897,7 @@ end
---@field SetTextColor fun(self: df_button, color: any) set the button text color
---@field SetText fun(self: df_button, text: string) set the button text
---@field SetClickFunction fun(self: df_button, func: function, param1: any, param2: any, clickType: "left"|"right"|nil)
---@field SetIconFilterMode fun(self: df_button, filterMode: any) set the filter mode for the icon, execute after SetIcon()

---create a Details Framework button
---@param parent frame
Expand Down Expand Up @@ -1097,7 +1107,7 @@ end
---@param callback function
---@param alpha number|nil
---@param buttonTemplate table|nil
---@return table|nil
---@return df_colorpickbutton
function detailsFramework:CreateColorPickButton(parent, name, member, callback, alpha, buttonTemplate)
return detailsFramework:NewColorPickButton(parent, name, member, callback, alpha, buttonTemplate)
end
Expand Down
6 changes: 5 additions & 1 deletion Libs/DF/cooltip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ local wipe = table.wipe
local insert = table.insert
local max = math.max

local GetSpellInfo = GetSpellInfo or function(spellID) if not spellID then return nil end local si = C_Spell.GetSpellInfo(spellID) if si then return si.name, nil, si.iconID, si.castTime, si.minRange, si.maxRange, si.spellID, si.originalIconID end end
local SPELLBOOK_BANK_PLAYER = Enum.SpellBookSpellBank and Enum.SpellBookSpellBank.Player or "player"
local IsPassiveSpell = IsPassiveSpell or C_Spell.IsSpellPassive

--api locals
local PixelUtil = PixelUtil or DFPixelUtil
local version = 24
Expand Down Expand Up @@ -1945,7 +1949,7 @@ function DF:CreateCoolTip()
local spellDescription = GetSpellDescription(spellId)
local cooldownTime, globalCooldown = GetSpellBaseCooldown(spellId)
--local cooldown = cooldownTime / 1000
local bIsPassive = IsPassiveSpell(spellId, "player")
local bIsPassive = IsPassiveSpell(spellId, SPELLBOOK_BANK_PLAYER)
local chargesAvailable, maxCharges, chargeCooldownStart, rechargeTime, chargeModRate = GetSpellCharges(spellId)

local tResourceCost = GetSpellPowerCost(spellId)
Expand Down
11 changes: 7 additions & 4 deletions Libs/DF/definitions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
---@field CreateTextureInfo fun(self:table, texture:atlasname|texturepath|textureid, width:number?, height:number?, left:number?, right:number?, top:number?, bottom:number?, imageWidthnumber?, imageHeightnumber?) : table deprecated, use: DetailsFramework:CreateAtlas()
---@field ApplyStandardBackdrop fun(self:table, frame:frame, bUseSolidColor:boolean?, alphaScale:number?)
---@field NewLabel fun(self:table, parent:frame, container:frame, name:string?, member:string?, text:string|table, font:string?, size:any?, color:any?, layer:drawlayer?) : df_label
---@field CreateLabel fun(self:table, parent:frame, text:string, size:any?, color:any?, font:string?, member:string?, name:string?, layer:drawlayer?) : df_label
---@field CreateLabel fun(self:table, parent:frame, text:any, size:any?, 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 CreateFontDropDown fun(self:table, parent:frame, func:function, default:any, width:number?, height:number?, member:string?, name:string?, template:table?) : df_dropdown
---@field CreateColorDropDown fun(self:table, parent:frame, func:function, default:any, width:number?, height:number?, member:string?, name:string?, template:table?) : df_dropdown
Expand All @@ -248,7 +248,7 @@
---@field CreateCheckboxGroup fun(self:table, parent:frame, radioOptions:df_radiooptions[], name:string?, options:table?, anchorOptions:table?) : df_checkboxgroup
---@field CreateRadioGroup fun(self:table, parent:frame, radioOptions:df_radiooptions[], name:string?, options:table?, anchorOptions:table?) : df_radiogroup
---@field CreateScrollBox fun(self:table, parent:frame, name:string, refreshFunc:function, data:table, width:number, height:number, lineAmount:number, lineHeight:number, createLineFunc:function?, autoAmount:boolean?, noScroll:boolean?, noBackdrop:boolean?) : df_scrollbox
---@field CreateAuraScrollBox fun(self:table, parent:frame, name:string?, data:table?, onRemoveCallback:function?, options:table?) : df_aurascrollbox
---@field CreateAuraScrollBox fun(self:table, parent:frame, name:string?, data:table?, onRemoveCallback:function?, options:table?, onSetupAuraClick:function?) : df_aurascrollbox
---@field CreateGridScrollBox fun(self:table, parent:frame, name:string?, refreshFunc:function, data:table?, createColumnFrameFunc:function, options:table?) : df_gridscrollbox
---@field CreateCanvasScrollBox fun(self:table, parent:frame, child:frame?, name:string?, options:table?) : df_canvasscrollbox
---@field CreateTabContainer fun(self:table, parent:frame, title:string, frameName:string, tabList:df_tabinfotable[], optionsTable:table?, hookList:table?, languageInfo:table?) : df_tabcontainer
Expand All @@ -264,7 +264,7 @@
---@field RandomBool fun(self:table, odds: number?) : boolean return a random boolean
---@field CreateHighlightTexture fun(self:table, parent:frame, parentKey:string?, alpha:number?, name:string?) : texture
---@field CreateIconRowGeneric fun(self:table, parent:frame, name:string?, options:table?)
---@field CreateColorPickButton fun(self:table, parent:frame, name:string?, member:string?, callback:function, alpha:number?, buttonTemplate:table?) : df_button
---@field CreateColorPickButton fun(self:table, parent:frame, name:string?, member:string?, callback:function, alpha:number?, buttonTemplate:table?) : df_colorpickbutton
---@field CreateSlider fun(self:table, parent:frame, width:number?, height:number?, minValue:number?, maxValue:number?, step:number?, defaultv:number?, isDecemal:boolean?, member:string?, name:string?, label:string?, sliderTemplate:string|table?, labelTemplate:string|table?) : df_slider, df_label?
---@field CreateFrameContainer fun(self:table, parent:frame, options:table?, frameName:string?) : df_framecontainer create a frame container, which is a frame that envelops another frame, and can be moved, resized, etc.
---@field CreateAnimation fun(self:table, animationGroup:animationgroup, animationType:animationtype, order:number, duration:number, arg1:any, arg2:any, arg3:any, arg4:any, arg5:any, arg6:any, arg7:any, arg8:any) : animation
Expand Down Expand Up @@ -307,15 +307,18 @@
---@field GetParentKeyPath fun(self:table, object:uiobject) : string
---@field GetParentNamePath fun(self:table, object:uiobject) : string
---@field GetAsianNumberSymbols fun(self:table) : string, string, string return the abbreviation for 1,000 10,000 and 100,000,000
---@field GetBestFontForLanguage fun(self:table, languageId:string?, western:string?, cyrillic:string?, china:string? korean:string?, taiwan:string?) : string
---@field GetBestFontForLanguage fun(self:table, languageId:string?, western:string?, cyrillic:string?, china:string?, korean:string?, taiwan:string?) : string
---@field CreateGlowOverlay fun(self:table, parent:frame, antsColor:any, glowColor:any) : frame
---@field CreateAnts fun(self:table, parent:frame, antTable:df_anttable, leftOffset:number?, rightOffset:number?, topOffset:number?, bottomOffset:number?) : frame
---@field CreateBorder fun(self:table, parent:frame, alpha1:number?, alpha2:number?, alpha3:number?) : frame
---@field CreateMenuWithGridScrollBox fun(self:table, parent:frame, name:string?, refreshMeFunc:function, refreshButtonFunc:function, clickFunc:function, onCreateButton:function, gridScrollBoxOptions:df_gridscrollbox_options) : df_gridscrollbox create a scrollbox with a grid layout to be used as a menu
---@field CreateSearchBox fun(self:table, parent:frame, callback:function) : df_searchbox
---@field
---@field




--[=[
Wrapped objects: when using the following functions, the object will be wrapped in a table, e.g. detailsFramework:CreateButton() will return a table with the button, the button will be accessible through the "button" key.
The wrapper table will have the same metatable as the wrapped object, so you can call methods on the wrapper table as if it was the wrapped object.
Expand Down
87 changes: 78 additions & 9 deletions Libs/DF/editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,55 @@ local _
--which object attributes are used to build the editor menu for each object type
local attributes = {
---@type df_editor_attribute[]
Texture = {
{
key = "texture",
label = "Texture",
widget = "textentry",
default = "",
setter = function(widget, value) widget:SetTexture(value) end,
},
{
key = "width",
label = "Width",
widget = "range",
minvalue = 5,
maxvalue = 120,
setter = function(widget, value) widget:SetWidth(value) end
},
{
key = "height",
label = "Height",
widget = "range",
minvalue = 5,
maxvalue = 120,
setter = function(widget, value) widget:SetHeight(value) end
},
{widget = "blank"},
{
key = "anchor",
label = "Anchor",
widget = "anchordropdown",
setter = function(widget, value) detailsFramework:SetAnchor(widget, value, widget:GetParent()) end
},
{
key = "anchoroffsetx",
label = "Anchor X Offset",
widget = "range",
minvalue = -20,
maxvalue = 20,
setter = function(widget, value) detailsFramework:SetAnchor(widget, value, widget:GetParent()) end
},
{
key = "anchoroffsety",
label = "Anchor Y Offset",
widget = "range",
minvalue = -20,
maxvalue = 20,
setter = function(widget, value) detailsFramework:SetAnchor(widget, value, widget:GetParent()) end
},
},

FontString = {
{
key = "text",
Expand Down Expand Up @@ -147,16 +196,16 @@ local attributes = {
key = "anchoroffsetx",
label = "Anchor X Offset",
widget = "range",
minvalue = -100,
maxvalue = 100,
minvalue = -20,
maxvalue = 20,
setter = function(widget, value) detailsFramework:SetAnchor(widget, value, widget:GetParent()) end
},
{
key = "anchoroffsety",
label = "Anchor Y Offset",
widget = "range",
minvalue = -100,
maxvalue = 100,
minvalue = -20,
maxvalue = 20,
setter = function(widget, value) detailsFramework:SetAnchor(widget, value, widget:GetParent()) end
},
{
Expand Down Expand Up @@ -291,13 +340,15 @@ detailsFramework.EditorMixin = {
local objectRegistered = self:GetObjectById(id)
assert(type(objectRegistered) == "table", "EditObjectById() object not found.")
self:EditObject(objectRegistered)
self.objectSelector:RefreshMe()
end,

EditObjectByIndex = function(self, index)
---@type df_editor_objectinfo
local objectRegistered = self:GetObjectByIndex(index)
assert(type(objectRegistered) == "table", "EditObjectById() object not found.")
self:EditObject(objectRegistered)
self.objectSelector:RefreshMe()
end,

---@param self df_editor
Expand Down Expand Up @@ -389,6 +440,8 @@ detailsFramework.EditorMixin = {
local profileTable, profileMap = self:GetEditingProfile()
profileMap = profileMap or {}

local conditionalKeys = profileMap.enable_if or {}

if (not object or not profileTable) then
return
end
Expand All @@ -405,6 +458,10 @@ detailsFramework.EditorMixin = {
if (objectType == "FontString") then
---@cast object fontstring
attributeList = attributes[objectType]

elseif (objectType == "Texture") then
---@cast object texture
attributeList = attributes[objectType]
end

--if there's extra options, add the attributeList to a new table and right after the extra options
Expand Down Expand Up @@ -445,6 +502,8 @@ detailsFramework.EditorMixin = {
value = profileTable[profileKey]
end

--print(value, profileKey, profileTable, option.key)

--if no value is found, attempt to get a default
if (type(value) == "nil") then
value = option.default
Expand All @@ -456,11 +515,11 @@ detailsFramework.EditorMixin = {
local maxValue = option.maxvalue

if (option.key == "anchoroffsetx") then
minValue = -object:GetParent():GetWidth()/2
maxValue = object:GetParent():GetWidth()/2
minValue = -math.floor(object:GetParent():GetWidth()/10)
maxValue = math.floor(object:GetParent():GetWidth()/10)
elseif (option.key == "anchoroffsety") then
minValue = -object:GetParent():GetHeight()/2
maxValue = object:GetParent():GetHeight()/2
minValue = -math.floor(object:GetParent():GetHeight()/10)
maxValue = math.floor(object:GetParent():GetHeight()/10)
end

if (bHasValue) then
Expand All @@ -470,7 +529,7 @@ detailsFramework.EditorMixin = {
anchorSettings = parentTable
end

menuOptions[#menuOptions+1] = {
local optionTable = {
type = option.widget,
name = option.label,
get = function() return value end,
Expand Down Expand Up @@ -526,6 +585,16 @@ detailsFramework.EditorMixin = {
usedecimals = option.usedecimals,
id = option.key,
}

--disabled = true
if (conditionalKeys[option.key]) then
local bIsEnabled = conditionalKeys[option.key](object, profileTable, profileKey)
if (not bIsEnabled) then
optionTable.disabled = true
end
end

menuOptions[#menuOptions+1] = optionTable
end
end
end
Expand Down
Loading

0 comments on commit 58644cd

Please sign in to comment.