mirror of
https://github.com/brues-code/pfUI.git
synced 2026-11-07 02:58:57 +00:00
Load only the client's locale strings; abbreviate numbers through ClassicAPI's numeric formatter; build the module environment once instead of on every load
This commit is contained in:
+23
-30
@@ -1,5 +1,3 @@
|
|||||||
pfUI.api = { }
|
|
||||||
|
|
||||||
-- load pfUI environment
|
-- load pfUI environment
|
||||||
setfenv(1, pfUI:GetEnvironment())
|
setfenv(1, pfUI:GetEnvironment())
|
||||||
|
|
||||||
@@ -450,37 +448,32 @@ function pfUI.api.GetBagFamily(bag)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- [ Abbreviate ]
|
-- [ Abbreviate ]
|
||||||
-- Abbreviates a number from 1234 to 1.23k
|
-- Abbreviates a number from 1234 to 1.23k, as the unitframes.abbrevnum
|
||||||
|
-- setting asks: "0" full numbers, "1" 2 decimals (4250 -> 4.25k),
|
||||||
|
-- "2" 1 decimal rounded down (4250 -> 4.2k)
|
||||||
-- 'number' [number] the number that should be abbreviated
|
-- 'number' [number] the number that should be abbreviated
|
||||||
-- 'returns: [string] the abbreviated value
|
-- 'returns: [string] the abbreviated value
|
||||||
|
local function CreateAbbreviateFormatter(step, rounding)
|
||||||
|
local Down = Enum.NumericRuleFormatRounding.Down
|
||||||
|
local formatter = C_StringUtil.CreateNumericRuleFormatter()
|
||||||
|
formatter:SetBreakpoints({
|
||||||
|
{ threshold = 0, format = "%d", components = { { step = 1, rounding = Down } } },
|
||||||
|
{ threshold = 1000, format = "%gk", components = { { div = 1000, step = step, rounding = rounding } } },
|
||||||
|
{ threshold = 1000000, format = "%gm", components = { { div = 1000000, step = step, rounding = rounding } } },
|
||||||
|
})
|
||||||
|
return formatter
|
||||||
|
end
|
||||||
|
|
||||||
|
local abbreviateFormatters = {
|
||||||
|
["1"] = CreateAbbreviateFormatter(0.01, Enum.NumericRuleFormatRounding.Nearest),
|
||||||
|
["2"] = CreateAbbreviateFormatter(0.1, Enum.NumericRuleFormatRounding.Down),
|
||||||
|
}
|
||||||
|
|
||||||
function pfUI.api.Abbreviate(number)
|
function pfUI.api.Abbreviate(number)
|
||||||
local mode = pfUI_config.unitframes.abbrevnum
|
local formatter = abbreviateFormatters[pfUI_config.unitframes.abbrevnum]
|
||||||
-- mode "0" = disabled (full numbers)
|
if not formatter then return math.floor(number) end
|
||||||
-- mode "1" = 2 decimals (4250 -> 4.25k) [legacy/default]
|
if number < 0 then return "-" .. formatter:FormatNumber(-number) end
|
||||||
-- mode "2" = 1 decimal (4250 -> 4.2k) - always rounds DOWN
|
return formatter:FormatNumber(number)
|
||||||
|
|
||||||
if mode == "1" or mode == "2" then
|
|
||||||
local sign = number < 0 and -1 or 1
|
|
||||||
number = math.abs(number)
|
|
||||||
|
|
||||||
if number > 1000000 then
|
|
||||||
if mode == "2" then
|
|
||||||
-- 1 decimal, round DOWN: 4.18m -> 4.1m
|
|
||||||
return (floor(number/100000) / 10 * sign) .. "m"
|
|
||||||
else
|
|
||||||
return pfUI.api.round(number/1000000*sign, 2) .. "m"
|
|
||||||
end
|
|
||||||
elseif number > 1000 then
|
|
||||||
if mode == "2" then
|
|
||||||
-- 1 decimal, round DOWN: 4180 -> 4.1k (not 4.2k)
|
|
||||||
return (floor(number/100) / 10 * sign) .. "k"
|
|
||||||
else
|
|
||||||
return pfUI.api.round(number/1000*sign, 2) .. "k"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return math.floor(number)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- [ SendChatMessageWide ]
|
-- [ SendChatMessageWide ]
|
||||||
|
|||||||
@@ -1,20 +1,4 @@
|
|||||||
<Ui xmlns="http://www.blizzard.com/wow/ui/">
|
<Ui xmlns="http://www.blizzard.com/wow/ui/">
|
||||||
<Include file="..\env\locales_enUS.lua"/>
|
|
||||||
<Include file="..\env\locales_koKR.lua"/>
|
|
||||||
<Include file="..\env\locales_frFR.lua"/>
|
|
||||||
<Include file="..\env\locales_deDE.lua"/>
|
|
||||||
<Include file="..\env\locales_zhCN.lua"/>
|
|
||||||
<Include file="..\env\locales_esES.lua"/>
|
|
||||||
<Include file="..\env\locales_ruRU.lua"/>
|
|
||||||
|
|
||||||
<Include file="..\env\combatlog_enUS.lua"/>
|
|
||||||
<Include file="..\env\combatlog_koKR.lua"/>
|
|
||||||
<Include file="..\env\combatlog_frFR.lua"/>
|
|
||||||
<Include file="..\env\combatlog_deDE.lua"/>
|
|
||||||
<Include file="..\env\combatlog_zhCN.lua"/>
|
|
||||||
<Include file="..\env\combatlog_esES.lua"/>
|
|
||||||
<Include file="..\env\combatlog_ruRU.lua"/>
|
|
||||||
|
|
||||||
<Include file="..\env\profiles.lua"/>
|
<Include file="..\env\profiles.lua"/>
|
||||||
|
|
||||||
<Include file="..\env\translations_enUS.lua"/>
|
<Include file="..\env\translations_enUS.lua"/>
|
||||||
|
|||||||
@@ -236,7 +236,9 @@ pfUI:RegisterModule("turtle-wow", function ()
|
|||||||
-- castbar.lua reads pfUI.synthetic_casts[unit] as a fallback when
|
-- castbar.lua reads pfUI.synthetic_casts[unit] as a fallback when
|
||||||
-- C_Spell.UnitCastingInfo returns nil.
|
-- C_Spell.UnitCastingInfo returns nil.
|
||||||
pfUI_locale["enUS"]["customcast"]["TRUESHOT"] = "Steady Shot"
|
pfUI_locale["enUS"]["customcast"]["TRUESHOT"] = "Steady Shot"
|
||||||
pfUI_locale["zhCN"]["customcast"]["TRUESHOT"] = "稳固射击"
|
if pfUI_locale["zhCN"] then -- loaded on zhCN clients only
|
||||||
|
pfUI_locale["zhCN"]["customcast"]["TRUESHOT"] = "稳固射击"
|
||||||
|
end
|
||||||
pfUI.synthetic_casts = pfUI.synthetic_casts or {}
|
pfUI.synthetic_casts = pfUI.synthetic_casts or {}
|
||||||
|
|
||||||
local steadyShotName = L["customcast"]["TRUESHOT"]
|
local steadyShotName = L["customcast"]["TRUESHOT"]
|
||||||
|
|||||||
@@ -84,6 +84,13 @@ pfUI.client = INTERFACE_VERSION
|
|||||||
|
|
||||||
-- setup pfUI namespace
|
-- setup pfUI namespace
|
||||||
setmetatable(pfUI.env, {__index = getfenv(0)})
|
setmetatable(pfUI.env, {__index = getfenv(0)})
|
||||||
|
pfUI.env._G = getfenv(0)
|
||||||
|
|
||||||
|
-- every pfUI.api entry is also a global of the pfUI environment
|
||||||
|
pfUI.api = setmetatable({}, {__newindex = function(api, key, value)
|
||||||
|
rawset(api, key, value)
|
||||||
|
pfUI.env[key] = value
|
||||||
|
end})
|
||||||
|
|
||||||
PFUI_CLASS_COLORS = setmetatable({
|
PFUI_CLASS_COLORS = setmetatable({
|
||||||
WARRIOR = { r = 0.78, g = 0.61, b = 0.43 },
|
WARRIOR = { r = 0.78, g = 0.61, b = 0.43 },
|
||||||
@@ -202,46 +209,44 @@ function pfUI:UpdateFonts()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local translations
|
-- the locale table is built on the first call, which comes from the
|
||||||
|
-- api files, after the locale files have loaded
|
||||||
function pfUI:GetEnvironment()
|
function pfUI:GetEnvironment()
|
||||||
-- load api into environment
|
if not pfUI.env.L then
|
||||||
for m, func in pairs(pfUI.api or {}) do
|
local L = pfUI_locale[GetLocale()] or pfUI_locale["enUS"]
|
||||||
pfUI.env[m] = func
|
L["class"] = L["class"] or tInvert(LOCALIZED_CLASS_NAMES_MALE)
|
||||||
end
|
if not L["race"] then
|
||||||
|
L["race"] = {}
|
||||||
if pfUI_config and pfUI_config.global and pfUI_config.global.language and not translations then
|
|
||||||
local lang = pfUI_config and pfUI_config.global and pfUI_config.global.language and pfUI_translation[pfUI_config.global.language] and pfUI_config.global.language or GetLocale()
|
|
||||||
pfUI.env.T = setmetatable(pfUI_translation[lang] or {}, { __index = function(tab,key)
|
|
||||||
local value = tostring(key)
|
|
||||||
rawset(tab,key,value)
|
|
||||||
return value
|
|
||||||
end})
|
|
||||||
translations = true
|
|
||||||
end
|
|
||||||
|
|
||||||
pfUI.env._G = getfenv(0)
|
|
||||||
pfUI.env.C = pfUI_config
|
|
||||||
pfUI.env.pfUI_throttle = _G.pfUI_throttle
|
|
||||||
pfUI.env.L = (pfUI_locale[GetLocale()] or pfUI_locale["enUS"])
|
|
||||||
pfUI.env.L["class"] = pfUI.env.L["class"] or tInvert(LOCALIZED_CLASS_NAMES_MALE)
|
|
||||||
if not pfUI.env.L["race"] then
|
|
||||||
pfUI.env.L["race"] = {}
|
|
||||||
local i = 1
|
local i = 1
|
||||||
local raceInfo = C_CreatureInfo.GetRaceInfo(i)
|
local raceInfo = C_CreatureInfo.GetRaceInfo(i)
|
||||||
while raceInfo ~= nil do
|
while raceInfo ~= nil do
|
||||||
pfUI.env.L["race"][raceInfo.clientFileString] = {
|
L["race"][raceInfo.clientFileString] = {
|
||||||
raceName = raceInfo.raceName,
|
raceName = raceInfo.raceName,
|
||||||
raceID = raceInfo.raceID,
|
raceID = raceInfo.raceID,
|
||||||
faction = C_CreatureInfo.GetFactionInfo(i).groupTag,
|
faction = C_CreatureInfo.GetFactionInfo(i).groupTag,
|
||||||
}
|
}
|
||||||
i = i + 1
|
i = i + 1
|
||||||
raceInfo = C_CreatureInfo.GetRaceInfo(i)
|
raceInfo = C_CreatureInfo.GetRaceInfo(i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
pfUI.env.L = L
|
||||||
|
end
|
||||||
|
|
||||||
return pfUI.env
|
return pfUI.env
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- C and T read the saved config, so they are set once it has loaded
|
||||||
|
local function SetupConfigEnvironment()
|
||||||
|
local language = pfUI_config.global.language
|
||||||
|
local lang = pfUI_translation[language] and language or GetLocale()
|
||||||
|
pfUI.env.T = setmetatable(pfUI_translation[lang] or {}, { __index = function(tab,key)
|
||||||
|
local value = tostring(key)
|
||||||
|
rawset(tab,key,value)
|
||||||
|
return value
|
||||||
|
end})
|
||||||
|
pfUI.env.C = pfUI_config
|
||||||
|
end
|
||||||
|
|
||||||
-- [ New Module Registry ]
|
-- [ New Module Registry ]
|
||||||
-- Tracks modules introduced after initial release so existing users get
|
-- Tracks modules introduced after initial release so existing users get
|
||||||
-- a one-time prompt asking if they want to enable them.
|
-- a one-time prompt asking if they want to enable them.
|
||||||
@@ -382,6 +387,7 @@ pfUI:SetScript("OnEvent", function()
|
|||||||
|
|
||||||
pfUI:LoadConfig()
|
pfUI:LoadConfig()
|
||||||
pfUI:MigrateConfig()
|
pfUI:MigrateConfig()
|
||||||
|
SetupConfigEnvironment()
|
||||||
pfUI:UpdateFonts()
|
pfUI:UpdateFonts()
|
||||||
|
|
||||||
-- load modules
|
-- load modules
|
||||||
|
|||||||
@@ -15,6 +15,22 @@ API_Check.lua
|
|||||||
|
|
||||||
pfUI.lua
|
pfUI.lua
|
||||||
|
|
||||||
|
# Client strings: enUS always (the fallback), plus the client's own locale.
|
||||||
|
env\locales_enUS.lua
|
||||||
|
env\combatlog_enUS.lua
|
||||||
|
env\locales_koKR.lua [AllowLoadTextLocale koKR]
|
||||||
|
env\combatlog_koKR.lua [AllowLoadTextLocale koKR]
|
||||||
|
env\locales_frFR.lua [AllowLoadTextLocale frFR]
|
||||||
|
env\combatlog_frFR.lua [AllowLoadTextLocale frFR]
|
||||||
|
env\locales_deDE.lua [AllowLoadTextLocale deDE]
|
||||||
|
env\combatlog_deDE.lua [AllowLoadTextLocale deDE]
|
||||||
|
env\locales_zhCN.lua [AllowLoadTextLocale zhCN]
|
||||||
|
env\combatlog_zhCN.lua [AllowLoadTextLocale zhCN]
|
||||||
|
env\locales_esES.lua [AllowLoadTextLocale esES]
|
||||||
|
env\combatlog_esES.lua [AllowLoadTextLocale esES]
|
||||||
|
env\locales_ruRU.lua [AllowLoadTextLocale ruRU]
|
||||||
|
env\combatlog_ruRU.lua [AllowLoadTextLocale ruRU]
|
||||||
|
|
||||||
init\env.xml
|
init\env.xml
|
||||||
init\stock.xml
|
init\stock.xml
|
||||||
init\api.xml
|
init\api.xml
|
||||||
|
|||||||
@@ -16,6 +16,22 @@ API_Check.lua
|
|||||||
|
|
||||||
pfUI.lua
|
pfUI.lua
|
||||||
|
|
||||||
|
# Client strings: enUS always (the fallback), plus the client's own locale.
|
||||||
|
env\locales_enUS.lua
|
||||||
|
env\combatlog_enUS.lua
|
||||||
|
env\locales_koKR.lua [AllowLoadTextLocale koKR]
|
||||||
|
env\combatlog_koKR.lua [AllowLoadTextLocale koKR]
|
||||||
|
env\locales_frFR.lua [AllowLoadTextLocale frFR]
|
||||||
|
env\combatlog_frFR.lua [AllowLoadTextLocale frFR]
|
||||||
|
env\locales_deDE.lua [AllowLoadTextLocale deDE]
|
||||||
|
env\combatlog_deDE.lua [AllowLoadTextLocale deDE]
|
||||||
|
env\locales_zhCN.lua [AllowLoadTextLocale zhCN]
|
||||||
|
env\combatlog_zhCN.lua [AllowLoadTextLocale zhCN]
|
||||||
|
env\locales_esES.lua [AllowLoadTextLocale esES]
|
||||||
|
env\combatlog_esES.lua [AllowLoadTextLocale esES]
|
||||||
|
env\locales_ruRU.lua [AllowLoadTextLocale ruRU]
|
||||||
|
env\combatlog_ruRU.lua [AllowLoadTextLocale ruRU]
|
||||||
|
|
||||||
init\env.xml
|
init\env.xml
|
||||||
init\api.xml
|
init\api.xml
|
||||||
init\libs.xml
|
init\libs.xml
|
||||||
|
|||||||
Reference in New Issue
Block a user