portoform barrier and division by zero fix, framework update

This commit is contained in:
Tercio Jose
2022-10-05 19:19:19 -03:00
parent 54510ee298
commit 35a79b4014
5 changed files with 1054 additions and 808 deletions
+151 -153
View File
@@ -943,75 +943,77 @@ local ButtonMetaFunctions = _G[DF.GlobalWidgetControlNames ["button"]]
------------------------------------------------------------------------------------------------------------
function ButtonMetaFunctions:SetTemplate (template)
if (type (template) == "string") then
template = DF:GetTemplate ("button", template)
function ButtonMetaFunctions:SetTemplate(template)
if (type(template) == "string") then
template = DF:GetTemplate("button", template)
end
if (not template) then
DF:Error ("template not found")
DF:Error("template not found")
return
end
if (template.width) then
self:SetWidth (template.width)
self:SetWidth(template.width)
end
if (template.height) then
self:SetHeight (template.height)
self:SetHeight(template.height)
end
if (template.backdrop) then
self:SetBackdrop (template.backdrop)
self:SetBackdrop(template.backdrop)
end
if (template.backdropcolor) then
local r, g, b, a = DF:ParseColors (template.backdropcolor)
self:SetBackdropColor (r, g, b, a)
local r, g, b, a = DF:ParseColors(template.backdropcolor)
self:SetBackdropColor(r, g, b, a)
self.onleave_backdrop = {r, g, b, a}
end
if (template.backdropbordercolor) then
local r, g, b, a = DF:ParseColors (template.backdropbordercolor)
self:SetBackdropBorderColor (r, g, b, a)
local r, g, b, a = DF:ParseColors(template.backdropbordercolor)
self:SetBackdropBorderColor(r, g, b, a)
self.onleave_backdrop_border_color = {r, g, b, a}
end
if (template.onentercolor) then
local r, g, b, a = DF:ParseColors (template.onentercolor)
local r, g, b, a = DF:ParseColors(template.onentercolor)
self.onenter_backdrop = {r, g, b, a}
end
if (template.onleavecolor) then
local r, g, b, a = DF:ParseColors (template.onleavecolor)
local r, g, b, a = DF:ParseColors(template.onleavecolor)
self.onleave_backdrop = {r, g, b, a}
end
if (template.onenterbordercolor) then
local r, g, b, a = DF:ParseColors (template.onenterbordercolor)
local r, g, b, a = DF:ParseColors(template.onenterbordercolor)
self.onenter_backdrop_border_color = {r, g, b, a}
end
if (template.onleavebordercolor) then
local r, g, b, a = DF:ParseColors (template.onleavebordercolor)
local r, g, b, a = DF:ParseColors(template.onleavebordercolor)
self.onleave_backdrop_border_color = {r, g, b, a}
end
if (template.icon) then
local i = template.icon
self:SetIcon (i.texture, i.width, i.height, i.layout, i.texcoord, i.color, i.textdistance, i.leftpadding)
self:SetIcon(i.texture, i.width, i.height, i.layout, i.texcoord, i.color, i.textdistance, i.leftpadding)
end
if (template.textsize) then
self.textsize = template.textsize
end
if (template.textfont) then
self.textfont = template.textfont
end
if (template.textcolor) then
self.textcolor = template.textcolor
end
if (template.textalign) then
self.textalign = template.textalign
end
@@ -1020,183 +1022,179 @@ end
------------------------------------------------------------------------------------------------------------
--> object constructor
local build_button = function (self)
self:SetSize (100, 20)
self.text = self:CreateFontString ("$parent_Text", "ARTWORK", "GameFontNormal")
self.text:SetJustifyH ("CENTER")
DF:SetFontSize (self.text, 10)
self.text:SetPoint ("CENTER", self, "CENTER", 0, 0)
self.texture_disabled = self:CreateTexture ("$parent_TextureDisabled", "OVERLAY")
local createButtonWidgets = function(self)
self:SetSize(100, 20)
self.text = self:CreateFontString("$parent_Text", "ARTWORK", "GameFontNormal")
self.text:SetJustifyH("CENTER")
DF:SetFontSize(self.text, 10)
self.text:SetPoint("CENTER", self, "CENTER", 0, 0)
self.texture_disabled = self:CreateTexture("$parent_TextureDisabled", "OVERLAY")
self.texture_disabled:SetAllPoints()
self.texture_disabled:Hide()
self.texture_disabled:SetTexture ("Interface\\Tooltips\\UI-Tooltip-Background")
self:SetScript ("OnDisable", function (self)
self.texture_disabled:SetTexture("Interface\\Tooltips\\UI-Tooltip-Background")
self:SetScript("OnDisable", function(self)
self.texture_disabled:Show()
self.texture_disabled:SetVertexColor (0, 0, 0)
self.texture_disabled:SetAlpha (.5)
self.texture_disabled:SetVertexColor(0, 0, 0)
self.texture_disabled:SetAlpha(.5)
end)
self:SetScript ("OnEnable", function (self)
self:SetScript("OnEnable", function(self)
self.texture_disabled:Hide()
end)
end
function DF:CreateButton (parent, func, w, h, text, param1, param2, texture, member, name, short_method, button_template, text_template)
return DF:NewButton (parent, parent, name, member, w, h, func, param1, param2, texture, text, short_method, button_template, text_template)
function DF:CreateButton(parent, func, width, height, text, param1, param2, texture, member, name, shortMethod, buttonTemplate, textTemplate)
return DF:NewButton(parent, parent, name, member, width, height, func, param1, param2, texture, text, shortMethod, buttonTemplate, textTemplate)
end
function DF:NewButton (parent, container, name, member, w, h, func, param1, param2, texture, text, short_method, button_template, text_template)
function DF:NewButton(parent, container, name, member, width, height, func, param1, param2, texture, text, shortMethod, buttonTemplate, textTemplate)
if (not name) then
name = "DetailsFrameworkButtonNumber" .. DF.ButtonCounter
DF.ButtonCounter = DF.ButtonCounter + 1
elseif (not parent) then
return error ("Details! FrameWork: parent not found.", 2)
return error("Details! FrameWork: parent not found.", 2)
end
if (not container) then
container = parent
end
if (name:find ("$parent")) then
local parentName = DF.GetParentName (parent)
name = name:gsub ("$parent", parentName)
if (name:find("$parent")) then
local parentName = DF.GetParentName(parent)
name = name:gsub("$parent", parentName)
end
local ButtonObject = {type = "button", dframework = true}
local buttonObject = {type = "button", dframework = true}
if (member) then
parent [member] = ButtonObject
end
parent[member] = buttonObject
end
if (parent.dframework) then
parent = parent.widget
end
if (container.dframework) then
container = container.widget
end
--> default members:
ButtonObject.is_locked = true
ButtonObject.container = container
ButtonObject.options = {OnGrab = false}
ButtonObject.button = CreateFrame ("button", name, parent,"BackdropTemplate")
DF:Mixin (ButtonObject.button, DF.WidgetFunctions)
build_button (ButtonObject.button)
ButtonObject.widget = ButtonObject.button
ButtonObject.button:SetBackdropColor (0, 0, 0, 0.4)
ButtonObject.button:SetBackdropBorderColor (1, 1, 1, 1)
--default members
buttonObject.is_locked = true
buttonObject.container = container
buttonObject.options = {OnGrab = false}
buttonObject.button = CreateFrame("button", name, parent, "BackdropTemplate")
DF:Mixin(buttonObject.button, DF.WidgetFunctions)
createButtonWidgets(buttonObject.button)
buttonObject.widget = buttonObject.button
buttonObject.button:SetBackdropColor(0, 0, 0, 0.4)
buttonObject.button:SetBackdropBorderColor(1, 1, 1, 1)
if (not APIButtonFunctions) then
APIButtonFunctions = true
local idx = getmetatable (ButtonObject.button).__index
for funcName, funcAddress in pairs (idx) do
if (not ButtonMetaFunctions [funcName]) then
ButtonMetaFunctions [funcName] = function (object, ...)
local x = loadstring ( "return _G['"..object.button:GetName().."']:"..funcName.."(...)")
return x (...)
local idx = getmetatable(buttonObject.button).__index
for funcName, funcAddress in pairs(idx) do
if (not ButtonMetaFunctions[funcName]) then
ButtonMetaFunctions[funcName] = function(object, ...)
local x = loadstring("return _G['"..object.button:GetName().."']:"..funcName.."(...)")
return x(...)
end
end
end
end
ButtonObject.button:SetWidth (w or 100)
ButtonObject.button:SetHeight (h or 20)
ButtonObject.button.MyObject = ButtonObject
ButtonObject.text_overlay = _G [name .. "_Text"]
ButtonObject.disabled_overlay = _G [name .. "_TextureDisabled"]
texture = texture or ""
ButtonObject.button:SetNormalTexture (texture)
ButtonObject.button:SetPushedTexture (texture)
ButtonObject.button:SetDisabledTexture (texture)
ButtonObject.button:SetHighlightTexture (texture, "ADD")
ButtonObject.button.text:SetText (text or "")
ButtonObject.button.text:SetPoint ("center", ButtonObject.button, "center")
buttonObject.button:SetWidth(width or 100)
buttonObject.button:SetHeight(height or 20)
buttonObject.button.MyObject = buttonObject
local text_width = ButtonObject.button.text:GetStringWidth()
if (text_width > w-15 and ButtonObject.button.text:GetText() ~= "") then
if (short_method == false) then --> if is false, do not use auto resize
buttonObject.text_overlay = _G[name .. "_Text"]
buttonObject.disabled_overlay = _G[name .. "_TextureDisabled"]
texture = texture or ""
buttonObject.button:SetNormalTexture(texture)
buttonObject.button:SetPushedTexture(texture)
buttonObject.button:SetDisabledTexture(texture)
buttonObject.button:SetHighlightTexture(texture, "ADD")
buttonObject.button.text:SetText(text or "")
buttonObject.button.text:SetPoint("center", buttonObject.button, "center")
local textWidth = buttonObject.button.text:GetStringWidth()
if (textWidth > width - 15 and buttonObject.button.text:GetText() ~= "") then
if (shortMethod == false) then --> if is false, do not use auto resize
--do nothing
elseif (not short_method) then --> if the value is omitted, use the default resize
local new_width = text_width+15
ButtonObject.button:SetWidth (new_width)
elseif (short_method == 1) then
elseif (not shortMethod) then --> if the value is omitted, use the default resize
local new_width = textWidth + 15
buttonObject.button:SetWidth(new_width)
elseif (shortMethod == 1) then
local loop = true
local textsize = 11
while (loop) do
if (text_width+15 < w or textsize < 8) then
if (textWidth + 15 < width or textsize < 8) then
loop = false
break
else
DF:SetFontSize (ButtonObject.button.text, textsize)
text_width = ButtonObject.button.text:GetStringWidth()
DF:SetFontSize(buttonObject.button.text, textsize)
textWidth = buttonObject.button.text:GetStringWidth()
textsize = textsize - 1
end
end
elseif (short_method == 2) then
elseif (shortMethod == 2) then
end
end
ButtonObject.func = func or cleanfunction
ButtonObject.funcright = cleanfunction
ButtonObject.param1 = param1
ButtonObject.param2 = param2
ButtonObject.short_method = short_method
if (text_template) then
if (text_template.size) then
DF:SetFontSize (ButtonObject.button.text, text_template.size)
buttonObject.func = func or cleanfunction
buttonObject.funcright = cleanfunction
buttonObject.param1 = param1
buttonObject.param2 = param2
buttonObject.short_method = shortMethod
if (textTemplate) then
if (textTemplate.size) then
DF:SetFontSize(buttonObject.button.text, textTemplate.size)
end
if (text_template.color) then
local r, g, b, a = DF:ParseColors (text_template.color)
ButtonObject.button.text:SetTextColor (r, g, b, a)
if (textTemplate.color) then
local r, g, b, a = DF:ParseColors(textTemplate.color)
buttonObject.button.text:SetTextColor(r, g, b, a)
end
if (text_template.font) then
local SharedMedia = LibStub:GetLibrary ("LibSharedMedia-3.0")
local font = SharedMedia:Fetch ("font", text_template.font)
DF:SetFontFace (ButtonObject.button.text, font)
if (textTemplate.font) then
local SharedMedia = LibStub:GetLibrary("LibSharedMedia-3.0")
local font = SharedMedia:Fetch("font", textTemplate.font)
DF:SetFontFace(buttonObject.button.text, font)
end
end
--> hooks
ButtonObject.HookList = {
OnEnter = {},
OnLeave = {},
OnHide = {},
OnShow = {},
OnMouseDown = {},
OnMouseUp = {},
}
ButtonObject.button:SetScript ("OnEnter", OnEnter)
ButtonObject.button:SetScript ("OnLeave", OnLeave)
ButtonObject.button:SetScript ("OnHide", OnHide)
ButtonObject.button:SetScript ("OnShow", OnShow)
ButtonObject.button:SetScript ("OnMouseDown", OnMouseDown)
ButtonObject.button:SetScript ("OnMouseUp", OnMouseUp)
_setmetatable (ButtonObject, ButtonMetaFunctions)
if (button_template) then
ButtonObject:SetTemplate (button_template)
--hooks
buttonObject.HookList = {
OnEnter = {},
OnLeave = {},
OnHide = {},
OnShow = {},
OnMouseDown = {},
OnMouseUp = {},
}
buttonObject.button:SetScript("OnEnter", OnEnter)
buttonObject.button:SetScript("OnLeave", OnLeave)
buttonObject.button:SetScript("OnHide", OnHide)
buttonObject.button:SetScript("OnShow", OnShow)
buttonObject.button:SetScript("OnMouseDown", OnMouseDown)
buttonObject.button:SetScript("OnMouseUp", OnMouseUp)
setmetatable(buttonObject, ButtonMetaFunctions)
if (buttonTemplate) then
buttonObject:SetTemplate(buttonTemplate)
end
return ButtonObject
return buttonObject
end
local pickcolor_callback = function (self, r, g, b, a, button)
+594 -577
View File
File diff suppressed because it is too large Load Diff
+305 -75
View File
@@ -1,9 +1,7 @@
--todo: GetText(addonId, phraseId)
--todo: SetText(addonId, phraseId, FontString, ...)
--todo: need to send a callback when setting a new language, this will be used by the volatile menu to refresh the menu
--[=[
DetailsFramework.Language.Register(addonId, languageId, gameLanguageOnly)
DetailsFramework.Language.Register(addonId, languageId[, gameLanguageOnly])
create a language table within an addon namespace
@addonId: an identifier, can be any table or string, will be used when getting the table with phrase translations, example: "DetailsLocalization", "Details", "PlaterLoc", _G.Plater
@languageId: game languages: "deDE", "enUS", "esES", "esMX", "frFR", "itIT", "koKR", "ptBR", "ruRU", "zhCN", "zhTW", or any other value if 'gameLanguageOnly' is false (default)
@@ -19,7 +17,7 @@
local newLanguageTable = DetailsFramework.Language.Register(_G.Details, "valyrianValyria", false)
newLanguageTable["STRING_MY_PHRASE"] = "ñuha udrir"
DetailsFramework.Language.GetLanguageTable(addonId, languageId)
DetailsFramework.Language.GetLanguageTable(addonId[, languageId])
get the languageTable for the requested languageId within the addon namespace
if languageId is not passed, uses the current language set for the addonId
the default languageId for the addon is the first language registered with DetailsFramework.Language.Register()
@@ -36,18 +34,24 @@
local languageTable = DetailsFramework.Language.GetLanguageTable("Details", "valyrianValyria")
fontString:SetText(languageTable["STRING_MY_PHRASE"])
DetailsFramework.Language.GetText(addonId, phraseId[, silent])
get a text from a registered addonId and phraseId
@addonId: an identifier, can be any table or string, will be used when getting the table with phrase translations, example: "DetailsLocalization", "Details", "PlaterLoc", _G.Plater
@phraseId: any string to identify the a translated text, example: phraseId: "OPTIONS_FRAME_WIDTH" text: "Adjust the Width of the frame."
@silent: if true won't error on invalid phrase text and instead use the phraseId as the text, it will still error on invalid addonId
DetailsFramework.Language.SetCurrentLanguage(addonId, languageId)
set the language used by default when retriving a languageTable with DF.Language.GetLanguageTable() and not passing the second argument (languageId) within the call
use this in combination with a savedVariable to use a language of the user choice
@addonId: an identifier, can be any table or string, will be used when getting the table with phrase translations, example: "DetailsLocalization", "Details", "PlaterLoc", _G.Plater
@languageId: game languages: "deDE", "enUS", "esES", "esMX", "frFR", "itIT", "koKR", "ptBR", "ruRU", "zhCN", "zhTW", or any other value if 'gameLanguageOnly' is false (default)
DetailsFramework.Language.RegisterFontString(addonId, fontString, phraseId, silent, ...)
DetailsFramework.Language.RegisterFontString(addonId, fontString, phraseId[, silent[, ...]])
when setting a languageId with DetailsFramework.Language.SetCurrentLanguage(), automatically change the text of all registered FontStrings
@addonId: an identifier, can be any table or string, will be used when getting the table with phrase translations, example: "DetailsLocalization", "Details", "PlaterLoc", _G.Plater
@fontString: a UIObject FontString
@phraseId: any string to identify the a translated text, example: "My Phrase", "STRING_TEXT_LENGTH", text: "This is my phrase"
@silent: if true won't error on invalid phrase text and instead use the phraseId as the text, it will still error on invalid addonId
@silent: if true won't error on invalid phrase text and instead use the phraseId as the text, it will still error on invalid addonId and fontString
@vararg: arguments to pass for format(text, ...)
DetailsFramework.Language.UpdateFontStringArguments(addonId, fontString, ...)
@@ -57,6 +61,24 @@
@addonId: an identifier, can be any table or string, will be used when getting the table with phrase translations, example: "DetailsLocalization", "Details", "PlaterLoc", _G.Plater
@fontString: a UIObject FontString
@vararg: arguments to pass for format(text, ...)
DetailsFramework.Language.RegisterTableKey(addonId, table, key, phraseId[, silent[, ...]])
when setting a languageId with DetailsFramework.Language.SetCurrentLanguage(), automatically change the text of all registered tables, table[key] = 'new translated text'
@addonId: an identifier, can be any table or string, will be used when getting the table with phrase translations, example: "DetailsLocalization", "Details", "PlaterLoc", _G.Plater
@table: a lua table
@key: any value except nil or boolean
@phraseId: any string to identify the a translated text, example: token: "OPTIONS_FRAME_WIDTH" text: "Adjust the Width of the frame."
@silent: if true won't error on invalid phrase text or table already registered, it will still error on invalid addonId, table, key and phraseId
@vararg: arguments to pass for format(text, ...)
DetailsFramework.Language.UpdateTableKeyArguments(addonId, table, key, ...)
--same as UpdateFontStringArguments() but for table keys
@addonId: an identifier, can be any table or string, will be used when getting the table with phrase translations, example: "DetailsLocalization", "Details", "PlaterLoc", _G.Plater
@table: a lua table
@key: any value except nil or boolean
@vararg: arguments to pass for format(text, ...)
--]=]
local DF = _G["DetailsFramework"]
@@ -81,12 +103,14 @@ local supportedGameLanguages = {
}
local functionSignature = {
["RegisterLanguage"] = "RegisterLanguage(addonID, languageID [, gameLanguageOnly])",
["RegisterLanguage"] = "RegisterLanguage(addonID, languageID[, gameLanguageOnly])",
["SetCurrentLanguage"] = "SetCurrentLanguage(addonID, languageID)",
["GetLanguageTable"] = "GetLanguageTable(addonID [, languageID])",
["RegisterFontString"] = "RegisterFontString(addonID, fontString, phraseID [, silent] [, ...]])",
["GetLanguageTable"] = "GetLanguageTable(addonID[, languageID])",
["RegisterFontString"] = "RegisterFontString(addonID, fontString, phraseID[, silent[, ...]])",
["UpdateFontStringArguments"] = "UpdateFontStringArguments(addonID, fontString, ...)",
["GetText"] = "GetText(addonID, phraseID [, silent])",
["RegisterTableKey"] = "RegisterTableKey(addonId, table, key, phraseId[[, silent[, ...]])",
["GetText"] = "GetText(addonID, phraseID[, silent])",
["UpdateTableKeyArguments"] = "UpdateTableKeyArguments(addonId, table, key, ...)",
}
local functionCallPath = {
@@ -96,6 +120,8 @@ local functionCallPath = {
["RegisterFontString"] = "DetailsFramework.Language.RegisterFontString",
["UpdateFontStringArguments"] = "DetailsFramework.Language.UpdateFontStringArguments",
["GetText"] = "DetailsFramework.Language.GetText",
["RegisterTableKey"] = "DetailsFramework.Language.RegisterTableKey",
["UpdateTableKeyArguments"] = "DetailsFramework.Language.UpdateTableKeyArguments",
}
local errorText = {
@@ -107,16 +133,20 @@ local errorText = {
["PhraseIDNotRegistered"] = "phraseID not registered",
["FontString"] = "require a FontString on #%d argument",
["FontStringNotRegistered"] = "FontString not registered yet",
["TableKeyNotRegistered"] = "table not registered yet",
["KeyNotRegistered"] = "key not registered yet",
["InvalidTable"] = "require a table on #%d argument",
["InvalidTableKey"] = "require a table key on #%d argument",
["TableKeyAlreadyRegistered"] = "table already registered", --not in use
}
--create languages namespace
DF.Language = {
RegisteredNamespaces = {},
}
--create language namespace
DF.Language = DF.Language or {version = 1}
DF.Language.RegisteredNamespaces = DF.Language.RegisteredNamespaces or {}
--internal functions
local isValid_AddonID = function(addonId)
if (type(addonId) ~= "string" and type(addonId) ~= "table") then
return false
@@ -146,10 +176,15 @@ local getOrCreateAddonNamespace = function(addonId, languageId)
if (not addonNamespaceTable) then
addonNamespaceTable = {
addonId = addonId,
--by default, the current language is the first registered language
currentLanguageId = languageId,
languages = {},
fontStrings = {},
tableKeys = setmetatable({}, {__mode = "k"}),
--set when the first language table is registered
defaultLanguageTable = nil,
}
DF.Language.RegisteredNamespaces[addonId] = addonNamespaceTable
end
@@ -181,6 +216,8 @@ local getCurrentLanguageId = function(addonNamespaceTable)
return addonNamespaceTable.currentLanguageId
end
--if invalid, the __index from the metatable get the value from the first registered table
--will return nil if the languageTable is from the first registered language
local getTextFromLangugeTable = function(languageTable, phraseId)
return languageTable[phraseId]
end
@@ -190,8 +227,8 @@ local getRegisteredFontStrings = function(addonNamespaceTable)
end
local getText = function(addonNamespaceTable, phraseId)
local currentLanguageId = getCurrentLanguageId(addonNamespaceTable) --never nil
local languageTable = getLanguageTable(addonNamespaceTable, currentLanguageId) --can be nil if the languageId isn't registered yet
local currentLanguageId = getCurrentLanguageId(addonNamespaceTable)
local languageTable = getLanguageTable(addonNamespaceTable, currentLanguageId)
--if the languageTable is invalid, let the function caller handle it
--note: languageTable is always valid when the callstack started at from DF.Language.SetCurrentLanguage
@@ -199,7 +236,9 @@ local getText = function(addonNamespaceTable, phraseId)
return false
end
local text = getTextFromLangugeTable(languageTable, phraseId)
--by using getTextFromLangugeTable the metatable will get the default of the first registered language
--local text = getTextFromLangugeTable(languageTable, phraseId)
local text = rawget(languageTable, phraseId)
if (isValid_Text(text)) then
return text
end
@@ -208,18 +247,24 @@ local getText = function(addonNamespaceTable, phraseId)
local clientLanguage = GetLocale()
if (currentLanguageId ~= clientLanguage) then
languageTable = getLanguageTable(addonNamespaceTable, clientLanguage)
text = getTextFromLangugeTable(languageTable, phraseId)
if (isValid_Text(text)) then
return text
if (languageTable) then
--text = getTextFromLangugeTable(languageTable, phraseId)
text = rawget(languageTable, phraseId)
if (isValid_Text(text)) then
return text
end
end
end
--attempt to get from english
if (currentLanguageId ~= CONST_LANGAGEID_ENUS and clientLanguage ~= CONST_LANGAGEID_ENUS) then
languageTable = getLanguageTable(addonNamespaceTable, CONST_LANGAGEID_ENUS)
text = getTextFromLangugeTable(languageTable, phraseId)
if (isValid_Text(text)) then
return text
if (languageTable) then
--text = getTextFromLangugeTable(languageTable, phraseId)
text = rawget(languageTable, phraseId)
if (isValid_Text(text)) then
return text
end
end
end
@@ -227,6 +272,14 @@ local getText = function(addonNamespaceTable, phraseId)
end
local setLanguageTable = function(addonNamespaceTable, languageId, languageTable)
local isFirstLanguage = not next(addonNamespaceTable.languages)
if (isFirstLanguage) then
addonNamespaceTable.defaultLanguageTable = languageTable
else
local defaultLanguageMetatable = {__index = function(table, key) return addonNamespaceTable.defaultLanguageTable[key] or key end}
setmetatable(languageTable, defaultLanguageMetatable)
end
addonNamespaceTable.languages[languageId] = languageTable
return languageTable
end
@@ -235,11 +288,7 @@ local setCurrentLanguageId = function(addonNamespaceTable, languageId)
addonNamespaceTable.currentLanguageId = languageId
end
local getFontStringTable = function(addonNamespaceTable, fontString)
return addonNamespaceTable.fontStrings[fontString]
end
local parseFontStringArguments = function(...)
local parseArguments = function(...)
local argumentAmount = select("#", ...)
if (argumentAmount > 0) then
return {...}
@@ -248,12 +297,30 @@ local parseFontStringArguments = function(...)
end
end
local updateFontStringTable_Arguments = function(fontStringTable, ...)
fontStringTable.arguments = parseFontStringArguments(...)
--hold information about a localization, used by registered fontStrings and keyTables, has .phraesId, .arguments and .key (on keyTables)
local createPhraseInfoTable = function(phraseId, key, ...)
return {phraseId = phraseId, key = key, arguments = parseArguments(...)}
end
local updateFontStringTable_PhraseId = function(fontStringTable, phraseId)
fontStringTable.phraseId = phraseId
local updatePhraseInfoArguments = function(phraseInfoTable, ...)
phraseInfoTable.arguments = parseArguments(...)
end
--get a phraseInfo and text returning a formatted text using arguments if they exists
local getFormattedText = function(phraseInfoTable, text)
if (phraseInfoTable.arguments) then
return format(text, unpack(phraseInfoTable.arguments))
else
return text
end
end
local updateFontStringTable_PhraseId = function(phraseInfoTable, phraseId)
phraseInfoTable.phraseId = phraseId
end
local getFontStringPhraseInfoTable = function(addonNamespaceTable, fontString)
return addonNamespaceTable.fontStrings[fontString]
end
local setFontString_InternalMembers = function(fontString, addonId, phraseId, arguments)
@@ -262,12 +329,9 @@ local setFontString_InternalMembers = function(fontString, addonId, phraseId, ar
fontString.__languageArguments = arguments or fontString.__languageArguments
end
local setFontString_Text = function(fontString, fontStringTable, text)
if (fontStringTable.arguments) then
fontString:SetText(format(text, unpack(fontStringTable.arguments)))
else
fontString:SetText(text)
end
local setFontString_Text = function(fontString, phraseInfoTable, text)
local formattedText = getFormattedText(phraseInfoTable, text)
fontString:SetText(formattedText)
end
--this method only exists on registered FontStrings
@@ -275,39 +339,109 @@ local fontStringMethod_SetTextByPhraseID = function(fontString, phraseId, ...)
local addonId = fontString.__languageAddonId
local addonNamespaceTable = getAddonNamespace(addonId)
local fontStringTable = getFontStringTable(addonNamespaceTable, fontString)
updateFontStringTable_PhraseId(fontStringTable, phraseId)
updateFontStringTable_Arguments(fontStringTable, ...)
setFontString_InternalMembers(fontString, addonId, phraseId, fontStringTable.arguments)
local phraseInfoTable = getFontStringPhraseInfoTable(addonNamespaceTable, fontString)
updateFontStringTable_PhraseId(phraseInfoTable, phraseId)
updatePhraseInfoArguments(phraseInfoTable, ...)
setFontString_InternalMembers(fontString, addonId, phraseId, phraseInfoTable.arguments)
local text = getText(addonNamespaceTable, phraseId)
setFontString_Text(fontString, fontStringTable, text)
setFontString_Text(fontString, phraseInfoTable, text)
return true
end
local registerFontString = function(addonNamespaceTable, fontString, phraseId, ...)
local fontStringTable = {phraseId = phraseId}
fontStringTable.arguments = parseFontStringArguments(...)
addonNamespaceTable.fontStrings[fontString] = fontStringTable
local phraseInfoTable = createPhraseInfoTable(phraseId, nil, ...)
addonNamespaceTable.fontStrings[fontString] = phraseInfoTable
--save internal information about the language directly in the FontString
setFontString_InternalMembers(fontString, addonNamespaceTable.addonId, phraseId, fontStringTable.arguments)
setFontString_InternalMembers(fontString, addonNamespaceTable.addonId, phraseId, phraseInfoTable.arguments)
fontString.SetTextByPhraseID = fontStringMethod_SetTextByPhraseID
return fontStringTable
return phraseInfoTable
end
--iterate among all registered fontStrings of an addon namespace and set the new text on them
local updateAllRegisteredFontStringText = function(addonNamespaceTable, languageTable)
local updateAllRegisteredFontStringText = function(addonNamespaceTable)
local fontStrings = getRegisteredFontStrings(addonNamespaceTable)
for fontString, fontStringTable in pairs(fontStrings) do
local phraseId = fontStringTable.phraseId
for fontString, phraseInfoTable in pairs(fontStrings) do
local phraseId = phraseInfoTable.phraseId
--note: text is always valid when the callstack started at from DF.Language.SetCurrentLanguage
local text = getText(addonNamespaceTable, phraseId)
setFontString_Text(fontString, fontStringTable, text)
setFontString_Text(fontString, phraseInfoTable, text)
end
end
--internal tableKey looks like:
--addonNamespaceTable.tableKeys = {} -> this table is a weaktable 'k'
--addonNamespaceTable.tableKeys[table] = {} -> table is a table from code elsewhere, it is used as a key for the internal code here, table created is what stores the keys
--addonNamespaceTable.tableKeys[table][key] -> key is the key from the table elsewhere which points to a string
--addonNamespaceTable.tableKeys[table][key] = {phraseId = phraseId, arguments = {...}, key = key}
--when registring a tableKey in practice, look like:
--Details.StoredStrings = {}; Details.StoredStrings["Height"] = "height": table is 'Details.StoredStrings' key is "Height"
--registerTableKey(_, Details.StoredStrings, "Height", _, _)
local setTableKey_Text = function(table, key, phraseInfoTable, text)
local formattedText = getFormattedText(phraseInfoTable, text)
table[key] = formattedText
end
local getTableKeyTable = function(addonNamespaceTable, table)
return addonNamespaceTable.tableKeys[table]
end
--get the phraseInfo from the addon namespace
local getTableKeyPhraseInfoTable = function(addonNamespaceTable, table, key)
return addonNamespaceTable.tableKeys[table][key]
end
--get the phraseInfo from the tableKey
local getPhraseInfoFromTableKey = function(tableKeyTable, key)
return tableKeyTable[key]
end
local isTableKeyRegistered = function(addonNamespaceTable, table)
return getTableKeyTable(addonNamespaceTable, table) and true
end
--return true if the phraseInfo is present in the tableKey
local isKeyRegisteredInTableKey = function(tableKeyTable, key)
return getPhraseInfoFromTableKey(tableKeyTable, key) and true
end
local getRegisteredTableKeys = function(addonNamespaceTable)
return addonNamespaceTable.tableKeys
end
local registerTableKeyTable = function(addonNamespaceTable, table, tableKeyTable)
addonNamespaceTable.tableKeys[table] = tableKeyTable
end
local registerTableKey = function(addonNamespaceTable, table, key, phraseId, ...)
local tableKeyTable = getTableKeyTable(addonNamespaceTable, table)
if (not tableKeyTable) then
tableKeyTable = {}
registerTableKeyTable(addonNamespaceTable, table, tableKeyTable)
end
--create a table for this table key as a table can hold several keys with localization strings
local phraseInfoTable = createPhraseInfoTable(phraseId, key, ...)
tableKeyTable[key] = phraseInfoTable
return tableKeyTable
end
--iterate among all registered tableKey of an addon namespace and set the new text on them
local updateAllRegisteredTableKeyText = function(addonNamespaceTable)
local tableKeys = getRegisteredTableKeys(addonNamespaceTable)
for table, tableKeyTable in pairs(tableKeys) do
for key, phraseInfoTable in pairs(tableKeyTable) do
local phraseId = phraseInfoTable.phraseId
--note: text is always valid when the callstack started at from DF.Language.SetCurrentLanguage
local text = getText(addonNamespaceTable, phraseId)
setTableKey_Text(table, key, phraseInfoTable, text)
end
end
end
@@ -386,16 +520,46 @@ function DF.Language.SetCurrentLanguage(addonId, languageId)
setCurrentLanguageId(languageId)
--go into the registered FontStrings and change their text
updateAllRegisteredFontStringText(addonNamespaceTable, languageTable)
--go into the registered FontStrings and KeyTables and change their text
updateAllRegisteredFontStringText(addonNamespaceTable)
updateAllRegisteredTableKeyText(addonNamespaceTable)
return true
end
--@addonId: an identifier, can be any table or string, will be used when getting the table with phrase translations, example: "DetailsLocalization", "Details", "PlaterLoc", _G.Plater
--@phraseId: any string to identify the a translated text, example: phraseId: "OPTIONS_FRAME_WIDTH" text: "Adjust the Width of the frame."
--@silent: if true won't error on invalid phrase text and instead use the phraseId as the text, it will still error on invalid addonId
function DF.Language.GetText(addonId, phraseId, silent)
if (not isValid_AddonID(addonId)) then
error(functionCallPath["GetText"] .. ": " .. format(errorText["AddonID"], 1) .. ", use: " .. functionSignature["GetText"] .. ".")
elseif (not isValid_PhraseID(phraseId)) then
error(functionCallPath["GetText"] .. ": " .. format(errorText["PhraseID"], 2) .. ", use: " .. functionSignature["GetText"] .. ".")
end
local addonNamespaceTable = getAddonNamespace(addonId)
if (not addonNamespaceTable) then
error(functionCallPath["GetText"] .. ": " .. errorText["NoLanguages"] .. ", use: " .. functionSignature["RegisterLanguage"] .. ".")
end
local text = getText(addonNamespaceTable, phraseId)
if (isValid_Text(text)) then
return text
end
if (not silent) then
error(functionCallPath["GetText"] .. ": " .. errorText["PhraseIDNotRegistered"] .. ", use: " .. functionSignature["GetLanguageTable"] .. "['PhraseID'] = 'translated text'.")
end
return phraseId
end
--@addonId: an identifier, can be any table or string, will be used when getting the table with phrase translations, example: "DetailsLocalization", "Details", "PlaterLoc", _G.Plater
--@fontString: a UIObject FontString
--@phraseId: any string to identify the a translated text, example: token: "OPTIONS_FRAME_WIDTH" text: "Adjust the Width of the frame."
--@silent: if true won't error on invalid phrase text and instead use the phraseId as the text, it will still error on invalid addonId
--@silent: if true won't error on invalid phrase text and instead use the phraseId as the text, it will still error on invalid addonId and fontString
--@vararg: arguments to pass for format(text, ...)
function DF.Language.RegisterFontString(addonId, fontString, phraseId, silent, ...)
if (not isValid_AddonID(addonId)) then
@@ -448,42 +612,108 @@ function DF.Language.UpdateFontStringArguments(addonId, fontString, ...)
error(functionCallPath["UpdateFontStringArguments"] .. ": " .. format(errorText["FontString"], 2) .. ", use: " .. functionSignature["UpdateFontStringArguments"] .. ".")
end
local fontStringTable = getFontStringTable(addonNamespaceTable, fontString)
if (not fontStringTable) then
local phraseInfoTable = getFontStringPhraseInfoTable(addonNamespaceTable, fontString)
if (not phraseInfoTable) then
error(functionCallPath["UpdateFontStringArguments"] .. ": " .. errorText["FontStringNotRegistered"] .. ", use: " .. functionSignature["RegisterFontString"] .. ".")
end
updateFontStringTable_Arguments(fontStringTable, ...)
updatePhraseInfoArguments(phraseInfoTable, ...)
local text = getText(addonNamespaceTable, fontStringTable.phraseId)
setFontString_Text(fontString, fontStringTable, text)
local text = getText(addonNamespaceTable, phraseInfoTable.phraseId)
setFontString_Text(fontString, phraseInfoTable, text)
return true
end
--@addonId: an identifier, can be any table or string, will be used when getting the table with phrase translations, example: "DetailsLocalization", "Details", "PlaterLoc", _G.Plater
--@phraseId: any string to identify the a translated text, example: phraseId: "OPTIONS_FRAME_WIDTH" text: "Adjust the Width of the frame."
--@silent: if true won't error on invalid phrase text and instead use the phraseId as the text, it will still error on invalid addonId
function DF.Language.GetText(addonId, phraseId, silent)
--@table: a lua table
--@key: any value except nil or boolean
--@phraseId: any string to identify the a translated text, example: token: "OPTIONS_FRAME_WIDTH" text: "Adjust the Width of the frame."
--@silent: if true won't error on invalid phrase text or table already registered, it will still error on invalid addonId, table, key and phraseId
--@vararg: arguments to pass for format(text, ...)
function DF.Language.RegisterTableKey(addonId, table, key, phraseId, silent, ...)
if (not isValid_AddonID(addonId)) then
error(functionCallPath["GetText"] .. ": " .. format(errorText["AddonID"], 1) .. ", use: " .. functionSignature["GetText"] .. ".")
error(functionCallPath["RegisterTableKey"] .. ": " .. format(errorText["AddonID"], 1) .. ", use: " .. functionSignature["RegisterTableKey"] .. ".")
end
elseif (not isValid_PhraseID(phraseId)) then
error(functionCallPath["GetText"] .. ": " .. format(errorText["PhraseID"], 2) .. ", use: " .. functionSignature["GetText"] .. ".")
if (type(table) ~= "table") then
error(functionCallPath["RegisterTableKey"] .. ": " .. format(errorText["InvalidTable"], 2) .. ", use: " .. functionSignature["RegisterTableKey"] .. ".")
end
if (key == nil or type(key) == "boolean") then
error(functionCallPath["RegisterTableKey"] .. ": " .. format(errorText["InvalidTableKey"], 3) .. ", use: " .. functionSignature["RegisterTableKey"] .. ".")
end
if (not isValid_PhraseID(phraseId)) then
error(functionCallPath["RegisterTableKey"] .. ": " .. format(errorText["PhraseID"], 4) .. ", use: " .. functionSignature["RegisterTableKey"] .. ".")
end
local addonNamespaceTable = getAddonNamespace(addonId)
if (not addonNamespaceTable) then
error(functionCallPath["GetText"] .. ": " .. errorText["NoLanguages"] .. ", use: " .. functionSignature["RegisterLanguage"] .. ".")
error(functionCallPath["RegisterTableKey"] .. ": " .. errorText["NoLanguages"] .. ", use: " .. functionSignature["RegisterLanguage"] .. ".")
end
local tableKeyTable = registerTableKey(addonNamespaceTable, table, key, phraseId, ...)
local text = getText(addonNamespaceTable, phraseId)
if (isValid_Text(text)) then
return text
if (not isValid_Text(text)) then
if (not silent) then
error(functionCallPath["RegisterTableKey"] .. ": " .. errorText["PhraseIDNotRegistered"] .. ", use: " .. functionSignature["GetLanguageTable"] .. "['PhraseID'] = 'translated text'.")
else
text = phraseId
end
end
if (not silent) then
error(functionCallPath["GetText"] .. ": " .. errorText["PhraseIDNotRegistered"] .. ", use: " .. functionSignature["GetLanguageTable"] .. "['PhraseID'] = 'translated text'.")
setTableKey_Text(table, key, tableKeyTable, text)
return true
end
--@addonId: an identifier, can be any table or string, will be used when getting the table with phrase translations, example: "DetailsLocalization", "Details", "PlaterLoc", _G.Plater
--@table: a lua table
--@key: any value except nil or boolean
--@vararg: arguments to pass for format(text, ...)
function DF.Language.UpdateTableKeyArguments(addonId, table, key, ...)
if (not isValid_AddonID(addonId)) then
error(functionCallPath["UpdateTableKeyArguments"] .. ": " .. format(errorText["AddonID"], 1) .. ", use: " .. functionSignature["UpdateTableKeyArguments"] .. ".")
end
return phraseId
local addonNamespaceTable = getAddonNamespace(addonId)
if (not addonNamespaceTable) then
error(functionCallPath["UpdateTableKeyArguments"] .. ": " .. errorText["NoLanguages"] .. ", use: " .. functionSignature["RegisterLanguage"] .. ".")
end
if (type(table) ~= "table") then
error(functionCallPath["UpdateTableKeyArguments"] .. ": " .. format(errorText["InvalidTable"], 2) .. ", use: " .. functionSignature["UpdateTableKeyArguments"] .. ".")
end
if (key == nil or type(key) == "boolean") then
error(functionCallPath["UpdateTableKeyArguments"] .. ": " .. format(errorText["InvalidTableKey"], 3) .. ", use: " .. functionSignature["UpdateTableKeyArguments"] .. ".")
end
if (not isTableKeyRegistered(addonNamespaceTable, table)) then
error(functionCallPath["UpdateTableKeyArguments"] .. ": " .. errorText["TableKeyNotRegistered"] .. ", use: " .. functionSignature["RegisterTableKey"] .. ".")
end
local tableKeyTable = getTableKeyTable(addonNamespaceTable, table) --can't nil as the line above checked if it exists
if (not isKeyRegisteredInTableKey(tableKeyTable, key)) then
error(functionCallPath["UpdateTableKeyArguments"] .. ": " .. errorText["KeyNotRegistered"] .. ", use: " .. functionSignature["RegisterTableKey"] .. ".")
end
local phraseInfo = getPhraseInfoFromTableKey(tableKeyTable, key) --can't nil as the line above checked if it exists
updatePhraseInfoArguments(phraseInfo, key, ...)
local text = getText(addonNamespaceTable, phraseInfo.phraseId)
setTableKey_Text(table, key, tableKeyTable, text)
return true
end
function DF.Language.RegisterTableKeyWithDefaultt(addonId, table, key, phraseId, defaultText)
if (addonId and phraseId) then
print("registered...")
DetailsFramework.Language.RegisterTableKey(addonId, table, key, phraseId)
else
print("used default")
table[key] = defaultText
end
end
+3 -3
View File
@@ -2328,8 +2328,8 @@ function atributo_heal:MontaDetalhesHealingDone (spellid, barra)
t1[4] = Loc ["STRING_MINIMUM_SHORT"] .. ": " .. _detalhes:comma_value (esta_magia.n_min)
t1[5] = Loc ["STRING_MAXIMUM_SHORT"] .. ": " .. _detalhes:comma_value (esta_magia.n_max)
t1[6] = Loc ["STRING_AVERAGE"] .. ": " .. _detalhes:comma_value (media_normal)
t1[7] = Loc ["STRING_HPS"] .. ": " .. _detalhes:comma_value (normal_curado/T)
t1[8] = normal_hits .. " / ".. _cstr ("%.1f", normal_hits/total_hits*100) .. "%"
t1[7] = Loc ["STRING_HPS"] .. ": " .. _detalhes:comma_value (normal_curado / max(T, 0.001))
t1[8] = normal_hits .. " / ".. _cstr ("%.1f", normal_hits / max(total_hits, 0.001) * 100) .. "%"
end
@@ -2354,7 +2354,7 @@ function atributo_heal:MontaDetalhesHealingDone (spellid, barra)
t2[5] = Loc ["STRING_MAXIMUM_SHORT"] .. ": " .. _detalhes:comma_value (esta_magia.c_max)
t2[6] = Loc ["STRING_AVERAGE"] .. ": " .. _detalhes:comma_value (media_critico)
t2[7] = Loc ["STRING_HPS"] .. ": " .. _detalhes:comma_value (crit_hps)
t2[8] = esta_magia.c_amt .. " [|cFFC0C0C0".. _cstr ("%.1f", esta_magia.c_amt/total_hits*100) .. "%|r]"
t2[8] = esta_magia.c_amt .. " [|cFFC0C0C0".. _cstr ("%.1f", esta_magia.c_amt / max(total_hits, 0.001) * 100) .. "%|r]"
end
end
+1
View File
@@ -420,6 +420,7 @@
--the damage that the warlock apply to its pet through soullink is ignored
--it is not useful for damage done or friendly fire
[SPELLID_WARLOCK_SOULLINK] = true,
[371597] = true, --Protoform Barrier gotten from an SPELL_ABSORBED cleu event
}
--> expose the ignore spells table to external scripts