Polishing the segments menu
This commit is contained in:
+27
-16
@@ -17,7 +17,7 @@ local max = math.max
|
||||
|
||||
--api locals
|
||||
local PixelUtil = PixelUtil or DFPixelUtil
|
||||
local version = 21
|
||||
local version = 22
|
||||
|
||||
local CONST_MENU_TYPE_MAINMENU = "main"
|
||||
local CONST_MENU_TYPE_SUBMENU = "sub"
|
||||
@@ -36,6 +36,7 @@ function DF:CreateCoolTip()
|
||||
tile = true, tileSize = 16, insets = {left = 0, right = 0, top = 0, bottom = 0}}
|
||||
local defaultBackdropColor = {0.1215, 0.1176, 0.1294, 0.8000}
|
||||
local defaultBackdropBorderColor = {0.05, 0.05, 0.05, 1}
|
||||
local defaultTexCoord = {0, 1, 0, 1}
|
||||
|
||||
--initialize
|
||||
local gameCooltip = {
|
||||
@@ -1498,6 +1499,9 @@ function DF:CreateCoolTip()
|
||||
wallpaper:SetDesaturated(true)
|
||||
else
|
||||
wallpaper:SetDesaturated(false)
|
||||
if (wallpaperTable[8]) then
|
||||
wallpaper:SetDesaturation(wallpaperTable[8])
|
||||
end
|
||||
end
|
||||
|
||||
wallpaper:Show()
|
||||
@@ -3003,7 +3007,16 @@ function DF:CreateCoolTip()
|
||||
|
||||
frame1.frameWallpaper:Hide()
|
||||
frame2.frameWallpaper:Hide()
|
||||
function gameCooltip:SetWallpaper(menuType, texture, texcoord, color, desaturate)
|
||||
|
||||
---set an image as wallpaper for the cooltip frame
|
||||
---@param menuType any
|
||||
---@param texture any
|
||||
---@param texcoord table
|
||||
---@param color any
|
||||
---@param bDesaturated boolean?
|
||||
---@param desaturation number?
|
||||
---@return nil
|
||||
function gameCooltip:SetWallpaper(menuType, texture, texcoord, color, bDesaturated, desaturation)
|
||||
if (gameCooltip.Indexes == 0) then
|
||||
return gameCooltip:PrintDebug("SetWallpaper() requires an already added line (Cooltip:AddLine()).")
|
||||
end
|
||||
@@ -3026,20 +3039,18 @@ function DF:CreateCoolTip()
|
||||
wallpaperTable = subMenuContainerWallpapers
|
||||
end
|
||||
|
||||
wallpaperTable[1] = texture
|
||||
if (texcoord) then
|
||||
wallpaperTable[2] = texcoord[1]
|
||||
wallpaperTable[3] = texcoord[2]
|
||||
wallpaperTable[4] = texcoord[3]
|
||||
wallpaperTable[5] = texcoord[4]
|
||||
else
|
||||
wallpaperTable[2] = 0
|
||||
wallpaperTable[3] = 1
|
||||
wallpaperTable[4] = 0
|
||||
wallpaperTable[5] = 1
|
||||
end
|
||||
wallpaperTable[6] = color
|
||||
wallpaperTable[7] = desaturate
|
||||
texcoord = texcoord or defaultTexCoord
|
||||
|
||||
--parse the texure
|
||||
local iconTexture, iconWidth, iconHeight, leftCoord, rightCoord, topCoord, bottomCoord, red, green, blue, alpha = detailsFramework:ParseTexture(texture, 1, 1, texcoord[1], texcoord[2], texcoord[3], texcoord[4], color)
|
||||
wallpaperTable[1] = iconTexture
|
||||
wallpaperTable[2] = leftCoord
|
||||
wallpaperTable[3] = rightCoord
|
||||
wallpaperTable[4] = topCoord
|
||||
wallpaperTable[5] = bottomCoord
|
||||
wallpaperTable[6] = {red, green, blue, alpha}
|
||||
wallpaperTable[7] = bDesaturated or false
|
||||
wallpaperTable[8] = desaturation
|
||||
end
|
||||
|
||||
function gameCooltip:SetBannerText(menuType, index, text, anchor, color, fontSize, fontFace, fontFlag)
|
||||
|
||||
@@ -44,6 +44,8 @@
|
||||
---@field colorName string?
|
||||
---@field nativeWidth number?
|
||||
---@field nativeHeight number?
|
||||
---@field desaturated boolean?
|
||||
---@field desaturation number?
|
||||
|
||||
---@alias templatetype
|
||||
---| "font"
|
||||
@@ -186,8 +188,8 @@
|
||||
---@field GetSpellBookSpells fun(self:table) : table<string, boolean>, spellid[] return a list of spells from the player spellbook
|
||||
---@field PreviewTexture fun(self:table, texture:atlasname|texturepath|textureid, left:number?, right:number?, top:number?, bottom:number?) : nil
|
||||
---@field SetAtlas fun(self:table, textureObject:texture, atlas:atlasinfo|atlasname, useAtlasSize:boolean?, filterMode:texturefilter?, resetTexCoords:boolean?) : nil
|
||||
---@field CreateAtlas fun(self:table, file:texturepath|textureid, width:number?, height:number?, leftTexCoord:number?, rightTexCoord:number?, topTexCoord:number?, bottomTexCoord:number?, tilesHorizontally:boolean?, tilesVertically:boolean?, vertexRed:any, vertexGreen:number?, vertexBlue:number?, vertexAlpha:number?) : atlasinfo
|
||||
---@field ParseTexture fun(self:table, texture:texturepath|textureid|atlasname|atlasinfo, width: number?, height: number?, leftTexCoord: number?, rightTexCoord: number?, topTexCoord: number?, bottomTexCoord: number?, vertexRed:number|string?, vertexGreenvertexRed:number?, vertexBluevertexRed:number?, vertexAlphavertexRed:number?) : any, number?, number?, number?, number?, number?, number?, number?, number?, number?, number?, number?
|
||||
---@field CreateAtlas fun(self:table, file:texturepath|textureid, width:number?, height:number?, leftTexCoord:number?, rightTexCoord:number?, topTexCoord:number?, bottomTexCoord:number?, tilesHorizontally:boolean?, tilesVertically:boolean?, vertexRed:any, vertexGreen:number?, vertexBlue:number?, vertexAlpha:number?, desaturated:boolean?, desaturation:number?, alpha:number) : atlasinfo
|
||||
---@field ParseTexture fun(self:table, texture:texturepath|textureid|atlasname|atlasinfo, width: number?, height: number?, leftTexCoord: number?, rightTexCoord: number?, topTexCoord: number?, bottomTexCoord: number?, vertexRed:number|string?, vertexGreenvertexRed:number?, vertexBluevertexRed:number?, vertexAlphavertexRed:number?) : any, number?, number?, number?, number?, number?, number?, number?, number?, number?, number?, number?, number?
|
||||
---@field IsTexture fun(self:table, texture:any, bCheckTextureObject: boolean?) : boolean
|
||||
---@field CreateAtlasString fun(self:table, atlas:atlasinfo|atlasname, textureHeight:number?, textureWidth:number?) : string
|
||||
---@field
|
||||
|
||||
+76
-3
@@ -1,6 +1,6 @@
|
||||
|
||||
|
||||
local dversion = 516
|
||||
local dversion = 517
|
||||
local major, minor = "DetailsFramework-1.0", dversion
|
||||
local DF, oldminor = LibStub:NewLibrary(major, minor)
|
||||
|
||||
@@ -1528,6 +1528,67 @@ function DF:TruncateText(fontString, maxWidth)
|
||||
fontString:SetText(text)
|
||||
end
|
||||
|
||||
---truncate removing text through a binary search with a max of 10 iterations
|
||||
---@param fontString table
|
||||
---@param maxWidth number
|
||||
function DF:TruncateTextSafeBinarySearch(fontString, maxWidth)
|
||||
local text = fontString:GetText()
|
||||
if text == nil or text == '' then return end
|
||||
|
||||
if fontString:GetUnboundedStringWidth() > maxWidth then
|
||||
local left = 1
|
||||
local right = #text
|
||||
local numIterations = 10
|
||||
|
||||
while left <= right and numIterations > 0 do
|
||||
local middle = math.floor((left + right) * 0.5)
|
||||
local substring = strsub(text, 1, middle)
|
||||
fontString:SetText(substring)
|
||||
|
||||
if fontString:GetUnboundedStringWidth() <= maxWidth then
|
||||
left = middle + 1
|
||||
else
|
||||
right = middle - 1
|
||||
end
|
||||
|
||||
numIterations = numIterations - 1
|
||||
end
|
||||
|
||||
text = strsub(text, 1, right)
|
||||
end
|
||||
|
||||
fontString:SetText(DF:CleanTruncateUTF8String(text))
|
||||
end
|
||||
|
||||
---truncate removing characters from the string until the maxWidth is reach
|
||||
---@param fontString table
|
||||
---@param maxWidth number
|
||||
function DF:TruncateTextBinarySearch(fontString, maxWidth)
|
||||
local text = fontString:GetText()
|
||||
if text == nil or text == '' then return end
|
||||
|
||||
if fontString:GetUnboundedStringWidth() > maxWidth then
|
||||
local left = 1
|
||||
local right = #text
|
||||
|
||||
while left <= right do
|
||||
local middle = math.floor((left + right) * 0.5)
|
||||
local substring = strsub(text, 1, middle)
|
||||
fontString:SetText(substring)
|
||||
|
||||
if fontString:GetUnboundedStringWidth() <= maxWidth then
|
||||
left = middle + 1
|
||||
else
|
||||
right = middle - 1
|
||||
end
|
||||
end
|
||||
|
||||
text = strsub(text, 1, right)
|
||||
end
|
||||
|
||||
fontString:SetText(DF:CleanTruncateUTF8String(text))
|
||||
end
|
||||
|
||||
---@param text string
|
||||
---@return string
|
||||
function DF:CleanTruncateUTF8String(text)
|
||||
@@ -2082,8 +2143,8 @@ end
|
||||
---* b (number|nil): The blue component of the color. This is optional if r is a string.
|
||||
---* a (number|nil): The alpha component of the color. This is optional and defaults to 1 if not provided.
|
||||
---* decimalsAmount (number|nil): The number of decimal places to round the color components to. This is optional and defaults to 4 if not provided.
|
||||
---* The function returns the color in the new format. The return type depends on the newFormat parameter. It can be a string, a table, or four separate number values (for the "numbers" format).
|
||||
---* For the "hex" format, it returns a string representing the color in hexadecimal format.
|
||||
---* The function returns the color in the new format. The return type depends on the newFormat parameter. It can be a string, a table, or four separate number values (for the "numbers" format).
|
||||
---* For the "hex" format, it returns a string representing the color in hexadecimal format.
|
||||
---@param newFormat string
|
||||
---@param r number|string
|
||||
---@param g number|nil
|
||||
@@ -5085,16 +5146,28 @@ function _G.__benchmark(bNotPrintResult)
|
||||
end
|
||||
|
||||
function DF:PreviewTexture(texture, left, right, top, bottom)
|
||||
if (texture and type(texture) == "table" and texture.GetObjectType and texture:GetObjectType() == "Texture") then
|
||||
DF:Msg("PreviewTexture: you have passed a texture object (uiobject) instead of the texture atlas, filename or id.")
|
||||
end
|
||||
|
||||
local preview = DetailsFrameworkTexturePreview or CreateFrame("frame", "DetailsFrameworkTexturePreview", UIParent)
|
||||
preview:SetSize(200, 200)
|
||||
preview:SetPoint("center")
|
||||
preview.texture = DetailsFrameworkTexturePreviewTexture or preview:CreateTexture("DetailsFrameworkTexturePreviewTexture", "artwork")
|
||||
preview.texture:SetAllPoints()
|
||||
preview.fontString = DetailsFrameworkTexturePreviewFontString or preview:CreateFontString("DetailsFrameworkTexturePreviewFontString", "artwork", "GameFontNormal")
|
||||
preview.fontString:SetPoint("center", preview, "center", 0, 0)
|
||||
|
||||
preview.texture:SetTexture("")
|
||||
preview.fontString:SetText("")
|
||||
|
||||
--check if the texture passed is an atlas
|
||||
if (type(texture) == "string" and C_Texture.GetAtlasInfo(texture)) then
|
||||
preview.texture:SetAtlas(texture)
|
||||
|
||||
elseif (type(texture) == "string" and texture:find("|T")) then
|
||||
preview.fontString:SetText(texture)
|
||||
|
||||
elseif (type(texture) == "table") then
|
||||
preview.texture:SetTexture(texture.file or texture.filename)
|
||||
preview.texture:SetTexCoord(texture.leftTexCoord, texture.rightTexCoord, texture.topTexCoord, texture.bottomTexCoord)
|
||||
|
||||
+25
-5
@@ -477,6 +477,15 @@ function detailsFramework:SetAtlas(textureObject, atlas, useAtlasSize, filterMod
|
||||
textureObject:SetTexture(atlasInfo.file, atlasInfo.tilesHorizontally and "REPEAT" or "CLAMP", atlasInfo.tilesVertically and "REPEAT" or "CLAMP", filterMode or "LINEAR")
|
||||
textureObject:SetTexCoord(atlasInfo.leftTexCoord or 0, atlasInfo.rightTexCoord or 1, atlasInfo.topTexCoord or 0, atlasInfo.bottomTexCoord or 1)
|
||||
|
||||
if (atlasInfo.desaturated) then
|
||||
textureObject:SetDesaturated(true)
|
||||
else
|
||||
textureObject:SetDesaturated(false)
|
||||
if (atlasInfo.desaturation) then
|
||||
textureObject:SetDesaturation(atlasInfo.desaturation)
|
||||
end
|
||||
end
|
||||
|
||||
if (atlasInfo.colorName) then
|
||||
textureObject:SetVertexColor(detailsFramework:ParseColors(atlasInfo.colorName))
|
||||
else
|
||||
@@ -496,7 +505,10 @@ end
|
||||
---@param textureWidth number?
|
||||
---@return string
|
||||
function detailsFramework:CreateAtlasString(atlas, textureHeight, textureWidth)
|
||||
local file, width, height, leftTexCoord, rightTexCoord, topTexCoord, bottomTexCoord, r, g, b, nativeWidth, nativeHeight = detailsFramework:ParseTexture(atlas)
|
||||
local file, width, height, leftTexCoord, rightTexCoord, topTexCoord, bottomTexCoord, r, g, b, a, nativeWidth, nativeHeight = detailsFramework:ParseTexture(atlas)
|
||||
|
||||
nativeWidth = nativeWidth or width or textureWidth
|
||||
nativeHeight = nativeHeight or height or textureHeight
|
||||
|
||||
if (not height) then
|
||||
return "|T" .. file .. "|t"
|
||||
@@ -507,9 +519,10 @@ function detailsFramework:CreateAtlasString(atlas, textureHeight, textureWidth)
|
||||
elseif (not r) then
|
||||
--the two zeros are the x and y offset
|
||||
--texCoords are multiplied by the heigh and width to get the actual pixel position
|
||||
return "|T" .. file .. ":" .. (textureHeight or height) .. ":" .. (textureWidth or width) .. ":0:0:" .. (nativeWidth or width) .. ":" .. (nativeHeight or height) .. ":" .. leftTexCoord*(nativeWidth or width) .. ":" .. rightTexCoord*(nativeWidth or width) .. ":" .. topTexCoord*(nativeHeight or height) .. ":" .. bottomTexCoord*(nativeHeight or height) .. "|t"
|
||||
local str = "|T" .. file .. ":" .. (textureHeight or height) .. ":" .. (textureWidth or width) .. ":0:0:" .. nativeWidth .. ":" .. nativeHeight .. ":" .. math.floor(leftTexCoord*nativeWidth) .. ":" .. math.floor(rightTexCoord*nativeWidth) .. ":" .. math.floor(topTexCoord*nativeHeight) .. ":" .. math.floor(bottomTexCoord*nativeHeight) .. "|t"
|
||||
return str
|
||||
else
|
||||
return "|T" .. file .. ":" .. (textureHeight or height) .. ":" .. (textureWidth or width) .. ":0:0:" .. (nativeWidth or width) .. ":" .. (nativeHeight or height) .. ":" .. leftTexCoord*(nativeWidth or width) .. ":" .. rightTexCoord*(nativeWidth or width) .. ":" .. topTexCoord*(nativeHeight or height) .. ":" .. bottomTexCoord*(nativeHeight or height) .. ":" .. r .. ":" .. g .. ":" .. b .. "|t"
|
||||
return "|T" .. file .. ":" .. (textureHeight or height) .. ":" .. (textureWidth or width) .. ":0:0:" .. nativeWidth .. ":" .. nativeHeight .. ":" .. math.floor(leftTexCoord*nativeWidth) .. ":" .. math.floor(rightTexCoord*nativeWidth) .. ":" .. math.floor(topTexCoord*nativeHeight) .. ":" .. math.floor(bottomTexCoord*nativeHeight) .. ":" .. r .. ":" .. g .. ":" .. b .. "|t"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -548,6 +561,7 @@ function detailsFramework:ParseTexture(texture, width, height, leftTexCoord, rig
|
||||
end
|
||||
|
||||
if (isAtlas) then
|
||||
--ui atlasinfo
|
||||
---@type atlasinfo
|
||||
local atlasInfo = isAtlas
|
||||
local textureId = atlasInfo.file
|
||||
@@ -567,7 +581,7 @@ function detailsFramework:ParseTexture(texture, width, height, leftTexCoord, rig
|
||||
end
|
||||
|
||||
local nativeWidth, nativeHeight = atlasInfo.nativeWidth, atlasInfo.nativeHeight
|
||||
return atlasInfo.file or atlasInfo.filename, width or atlasInfo.width, height or atlasInfo.height, atlasInfo.leftTexCoord, atlasInfo.rightTexCoord, atlasInfo.topTexCoord, atlasInfo.bottomTexCoord, r, g, b, a, nativeWidth, nativeHeight
|
||||
return atlasInfo.file or atlasInfo.filename, width or atlasInfo.width, height or atlasInfo.height, atlasInfo.leftTexCoord or 0, atlasInfo.rightTexCoord or 1, atlasInfo.topTexCoord or 0, atlasInfo.bottomTexCoord or 1, r, g, b, a, nativeWidth, nativeHeight
|
||||
end
|
||||
|
||||
if (type(vertexRed) == "string" or type(vertexRed) == "table") then
|
||||
@@ -593,8 +607,11 @@ end
|
||||
---@param vertexGreen number? green color to use with SetVertexColor
|
||||
---@param vertexBlue number? blue color to use with SetVertexColor
|
||||
---@param vertexAlpha number? alpha color to use with SetVertexColor
|
||||
---@param desaturated boolean? if the texture should be desaturated
|
||||
---@param desaturation number? the amount of desaturation to use with SetDesaturation
|
||||
---@param alpha number? the alpha to use with SetAlpha
|
||||
---@return df_atlasinfo
|
||||
function detailsFramework:CreateAtlas(file, width, height, leftTexCoord, rightTexCoord, topTexCoord, bottomTexCoord, tilesHorizontally, tilesVertically, vertexRed, vertexGreen, vertexBlue, vertexAlpha)
|
||||
function detailsFramework:CreateAtlas(file, width, height, leftTexCoord, rightTexCoord, topTexCoord, bottomTexCoord, tilesHorizontally, tilesVertically, vertexRed, vertexGreen, vertexBlue, vertexAlpha, desaturated, desaturation, alpha)
|
||||
---@type df_atlasinfo
|
||||
local atlasInfo = {
|
||||
file = file,
|
||||
@@ -606,6 +623,9 @@ function detailsFramework:CreateAtlas(file, width, height, leftTexCoord, rightTe
|
||||
bottomTexCoord = bottomTexCoord or 1,
|
||||
tilesHorizontally = tilesHorizontally or false,
|
||||
tilesVertically = tilesVertically or false,
|
||||
desaturated = desaturated,
|
||||
desaturation = desaturation,
|
||||
alpha = alpha,
|
||||
}
|
||||
|
||||
--parse the colors passed
|
||||
|
||||
Reference in New Issue
Block a user