Skip to content

Commit

Permalink
Framework Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Tercioo committed Mar 14, 2024
1 parent c382b77 commit 6924231
Show file tree
Hide file tree
Showing 22 changed files with 2,660 additions and 698 deletions.
5 changes: 3 additions & 2 deletions libs/DF/buildmenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ local _
---@field desc string
---@field descPhraseId string
---@field hooks table
---@field include_default boolean

---@class df_menu_toggle : df_menu_table
---@field set function
Expand Down Expand Up @@ -962,7 +963,7 @@ function detailsFramework:BuildMenuVolatile(parent, menuOptions, xOffset, yOffse

do
if (widgetTable.type == "selectfont") then
local func = detailsFramework:CreateFontListGenerator(widgetTable.set)
local func = detailsFramework:CreateFontListGenerator(widgetTable.set, widgetTable.include_default)
dropdown:SetFunction(func)

elseif (widgetTable.type == "selectcolor") then
Expand Down Expand Up @@ -1202,7 +1203,7 @@ function detailsFramework:BuildMenu(parent, menuOptions, xOffset, yOffset, heigh
local dropdown
do
if (widgetTable.type == "selectfont") then
dropdown = detailsFramework:CreateFontDropDown(parent, widgetTable.set, widgetTable.get(), widgetWidth or 140, widgetHeight or defaultHeight, nil, "$parentWidget" .. index, dropdownTemplate)
dropdown = detailsFramework:CreateFontDropDown(parent, widgetTable.set, widgetTable.get(), widgetWidth or 140, widgetHeight or defaultHeight, nil, "$parentWidget" .. index, dropdownTemplate, widgetTable.include_default)

elseif (widgetTable.type == "selectcolor") then
dropdown = detailsFramework:CreateColorDropDown(parent, widgetTable.set, widgetTable.get(), widgetWidth or 140, widgetHeight or defaultHeight, nil, "$parentWidget" .. index, dropdownTemplate)
Expand Down
109 changes: 70 additions & 39 deletions libs/DF/button.lua
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ detailsFramework:Mixin(ButtonMetaFunctions, detailsFramework.ScriptHookMixin)
end
end

local noColor = {1, 1, 1, 1}

---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 texture any
Expand All @@ -403,6 +405,16 @@ detailsFramework:Mixin(ButtonMetaFunctions, detailsFramework.ScriptHookMixin)
self.widget.text:SetPoint("left", self.icon, "right", textDistance or 2, 0 + (textHeight or 0))
end

overlay = overlay or noColor
local red, green, blue, alpha = detailsFramework:ParseColors(overlay or noColor)

local left, right, top, bottom = texcoord and texcoord[1], texcoord and texcoord[2], texcoord and texcoord[3], texcoord and texcoord[4]
texture, width, height, left, right, top, bottom, red, green, blue, alpha = detailsFramework:ParseTexture(texture, width, height, left, right, top, bottom, red, green, blue, alpha)

if (red == nil) then
red, green, blue, alpha = 1, 1, 1, 1
end

if (type(texture) == "string") then
local isAtlas = C_Texture.GetAtlasInfo(texture)
if (isAtlas) then
Expand All @@ -414,33 +426,17 @@ detailsFramework:Mixin(ButtonMetaFunctions, detailsFramework.ScriptHookMixin)
else
self.icon:SetTexture(texture)
end

elseif (type(texture) == "table") then
local r, g, b, a = detailsFramework:ParseColors(texture)
self.icon:SetColorTexture(r, g, b, a)
else
self.icon:SetTexture(texture)
end

self.icon:SetSize(width or self.height * 0.8, height or self.height * 0.8)

self.icon:SetDrawLayer(layout or "artwork")

if (texcoord) then
self.icon:SetTexCoord(unpack(texcoord))
else
self.icon:SetTexCoord(0, 1, 0, 1)
end
self.icon:SetTexCoord(left, right, top, bottom)

if (overlay) then
if (type(overlay) == "string") then
local r, g, b, a = detailsFramework:ParseColors(overlay)
self.icon:SetVertexColor(r, g, b, a)
else
self.icon:SetVertexColor(unpack(overlay))
end
else
self.icon:SetVertexColor(1, 1, 1, 1)
end
self.icon:SetVertexColor(red, green, blue, alpha)

local buttonWidth = self.button:GetWidth()
local iconWidth = self.icon:GetWidth()
Expand Down Expand Up @@ -481,12 +477,16 @@ detailsFramework:Mixin(ButtonMetaFunctions, detailsFramework.ScriptHookMixin)
---enable the button making it clickable and not grayed out
---@return unknown
function ButtonMetaFunctions:Enable()

return self.button:Enable()
end

---disable the button making it unclickable and grayed out
---@return unknown
function ButtonMetaFunctions:Disable()
if (self.color_texture) then
self.color_texture:SetVertexColor(0.14, 0.14, 0.14)
end
return self.button:Disable()
end

Expand Down Expand Up @@ -733,11 +733,9 @@ detailsFramework:Mixin(ButtonMetaFunctions, detailsFramework.ScriptHookMixin)
---receives a table where the keys are settings and the values are the values to set
---this is the list of keys the table support:
---width, height, icon|table, textcolor, textsize, textfont, textalign, backdrop, backdropcolor, backdropbordercolor, onentercolor, onleavecolor, onenterbordercolor, onleavebordercolor
---@param template table
---@param template table|string
function ButtonMetaFunctions:SetTemplate(template)
if (type(template) == "string") then
template = detailsFramework:GetTemplate("button", template)
end
template = detailsFramework:ParseTemplate(self.type, template)

if (not template) then
detailsFramework:Error("template not found")
Expand Down Expand Up @@ -808,6 +806,25 @@ function ButtonMetaFunctions:SetTemplate(template)
if (template.textalign) then
self.textalign = template.textalign
end

if (template.rounded_corner) then
self:SetBackdrop(nil)
detailsFramework:AddRoundedCornersToFrame(self.widget or self, template.rounded_corner)

--check if this is a color picker button
if (self.__iscolorpicker) then
self.color_texture:SetTexture([[Interface\CHARACTERFRAME\TempPortraitAlphaMaskSmall]], "CLAMP", "CLAMP", "TRILINEAR")
self.color_texture:SetDrawLayer("overlay", 7)
self.color_texture:SetPoint("topleft", self.widget, "topleft", 2, -2)
self.color_texture:SetPoint("bottomright", self.widget, "bottomright", -2, 2)

self.background_texture:SetDrawLayer("overlay", 6)
self.background_texture:SetPoint("topleft", self.color_texture, "topleft", 2, -2)
self.background_texture:SetPoint("bottomright", self.color_texture, "bottomright", -2, 2)

self.widget.texture_disabled:SetTexture([[Interface\CHARACTERFRAME\TempPortraitAlphaMaskSmall]], "CLAMP", "CLAMP", "TRILINEAR")
end
end
end

------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -840,7 +857,7 @@ end
self:SetScript("OnEnable", onEnableFunc)
end

---@class df_button : button, df_scripthookmixin
---@class df_button : button, df_scripthookmixin, df_widgets
---@field widget button
---@field tooltip string
---@field shown boolean
Expand All @@ -857,7 +874,7 @@ end
---@field textfont string
---@field textsize number
---@field icon texture created after calling SetIcon()
---@field SetTemplate fun(self: df_button, template: table) set the button visual by a template
---@field SetTemplate fun(self: df_button, template: table|string) set the button visual by a template
---@field RightClick fun(self: df_button) right click the button executing its right click function
---@field Exec fun(self: df_button) execute the button function for the left button
---@field Disable fun(self: df_button) disable the button
Expand All @@ -873,8 +890,8 @@ end
---@field SetClickFunction fun(self: df_button, func: function, param1: any, param2: any, clickType: "left"|"right"|nil)

---create a Details Framework button
---@param parent table
---@param func function
---@param parent frame
---@param callback function
---@param width number
---@param height number
---@param text any
Expand All @@ -887,8 +904,8 @@ end
---@param buttonTemplate table|nil
---@param textTemplate table|nil
---@return df_button
function detailsFramework:CreateButton(parent, func, width, height, text, param1, param2, texture, member, name, shortMethod, buttonTemplate, textTemplate)
return detailsFramework:NewButton(parent, parent, name, member, width, height, func, param1, param2, texture, text, shortMethod, buttonTemplate, textTemplate)
function detailsFramework:CreateButton(parent, callback, width, height, text, param1, param2, texture, member, name, shortMethod, buttonTemplate, textTemplate)
return detailsFramework:NewButton(parent, parent, name, member, width, height, callback, param1, param2, texture, text, shortMethod, buttonTemplate, textTemplate)
end

---@return df_button
Expand Down Expand Up @@ -1064,6 +1081,15 @@ end
return self.color_texture:GetVertexColor()
end

---@class df_colorpickbutton : df_button
---@field color_callback function
---@field Cancel function
---@field SetColor function
---@field GetColor function
---@field __iscolorpicker boolean
---@field color_texture texture
---@field background_texture texture

---create a button which opens a color picker when clicked
---@param parent table
---@param name string|nil
Expand All @@ -1077,33 +1103,38 @@ end
end

function detailsFramework:NewColorPickButton(parent, name, member, callback, alpha, buttonTemplate)
--button
local colorPickButton = detailsFramework:NewButton(parent, _, name, member, 16, 16, pickcolor, alpha, "param2", nil, nil, nil, buttonTemplate)
local colorPickButton = detailsFramework:NewButton(parent, _, name, member, 16, 16, pickcolor, alpha, "param2")
---@cast colorPickButton df_colorpickbutton

colorPickButton.color_callback = callback
colorPickButton.Cancel = colorpickCancel
colorPickButton.SetColor = setColorPickColor
colorPickButton.GetColor = getColorPickColor
colorPickButton.__iscolorpicker = true

colorPickButton.HookList.OnColorChanged = {}

if (not buttonTemplate) then
colorPickButton:SetTemplate(detailsFramework:GetTemplate("button", "OPTIONS_BUTTON_TEMPLATE"))
end

--background showing a grid to indicate the transparency
local background = colorPickButton:CreateTexture(nil, "background", nil, 2)
local background = colorPickButton:CreateTexture("$parentBackgroupTransparency", "background", nil, 2)
background:SetPoint("topleft", colorPickButton.widget, "topleft", 0, 0)
background:SetPoint("bottomright", colorPickButton.widget, "bottomright", 0, 0)
background:SetTexture([[Interface\ITEMSOCKETINGFRAME\UI-EMPTYSOCKET]])
background:SetTexCoord(3/16, 13/16, 3/16, 13/16)
background:SetAtlas("AnimCreate_Icon_Texture")
background:SetAlpha(0.3)
colorPickButton.background_texture = background

--texture which shows the texture color
local colorTexture = detailsFramework:NewImage(colorPickButton, nil, 16, 16, nil, nil, "color_texture", "$parentTex")
local colorTexture = colorPickButton:CreateTexture("$parentTex", "overlay")
colorTexture:SetColorTexture(1, 1, 1)
colorTexture:SetPoint("topleft", colorPickButton.widget, "topleft", 0, 0)
colorTexture:SetPoint("bottomright", colorPickButton.widget, "bottomright", 0, 0)
colorTexture:SetDrawLayer("background", 3)
colorPickButton.color_texture = colorTexture

if (not buttonTemplate) then
colorPickButton:SetTemplate(detailsFramework:GetTemplate("button", "OPTIONS_BUTTON_TEMPLATE"))
else
colorPickButton:SetTemplate(buttonTemplate)
end

return colorPickButton
end
Expand Down
Loading

0 comments on commit 6924231

Please sign in to comment.