Skip to content

Commit

Permalink
Polishing the segments menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Tercioo committed Mar 3, 2024
1 parent 8ab122b commit ca192bb
Show file tree
Hide file tree
Showing 12 changed files with 376 additions and 94 deletions.
6 changes: 3 additions & 3 deletions Definitions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
---@field contra string the name of the player enemy in a 1v1 pvp combat
---@field bossTimers table[] stored timers for bigwigs and dbm
---@field last_events_tables table[] where the death log of each player is stored
---@field
---@field boss_hp number percentage of the health points of the boss
---@field
---@field
---@field
Expand Down Expand Up @@ -251,7 +251,7 @@
---@field is_world_trash_combat boolean when true this combat is a regular combat done in the world, not in a dungeon, raid, battleground, arena, ...
---@field player_last_events table<string, table[]> record the latest events of each player, latter used to build the death log
---@field
---@field
---@field FindEnemyName fun(combat: combat) : string attempt to get the name of the enemy in the combat by getting the top most damaged unit by the player
---@field GetTryNumber fun(combat: combat) : number?
---@field GetFormattedCombatTime fun(combat: combat) : string
---@field GetMSTime fun(combat: combat) : number, number
Expand Down Expand Up @@ -421,7 +421,7 @@
---@field friendlyfire_total number
---@field friendlyfire table<actorname, friendlyfiretable>
---@field damage_taken number amount of damage the actor took during the segment
---@field damage_from table<string, boolean> store the name of the actors which damaged the actor, format: [actorName] = true
---@field damage_from table<actorname, boolean> store the name of the actors which damaged the actor, format: [actorName] = true
---@field totalabsorbed number amount of damage dealt by the actor by got absorbed by the target, this is a "ABSORB" type of miss but still counts as damage done
---@field augmentedSpellsContainer spellcontainer

Expand Down
43 changes: 27 additions & 16 deletions Libs/DF/cooltip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 = {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions Libs/DF/definitions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
---@field colorName string?
---@field nativeWidth number?
---@field nativeHeight number?
---@field desaturated boolean?
---@field desaturation number?

---@alias templatetype
---| "font"
Expand Down Expand Up @@ -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
Expand Down
79 changes: 76 additions & 3 deletions Libs/DF/fw.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
30 changes: 25 additions & 5 deletions Libs/DF/picture.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions boot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
DamageSpellsCache = {}
}

Details222.Unknown = _G["UNKNOWN"]

--namespace color
Details222.ColorScheme = {
["gradient-background"] = {0.1215, 0.1176, 0.1294, 0.8},
Expand Down
Loading

0 comments on commit ca192bb

Please sign in to comment.