main
JeffyLikesApples 11 months ago
parent c4b8c781bc
commit 8f93bae7a9
  1. 108
      DiesalComm-1.0/DiesalComm-1.0.lua
  2. 1
      DiesalGUI-2.0/Objects/Branch.lua
  3. 2
      DiesalGUI-2.0/Objects/ComboBoxItem.lua
  4. 4
      DiesalGUI-2.0/Objects/ObjectBase.lua
  5. 3
      DiesalMenu-2.0/Objects/MenuItem.lua
  6. 128
      DiesalStyle-2.0/DiesalStyle-2.0.lua

@ -1,3 +1,4 @@
---@diagnostic disable: inject-field, undefined-field, undefined-global
--- allows you to send messages of unlimited length over the addon comm channels. --- allows you to send messages of unlimited length over the addon comm channels.
-- It'll automatically split the messages into multiple parts and rebuild them on the receiving end.\\ -- It'll automatically split the messages into multiple parts and rebuild them on the receiving end.\\
-- **ChatThrottleLib** is of course being used to avoid being disconnected by the server. -- **ChatThrottleLib** is of course being used to avoid being disconnected by the server.
@ -15,7 +16,9 @@
-- ~~| Initialize library |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- ~~| Initialize library |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
local MAJOR, MINOR = "DiesalComm-1.0", 1 local MAJOR, MINOR = "DiesalComm-1.0", 1
local DiesalComm, oldminor = LibStub:NewLibrary(MAJOR, MINOR) local DiesalComm, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
if not DiesalComm then return end if not DiesalComm then
return
end
local CallbackHandler = LibStub:GetLibrary("CallbackHandler-1.0") local CallbackHandler = LibStub:GetLibrary("CallbackHandler-1.0")
local CTL = assert(ChatThrottleLib, "DiesalComm-1.0 requires ChatThrottleLib") local CTL = assert(ChatThrottleLib, "DiesalComm-1.0 requires ChatThrottleLib")
@ -31,42 +34,39 @@ local Ambiguate = Ambiguate
DiesalComm.embeds = DiesalComm.embeds or {} DiesalComm.embeds = DiesalComm.embeds or {}
DiesalComm.msg_spool = DiesalComm.msg_spool or {} DiesalComm.msg_spool = DiesalComm.msg_spool or {}
local COMM_MODES = {'single','first','next','last'} local COMM_MODES = { "single", "first", "next", "last" }
local HEADER_SIZE = 14 local HEADER_SIZE = 14
local HEADER_FORMAT = '%[%x%x:%x%x%x%x:%x%x%x%x%]' local HEADER_FORMAT = "%[%x%x:%x%x%x%x:%x%x%x%x%]"
local MAX_CHUNK_SIZE = 240 local MAX_CHUNK_SIZE = 240
--- Register for Addon Traffic on a specified prefix --- Register for Addon Traffic on a specified prefix
-- @param prefix A printable character (\032-\255) classification of the message (typically AddonName or AddonNameEvent), max 16 characters -- @param prefix A printable character (\032-\255) classification of the message (typically AddonName or AddonNameEvent), max 16 characters
-- @param method Callback to call on message reception: Function reference, or method name (string) to call on self. Defaults to "OnCommReceived" -- @param method Callback to call on message reception: Function reference, or method name (string) to call on self. Defaults to "OnCommReceived"
function DiesalComm:RegisterComm(prefix, method) function DiesalComm:RegisterComm(prefix, method)
if method == nil then method = "OnCommReceived" end if method == nil then
if #prefix > 15 then error("AceComm:RegisterComm(prefix,method): prefix length is limited to 15 characters") end method = "OnCommReceived"
end
if #prefix > 15 then
error("AceComm:RegisterComm(prefix,method): prefix length is limited to 15 characters")
end
RegisterAddonMessagePrefix(prefix) RegisterAddonMessagePrefix(prefix)
return DiesalComm.RegisterCallback(self, prefix, method) return DiesalComm.RegisterCallback(self, prefix, method)
end end
local function formatValue(num, len)
num = format("%X", num)
local function formatValue(num,len)
num = format('%X',num)
for i = 1, len - #num do for i = 1, len - #num do
num = "0"..num num = "0" .. num
end end
return num return num
end end
local function encodeHeader(mode, chunk, totalChunks)
local function encodeHeader(mode, chunk ,totalChunks ) return "[" .. formatValue(mode, 2) .. ":" .. formatValue(chunk, 4) .. ":" .. formatValue(totalChunks, 4) .. "]"
return '['..formatValue(mode,2)..':'..formatValue(chunk,4)..':'..formatValue(totalChunks,4)..']'
end
local function decodeHeader()
end end
local function decodeHeader() end
--- Send a message over the Addon Channel --- Send a message over the Addon Channel
-- @param prefix A printable character (\032-\255) classification of the message (typically AddonName or AddonNameEvent) -- @param prefix A printable character (\032-\255) classification of the message (typically AddonName or AddonNameEvent)
@ -78,51 +78,56 @@ end
-- @param prio OPTIONAL: ChatThrottleLib priority, "BULK", "NORMAL" or "ALERT". Defaults to "NORMAL". -- @param prio OPTIONAL: ChatThrottleLib priority, "BULK", "NORMAL" or "ALERT". Defaults to "NORMAL".
function AceComm:SendCommMessage(prefix, text, channel, target, callbackFn, callbackArg, prio) function AceComm:SendCommMessage(prefix, text, channel, target, callbackFn, callbackArg, prio)
prio = prio or "NORMAL" prio = prio or "NORMAL"
if type(prefix)~="string" and type(text)~="string" and type(channel)~="string" and (target==nil or type(target)~="string") and (prio~="BULK" or prio~="NORMAL" or prio~="ALERT") then if
type(prefix) ~= "string"
and type(text) ~= "string"
and type(channel) ~= "string"
and (target == nil or type(target) ~= "string")
and (prio ~= "BULK" or prio ~= "NORMAL" or prio ~= "ALERT")
then
error('Usage: SendCommMessage(addon, "prefix", "text", "channel"[, "target"[, callbackFn, callbackarg[, "prio"]]])', 2) error('Usage: SendCommMessage(addon, "prefix", "text", "channel"[, "target"[, callbackFn, callbackarg[, "prio"]]])', 2)
end end
local textlen = #text local textlen = #text
local ctlCallback = callbackFn and function(sent) return callbackFn(callbackArg, sent, textlen) end or nil local ctlCallback = callbackFn and function(sent)
return callbackFn(callbackArg, sent, textlen)
end or nil
if textlen <= MAX_CHUNK_SIZE then -- fits all in one message if textlen <= MAX_CHUNK_SIZE then -- fits all in one message
text = '[0:0000:0000]'..text text = "[0:0000:0000]" .. text
CTL:SendAddonMessage(prio, prefix, text, channel, target, nil, ctlCallback, textlen) CTL:SendAddonMessage(prio, prefix, text, channel, target, nil, ctlCallback, textlen)
else else
-- first part -- first part
local chunk = strsub(text, 1, maxtextlen) local chunk = strsub(text, 1, maxtextlen)
CTL:SendAddonMessage(prio, prefix, MSG_MULTI_FIRST..chunk, distribution, target, queueName, ctlCallback, maxtextlen) CTL:SendAddonMessage(prio, prefix, MSG_MULTI_FIRST .. chunk, distribution, target, queueName, ctlCallback, maxtextlen)
-- continuation -- continuation
local pos = 1+maxtextlen local pos = 1 + maxtextlen
while pos+maxtextlen <= textlen do while pos + maxtextlen <= textlen do
chunk = strsub(text, pos, pos+maxtextlen-1) chunk = strsub(text, pos, pos + maxtextlen - 1)
CTL:SendAddonMessage(prio, prefix, MSG_MULTI_NEXT..chunk, distribution, target, queueName, ctlCallback, pos+maxtextlen-1) CTL:SendAddonMessage(prio, prefix, MSG_MULTI_NEXT .. chunk, distribution, target, queueName, ctlCallback, pos + maxtextlen - 1)
pos = pos + maxtextlen pos = pos + maxtextlen
end end
-- final part -- final part
chunk = strsub(text, pos) chunk = strsub(text, pos)
CTL:SendAddonMessage(prio, prefix, MSG_MULTI_LAST..chunk, distribution, target, queueName, ctlCallback, textlen) CTL:SendAddonMessage(prio, prefix, MSG_MULTI_LAST .. chunk, distribution, target, queueName, ctlCallback, textlen)
end end
end end
---------------------------------------- ----------------------------------------
-- Message receiving -- Message receiving
---------------------------------------- ----------------------------------------
do do
local compost = setmetatable({}, {__mode = "k"}) local compost = setmetatable({}, { __mode = "k" })
local function new() local function new()
local t = next(compost) local t = next(compost)
if t then if t then
compost[t]=nil compost[t] = nil
for i=#t,3,-1 do -- faster than pairs loop. don't even nil out 1/2 since they'll be overwritten for i = #t, 3, -1 do -- faster than pairs loop. don't even nil out 1/2 since they'll be overwritten
t[i]=nil t[i] = nil
end end
return t return t
end end
@ -130,12 +135,12 @@ do
return {} return {}
end end
local function lostdatawarning(prefix,sender,where) local function lostdatawarning(prefix, sender, where)
DEFAULT_CHAT_FRAME:AddMessage(MAJOR..": Warning: lost network data regarding '"..tostring(prefix).."' from '"..tostring(sender).."' (in "..where..")") DEFAULT_CHAT_FRAME:AddMessage(MAJOR .. ": Warning: lost network data regarding '" .. tostring(prefix) .. "' from '" .. tostring(sender) .. "' (in " .. where .. ")")
end end
function AceComm:OnReceiveMultipartFirst(prefix, message, distribution, sender) function AceComm:OnReceiveMultipartFirst(prefix, message, distribution, sender)
local key = prefix.."\t"..distribution.."\t"..sender -- a unique stream is defined by the prefix + distribution + sender local key = prefix .. "\t" .. distribution .. "\t" .. sender -- a unique stream is defined by the prefix + distribution + sender
local spool = AceComm.multipart_spool local spool = AceComm.multipart_spool
--[[ --[[
@ -149,7 +154,7 @@ do
end end
function AceComm:OnReceiveMultipartNext(prefix, message, distribution, sender) function AceComm:OnReceiveMultipartNext(prefix, message, distribution, sender)
local key = prefix.."\t"..distribution.."\t"..sender -- a unique stream is defined by the prefix + distribution + sender local key = prefix .. "\t" .. distribution .. "\t" .. sender -- a unique stream is defined by the prefix + distribution + sender
local spool = AceComm.multipart_spool local spool = AceComm.multipart_spool
local olddata = spool[key] local olddata = spool[key]
@ -158,7 +163,7 @@ do
return return
end end
if type(olddata)~="table" then if type(olddata) ~= "table" then
-- ... but what we have is not a table. So make it one. (Pull a composted one if available) -- ... but what we have is not a table. So make it one. (Pull a composted one if available)
local t = new() local t = new()
t[1] = olddata -- add old data as first string t[1] = olddata -- add old data as first string
@ -170,7 +175,7 @@ do
end end
function AceComm:OnReceiveMultipartLast(prefix, message, distribution, sender) function AceComm:OnReceiveMultipartLast(prefix, message, distribution, sender)
local key = prefix.."\t"..distribution.."\t"..sender -- a unique stream is defined by the prefix + distribution + sender local key = prefix .. "\t" .. distribution .. "\t" .. sender -- a unique stream is defined by the prefix + distribution + sender
local spool = AceComm.multipart_spool local spool = AceComm.multipart_spool
local olddata = spool[key] local olddata = spool[key]
@ -188,25 +193,17 @@ do
compost[olddata] = true compost[olddata] = true
else else
-- if we've only received a "first", the spooled data will still only be a string -- if we've only received a "first", the spooled data will still only be a string
AceComm.callbacks:Fire(prefix, olddata..message, distribution, sender) AceComm.callbacks:Fire(prefix, olddata .. message, distribution, sender)
end end
end end
end end
---------------------------------------- ----------------------------------------
-- Embed CallbackHandler -- Embed CallbackHandler
---------------------------------------- ----------------------------------------
if not AceComm.callbacks then if not AceComm.callbacks then
AceComm.callbacks = CallbackHandler:New(AceComm, AceComm.callbacks = CallbackHandler:New(AceComm, "_RegisterComm", "UnregisterComm", "UnregisterAllComm")
"_RegisterComm",
"UnregisterComm",
"UnregisterAllComm")
end end
AceComm.callbacks.OnUsed = nil AceComm.callbacks.OnUsed = nil
@ -217,13 +214,13 @@ local function OnEvent(self, event, prefix, message, distribution, sender)
sender = Ambiguate(sender, "none") sender = Ambiguate(sender, "none")
local control, rest = match(message, "^([\001-\009])(.*)") local control, rest = match(message, "^([\001-\009])(.*)")
if control then if control then
if control==MSG_MULTI_FIRST then if control == MSG_MULTI_FIRST then
AceComm:OnReceiveMultipartFirst(prefix, rest, distribution, sender) AceComm:OnReceiveMultipartFirst(prefix, rest, distribution, sender)
elseif control==MSG_MULTI_NEXT then elseif control == MSG_MULTI_NEXT then
AceComm:OnReceiveMultipartNext(prefix, rest, distribution, sender) AceComm:OnReceiveMultipartNext(prefix, rest, distribution, sender)
elseif control==MSG_MULTI_LAST then elseif control == MSG_MULTI_LAST then
AceComm:OnReceiveMultipartLast(prefix, rest, distribution, sender) AceComm:OnReceiveMultipartLast(prefix, rest, distribution, sender)
elseif control==MSG_ESCAPE then elseif control == MSG_ESCAPE then
AceComm.callbacks:Fire(prefix, rest, distribution, sender) AceComm.callbacks:Fire(prefix, rest, distribution, sender)
else else
-- unknown control character, ignore SILENTLY (dont warn unnecessarily about future extensions!) -- unknown control character, ignore SILENTLY (dont warn unnecessarily about future extensions!)
@ -233,7 +230,7 @@ local function OnEvent(self, event, prefix, message, distribution, sender)
AceComm.callbacks:Fire(prefix, message, distribution, sender) AceComm.callbacks:Fire(prefix, message, distribution, sender)
end end
else else
assert(false, "Received "..tostring(event).." event?!") assert(false, "Received " .. tostring(event) .. " event?!")
end end
end end
@ -242,7 +239,6 @@ AceComm.frame:SetScript("OnEvent", OnEvent)
AceComm.frame:UnregisterAllEvents() AceComm.frame:UnregisterAllEvents()
AceComm.frame:RegisterEvent("CHAT_MSG_ADDON") AceComm.frame:RegisterEvent("CHAT_MSG_ADDON")
---------------------------------------- ----------------------------------------
-- Base library stuff -- Base library stuff
---------------------------------------- ----------------------------------------

@ -312,6 +312,7 @@ local function Constructor()
local icon = self:CreateRegion("Texture", "icon", button) local icon = self:CreateRegion("Texture", "icon", button)
DiesalStyle:StyleTexture(icon, { DiesalStyle:StyleTexture(icon, {
type = "texture",
position = { 0, nil, 2, nil }, position = { 0, nil, 2, nil },
height = 16, height = 16,
width = 16, width = 16,

@ -116,7 +116,6 @@ local function Constructor()
frame:SetScript("OnEnter", function(this) end) frame:SetScript("OnEnter", function(this) end)
frame:SetScript("OnLeave", function(this) end) frame:SetScript("OnLeave", function(this) end)
---@type Diesal.GUI.Region.FontString
local text = self:CreateRegion("FontString", "text", frame) local text = self:CreateRegion("FontString", "text", frame)
text:SetPoint("TOPLEFT", 12, -2) text:SetPoint("TOPLEFT", 12, -2)
text:SetPoint("BOTTOMRIGHT", 0, 0) text:SetPoint("BOTTOMRIGHT", 0, 0)
@ -126,6 +125,7 @@ local function Constructor()
local check = self:CreateRegion("Texture", "check", frame) --[[ @as Texture ]] local check = self:CreateRegion("Texture", "check", frame) --[[ @as Texture ]]
DiesalStyle:StyleTexture(check, { DiesalStyle:StyleTexture(check, {
type = "texture",
position = { 2, nil, 0, nil }, position = { 2, nil, 0, nil },
height = 16, height = 16,
width = 16, width = 16,

@ -170,7 +170,7 @@ local ObjectBase = {
---@return RT ---@return RT
CreateRegion = function(self, regionType, regionName, parentRegion, defaultFontObject, ...) CreateRegion = function(self, regionType, regionName, parentRegion, defaultFontObject, ...)
if regionType == "FontString" then if regionType == "FontString" then
---@type Diesal.GUI.Region.FontString ---@class Diesal.GUI.Region.FontString
local fontString = parentRegion:CreateFontString() local fontString = parentRegion:CreateFontString()
fontString.defaultFontObject = defaultFontObject or _G.DiesalFontNormal fontString.defaultFontObject = defaultFontObject or _G.DiesalFontNormal
fontString:SetFont(fontString.defaultFontObject:GetFont()) fontString:SetFont(fontString.defaultFontObject:GetFont())
@ -434,7 +434,7 @@ DiesalGUI.ObjectBase = ObjectBase
---@class Diesal.GUI.ObjectBase.Settings ---@class Diesal.GUI.ObjectBase.Settings
---@field parent Frame ---@field parent Frame
---@field parentObject Diesal.Object ---@field parentObject Diesal.Object?
---@field height number ---@field height number
---@field width number ---@field width number

@ -120,6 +120,7 @@ local methods = {
subMenu:Show() subMenu:Show()
end, end,
} }
---@alias DiesalMenuItem Diesal.Menu.MenuItem
-- | Constructor |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- | Constructor |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
local function Constructor() local function Constructor()
---@class Diesal.Menu.MenuItem : Diesal.GUI.ObjectBase ---@class Diesal.Menu.MenuItem : Diesal.GUI.ObjectBase
@ -162,6 +163,7 @@ local function Constructor()
local check = self:CreateRegion("Texture", "check", frame) local check = self:CreateRegion("Texture", "check", frame)
DiesalStyle:StyleTexture(check, { DiesalStyle:StyleTexture(check, {
type = "texture",
position = { 1, nil, 0, nil }, position = { 1, nil, 0, nil },
height = 16, height = 16,
width = 16, width = 16,
@ -169,6 +171,7 @@ local function Constructor()
}) })
local arrow = self:CreateRegion("Texture", "arrow", frame) local arrow = self:CreateRegion("Texture", "arrow", frame)
DiesalStyle:StyleTexture(arrow, { DiesalStyle:StyleTexture(arrow, {
type = "texture",
position = { nil, 2, -1, nil }, position = { nil, 2, -1, nil },
height = 16, height = 16,
width = 16, width = 16,

@ -34,6 +34,7 @@ DiesalStyle.Formatters = DiesalStyle.Formatters or {}
-- ~~| DiesalStyle UpValues |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- ~~| DiesalStyle UpValues |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
local AddonName = ... local AddonName = ...
---@type table<Diesal.Style.Texture, boolean>
local ReleasedTextures = DiesalStyle.ReleasedTextures local ReleasedTextures = DiesalStyle.ReleasedTextures
local TextureFrame = DiesalStyle.TextureFrame local TextureFrame = DiesalStyle.TextureFrame
local Media = DiesalStyle.Media local Media = DiesalStyle.Media
@ -42,6 +43,7 @@ local Formatters = DiesalStyle.Formatters
-- ~~| Locals |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- ~~| Locals |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
local OUTLINES = { "_LEFT", "_RIGHT", "_TOP", "_BOTTOM" } local OUTLINES = { "_LEFT", "_RIGHT", "_TOP", "_BOTTOM" }
---@diagnostic disable-next-line: undefined-global
local MEDIA_PATH = MEDIA_PATH local MEDIA_PATH = MEDIA_PATH
or type(AddonName) == "table" and string.format("Interface\\AddOns\\Media\\") or type(AddonName) == "table" and string.format("Interface\\AddOns\\Media\\")
or AddonName == "DiesalLibs" and string.format("Interface\\AddOns\\%s\\%s\\Media\\", AddonName, MAJOR) or AddonName == "DiesalLibs" and string.format("Interface\\AddOns\\%s\\%s\\Media\\", AddonName, MAJOR)
@ -70,14 +72,14 @@ local function getMedia(mediaType, name)
end end
local function newTexture() local function newTexture()
local newTexture = next(ReleasedTextures) local nt = next(ReleasedTextures)
if not newTexture then if not nt then
newTexture = TextureFrame:CreateTexture() nt = TextureFrame:CreateTexture() --[[@as Diesal.Style.Texture]]
else else
newTexture:Show() nt:Show()
ReleasedTextures[newTexture] = nil ReleasedTextures[nt] = nil
end end
return newTexture return nt
end end
local function releaseTexture(texture) local function releaseTexture(texture)
@ -114,8 +116,7 @@ local function GetBlizzColorValues(value)
if type(value) == "table" and #value >= 3 then if type(value) == "table" and #value >= 3 then
return value[1] / 255, value[2] / 255, value[3] / 255 return value[1] / 255, value[2] / 255, value[3] / 255
elseif type(value) == "string" then elseif type(value) == "string" then
return tonumber(sub(value, 1, 2), 16) / 255, tonumber(sub(value, 3, 4), 16) / 255, return tonumber(sub(value, 1, 2), 16) / 255, tonumber(sub(value, 3, 4), 16) / 255, tonumber(sub(value, 5, 6), 16) / 255
tonumber(sub(value, 5, 6), 16) / 255
end end
end end
@ -177,18 +178,13 @@ end
local function setColor(texture, r, g, b, a) local function setColor(texture, r, g, b, a)
local status, err = pcall(texture.SetColorTexture, texture, r, g, b, a) local status, err = pcall(texture.SetColorTexture, texture, r, g, b, a)
if not status then if not status then
errorhandler( errorhandler('error in "' .. (texture.style.name or "texture") .. '" ' .. texture.style.mode .. " or alpha setting", r, g, b, a)
'error in "' .. (texture.style.name or "texture") .. '" ' .. texture.style.mode .. " or alpha setting", r, g,
b,
a)
end end
end end
local function setGradient(texture, orientation, r1, g1, b1, a1, r2, g2, b2, a2) local function setGradient(texture, orientation, r1, g1, b1, a1, r2, g2, b2, a2)
local status, err = pcall(texture.SetGradient, texture, orientation, CreateColor(r1, g1, b1, a1), local status, err = pcall(texture.SetGradient, texture, orientation, CreateColor(r1, g1, b1, a1), CreateColor(r2, g2, b2, a2))
CreateColor(r2, g2, b2, a2))
if not status then if not status then
errorhandler('error in "' .. errorhandler('error in "' .. (texture.style.name or "texture") .. '" ' .. texture.style.mode .. " or alpha setting.")
(texture.style.name or "texture") .. '" ' .. texture.style.mode .. " or alpha setting.")
end end
end end
-- ~~| Media |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- ~~| Media |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -462,24 +458,18 @@ do -- | Set Colors |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Colors.UI_200 = HSL(Colors.UI_Hue, Colors.UI_Saturation, 0.07) Colors.UI_200 = HSL(Colors.UI_Hue, Colors.UI_Saturation, 0.07)
-- level 3 -- level 3
Colors.UI_300 = HSL(Colors.UI_Hue, Colors.UI_Saturation, 0.12) Colors.UI_300 = HSL(Colors.UI_Hue, Colors.UI_Saturation, 0.12)
Colors.UI_300_GR = { HSL(Colors.UI_Hue, Colors.UI_Saturation, 0.12), HSL(Colors.UI_Hue, Colors.UI_Saturation, Colors.UI_300_GR = { HSL(Colors.UI_Hue, Colors.UI_Saturation, 0.12), HSL(Colors.UI_Hue, Colors.UI_Saturation, 0.11) }
0.11) }
Colors.UI_350 = HSL(Colors.UI_Hue, Colors.UI_Saturation, 0.15) Colors.UI_350 = HSL(Colors.UI_Hue, Colors.UI_Saturation, 0.15)
Colors.UI_350_GR = { HSL(Colors.UI_Hue, Colors.UI_Saturation, 0.17), HSL(Colors.UI_Hue, Colors.UI_Saturation, Colors.UI_350_GR = { HSL(Colors.UI_Hue, Colors.UI_Saturation, 0.17), HSL(Colors.UI_Hue, Colors.UI_Saturation, 0.14) }
0.14) }
-- level 4 -- level 4
Colors.UI_400 = HSL(Colors.UI_Hue, Colors.UI_Saturation, 0.20) Colors.UI_400 = HSL(Colors.UI_Hue, Colors.UI_Saturation, 0.20)
Colors.UI_400_GR = { HSL(Colors.UI_Hue, Colors.UI_Saturation, 0.20), HSL(Colors.UI_Hue, Colors.UI_Saturation, Colors.UI_400_GR = { HSL(Colors.UI_Hue, Colors.UI_Saturation, 0.20), HSL(Colors.UI_Hue, Colors.UI_Saturation, 0.17) }
0.17) } Colors.UI_450_GR = { HSL(Colors.UI_Hue, Colors.UI_Saturation, 0.24), HSL(Colors.UI_Hue, Colors.UI_Saturation, 0.20) }
Colors.UI_450_GR = { HSL(Colors.UI_Hue, Colors.UI_Saturation, 0.24), HSL(Colors.UI_Hue, Colors.UI_Saturation,
0.20) }
-- level 5 -- level 5
Colors.UI_500 = HSL(Colors.UI_Hue, Colors.UI_Saturation, 0.29) Colors.UI_500 = HSL(Colors.UI_Hue, Colors.UI_Saturation, 0.29)
Colors.UI_500_GR = { HSL(Colors.UI_Hue, Colors.UI_Saturation, 0.29), HSL(Colors.UI_Hue, Colors.UI_Saturation, Colors.UI_500_GR = { HSL(Colors.UI_Hue, Colors.UI_Saturation, 0.29), HSL(Colors.UI_Hue, Colors.UI_Saturation, 0.26) }
0.26) }
Colors.UI_600_GR = { HSL(Colors.UI_Hue, Colors.UI_Saturation, 0.35), HSL(Colors.UI_Hue, Colors.UI_Saturation, Colors.UI_600_GR = { HSL(Colors.UI_Hue, Colors.UI_Saturation, 0.35), HSL(Colors.UI_Hue, Colors.UI_Saturation, 0.32) }
0.32) }
-- font Colors -35 -- font Colors -35
Colors.UI_F450 = HSL(Colors.UI_Hue, Colors.UI_Saturation, 0.75) Colors.UI_F450 = HSL(Colors.UI_Hue, Colors.UI_Saturation, 0.75)
@ -4152,9 +4142,7 @@ do -- Set Material Icons
end end
---@param iconName string ---@param iconName string
---@param iconType? "regular" | "outlined" | "round" | "sharp" | "twotone" function DiesalStyle.MaterialIcon(iconName)
function DiesalStyle.MaterialIcon(iconName, iconType)
iconType = iconType or "regular"
if MaterialIcons.bytes[iconName] then if MaterialIcons.bytes[iconName] then
return utf8(MaterialIcons.bytes[iconName]) return utf8(MaterialIcons.bytes[iconName])
end end
@ -4200,10 +4188,8 @@ do -- Set Icons
---@param key string ---@param key string
---@param table table ---@param table table
local function checkType(prefix, key, table) local function checkType(prefix, key, table)
assert(type(key) == "string", assert(type(key) == "string", string.format("key %d for %s not a string.", prefixInfo[prefix].count, prefixInfo[prefix].prefix))
string.format("key %d for %s not a string.", prefixInfo[prefix].count, prefixInfo[prefix].prefix)) assert(type(table) == "table", string.format("value %d for %s is not a table.", prefixInfo[prefix].count, prefixInfo[prefix].prefix))
assert(type(table) == "table",
string.format("value %d for %s is not a table.", prefixInfo[prefix].count, prefixInfo[prefix].prefix))
end end
for p1, p1Table in pairs(iconsToAdd) do for p1, p1Table in pairs(iconsToAdd) do
@ -4217,21 +4203,15 @@ do -- Set Icons
local filePrefixes = string.format("%s%s%s", p1, p2, p3) local filePrefixes = string.format("%s%s%s", p1, p2, p3)
Icons[p1][p2][p3] = Icons[p1][p2][p3] or {} Icons[p1][p2][p3] = Icons[p1][p2][p3] or {}
for iconSize, fileDimTable in pairs(p3Table) do for iconSize, fileDimTable in pairs(p3Table) do
assert(type(iconSize) == "number", assert(type(iconSize) == "number", string.format("icon size key %d for %s is not a number.", prefixInfo[3].iconSize, filePrefixes))
string.format("icon size key %d for %s is not a number.", prefixInfo[3].iconSize,
filePrefixes))
filePrefixes = string.format("%s[%d]", filePrefixes, iconSize) filePrefixes = string.format("%s[%d]", filePrefixes, iconSize)
Icons[p1][p2][p3][iconSize] = Icons[p1][p2][p3][iconSize] or {} Icons[p1][p2][p3][iconSize] = Icons[p1][p2][p3][iconSize] or {}
for fileDimKey, iconColumns in pairs(fileDimTable) do for fileDimKey, iconColumns in pairs(fileDimTable) do
assert(type(fileDimKey == "string"), assert(type(fileDimKey == "string"), string.format("file dimensions key for file %d in %s is not a string.", prefixInfo[3].file, filePrefixes))
string.format("file dimensions key for file %d in %s is not a string.",
prefixInfo[3].file, filePrefixes))
local fileDims = strsplittable("x", fileDimKey, 2) local fileDims = strsplittable("x", fileDimKey, 2)
assert(type(tonumber(fileDims[1])) == "number", assert(type(tonumber(fileDims[1])) == "number", string.format("could not obtain width from %s in %s", fileDimKey, filePrefixes))
string.format("could not obtain width from %s in %s", fileDimKey, filePrefixes)) assert(type(tonumber(fileDims[2])) == "number", string.format("could not obtain height from %s in %s", fileDimKey, filePrefixes))
assert(type(tonumber(fileDims[2])) == "number",
string.format("could not obtain height from %s in %s", fileDimKey, filePrefixes))
Icons[p1][p2][p3][iconSize][fileDimKey] = Icons[p1][p2][p3][iconSize][fileDimKey] or {} Icons[p1][p2][p3][iconSize][fileDimKey] = Icons[p1][p2][p3][iconSize][fileDimKey] or {}
filePrefixes = string.format("%s[%s]", filePrefixes, fileDimKey) filePrefixes = string.format("%s[%s]", filePrefixes, fileDimKey)
@ -4247,18 +4227,14 @@ do -- Set Icons
local rowCount = 0 local rowCount = 0
for column, rows in pairs(iconColumns) do for column, rows in pairs(iconColumns) do
columnCount = columnCount + 1 columnCount = columnCount + 1
assert(type(column) == "number", assert(type(column) == "number", string.format("column %d key in %s is not a number.", columnCount, filePrefixes))
string.format("column %d key in %s is not a number.", columnCount, filePrefixes)) assert(type(rows) == "table", string.format("column %d value in %s is not a table.", columnCount, filePrefixes))
assert(type(rows) == "table",
string.format("column %d value in %s is not a table.", columnCount, filePrefixes))
local filePrefixesColumn = string.format("%s[%d]", filePrefixes, column) local filePrefixesColumn = string.format("%s[%d]", filePrefixes, column)
iconsFileTable[column] = iconsFileTable[column] or {} iconsFileTable[column] = iconsFileTable[column] or {}
for row, icon in pairs(rows) do for row, icon in pairs(rows) do
rowCount = rowCount + 1 rowCount = rowCount + 1
assert(type(row) == "number", assert(type(row) == "number", string.format("row %d key in %s is not a number.", rowCount, filePrefixesColumn))
string.format("row %d key in %s is not a number.", rowCount, filePrefixesColumn)) assert(type(icon) == "string", string.format("row %d value in %s is not a string.", rowCount, filePrefixesColumn))
assert(type(icon) == "string",
string.format("row %d value in %s is not a string.", rowCount, filePrefixesColumn))
local filePrefixesColumnRow = string.format("%s[%d]", filePrefixesColumn, row) local filePrefixesColumnRow = string.format("%s[%d]", filePrefixesColumn, row)
local iconName = icon local iconName = icon
@ -4301,8 +4277,7 @@ do -- Set Icons
---@param iconTable DiesalStyle.Icon ---@param iconTable DiesalStyle.Icon
local function CreateIconStyle(iconTable) local function CreateIconStyle(iconTable)
local fileName = string.format("%s%s%s", iconTable.file.prefix[1], iconTable.file.prefix[2], local fileName = string.format("%s%s%s", iconTable.file.prefix[1], iconTable.file.prefix[2], iconTable.file.prefix[3])
iconTable.file.prefix[3])
local iconSize = iconTable.file.size.icon local iconSize = iconTable.file.size.icon
fileName = fileName .. (iconSize ~= 16 and iconSize or "") fileName = fileName .. (iconSize ~= 16 and iconSize or "")
@ -4677,10 +4652,8 @@ function DiesalStyle:StyleTexture(texture, style)
texture.style.alpha = formatAlpha(style.alpha) or texture.style.alpha or { 1, 1 } texture.style.alpha = formatAlpha(style.alpha) or texture.style.alpha or { 1, 1 }
-- gradient -- gradient
if texture.style.gradient then if texture.style.gradient then
texture.style.gradient.orientation = style.gradient_orientation or texture.style.gradient.orientation or texture.style.gradient.orientation = style.gradient_orientation or texture.style.gradient.orientation or DEFAULT_GRADIENT_ORIENTATION
DEFAULT_GRADIENT_ORIENTATION texture.style.gradient.color = style.gradient_color or texture.style.gradient.color or { DEFAULT_COLOR, DEFAULT_COLOR }
texture.style.gradient.color = style.gradient_color or texture.style.gradient.color or
{ DEFAULT_COLOR, DEFAULT_COLOR }
end end
-- image -- image
if texture.style.image then if texture.style.image then
@ -4716,8 +4689,7 @@ function DiesalStyle:StyleTexture(texture, style)
end end
if style.debug then if style.debug then
print(texture:GetHeight(), texture.style.position[1], texture.style.position[2], texture.style.position[3], print(texture:GetHeight(), texture.style.position[1], texture.style.position[2], texture.style.position[3], texture.style.position[4])
texture.style.position[4])
end end
-- [1] Texture > [2] gradient > [3] color -- [1] Texture > [2] gradient > [3] color
if texture.style.image then -- [1] Texture if texture.style.image then -- [1] Texture
@ -4727,10 +4699,8 @@ function DiesalStyle:StyleTexture(texture, style)
setGradient(texture, "HORIZONTAL", 1, 1, 1, 1, 1, 1, 1, 1) -- clear gradient setGradient(texture, "HORIZONTAL", 1, 1, 1, 1, 1, 1, 1, 1) -- clear gradient
texture:SetColorTexture(1, 1, 1, 1) -- clear color texture:SetColorTexture(1, 1, 1, 1) -- clear color
-- apply settings -- apply settings
texture:SetTexCoord(texture.style.image.coords[1], texture.style.image.coords[2], texture.style.image.coords[3], texture:SetTexCoord(texture.style.image.coords[1], texture.style.image.coords[2], texture.style.image.coords[3], texture.style.image.coords[4])
texture.style.image.coords[4]) texture:SetTexture(texture.style.image.file, texture.style.image.tiling and texture.style.image.tiling[1], texture.style.image.tiling and texture.style.image.tiling[2])
texture:SetTexture(texture.style.image.file, texture.style.image.tiling and texture.style.image.tiling[1],
texture.style.image.tiling and texture.style.image.tiling[2])
texture:SetHorizTile(texture.style.image.tiling[1] and true) texture:SetHorizTile(texture.style.image.tiling[1] and true)
texture:SetVertTile(texture.style.image.tiling[2] and true) texture:SetVertTile(texture.style.image.tiling[2] and true)
local r, g, b = GetBlizzColorValues(texture.style.image.color) local r, g, b = GetBlizzColorValues(texture.style.image.color)
@ -4742,13 +4712,9 @@ function DiesalStyle:StyleTexture(texture, style)
texture:SetTexture() -- clear image texture:SetTexture() -- clear image
texture:SetColorTexture(1, 1, 1, 1) -- clear color texture:SetColorTexture(1, 1, 1, 1) -- clear color
-- apply settings -- apply settings
local r1, g1, b1 = GetBlizzColorValues(texture.style.gradient.color local r1, g1, b1 = GetBlizzColorValues(texture.style.gradient.color[texture.style.gradient.orientation == "HORIZONTAL" and 1 or 2])
[texture.style.gradient.orientation == "HORIZONTAL" and 1 or 2]) local r2, g2, b2 = GetBlizzColorValues(texture.style.gradient.color[texture.style.gradient.orientation == "HORIZONTAL" and 2 or 1])
local r2, g2, b2 = GetBlizzColorValues(texture.style.gradient.color local a1, a2 = texture.style.alpha[texture.style.gradient.orientation == "HORIZONTAL" and 1 or 2], texture.style.alpha[texture.style.gradient.orientation == "HORIZONTAL" and 2 or 1]
[texture.style.gradient.orientation == "HORIZONTAL" and 2 or 1])
local a1, a2 =
texture.style.alpha[texture.style.gradient.orientation == "HORIZONTAL" and 1 or 2],
texture.style.alpha[texture.style.gradient.orientation == "HORIZONTAL" and 2 or 1]
setGradient(texture, texture.style.gradient.orientation, r1, g1, b1, a1, r2, g2, b2, a2) setGradient(texture, texture.style.gradient.orientation, r1, g1, b1, a1, r2, g2, b2, a2)
elseif texture.style.color then -- [3] color elseif texture.style.color then -- [3] color
-- set mode -- set mode
@ -4794,8 +4760,7 @@ function DiesalStyle:StyleOutline(leftTexture, rightTexture, topTexture, bottomT
color = style.gradient[2] and style.gradient[3] and { style.gradient[2], style.gradient[3] }, color = style.gradient[2] and style.gradient[3] and { style.gradient[2], style.gradient[3] },
} }
end end
style.gradient_orientation = style.gradient_orientation and style.gradient_orientation = style.gradient_orientation and style.gradient_orientation:upper() --formatOrientation(style.gradient_orientation) -- fuck you
style.gradient_orientation:upper() --formatOrientation(style.gradient_orientation) -- fuck you
if not texture.style.gradient and (style.gradient_orientation or style.gradient_alpha or style.gradient_color) then if not texture.style.gradient and (style.gradient_orientation or style.gradient_alpha or style.gradient_color) then
texture.style.gradient = {} texture.style.gradient = {}
end end
@ -4808,10 +4773,8 @@ function DiesalStyle:StyleOutline(leftTexture, rightTexture, topTexture, bottomT
texture.style.alpha = formatAlpha(style.alpha) or texture.style.alpha or { 1, 1 } texture.style.alpha = formatAlpha(style.alpha) or texture.style.alpha or { 1, 1 }
-- gradient -- gradient
if texture.style.gradient then if texture.style.gradient then
texture.style.gradient.orientation = style.gradient_orientation or texture.style.gradient.orientation or texture.style.gradient.orientation = style.gradient_orientation or texture.style.gradient.orientation or DEFAULT_GRADIENT_ORIENTATION
DEFAULT_GRADIENT_ORIENTATION texture.style.gradient.color = style.gradient_color or texture.style.gradient.color or { DEFAULT_COLOR, DEFAULT_COLOR }
texture.style.gradient.color = style.gradient_color or texture.style.gradient.color or
{ DEFAULT_COLOR, DEFAULT_COLOR }
end end
-- | Apply Settings |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- | Apply Settings |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -4990,8 +4953,7 @@ end
---@param frame Frame ---@param frame Frame
---@param style Diesal.Style.ShadowStyle ---@param style Diesal.Style.ShadowStyle
function DiesalStyle:StyleShadow(object, frame, style) function DiesalStyle:StyleShadow(object, frame, style)
object.shadow = object.shadow or object.shadow = object.shadow or CreateFrame("Frame", nil, frame, BackdropTemplateMixin and "BackdropTemplate") --CreateFrame("Frame",nil,frame)
CreateFrame("Frame", nil, frame, BackdropTemplateMixin and "BackdropTemplate") --CreateFrame("Frame",nil,frame)
object.shadow:Show() object.shadow:Show()
if not object.shadow.style or style.clear then if not object.shadow.style or style.clear then
object.shadow.style = {} object.shadow.style = {}
@ -4999,8 +4961,7 @@ function DiesalStyle:StyleShadow(object, frame, style)
local shadowStyle = object.shadow.style local shadowStyle = object.shadow.style
-- ~~ Format New Settings ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- ~~ Format New Settings ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
local red, green, blue = DiesalTools.GetColor(style.color) local red, green, blue = DiesalTools.GetColor(style.color)
local offset = style.offset and type(style.offset) == "number" and local offset = style.offset and type(style.offset) == "number" and { style.offset, style.offset, style.offset, style.offset } or style.offset
{ style.offset, style.offset, style.offset, style.offset } or style.offset
-- Setting ~~~~~~~~~~~~~~~~~~~~~~~ New Setting ~~~~~~~~~~~~~~~ Old Setting ~~~~~~~~~~~~~~~~~ Default ~~~~~~~~~~~~~~~~~~ -- Setting ~~~~~~~~~~~~~~~~~~~~~~~ New Setting ~~~~~~~~~~~~~~~ Old Setting ~~~~~~~~~~~~~~~~~ Default ~~~~~~~~~~~~~~~~~~
shadowStyle.edgeFile = style.edgeFile or shadowStyle.edgeFile or getMedia("border", "shadow") shadowStyle.edgeFile = style.edgeFile or shadowStyle.edgeFile or getMedia("border", "shadow")
shadowStyle.edgeSize = style.edgeSize or shadowStyle.edgeSize or 28 shadowStyle.edgeSize = style.edgeSize or shadowStyle.edgeSize or 28
@ -5146,7 +5107,7 @@ function DiesalStyle:UpdateObjectStyle(object, name, style)
local textures = {} local textures = {}
for i = 1, #OUTLINES do for i = 1, #OUTLINES do
local texture = object.textures[name .. OUTLINES[i]] local texture = object.textures[name .. OUTLINES[i]]
if not texture then if type(texture) == "nil" then
texture = newTexture() texture = newTexture()
object.textures[name .. OUTLINES[i]] = texture object.textures[name .. OUTLINES[i]] = texture
end end
@ -5157,6 +5118,7 @@ function DiesalStyle:UpdateObjectStyle(object, name, style)
return return
end end
if styleType == "Shadow" then if styleType == "Shadow" then
---@cast object Diesal.Style.ShadowObject
DiesalStyle:StyleShadow(object, frame, style --[[ @as Diesal.Style.ShadowStyle ]]) DiesalStyle:StyleShadow(object, frame, style --[[ @as Diesal.Style.ShadowStyle ]])
return return
end end

Loading…
Cancel
Save