mirror of
https://github.com/brues-code/pfUI.git
synced 2026-11-02 17:06:57 +00:00
The module polled: a central OnUpdate at 100 Hz over every visible plate, a full OnDataChanged refresh of each plate every 0.5 s, and per-tick reads of the engine's name/level regions, frame size, mouse state and SpellIsTargeting. ClassicAPI feeds every unit event to the nameplateN tokens, so none of that is needed. Each bound plate now registers its unit events on its own frame against its token (UNIT_HEALTH/MAXHEALTH, UNIT_AURA_DELTA, UNIT_FLAGS, UNIT_DYNAMIC_FLAGS, UNIT_FACTION, UNIT_LEVEL, UNIT_CLASSIFICATION_CHANGED, UNIT_NAME_UPDATE, UNIT_TARGET, the casts) and each handler updates only what that event can change; the module-level events (target, combat, level-up, roster, guild, spell targeting) fan out to the plates they concern. Health comes from UnitHealth on the token instead of the engine bar's OnValueChanged hook; name, level and difficulty colour from UnitName/UnitLevel/GetDifficultyColor instead of the blanked engine regions (UnitLevel's -1 is exactly the engine's skull case, so "??B" survives). The engine resets the plate's size at every bind, so the engine frame's size and click routing are re-applied from its OnShow instead of being checked every tick; the overlay steps aside for ground-target spells on CURRENT_SPELL_CAST_CHANGED. The only OnUpdate left is a driver frame, shown while a castbar sweeps or the target zoom animates and hidden when both sets are empty; the zoom is time-based now rather than per-tick multiplication. The nameplates/nameplates_target/nameplates_mass throttle categories no longer mean anything and are gone from libthrottle and the GUI; nameplates_castbar stays as the sweep rate of non-target castbars. Mouseover tracking is gone (the token already names the unit), and libhealth's "known" return now decides whether absolute health is shown, so a unit whose health is only known as a percentage no longer prints "57 | 57%".
171 lines
4.7 KiB
Lua
171 lines
4.7 KiB
Lua
-- load pfUI environment
|
|
setfenv(1, pfUI:GetEnvironment())
|
|
|
|
-- return instantly when another libthrottle is already active
|
|
if pfUI.api.libthrottle then return end
|
|
|
|
-- Create libthrottle namespace
|
|
local libthrottle = CreateFrame("Frame", "pfLibThrottle")
|
|
pfUI.api.libthrottle = libthrottle
|
|
|
|
-- Preset definitions (FPS -> seconds)
|
|
libthrottle.presets = {
|
|
["very_slow"] = { fps = 2, delay = 0.5 },
|
|
["slow"] = { fps = 5, delay = 0.2 },
|
|
["normal"] = { fps = 10, delay = 0.1 },
|
|
["fast"] = { fps = 20, delay = 0.05 },
|
|
["very_fast"] = { fps = 30, delay = 0.033 },
|
|
["fastest"] = { fps = 50, delay = 0.02 },
|
|
}
|
|
|
|
-- Localized preset names
|
|
libthrottle.presetNames = {
|
|
["very_slow"] = "Very Slow (2 FPS)",
|
|
["slow"] = "Slow (5 FPS)",
|
|
["normal"] = "Normal (10 FPS)",
|
|
["fast"] = "Fast (20 FPS)",
|
|
["very_fast"] = "Very Fast (30 FPS)",
|
|
["fastest"] = "Fastest (50 FPS)",
|
|
["custom"] = "Custom",
|
|
}
|
|
|
|
-- Default throttle categories
|
|
libthrottle.defaults = {
|
|
nameplates_castbar = "custom",
|
|
tooltip_cursor = "fastest",
|
|
chat_tab = "custom",
|
|
swingtimer = "custom",
|
|
}
|
|
|
|
-- Convert FPS to throttle delay in seconds
|
|
function libthrottle:FpsToDelay(fps)
|
|
if not fps or fps <= 0 then return 0.1 end
|
|
return 1 / fps
|
|
end
|
|
|
|
-- Convert delay to FPS
|
|
function libthrottle:DelayToFps(delay)
|
|
if not delay or delay <= 0 then return 10 end
|
|
return math.floor(1 / delay)
|
|
end
|
|
|
|
-- Get throttle delay for a category
|
|
-- Returns: delay in seconds
|
|
function libthrottle:Get(category)
|
|
local configValue = _G.pfUI_throttle and _G.pfUI_throttle[category]
|
|
if not configValue then
|
|
configValue = self.defaults[category] or "normal"
|
|
end
|
|
|
|
-- Check if it's a preset name
|
|
local preset = self.presets[configValue]
|
|
if preset then
|
|
return preset.delay
|
|
end
|
|
|
|
-- If it's "custom", read from the _custom field
|
|
if configValue == "custom" then
|
|
local customFps = tonumber(_G.pfUI_throttle[category .. "_custom"])
|
|
if customFps then
|
|
return self:FpsToDelay(customFps)
|
|
end
|
|
end
|
|
|
|
-- Fallback to normal preset
|
|
return self.presets["normal"].delay
|
|
end
|
|
|
|
-- Get FPS value for a category (for display purposes)
|
|
function libthrottle:GetFps(category)
|
|
local delay = self:Get(category)
|
|
return self:DelayToFps(delay)
|
|
end
|
|
|
|
-- Get preset name for a category
|
|
function libthrottle:GetPreset(category)
|
|
local configValue = _G.pfUI_throttle and _G.pfUI_throttle[category]
|
|
if not configValue then
|
|
return self.defaults[category] or "normal"
|
|
end
|
|
|
|
-- Check if it's a known preset
|
|
if self.presets[configValue] then
|
|
return configValue
|
|
end
|
|
|
|
-- Must be a custom value
|
|
return "custom"
|
|
end
|
|
|
|
-- Check if a category is using custom FPS
|
|
function libthrottle:IsCustom(category)
|
|
return self:GetPreset(category) == "custom"
|
|
end
|
|
|
|
-- Set throttle for a category
|
|
function libthrottle:Set(category, value)
|
|
if not _G.pfUI_throttle then _G.pfUI_throttle = {} end
|
|
|
|
-- Validate preset
|
|
if type(value) == "string" and self.presets[value] then
|
|
_G.pfUI_throttle[category] = value
|
|
return true
|
|
end
|
|
|
|
-- If it's "custom", keep it
|
|
if value == "custom" then
|
|
_G.pfUI_throttle[category] = value
|
|
return true
|
|
end
|
|
|
|
return false
|
|
end
|
|
|
|
-- Reset a category to its default value
|
|
function libthrottle:ResetToDefault(category)
|
|
local default = self.defaults[category]
|
|
if default then
|
|
if not _G.pfUI_throttle then _G.pfUI_throttle = {} end
|
|
_G.pfUI_throttle[category] = default
|
|
return true
|
|
end
|
|
return false
|
|
end
|
|
|
|
-- Reset all categories to defaults
|
|
function libthrottle:ResetAllToDefaults()
|
|
if not _G.pfUI_throttle then _G.pfUI_throttle = {} end
|
|
for category, default in pairs(self.defaults) do
|
|
_G.pfUI_throttle[category] = default
|
|
end
|
|
end
|
|
|
|
-- Initialize - set defaults if config doesn't exist
|
|
libthrottle:SetScript("OnEvent", function()
|
|
if event == "PLAYER_ENTERING_WORLD" then
|
|
if not _G.pfUI_throttle then
|
|
_G.pfUI_throttle = {}
|
|
end
|
|
|
|
-- Set defaults for any missing categories
|
|
for category, default in pairs(libthrottle.defaults) do
|
|
if not _G.pfUI_throttle[category] then
|
|
_G.pfUI_throttle[category] = default
|
|
end
|
|
end
|
|
|
|
-- Set defaults for custom fields if missing
|
|
if not _G.pfUI_throttle.nameplates_castbar_custom then _G.pfUI_throttle.nameplates_castbar_custom = "100" end
|
|
if not _G.pfUI_throttle.tooltip_cursor_custom then _G.pfUI_throttle.tooltip_cursor_custom = "10" end
|
|
if not _G.pfUI_throttle.chat_tab_custom then _G.pfUI_throttle.chat_tab_custom = "10" end
|
|
if not _G.pfUI_throttle.swingtimer_custom then _G.pfUI_throttle.swingtimer_custom = "50" end
|
|
|
|
this:UnregisterEvent("PLAYER_ENTERING_WORLD")
|
|
end
|
|
end)
|
|
|
|
libthrottle:RegisterEvent("PLAYER_ENTERING_WORLD")
|
|
|
|
-- Export to pfUI namespace for easier access
|
|
pfUI.throttle = libthrottle
|